/// <summary> /// Sets a BreakPoint at a given address in the debugged process. /// </summary> /// <param name="address">The address at which a BreakPoint should be placed.</param> /// <returns></returns> public NIDebugger SetBreakpoint(uint address) { if (breakpoints.Keys.Contains(address) == false) { NIBreakPoint bp = new NIBreakPoint() { bpAddress = address}; byte[] origBytes; ReadData(address, 2, out origBytes); bp.originalBytes = origBytes; breakpoints.Add(address, bp); WriteData(address, BREAKPOINT); } return this; }
private void bw_Continue(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; while (1==1) { if (debuggedProcess.HasExited) { return; } pauseAllThreads(); //Console.WriteLine("threads paused"); foreach (uint address in breakpoints.Keys) { foreach (ProcessThread pThread in debuggedProcess.Threads) { if (getContext(pThread.Id).Eip == address) { Console.WriteLine("We hit a breakpoint: " + address.ToString("X")); lastBreakpoint = breakpoints[address]; lastBreakpoint.threadId = (uint)pThread.Id; getContext(pThread.Id); e.Cancel = true; mre.Set(); return; } } } resumeAllThreads(); //Console.WriteLine("threads resumed"); } }