fix several issues relating to elf and registers and add mmap

This commit is contained in:
Matheus
2022-08-18 17:50:34 -03:00
parent fc6d0000c5
commit 0984a6458d
9 changed files with 243 additions and 34 deletions
+18 -14
View File
@@ -5,6 +5,12 @@ section .text
push rbp
mov rbp, [rsp+24] ; save CS for usermode checking
; check and patch ss if it is invalid because of the syscall instruction
cmp qword [rsp+48], 0x33
jne .keepgoing
mov qword [rsp+48], 0x43
.keepgoing:
push rsi
push rdi
push r15
@@ -22,12 +28,13 @@ section .text
mov rax, ds
cmp rax,0x40
cmp rbp,0x3b
jne .noswapgs
swapgs
.noswapgs:
mov rax, ds
push rax
mov rax, es
push rax
@@ -38,10 +45,10 @@ section .text
; now use kernel segments for data
mov rax, 0x30
mov ds, rax
mov es, rax
mov ss, rax
;mov rax, 0x38
;mov ds, rax
;mov es, rax
;mov ss, rax
mov rdi,cr2
push rdi
@@ -52,18 +59,15 @@ section .text
add rsp, 24 ; cr2 gs fs
cmp rbp,0x3b
jne .noswapgspop
swapgs
.noswapgspop:
pop rax
cmp rax,0x43
je .dontpopsegs
mov es,rax
pop rax
mov ds,rax
swapgs
jmp .poprest
.dontpopsegs:
add rsp,8 ; ds
.poprest:
pop rax
pop rbx
pop rcx
+8 -4
View File
@@ -2,12 +2,13 @@ section .rodata
extern syscall_libc_log
func_count equ 1
extern syscall_mmap
func_count equ 2
func_table:
dq syscall_libc_log
dq syscall_mmap
section .text
global asm_syscall_entry
@@ -45,11 +46,14 @@ asm_syscall_entry:
push r8
push r9
push r10
; system V C abi expects the third param to be in rcx
; but the param is in rdx because of the syscall instruction
mov rcx, rdx
mov rcx, r10
call [func_table + rax * 8]