public void OnBreakpoint(DebuggerThread Thread, uint Address, uint Code, bool FirstChance) { frm.DebugLog(string.Format("Breakpoint hit at 0x{0:X8} with code {1:X8}", Address, Code)); var Module = frm.DebuggerInst.ResolveModule(Address); if (Module != null) { frm.DebugBreakpoint(Module, Address); } }
public static ExceptionHandledQuery GetExceptionHandledQuery(DebuggerThread Context, DataProcessor Data) { ExceptionHandledQuery Query = new ExceptionHandledQuery(); Query.ReponseAddr = new IntPtr(Data.Pop()); Query.ExceptionAddress = Data.Pop(); Query.ExceptionCode = Data.Pop(); Query.ParameterCount = Data.Pop(); Query.ParameterBase = new IntPtr(Data.Pop()); return(Query); }
// Based on DebugProcess public DebuggerProcess() { Handle = IntPtr.Zero; ProcessID = 0; ImageBase = IntPtr.Zero; Path = ""; Modules = new List <DebuggerModule>(); Threads = new List <DebuggerThread>(); MainThread = null; }
public static ExceptionHandledQuery GetExceptionHandledQuery(DebuggerThread Context, uint[] Data) { ExceptionHandledQuery Query = new ExceptionHandledQuery(); Query.ReponseAddr = new IntPtr(Data[0]); Query.ExceptionAddress = Data[1]; Query.ExceptionCode = Data[2]; Query.ParameterCount = Data[3]; Query.ParameterBase = new IntPtr(Data[4]); return(Query); }
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 void DebugSingleStep(DebuggerThread Thread) { Invoke(new MethodInvoker(delegate() { if (applyBreakpointOnStep != null) { var offset = applyBreakpointOnStep.Offset; Thread.OwningProcess.WriteMemoryBlock(new IntPtr(offset), applyBreakpointOnStep.Patched); applyBreakpointOnStep = null; } // otherwise, expose to ui? })); }
public static FileClosed GetFileClosedReport(DebuggerThread Context, uint[] Data) { // TODO: Restructure this library uint InvalidHandle = (uint)VsChromium.Core.Win32.Handles.NativeMethods.INVALID_HANDLE_VALUE; // Skip invalid file handles if (Data[0] == InvalidHandle) { return(null); } FileClosed Report = new FileClosed(); Report.Handle = new IntPtr(Data[0]); return(Report); }
public static HLECache GetHLECacheReport(DebuggerThread Context, DataProcessor Data) { HLECache Report = new HLECache(); var Type = (StringType)Data.Pop(); if (Type != StringType.CHAR) { throw new Exception("GetHLECacheReport expects a string message"); } var Length = Data.Pop();; var MessagePtr = new IntPtr(Data.Pop()); Report.FileName = Context.OwningProcess.ReadString(MessagePtr, Length); return(Report); }
public static HLECache GetHLECacheReport(DebuggerThread Context, uint[] Data) { HLECache Report = new HLECache(); StringType Type = (StringType)Data[0]; if (Type != StringType.CHAR) { throw new Exception("GetHLECacheReport expects a string message"); } uint Length = Data[1]; IntPtr MessagePtr = new IntPtr(Data[2]); Report.FileName = Context.OwningProcess.ReadString(MessagePtr, Length); return(Report); }
public static DebuggerNewTarget GetDebuggerNewTargetReport(DebuggerThread Context, DataProcessor Data) { var Report = new DebuggerNewTarget(); StringType Type = (StringType)Data.Pop(); if (Type != StringType.CHAR) { throw new Exception("GetDebuggerInitReport expects a string message"); } uint Length = Data.Pop(); IntPtr MessagePtr = new IntPtr(Data.Pop()); Report.CommandLine = Context.OwningProcess.ReadString(MessagePtr, Length); return(Report); }
public static KernelPatch GetKernelPatchReport(DebuggerThread Context, uint[] Data) { KernelPatch Report = new KernelPatch(); StringType Type = (StringType)Data[0]; if (Type != StringType.CHAR) { throw new Exception("GetKernelPatchReport expects a string message"); } uint Length = Data[1]; IntPtr MessagePtr = new IntPtr(Data[2]); Report.Name = Context.OwningProcess.ReadString(MessagePtr, Length); Report.Address = new IntPtr(Data[3]); return(Report); }
public static KernelPatch GetKernelPatchReport(DebuggerThread Context, DataProcessor Data) { KernelPatch Report = new KernelPatch(); var Type = (StringType)Data.Pop(); if (Type != StringType.CHAR) { throw new Exception("GetKernelPatchReport expects a string message"); } var Length = Data.Pop(); var MessagePtr = new IntPtr(Data.Pop()); Report.Name = Context.OwningProcess.ReadString(MessagePtr, Length); Report.Address = new IntPtr(Data.Pop()); return(Report); }
public static DebuggerInit GetDebuggerInitReport(DebuggerThread Context, uint[] Data) { DebuggerInit Report = new DebuggerInit(); // Data[0] is free StringType Type = (StringType)Data[1]; if (Type != StringType.CHAR) { throw new Exception("GetDebuggerInitReport expects a string message"); } uint Length = Data[2]; IntPtr MessagePtr = new IntPtr(Data[3]); Report.Title = Context.OwningProcess.ReadString(MessagePtr, Length); return(Report); }
public static FileOpened GetFileOpenedReport(DebuggerThread Context, DataProcessor Data) { FileOpened Report = new FileOpened(); Report.Handle = new IntPtr(Data.Pop()); var Type = (StringType)Data.Pop(); if (Type != StringType.WCHAR) { throw new Exception("GetFileOpenedReport expects a widestring message"); } var Length = Data.Pop(); var MessagePtr = new IntPtr(Data.Pop()); Report.FileName = Context.OwningProcess.ReadWString(MessagePtr, Length); Report.Succeeded = Data.Pop() != 0; return(Report); }
public static FileOpened GetFileOpenedReport(DebuggerThread Context, uint[] Data) { FileOpened Report = new FileOpened(); Report.Handle = new IntPtr(Data[0]); StringType Type = (StringType)Data[1]; if (Type != StringType.WCHAR) { throw new Exception("GetFileOpenedReport expects a widestring message"); } uint Length = Data[2]; IntPtr MessagePtr = new IntPtr(Data[3]); Report.FileName = Context.OwningProcess.ReadWString(MessagePtr, Length); Report.Succeeded = Data[4] != 0; return(Report); }
public void OnThreadExit(DebuggerThread Thread, uint ExitCode) { frm.DebugLog(string.Format("Thread exited {0} ({1})", Thread.ThreadID, NtStatus.PrettyPrint(ExitCode))); frm.DebugThreads.Remove(Thread); }
private void PopulateThreadList(ToolStripComboBox cbItems, DebuggerThread FocusThread) { cbItems.Items.Clear(); uint AutoThreadId = DebugThreads[0].OwningProcess.MainThread.ThreadID; if (FocusThread != null) { AutoThreadId = FocusThread.ThreadID; } int AutoIndex = 0; foreach (DebuggerThread Thread in DebugThreads) { bool IsMainThread = (Thread.Handle == Thread.OwningProcess.MainThread.Handle); bool IsFocusThread = (FocusThread != null) && (Thread.Handle == FocusThread.Handle); string PrefixStr = ""; // Threads with focus are marked differently if (IsFocusThread) { PrefixStr = "* "; } // Main threads always override any existing prefix if (IsMainThread) { PrefixStr = "> "; } string DisplayStr = string.Format("{0}[{1}] ", PrefixStr, (uint)Thread.Handle); // Resolve thread name if (IsMainThread) { DisplayStr += "Main Thread"; } else if (Thread.DebugName != null) { DisplayStr += Thread.DebugName; } else { string fn = Path.GetFileName(Thread.OwningProcess.Path); DisplayStr += string.Format("{0}!{1:X8}", fn, (uint)Thread.StartAddress); } // Check if the thread is already suspended if (Thread.WasSuspended) { DisplayStr += " (suspended)"; } if (AutoThreadId == Thread.ThreadID) { AutoIndex = cbItems.Items.Count; } cbItems.Items.Add(DisplayStr); } // Auto-select this thread cbItems.SelectedIndex = AutoIndex; }
public void OnThreadCreate(DebuggerThread Thread) { frm.DebugLog(string.Format("Thread created {0}", Thread.ThreadID)); frm.DebugThreads.Add(Thread); }
private void DebugBreakpoint(DebuggerThread Thread, DebuggerModule Module, uint Address) { Invoke(new MethodInvoker(delegate() { SuspendedOnBp = true; bool auto_resume = true; if (cbBreakpointAll.Checked == false) { // Ignore all submodule breakpoints // (effectively triggers from Cxbx.exe and default.xbe) if (cbBreakpointCxbx.Checked) { auto_resume = (!Module.Core); } } if (auto_resume) { Resume(); } else { DebuggerInst.Trace(); var stackFrame = Thread.CallstackCache.StackFrames[0]; var currentIp = stackFrame.eip; currentIp -= 1; // Size of the 0xcc instruction Thread.ModifyPC(currentIp); var patch = patchMan.DataPatches.FirstOrDefault(x => x.Offset == currentIp); if (patch == null) { throw new Exception($"Failed to find breakpoint patch for address {currentIp}"); } if (patch.Original == null) { throw new Exception($"Original memory is missing for breakpoint patch at address {currentIp}"); } // write back the single byte // note: original should not also be a breakpoint - or this will endlessly loop Thread.OwningProcess.WriteMemoryBlock(new IntPtr(currentIp), patch.Original); // Sets a single-step trap Thread.SetSingleStepTrap(true); // Save this patch instance - note how this isn's thread safe at all applyBreakpointOnStep = patch; if (userScript.IsValid) { MainProcess.ContextThread = Thread; userScript.OnBreakpoint(new DebuggerTest(this), currentIp); } Resume(); } })); }
public void OnThreadNamed(DebuggerThread Thread) { frm.DebugLog($"Thread {Thread.ThreadID} named {Thread.DebugName}"); }
public void OnThreadExit(DebuggerThread Thread, uint ExitCode) { MainProcess.Threads.Remove(Thread); }
public void OnThreadExit(DebuggerThread Thread, uint ExitCode) { frm.DebugLog($"Thread exited {Thread.ThreadID} ({NtStatus.PrettyPrint(ExitCode)})"); frm.DebugThreads.Remove(Thread); }
public void OnThreadCreate(DebuggerThread Thread) { // todo: check out base address of this? }
public void OnThreadNamed(DebuggerThread Thread) { frm.DebugLog(string.Format("Thread {0} named {1}", Thread.ThreadID, Thread.DebugName)); }
public void OnSingleStep(DebuggerThread Thread) { frm.DebugSingleStep(Thread); }
public void OnThreadExit(DebuggerThread Thread, uint ExitCode) { // todo: check out base address of this? }
public void OnThreadNamed(DebuggerThread Thread) { // Unused }
public void OnThreadCreate(DebuggerThread Thread) { MainProcess.Threads.Add(Thread); }
public void OnThreadCreate(DebuggerThread Thread) { frm.DebugLog($"Thread created {Thread.ThreadID}"); frm.DebugThreads.Add(Thread); }