mrrrp
This commit is contained in:
parent
07c7f6df35
commit
e1efc5acaf
12
build
12
build
|
@ -1,15 +1,17 @@
|
|||
#!/bin/sh
|
||||
mkdir -p target
|
||||
./charjmpt.lua > target/charjmpt.s
|
||||
gcc -c meow.s -o target/amogus.o || exit
|
||||
gnu() { shift 1 && gcc "$@"; }
|
||||
gnu() { shift 1 && clang "$@"; }
|
||||
"$(command -v ~/stuff/zig/zig || echo gnu)" \
|
||||
cc -O3 -shared -static -nostdlib -nodefaultlibs target/amogus.o -o target/amogus || exit
|
||||
objdump -d target/amogus
|
||||
strip -K entry target/amogus
|
||||
objdump -t target/amogus
|
||||
du -b target/amogus
|
||||
cp target/amogus target/amogstrip
|
||||
strip -K entry target/amogstrip
|
||||
objdump -t target/amogstrip
|
||||
du -b target/amogstrip
|
||||
rm -rf target/cg/
|
||||
mkdir -p target/cg
|
||||
cp target/amogus target/cg/
|
||||
cp target/amogstrip target/cg/amogus
|
||||
cp amogus.h target/cg/
|
||||
|
||||
|
|
10
charjmpt.lua
Executable file
10
charjmpt.lua
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env lua
|
||||
print("charjmpt:")
|
||||
chars = {
|
||||
['\0'] = "parse_exit",
|
||||
}
|
||||
local def = "parse_self"
|
||||
for n=0,255 do
|
||||
local c = string.char(n)
|
||||
print("\t.4byte "..(chars[c] or "parse_self").." - charjmpt_prej")
|
||||
end
|
8
ctest
8
ctest
|
@ -3,5 +3,9 @@
|
|||
export C_INCLUDE_PATH="$PWD:$C_INCLUDE_PATH"
|
||||
export LD_LIBRARY_PATH="$PWD/target:$LD_LIBRARY_PATH"
|
||||
export LIBRARY_PATH="$PWD/target:$LIBRARY_PATH"
|
||||
gcc test.c -o target/cmogus -L"$LIBRARY_PATH" -l:amogus || exit
|
||||
target/cmogus
|
||||
gcc -O2 test.c -o target/cmogus -L"$LIBRARY_PATH" -l:amogus || exit
|
||||
gdb -q \
|
||||
-iex 'set confirm no' \
|
||||
-ex 'layout asm' \
|
||||
-ex 'start' \
|
||||
target/cmogus
|
||||
|
|
57
meow.s
57
meow.s
|
@ -3,7 +3,6 @@
|
|||
.globl entry
|
||||
.type entry, @function
|
||||
_start:
|
||||
#mov -4(%ebp),%eax
|
||||
pop %rax
|
||||
mov %rax,argc(%rip)
|
||||
mov %rax,%rdi
|
||||
|
@ -72,19 +71,59 @@ _exit:
|
|||
syscall
|
||||
ret
|
||||
|
||||
.include "target/charjmpt.s"
|
||||
|
||||
# rdi - where
|
||||
# rsi - char
|
||||
#parse_...:
|
||||
|
||||
parse_self:
|
||||
xor %rax,%rax
|
||||
ret
|
||||
|
||||
parse_exit:
|
||||
mov $1,%rax
|
||||
ret
|
||||
|
||||
|
||||
# rdi - regex
|
||||
# rsi - callback
|
||||
# rdx - cb data
|
||||
entry:
|
||||
push %r12
|
||||
sub $8,%r12
|
||||
mov %rsp,%r12
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
sub $48,%rsp
|
||||
mov %rsi,-8(%rbp)
|
||||
mov %rdx,-16(%rbp)
|
||||
mov %rdi,-24(%rbp)
|
||||
entry_parse_begin:
|
||||
test %rdi,%rdi
|
||||
movzbl (%rdi),%ecx
|
||||
lea charjmpt(%rip),%r11
|
||||
movzx %cl,%r10
|
||||
shl $2,%r10
|
||||
add %r10,%r11
|
||||
movsxd (%r11),%r11
|
||||
charjmpt_prej:
|
||||
lea charjmpt_prej(%rip),%r10
|
||||
add %r10,%r11
|
||||
mov %rdi,-32(%rbp)
|
||||
call *%r11
|
||||
test %rax,%rax
|
||||
jnz entry_parse_end
|
||||
mov %rdi,%rcx
|
||||
mov -32(%rbp),%rdi
|
||||
inc %rdi
|
||||
jmp entry_parse_begin
|
||||
entry_parse_end:
|
||||
mov %r12,%rsp
|
||||
add $8,%r12
|
||||
pop %r12
|
||||
mov %rdi,%rsi
|
||||
mov -24(%rbp),%rdi
|
||||
sub %rdi,%rsi
|
||||
inc %rsi
|
||||
mov -16(%rbp),%rdx
|
||||
mov -8(%rbp),%r9
|
||||
entry_pre_call:
|
||||
call *%r9
|
||||
mov %rbp,%rsp
|
||||
pop %rbp
|
||||
ret
|
||||
|
||||
.bss
|
||||
|
|
6
test.c
6
test.c
|
@ -6,12 +6,14 @@
|
|||
void callback(char* str, int size, void* data) {
|
||||
char** out = (char**)data;
|
||||
*out = (char*)malloc(size);
|
||||
memcpy(str, *out, size);
|
||||
if(str!=NULL)
|
||||
memcpy(*out, str, size);
|
||||
else abort();
|
||||
}
|
||||
|
||||
int main() {
|
||||
char* match;
|
||||
if(!entry("meow.*|m(r(r(p..*)))",callback,&match))
|
||||
if(!entry("me\\|\\|ow.*|m(r(r(p..*)))",callback,&match))
|
||||
return 1;
|
||||
printf("%s",match);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue