Search code examples
x86cmp

cmp and je not working when comparing equal values


[Homework disclaimer]

I'm working on the binary bomb lab. Basically, I have to use the objdump of a "bomb" executable to find the right input strings to disarm the "bomb." Currently I've solved 5/7 phases and am working on the 6th phase which contains this assembly:

 8048eb0:   39 18                   cmp    %ebx,(%eax)
 8048eb2:   74 05                   je     8048eb9 <phase_6+0x49>
 8048eb4:   e8 d0 0a 00 00          call   8049989 <explode_bomb>

To not explode the bomb, I need to set ebx and eax to same value so that je is called instead of the explode_bomb function. So, I found an input string that gives the same value of ebx and eax. However, when I reach this point in the program's execution, the je isn't called even though ebx and eax are the same value. In GDB:

Good work!  On to the next...
134530284

Breakpoint 2, 0x08048e74 in phase_6 ()
Current language:  auto; currently asm
(gdb) break *0x8048eb0
Breakpoint 3 at 0x8048eb0
(gdb) c
Continuing.

Breakpoint 3, 0x08048eb0 in phase_6 ()
(gdb) print $ebx
$1 = 134530284
(gdb) print $eax
$2 = 134530284
(gdb) si
0x08048eb2 in phase_6 ()
(gdb) si
0x08048eb4 in phase_6 ()
(gdb) si
0x08049989 in explode_bomb ()
(gdb) 

Why is this not working? This is the first time this assignment where this issue has come up.


Solution

  • (%eax) is not the same as %eax.

    (%eax) means load the value pointed to by eax, not eax itself.