Skip to content

Commit

Permalink
Win-specific: Fix some crashes in scan libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Abs62 committed Dec 16, 2011
1 parent 5e49c32 commit 0c7a920
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 201 deletions.
12 changes: 6 additions & 6 deletions mouseover_win32/HookImportFunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ static BOOL HookImportFunction(HMODULE hModule, LPCSTR szImportModule, LPCSTR sz
if (bDoHook) {
MEMORY_BASIC_INFORMATION mbi_thunk;
DWORD dwOldProtect;

if( !VirtualQuery(pRealThunk, &mbi_thunk, sizeof(MEMORY_BASIC_INFORMATION)) )
if( VirtualQuery(pRealThunk, &mbi_thunk, sizeof(MEMORY_BASIC_INFORMATION)) != sizeof(MEMORY_BASIC_INFORMATION))
return FALSE;
if( !VirtualProtect(mbi_thunk.BaseAddress, mbi_thunk.RegionSize, PAGE_READWRITE, &mbi_thunk.Protect) )
return FALSE;
if (paOrigFuncs)
*paOrigFuncs = (PROC)pRealThunk->u1.Function;
pRealThunk->u1.Function = (DWORD)paHookFuncs;
*paOrigFuncs = (PROC)InterlockedExchange((long *)&(pRealThunk->u1.Function), (long)paHookFuncs);
else
InterlockedExchange((long *)&(pRealThunk->u1.Function), (long)paHookFuncs);

VirtualProtect(mbi_thunk.BaseAddress, mbi_thunk.RegionSize, mbi_thunk.Protect, &dwOldProtect);
return TRUE;
Expand Down Expand Up @@ -128,10 +128,10 @@ BOOL HookAPI(LPCSTR szImportModule, LPCSTR szFunc, PROC paHookFuncs, PROC* paOri

if(hSnapshot == INVALID_HANDLE_VALUE) return FALSE;

bOk = Module32First(hSnapshot,&me);
bOk = Module32First(hSnapshot, &me);
while (bOk) {
HookImportFunction(me.hModule, szImportModule, szFunc, paHookFuncs, paOrigFuncs);
bOk = Module32Next(hSnapshot,&me);
bOk = Module32Next(hSnapshot, &me);
}
CloseHandle(hSnapshot);
return TRUE;
Expand Down
1 change: 0 additions & 1 deletion mouseover_win32/HookImportFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <windows.h>


BOOL HookAPI(LPCSTR szImportModule, LPCSTR szFunc, PROC paHookFuncs, PROC* paOrigFuncs);

#endif
Loading

0 comments on commit 0c7a920

Please sign in to comment.