section .data
title: db "Drop Groups v0.1",10,0
author: db "written by Philip Rushik",10,10,0
section .text
global _start
_start:
xor rbp,rbp ;AMD64 ABI Requirement
pop rdi ;Get argument count
mov rsi,rsp ;Get argument array
and rsp,-16 ;Align stack pointer
push rdi ;store arg count
push rsi ;store arg address
mov rax,1 ;write
mov rdi,1 ;stdout
mov rsi,title ;text to write
mov rdx,17 ;size
syscall ;do it
mov rax,1 ;write
mov rdi,1 ;stdout
mov rsi,author ;text to write
mov rdx,26 ;size
syscall ;do it
mov rax,116 ;setgroups
mov rdi,0 ;size = 0
lea rsi,0 ;groups = null
syscall
mov rax,57 ;fork - maybe vfork would be better
syscall
cmp rax,0 ;compare rax with 0
jnz parent ;if not 0, wait for child
child:
mov rax,59 ;execve
mov rsi,rsp ;args
add rsi,24 ;adjust this to be the right place
mov rdi,[rsi] ;use agv[1] as prog
add rdi,8 ;this is arg[1]
add rsi,8 ;arg[1] is also the program to run
mov rdx,0 ;nothing
syscall
jmp exit ;don't wait by accident
parent:
push rax ;save the pid
mov rax,61 ;wait4
pop rdi ;get back the pid
mov rsi,0 ;status - null (termination only)
mov rdx,0 ;0 - no options
mov r10,0 ;null
syscall
exit:
mov rax,60 ;exit
syscall
ret ;don't get here