CS 202 - Homework 7

Due: Friday 4/20, at 5pm

This homework is the "bomb lab" from the Bryant and O'Hallaron text, customized for our course. Here is the write-up.

You may work in groups of two (highly recommended!), or by yourself if you prefer. Grading happens automatically; your current score will be displayed (anonymously) on the scoreboard.

To get started, form a team and check out your personal bomb here. If you work in a team, enter both usernames separated by an underscore, and one of the emails. You will need to save the bomb on basin or on one of the lab machines.

This is a difficult lab and will require significant time. For added incentive to get started early, your total score will be computed as follows:

```total = min(10, score_Fri) + min(25, score_Mon) + score_final

where:
score_Fri is your score as of 5pm this Friday, 4/13;
score_Mon is your score as of 5pm on Monday, 4/16;
score_final is your score (max 70) by the deadline, 5pm on Friday 4/20.
```

Your final score is out of 100; up to 105 is possible. You cannot take any extensions on any of the deadlines. Please keep track of the total time; you will report it on the submission page (link below).

Honor code note: You (obviously) may not share any of the solutions to any of the stages (which will also differ by bomb). Also, you may not provide specific instructions on how to diffuse a stage once you figured it out. But you may help your classmates by explaining general concepts and by giving suggestions of what to try next (e.g., "have you examined the memory pointed to by register X?" or "have you tried setting a breakpoint in Y?").

Hints

Here are the most important gdb instructions:

```gdb -tui bomb  // start gdb on your bomb
lay asm        // show disassembled code
lay reg        // show registers

start          // start program from the top

step           // step one C instruction
next           // like step, but "step over" function calls

stepi          // step one assembly instruction
nexti          // like stepi, but "step over" function calls

b LOC          // set breakpoint at LOC
run            // run from beginning until it hits breakpoint
run a.txt      // run, taking bomb input from text file

cont           // continue running until next breakpoint

x/3dw \$rax     // examine 3 4-byte words in memory pointed to by %rax in decimal
// (for other variants of the powerful x command see the linked documentation)

Control-D      // one way to quit out of gdb
```
Other hints:
• If you're creating text files on a PC they will have CRLF end-of-line characters and fail string comparison. To fix, edit your files directly on basin (e.g. using emacs or vi), or use the utility "dos2unix" to convert all CRLF to just LF:
```linux> dos2unix psol.txt
```
• If you find yourself typing the same commands into gdb over and over, write these commands in a text editor and cut and paste them into your shell, starting with "gdb -tui bomb".

• To set a breakpoint at a specific address, use the following syntax (note the '*'):
```b *0x400c40
```
• Breakpoints are your friends! It might be a good idea to set multiple breakpoints: one in the function you're currently working on, and others in functions that you'd rather not have getting executed :).

Electronic submission

While your grade is determined by your online scores, I still want you to submit your text file with your solutions, mainly so I get a record of the total time taken and your collaborators. Please upload your textfile "psol.txt" via the HW 7 submission page by the due date. (It's fine if your file has a different name, you can ignore the warning.) Only one person per team should submit (whoever checked out the bomb). Minus 3 points if you don't submit!

Good luck and have fun!