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.)
ENDBR64and thePUSH RBP/MOV RBP,RSPpair 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],EDIstores the incoming argument. On x86-64 Linux the first integer argument arrives in theEDIregister;[RBP + -0x4]is a slot on the stack, four bytes below the frame marker. The next twoMOVs carry that same value back out intoEDI— 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 0x00101169hands the value to another function — the one at address00101169, which the symbol table namesscramble. Its answer comes back inEAX, by the same register convention.CMP EAX,0x191b2compares that answer with the number0x191b2— 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 theMOV EAX,0x0line. Fall through instead andEAXbecomes 1. Either way,LEAVE/RETreturnsEAXto 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.