@@ -59,6 +59,7 @@ void StartMonitor()
5959{
6060 OutputDebugString (TEXT (" Do start \n " ));
6161
62+ /*
6263 HANDLE hMutexSingleton = NULL;
6364
6465 hMutexSingleton = CreateMutex(NULL, TRUE, TEXT("APIHOOK_Monitor_Mutex_Singleton"));
@@ -74,21 +75,51 @@ void StartMonitor()
7475 OutputDebugString(TEXT("CreateMutex ERROR\n"));
7576 return;
7677 }
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+ }
77105
78106 Log ();
79107
108+ CloseHandle (hTargetListFile);
109+ hTargetListFile = NULL ;
110+
111+ /*
80112 ReleaseMutex(hMutexSingleton);
81113 CloseHandle(hMutexSingleton);
82114 hMutexSingleton = NULL;
83-
115+ */
84116}
85117
86118
87119void StopMonitor ()
88120{
89121 OutputDebugString (TEXT (" Do stop \n " ));
90-
91- MyCreateProcess (TEXT (" DllUnInject.dll" ));
122+ MyCreateProcess (TEXT (" DllUnInject.exe" ));
92123
93124}
94125
@@ -103,15 +134,13 @@ void RestartMonitor()
103134
104135void MyCreateProcess (LPCTSTR szProcessName)
105136{
106- TCHAR szCurrentDirectory[MAX_PATH];
107137 TCHAR szProcessPath[MAX_PATH];
108138 STARTUPINFO si;
109139 PROCESS_INFORMATION pi;
110140
111141 ZeroMemory (&si, sizeof (si));
112142 ZeroMemory (&pi, sizeof (pi));
113- GetCurrentDirectory (MAX_PATH, szCurrentDirectory);
114- StringCbCopy (szProcessPath, MAX_PATH, szCurrentDirectory);
143+ GetCurrentDirectory (MAX_PATH, szProcessPath);
115144 StringCbCat (szProcessPath, MAX_PATH, TEXT (" \\ " ));
116145 StringCbCat (szProcessPath, MAX_PATH, szProcessName);
117146 OutputDebugString (TEXT (" CreateProcess " ));
@@ -127,4 +156,4 @@ void MyCreateProcess(LPCTSTR szProcessName)
127156 WaitForSingleObject (pi.hProcess , INFINITE);
128157 OutputDebugString (szProcessName);
129158 OutputDebugString (TEXT (" Finished\n " ));
130- }
159+ }
0 commit comments