private static void SetDebugRegisters(HookRegister register, uint hookLocation, ref ThreadContext ct, bool remove) { if (remove) { uint flagBit = 0; switch (register) { case HookRegister.DR0: flagBit = 1 << 0; ct.Dr0 = 0; break; case HookRegister.DR1: flagBit = 1 << 2; ct.Dr1 = 0; break; case HookRegister.DR2: flagBit = 1 << 4; ct.Dr2 = 0; break; case HookRegister.DR3: flagBit = 1 << 6; ct.Dr3 = 0; break; } ct.Dr7 &= ~flagBit; } else { switch (register) { case HookRegister.DR0: ct.Dr0 = (uint)hookLocation; ct.Dr7 |= 1 << 0; break; case HookRegister.DR1: ct.Dr1 = (uint)hookLocation; ct.Dr7 |= 1 << 2; break; case HookRegister.DR2: ct.Dr2 = (uint)hookLocation; ct.Dr7 |= 1 << 4; break; case HookRegister.DR3: ct.Dr3 = (uint)hookLocation; ct.Dr7 |= 1 << 6; break; } ct.Dr6 = 0; } }
private void Method_SelectedIndexChanged(object sender, EventArgs e) { if (this.Method.SelectedIndex == 1) { AddressLabel.Text = R._("書き込む"); AddressLabel.Show(); Address.Show(); HookRegisterLabel.Hide(); HookRegister.Hide(); FREEAREALabel.Hide(); FREEAREA.Hide(); PatchMakerButton.Show(); DebugSymbol.Show(); DebugSymbolComboBox.Show(); ELFLabel.Hide(); ELFComboBox.Hide(); Address.Value = FREEAREA.Value; } else if (this.Method.SelectedIndex == 2) { AddressLabel.Text = R._("フックするアドレス"); AddressLabel.Show(); Address.Show(); HookRegisterLabel.Show(); HookRegister.Show(); FREEAREALabel.Show(); FREEAREA.Show(); PatchMakerButton.Show(); DebugSymbol.Show(); DebugSymbolComboBox.Show(); ELFLabel.Hide(); ELFComboBox.Hide(); Address.Value = 0; } else { AddressLabel.Hide(); Address.Hide(); HookRegisterLabel.Hide(); HookRegister.Hide(); FREEAREALabel.Hide(); FREEAREA.Hide(); PatchMakerButton.Hide(); DebugSymbol.Hide(); DebugSymbolComboBox.Hide(); ELFLabel.Show(); ELFComboBox.Show(); } }
public HardwareBreakpointHook(HookRegister register, uint hookLocation, HandleHookCallback callback) { var i = new HookItem { Callback = callback, Location = hookLocation, Register = register }; _hook = i; Hooks.Add(i); _hookCount++; // So basically, DR hooks work off "waiting for a debug event" basically. // In actuality we're waiting on an exception, but for the sake of wrapping a hook, // we'll do it in a separate thread. This means we need to ensure we close the thread (IsBackground) when the app closes // and ensure we only ever create *one* polling thread. if (_hookCount == 0 || _workerThread == null) { _workerThread = new Thread(() => InstallHardwareHook()); _workerThread.IsBackground = true; _workerThread.Start(); } SetThreadHook(i, false); }