Skip to content

Commit

Permalink
AcquireSRWLockExclusive hook
Browse files Browse the repository at this point in the history
- compAtibility With more games
  • Loading branch information
ThirteenAG committed Nov 12, 2023
1 parent 0947e93 commit 983f440
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ enum Kernel32ExportsNames
eGetCurrentProcessId,
eGetCommandLineA,
eGetCommandLineW,
eAcquireSRWLockExclusive,
eCreateFileA,
eCreateFileW,
eGetFileAttributesA,
Expand Down Expand Up @@ -808,6 +809,12 @@ LPWSTR WINAPI CustomGetCommandLineW()
return GetCommandLineW();
}

void WINAPI CustomAcquireSRWLockExclusive(PSRWLOCK SRWLock)
{
LoadPluginsAndRestoreIAT((uintptr_t)_ReturnAddress());
return AcquireSRWLockExclusive(SRWLock);
}

std::filesystem::path GetFileName(auto lpFilename)
{
std::error_code ec;
Expand Down Expand Up @@ -1073,6 +1080,7 @@ bool HookKernel32IAT(HMODULE mod, bool exe)
Kernel32Data[eGetCurrentProcessId][ProcAddress] = (size_t)GetProcAddress(GetModuleHandle(TEXT("KERNEL32.DLL")), "GetCurrentProcessId");
Kernel32Data[eGetCommandLineA][ProcAddress] = (size_t)GetProcAddress(GetModuleHandle(TEXT("KERNEL32.DLL")), "GetCommandLineA");
Kernel32Data[eGetCommandLineW][ProcAddress] = (size_t)GetProcAddress(GetModuleHandle(TEXT("KERNEL32.DLL")), "GetCommandLineW");
Kernel32Data[eAcquireSRWLockExclusive][ProcAddress] = (size_t)GetProcAddress(GetModuleHandle(TEXT("KERNEL32.DLL")), "AcquireSRWLockExclusive");
Kernel32Data[eCreateFileA][ProcAddress] = (size_t)GetProcAddress(GetModuleHandle(TEXT("KERNEL32.DLL")), "CreateFileA");
Kernel32Data[eCreateFileW][ProcAddress] = (size_t)GetProcAddress(GetModuleHandle(TEXT("KERNEL32.DLL")), "CreateFileW");
Kernel32Data[eGetFileAttributesA][ProcAddress] = (size_t)GetProcAddress(GetModuleHandle(TEXT("KERNEL32.DLL")), "GetFileAttributesA");
Expand Down Expand Up @@ -1227,6 +1235,12 @@ bool HookKernel32IAT(HMODULE mod, bool exe)
*(size_t*)i = (size_t)CustomGetCommandLineW;
matchedImports++;
}
else if (ptr == Kernel32Data[eAcquireSRWLockExclusive][ProcAddress])
{
if (exe) Kernel32Data[eAcquireSRWLockExclusive][IATPtr] = i;
*(size_t*)i = (size_t)CustomAcquireSRWLockExclusive;
matchedImports++;
}
else if (ptr == Kernel32Data[eCreateFileA][ProcAddress])
{
if (exe) Kernel32Data[eCreateFileA][IATPtr] = i;
Expand Down

0 comments on commit 983f440

Please sign in to comment.