I've been looking it over and I think that the actual change in the numbers takes place in read_six_numbers.
from read_six_numbers+3 to read_six_numbers+56
Here is the code...am I correct?
Main Topics
Browse All TopicsI'm trying to get the value of the register of eax at the address 0x8048dc0. The assembler dump is below. Basically it reads 6 numbers and compares them to value of eax and the above memory location if I'm correct. I can't quite figure out how to iterate through the loop to get the register value each time it loops.
Right now the is what I'm doing:
(gdb) disas phase_2
Dump of assembler code for function phase_2:
0x08048d91 <phase_2+0>: push %ebp
0x08048d92 <phase_2+1>: mov %esp,%ebp
0x08048d94 <phase_2+3>: push %esi
0x08048d95 <phase_2+4>: push %ebx
0x08048d96 <phase_2+5>: sub $0x30,%esp
0x08048d99 <phase_2+8>: lea -0x20(%ebp),%eax
0x08048d9c <phase_2+11>: mov %eax,0x4(%esp)
0x08048da0 <phase_2+15>: mov 0x8(%ebp),%eax
0x08048da3 <phase_2+18>: mov %eax,(%esp)
0x08048da6 <phase_2+21>: call 0x8048f56 <read_six_numbers>
0x08048dab <phase_2+26>: cmpl $0x1,-0x20(%ebp)
0x08048daf <phase_2+30>: je 0x8048db6 <phase_2+37>
0x08048db1 <phase_2+32>: call 0x8048f2c <explode_bomb>
0x08048db6 <phase_2+37>: mov $0x2,%ebx
0x08048dbb <phase_2+42>: lea -0x20(%ebp),%esi
0x08048dbe <phase_2+45>: mov %ebx,%eax
0x08048dc0 <phase_2+47>: imul -0x8(%esi,%ebx,4),%eax
0x08048dc5 <phase_2+52>: cmp %eax,-0x4(%esi,%ebx,4)
0x08048dc9 <phase_2+56>: je 0x8048dd0 <phase_2+63>
0x08048dcb <phase_2+58>: call 0x8048f2c <explode_bomb>
0x08048dd0 <phase_2+63>: add $0x1,%ebx
0x08048dd3 <phase_2+66>: cmp $0x7,%ebx
0x08048dd6 <phase_2+69>: jne 0x8048dbe <phase_2+45>
0x08048dd8 <phase_2+71>: add $0x30,%esp
0x08048ddb <phase_2+74>: pop %ebx
0x08048ddc <phase_2+75>: pop %esi
0x08048ddd <phase_2+76>: pop %ebp
0x08048dde <phase_2+77>: ret
End of assembler dump.
(gdb) break *0x08048dc0
Breakpoint 4 at 0x8048dc0
(gdb) r input.txt
Starting program: /home/jalexanb/lab1/bomb72
Welcome to my fiendish little bomb. You have 6 phases with
which to blow yourself up. Have a nice day!
Phase 1 defused. How about the next one?
Breakpoint 3, 0x08048d96 in phase_2 ()
(gdb) info registers
eax 0x804a890 134523024
ecx 0xd 13
edx 0x2 2
ebx 0xbffe9cb4 -1073832780
esp 0xbffe9bf0 0xbffe9bf0
ebp 0xbffe9bf8 0xbffe9bf8
esi 0x941ca0 9706656
edi 0x0 0
eip 0x8048d96 0x8048d96 <phase_2+5>
eflags 0x282 [ SF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) step
Single stepping until exit from function phase_2,
which has no line number information.
BOOM!!!
The bomb has blown up.
Program exited with code 010.
I'm not sure what I'm not doing correctly any thoughts?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I see you've made some progress.
>> I'm not sure what I'm not doing correctly any thoughts?
The bomb explodes because the input you gave is not correct. In order to continue, you'll have to pass the right input. More directly, you'll have to make that it never calls explode_bomb :) The loop won't continue when the bomb explodes.
>> I've been looking it over and I think that the actual change in the numbers takes place in read_six_numbers.
All the read_six_numbers function does, is exactly what it says ... It reads 6 numbers from the provided string, and places them on the stack.
>> Here is what I have determine the instructions in phase_2 to do. Correct me if I'm wrong.
>> 0x08048d91 <phase_2+0>: push %ebp
>> pushes ebp on the stack ebp = input
>> 0x08048d92 <phase_2+1>: mov %esp,%ebp
>> ebp = esp (esp =*input)
%ebp is the base pointer ... This is just the standard way to start a new stack frame at the start of a function. It is not your input, although some of the input might be found relative to the (new) base pointer.
>> 0x08048d9c <phase_2+11>: mov %eax,0x4(%esp)
>> eax = esp + 4
The mov instruction moves the value of the left argument to the location specified in the right argument. Not the other way around.
>> 0x08048da0 <phase_2+15>: mov 0x8(%ebp),%eax
>> eax = ebp + 8
>> 0x08048da3 <phase_2+18>: mov %eax,(%esp)
>> esp = eax
There is a dereferencing operation that you missed. With C-like syntax :
eax = *(ebp + 8)
*(esp) = eax
(ebp + 8) is an address, but we're not interested in the address - we're interested in the value that is located at that address. Hence the dereference operation. Similarly for (esp).
>> 0x08048da6 <phase_2+21>: call 0x8048f56 <read_six_numbers>
>> calls read_six_numbers with eax as parameter
The parameter is passed on the stack, not in eax.
>> 0x08048dab <phase_2+26>: cmpl $0x1,-0x20(%ebp)
>> compares ebp 32 to see if its equal to 1
Don't forget the dereference operation again ...
>> 0x08048dc0 <phase_2+47>: imul -0x8(%esi,%ebx,4),%eax
>> eax = (esi + ebx * 4 8) * (esi + ebx * 4 8)
imul multiplies its both arguments, ie. :
imul a, b
means :
b = b * a
Also don't forget to dereference ...
>> 0x08048dc5 <phase_2+52>: cmp %eax,-0x4(%esi,%ebx,4)
>> compares if (esi + ebx * 4 4) == eax
dereference ...
>> 0x08048dd8 <phase_2+71>: add $0x30,%esp
>> esp = esp + 30
hex vs. decimal mistake here ...
The bomb explodes because the input you gave is not correct. In order to continue, you'll have to pass the right input. More directly, you'll have to make that it never calls explode_bomb :) The loop won't continue when the bomb explodes.
>>>Right I understand that.
All the read_six_numbers function does, is exactly what it says ... It reads 6 numbers from the provided string, and places them on the stack.
>>Right I understand this.
>> Here is what I have determine the instructions in phase_2 to do. Correct me if I'm wrong.
>> 0x08048d91 <phase_2+0>: push %ebp
>> pushes ebp on the stack ebp = input
>> 0x08048d92 <phase_2+1>: mov %esp,%ebp
>> ebp = esp (esp =*input)
%ebp is the base pointer ... This is just the standard way to start a new stack frame at the start of a function. It is not your input, although some of the input might be found relative to the (new) base pointer.
0x08048d91 <phase_2+0>: push %ebp
puashes ebp onto the stack
0x08048d92 <phase_2+1>: mov %esp,%ebp
ebp = *esp esp pointer is being pointed at ebp on the stack
>> 0x08048d9c <phase_2+11>: mov %eax,0x4(%esp)
>> eax = esp + 4
The mov instruction moves the value of the left argument to the location specified in the right argument. Not the other way around.
0x08048d9c <phase_2+11>: mov %eax,0x4(%esp)
eax = (%esp+4) moves eax to the position (%esp+4) on the stack
>> 0x08048da0 <phase_2+15>: mov 0x8(%ebp),%eax
>> eax = ebp + 8
>> 0x08048da3 <phase_2+18>: mov %eax,(%esp)
>> esp = eax
There is a dereferencing operation that you missed. With C-like syntax :
0x08048da0 <phase_2+15>: mov 0x8(%ebp),%eax
move the value of (ebp+8) to = eax
0x08048da3 <phase_2+18>: mov %eax,(%esp)
*(esp) = eax sets stack pointer esp to eax
eax = *(ebp + 8)
*(esp) = eax
(ebp + 8) is an address, but we're not interested in the address - we're interested in the value that is located at that address. Hence the dereference operation. Similarly for (esp).
>> 0x08048dab <phase_2+26>: cmpl $0x1,-0x20(%ebp)
>> compares ebp 32 to see if its equal to 1
Don't forget the dereference operation again ...
Not sure about the dereference here...Should this be
0x08048dab <phase_2+26>: cmpl $0x1,-0x20(%ebp)
(ebp - 32) : : 1?? Not sure where the dereferencign comes in...
>> 0x08048dc0 <phase_2+47>: imul -0x8(%esi,%ebx,4),%eax
>> eax = *(esi + ebx * 4 - 8) * *(esi + ebx * 4 - 8)
imul multiplies its both arguments, ie. :
imul a, b
means :
b = b * a
Also don't forget to dereference ...
eax = *(esi + ebx * 4 - 8) * *(esi + ebx * 4 - 8)
>> 0x08048dc5 <phase_2+52>: cmp %eax,-0x4(%esi,%ebx,4)
>> compares if (esi + ebx * 4 4) == eax
dereference ...
>> 0x08048dd8 <phase_2+71>: add $0x30,%esp
esp = esp + 48
hex vs. decimal mistake here ...
esp = esp +48
Could you explain dereferencing? Maybe with an example? This is probably not clicking for me because I am learning C and Assembly at the same time...thanks.
Am I wrong in thinking that this is the loop for the phase?
0x08048db6 <phase_2+37>: mov $0x2,%ebx
0x08048dbb <phase_2+42>: lea -0x20(%ebp),%esi
0x08048dbe <phase_2+45>: mov %ebx,%eax
0x08048dc0 <phase_2+47>: imul -0x8(%esi,%ebx,4),%eax
0x08048dc5 <phase_2+52>: cmp %eax,-0x4(%esi,%ebx,4)
0x08048dc9 <phase_2+56>: je 0x8048dd0 <phase_2+63>
0x08048dcb <phase_2+58>: call 0x8048f2c <explode_bomb>
0x08048dd0 <phase_2+63>: add $0x1,%ebx
0x08048dd3 <phase_2+66>: cmp $0x7,%ebx
0x08048dd6 <phase_2+69>: jne 0x8048dbe <phase_2+45>
0x08048dd8 <phase_2+71>: add $0x30,%esp
And that the after the input is put through the read_six_numbers function each of the values will be incremented by some amount. Which I need to find and then applying to the first input number to find the next number and so on?
>> 0x08048d92 <phase_2+1>: mov %esp,%ebp
>> ebp = *esp esp pointer is being pointed at ebp on the stack
What this means is that the current base pointer (ebp) is set to the top of the stack (esp), so a new stack frame can be started for the function.
If you're not sure about what a stack frame is, take a look here :
http://en.wikipedia.org/wi
>> 0x08048d9c <phase_2+11>: mov %eax,0x4(%esp)
>> eax = (%esp+4) moves eax to the position (%esp+4) on the stack
Although your pseudo code is misleading (the assignment is still the wrong way around, and the dereference operation is still not there), your explanation in words sounds correct.
>> 0x08048da0 <phase_2+15>: mov 0x8(%ebp),%eax
>> move the value of (ebp+8) to = eax
Not the value of (ebp+8), but the value that is located at address (ebp+8). There's an important distinction there.
>> 0x08048da3 <phase_2+18>: mov %eax,(%esp)
>> *(esp) = eax sets stack pointer esp to eax
No, you're missing the dereference operation again. This instruction places the value in eax at the top of the stack. It does not modify the stack pointer (esp), but rather the memory that it's pointing to.
>> 0x08048dab <phase_2+26>: cmpl $0x1,-0x20(%ebp)
>> (ebp - 32) : : 1?? Not sure where the dereferencign comes in...
Always the same ... It's not (ebp-32), but it's *(ebp-32). Do you understand what the * means ? Do you know the C language, and what the dereference operator (*) does there ?
>> eax = *(esi + ebx * 4 - 8) * *(esi + ebx * 4 - 8)
That's only one half of my remark. Did you understand what I said about how the imul instruction works, and which values it multiplies ?
>> Could you explain dereferencing? Maybe with an example? This is probably not clicking for me because I am learning C and Assembly at the same time...thanks.
Dereferencing means that you have a pointer (a memory address), and instead of using that address, you get the value that is located at that address in memory. You follow the pointer to get to the value it's pointing to - ie. you're dereferencing the pointer.
>> Am I wrong in thinking that this is the loop for the phase?
That's a loop indeed, which performs some calculations and checks based on the six numbers that were entered by the user.
>> And that the after the input is put through the read_six_numbers function each of the values will be incremented by some amount.
Not really. What is happening is that each of the numbers is compared to a specific (calculated) value, and if one of them has the wrong value, the bomb explodes. It's your job to figure out those values.
Okay so I need to look at the value of the memory addresses when the pointer is being dereferenced?
>>Always the same ... It's not (ebp-32), but it's *(ebp-32). Do you understand what the * means ? Do you >>know the C language, and what the dereference operator (*) does there ?
Does this mean *(ebp-32) is a memory location? Or does it mean that I would find the value at that memory location and then subtract 32 from it?
>>Although your pseudo code is misleading (the assignment is still the wrong way around, and the >>dereference operation is still not there), your explanation in words sounds correct
Yea sorry about that not really sure how to express most of what I want to say via assembly code...
>>No, you're missing the dereference operation again. This instruction places the value in eax at the top >>of the stack. It does not modify the stack pointer (esp), but rather the memory that it's pointing to.
That is what I was trying to say...because esp points to the top of the stack. So setting the pointer of esp to the value of eax would put that value at the top of the stack i.e. that memory location.
What command would I use to look up the value at a particular location?
>>Not really. What is happening is that each of the numbers is compared to a specific (calculated) value, >>and if one of them has the wrong value, the bomb explodes. It's your job to figure out those values.
If the calculation isn't done in the loop and it isn't done in the read_six_numbers function there doesn't seem to be anywhere else it could be done.
>> Does this mean *(ebp-32) is a memory location? Or does it mean that I would find the value at that memory location and then subtract 32 from it?
It means that (ebp-32) is a memory location (address), and that you get the value at that memory location.
>> So setting the pointer of esp to the value of eax
You seem to understand what happens, but this phrase is still wrong ... You don't actually set the stack pointer (esp), since that would imply modifying esp. But you set the value that esp points to.
>> What command would I use to look up the value at a particular location?
What do you mean ? In the debugger ? You can use the examine (x) command :
http://sourceware.org/gdb/
>> If the calculation isn't done in the loop
I never said it wasn't done in the loop.
So I know what I need to find is in the loop.
0x08048dc0 <phase_2+47>: imul -0x8(%esi,%ebx,4),%eax
0x08048dc5 <phase_2+52>: cmp %eax,-0x4(%esi,%ebx,4)
this is the only part that I see that different values are calculated and compared. But in order for me to figure out eax(the numbers I need) I would have to find the values of esi and ebx. Am I understanding this correctly?
>> 0x08048dbb <phase_2+42>: lea -0x20(%ebp),%esi
>> the value of esi would be found in memory location 0x08048dbb?
The lea (load effective address) instruction is an exception. It skips the dereference operation, and just works with the address.
>> this is the only part that I see that different values are calculated and compared. But in order for me to figure out eax(the numbers I need) I would have to find the values of esi and ebx. Am I understanding this correctly?
You are :)
ebx would be found here correct?
0x08048db6 <phase_2+37>: mov $0x2,%ebx
Which ebx would be equal to 2.But, it would be incremented by one each time the loop iterates by this
0x08048dd0 <phase_2+63>: add $0x1,%ebx
As for esi
0x08048dbb <phase_2+42>: lea -0x20(%ebp),%esi
The value of esi would be found in the memory location 0x08048dbb correct? Or is the address (%ebp - 20) the value of esi. I'm thinking the later...
Business Accounts
Answer for Membership
by: purewinPosted on 2009-10-18 at 12:36:16ID: 25601057
Any help would be appreciated. :)