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
Re: Current Instruction Address (register EIP)
Code:
unsigned int dwEip;
__asm{
call geip;
geip:
pop dwEip;
};
printf("\nValue of EIP:%08x",dwEip);
Re: Current Instruction Address (register EIP)
[ redirected ]
Regards,
Siddhartha
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
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
Re: Current Instruction Address (register EIP)
Hi,
Brilliant, that is exactly what I needed! :)
Lea Hayes