Jump to content

Use another language to call a function: Difference between revisions

→‎UASM 2.52: reworked the UASM example, added NASM
(It is what it is -_-)
(→‎UASM 2.52: reworked the UASM example, added NASM)
Line 2,128:
<lang asm>
option casemap:none
 
 
strlen proto :qword
strncpy proto :qword, :qword, :dword
 
Query proto :qword, :qword
Line 2,136 ⟶ 2,140:
.code
Query proc Data:qword, len:qword
local d:qword, l:qword, s:dword
 
mov r9d, Data
mov r8l, len
movinvoke r10dstrlen, sizeof(addr szstr)
cmp.if r10,rax r8<= l
mov eaxs, 1eax
ja _err
invoke strncpy, d, addr szstr, s
mov ecx, r10d
mov rdieax, r9s
mov rsirax, offset szstrl
mov dword ptr [rax], r10decx
rep movsb
mov rax, r81
ret
mov dword ptr [rax], r10d
.endif
mov eax, 1
mov ecxrax, r10d0
ret
Query endp
</lang>
 
===NASM===
<lang asm>
section .data
szmsg db "Here I am",0
 
section .text
global Query
 
_errstrlen:
mov rax,0push rbp
mov rbp, rsp
mov rsi, rdi
mov rcx, -1
_1:
inc rcx
cmp byte [rsi+rcx], 0
jne _1
mov rax, rcx
pop rbp
ret
 
Query endp
Query:
end
push rbp
mov rbp, rsp
;;mov r9, rcx ;;Arg 1, windows
;;mov r8, rdx ;;Arg 2, windows
mov r9, rdi ;;Arg 1, Linux
mov r8, rsi ;;Arg 2, Linux
lea rdi, szmsg
call strlen
cmp rax, r8
jg _err
mov r10d, eax
mov rdi, r9
lea rsi, szmsg
rep movsb
mov rax, r8
mov dword [rax], r10d
jmp _exit
 
ja _err:
mov rax, 0
_exit:
pop rbp
ret
</lang>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.