| View previous topic :: View next topic |
| Author |
Message |
LolSalad Grandmaster Cheater
Reputation: 1
Joined: 26 Aug 2007 Posts: 988 Location: Australia
|
Posted: Sun May 17, 2009 6:07 am Post subject: [C++, inline ASM] Getting the value of EIP |
|
|
| Code: | #include <iostream>
#include <windows.h>
using std::cout;
using std::cin;
#define getEIP(ev) __asm { \
__asm call get_eip \
__asm sub eax, 5 \
__asm mov ev, eax \
}
int main(int argc, char** args) {
void* eipval;
getEIP(eipval);
cout << eipval;
cin.sync();
cin.ignore();
return EXIT_SUCCESS;
__asm {
get_eip:
mov eax, [esp]
ret
}
} |
This works, but I have to create the get_eip label after the return function in any functions that I want to use it in. Is there a more efficient way?
_________________
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Sun May 17, 2009 6:53 am Post subject: |
|
|
if it's code for in a static executable (so no relocations or whatever) then I think you can do: __asm mov my_var, $
$ will be replaced with the address of that instruction when compiled.
Otherwise you'll have to do something like:
| Code: |
__asm{
call blabla
blabla:
mov eax, [esp]
mov my_variable, eax
sub esp, 4
}
//now you have the eip of the 'call blabla' instruction in my_variable
|
|
|
| Back to top |
|
 |
|