| 99 | } |
| 100 | |
| 101 | static void InjectThisDll(HANDLE hProcess) |
| 102 | { |
| 103 | HMODULE kernel32 = GetModuleHandleA("kernel32"); |
| 104 | auto pVirtualAllocEx = (decltype(&VirtualAllocEx))GetProcAddress(kernel32, "VirtualAllocEx"); |
| 105 | auto pWriteProcessMemory = (decltype(&WriteProcessMemory))GetProcAddress(kernel32, "WriteProcessMemory"); |
| 106 | auto pCreateRemoteThread = (decltype(&CreateRemoteThread))GetProcAddress(kernel32, "CreateRemoteThread"); |
| 107 | |
| 108 | WCHAR thisDllPath[2048]{}; |
| 109 | GetModuleFileNameW((HMODULE)&__ImageBase, thisDllPath, _countof(thisDllPath)); |
| 110 | |
| 111 | size_t pathSize = (wcslen(thisDllPath) + 1) * sizeof(WCHAR); |
| 112 | LPVOID pathAddr = pVirtualAllocEx(hProcess, NULL, pathSize, MEM_COMMIT, PAGE_READWRITE); |
| 113 | pWriteProcessMemory(hProcess, pathAddr, thisDllPath, pathSize, NULL); |
| 114 | |
| 115 | HANDLE loader = pCreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)&LoadLibraryW, pathAddr, 0, NULL); |
| 116 | WaitForSingleObject(loader, INFINITE); |
| 117 | CloseHandle(loader); |
| 118 | } |
| 119 | |
| 120 | int APIENTRY _BootstrapEntry(HWND, HINSTANCE, LPWSTR commandLine, int) |
| 121 | { |
no outgoing calls
no test coverage detected