Skip to content

Reading the Listing

The Listing is the program as the processor will execute it: one line per instruction, each with the address it lives at. It is the ground truth of reverse engineering — the decompiler can mislead, as the next chapter will show it cheerfully doing, but the Listing only ever says what the bytes say. This chapter reads one small function in it, line by line, and needs only the handful of instruction kinds the specimen uses.

Here is check_code, exactly as Ghidra's engine reports it (the transcript this was lifted from ships as examples/listing-check-code.txt; the CodeBrowser adds its labels and shows the call target by name):

001011a0  ENDBR64
001011a4  PUSH RBP
001011a5  MOV RBP,RSP
001011a8  SUB RSP,0x8
001011ac  MOV dword ptr [RBP + -0x4],EDI
001011af  MOV EAX,dword ptr [RBP + -0x4]
001011b2  MOV EDI,EAX
001011b4  CALL 0x00101169
001011b9  CMP EAX,0x191b2
001011be  JNZ 0x001011c7
001011c0  MOV EAX,0x1
001011c5  JMP 0x001011cc
001011c7  MOV EAX,0x0
001011cc  LEAVE
001011cd  RET

Walking it

The addresses run 001011a0 upward because the specimen is a position-independent executable: Ghidra loads it at a base of 00100000 and every address you will see in this guide carries that offset. (The file itself thinks check_code is at 0x11a0; chapter 13's quick-look tools will show it that way. Same code, different bookkeeping.)

  • ENDBR64 and the PUSH RBP / MOV RBP,RSP pair are the prologue — the standard doorway into a function, present in nearly every function the compiler emitted. Learn to see it as punctuation, not content.
  • MOV dword ptr [RBP + -0x4],EDI stores the incoming argument. On x86-64 Linux the first integer argument arrives in the EDI register; [RBP + -0x4] is a slot on the stack, four bytes below the frame marker. The next two MOVs carry that same value back out into EDI — the compiler at -O0 (no optimisation, the setting this specimen was built with) shuffles values through memory rather than keeping them in registers. Real-world code built with optimisation is terser and harder; the specimen is deliberately plain.
  • CALL 0x00101169 hands the value to another function — the one at address 00101169, which the symbol table names scramble. Its answer comes back in EAX, by the same register convention.
  • CMP EAX,0x191b2 compares that answer with the number 0x191b2 — 102834 in decimal. This is the decision the whole program exists to make, and it takes one line of the Listing to say it.
  • JNZ 0x001011c7 — jump if not zero, i.e. if the comparison failed — skips to the MOV EAX,0x0 line. Fall through instead and EAX becomes 1. Either way, LEAVE/RET returns EAX to the caller: 1 for "the mechanism accepted this attempt", 0 for "it didn't".

That is the entire logic of the lock, read off fifteen lines. Notice what the Listing did not require: the argument's journey through memory, the prologue, the register names are all learnable once and then read as furniture; the story is call, compare, branch.

Check: a reader who can point at the CMP line and say what is being compared with what — the scrambled attempt against 102834 — has read the Listing successfully. But the Listing hasn't yet said what scramble does to the attempt, and without that the comparison is a riddle. That is the decompiler's job, and it is next.