@@ -59,6 +59,7 @@ void StartMonitor()
59
59
{
60
60
OutputDebugString (TEXT (" Do start \n " ));
61
61
62
+ /*
62
63
HANDLE hMutexSingleton = NULL;
63
64
64
65
hMutexSingleton = CreateMutex(NULL, TRUE, TEXT("APIHOOK_Monitor_Mutex_Singleton"));
@@ -74,21 +75,51 @@ void StartMonitor()
74
75
OutputDebugString(TEXT("CreateMutex ERROR\n"));
75
76
return;
76
77
}
78
+ */
79
+
80
+ HANDLE hTargetListFile = NULL ;
81
+ TCHAR szTargetListFilePath[MAX_PATH];
82
+
83
+ GetCurrentDirectory (MAX_PATH, szTargetListFilePath);
84
+ StringCbCat (szTargetListFilePath, MAX_PATH, TEXT (" \\ TargetList.txt" ));
85
+ hTargetListFile = CreateFile (szTargetListFilePath, GENERIC_WRITE, FILE_SHARE_READ, NULL , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
86
+ if (INVALID_HANDLE_VALUE == hTargetListFile)
87
+ {
88
+ OutputDebugString (TEXT (" CreateFile ERROR\n " ));
89
+ switch (GetLastError ())
90
+ {
91
+ case ERROR_FILE_NOT_FOUND:
92
+ OutputDebugString (TEXT (" TargetList.txt is not found\n " ));
93
+ printf_s (" TargetList.txt is not found\n " );
94
+ break ;
95
+ case ERROR_SHARING_VIOLATION:
96
+ OutputDebugString (TEXT (" Monitor.exe is already running\n " ));
97
+ printf_s (" Monitor.exe is already running\n " );
98
+ break ;
99
+ default :
100
+ printf_s (" create file targetlist error: %d\n " , GetLastError ());
101
+ break ;
102
+ }
103
+ return ;
104
+ }
77
105
78
106
Log ();
79
107
108
+ CloseHandle (hTargetListFile);
109
+ hTargetListFile = NULL ;
110
+
111
+ /*
80
112
ReleaseMutex(hMutexSingleton);
81
113
CloseHandle(hMutexSingleton);
82
114
hMutexSingleton = NULL;
83
-
115
+ */
84
116
}
85
117
86
118
87
119
void StopMonitor ()
88
120
{
89
121
OutputDebugString (TEXT (" Do stop \n " ));
90
-
91
- MyCreateProcess (TEXT (" DllUnInject.dll" ));
122
+ MyCreateProcess (TEXT (" DllUnInject.exe" ));
92
123
93
124
}
94
125
@@ -103,15 +134,13 @@ void RestartMonitor()
103
134
104
135
void MyCreateProcess (LPCTSTR szProcessName)
105
136
{
106
- TCHAR szCurrentDirectory[MAX_PATH];
107
137
TCHAR szProcessPath[MAX_PATH];
108
138
STARTUPINFO si;
109
139
PROCESS_INFORMATION pi ;
110
140
111
141
ZeroMemory (&si, sizeof (si));
112
142
ZeroMemory (&pi , sizeof (pi ));
113
- GetCurrentDirectory (MAX_PATH, szCurrentDirectory);
114
- StringCbCopy (szProcessPath, MAX_PATH, szCurrentDirectory);
143
+ GetCurrentDirectory (MAX_PATH, szProcessPath);
115
144
StringCbCat (szProcessPath, MAX_PATH, TEXT (" \\ " ));
116
145
StringCbCat (szProcessPath, MAX_PATH, szProcessName);
117
146
OutputDebugString (TEXT (" CreateProcess " ));
@@ -127,4 +156,4 @@ void MyCreateProcess(LPCTSTR szProcessName)
127
156
WaitForSingleObject (pi .hProcess , INFINITE);
128
157
OutputDebugString (szProcessName);
129
158
OutputDebugString (TEXT (" Finished\n " ));
130
- }
159
+ }
0 commit comments