函数指针设置为静态地址 [英] Set a function pointer to a static address

查看:133
本文介绍了函数指针设置为静态地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注入DLL到另一个进程,并想调用一个函数,在二进制基础上的地址(0x54315)。

如何才能真正宣告一个函数,然后将其设置到这个地址?

 的#define FUNC 0x54315无效* myFuncPtr;诠释的main()
{
 myFuncPtr = FUNC; // pretty肯定这不是如何 myFuncPtr(); // 叫它?
}


解决方案

现有的答案工作,但你甚至不需要为函数指针的变量。你可以做:

 的#define MYFUNC((无效(*)(无效))0x54315)

然后调用它作为 MYFUNC()就像你普通函数。请注意,你应该改变类型中投符合实际的参数和返回类型的功能。

I'm injecting a DLL into another process and want to call a function that is in that binary based on it's address (0x54315).

How can I actually declare a function, and then set it to this address?

#define FUNC 0x54315

void *myFuncPtr;

int main()
{
 myFuncPtr = FUNC;  // pretty sure this isn't how

 myFuncPtr(); // call it?
}

解决方案

The existing answers work, but you don't even need a variable for the function pointer. You can just do:

#define myfunc ((void (*)(void))0x54315)

and then call it as myfunc() just like you would an ordinary function. Note that you should change the type in the cast to match the actual argument and return types of the function.

这篇关于函数指针设置为静态地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆