@@ -34,6 +34,8 @@ static bool g_running;
3434// ----------------------------------------------------------------------------
3535static void HandleNewProcess (DWORD pid, LPCWSTR filePath)
3636{
37+ bool ok = false ;
38+ HANDLE hFile = INVALID_HANDLE_VALUE ;
3739 HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS , FALSE , pid);
3840
3941 snprintf (g_path, sizeof (g_path), PIPE_NAME , pid);
@@ -43,31 +45,30 @@ static void HandleNewProcess(DWORD pid, LPCWSTR filePath)
4345 if (hPipe == INVALID_HANDLE_VALUE )
4446 {
4547 PID_DEBUG (" couldn't open named pipe (error 0x%x)\n " , pid, GetLastError ());
46- return ;
4748 }
4849 else
4950 {
5051 g_namedPipes.push_back (hPipe);
51- }
5252
53- PID_DEBUG (" starting %ws\n " , pid, filePath);
53+ PID_DEBUG (" Starting %ws\n " , pid, filePath);
5454
55- GetCurrentDirectoryW (MAX_PATH , g_pathw);
56- std::wstring currentDir (g_pathw);
55+ GetCurrentDirectoryW (MAX_PATH , g_pathw);
56+ std::wstring currentDir (g_pathw);
5757
58- GetModuleFileNameW (NULL , g_pathw, MAX_PATH );
59- wcsrchr (g_pathw, L' \\ ' )[1 ] = 0 ;
60- SetCurrentDirectoryW (g_pathw);
61-
62- WIN32_FIND_DATAW findData;
63- HANDLE hFile = FindFirstFileW (L" .\\ UnrealKey64.dll" , &findData);
58+ GetModuleFileNameW (NULL , g_pathw, MAX_PATH );
59+ wcsrchr (g_pathw, L' \\ ' )[1 ] = 0 ;
60+ SetCurrentDirectoryW (g_pathw);
61+
62+ WIN32_FIND_DATAW findData = { 0 };
63+ hFile = FindFirstFileW (L" .\\ UnrealKey64.dll" , &findData);
64+ wcscat_s (g_pathw, findData.cFileName );
6465
65- SetCurrentDirectoryW (currentDir.c_str ());
66+ SetCurrentDirectoryW (currentDir.c_str ());
67+ }
6668
6769 if (hFile != INVALID_HANDLE_VALUE )
6870 {
6971 // got DLL path, load it in the remote process
70- wcscat_s (g_pathw, findData.cFileName );
7172
7273 LPVOID procMem = VirtualAllocEx (hProcess, NULL , sizeof (g_pathw), MEM_RESERVE | MEM_COMMIT , PAGE_READWRITE );
7374 if (WriteProcessMemory (hProcess, procMem, g_pathw, sizeof (g_pathw), NULL ))
@@ -79,23 +80,40 @@ static void HandleNewProcess(DWORD pid, LPCWSTR filePath)
7980 if (hThread)
8081 {
8182 WaitForSingleObject (hThread, INFINITE );
83+
84+ DWORD exitCode;
85+ if (GetExitCodeThread (hThread, &exitCode) && exitCode)
86+ {
87+ ok = true ;
88+ }
89+ else
90+ {
91+ PID_DEBUG (" Remote thread init error\n " , pid);
92+ }
93+
8294 CloseHandle (hThread);
8395 }
8496 else
8597 {
86- PID_DEBUG (" couldn 't start remote thread\n " , pid);
98+ PID_DEBUG (" Couldn 't start remote thread (error 0x%x) \n " , pid, GetLastError () );
8799 }
88100 }
89101 else
90102 {
91- PID_DEBUG (" couldn 't write to process memory\n " , pid);
103+ PID_DEBUG (" Couldn 't write to process memory (error 0x%x) \n " , pid, GetLastError () );
92104 }
93105
94106 FindClose (hFile);
95107 }
96108 else
97109 {
98- PID_DEBUG (" couldn't find UnrealKey64.dll\n " , pid);
110+ PID_DEBUG (" Couldn't find UnrealKey64.dll\n " , pid);
111+ }
112+
113+ if (!ok)
114+ {
115+ // can't do anything useful here, just leave
116+ TerminateProcess (hProcess, 1 );
99117 }
100118
101119 CloseHandle (hProcess);
0 commit comments