I have given assignment to read binary bomb. I am confused as far as how func4 and phase_4 linked together.
the following are the code.
===================
Dump of assembler code for function phase_4:
0x08048d3a <+0>: push %ebp
0x08048d3b <+1>: mov %esp,%ebp
0x08048d3d <+3>: sub $0x28,%esp
0x08048d40 <+6>: lea -0x10(%ebp),%eax
0x08048d43 <+9>: mov %eax,0xc(%esp)
0x08048d47 <+13>: lea -0xc(%ebp),%eax
0x08048d4a <+16>: mov %eax,0x8(%esp)
0x08048d4e <+20>: movl $0x804a1aa,0x4(%esp)** //input format
//(gdb) x /s0x804a1aa => “%d %d”
0x08048d56 <+28>: mov 0x8(%ebp),%eax
0x08048d59 <+31>: mov %eax,(%esp)
0x08048d5c <+34>: call 0x804870c <__isoc99_sscanf@plt>
0x08048d61 <+39>: cmp $0x2,%eax // if not == 2 , bomb
0x08048d64 <+42>: jne 0x8048d72 <phase_4+56>
0x08048d66 <+44>: mov -0xc(%ebp),%eax //
0x08048d69 <+47>: test %eax,%eax
0x08048d6b <+49>: js 0x8048d72 <phase_4+56>
0x08048d6d <+51>: cmp $0xe,%eax // if <= 14 , ok
0x08048d70 <+54>: jle 0x8048d77 <phase_4+61>
0x08048d72 <+56>: call 0x8049138 <explode_bomb>
0x08048d77 <+61>: movl $0xe,0x8(%esp)
0x08048d7f <+69>: movl $0x0,0x4(%esp)
0x08048d87 <+77>: mov -0xc(%ebp),%eax
0x08048d8a <+80>: mov %eax,(%esp)
0x08048d8d <+83>: call 0x8048a80 <func4>
0x08048d92 <+88>: cmp $0x1f,%eax // compare output of func4 with 31 ( ? )
0x08048d95 <+91>: jne 0x8048d9d <phase_4+99>
0x08048d97 <+93>: cmpl $0x1f,-0x10(%ebp) // output of fun4 must == 0x1f
// (gdb) p /d 0x1f => 31
0x08048d9b <+97>: je 0x8048da2 <phase_4+104>
0x08048d9d <+99>: call 0x8049138 <explode_bomb>
0x08048da2 <+104>: leave
0x08048da3 <+105>: ret
====================
Dump of assembler code for function func4:
0x08048a80 <+0>: push %ebp
0x08048a81 <+1>: mov %esp,%ebp
0x08048a83 <+3>: sub $0x18,%esp
0x08048a86 <+6>: mov %ebx,-0x8(%ebp)
0x08048a89 <+9>: mov %esi,-0x4(%ebp)
0x08048a8c <+12>: mov 0x8(%ebp),%eax
0x08048a8f <+15>: mov 0xc(%ebp),%edx
0x08048a92 <+18>: mov 0x10(%ebp),%esi
0x08048a95 <+21>: mov %esi,%ecx
0x08048a97 <+23>: sub %edx,%ecx
0x08048a99 <+25>: mov %ecx,%ebx
0x08048a9b <+27>: shr $0x1f,%ebx
0x08048a9e <+30>: lea (%ebx,%ecx,1),%ecx
0x08048aa1 <+33>: sar %ecx
0x08048aa3 <+35>: lea (%ecx,%edx,1),%ebx
0x08048aa6 <+38>: cmp %eax,%ebx
0x08048aa8 <+40>: jle 0x8048ac1 <func4+65>
0x08048aaa <+42>: lea -0x1(%ebx),%ecx
0x08048aad <+45>: mov %ecx,0x8(%esp)
0x08048ab1 <+49>: mov %edx,0x4(%esp)
0x08048ab5 <+53>: mov %eax,(%esp)
0x08048ab8 <+56>: call 0x8048a80 <func4>
0x08048abd <+61>: add %eax,%ebx
0x08048abf <+63>: jmp 0x8048ada <func4+90>
0x08048ac1 <+65>: cmp %eax,%ebx
0x08048ac3 <+67>: jge 0x8048ada <func4+90>
0x08048ac5 <+69>: mov %esi,0x8(%esp)
0x08048ac9 <+73>: lea 0x1(%ebx),%edx
0x08048acc <+76>: mov %edx,0x4(%esp)
0x08048ad0 <+80>: mov %eax,(%esp)
0x08048ad3 <+83>: call 0x8048a80 <func4>
0x08048ad8 <+88>: add %eax,%ebx
0x08048ada <+90>: mov %ebx,%eax
0x08048adc <+92>: mov -0x8(%ebp),%ebx
0x08048adf <+95>: mov -0x4(%ebp),%esi
0x08048ae2 <+98>: mov %ebp,%esp
0x08048ae4 <+100>: pop %ebp
0x08048ae5 <+101>: ret
=================================
- line 20, I assume my input must be (%d , %d)
- line 39, the first input must x = 2 ?
- line 51, the second input must y <= 14 ?
- then call func4(x,y)
- line 88, compare output of func4(x,y) or %eax = 31 ?
- line 93, what do I have to compare -0x10(%ebp) = 31 ? what is exactly -0x10(%ebp) when the output should already be %eax on line 88 ? why do I have to check for this value ?
- when I try to find the answer of %d %d , since I already now the first one is (2,y) , can I just keep doing (2,0) then (2,1) ... (2,14) until I got the correct answer which is break at line 88 and run each answer until I got %eax = 31 ? Is this the correct approach to defused the bomb ? I'm so lost .. if not what would possibly be my approach, if I can not read what func4 is actually doing.
I'm so confused. Am I interpret this correct ?
Thank you