Use nonvolatile registers for storage

This commit is contained in:
mkrsym1 2023-06-26 12:18:25 +03:00
parent a0e79dcea0
commit 851ebb5b9a
2 changed files with 35 additions and 29 deletions

View File

@ -1,65 +1,70 @@
BITS 64
main: ; Replacement entry point
push rbp
mov rbp, rsp
sub rsp, 30h + 90h
push rsi
push rdi
push r12
push r13
push r14
call GetKernel32ModuleHandle
mov [rbp - 8h], rax ; kernel32.dll
mov rsi, rax ; kernel32.dll
mov rcx, rax
call GetAddressOf_GetProcAddress
mov [rbp - 10h], rax ; *GetProcAddress
mov rdi, rax ; *GetProcAddress
mov rcx, [rbp - 8h] ; kernel32.dll
mov rcx, rsi ; kernel32.dll
lea rdx, [rel s_LoadLibraryA]
mov rax, [rbp - 10h] ; *GetProcAddress
mov rax, rdi ; *GetProcAddress
call rax ; rax = *LoadLibraryA
lea rcx, [rel dllPath]
call rax ; LoadLibraryA(dllPath)
mov rcx, [rbp - 8h] ; kernel32.dll
mov rcx, rsi ; kernel32.dll
lea rdx, [rel s_GetModuleHandleA]
mov rax, [rbp - 10h] ; *GetProcAddress
mov rax, rdi ; *GetProcAddress
call rax ; rax = *GetModuleHandle
mov [rbp - 18h], rax
mov r12, rax
mov rcx, 0
call rax ; rax = .exe base address
mov [rbp - 20h], rax
mov r13, rax
mov rcx, [rbp - 8h] ; kernel32.dll
mov rcx, rsi ; kernel32.dll
lea rdx, [rel s_GetCommandLineW]
mov rax, [rbp - 10h] ; *GetProcAddress
mov rax, rdi ; *GetProcAddress
call rax ; rax = *GetCommandLineW
call rax ; rax = command line
mov [rbp - 28h], rax
mov r14, rax
lea rcx, [rel s_UnityPlayer.dll]
mov rax, [rbp - 18h] ; *GetModuleHandleA
mov rax, r12 ; *GetModuleHandleA
call rax ; rax = UnityPlayer.dll
mov rcx, rax
lea rdx, [rel s_UnityMain]
mov rax, [rbp - 10h] ; *GetProcAddress
mov rax, rdi ; *GetProcAddress
call rax ; rax = *UnityMain
mov rcx, [rbp - 20h] ; .exe base address
mov rcx, r13 ; .exe base address
mov rdx, 0 ; hPrevInstance - 0
mov r8, [rbp - 28h] ; command line
mov r8, r14 ; command line
mov r9, 1 ; SW_NORMAL
call rax ; UnityMain(...)
add rsp, 30h + 90h
pop rbp
pop r14
pop r13
pop r12
pop rdi
pop rsi
ret

View File

@ -1,30 +1,31 @@
BITS 64
main: ; Replacement entry point
push rbp
mov rbp, rsp
sub rsp, 10h + 90h
push rsi
push rdi
sub rsp, 8h
call GetKernel32ModuleHandle
mov [rbp - 8h], rax ; kernel32.dll
mov rsi, rax ; kernel32.dll
mov rcx, rax
call GetAddressOf_GetProcAddress
mov [rbp - 10h], rax ; *GetProcAddress
mov rdi, rax ; *GetProcAddress
mov rcx, [rbp - 8h] ; kernel32.dll
mov rcx, rsi ; kernel32.dll
lea rdx, [rel s_LoadLibraryA]
mov rax, [rbp - 10h] ; *GetProcAddress
mov rax, rdi ; *GetProcAddress
call rax ; rax = *LoadLibraryA
lea rcx, [rel dllPath]
call rax ; LoadLibraryA(dllPath)
add rsp, 10h + 90h
pop rbp
add rsp, 8h
pop rdi
pop rsi
ret