EIP
EIP
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!
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Re: EIP
For mov EAX, EIP:
It's movEAXEIP that I believe they're talking about. To do 'mov EIP, EAX' you'd just do 'jmp eax'.
Code: Select all
codeWantingEIP:
call movEAXEIP
; do stuff with EIP
movEAXEIP:
mov eax, [esp]
ret
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Re: EIP
No need for a RET, this works too, and is simpler.
Code: Select all
codeWantingEIP:
call next
next:
pop eax
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Re: EIP
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.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: EIP
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
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
-
- Member
- Posts: 524
- Joined: Sun Nov 09, 2008 2:55 am
- Location: Pennsylvania, USA
Re: EIP
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.
Code: Select all
mov eax, dword [esp]
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: EIP
Or just use
Code: Select all
getEip:
pop eax
jmp eax
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: EIP
not really a good idea, in general, because it will trash the CPUs CALL stack...thepowersgang wrote:Or just useCode: Select all
getEip: pop eax jmp eax
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Re: EIP
Aha! I knew there was something like that!
That's why I used the code I did.
That's why I used the code I did.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: EIP
callstack-friendly:
Code: Select all
pop eax
push eax
ret
- Firestryke31
- Member
- Posts: 550
- Joined: Sat Nov 29, 2008 1:07 pm
- Location: Throw a dart at central Texas
- Contact:
Re: EIP
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?
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?