Commit 49a5d7ba authored by PoroCYon's avatar PoroCYon
Browse files

add lzma/gzip option, clean up makefile

parent 2710ed9b
header_test-32: header-32 Makefile
lzma --format=lzma -9 --extreme --lzma1=preset=9,lc=1,lp=0,pb=0 --keep --stdout /bin/ls > ls.xz
cat header-32 ls.xz > header_test-32
chmod +x header_test-32
wc -c header_test-32
LIST :=
ifneq ($(MKLIST),)
LIST := -l header-BITS.list
endif
all: header-32 header-64
test: header_test-32 header_test-64
header-32 : header-32.asm Makefile
nasm -f bin -o header-32 header-32.asm -l header-32.list
chmod +x header-32
wc -c header-32
header-%: header-%.asm
nasm -fbin -o "$@" "$<" $(subst BITS,$*,$(LIST))
@chmod +x "$@"
@wc -c "$@"
header_test: header Makefile
header_test-%: header-%
lzma --format=lzma -9 --extreme --lzma1=preset=9,lc=1,lp=0,pb=0 --keep --stdout /bin/ls > ls.xz
cat header ls.xz > header_test
chmod +x header_test
wc -c header_test
@cat "$<" ls.xz > "$@"
@chmod +x "$@"
@wc -c "$@"
clean:
@-rm -vf header{,_test}-{32,64} header-{32,64}.list ls.xz
.PHONY: all test clean
header : header.asm Makefile
nasm -f bin -o header header.asm -l header.list
chmod +x header
wc -c header
......@@ -122,13 +122,13 @@ _parent:
mov dl, 16+8
add edx, esp
; execve demo
; execve demo
mov eax, sys_execve
mov ecx, esp ;use our args as args
int 0x80
_child:
; open self
; open self
mov ebx, __self
mov al, sys_open ;open
int 0x80
......@@ -157,11 +157,14 @@ _child:
;execve
mov al, sys_execve
; mov edi, __gzip
%ifdef USE_GZIP
mov edi, __gzip
%else
push 0
push __gzip
pop ebx
push ebx
%endif
; use our arguments
mov ecx, esp
; xor rdx, rdx ;empty environ
......@@ -175,11 +178,15 @@ _child:
; ; ===========================
__gzip:
db '/usr/bin/xzcat',0,
%ifdef USE_GZIP
db '/bin/zcat',0
%else
db '/usr/bin/xzcat',0
%endif
__self:
db '/proc/self/exe',0
__memfd:
db '/dev/fd/3',0
filesize equ $ - $$
filesize equ $ - $$
\ No newline at end of file
......@@ -9,7 +9,7 @@ BITS 64
org 0x00400000
;a bunch of definitions so I don't have to memorize syscall numbers
%include "syscalls.asm"
%include "syscalls-64.asm"
;this is a hack that's 2 bytes smaller than mov!
;works best between registers, for constants not so much
......@@ -136,7 +136,7 @@ _parent:
mov dl, 16+8
add rdx,rsp
; execve demo
; execve demo
mov al, sys_execve
minimov rsi, rsp ;use our args as args
syscall
......@@ -148,9 +148,9 @@ _child:
mov edi, `exe\x00`
mov [rel __hi_were_the_replacements], edi
; open self
; open self
pop rdi
mov al, sys_open ;open
syscall
......@@ -178,11 +178,14 @@ _child:
;execve
mov al, sys_execve
; mov edi, __gzip
%ifdef USE_GZIP
mov edi, __gzip
%else
push 0
push __gzip
pop rdi
push rdi
%endif
; use our arguments
minimov rsi, rsp
; xor rdx, rdx ;empty environ
......@@ -195,15 +198,19 @@ _child:
__gzip:
;e_shoff and e_flags are 12 bytes and can be nonsense
db '/usr/bin/xzcat',0,
%ifdef USE_GZIP
db '/bin/zcat',0
%else
db '/usr/bin/xzcat',0
%endif
;replacing the "fd/3" with "exe\0" on the fly saves... 4 bytes
;its actually good we did this because the __memfd load into register
;its actually good we did this because the __memfd load into register
;can be done before fork so that both processes get it
__memfd:
db '/proc/self/'
__hi_were_the_replacements:
db 'fd/3',0
filesize equ $ - $$
filesize equ $ - $$
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment