mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-28 21:01:04 +00:00
[Refs #87: Static Analysis] Add error checks for injecting remote DLL
This commit is contained in:
@@ -43,14 +43,29 @@ void InjectDLL(HANDLE hProcess, wstring libName)
|
||||
|
||||
static HMODULE kernel32 = GetModuleHandle(_T("Kernel32"));
|
||||
|
||||
if(kernel32 == NULL)
|
||||
{
|
||||
RDCERR("Couldn't get handle for kernel32.dll");
|
||||
return;
|
||||
}
|
||||
|
||||
void *remoteMem = VirtualAllocEx(hProcess, NULL, sizeof(dllPath), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
WriteProcessMemory(hProcess, remoteMem, (void *)dllPath, sizeof(dllPath), NULL);
|
||||
if(remoteMem)
|
||||
{
|
||||
WriteProcessMemory(hProcess, remoteMem, (void *)dllPath, sizeof(dllPath), NULL);
|
||||
|
||||
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(kernel32, "LoadLibraryW"), remoteMem, 0, NULL);
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
|
||||
CloseHandle(hThread);
|
||||
VirtualFreeEx(hProcess, remoteMem, sizeof(dllPath), MEM_RELEASE);
|
||||
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(kernel32, "LoadLibraryW"), remoteMem, 0, NULL);
|
||||
if(hThread)
|
||||
{
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
CloseHandle(hThread);
|
||||
}
|
||||
VirtualFreeEx(hProcess, remoteMem, sizeof(dllPath), MEM_RELEASE);
|
||||
}
|
||||
else
|
||||
{
|
||||
RDCERR("Couldn't allocate remote memory for DLL '%ls'", libName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
uintptr_t FindRemoteDLL(DWORD pid, wstring libName)
|
||||
|
||||
Reference in New Issue
Block a user