| 2 | #include <iostream> |
| 3 | |
| 4 | int main(int argc, char ** argv) |
| 5 | { |
| 6 | STARTUPINFOA startupInfo = { sizeof(startupInfo) }; |
| 7 | PROCESS_INFORMATION processInfo; |
| 8 | BOOL created = CreateProcessA(NULL, "DivinityEngine2.exe", NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startupInfo, &processInfo); |
| 9 | if (!created) |
| 10 | { |
| 11 | std::cerr << "Could not launch editor process: error " << GetLastError() << std::endl; |
| 12 | return 2; |
| 13 | } |
| 14 | |
| 15 | const char * DebugDllPath = "OsirisDebugBackend.dll"; |
| 16 | LPVOID dllPathPtr = VirtualAllocEx(processInfo.hProcess, NULL, strlen(DebugDllPath) + 1, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); |
| 17 | if (dllPathPtr == NULL) |
| 18 | { |
| 19 | TerminateProcess(processInfo.hProcess, 1); |
| 20 | std::cerr << "Could not allocate memory for DLL name: error " << GetLastError() << std::endl; |
| 21 | return 2; |
| 22 | } |
| 23 | |
| 24 | BOOL pathWriteOk = WriteProcessMemory(processInfo.hProcess, dllPathPtr, DebugDllPath, strlen(DebugDllPath) + 1, NULL); |
| 25 | if (!pathWriteOk) |
| 26 | { |
| 27 | TerminateProcess(processInfo.hProcess, 1); |
| 28 | std::cerr << "Could not write DLL name: error " << GetLastError() << std::endl; |
| 29 | return 2; |
| 30 | } |
| 31 | |
| 32 | HMODULE hKernel32 = GetModuleHandleA("kernel32.dll"); |
| 33 | LPVOID pLoadLibrary = (LPVOID)GetProcAddress(hKernel32, "LoadLibraryA"); |
| 34 | |
| 35 | HANDLE hLoaderThread = CreateRemoteThread(processInfo.hProcess, NULL, NULL, |
| 36 | (LPTHREAD_START_ROUTINE)pLoadLibrary, dllPathPtr, NULL, NULL); |
| 37 | if (hLoaderThread == NULL) |
| 38 | { |
| 39 | TerminateProcess(processInfo.hProcess, 1); |
| 40 | std::cerr << "Could not start library loader thread: error " << GetLastError() << std::endl; |
| 41 | return 2; |
| 42 | } |
| 43 | |
| 44 | WaitForSingleObject(hLoaderThread, INFINITE); |
| 45 | CloseHandle(hLoaderThread); |
| 46 | |
| 47 | ResumeThread(processInfo.hThread); |
| 48 | CloseHandle(processInfo.hThread); |
| 49 | CloseHandle(processInfo.hProcess); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 |
nothing calls this directly
no outgoing calls
no test coverage detected