diff options
Diffstat (limited to 'bruiser')
-rw-r--r-- | bruiser/autogen/wasm/ft/autowasm.c | 261 | ||||
-rw-r--r-- | bruiser/autogen/wasm/ft/makefile | 14 | ||||
-rwxr-xr-x | bruiser/autogen/wasm/ltg.sh | 2 | ||||
-rw-r--r-- | bruiser/autogen/wasm/ltg/makefile | 129 | ||||
-rw-r--r-- | bruiser/bruiser-extra.h | 1 | ||||
-rw-r--r-- | bruiser/bruiser.cpp | 73 | ||||
-rw-r--r-- | bruiser/bruiser.h | 5 | ||||
m--------- | bruiser/faultreiber | 0 | ||||
-rw-r--r-- | bruiser/lua-5.3.4/src/Makefile | 2 | ||||
-rw-r--r-- | bruiser/makefile | 45 | ||||
m--------- | bruiser/tablegen | 0 |
11 files changed, 369 insertions, 163 deletions
diff --git a/bruiser/autogen/wasm/ft/autowasm.c b/bruiser/autogen/wasm/ft/autowasm.c index 30442ba..cbc6e5a 100644 --- a/bruiser/autogen/wasm/ft/autowasm.c +++ b/bruiser/autogen/wasm/ft/autowasm.c @@ -4,170 +4,179 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/resource.h> -#include "./aggregate.h" -#include "./read.h" #include "./structs.h" +#include "./read.h" +#include "./aggregate.h" + #pragma weak main -int main(int argc, char **argv) { +int main (int argc, char** argv) { + const rlim_t kStackSize = 160 * 1024 * 1024; // min stack size = 16 MB + struct rlimit rl; + int result; + + result = getrlimit(RLIMIT_STACK, &rl); + if (result == 0) + { + if (rl.rlim_cur < kStackSize) + { + rl.rlim_cur = kStackSize; + result = setrlimit(RLIMIT_STACK, &rl); + if (result != 0) + { + fprintf(stderr, "setrlimit returned result = %d\n", result); + } + } + } int wasm = open("./test.wasm", O_RDONLY); - read_aggr_wasm(wasm); - - printf("magic_number:%x\n", magic_number_container->magic_number); - printf("version:%x\n", version_container->version); - - printf("type section id:%d\n", W_Type_Section_container->id); - printf("type section payloadlength:%d\n", - W_Type_Section_container->payloadlength); - printf("type_section entry count:%d\n", W_Type_Section_container->count); - for (int i = 0; i < W_Type_Section_container->count; ++i) { - printf("param_count:%d\n", - W_Type_Section_container->entries[i]->param_count); - for (int j = 0; j < W_Type_Section_container->entries[i]->param_count; ++j) - printf("param_types:%d\n", - W_Type_Section_container->entries[i]->param_types[j]); - printf("return_count:%d\n", - W_Type_Section_container->entries[i]->return_count); - for (int j = 0; j < W_Type_Section_container->entries[i]->return_count; ++j) - printf("param_types:%d\n", - W_Type_Section_container->entries[i]->return_types[j]); + wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm); + printf("finished reading\n"); + +#if 0 + printf("magic_number:%x\n", lib_ret->obj->magic_number_container->magic_number); + printf("version:%x\n", lib_ret->obj->version_container->version); + + printf("type section id:%d\n", lib_ret->obj->W_Type_Section_container->id); + printf("type section payloadlength:%d\n", lib_ret->obj->W_Type_Section_container->payloadlength); + printf("type_section entry count:%d\n", lib_ret->obj->W_Type_Section_container->count); + for (int i=0; i < lib_ret->obj->W_Type_Section_container->count; ++i) { + printf("param_count:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->param_count); + for (int j = 0; j < lib_ret->obj->W_Type_Section_container->entries[i]->param_count; ++j) + printf("param_types:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->param_types[j]); + printf("return_count:%d\n", lib_ret->obj->W_Type_Section_container->entries[i]->return_count); + for (int j = 0; j < lib_ret->obj->W_Type_Section_container->entries[i]->return_count; ++j) + printf("param_types:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->return_types[j]); } - printf("import_section_id:%d\n", W_Import_Section_container->id); - printf("import_section_payloadlength:%d\n", - W_Import_Section_container->payloadlength); - printf("import_section_count:%d\n", W_Import_Section_container->count); - for (int i = 0; i < W_Import_Section_container->count; ++i) { - printf("module_length:%d\n", - W_Import_Section_container->entries[i]->module_length); - printf("module_str:%s\n", - W_Import_Section_container->entries[i]->module_str); - printf("field_length:%d\n", - W_Import_Section_container->entries[i]->field_len); - printf("field_str:%s\n", W_Import_Section_container->entries[i]->field_str); - printf("kind:%d\n", W_Import_Section_container->entries[i]->kind); - if (W_Import_Section_container->entries[i]->kind == 0) - printf("type:%d\n", W_Import_Section_container->entries[i]->kind); + printf("import_section_id:%d\n", lib_ret->obj->W_Import_Section_container->id); + printf("import_section_payloadlength:%d\n", lib_ret->obj->W_Import_Section_container->payloadlength); + printf("import_section_count:%d\n", lib_ret->obj->W_Import_Section_container->count); + for(int i = 0; i < lib_ret->obj->W_Import_Section_container->count; ++i) { + printf("module_length:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->module_length); + printf("module_str:%s\n", lib_ret->obj->W_Import_Section_container->entries[i]->module_str); + printf("field_length:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->field_len); + printf("field_str:%s\n", lib_ret->obj->W_Import_Section_container->entries[i]->field_str); + printf("kind:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->kind); + if (lib_ret->obj->W_Import_Section_container->entries[i]->kind == 0) + printf("type:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->kind); printf("\n"); } - printf("function_section_id:%d\n", W_Function_Section_container->id); - printf("function_section_payloadlength:%d\n", - W_Function_Section_container->payloadlength); - printf("function_section_count:%d\n", W_Function_Section_container->count); - for (int i = 0; i < W_Function_Section_container->count; ++i) - printf("type:%d\n", W_Function_Section_container->types[i]); - - printf("table_section_id:%d\n", W_Table_Section_container->id); - printf("table_section_payloadlength:%d\n", - W_Table_Section_container->payloadlength); - printf("table_section_count:%d\n", W_Table_Section_container->count); - for (int i = 0; i < W_Table_Section_container->count; ++i) { - printf("element_type:%d\n", - W_Table_Section_container->entries[i]->element_type); - printf("rl_flags:%d\n", - W_Table_Section_container->entries[i]->resizable_limit->flags); - printf("rl_initial:%d\n", - W_Table_Section_container->entries[i]->resizable_limit->initial); - printf("rl_maximum:%d\n", - W_Table_Section_container->entries[i]->resizable_limit->maximum); + printf("function_section_id:%d\n", lib_ret->obj->W_Function_Section_container->id); + printf("function_section_payloadlength:%d\n", lib_ret->obj->W_Function_Section_container->payloadlength); + printf("function_section_count:%d\n", lib_ret->obj->W_Function_Section_container->count); + for (int i = 0; i < lib_ret->obj->W_Function_Section_container->count; ++i) + printf("type:%d\n", lib_ret->obj->W_Function_Section_container->types[i]); + + printf("table_section_id:%d\n", lib_ret->obj->W_Table_Section_container->id); + printf("table_section_payloadlength:%d\n", lib_ret->obj->W_Table_Section_container->payloadlength); + printf("table_section_count:%d\n", lib_ret->obj->W_Table_Section_container->count); + for (int i = 0; i < lib_ret->obj->W_Table_Section_container->count; ++i) { + printf("element_type:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->element_type); + printf("rl_flags:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->flags); + printf("rl_initial:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->initial); + printf("rl_maximum:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->maximum); } - printf("memory_section_id:%d\n", W_Memory_Section_container->id); - printf("memory_section_payload_length:%d\n", - W_Memory_Section_container->payloadlength); - printf("rl_flags:%d\n", - W_Memory_Section_container->entries->resizable_limit->flags); - printf("rl_initial:%d\n", - W_Memory_Section_container->entries->resizable_limit->initial); - printf("rl_maximum:%d\n", - W_Memory_Section_container->entries->resizable_limit->maximum); - - if (W_Global_Section_container == NULL) - printf("global section doesnt exist.\n"); - - printf("export_section_id:%d\n", W_Export_Section_container->id); - printf("export_section_payloadlength:%d\n", - W_Export_Section_container->payloadlength); - printf("entry count:%d\n", W_Export_Section_container->count); - - for (int i = 0; i < W_Export_Section_container->count; ++i) { - printf("field_len:%d\n", W_Export_Section_container->entries[i]->field_len); - printf("field_str:%s\n", W_Export_Section_container->entries[i]->field_str); - printf("kind:%d\n", W_Export_Section_container->entries[i]->kind); - printf("index:%d\n", W_Export_Section_container->entries[i]->index); + printf("memory_section_id:%d\n", lib_ret->obj->W_Memory_Section_container->id); + printf("memory_section_payload_length:%d\n", lib_ret->obj->W_Memory_Section_container->payloadlength); + printf("rl_flags:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->flags); + printf("rl_initial:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->initial); + printf("rl_maximum:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->maximum); + + if (lib_ret->obj->W_Global_Section_container == NULL) printf("global section doesnt exist.\n"); + + printf("export_section_id:%d\n", lib_ret->obj->W_Export_Section_container->id); + printf("export_section_payloadlength:%d\n", lib_ret->obj->W_Export_Section_container->payloadlength); + printf("entry count:%d\n", lib_ret->obj->W_Export_Section_container->count); + + for (int i = 0; i < lib_ret->obj->W_Export_Section_container->count; ++i) { + printf("field_len:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->field_len); + printf("field_str:%s\n", lib_ret->obj->W_Export_Section_container->entries[i]->field_str); + printf("kind:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->kind); + printf("index:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->index); } - if (W_Start_Section_container == NULL) - printf("start section doesnt exist.\n"); + if (lib_ret->obj->W_Start_Section_container == NULL) printf("start section doesnt exist.\n"); - printf("element_seciton_id:%d\n", W_Element_Section_container->id); - printf("element_section_payloadlength:%d\n", - W_Element_Section_container->payloadlength); - printf("entry count:%d\n", W_Element_Section_container->count); + printf("element_seciton_id:%d\n", lib_ret->obj->W_Element_Section_container->id); + printf("element_section_payloadlength:%d\n", lib_ret->obj->W_Element_Section_container->payloadlength); + printf("entry count:%d\n", lib_ret->obj->W_Element_Section_container->count); - for (int i = 0; i < W_Element_Section_container->count; ++i) { - printf("index:%d\n", W_Element_Section_container->entries[i]->index); + for (int i = 0; i < lib_ret->obj->W_Element_Section_container->count; ++i) { + printf("index:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->index); for (int j = 0; j < 3; ++j) { - printf("code:%d\n", - W_Element_Section_container->entries[i]->init->code[j]); + printf("code:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->init->code[j]); } - printf("num_length:%d\n", - W_Element_Section_container->entries[i]->num_length); - for (int j = 0; j < W_Element_Section_container->entries[i]->num_length; - ++j) { - printf("elems:%d\n", W_Element_Section_container->entries[i]->elems[j]); + printf("num_length:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->num_length); + for (int j = 0; j < lib_ret->obj->W_Element_Section_container->entries[i]->num_length; ++j) { + printf("elems:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->elems[j]); } } - printf("code_section_id:%d\n", W_Code_Section_container->id); - printf("code_section_payloadlength:%d\n", - W_Code_Section_container->payloadlength); - printf("count:%d\n", W_Code_Section_container->count); - - for (int i = 0; i < W_Code_Section_container->count; ++i) { - printf("body_size:%d\n", W_Code_Section_container->bodies[i]->body_size); - printf("local_count:%d\n", - W_Code_Section_container->bodies[i]->local_count); - if (W_Code_Section_container->bodies[i]->local_count > 0) { - for (int j = 0; j < W_Code_Section_container->bodies[i]->local_count; - ++j) { - for (int k = 0; - k < W_Code_Section_container->bodies[i]->locals[j]->count; ++k) { + printf("code_section_id:%d\n", lib_ret->obj->W_Code_Section_container->id); + printf("code_section_payloadlength:%d\n", lib_ret->obj->W_Code_Section_container->payloadlength); + printf("count:%d\n", lib_ret->obj->W_Code_Section_container->count); + + for (int i = 0; i < lib_ret->obj->W_Code_Section_container->count; ++i) { + printf("body_size:%d\n", lib_ret->obj->W_Code_Section_container->bodies[i]->body_size); + printf("local_count:%d\n", lib_ret->obj->W_Code_Section_container->bodies[i]->local_count); + if (lib_ret->obj->W_Code_Section_container->bodies[i]->local_count > 0) { + for (int j =0; j < lib_ret->obj->W_Code_Section_container->bodies[i]->local_count; ++j) { + for (int k = 0; k < lib_ret->obj->W_Code_Section_container->bodies[i]->locals[j]->count; ++k) { } } } printf("code:\n"); - for (int j = 0; j < W_Code_Section_container->bodies[i]->body_size; ++j) { - printf("%02x ", W_Code_Section_container->bodies[i]->code[j]); + for (int j = 0; j < lib_ret->obj->W_Code_Section_container->bodies[i]->body_size; ++j) { + printf("%02x ", lib_ret->obj->W_Code_Section_container->bodies[i]->code[j]); } printf("\n"); } - printf("data_section_id:%d\n", W_Data_Section_container->id); - printf("data_section_payloadlength:%d\n", - W_Data_Section_container->payloadlength); - printf("data seg count:%d\n", W_Data_Section_container->count); + printf("data_section_id:%d\n", lib_ret->obj->W_Data_Section_container->id); + printf("data_section_payloadlength:%d\n", lib_ret->obj->W_Data_Section_container->payloadlength); + printf("data seg count:%d\n", lib_ret->obj->W_Data_Section_container->count); - for (int i = 0; i < W_Data_Section_container->count; ++i) { - printf("index:%d\n", W_Data_Section_container->entries[i]->index); - printf("size:%d\n", W_Data_Section_container->entries[i]->size); + for (int i = 0; i < lib_ret->obj->W_Data_Section_container->count; ++i) { + printf("index:%d\n", lib_ret->obj->W_Data_Section_container->entries[i]->index); + printf("size:%d\n", lib_ret->obj->W_Data_Section_container->entries[i]->size); printf("code:\n"); - for (int j = 0; j < W_Data_Section_container->entries[i]->size; ++j) { - printf("%c ", W_Data_Section_container->entries[i]->data[j]); + for (int j = 0; j < lib_ret->obj->W_Data_Section_container->entries[i]->size; ++j) { + printf("%c ", lib_ret->obj->W_Data_Section_container->entries[i]->data[j]); } printf("\n"); int j = 0; printf("offset:\n"); - while (1) { - printf("%02x ", W_Data_Section_container->entries[i]->offset->code[j]); - if (W_Data_Section_container->entries[i]->offset->code[j] == 11) { + while(1) { + printf("%02x ", lib_ret->obj->W_Data_Section_container->entries[i]->offset->code[j]); + if (lib_ret->obj->W_Data_Section_container->entries[i]->offset->code[j] == 11) { break; } j++; } printf("\n"); } - - release_all(); +#endif + + printf("sizeof magic:%d\n", sizeof(magic_number)); + printf("sizeof version:%d\n", sizeof(version)); + printf("current void count:%d\n", lib_ret->current_void_count); + printf("void_train first:0x%x\n", lib_ret->void_train[0]); + printf("void_train first:0x%x\n", lib_ret->void_train[1]); + printf("void_train self address:0x%x\n", lib_ret->void_train); + //free(lib_ret->void_train[0]); + //release_all(lib_ret->void_train, lib_ret->current_void_count); + //free(lib_ret->void_train[2]); + //free(lib_ret->void_train[1]); + //free(lib_ret->void_train[0]); + for (int i = lib_ret->current_void_count - 1; i >= 0; --i) { + printf("%d:0x%x ", i, lib_ret->void_train[i]); + //if (i == 1) continue; + free(lib_ret->void_train[i]); + } + free(lib_ret->void_train); + free(lib_ret->obj); + free(lib_ret); return 0; } diff --git a/bruiser/autogen/wasm/ft/makefile b/bruiser/autogen/wasm/ft/makefile index 86f0a6b..be67649 100644 --- a/bruiser/autogen/wasm/ft/makefile +++ b/bruiser/autogen/wasm/ft/makefile @@ -53,7 +53,7 @@ LD_FLAGS+=$(EXTRA_LD_FLAGS) .PHONY:all clean help ASM SO TAGS -all:$(TARGET) +all:$(TARGET) $(TARGET)-dbg everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS $(TARGET)-cov @@ -82,10 +82,10 @@ $(TARGET): $(TARGET).o read.o aggregate.o structs.o $(TARGET)-static: $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -static -o $@ -$(TARGET)-dbg: $(TARGET).odbg read.o aggregate.o structs.o +$(TARGET)-dbg: $(TARGET).odbg read.odbg aggregate.odbg structs.odbg $(CC) $^ $(LD_FLAGS) -g -o $@ -$(TARGET)-cov: $(TARGET).ocov read.o aggregate.o structs.o +$(TARGET)-cov: $(TARGET).ocov read.ocov aggregate.ocov structs.ocov $(CC) $^ $(LD_FLAGS) $(COV_LD) -o $@ cov: @@ -116,7 +116,13 @@ $(TARGET).so: $(TARGET).o read.o aggregate.o structs.o $(CC) $^ $(LD_FLAGS) -shared -o $@ $(TARGET).a: $(TARGET).o read.o aggregate.o structs.o - ar rcs $(TARGET).a $(TARGET).o + ar rcs $(TARGET).a $(TARGET).o read.o aggregate.o structs.o + +valgrind: $(TARGET) + valgrind --leak-check=yes $(TARGET) + +test: $(TARGET) + $(TARGET) clean: rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov diff --git a/bruiser/autogen/wasm/ltg.sh b/bruiser/autogen/wasm/ltg.sh index 94f052b..a7ca2e9 100755 --- a/bruiser/autogen/wasm/ltg.sh +++ b/bruiser/autogen/wasm/ltg.sh @@ -1,6 +1,6 @@ #!/usr/bin/bash cd $(dirname $0) -"../../tablegen/luatablegen.py" --out ./ltg/ --luaheader ../../../lua-5.3.4/src --headeraggr ./ltg/wasm_tables.h --lualibpath ./ltg/wasm.lua --docpath ./ltg/wasm.md --xml ./ltg/wasm.xml --tbldefs ./ltg/ +"../../tablegen/luatablegen.py" --out ./ltg/ --luaheader ../../../lua-5.3.4/src --headeraggr ./ltg/wasm_tables.h --lualibpath ./ltg/wasm.lua --docpath ./ltg/wasm.md --xml ./ltg/wasm.xml --tbldefs ./ltg/ --name wasm clang-format ./ltg/*.c ./ltg/*.h -i for filename in ./ltg/*.c; do gcc -c $filename > /dev/null 2>&1 diff --git a/bruiser/autogen/wasm/ltg/makefile b/bruiser/autogen/wasm/ltg/makefile index b59a216..3a98ee0 100644 --- a/bruiser/autogen/wasm/ltg/makefile +++ b/bruiser/autogen/wasm/ltg/makefile @@ -1,12 +1,14 @@ +TARGET=wasm_tables +SHELL=bash +SHELL?=bash CC=clang CC?=clang -CC_FLAGS=-fpic +CC_FLAGS= -fPIC CC_EXTRA?= -CC_FLAGS+=$(CC_EXTRA) -SRCS=$(wildcard *.c) -TBG_OBJLIST=$(patsubst %.c, %.o , $(wildcard *.c)) -TBG_OBJLIST_DBG=$(patsubst %.c, %.odbg , $(wildcard *.c)) -TBG_OBJLIST_COV=$(patsubst %.c, %.ocov , $(wildcard *.c)) +CTAGS_I_PATH?=./ +LD_FLAGS= +LIB_LUA=../../../lua-5.3.4/src/liblua.a +EXTRA_LD_FLAGS?=-lm -ldl ADD_SANITIZERS_CC= -g -fsanitize=address -fno-omit-frame-pointer ADD_SANITIZERS_LD= -g -fsanitize=address MEM_SANITIZERS_CC= -g -fsanitize=memory -fno-omit-frame-pointer @@ -14,14 +16,47 @@ MEM_SANITIZERS_LD= -g -fsanitize=memory UB_SANITIZERS_CC= -g -fsanitize=undefined -fno-omit-frame-pointer UB_SANITIZERS_LD= -g -fsanitize=undefined COV_CC= -fprofile-instr-generate -fcoverage-mapping +COV_LD= -fprofile-instr-generate +# BUILD_MODES are=RELEASE(default), DEBUG,ADDSAN,MEMSAN,UBSAN +BUILD_MODE?=RELEASE +OBJ_LIST:=$(patsubst %.c, %.o, $(wildcard *.c)) +ASM_LIST:=$(patsubst %.c, %.dis, $(wildcard *.c)) + +ifeq ($(BUILD_MODE), ADDSAN) +ifeq ($(CC), gcc) +$(error This build mode is only useable with clang.) +endif +CC_EXTRA+=$(ADD_SANITIZERS_CC) +EXTRA_LD_FLAGS+=$(ADD_SANITIZERS_LD) +endif + +ifeq ($(BUILD_MODE), MEMSAN) +ifeq ($(CC), gcc) +$(error This build mode is only useable with clang.) +endif +CC_EXTRA+=$(MEM_SANITIZERS_CC) +EXTRA_LD_FLAGS+=$(MEM_SANITIZERS_LD) +endif + +ifeq ($(BUILD_MODE), UBSAN) +ifeq ($(CC), gcc) +$(error This build mode is only useable with clang.) +endif +CC_EXTRA+=$(UB_SANITIZERS_CC) +EXTRA_LD_FLAGS+=$(UB_SANITIZERS_LD) +endif + +SRCS:=$(wildcard *.c) +CC_FLAGS+=$(CC_EXTRA) +LD_FLAGS+=$(EXTRA_LD_FLAGS) .DEFAULT:all -.PHONY:all clean help +.PHONY:all clean help ASM SO TAGS + +all:$(TARGET) -all:$(TBG_OBJLIST) $(TBG_OBJLIST_DBG) $(TBG_OBJLIST_COV) - @echo $(TBG_OBJLIST) - @echo $(TBG_OBJLIST_INC) +everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS $(TARGET)-cov depend:.depend @@ -42,10 +77,78 @@ depend:.depend %.ocov:%.c $(CC) $(CC_FLAGS) $(COV_CC) -c $< -o $@ +$(LIB_LUA): + $(MAKE) -C ../../../lua-5.3.4/src linux + +$(TARGET): $(TARGET).o $(LIB_LUA) $(OBJ_LIST) + $(CC) $(LD_FLAGS) $^ -o $@ + +$(TARGET)-static: $(TARGET).o $(LIB_LUA) $(OBJ_LIST) + $(CC) $^ $(LD_FLAGS) -static -o $@ + +$(TARGET)-dbg: $(TARGET).odbg $(LIB_LUA) $(OBJ_LIST) + $(CC) $^ $(LD_FLAGS) -g -o $@ + +$(TARGET)-cov: $(TARGET).ocov $(LIB_LUA) $(OBJ_LIST) + $(CC) $^ $(LD_FLAGS) $(COV_LD) -o $@ + +cov: + @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata + @llvm-cov show $(TARGET)-cov -instr-profile=default.profdata + +covrep: + @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata + @llvm-cov report $(TARGET)-cov -instr-profile=default.profdata + +ASM:$(ASM_LIST) + +SO:$(TARGET).so + +A:$(TARGET).a + +TAGS:tags + +tags:$(SRCS) + $(shell $(CC) -c -I $(CTAGS_I_PATH) -M $(SRCS)|\ + sed -e 's/[\\ ]/\n/g'|sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d'|\ + ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q) + +%.dis: %.o + objdump -r -d -M intel -S $< > $@ + +$(TARGET).so: $(TARGET).o $(LIB_LUA) $(OBJ_LIST) + $(CC) $^ $(LD_FLAGS) -shared -o $@ + +$(TARGET).a: $(TARGET).o $(LIB_LUA) $(OBJ_LIST) + ar rcs $(TARGET).a $(OBJ_LIST) + +runcov: $(TARGET)-cov + $(TARGET)-cov + +valgrind: $(TARGET) + - valgrind --leak-check=yes $(TARGET) + clean: - rm -f *.o *~ $(TARGET) *.ocov *.odbg + rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov + +deepclean: clean + if [[ -d tags ]];then rm tags;fi rm .depend + $(MAKE) -C ../lua5 clean help: - @echo "all is the default target" - @echo "there is clean." + @echo "--all is the default target, runs $(TARGET) target" + @echo "--everything will build everything" + @echo "--SO will generate the so" + @echo "--ASM will generate assembly files" + @echo "--TAGS will generate tags file" + @echo "--$(TARGET) builds the dynamically-linked executable" + @echo "--$(TARGET)-dbg will generate the debug build. BUILD_MODE should be set to DEBUG to work" + @echo "--$(TARGET)-static will statically link the executable to the libraries" + @echo "--$(TARGET)-cov is the coverage build" + @echo "--cov will print the coverage report" + @echo "--covrep will print the line coverage report" + @echo "--A will build the static library" + @echo "--TAGS will build the tags file" + @echo "--clean" + @echo "--deepclean will clean almost everything" diff --git a/bruiser/bruiser-extra.h b/bruiser/bruiser-extra.h index 7ef9454..c50e5e3 100644 --- a/bruiser/bruiser-extra.h +++ b/bruiser/bruiser-extra.h @@ -138,6 +138,7 @@ std::vector<std::string> LUA_FUNCS = "xsize()", "xclear()", "xmemusage()", + "getwasmobj(", "_G", "_VERSION", "assert", diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 65564b4..bc4ad65 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -32,7 +32,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #include "asmrewriter.h" #include "ramdump.h" #include "ffs.h" -#include "./luatablegen/wasm_tables.h" +#include <fcntl.h> +#include "./autogen/wasm/ltg/wasm_tables.h" +#include "./autogen/wasm/ft/aggregate.h" /*standard headers*/ #include <exception> #include <fstream> @@ -256,7 +258,7 @@ class LuaEngine } void registerAutogenTables(void) { - reg_tablegen_tables(LS); + reg_tablegen_tables_wasm(LS); } void RunLuaDefaults(void) { @@ -532,6 +534,7 @@ class PyExec { } int getWasmModule(void) { + return 0; } void killPyObj(void) { @@ -1372,6 +1375,7 @@ class LuaWrapper PRINT_WITH_COLOR_LB(RED,"bad arg. nil passed. expected a value."); } PyExec py(filename.c_str(), funcname.c_str(), objjpath.c_str()); + return 0; } int BruiserPyLoader(lua_State* __ls ) { @@ -1517,7 +1521,7 @@ class LuaWrapper } int BruiserLuaGetXMemSize(lua_State* __ls) { - int argc = lua_gettop(__ls); + int argc [[maybe_unused]] = lua_gettop(__ls); int sum = 0; for (auto& iter : vptrs) { sum += std::get<2>(iter); @@ -1674,6 +1678,68 @@ class LuaWrapper } #endif + int BruiserLuaGetWASMObj(lua_State* __ls) { + if (lua_gettop(__ls) != 1) PRINT_WITH_COLOR_LB(RED, "at least one argument denoting the path is required."); + std::string obj_path = lua_tostring(__ls, 1); + int wasm_file = open(obj_path.c_str(), O_RDONLY); + wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm_file); + close(wasm_file); + lua_newtable(__ls); + lua_pushstring(__ls, "magic"); + magic_number_push_args(__ls, lib_ret->obj->magic_number_container); + new_magic_number(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "version"); + version_push_args(__ls, lib_ret->obj->version_container); + new_version(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "type_section"); + W_Type_Section_push_args(__ls, lib_ret->obj->W_Type_Section_container); + new_W_Type_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "import_section"); + W_Import_Section_push_args(__ls, lib_ret->obj->W_Import_Section_container); + new_W_Import_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "function_section"); + W_Function_Section_push_args(__ls, lib_ret->obj->W_Function_Section_container); + new_W_Function_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "table_section"); + W_Table_Section_push_args(__ls, lib_ret->obj->W_Table_Section_container); + new_W_Table_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "memory_section"); + W_Memory_Section_push_args(__ls, lib_ret->obj->W_Memory_Section_container); + new_W_Memory_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "global_section"); + W_Global_Section_push_args(__ls, lib_ret->obj->W_Global_Section_container); + new_W_Global_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "export_section"); + W_Export_Section_push_args(__ls, lib_ret->obj->W_Export_Section_container); + new_W_Export_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "start_section"); + W_Start_Section_push_args(__ls, lib_ret->obj->W_Start_Section_container); + new_W_Start_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "element_section"); + W_Element_Section_push_args(__ls, lib_ret->obj->W_Element_Section_container); + new_W_Element_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "code_section"); + W_Code_Section_push_args(__ls, lib_ret->obj->W_Code_Section_container); + new_W_Code_Section(__ls); + lua_settable(__ls, -3); + lua_pushstring(__ls, "data_section"); + W_Data_Section_push_args(__ls, lib_ret->obj->W_Data_Section_container); + new_W_Data_Section(__ls); + lua_settable(__ls, -3); + return 1; + } + int BruiserLuaXObjAllocGlobal(lua_State* __ls) { int numargs = lua_gettop(__ls); if (numargs != 2) {PRINT_WITH_COLOR_LB(RED, "expected exactly two args. did not get that.");return 0;} @@ -2413,6 +2479,7 @@ int main(int argc, const char **argv) { lua_register(LE.GetLuaState(), "xclear", &LuaDispatch<&LuaWrapper::BruiserLuaXObjDeallocate>); lua_register(LE.GetLuaState(), "xmemusage", &LuaDispatch<&LuaWrapper::BruiserLuaGetXMemSize>); lua_register(LE.GetLuaState(), "dwasm", &LuaDispatch<&LuaWrapper::BruiserLuaDWASMPy>); + lua_register(LE.GetLuaState(), "getwasmobj", &LuaDispatch<&LuaWrapper::BruiserLuaGetWASMObj>); runloop.setLW(std::move(LW)); runloop.run(); diff --git a/bruiser/bruiser.h b/bruiser/bruiser.h index f95658d..ff47919 100644 --- a/bruiser/bruiser.h +++ b/bruiser/bruiser.h @@ -163,7 +163,8 @@ help CMDHelp[] = { {"ramdump", "ramdump(pid)", "dumps the ram", "", "ram contents"}, {"xsize", "xsize()", "returns the number of currently registered xobjs", "", "nothing"}, {"xclear", "xclear()", "deallocates all xobjs, freeing memory", "", "nothing"}, - {"xmemusage", "xmemusage()", "returns how much memory the xobjcts are occupying", "", "total memory used by xobjects"} + {"xmemusage", "xmemusage()", "returns how much memory the xobjcts are occupying", "", "total memory used by xobjects"}, + {"getwasmobj", "getwasmobj(path)", "returns a wasm object", "", "a wasm object"} }; /**********************************************************************************************************************/ /** @@ -317,7 +318,7 @@ class Daemonize struct ELFHDR_64 { public: ELFHDR_64() = default; - ELFHDR_64(__uint128_t _ident, uint16_t _type, uint16_t _machine, + ELFHDR_64(__uint128_t _ident, uint16_t _type, uint16_t _machine, uint32_t _version, uint64_t _entry, uint64_t _phoff, uint64_t _shoff, uint32_t _flags, uint16_t _ehsize, uint16_t _phentsize, uint16_t _phnum, uint16_t _shentsize, uint16_t _shnum, uint16_t _shstrndx) { diff --git a/bruiser/faultreiber b/bruiser/faultreiber -Subproject cbd94dd817ac2f1d79a9643a651bd2d8982fcf5 +Subproject 66a3830f30ed12281938fae30e5fb77a248333c diff --git a/bruiser/lua-5.3.4/src/Makefile b/bruiser/lua-5.3.4/src/Makefile index 202d0c9..7167d32 100644 --- a/bruiser/lua-5.3.4/src/Makefile +++ b/bruiser/lua-5.3.4/src/Makefile @@ -7,7 +7,7 @@ PLAT= linux CC= gcc -std=gnu99 -CFLAGS= -fpic -O2 -Wall -Wextra -DLUA_COMPAT_MODULE -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS) +CFLAGS= -fPIC -O2 -Wall -Wextra -DLUA_COMPAT_MODULE -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LIBS= -lm $(SYSLIBS) $(MYLIBS) diff --git a/bruiser/makefile b/bruiser/makefile index 07f2dc4..6f5cea2 100644 --- a/bruiser/makefile +++ b/bruiser/makefile @@ -2,6 +2,10 @@ TARGET=bruiser LLVM_CONF?=llvm-config PY_CONF?=python3-config LIB_LUA=./lua-5.3.4/src/liblua.a +FT_WASM_SO=./autogen/wasm/ft/autowasm.so +FT_WASM_A=./autogen/wasm/ft/autowasm.a +LTG_WASM_SO=./autogen/wasm/ltg/wasm_tables.so +LTG_WASM_A=./autogen/wasm/ltg/wasm_tables.a SHELL=bash SHELL?=bash CC=clang @@ -73,9 +77,9 @@ C_SRCS:=$(wildcard *.c) CXX_FLAGS+=$(CXX_EXTRA) EXTRA_LD_FLAGS+=$(shell $(PY_CONF) --ldflags) -lffi -lcapstone -lkeystone -L./lua-5.3.4/src LD_FLAGS+=$(EXTRA_LD_FLAGS) -TBG_OBJLIST_INC=$(patsubst ./luatablegen/%.c, ./luatablegen/%.o, $(wildcard ./luatablegen/*.c)) -TBG_OBJLIST_DBG_INC=$(patsubst ./luatablegen/%.c, ./luatablegen/%.odbg, $(wildcard ./luatablegen/*.c)) -TBG_OBJLIST_COV_INC=$(patsubst ./luatablegen/%.c, ./luatablegen/%.ocov, $(wildcard ./luatablegen/*.c)) +TBG_OBJLIST_INC_WASM=$(patsubst ./autogen/wasm/ltg/%.c, ./autogen/wasm/ltg/%.o, $(wildcard ./autogen/wasm/ltg/*.c)) +TBG_OBJLIST_DBG_INC_WASM=$(patsubst ./autogen/wasm/ltg/%.c, ./autogen/wasm/ltg/%.odbg, $(wildcard ./autogen/wasm/ltg/*.c)) +TBG_OBJLIST_COV_INC_WASM=$(patsubst ./autogen/wasm/ltg/%.c, ./autogen/wasm/ltg/%.ocov, $(wildcard ./autogen/wasm/ltg/*.c)) .DEFAULT:all @@ -127,11 +131,13 @@ linenoise.odbg: ./linenoise/linenoise.c linenoise.ocov: ./linenoise/linenoise.c $(CC) $(CC_FLAGS) $(COV_CXX) linenoise/linenoise.c -c -o linenoise.ocov -./wasmtablegen.json: - if [[ ls -l ./luatablegen | wc -l == 2 ]];then ./tablegen.sh;else :;fi +./autogen/wasm/ft/wasm.xml: + #if [[ ls -l ./autogen/wasm/ft/ | wc -l == 2 ]];then ./autogen/wasm/ft.sh;else :;fi + ./autogen/wasm/ft.sh -./luatablegen/%.c: ./wasmtablegen.json - ./tablegen.sh +./autogen/wasm/ltg/wasm.xml: + #if [[ ls -l ./autogen/wasm/ltg/ | wc -l == 2 ]];then ./autogen/wasm/ltg.sh;else :;fi + ./autogen/wasm/ltg.sh ./luatablegen/%.o:./luatablegen/%.c $(MAKE) -C luatablegen @@ -139,17 +145,29 @@ linenoise.ocov: ./linenoise/linenoise.c $(LIB_LUA): $(MAKE) -C lua-5.3.4/src linux +$(FT_WASM_SO): ./autogen/wasm/ft/wasm.xml + $(MAKE) -C ./autogen/wasm/ft SO + +$(FT_WASM_A): ./autogen/wasm/ft/wasm.xml + $(MAKE) -C ./autogen/wasm/ft A + +$(LTG_WASM_SO): ./autogen/wasm/ltg/wasm.xml + $(MAKE) -C ./autogen/wasm/ltg SO + +$(LTG_WASM_A): ./autogen/wasm/ltg/wasm.xml + $(MAKE) -C ./autogen/wasm/ltg A + %.odbg:%.cpp $(CXX) $(CXX_FLAGS) -g -c $< -o $@ %.ocov:%.cpp $(CXX) $(CXX_FLAGS) $(COV_CXX) -c $< -o $@ -$(TARGET): $(TARGET).o ../m0/mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC) +$(TARGET): $(TARGET).o ../m0/mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(FT_WASM_A) $(LTG_WASM_A) $(CXX) $^ $(LD_FLAGS) -o $@ # currently broken since it needs a static libpython -$(TARGET)-static: $(TARGET).o ../m0/mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC) +$(TARGET)-static: $(TARGET).o ../m0/mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(FT_WASM_A) $(LTG_WASM_A) $(CXX) $^ $(LD_FLAGS) -static -o $@ $(TARGET)-dbg: $(TARGET).odbg ../m0/mutator_aux.odbg ../tinyxml2/tinyxml2.odbg linenoise.odbg CompletionHints.odbg mutagen.o ORCmutation.o bruiserffi.odbg asmrewriter.odbg bruisercapstone.odbg ramdump.odbg ffs.odbg $(LIB_LUA) $(TBG_OBJLIST_DBG_INC) @@ -193,16 +211,17 @@ runcov: $(TARGET)-cov $(TARGET)-cov --lua ./lua-scripts/regtest.lua valgrind: $(TARGET) - valgrind --leak-check=yes $(TARGET) --lua ./lua-scripts/regtest.lua + - valgrind --leak-check=yes $(TARGET) --lua ./lua-scripts/regtest.lua clean: rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov deepclean: clean - rm tags - rm .depend + - rm tags + - rm .depend $(MAKE) -C lua-5.3.4 clean - $(MAKE) -C luatablegen clean + $(MAKE) -C ./autogen/wasm/ft clean + $(MAKE) -C ./autogen/wasm/ltg clean help: @echo "--all is the default target, runs $(TARGET) target" diff --git a/bruiser/tablegen b/bruiser/tablegen -Subproject 33c3ddfcc94d7c1f9a98d635881ebcc63dffcc2 +Subproject 9ca06ce6baaa38010af869096cd498ffbf24de9 |