我可以推断编程用C ++ DLL使用的调用约定? [英] Can I programatically deduce the calling convention used by a C++ dll?

查看:123
本文介绍了我可以推断编程用C ++ DLL使用的调用约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你想编写一个C ++ DLL文件测试功能的程序。
你应该让用户选择一个DLL(我们假定我们在谈论C ++动态链接库)。
他应该能够获得的由DLL导出的所有函数的列表。
然后,用户应该能够从列表中选择一个函数名,手工输入的参数列表(参数是所有的基本类型,如int,双,布尔或字符数组(如C型字符串)),并尝试运行用指定的参数选择的功能。
他想知道如果函数使用指定的参数运行,还是他们导致崩溃(因为他们没有例如签名一致)。

Imagine you'd like to write a program that tests functions in a c++ dll file. You should enable the user to select a dll (we assume we are talking about c++ dlls). He should be able to obtain a list of all functions exported by the dll. Then, the user should be able to select a function name from the list, manually input a list of arguments ( the arguments are all basic types, like int, double, bool or char arrays (e.g. c-type strings) ) and attempt to run the selected function with the specified arguments. He'd like to know if the function runs with the specified arguments, or do they cause it to crash ( because they don't match the signature for example ).

主要的问题是,C ++,是一个强类型语言,你需要知道的论据,在我的情况在编译time.And函数调用的数量和类型,我根本不知道这些参数是,直到用户在运行时选择它们。

The main problem is that C++, being a strongly typed language, requires you to know the number and type of the arguments for a function call at compile time.And in my case, I simply don't know what these arguments are, until the user selects them at runtime.

我想出了,唯一的解决办法是使用装配手动推调用堆栈上的参数。

The only solution I came up with, was to use assembly to manually push the arguments on the call stack.

不过,我已经认识到,如果我想惹组装,我最好做该死的肯定,我知道这调用约定在DLL中的功能使用。

However, I've come to understand that if I want to mess with assembly, I'd better make damn sure that I know which calling convention are the functions in the dll using.

所以,(终于:)这里是我的问题:我可以推断programmaticaly调用约定? Dependency Walker中不会帮我,我不知道如何手动读取PE格式。

So (finally:) here's my question: can I deduce the calling convention programmaticaly? Dependency Walker won't help me, and I've no idea how to manually read PE format.

推荐答案

答案的也许

如果该函数的名称是C ++的装饰,那么就可以确定从名字装修参数个数和类型,这是你最好的情况下,且相当容易,如果MSVC被用来写code放在第一位

If the functions names are C++ decorated, then you can determine the argument count and types from the name decoration, this is your best case scenario, and fairly likely if MSVC was used to write the code in the first place.

如果导出功能stdcall调用约定(Windows API的默认设置),可以判断的字节数要推,而不是类型的参数。

If the exported functions are stdcall calling convention (the default for windows api), you can determine the number of bytes to be pushed, but not the types of the arguments.

坏消息是,C调用约定,没有任何办法通过查看符号名告诉。您需要能够访问源$ C ​​$ c或调试信息。

The bad news is that for C calling convention, there isn't any way to tell by looking at the symbol names. You would need to have access to the source code or the debug info.

http://en.wikipedia.org/wiki/X86_calling_conventions

这一个功能是作为出口的名称不是的需要的有与连接器看到名称的任何关系,但大部分时间,导出的名称和符号名的链接程序将是相同的。

The name that a function is given as an export is not required to have any relationship with the name that the linker sees, but most of the time, the exported name and the symbol name that the linker sees are the same.

这篇关于我可以推断编程用C ++ DLL使用的调用约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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