@@ -96,18 +96,20 @@ void DoSearchModule(DWORD dwProcessId)
96
96
CloseHandle (hModuleSnap);
97
97
98
98
// do DllUnInject
99
- if (hEasyHook64 || hHookDll)
99
+ if (hHookDll)
100
100
{
101
- DoDllUnInject (dwProcessId, hEasyHook64, hHookDll);
101
+ OutputDebugString (L" HookDll.dll UnInject START\n " );
102
+ DoDllUnInject (dwProcessId, hHookDll);
103
+ }
104
+ if (hEasyHook64)
105
+ {
106
+ OutputDebugString (L" EasyHook64.dll UnInject START\n " );
107
+ DoDllUnInject (dwProcessId, hEasyHook64);
102
108
}
103
-
104
109
}
105
110
106
- void DoDllUnInject (DWORD dwProcessId, HMODULE hEasyHook64, HMODULE hHookDll )
111
+ void DoDllUnInject (DWORD dwProcessId, HMODULE hModule )
107
112
{
108
- SIZE_T stBufSize = sizeof (HMODULE);
109
- SIZE_T stWriteSize = 0 ;
110
- LPVOID pRemoteBuf = NULL ;
111
113
HMODULE hKernel32 = NULL ;
112
114
PTHREAD_START_ROUTINE pThreadProc = NULL ;
113
115
HANDLE hThread = NULL ;
@@ -117,57 +119,15 @@ void DoDllUnInject(DWORD dwProcessId, HMODULE hEasyHook64, HMODULE hHookDll)
117
119
hKernel32 = GetModuleHandle (L" kernel32.dll" );
118
120
pThreadProc = (PTHREAD_START_ROUTINE)GetProcAddress (hKernel32, " FreeLibrary" );
119
121
120
- // alloc in the target process
121
- pRemoteBuf = VirtualAllocEx (hProcess, NULL , stBufSize, MEM_COMMIT, PAGE_READWRITE);
122
- if (!pRemoteBuf)
123
- {
124
- OutputDebugString (L" VirtualAllocEx ERROR\n " );
125
- return ;
126
- }
127
-
128
- // do UnInject to HookDll.dll
129
- if (hHookDll)
130
- {
131
- OutputDebugString (L" HookDll.dll UnInject START\n " );
132
- WriteProcessMemory (hProcess, pRemoteBuf, (LPVOID)&hHookDll, stBufSize, &stWriteSize);
133
- if (stBufSize != stWriteSize)
134
- {
135
- OutputDebugString (L" WriteProcessMemory ERROR\n " );
136
- return ;
137
- }
138
- hThread = CreateRemoteThread (hProcess,
139
- NULL ,
140
- 0 ,
141
- (LPTHREAD_START_ROUTINE)pThreadProc,
142
- pRemoteBuf,
143
- 0 ,
144
- NULL );
145
- if (hThread)
146
- {
147
- WaitForSingleObject (hThread, INFINITE);
148
- CloseHandle (hThread);
149
- }
150
- else
151
- {
152
- OutputDebugString (L" CreateRemoteThread ERROR\n " );
153
- }
154
- }
155
-
156
- // do UnInject to EasyHook64.dll
157
- if (hEasyHook64)
122
+ // do UnInject
123
+ if (hModule)
158
124
{
159
- OutputDebugString (L" EasyHook64.dll UnInject START\n " );
160
- WriteProcessMemory (hProcess, pRemoteBuf, (LPVOID)&hEasyHook64, stBufSize, &stWriteSize);
161
- if (stBufSize != stWriteSize)
162
- {
163
- OutputDebugString (L" WriteProcessMemory ERROR\n " );
164
- return ;
165
- }
125
+
166
126
hThread = CreateRemoteThread (hProcess,
167
127
NULL ,
168
128
0 ,
169
129
(LPTHREAD_START_ROUTINE)pThreadProc,
170
- pRemoteBuf ,
130
+ hModule ,
171
131
0 ,
172
132
NULL );
173
133
if (hThread)
@@ -180,8 +140,6 @@ void DoDllUnInject(DWORD dwProcessId, HMODULE hEasyHook64, HMODULE hHookDll)
180
140
OutputDebugString (L" CreateRemoteThread ERROR\n " );
181
141
}
182
142
}
183
-
184
- VirtualFreeEx (hProcess, pRemoteBuf, stBufSize, MEM_RELEASE);
185
143
}
186
144
187
145
void DoReleaseSemaphoreStatus ()
0 commit comments