private void HandleCreateProcess(WinDebug.DEBUG_EVENT DebugEvent) { var DebugInfo = DebugEvent.CreateProcessInfo; var Process = new DebuggerProcess(); Process.Core = true; Process.Handle = DebugInfo.hProcess; Process.ProcessID = WinLowLevel.GetProcessId(Process.Handle); Process.Path = ResolveProcessPath(DebugInfo.hFile); // Skip over allocated Xbox memory Process.ImageBase = DebugInfo.lpBaseOfImage + VM_PLACEHOLDER_SIZE; var MainThread = new DebuggerThread(Process); MainThread.Handle = DebugInfo.hThread; MainThread.ThreadID = NativeMethods.GetThreadId(DebugInfo.hThread); MainThread.ThreadBase = DebugInfo.lpThreadLocalBase; // Setup as the main thread // TODO Check that we need to treat this as a special case Process.MainThread = MainThread; DebugInstance = new DebuggerInstance(Process); RegisterEventInterfaces(DebugInstance); foreach (IDebuggerProcessEvents Event in ProcessEvents) { Event.OnProcessCreate(Process); } foreach (IDebuggerThreadEvents Event in ThreadEvents) { Event.OnThreadCreate(MainThread); } var XboxModule = new DebuggerModule(); XboxModule.Path = Target; XboxModule.ImageBase = DebugInfo.lpBaseOfImage; XboxModule.Core = true; foreach (IDebuggerModuleEvents Event in ModuleEvents) { Event.OnModuleLoaded(XboxModule); } }
private string ResolveProcessPath(IntPtr FileHandle) { string path = ""; const int bufSize = 1024; var strPtr = Marshal.AllocHGlobal(bufSize); uint length = WinLowLevel.GetFinalPathNameByHandleW ( FileHandle, strPtr, bufSize, 0 ); if (length != 0) { path = Marshal.PtrToStringUni(strPtr, (int)length); path = path.TrimStart('\\', '?'); } Marshal.FreeHGlobal(strPtr); return(path); }