CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2002
    Location
    United Kingdom
    Posts
    491

    Current Instruction Address (register EIP)

    Hi,

    I am creating some specialised exception handling code for a set of apps I am creating. I need to know how to retrieve the current instruction address, i.e. the value of register EIP into a variable of type LPVOID. Does anybody know how this can be done without having to write any assembly code.

    If not how can I create some nested assembly code to do this?

    The value from EIP will not be modified in any way, I just want to output it to the user in some way.

    Any help would be greatly appreciated!

    Best Regards,
    Lea Hayes

  2. #2
    Join Date
    Oct 2005
    Posts
    6

    Re: Current Instruction Address (register EIP)

    Code:
    	unsigned int dwEip;
    
    	__asm{
    	
    		call  geip;
    geip:
    		pop	dwEip;
    	};
    	
    	printf("\nValue of EIP:%08x",dwEip);

  3. #3
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: Current Instruction Address (register EIP)

    [ redirected ]

    Regards,
    Siddhartha

  4. #4
    Join Date
    Jan 2002
    Location
    United Kingdom
    Posts
    491

    Re: Current Instruction Address (register EIP)

    Hi,

    That works great; thanks for that.

    Do you know how I could extend this slightly so it could go inside a C++ function? For example:

    Code:
    void MyFunc()
    {
        unsigned int dwEip;
        __asm {...}
    
       printf("\nValue of EIP:%08x",dwEip);
    }
    
    void AnotherFunc()
    {
       // some code
    
       MyFunc();   // which displays the EIP of this line.
    }
    If it isn't possible i'll just create a macro, but it would be handy if it were possible.

    Thanks for your help.
    Lea

  5. #5
    Join Date
    Apr 2003
    Posts
    1,755

    Smile Re: Current Instruction Address (register EIP)

    Here's the C/C++ code
    Code:
    void __stdcall GetEIP(void **ppeip_ret)
    {   
       void **ppeip = (void**)&ppeip_ret;
       *ppeip_ret = ppeip[-1];
    }
    
    
    void main()
    {  
       void *pv = NULL;
       GetEIP(&pv);
    
       ...
    
    }
    Hope it will help you

  6. #6
    Join Date
    Jan 2002
    Location
    United Kingdom
    Posts
    491

    Re: Current Instruction Address (register EIP)

    Hi,

    Brilliant, that is exactly what I needed!

    Lea Hayes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured