Navigating Disassembly
Binary Analysis with Ghidra · Reverse Engineering track
8 min read
In this module
Reading Code Without Source
Ghidra is open and the binary is loaded. Now comes the actual work: reading x86 and ARM assembly in Ghidra's presentation, chasing cross-references, and building up a mental model of the program one function at a time.
Reading x86 Disassembly in Ghidra
Ghidra displays x86 disassembly in a format that combines the raw assembly with helpful annotations. A typical listing looks like this:
FUN_00401230:00401230 PUSH RBP00401231 MOV RBP,RSP00401234 SUB RSP,0x4000401238 MOV qword ptr [RBP + local_8],RDI0040123c MOV dword ptr [RBP + local_c],ESI00401240 LEA RAX,[RBP + local_48]00401244 MOV RDI,RAX00401247 CALL recv_wrapper0040124c TEST EAX,EAX0040124e JLE LAB_00401290Ghidra adds several helpful layers on top of the raw bytes:
- Function labels like
FUN_00401230mark function entry points. The auto-generated name tells you the address; you should rename it to something meaningful - Local variable references like
local_8andlocal_48replace raw stack offsets, making it easier to track which stack slot is being accessed - Call targets are resolved - instead of
CALL 0x00401100, you seeCALL recv_wrapper(or the actual library name for imported functions)
The same function can also be viewed as blocks in Window → Function Graph, which is the control flow graph from Control Flow Reconstruction drawn for you. The listing above ends on a conditional jump, so the graph splits there. The JLE is two bytes, which puts the fall-through block at 00401250; what happens after the split is illustrative:
Ghidra colours the two edges out of a conditional block differently (green for taken, red for fall-through by default). A loop shows up as an edge that climbs back to a block higher up the graph.
Reading ARM Disassembly in Ghidra
ARM disassembly in Ghidra follows the same principles but with ARM's different instruction format:
FUN_00010430:00010430 PUSH {R4,R5,LR}00010434 SUB SP,SP,#0x2400010438 MOV R4,R00001043c MOV R5,R100010440 ADD R0,SP,#0x800010444 MOV R1,R400010448 MOV R2,R50001044c BL memcpy00010450 CMP R0,#0x000010454 BEQ LAB_00010478ARM's load-store architecture means you see more register-to-register operations and explicit load/store instructions. Function calls use BL (Branch with Link) instead of x86's CALL. Parameters are passed in R0-R3 (first four arguments) rather than x86-64's RDI, RSI, RDX, RCX.
Cross-References: The Web of Connections
Cross-references (xrefs) are the most powerful navigation tool in Ghidra. They answer two fundamental questions:
- "Who calls this function?" - select a function name and choose References > Show References to (Ctrl+Shift+F) to see every location that calls it
- "What does this code reference?" - select a data address and do the same to see every instruction that reads, writes, or takes the address of that location
For vulnerability research, xrefs are indispensable. When you identify a dangerous function like memcpy, list its references to see every call site. Each call site is a potential vulnerability if the arguments are attacker-controlled.
// Cross-references to memcpy in a typical binary:// Showing: CALL references to memcpy//// 00401247 CALL memcpy (in parse_header)// 00401892 CALL memcpy (in process_chunk)// 00401f30 CALL memcpy (in handle_response)// 004023a1 CALL memcpy (in decode_payload)Each of these is a sink that needs auditing. Navigate to each one, examine where the size argument comes from, and determine whether it is properly validated.
Following Call Chains
Real vulnerability analysis requires following chains of function calls. A typical discovery process:
- You find that
process_message()callsparse_header()with network data parse_header()extracts a length field and passes it toallocate_buffer()allocate_buffer()callsmalloc()with that length- Back in
process_message(), the length is used inmemcpy()
To trace this chain in Ghidra:
- Start at
process_message(), read the decompiled code - Double-click on
parse_header()to jump into it - Read that function, note what it returns
- Press Alt+Left to go back (like a browser back button)
- Continue tracing through each function in the chain
The decompiler makes this far more tractable than raw assembly. Parameters, return values, variable types — all rendered in C-like form, so tracing data flow feels almost natural.
Ghidra maintains a navigation history, just like a web browser. Alt+Left goes back, Alt+Right goes forward. Use this constantly as you explore call chains - jump into a function to understand it, then jump back to continue reading the caller. The navigation history also appears in the toolbar as back/forward arrows.
Renaming Functions and Variables
Rename immediately — the moment you understand what something does, not after. It's the single most productive action in Ghidra:
Before renaming:
undefined8 FUN_00401230(int param_1, long param_2, uint param_3) { void *pvVar1; uint uVar2; uVar2 = *(uint *)(param_2 + 4); pvVar1 = malloc((ulong)uVar2); if (pvVar1 != NULL) { memcpy(pvVar1, (void *)(param_2 + 8), (ulong)uVar2); FUN_004015a0(param_1, pvVar1, uVar2); } return 0;}After renaming:
int process_client_data(int client_fd, uint8_t *packet, uint bytes_received) { void *payload_buf; uint payload_len; payload_len = *(uint *)(packet + 4); // length field from the header payload_buf = malloc((ulong)payload_len); if (payload_buf != NULL) { memcpy(payload_buf, packet + 8, (ulong)payload_len); dispatch_to_handler(client_fd, payload_buf, payload_len); } return 0;}The renamed version makes a bug easy to spot. payload_len comes from the packet header, so the attacker chooses it, and nothing compares it with bytes_received, the parameter that's never used. The malloc and memcpy agree with each other, so the destination is fine. The source isn't: claim a 64 KB payload in a 20-byte packet and memcpy reads far past the end of the received data, copying neighbouring heap memory into the buffer that gets processed (and perhaps echoed back), much like Heartbleed. The fix is a check that payload_len <= bytes_received - 8 (after checking bytes_received >= 8).
Renaming workflow:
- Click on a symbol (function name, variable, parameter)
- Press L to open the rename dialogue
- Type the new name
- Press Enter
Ghidra updates the name everywhere it appears - in the listing, the decompiler, the symbol tree, and all cross-references.
Adding Comments and Bookmarks
As you analyse, annotate your findings directly in Ghidra:
Comments (press ;) add notes at specific addresses. Use them to record your understanding, flag potential vulnerabilities, or note questions for later investigation:
00401247 CALL memcpy ; VULN: payload_len from network, no bounds checkBookmarks (Ctrl+D) mark addresses you want to return to. Create bookmarks for:
- Potential vulnerability sites
- Functions you need to analyse further
- Interesting code patterns
- Entry points from the network or file input
Bookmarks appear in the Bookmarks window (Window -> Bookmarks) where you can organise and filter them.
Decompiler Output vs. Actual Assembly
The decompiler is a powerful aid, but it is an approximation. Cases where you must cross-check against the assembly:
Optimised arithmetic - the compiler may have replaced a multiplication with shifts and adds, or used SIMD instructions. The decompiler might not perfectly reconstruct the original expression.
Unusual calling conventions - if the binary uses a non-standard calling convention or passes parameters through global variables, the decompiler may misidentify parameters.
Inline assembly - any inline assembly in the original source will look strange in the decompiler because it does not follow the normal compilation patterns.
Obfuscated code - intentionally obfuscated binaries use patterns that confuse decompilers: opaque predicates, control flow flattening, and code virtualisation. The decompiler output may be misleading.
When the decompiler output looks wrong, switch to the Listing view and read the actual instructions. Assembly never lies. It's hard to read, but it shows exactly what the CPU executes — no interpretation, no guessing.
Tip: click on a line in the decompiler to highlight the corresponding assembly instructions in the Listing view, and vice versa. This synchronised navigation makes it easy to cross-reference the two views.