I am relatively new to assembly and am trying to understand the following assembler dump (this is from the common 'binary bomb' exercise which I am attempting in order to get more familiar with assembly). The basic premise is that you have to find the right input needed to exit the program successfully without "triggering the bomb" (calling the explode_bomb function) by inspecting the assembly and setting breakpoints. It is a common exercise used to teach GDB debugging and assembly syntax.
From what I can understand, this program first checks string input using scanf and checks whether 1 argument is provided. Upon setting a breakpoint and inspecting the value of the eax register, I am able to see the input value I enter so it seems as though I should be looking for this to be compared with something else. The program then moves some things around and compares the value of the eax register to the binary value 0x52b = 1323. However, I have tried using this value as my input and it does not work so I am wondering whether I am misunderstanding the logic behind this program.
I would greatly appreciate any help/advise!
Updated (I am not sure whether this is correct):
- The program takes 1 input argument, stores in eax register. Explodes if not 1 argument input.
- The program then does
mov 0x1c(%esp),%eax
which essentially doeseax = [esp + 0x1c]
(wouldn't this overwrite the program's input?) - The program then does
lea (%eax,%eax,2),%eax
which essentially doeseax = eax + eax * 2
- Finally, the program does
cmp $0x52b,%eax
which compares the value in theeax
register to0x52b
.
0x08048bd0 <+0>: sub $0x2c,%esp
0x08048bd3 <+3>: movl $0x0,0x1c(%esp)
0x08048bdb <+11>: lea 0x1c(%esp),%eax
0x08048bdf <+15>: mov %eax,0x8(%esp)
0x08048be3 <+19>: movl $0x804a644,0x4(%esp)
0x08048beb <+27>: mov 0x30(%esp),%eax
0x08048bef <+31>: mov %eax,(%esp)
0x08048bf2 <+34>: call 0x8048870 <__isoc99_sscanf@plt>
0x08048bf7 <+39>: cmp $0x1,%eax
0x08048bfa <+42>: je 0x8048c01 <phase_1+49>
0x08048bfc <+44>: call 0x8049363 <explode_bomb>
0x08048c01 <+49>: mov 0x1c(%esp),%eax
0x08048c05 <+53>: lea (%eax,%eax,2),%eax
0x08048c08 <+56>: cmp $0x52b,%eax
0x08048c0d <+61>: je 0x8048c14 <phase_1+68>
0x08048c0f <+63>: call 0x8049363 <explode_bomb>
0x08048c14 <+68>: add $0x2c,%esp
0x08048c17 <+71>: ret