Practical Advice for Solving Assembly Puzzles

Setting up your debugging environment

There's two main ways to view the assembly for a compiled program.

The first is to use objdump to extract the assembly. For example, if your compiled program is called nanobomb1, you can dump the assembly to the terminal with the command objdump -d nanobomb1. This spills everything onto the screen which can be kind of unwieldy, so you can try doing objdump -d nanobomb1 > nanobomb1.s to create a file called nanobomb1.s that contains all the assembly. This also gives you the benefit of syntax highlighting.

However, I recommend using the second approach which is to view assembly within gdb as you're debugging. To do so, I would use the following commands:

  1. gdb ./nanobomb1 (Invokes gdb onto our program we want to debug.)
  2. layout asm (Change the UI so that we can see the assembly as we step.)
  3. layout reg (Optional: change the UI to also show the values of registers.)
  4. b try_defuse (Put a breakpoint on the function of interest. The function name will be different on assign5.)
  5. r (Run the program. On assign5, use r input.txt so that previous passwords are passed along.)
  6. Use <CTRL+L> as necessary to repaint the screen to clear any visual artifacts that occur.

Once you've done this, you'll be able to step through assembly code and see what line you're on and the values of registers as you go along. Here are the gdb commands that might be helpful here:

General Format of an Assembly Puzzle

CS 107A nanobombs and assign5 generally follow this structure:

General Strategy for Approaching Assembly Puzzles

General Advice for Working with Assembly in gdb