x64dbg conditional breakpoints and hardware breakpoints practical quick review: don’t set breakpoints too wide

The usage and trade-offs of conditional breakpoints/hardware breakpoints/memory breakpoints, with a comparison table of typical scenarios and several pitfalls that are easy to avoid.

The biggest waste of time during debugging is "setting breakpoints too wide". This article will record the usage and trade-offs of conditional breakpoints, hardware breakpoints, and memory breakpoints.

1. Problems with common breakpoints

above and below large functions bp, it takes dozens of hits to reach the target branch. Three more precise methods: conditional breakpoints, hardware breakpoints, and memory breakpoints.

2. Conditional breakpoints

Directly download x64dbg from the command bar:

text
bp 0x401000, "eax==0x1234"
bp 0x401000, "[[esp+4]]==0x1000"
  • The condition is evaluated on each hit. Writing too complex will significantly slow down the process.
  • Don’t use string comparison strcmp, changing to comparing pointers or lengths is faster
  • Script variables for counting requirements:
text
$count = 0
bp 0x401000, "$count++; $count==5"

It is broken only after the 5th hit, and the front is automatically released.

3. Hardware breakpoint (do not move instruction byte)

text
bph 0x401000, r        ; 读
bph 0x401000, w        ; 写
bph 0x401000, x        ; 执行

advantage:

  • Do not modify the original bytes and avoid CRC/byte comparison self-checking
  • Only 4 debug registers are available, up to 4 simultaneously
  • Suitable for questions such as "Who changed this value" and "Who read this global situation"

Disadvantages: It is easy to miss hits when switching between multiple threads, and it is not sensitive to cross-page access.

4. Memory breakpoints

Coarse-grained, but covering the entire page:

text
bpm 0x7FF000, r
bpm 0x7FF000, w
  • Used for "When will this decrypted code be executed?"
  • After hitting, confirm whether it falls on the target instruction. The page-level breakpoint will also hit the adjacent code.
  • It may not be triggered when the memory is modified in kernel mode, and single-stepping is required.

5. Typical scene comparison

needFirst choice
Calls that only care about a certain parameter valueconditional breakpoint
Find out who modified a global variableHardware write breakpoint
After shell decryption, jump to OEPHardware execution breakpoints
Who will execute first in a large decryption area?memory breakpoint
Nth time in loopConditional breakpoint + count variable

6. Several pits

  1. If the conditional expression is written incorrectly, no error will be reported, but it will never hit the target; first use the constant true condition to verify the syntax
  2. Hardware breakpoints are maintained by thread and will be overwritten by other threads under multi-threading. Be careful when switching threads.
  3. If the breakpoint is left at the hooked address, it will fight with the hook. Make sure there is no inline hook first.
  4. The address will change when ASLR is turned on. Use "module base address + RVA", or break at the entrance and calculate again.
bash
# 调试时关掉目标进程的 ASLR
setdllcharacteristics -d sample.exe

7. Efficiency Suggestions

  • First bp Go to the module entrance to get the base address, and then use "base address + RVA" to set a precise breakpoint.
  • Log breakpoint (log command) saves time than interrupts, especially when observing in batches
  • For complex logic, write scripts first, which is much faster than writing by hand.

The above are debugger usage tips and are only used for local sample analysis.

Vegetarian avatar
素菜Lv3UID 215339
Are there similar technical documents that can be summarized into a skill for AI to learn? Otherwise, it feels like you have to try one method after another every time you crack it.
kevin's avatar
kevinLv1UID 725307
support support
Mumu's avatar
木木Lv1UID 641709
777777777777777

please Log in or Register an account Participate in discussions, download exclusive add-ons or unlock level posts.