MCPcopy Create free account
hub / github.com/apitrace/apitrace / attachDebugger

Function attachDebugger

inject/injector.cpp:255–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253
254
255static BOOL
256attachDebugger(DWORD dwProcessId)
257{
258 long lRet;
259
260 HKEY hKey;
261 lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", 0, KEY_READ, &hKey);
262 if (lRet != ERROR_SUCCESS) {
263 debugPrintf("inject: error: RegOpenKeyExA failed\n");
264 return FALSE;
265 }
266
267 char szDebugger[1024];
268 DWORD cbDebugger = sizeof szDebugger;
269 lRet = RegQueryValueExA(hKey, "Debugger", NULL, NULL, (BYTE *)szDebugger, &cbDebugger);
270
271 RegCloseKey(hKey);
272
273 if (lRet != ERROR_SUCCESS) {
274 if (lRet == ERROR_FILE_NOT_FOUND) {
275 debugPrintf("inject: error: no automatic debugger configured\n");
276 } else {
277 debugPrintf("inject: error: RegQueryValueExA failed (0x%08lx)\n", lRet);
278 }
279 return FALSE;
280 }
281
282 SECURITY_ATTRIBUTES sa = { sizeof sa, 0, TRUE };
283 HANDLE hEvent = CreateEvent(&sa, FALSE, FALSE, NULL);
284
285 char szDebuggerCommand[1024];
286 _snprintf(szDebuggerCommand, sizeof szDebuggerCommand, szDebugger,
287 dwProcessId, (DWORD)(UINT_PTR)hEvent, NULL);
288
289 debugPrintf("%s\n", szDebuggerCommand);
290
291 PROCESS_INFORMATION pi;
292 ZeroMemory(&pi, sizeof pi);
293 STARTUPINFOA si;
294 ZeroMemory(&si, sizeof si);
295 si.cb = sizeof si;
296
297 BOOL bRet = FALSE;
298 if (!CreateProcessA(
299 NULL,
300 szDebuggerCommand,
301 NULL, // process attributes
302 NULL, // thread attributes
303 TRUE, // inherit (event) handles
304 0,
305 NULL, // environment
306 NULL, // current directory
307 &si,
308 &pi)) {
309 debugPrintf("inject: error: failed to execute \"%s\" with 0x%08lx\n",
310 szDebuggerCommand,
311 GetLastError());
312 } else {

Callers 1

mainFunction · 0.85

Calls 1

debugPrintfFunction · 0.70

Tested by

no test coverage detected