Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++, inline ASM] Getting the value of EIP

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
LolSalad
Grandmaster Cheater
Reputation: 1

Joined: 26 Aug 2007
Posts: 988
Location: Australia

PostPosted: Sun May 17, 2009 6:07 am    Post subject: [C++, inline ASM] Getting the value of EIP Reply with quote

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
View user's profile Send private message MSN Messenger
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sun May 17, 2009 6:49 am    Post subject: Reply with quote

http://msdn.microsoft.com/en-us/library/64ez38eh(VS.71).aspx
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sun May 17, 2009 6:53 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites