@@ -16,22 +16,22 @@ namespace LibraryInject
1616 {
1717 auto hProcess = (win::Handle)OpenProcess (PROCESS_ALL_ACCESS, FALSE , processId);
1818 if (!hProcess) {
19- LOGI << " OpenProcess failed with [" << win::GetErrorDescription (GetLastError ()) << " ]; re-attemping with elevated privileges" ;
19+ LOGI << " OpenProcess failed with [" << win::GetErrorDescription (GetLastError ()) << " ]; re-attemping with elevated privileges" << std::endl ;
2020
2121 // Increase privileges
2222 win::Handle hToken;
2323 {
2424 HANDLE tempHandle;
2525 if (!OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tempHandle)) {
26- LOGE << " OpenProcessToken failed for current process. Error: " << win::GetErrorDescription (GetLastError ());
26+ LOGE << " OpenProcessToken failed for current process. Error: " << win::GetErrorDescription (GetLastError ()) << std::endl ;
2727 exit (1 );
2828 }
2929 hToken = win::Handle (tempHandle);
3030 }
3131
3232 LUID debugPrivilegeId;
3333 if (!LookupPrivilegeValue (NULL , SE_DEBUG_NAME, &debugPrivilegeId)) {
34- LOGE << " LookupPrivilegeValue failed for current process. Error: " << win::GetErrorDescription (GetLastError ());
34+ LOGE << " LookupPrivilegeValue failed for current process. Error: " << win::GetErrorDescription (GetLastError ()) << std::endl ;
3535 exit (1 );
3636 }
3737
@@ -42,12 +42,12 @@ namespace LibraryInject
4242 }
4343 };
4444 if (!AdjustTokenPrivileges (hToken, FALSE , &tokenPrivileges, sizeof (tokenPrivileges), NULL , NULL )) {
45- LOGE << " AdjustTokenPrivileges failed for current process. Error: " << win::GetErrorDescription (GetLastError ());
45+ LOGE << " AdjustTokenPrivileges failed for current process. Error: " << win::GetErrorDescription (GetLastError ()) << std::endl ;
4646 exit (1 );
4747 }
4848
4949 if (!(hProcess = (win::Handle)OpenProcess (PROCESS_ALL_ACCESS, FALSE , processId))) {
50- LOGE << " Could not open process to attach with elevated privileges. Error: " << win::GetErrorDescription (GetLastError ());
50+ LOGE << " Could not open process to attach with elevated privileges. Error: " << win::GetErrorDescription (GetLastError ()) << std::endl ;
5151 exit (1 );
5252 }
5353 }
@@ -64,14 +64,14 @@ namespace LibraryInject
6464 if (pRemoteMem == NULL )
6565 {
6666 auto error = GetLastError ();
67- LOGE << " Could not allocate memory in target process. Error: " << win::GetErrorDescription (error);
67+ LOGE << " Could not allocate memory in target process. Error: " << win::GetErrorDescription (error) << std::endl ;
6868 exit (1 );
6969 }
7070
7171 if (!WriteProcessMemory (hProcess, pRemoteMem, absDllPath.c_str (), remoteMemSize, NULL ))
7272 {
7373 auto error = GetLastError ();
74- LOGE << " WriteProcessMemory failed. Error: " << win::GetErrorDescription (error);
74+ LOGE << " WriteProcessMemory failed. Error: " << win::GetErrorDescription (error) << std::endl ;
7575 exit (1 );
7676 }
7777 FlushInstructionCache (hProcess, pRemoteMem, remoteMemSize);
@@ -91,7 +91,7 @@ namespace LibraryInject
9191 {
9292 auto error = GetLastError ();
9393 LOGE << " Could not create remote thread in target process. Error: " << win::GetErrorDescription (error);
94- LOGE << " Tip: Check bit-ness of the application and DXGIOverlay.exe." ;
94+ LOGE << " Tip: Check bit-ness of the application and DXGIOverlay.exe." << std::endl ;
9595 VirtualFreeEx (hProcess, pRemoteMem, 0 , MEM_RELEASE);
9696 exit (1 );
9797 }
@@ -107,4 +107,38 @@ namespace LibraryInject
107107 auto hTargetProcess = LibraryInject::OpenProcessAndMaybeElevate_ (processId);
108108 LibraryInject::InjectDll (hTargetProcess, dllPath);
109109 }
110+
111+ ProcessMap GetProcessNames ()
112+ {
113+ ProcessMap processMap;
114+
115+ DWORD processIds[1024 ];
116+ DWORD processIdsSize;
117+ EnumProcesses (processIds, sizeof (processIds), &processIdsSize);
118+
119+ auto processIdsFound = processIdsSize / sizeof (DWORD);
120+ for (unsigned idx = 0 ; idx < processIdsFound; idx++)
121+ {
122+ auto processId = processIds[idx];
123+ if (processId == 0 )
124+ {
125+ continue ;
126+ }
127+
128+ auto hProcess = ::OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0 , processId);
129+ if (!hProcess)
130+ {
131+ continue ;
132+ }
133+
134+ CHAR pProcessName[MAX_PATH] = " NOT_FOUND" ;
135+ GetModuleBaseName (hProcess, 0 , pProcessName, sizeof (pProcessName) / sizeof (CHAR));
136+
137+ CloseHandle (hProcess);
138+
139+ processMap[processId] = pProcessName;
140+ }
141+
142+ return processMap;
143+ }
110144}
0 commit comments