Skip to content

Instantly share code, notes, and snippets.

@razvand
Last active November 29, 2015 15:01
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 razvand/a9dbb356d2344723408c to your computer and use it in GitHub Desktop.
Save razvand/a9dbb356d2344723408c to your computer and use it in GitHub Desktop.
Calling external functions from within SASM on Windows (x86, 32 bit)
%include "io.inc"
extern _malloc
extern _printf
extern _strcpy
extern _puts
extern _free
section .data
print_format: db "ret: %p", 13, 10, 0
malloc_ret: dd 0
section .text
global CMAIN
CMAIN:
push ebp
mov ebp, esp
mov al, 0x61
PRINT_CHAR al
PRINT_CHAR 13
PRINT_CHAR 10
push 100
call _malloc
add esp, 4
; Save malloc pointer value.
mov dword [malloc_ret], eax
push eax
push print_format
call _printf
add esp, 8
push print_format
push dword [malloc_ret]
call _strcpy
add esp, 8
push dword [malloc_ret]
call _puts
add esp, 4
push dword [malloc_ret]
call _free
add esp, 4
leave
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment