Given what you learned about CALL and RET, explain how you would read the value of EIP? Why can’t you just do MOV EAX, EIP?
You can't do MOV EAX, EIP because the instruction pointer is not readily accessible, likely as a security feature.
Here is one way you can get EIP (after the call) into another register.
_start: call geteip ; ... geteip: pop eax ;eax = eip (_start + sizeof(call)) ; push eax ; ret
Or access EBP+4 of function with stack frames, if not read ESP value in the function begin.
ReplyDeleteYou can also do something like this:
ReplyDeletecall 0 ; E8 00 00 00 00
pop eax ; 58
You don't need to use labels like "geteip" with this method.