Page 1 of 1
EIP
Posted: Sun Jan 18, 2009 6:04 pm
by sweetgum
Im reading the intel manuals and it talks about how the only way to access the EIP is by executing a CALL instruction then reading the value of the return instruction pointer from the procedure stack. Can someone explain to me how this is done with a small example? Thanks!
Re: EIP
Posted: Sun Jan 18, 2009 6:12 pm
by Firestryke31
For mov EAX, EIP:
Code: Select all
codeWantingEIP:
call movEAXEIP
; do stuff with EIP
movEAXEIP:
mov eax, [esp]
ret
It's movEAXEIP that I believe they're talking about. To do 'mov EIP, EAX' you'd just do 'jmp eax'.
Re: EIP
Posted: Sun Jan 18, 2009 7:11 pm
by CodeCat
No need for a RET, this works too, and is simpler.
Code: Select all
codeWantingEIP:
call next
next:
pop eax
Re: EIP
Posted: Sun Jan 18, 2009 8:10 pm
by Firestryke31
I was just remembering a thread where there was all of this talk about some sort of return address stack cache and doing that messes it up and slows everything down for a while. I don't know if that's really the case, but better safe than sorry.
Re: EIP
Posted: Sun Jan 18, 2009 9:23 pm
by Love4Boobies
Lol. No, that's not what he's asking. After doing the call, you get EIP from the stack. Check the Intel manuals to see exactly what CALL pushes on the stack (sizes and order) and then read memory relative to SP
Re: EIP
Posted: Mon Jan 19, 2009 6:10 pm
by sweetgum
If I pop the value of EIP, does it affect the functionality if i use ret? ret is supposed to pop the top of the stack to eip
Re: EIP
Posted: Mon Jan 19, 2009 6:35 pm
by JohnnyTheDon
If you pop EIP, then ret won't work. Instead use someting like
Which will keep ret working and give you the value of the pushed EIP.
Re: EIP
Posted: Tue Jan 20, 2009 1:25 am
by thepowersgang
Re: EIP
Posted: Tue Jan 20, 2009 9:24 am
by JAAman
thepowersgang wrote:Or just use
not really a good idea, in general, because it will trash the CPUs CALL stack...
Re: EIP
Posted: Tue Jan 20, 2009 12:29 pm
by Firestryke31
Aha! I knew there was something like that!
That's why I used the code I did.
Re: EIP
Posted: Tue Jan 20, 2009 1:22 pm
by Combuster
Re: EIP
Posted: Tue Jan 20, 2009 5:30 pm
by Firestryke31
Isn't that almost what I had in the second post in the thread? Or is this some sort of "come up with as many ways to do the exact same thing" contest?