Skip to content

Instantly share code, notes, and snippets.

@kostyll
Last active October 18, 2016 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostyll/20d165265444a0c033b9b4c4c6bd6d80 to your computer and use it in GitHub Desktop.
Save kostyll/20d165265444a0c033b9b4c4c6bd6d80 to your computer and use it in GitHub Desktop.
[test.asm]
[BITS 64]
section .code
global foo
export foo
foo:
push rbp
mov rbp, rsp
mov rbx, rcx
add rbx, 3
mov rax, rbx
pop rbp
ret
global DllMain@16
DllMain@16:
ret
[testdll.c]
#include <inttypes.h>
#include <windows.h>
#include <stdio.h>
typedef uint64_t (*tFoo)(uint64_t);
int main(int argc, char **argv) {
tFoo foo;
HMODULE testmodule = LoadLibrary("test.dll");
if ( !testmodule ) {
printf("Cannot load test.dll!\n");
return -1;
}
foo = (tFoo)GetProcAddress(testmodule, "foo");
if ( !foo ) {
printf("Cannot find foo function!");
return -1;
}
printf("foo() = %d\n", foo((uint64_t)34));
return 0;
}
[commands]
nasm -f win64 test.asm -o test.obj
/cross/mxe/usr/bin/x86_64-w64-mingw32.shared-ld test.obj -o test.dll
/cross/mxe/usr/bin/x86_64-w64-mingw32.shared-gcc testdll.c -o testdll.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment