From cfa5dd3ea5c68444edff26615f44026183037d3c Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 8 May 2019 13:51:50 +0100 Subject: [PATCH] Add more specific errors if DLL injection fails --- renderdoc/os/win32/win32_process.cpp | 30 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/renderdoc/os/win32/win32_process.cpp b/renderdoc/os/win32/win32_process.cpp index 54500f59e..cef4834d6 100644 --- a/renderdoc/os/win32/win32_process.cpp +++ b/renderdoc/os/win32/win32_process.cpp @@ -279,21 +279,33 @@ void InjectDLL(HANDLE hProcess, std::wstring libName) VirtualAllocEx(hProcess, NULL, sizeof(dllPath), MEM_COMMIT, PAGE_EXECUTE_READWRITE); 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); - if(hThread) + BOOL success = WriteProcessMemory(hProcess, remoteMem, (void *)dllPath, sizeof(dllPath), NULL); + if(success) { - WaitForSingleObject(hThread, INFINITE); - CloseHandle(hThread); + HANDLE hThread = CreateRemoteThread( + hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(kernel32, "LoadLibraryW"), + remoteMem, 0, NULL); + if(hThread) + { + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + } + else + { + RDCERR("Couldn't create remote thread for LoadLibraryW: %u", GetLastError()); + } } + else + { + RDCERR("Couldn't write remote memory %p with dllPath '%ls': %u", remoteMem, dllPath, + GetLastError()); + } + VirtualFreeEx(hProcess, remoteMem, 0, MEM_RELEASE); } else { - RDCERR("Couldn't allocate remote memory for DLL '%ls'", libName.c_str()); + RDCERR("Couldn't allocate remote memory for DLL '%ls': %u", libName.c_str(), GetLastError()); } }