Lion Cipher Lab
Watch what a compiler does to a C function: read your own program's assembly, plain and optimised
- Foundations
- Beginner
- ~60 min
- Free · no account required
Why it matters
Reverse engineering means working out what a program does when you do not have its source. Every reverse engineering tool, from a debugger to a decompiler, is showing you the compiler's output read backwards. If you have watched a compiler turn your own code into assembly, you know what the shapes mean: how an if looks, how a loop looks, how a function call looks. That makes unknown programs a lot less intimidating. You also learn the honest limits: names of variables and comments are gone, and an optimiser can rearrange almost everything.
What you'll learn
- asking gcc for assembly (-S) in Intel syntax and for a compiled object's disassembly with objdump
- reading the five instruction families that cover most code: mov, arithmetic, compare, jump, call and ret
- recognising a function's arguments and return value from registers
- mapping an if statement and a loop onto compare-and-jump patterns
- comparing -O0 with -O2 output and explaining why optimised code is harder to read back
- writing the C you think a snippet of assembly came from, then testing the guess by compiling it
Steps in this lab
- The idea: compilers are translators, analysts translate back
- Write three tiny functions
- Ask the compiler for its assembly
- The cast list: five kinds of instruction
- Read scale: arithmetic and a return
- Read biggest: how an if looks
- Read sum_to: how a loop looks
- Disassemble the real program with objdump
- Turn the optimiser on and compare
- What a pro does differently, and when not to do this by hand
- Clean up
Open the full interactive lab →