|
-
October 14th, 2005, 08:54 AM
#1
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
-
October 14th, 2005, 10:05 AM
#2
Re: Current Instruction Address (register EIP)
Code:
unsigned int dwEip;
__asm{
call geip;
geip:
pop dwEip;
};
printf("\nValue of EIP:%08x",dwEip);
-
October 14th, 2005, 10:10 AM
#3
Re: Current Instruction Address (register EIP)
[ redirected ]
Regards,
Siddhartha
-
October 14th, 2005, 10:25 AM
#4
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
-
October 14th, 2005, 11:05 AM
#5
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
-
October 14th, 2005, 12:15 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|