amxmodx/amxmodx/natives-amd64.asm

92 lines
2.4 KiB
NASM
Raw Normal View History

2005-07-31 20:11:58 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2005-08-01 19:05:10 +00:00
; (C)2005 by David "BAILOPAN" Anderson ;
; register_native functions for amd64 ;;;;;;
; Based on the concept by Julien "dJeyL" Laurent ;
2005-07-31 20:11:58 +00:00
; Thanks to T(+)rget for pushing me to implement this ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Licensed under the GNU General Public License, version 2
;;This is a portion of AMX Mod X
;; and is maintained by the AMX Mod X development team.
;;Initializes the global variable
BITS 64
section .text
global amxx_DynaInit, _amxx_DynaInit
;void amxx_DynaInit(void *ptr);
amxx_DynaInit:
_amxx_DynaInit:
2005-08-01 02:23:42 +00:00
mov [GLOBAL_GATE wrt rip], rdi
2005-07-31 20:11:58 +00:00
ret
;;Assembles the gateway function
global amxx_DynaMake, _amxx_DynaMake
;int amxx_DynaMake(char *buffer, int id);
amxx_DynaMake:
_amxx_DynaMake:
;we're not damaging the stack I think so we should be safe with no prologue
;save these two we're about to destroy them
2005-08-01 02:23:42 +00:00
push rsi ;push id
push rdi ;push buffer
2005-07-31 20:11:58 +00:00
mov rsi, _amxx_DynaFuncStart
mov rcx, _amxx_DynaFuncEnd - _amxx_DynaFuncStart
cld ;clear direction flag (just in case)
rep movsb
pop rdi ;get buffer as destination
pop rax ;get id
;align us to mov rsi, 1234... - on x86-64 this is 2 bytes after the differential
2005-08-01 02:23:42 +00:00
add rdi, (_amxx_DynaFuncStart.move-_amxx_DynaFuncStart) + 2
2005-07-31 20:11:58 +00:00
mov [rdi], qword rax
2005-08-01 02:23:42 +00:00
;align rdi to the call
add rdi, (_amxx_DynaFuncStart.call-_amxx_DynaFuncStart.move)
mov rax, qword [GLOBAL_GATE wrt rip]
;copy the real address
mov [rdi], rax
2005-07-31 20:11:58 +00:00
ret
;;The gateway function we will re-assemble
;; This is similar to dJeyL's but a tad more elegant, as it's written in pure assembly
;; and NASM > GAS :')
global amxx_DynaFunc, _amxx_DynaFunc
;int amxx_DynaFunc(AMX *amx, cell *params);
amxx_DynaFunc:
_amxx_DynaFunc:
_amxx_DynaFuncStart:
2005-08-01 02:23:42 +00:00
push rbp
2005-07-31 20:11:58 +00:00
mov rbp, rsp
;we're given an amx and params... we're also hardcoded for this though:
mov rdx, rsi ;move 2nd param to 3rd
mov rsi, rdi ;move 1st param to 2nd
;this old trick, we'll move in the real pointer in a bit.
2005-08-01 02:23:42 +00:00
.move:
mov rdi, qword 1234567812345678h
.call:
mov rcx, qword 1234567812345678h
call rcx
2005-07-31 20:11:58 +00:00
pop rbp
ret
_amxx_DynaFuncEnd:
;;Just returns the buffer size required
global _amxx_DynaCodesize, amxx_DynaCodesize
;int amxx_DynaCodesize()
amxx_DynaCodesize:
_amxx_DynaCodesize:
2005-08-01 19:05:10 +00:00
; on x86-64 this is 34 bytes
2005-07-31 20:11:58 +00:00
mov rax, _amxx_DynaFuncEnd - _amxx_DynaFuncStart
ret
2005-08-01 02:23:42 +00:00
section .data
2005-07-31 20:11:58 +00:00
GLOBAL_GATE DQ 0