[2.0-rc.1] Native.ahk - A way for binding third-party dll libraries to AHK, and create native functions from MCode

Post your working scripts, libraries and tools.
User avatar
thqby
Posts: 433
Joined: 16 Apr 2021, 11:18
Contact:

Re: [2.0-rc.1] Native.ahk - A way for binding third-party dll libraries to AHK, and create native functions from MCode

25 Nov 2022, 10:01

You can obtain all the exported function names and addresses, but you still need to provide the function parameter information yourself.

Of course, you can also parse the header file and extract this information. However, due to the complexity of the header file syntax, it may not be reliable. I am currently trying to generate and export function signatures through the c++compiler.
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: [2.0-rc.1] Native.ahk - A way for binding third-party dll libraries to AHK, and create native functions from MCode

25 Nov 2022, 20:30

thqby wrote:
25 Nov 2022, 05:57
I know this, but I'm confused that I didn't see the code of the recovery stack in mdfunc.
Of course it won't be in MdFunc, because C++ can't manipulate the stack pointer directly; but you probably didn't meant that so literally.

The low level implementation for x86 is in x86call.asm, DynaCall. MASM automatically inserts the following prologue and epilogue:

Code: Select all

push ebp
mov ebp, esp
...
leave
leave is exactly equivalent to:

Code: Select all

mov esp, ebp
pop ebp
enter would be equivalent to the first two instructions, but it's purportedly less efficient.

I am currently trying to generate and export function signatures through the c++compiler.
If this is for standard Windows functions, you might consider using the metadata from win32metadata. Reading it is very similar to reading the WinRT metadata.
eugenesv
Posts: 178
Joined: 21 Dec 2015, 10:11

Re: create function or method with native code

12 Sep 2023, 12:18

neogna2 wrote:
14 Feb 2022, 07:34
Thanks. Here is an example of those steps for anyone else following along.
Paste the C++ source int add(int a, int b) { return a + b; } into Godbolt and choose x64 msvc v19.latest and set flags /FAc /O2 to get this output
by the way, if you're going the web route with Godbolt you could also use https://asmjit.com/parser.html to produce the concatenated hex machine code in the website's hex-dump section by pasting the assembly instructions (can select gcc in Godbolt to remove some extra labels that msvc has to avoid cleaning them up, and if you use msvc don't need /..c flag, only /Fa since you don't need those mcodes anymore)
so pasting from gcc's output with -O3

Code: Select all

_Z3addii:
        lea     eax, [rdi+rsi]
        ret
to the asmjit site will get you the same 8D0437C3

and msvc's 8D0411C3 from

Code: Select all

        lea     eax, DWORD PTR [rcx+rdx]
        ret     0

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 47 guests