#Why this matters
Static decompilation works best when all code and strings sit cleanly in .text and .rodata. Real programs and malware frequently build strings on the stack, decrypt configuration blocks on the heap, or unpack entire executables in memory at runtime.
Dynamic analysis observes the process while it runs inside a controlled environment. Instead of manually simulating twenty rounds of an XOR or RC4 loop on paper, you let the CPU run the decryption loop, pause immediately afterward, and read the plaintext directly from memory.
#Fast triage with ltrace and strace
Before opening a full interactive debugger, check what the binary asks the OS and standard libraries to do. On Linux, ltrace hooks calls across the Procedure Linkage Table (PLT) to shared libraries such as libc.so.6, while strace logs kernel system calls (openat, read, connect) via ptrace.
$ printf "test_key_123\n" | ltrace ./license_check
fgets("test_key_123\n", 64, 0x7f9a1c41a8e0) = 0x7ffd8a2b1010
strlen("test_key_123") = 12
strcmp("test_key_123", "S4mSU-2026-KEY") = 32
puts("Invalid license") = 16
+++ exited (status 1) +++In four lines, ltrace reveals the expected string length and comparison without touching assembly. Remember one boundary: ltrace only sees calls through dynamic linking. If a binary is statically linked (-static) or performs inline string comparisons without calling strcmp, ltrace prints nothing for those internal checks, and you must move to strace or a debugger.
#Debugging Linux binaries with GDB
When you open a Position-Independent Executable (PIE) in Ghidra, addresses often look like 0x1011a9 (relative to base 0x100000 or 0x0). At runtime, the OS loader maps PIE code at a virtual base address. By default, GDB disables ASLR (set disable-randomization on), mapping a 64-bit PIE ELF at a predictable base such as 0x555555554000. Always check info proc mappings (or vmmap in GEF/pwndbg) once started (starti), then add the runtime base to the file offset before setting breakpoints.
Breakpoints come in three forms:
- Software breakpoints (
b *addr): GDB writes0xCC(INT3) over the first byte of the instruction. Unlimited in number, but detectable by self-checksumming code. - Hardware breakpoints (
hb *addr): Uses the CPU's four debug registers (DR0toDR3on x86/x64). Leaves code bytes untouched, making them ideal when integrity checks scan.text. - Watchpoints (
watch *addr): Pauses whenever a specific memory word is modified, useful for catching the exact instruction that writes a decrypted byte to the heap.
Once paused, step deliberately: use ni (next instruction) to step over library calls like printf, si (step instruction) to step into a custom function, and finish to run until the current function returns. Inspect state with i r (info registers), x/16gx $rsp (16 64-bit hex words on the stack), or x/s $rdi (null-terminated string pointed to by RDI).
#Debugging Windows binaries with x64dbg
On Windows, x64dbg (for 64-bit PE files, alongside x32dbg for 32-bit) provides a graphical view with five synchronized panes: CPU disassembly, Registers, Stack, Memory Dump, and Memory Map.
| Task | GDB command | x64dbg action or command |
|---|---|---|
| Break at address or API | b *0x5555555551a9 or b strcmp |
bp VirtualAlloc in command bar (F2 in disassembly) |
| Hardware breakpoint | hb *addr |
bph addr, x (or Breakpoint, Hardware in context menu) |
| Step over / Step into | ni / si |
F8 / F7 |
| Run / Execute till return | c / finish |
F9 / Ctrl+F9 |
| View pointer contents | x/s $rdi or x/32bx $rax |
Right-click register, select Follow in Dump |
Remember the calling convention shift: Windows x64 passes the first four integer or pointer arguments in RCX, RDX, R8, and R9, with the return value in RAX. To dump a runtime-unpacked PE from memory in x64dbg, set bp VirtualAlloc, run (F9), press Ctrl+F9 to execute until VirtualAlloc returns, follow RAX in the Dump pane, set a write/execute breakpoint or step until the decryption loop finishes, and save the clean memory region via the Memory Map tab.
#Recognising and handling anti-debugging
Binaries built for copy protection or malware evasion often check whether a debugger is attached before revealing their real behaviour:
- Linux
ptraceself-attach: A process callsptrace(PTRACE_TRACEME, 0, 1, 0). Because a process can have only one tracer at a time,ptracereturns-1under GDB. - Linux
/proc/self/status: ReadingTracerPid:reveals0normally and a non-zero debugger PID when traced. - Windows
IsDebuggerPresent(): Reads theBeingDebuggedbyte inside the Process Environment Block (PEB).NtQueryInformationProcess(ProcessDebugPort) performs a kernel-backed check. - Timing checks: Comparing two
rdtsctimestamps detects slow manual single-stepping.
In an authorised lab, you can bypass a ptrace or IsDebuggerPresent check non-destructively by breaking right after the call, setting $rax = 0 (or flipping the Zero Flag ZF before the conditional jump), or clearing the PEB BeingDebugged flag in x64dbg.
#Common mistakes
- Forgetting the PIE/ASLR base offset: Typing a Ghidra relative offset like
0x1234directly intob *0x1234in GDB fails because the executable is mapped at0x555555554000 + 0x1234. - Stepping into system libraries with
si: UsingsionprintforHeapAllocdrops you deep intolibcorntdll; usenito step over standard APIs orfinish(Ctrl+F9) to climb back out. - Placing
0xCCbreakpoints inside self-checked code: Software breakpoints modify.textbytes and fail checksum checks or cause crashes if placed mid-instruction; use hardware breakpoints (hb/bph) instead. - Trusting
ltraceon static binaries: Assuming a binary performs no checks becauseltraceshows zero calls when the binary was statically linked or uses rawsyscallinstructions.
#Summary
Dynamic analysis pairs lightweight tracers (ltrace, strace) with interactive debuggers (GDB, x64dbg) to inspect live registers, stack frames, and heap buffers at runtime. Accounting for PIE base addresses, choosing between software, hardware, and watchpoint breakpoints, and following API allocations lets you capture unpacked or decrypted payloads without reversing every instruction statically. When anti-debugging checks appear in lab binaries, stepping past the check and adjusting the return register or flag keeps analysis moving safely inside an isolated VM.