#Why this matters
When an incident responder encounters an unfamiliar executable or a reverse engineer opens a compiled CTF binary, running the program blindly is either unsafe or uninformative. Static analysis lets you inspect a binary's capabilities, control flow, and data structures without executing a single instruction.
In earlier lessons, you learned how ELF and PE headers organize .text, .rodata, and import tables, and how CPU registers carry function arguments. Tools such as Ghidra and IDA combine those structural clues with control-flow graphing and decompilation so you can read complex binaries in minutes rather than decoding hundreds of raw opcodes by hand.
#Disassembly strategies and decompilation
Disassemblers turn raw bytes from code sections into assembly mnemonics, but how they walk those bytes matters when data sits inside code sections (such as jump tables or alignment padding).
| Technique | How it works | Strength | Limitation |
|---|---|---|---|
Linear sweep (objdump -d) |
Decodes .text sequentially from start to end |
Fast, zero setup | Misinterprets inline data bytes as instructions |
| Recursive descent (IDA, Ghidra) | Follows calls, branches, and known entry points | Separates code from data and builds a CFG | Misses targets computed only at runtime (indirect jumps) |
| Decompilation | Lifts assembly into IR (Ghidra P-Code), recovers SSA variables, emits C | Condenses register juggling into readable expressions | Can hide subtle size, signedness, or stack-layout details |
Modern decompilers do not translate assembly directly to C line by line. Ghidra lifts each machine instruction into P-Code (a register-transfer intermediate language), runs data-flow and type-propagation passes, collapses stack offsets into local variables, and emits structured if/while blocks. IDA Pro and IDA Free follow a similar multi-stage pipeline with microcode (though IDA Free restricts some features compared to the commercial edition).
- Triagefile, strings, imports
- LoadAuto-analyze ELF or PE in Ghidra or IDA
- AnchorFind main, imports, and string XREFs
- RefineRename symbols, retype args, apply structs
- VerifyCross-check pseudocode against assembly
#Navigating stripped binaries with XREFs and signatures
Production binaries and reverse-engineering challenges are usually compiled with strip, which deletes the .symtab symbol table and DWARF debug info. Function names like check_license disappear and become FUN_001011a9 in Ghidra or sub_1400011A9 in IDA. However, three anchors survive stripping:
- Dynamic imports: Functions resolved from shared libraries (
libc.so.6,kernel32.dll) remain named in.dynsym/ PLT or the PE Import Address Table (IAT). - String literals: Messages such as
"Invalid key"or"Usage: %s <token>"stay in.rodataor.rdata. - Startup stubs: The binary's entry point (
_start) still handsmainto the C runtime. On classic System V x86-64 Linux binaries,_startpasses the address ofmaininRDI(the first argument) to__libc_start_main.
Once you open a binary, use the Strings window or Imports tree to pick a meaningful anchor, then follow Cross-References (XREFs) to see every function that references it. For statically linked binaries where printf or strlen were compiled straight into .text, enable Function ID (Ghidra) or FLIRT signatures (IDA) to label standard library functions automatically instead of reversing memcpy by hand.
#Reading and refining decompiled output
Out of the box, a decompiler guesses generic names (param_1, local_28, uVar1) and default integer widths. Reading raw decompiler output without cleaning it up slows you down on non-trivial functions.
Consider a stripped x86-64 ELF binary vault_check inspected in Ghidra after following an XREF from "Access granted\n":
undefined8 FUN_001011a9(long param_1)
{
size_t sVar1;
uint local_14;
sVar1 = strlen((char *)param_1);
if (sVar1 == 8) {
for (local_14 = 0; (int)local_14 < 8; local_14 = local_14 + 1) {
if ((byte)(*(char *)(param_1 + (int)local_14) ^ 0x2a) != DAT_00102010[local_14]) {
return 0;
}
}
return 1;
}
return 0;
}Renaming FUN_001011a9 to verify_token, param_1 to user_input, sVar1 to len, local_14 to idx, and DAT_00102010 to expected_xor_bytes (with type byte[8]) immediately clarifies the contract: the function requires an 8-byte string where each character XORed with 0x2a matches the 8 bytes stored in .rodata at 0x102010.
When structures are passed by pointer, defining a struct in Ghidra's Data Type Manager (or IDA's Structures view) removes raw offset arithmetic. If *(int *)(param_1 + 0x10) appears across five functions, creating a Session struct with field role_id at offset 0x10 turns every reference into session->role_id.
$ objdump -s -j .rodata ./vault_check | head -n 6
./vault_check: file format elf64-x86-64
Contents of section .rodata:
2000 01000200 41636365 73732067 72616e74 ....Access grant
2010 791e4779 7f751a1b 00 y.Gy.u...With the 8 bytes at 0x2010 (79 1e 47 79 7f 75 1a 1b), XORing each byte with 0x2a recovers the exact 8-character password (S4mSU_01) directly from static inspection.
#Cross-checking pseudocode against assembly
Decompilers make mistakes when binary optimizations violate simple C assumptions. Always check the disassembly view when something looks strange:
- Signed vs unsigned comparisons: Assembly differentiates
JL(signed less-than) fromJB(unsigned below). If a decompiler defaults a variable tointinstead ofuint, a large positive length check can look negative. - Wrong function signatures: Calling-convention mismatches (System V
RDI, RSI, RDX, RCXvs Windows x64RCX, RDX, R8, R9) or variadic functions (printf,ioctl) can cause the decompiler to hide an argument register or invent extra parameters. - Inlined helpers and tail calls: Compilers at
-O2or-O3often replacereturn helper(x);with a directJMP helper(tail call) or merge two small functions, making the call graph look flatter than the original source.
#Common mistakes
- Trusting decompiled C blindly: Treating pseudocode casts, array bounds, or dead-code removal as ground truth without verifying the underlying
cmp,test, ormovzx/movsxinstructions. - Starting at offset zero: Reading every
FUN_*sequentially from the top of.textinstead of pivoting from_start, imported APIs, and string XREFs. - Skipping annotations: Leaving dozens of functions named
FUN_00401200and variables namedlocal_48makes multi-function call chains impossible to track. - Ignoring architecture and ABI settings: Analyzing a bare-metal firmware blob or Windows DLL with the wrong calling convention or base address breaks every cross-reference and pointer cast.
#Summary
Static analysis combines binary headers, recursive-descent disassembly, cross-references, and intermediate-representation decompilation to explain program behavior without executing untrusted code. Anchoring on _start, dynamic imports, and .rodata strings lets you bypass missing symbols in stripped binaries, while renaming variables and defining structs turns raw pointer math into readable logic. Always validate critical checks, types, and loop bounds against the assembly listing before drawing conclusions.