public DebuggerInstance(DebuggerProcess InitialProcess) { Processes = new List <DebuggerProcess>(); Processes.Add(InitialProcess); MainProcess = InitialProcess; CurrentThread = InitialProcess.MainThread; }
// Based on DebugThread public DebuggerThread(DebuggerProcess Owner) { OwningProcess = Owner; Handle = IntPtr.Zero; ThreadID = 0; StartAddress = IntPtr.Zero; ThreadBase = IntPtr.Zero; }
private void Read(DebuggerProcess OwningProcess, Patch PatchItem) { int Size = PatchSize(ref PatchItem); if (Size > 0) { byte[] Current = OwningProcess.ReadMemoryBlock(new IntPtr(PatchItem.Offset), (uint)Size); PatchItem.Original = Current; } }
private void Apply(DebuggerProcess OwningProcess, Patch PatchItem) { int Size = PatchTypeLength(PatchItem.DisplayAs); // Repatch if (PatchItem.Original?.Length == Size && PatchItem.Patched?.Length == Size) { OwningProcess.WriteMemoryBlock(new IntPtr(PatchItem.Offset), PatchItem.Patched); } }
public string Read(DebuggerProcess OwningProcess, Patch PatchItem) { int Size = PatchSize(PatchItem); if (Size == 0) { return(""); } byte[] Current = OwningProcess.ReadMemoryBlock(new IntPtr(PatchItem.Offset), (uint)Size); return(Format(PatchItem.DisplayAs, Current)); }
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 Setup(DebuggerProcess OwningProcess, Patch PatchItem) { if (PatchItem.Original == null) { int Size = PatchSize(ref PatchItem); if (Size > 0) { byte[] Current = OwningProcess.ReadMemoryBlock(new IntPtr(PatchItem.Offset), (uint)Size); if (Current != null) { PatchItem.Original = Current; Apply(OwningProcess, PatchItem); } } } }
public void OnProcessExit(DebuggerProcess Process, uint ExitCode) { int remainingThreads = Process.Threads.Count; frm.DebugLog(string.Format("Process exited {0} ({1})", Process.ProcessID, NtStatus.PrettyPrint(ExitCode))); frm.DebugLog(string.Format("{0} child thread(s) remain open", remainingThreads)); frm.DebugModules.Clear(); // Ask to close if the process was forced to exit if (ExitCode == 1) { if (frm.DebugAsk("The debugger was detached from the host\n\nDo you want to close the debugger?")) { frm.Close(); } } }
/// <summary> /// Re-read original bytes of all data patches /// </summary> /// <param name="OwningProcess"></param> public void RefreshDataPatches(DebuggerProcess OwningProcess) { Data.ForEach(x => Read(OwningProcess, x)); }
public void OnProcessExit(DebuggerProcess Process, uint ExitCode) { }
public void OnProcessCreate(DebuggerProcess Process) { // TODO: apply pending patches }
public bool Write(DebuggerProcess OwningProcess, Patch PatchItem, string NewValue) { IntPtr PatchAddr = new IntPtr(PatchItem.Offset); switch (PatchItem.DisplayAs) { case PatchType.Byte: { byte Value = 0; if (Common.ReadByte(NewValue, ref Value)) { OwningProcess.WriteMemory(PatchAddr, Value); return(true); } break; } case PatchType.Short: { short Value; if (short.TryParse(NewValue, out Value)) { OwningProcess.WriteMemory(PatchAddr, Value); return(true); } break; } case PatchType.UShort: { ushort Value; if (ushort.TryParse(NewValue, out Value)) { OwningProcess.WriteMemory(PatchAddr, Value); return(true); } break; } case PatchType.Int: { int Value; if (int.TryParse(NewValue, out Value)) { OwningProcess.WriteMemory(PatchAddr, Value); return(true); } break; } case PatchType.UInt: { uint Value; if (uint.TryParse(NewValue, out Value)) { OwningProcess.WriteMemory(PatchAddr, Value); return(true); } break; } case PatchType.Float: { float Value; if (float.TryParse(NewValue, out Value)) { OwningProcess.WriteMemory(PatchAddr, Value); return(true); } break; } case PatchType.Array: { List <byte> ParsedBytes = new List <byte>(); string[] Items = NewValue.Split(new char[] { ' ' }); foreach (string Item in Items) { byte Value = 0; if (Common.ReadByte(Item, ref Value)) { ParsedBytes.Add(Value); } } if (ParsedBytes.Count == PatchItem.Patched.Length) { OwningProcess.WriteMemoryBlock(PatchAddr, ParsedBytes.ToArray()); return(true); } break; } } return(false); }
public void OnProcessCreate(DebuggerProcess Process) { AddressLookup.Add((uint)Process.ImageBase); AddressLookup.Sort(); }
/// <summary> /// Re-read original bytes and patch, if possible /// </summary> /// <param name="OwningProcess"></param> public void UpdateDataPatches(DebuggerProcess OwningProcess) { Data.ForEach(x => Read(OwningProcess, x)); Data.ForEach(x => Apply(OwningProcess, x)); }
/// <summary> /// Read original bytes and patch, if possible /// </summary> /// <param name="OwningProcess"></param> public void SetupDataPatches(DebuggerProcess OwningProcess) { Data.ForEach(x => Setup(OwningProcess, x)); }
public void OnProcessCreate(DebuggerProcess Process) { frm.DebugModules.Add(Process); frm.MainProcess = Process; }
public void OnProcessExit(DebuggerProcess Process, uint ExitCode) { AddressLookup.Remove((uint)Process.ImageBase); }