Skip to content

Commit

Permalink
replace offsets into signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeMod committed Apr 16, 2023
1 parent 9880244 commit 8210565
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 123 deletions.
15 changes: 7 additions & 8 deletions metahook.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,31 @@ inline PVOID MH_GetModuleBase(HMODULE hModule)
return (PVOID)mem.AllocationBase;
}

inline DWORD MH_GetModuleSize(HMODULE hModule)
inline LONG_PTR MH_GetModuleSize(HMODULE hModule)
{
return ((IMAGE_NT_HEADERS*)((LONG_PTR)hModule + ((IMAGE_DOS_HEADER*)hModule)->e_lfanew))->OptionalHeader.SizeOfImage;
}

inline void* MH_SearchPattern(void* pStartSearch, DWORD dwSearchLen, const char* pPattern, DWORD dwPatternLen)
inline void* MH_SearchPattern(void* pStartSearch, LONG_PTR dwSearchLen, const char* pPattern, LONG_PTR dwPatternLen)
{
LONG_PTR dwStartAddr = (LONG_PTR)pStartSearch;
LONG_PTR dwEndAddr = dwStartAddr + dwSearchLen - dwPatternLen;
BYTE *dwStartAddr = (BYTE *)pStartSearch;
BYTE *dwEndAddr = dwStartAddr + dwSearchLen - dwPatternLen;

while (dwStartAddr < dwEndAddr)
{
bool found = true;

for (DWORD i = 0; i < dwPatternLen; i++)
for (LONG_PTR i = 0; i < dwPatternLen; i++)
{
char code = *(char*)(dwStartAddr + i);
if (pPattern[i] != 0x2A && pPattern[i] != code)
if ((BYTE)pPattern[i] != 0x2A && (BYTE)pPattern[i] != dwStartAddr[i])
{
found = false;
break;
}
}

if (found)
return (void*)dwStartAddr;
return dwStartAddr;

dwStartAddr++;
}
Expand Down
Loading

0 comments on commit 8210565

Please sign in to comment.