Complete Solution: Solve floors 1, 2, 3, 4. (5 extra credit)
Due before 11:59pm Tuesday Nov. 7
This lab should be done with your lab 6 partner: Lab 6 Partners
Expectations for Working with Partners
In this assignment, you and your partner are going to receive a binary maze program. Your maze has 5 phases, one for each floor of Parrish Hall (from the roof to out the door). Each floor's phase is a binary puzzle that needs to be solved to move on to the next floor. To solve a puzzle you need to enter a correct phrase on stdin (you can also have your maze read phrases from a file given as a command line argument).
Your goal is to solve all phases/floors of your maze, limiting the number of times you trip-up along the way and have to start all over.
Your maze will automatically notify me every time you trip-up and whenever you have solved a puzzle on a particular floor. In addition, your maze will only run on one of the CS lab machines.
Part 1: The Checkpoint (due Thursday Nov. 2 (after the midterm)):
Part 2: The complete solution (due Tuesday Nov 7 ):
Both you and your partner should do:
cd ~/cs31/labs
git clone [your_Lab06]Then cd into your Lab06-you-partner subdirectory.
$ ls README.md QUESTIONNAIRE maze_ID maze_how_we_solved_it soln.txt
http://almond.cs.swarthmore.edu:8000
mv ~/Desktop/mazeX.tar ~/cs31/Labs/Lab06-you-partner/.
cd ~/cs31/Labs/Lab06-you-partner/. ls mazeX.tar git add mazeX.tar git commit git pushYour partner should then to a git pull to get the copy of the mazeX.tar file.
cd ~/cs31/Labs/Lab06-you-partner/. git pull ls mazeX.tar
cd ~/cs31/Labs/Lab06-you-partner ls # you should see your mazeX.tar file tar xvf mazeX.tar
ls README maze* main.c
From firefox running on a CS lab machine, enter this url (you cannot connect to this url from outside our network):
almond.cs.swarthmore.edu:8000/scoreboardYou will see your maze in this list. The scoreboard displays how many stages you have solved, how many total trip-ups you have had, and your score so far.
This information is updated about every 20 seconds. Re-load the
page to see the latest information.
You can receive up to 71 points out of 66 total for this lab (5 points are extra credit):
To kill your maze executable (to make it exit without tripping-up), type CNTRL-C. This way you can run your maze, solve a puzzle on a floor, and then exit and come back later to try the puzzle on the next floor.
You can use many tools to help you solve your maze. Look at the hints section below for some tips and ideas. The best way is to use ddd or gdb to step through the disassembled binary.
Although the puzzles on each floor get progressively harder to solve, the expertise you gain as you move from floor to floor should offset this difficulty.
Once you have solved the puzzle on a floor, I encourage you to run your maze with a soln.txt file containing the input phrases for the floors you have solved. The format of the file should be one phrase per line, in order of the maze floors. Using an input file will help to prevent you from accidentally tripping up in the maze on a previously solved floor. For example:
./maze soln.txtwill read the input lines from soln.txt until it reaches EOF (end of file), and then switch over to stdin for the remaining input. This feature is also nice so you don't have to keep retyping the solutions to floors you have already solved. The maze ignores blank input lines, both in the file and on stdin.
To avoid accidentally tripping up in the maze, you will need to learn how to
single-step through the assembly code and how to set breakpoints. You
will also need to learn how to inspect both the registers and the
memory states. One of the nice side-effects of doing the lab is that
you will get very good at using a debugger. This is a crucial skill
that will pay big dividends the rest of your career.
Describe at a high-level what the original C code is doing for each floor. For example, is it doing some type of numeric computation, string processing, function calls, etc. and describe the specific computation it is doing (i.e. what type of string processing and how is that being used?).
Do not list registers and assembly code for this part, but describe what the puzzle on each floor is doing at a higher-level in terms of C semantics. You do not need to reverse engineer the IA32 code and translate every part of it to equivalent C code. Instead, give a rough idea of equivalent C or pseudo code for the main part of the puzzle on each floor. For example, something like "uses an if-else to choose to do X or Y based on the input value Z" is an appropriate right level of explanation. Something like "moves the value at %ebp-8 into register %eax" is way too low-level.
This part of the lab should not be onerous; you should be able to explain each puzzle in a short paragraph or two (maybe with a few lines of C or pseudo code to help explain). I recommend doing the write-ups for each floor as you solve them.
Excessively verbose, low-level descriptions will be penalized, as will vague descriptions; you want to clearly demonstrate to me that you figured out what that floor is doing by examining the IA32 code for each floor in your maze executable.
If you are unable to solve a floor, you can still receive partial credit for
it in the write-up part by telling me what you have determined about that
floor.
We do make one request, please do not use brute force! You could write a program that will try every possible input string to find the right one. But this is no good for several reasons:
You may see some x86 instructions in your maze assembly that are not on the IA32 cheatsheet. In this case, look at some of the IA32 Documentation and References for information about that instruction. The wikipedia page may be most useful.One instruction that you may see is cmov, which is a conditional move instruction that uses the condition codes to either move or not. The encoding is similar to the conditional jump instructions. For example, cmovge performs a move if greater than or equal to.
There is a bit of an art in determining how deep to trace through assembly code execution. You will need to trace into some function calls, but can also first try to see what happens before and after the call. You may also assume that C library functions functions, like scanf, do what you think they do---tracing into the scanf function, for example, will not help you figure out the solution to a level.
One note about the x command in gdb: its formatting is sticky, so if you want to print out the contents of different memory addresses for different sized values and types, you need to specify the format for each difference. For example:
x/s 0x1234 # print as a string what is stored at memory address 0x1234
x 0x5678 # also prints as a string (x's formatting is sticky)
x/wd 0x5678 # to print as an int what is stored at memory address 0x5678
# after printing as a string, need to specify the width and type
# w: 4 bytes, d: print as decimal int
# (x/wx) would print the 4-byte value in hex
x/a 0x9abc # will print what is at memory address 0x9abc as an address
See the gdb guide above for more examples of using the x command, including
the different formatting options.
Although objdump -d gives you a lot of information, it doesn't tell you the whole story. Calls to system-level functions are displayed in a cryptic form. For example, a call to sscanf might appear as:
8048c36: e8 99 fc ff ff call 80488d4 <_init+0x1a0>To determine that the call was to sscanf, you would need to disassemble within gdb.
Looking for documentation about a particular tool? The the commands apropos and man will help you find documentation about unix utilities, and in gdb the help command will explain gdb commands:
$ man objdump (gdb) help niHere is some more information on man and reading manual pages: man
Checkpoint: For the checkpoint, you need do nothing to "submit" it. I'll check the scoreboard at the due date to verify whether or not you met the checkpoint.
Complete Solution: For the complete solution you need to push your changes to the following files:
From one of your local repos (in your ~you/cs31/labs/Lab6-partner1-partner2 subdirectory)
git push
git add QUESTIONNAIRE git commit git pushAnother likely source of a failed push is that your partner pushed, and you have not pulled their changes. Do a git pull. Compile and test that your code still works. Then you can add, commit, and push.
If that doesn't work, take a look at the "Troubleshooting" section of the Using git page. You may need to pull and merge some changes from master into your local. If so, this indicates that your partner pushed changes that you have not yet merged into your local. Anytime you pull into your local, you need to check that the result is that your code still compiles and runs before submitting.