Skip to content

Instantly share code, notes, and snippets.

@crcx
Created April 27, 2017 18:39
Show Gist options
  • Save crcx/fb3256cee3c56e9adfe31db248477c28 to your computer and use it in GitHub Desktop.
Save crcx/fb3256cee3c56e9adfe31db248477c28 to your computer and use it in GitHub Desktop.
lib_addr dd 0
; void *dlopen(const char *file, int mode);
code 'from', _from
upsh 32
call parse
embed 'zt'
upop edx
pusha
push 0
push edx
call dlopen
add esp, 8
mov dword [lib_addr], eax
popa
next
; void *dlsym(void *restrict handle, const char *restrict name);
code 'import', _import
pusha
upsh 32
call parse
embed '2dup entry zt'
upop edx
push edx
push [lib_addr]
call dlsym
add esp, 8
call literal
popa
call literal
upsh _pascal_invoke
call compile
jmp ssemi
code 'cimport', _cimport
pusha
upsh 32
call parse
embed '2dup entry zt'
upop edx
push edx
push [lib_addr]
call dlsym
add esp, 8
call literal
popa
call literal
upsh _c_invoke
call compile
jmp ssemi
_pascal_invoke:
swap
upop [faddr] ; Get the function address
upop ecx
cmp ecx, 0
jz .run
.chain: push eax
drop
loop .chain
.run: upsh [faddr] ; Restore the function address
call dword eax
next
_c_invoke:
swap
upop [faddr] ; Get the function address
xor ebx,ebx
upop ecx
cmp ecx, 0
jz .run
.chain: push dword eax
drop
add ebx, 4
loop .chain
.run: mov dword [tempX], ebx
upsh [faddr] ; Restore the function address
call dword eax
mov ebx, dword [tempX]
add esp, ebx
next
faddr dd 0
tempX dd 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment