Reputation: 43
I'm following Aleph One's awesome introduction to smashing the stack, but I've gotten stuck running one of the example programs he has. The issue is that when I compile the line jmp 0x2a
, and disassemble it, that exact line is produced, whereas in aleph's code, it is translated to jmp 0x800015f <main+47>
. How do I force gcc to make this a relative jump and not an absolute one (which is what I think is going on).
Upvotes: 4
Views: 6411
Reputation: 57774
The problem is the 0x2a
. That looks like an absolute address, but what you want is a relative address.
That can be accomplished by labeling the destination and jumping to that: assemblers prefer generating a relative jump most of the time. Or use a relative address. Most assemblers accept something similar to .+0x2a
where .
is a symbol meaning the current instruction pointer. Some use $
instead.
Upvotes: 4