Can I programmatically infer the calling convention used by the C ++ dll?

Imagine you want to write a program that checks functions in a C ++ dll file. You must allow the user to choose a dll (we assume that we are talking about a C ++ dll). It should be able to get a list of all the functions exported by the dll. Then the user should be able to select a function name from the list, manually enter a list of arguments (arguments are all basic types, such as int, double, bool or char arrays (for example, c-type strings)) and try to run the selected function with the specified arguments . He would like to know if the function works with the specified arguments or they lead to its failure (because they do not match the signature, for example).

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

The only solution I came across was to use assembly to manually enter arguments into the call stack.

However, I realized that if I want to communicate with the assembly, I have to make sure that I know what calling convention are functions in the dll using.

So (finally :) here is my question: can I infer the calling convention programmatically? Dependency Walker will not help me, and I do not know how to manually read the PE format.

+5
5

.

++, , , , MSVC .

stdcall ( windows api), , , .

, C , . .

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

, , , - , , , , , .

+3

, 32- 64- , , , 32- . 64- Windows , , ( , ), , do (, - ).

, Microsoft x64, , , , /. , , , . - , [] - , , , .

+3

: " fastcall, , stdcall".

, IDA, ( - idk).

, , 90% . pop push, stdcall, ( ecx), cdecl. Fastcall , - .. dunno . , , , .

, , , ? .

+2

, ++, -

  • , ,
  • , DLL.

, . , , , , ?

0

All Articles