From c2c4447632dbfb082c7b5b5720edd27424db7b82 Mon Sep 17 00:00:00 2001 From: Kimapr Date: Wed, 3 Apr 2024 17:18:26 +0500 Subject: [PATCH] meow --- build | 9 +++++++ meow.s | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test | 2 ++ 3 files changed, 95 insertions(+) create mode 100755 build create mode 100644 meow.s create mode 100755 test diff --git a/build b/build new file mode 100755 index 0000000..a6898b1 --- /dev/null +++ b/build @@ -0,0 +1,9 @@ +#!/bin/sh +#~/stuff/zig/zig cc -static -nostdlib -nodefaultlibs meow.s -o amogus || exit +#gcc -static -nostdlib -nodefaultlibs meow.s -o amogus.o || exit +gcc -c meow.s -o amogus.o || exit +~/stuff/zig/zig cc -static -nostdlib -nodefaultlibs amogus.o -o amogus || exit +#clang -static -nostdlib -nodefaultlibs meow.s -o amogus || exit +objdump -d amogus +strip -K entry amogus +du -b amogus diff --git a/meow.s b/meow.s new file mode 100644 index 0000000..812b5cb --- /dev/null +++ b/meow.s @@ -0,0 +1,84 @@ +.globl _start +.type _start, @function +.globl entry +.type entry, @function +_start: + #mov -4(%ebp),%eax + pop %rax + mov %rax,argc(%rip) + mov %rax,%rdi + pop %rax + mov %rax,argv(%rip) + cmp $1,%rdi + jg endif + mov $1,%rdi + call usage + jmp _exit +endif: + + mov $0,%rdi + jmp _exit + +usage: + lea help0(%rip),%rdi + mov $help0l,%rsi + + call write + + mov [argv],%rdi + push %rdi + call strlen + pop %rdi + mov %rax,%rsi + call write + + lea help1(%rip),%rdi + mov $help1l,%rsi + call write + + ret + +# rdi - buf +# -> rax - len +strlen: + mov %rdi,%rax + strlen_loop: + movb 0(%rax),%sil + inc %rax + test %sil,%sil + jnz strlen_loop + sub $1,%rax + sub %rdi,%rax + ret + +# rdi - buf +# rsi - len +write: + push %rdi + push %rsi + pop %rdx + pop %rsi + mov $1,%rax + mov $1,%rdi + syscall + ret +help0: + .ascii "Usage: " + .set help0l, .-help0 +help1: + .ascii " regex0 [regex1 ...]\nstdout: NUL-separated list of matching strings\n" + .set help1l, .-help1 +_exit: + mov $0x3c,%rax + syscall + ret +entry: + ret + +.bss +argc: + .zero 8 +argv: + .zero 8 +buf: + .zero 65536 diff --git a/test b/test new file mode 100755 index 0000000..aa89e17 --- /dev/null +++ b/test @@ -0,0 +1,2 @@ +#!/bin/sh +./build && gdb -iex 'set confirm no' -ex 'run' amogus