13.x — Chapter 13 summary and quiz

📘 Chapter 13⏱ about 2 min read✍️ Beginner friendly
Read one box at a time. No rush.

Quick review#

  • Reverse engineering works out how a program works without its source code. Only do it on things you're allowed to.
  • A program file has sections: code in .text, text and constants in .rodata/.rdata.
  • Registers are the CPU's tiny fast variables. eax/rax holds return values. On Linux, arguments arrive in rdi, rsi, rdx...
  • if becomes cmp/test + a conditional jump. A jump backwards is usually a loop.
  • Struct members are offsets like [rdi+8]. Virtual calls go through a vtable.
  • Tools: strings, Ghidra (static), x64dbg / gdb (dynamic).
  • Practise on crackmes and CTFs, inside a virtual machine.
Quick check

Pick an answer. You find out right away if it is right.

Quick check #1

In mov eax, edi (Intel syntax), where does the value go?

Quick check #2

A function returns an int. Which register usually holds the answer on x86-64?

Quick check #3

Which of these is fine to reverse engineer?

Quiz time
Question #1

What does this assembly function do? Write it as a C++ function.

Assembly (x86-64, GCC -O1)
mystery(int):        lea     eax, [rdi+rdi*2]        ret

It returns its argument times 3 (x + x*2):

C++
int mystery(int x){    return x * 3;}

Compilers love lea for small multiplications because it's fast.

Question #2

You see this inside a function. What C++ does it probably come from?

Assembly (x86-64, GCC -O1)
        mov     eax, DWORD PTR [rdi+4]        add     eax, DWORD PTR [rdi+8]        ret

rdi is a pointer or reference to a struct. It returns the member at offset 4 plus the member at offset 8. For example:

C++
struct Box{    int a;   // offset 0    int b;   // offset 4    int c;   // offset 8}; int sumBC(const Box& box){    return box.b + box.c;}
Question #3

Your level 1 crackme was cracked with strings in one second. Name two ways the level 2 version makes that harder.

  1. The password is stored scrambled (XOR-ed), so it doesn't appear as readable text.
  2. The check is in its own function with a loop, so you have to read the code (in Ghidra or a debugger) to understand how to unscramble it.
Finished reading? Tick it off. Your progress is saved in this browser.

Tip: press ← / → to move between lessons, / to search.