找到你要的答案

Q:Getting information about a function address

Q:获取有关函数地址的信息

Yes, it's one of "these" questions again.

I got a basic reflection framework up and running, although it still requires the front end user to manually register each method (including return type, argument). However I got the idea of making each function virtual which needs to be reflected, as (even though it's compiler dependent) those functions should technically be in the vtable (if not optimized out). So I got to the point where I got the address of each function, and successfully call/execute each. However, is there a way to "get" the return type, and argument types given the address of this function.

Now before you say this is impossible, I don't mind the weirdest way, hackiest way, since I'm only doing this for the challenge. However I do not want preparsing method, or anything similar, as that is not my aim.

是的,这是一个“这些”问题。

我得到了一个基本的反射框架和运行,虽然它仍然需要前端用户手动注册每个方法(包括返回类型,参数)。然而我使每个功能的虚拟需要体现的理念,作为(即使它的编译依赖)这些功能应该是在vtable(如果不是优化了)。所以我得到了我得到每个函数的地址,并成功地调用/执行每个。但是,是否有方法“获取”返回类型,以及给定该函数地址的参数类型。

现在,在你说这是不可能的,我不介意的方式,hackiest方式,因为我只有这样的挑战。但是我不想preparsing方法,或类似的话,因为这不是我的目的。

answer1: 回答1:

use a decompiler or a debugger (idapro, ollydebug, windasm ... ) then check how many push there are before the call to that function to guess argument, and try to find what was stored in eax to know what is the return. this is low-level stuff, it is not an easy task at all.

使用反编译器和调试器(IDAPro、OllyDebug、windasm…)然后检查之前有称为函数猜测争论多少推,并试图找出什么是存储在EAX知道回报是什么。这是低级的东西,这不是一件容易的事。

answer2: 回答2:

In C++11, you can make your registration and call interface use a template such as:

template <class Return, class... Args>

You can then specialize it to store type information in the registration function and compare it to the runtime arguments: basically, serialize a type object through template metaprogramming, compare, cast the function pointer to the required type, and call it with the argument list.

在C++ 11,你可以让你的注册和调用接口使用一个模板等:

template <class Return, class... Args>

然后你可以专门存储类型信息在注册功能和比较它的运行参数:基本上,序列化类型对象通过模板元编程,比较,把函数指针所需要的类型,并调用它的参数列表。

c++  reflection