error on architecture mismatch

This commit is contained in:
Akash Mozumdar 2018-08-22 15:11:58 -04:00
parent cda2cefc28
commit 588b013392

View File

@ -57,16 +57,32 @@ namespace Host
FreeLibrary(textHooker); FreeLibrary(textHooker);
if (HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId)) if (HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId))
{
#ifdef _WIN64
BOOL invalidProcess = FALSE;
IsWow64Process(processHandle, &invalidProcess);
if (invalidProcess)
{
AddConsoleOutput(L"architecture mismatch: try 32 bit NextHooker instead");
CloseHandle(processHandle);
return false;
}
#endif
if (LPVOID remoteData = VirtualAllocEx(processHandle, nullptr, textHookerPathSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)) if (LPVOID remoteData = VirtualAllocEx(processHandle, nullptr, textHookerPathSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE))
if (WriteProcessMemory(processHandle, remoteData, textHookerPath, textHookerPathSize, nullptr)) {
if (HANDLE thread = CreateRemoteThread(processHandle, nullptr, 0, (LPTHREAD_START_ROUTINE)LoadLibraryW, remoteData, 0, nullptr)) WriteProcessMemory(processHandle, remoteData, textHookerPath, textHookerPathSize, nullptr);
{ if (HANDLE thread = CreateRemoteThread(processHandle, nullptr, 0, (LPTHREAD_START_ROUTINE)LoadLibraryW, remoteData, 0, nullptr))
WaitForSingleObject(thread, timeout); {
CloseHandle(thread); WaitForSingleObject(thread, timeout);
VirtualFreeEx(processHandle, remoteData, 0, MEM_RELEASE); CloseHandle(thread);
CloseHandle(processHandle); VirtualFreeEx(processHandle, remoteData, 0, MEM_RELEASE);
return true; CloseHandle(processHandle);
} return true;
}
VirtualFreeEx(processHandle, remoteData, 0, MEM_RELEASE);
CloseHandle(processHandle);
}
}
AddConsoleOutput(L"couldn't inject dll"); AddConsoleOutput(L"couldn't inject dll");
return false; return false;