I'm trying to get the function address to copy its content into a buffer using memcpy.
The problem I'm having is with getting function address. Here is my code:
__declspec(noinline) int gio()
{
const char yle[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
return 7;
}
int main(int argc, TCHAR* argv[])
{
int(*funcptr)() = gio;
unsigned char *p = (unsigned char *)&funcptr;
size_t ik;
for (ik = 0; ik < sizeof funcptr; ik++)
{
printf("%02x ", p[ik]);
}
putchar('\n');
printf("gio x -> %x\n", gio);
printf("gio p -> %p\n", gio);
}
I created a little test program where I try to print function address with different ways.
I'm using Visual Studio and had turn off the optimization and inline function expansion(but used noinline anyway). all the print statements print same output(0x00d213ca
screenshot) but when I put my cursor(inside VS) on gio
function it shows totally different address(0x00d218c0
screenshot).
When I right click on gio function and Go To Dissasembler
I jump to the address which was shown when I put my cursor on it(0x00d218c0
screenshot). Which clearly shows where this function really is.
I got little confused here, seems like I don't understand something.
Why do print statements show incorrect value? What is the way to get the "real" function address?