Click to See Complete Forum and Search --> : Current Instruction Address (register EIP)


lhayes00
October 14th, 2005, 08:54 AM
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

kernel_gaddafi
October 14th, 2005, 10:05 AM
unsigned int dwEip;

__asm{

call geip;
geip:
pop dwEip;
};

printf("\nValue of EIP:%08x",dwEip);

Siddhartha
October 14th, 2005, 10:10 AM
[ redirected ]

Regards,
Siddhartha

lhayes00
October 14th, 2005, 10:25 AM
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:

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

rxbagain
October 14th, 2005, 11:05 AM
Here's the C/C++ codevoid __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

lhayes00
October 14th, 2005, 12:15 PM
Hi,

Brilliant, that is exactly what I needed! :)

Lea Hayes