diff options
author | bloodstalker <thabogre@gmail.com> | 2018-06-01 08:07:09 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-06-01 08:07:09 +0000 |
commit | c3531e8e096cf5f1ecc723acf602e157995267da (patch) | |
tree | 97eabe759383eb7b876fa15cd7cd42c270e6ef07 /bruiser | |
parent | added test files for the wasm linker. added two scripts to extra-tools (diff) | |
download | mutator-c3531e8e096cf5f1ecc723acf602e157995267da.tar.gz mutator-c3531e8e096cf5f1ecc723acf602e157995267da.zip |
fixed a bug with default.lua. added the blueprint for the wasm interface to bruiser.
Diffstat (limited to 'bruiser')
-rw-r--r-- | bruiser/bruiser.cpp | 7 | ||||
-rw-r--r-- | bruiser/bruiser.h | 1 | ||||
-rw-r--r-- | bruiser/defaults.lua | 4 | ||||
-rw-r--r-- | bruiser/lua-scripts/demo1.lua | 60 | ||||
-rw-r--r-- | bruiser/wasm.c | 32 | ||||
-rw-r--r-- | bruiser/wasm.h | 221 | ||||
-rwxr-xr-x | bruiser/wasm.sh | 7 | ||||
-rw-r--r-- | bruiser/wasm/test/linker/makefile | 44 |
8 files changed, 343 insertions, 33 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 2e1fa71..7b3864d 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -118,6 +118,7 @@ cl::opt<bool> SRC("src", cl::desc("source file is needed"), cl::init(false), cl: cl::opt<bool> KEEPALIVE("keepalive", cl::desc("drop to cli after running script in non-cli mode"), cl::init(false), cl::cat(BruiserCategory), cl::ZeroOrMore); cl::opt<std::string> NonCLILuaScript("lua", cl::desc("specifies a lua script for bruiser to run in non-interactive mode"), cl::init(""), cl::cat(BruiserCategory), cl::Optional); cl::opt<std::string> LuaDefault("luadefault", cl::desc("the path to the luadefault file. the default option is where the bruiser executable is."), cl::init(""), cl::cat(BruiserCategory), cl::ZeroOrMore); +cl::opt<std::string> SHELL_HISTORY_FILE("history", cl::desc("path to bruiser's history file"), cl::init("./bruiser-history.lua"), cl::cat(BruiserCategory), cl::ZeroOrMore); /**********************************************************************************************************************/ template <typename T> int pushLuaTableInt(lua_State* __ls, std::vector<T> vec) { @@ -2217,7 +2218,7 @@ class RunLoop /*cli execution loop*/ while((command = linenoise(">>>")) != NULL) { linenoiseHistoryAdd(command); - linenoiseHistorySave(SHELL_HISTORY_FILE); + linenoiseHistorySave(SHELL_HISTORY_FILE.c_str()); le.RunChunk(command); linenoiseFree(command); } @@ -2288,14 +2289,14 @@ int main(int argc, const char **argv) { std::transform(argv_n.begin(), argv_n.end(), std::back_inserter(vc), convert); /*initializing the log*/ - bruiser::BruiserReport BruiserLog; + //bruiser::BruiserReport BruiserLog; /*linenoise init*/ linenoiseSetCompletionCallback(bruiser::ShellCompletion); linenoiseSetHintsCallback(bruiser::ShellHints); /*setting up the initial history size to SHELL_HISTORY_SIZE*/ linenoiseHistorySetMaxLen(SHELL_HISTORY_SIZE); - linenoiseHistoryLoad(SHELL_HISTORY_FILE); + linenoiseHistoryLoad(SHELL_HISTORY_FILE.c_str()); linenoiseSetMultiLine(1); /*start running bruiser*/ diff --git a/bruiser/bruiser.h b/bruiser/bruiser.h index 72ea366..f95658d 100644 --- a/bruiser/bruiser.h +++ b/bruiser/bruiser.h @@ -78,7 +78,6 @@ namespace bruiser #define NO_BOLD 0 #define SHELL_HISTORY_SIZE 10000 -#define SHELL_HISTORY_FILE "bruiser-history.txt" #define GLOBAL_TIME_OUT 100000 diff --git a/bruiser/defaults.lua b/bruiser/defaults.lua index 756ba81..d0e91d4 100644 --- a/bruiser/defaults.lua +++ b/bruiser/defaults.lua @@ -10,10 +10,10 @@ function default_luarocks_modules() local path = string.match(line, "LUA_PATH%s*=%s*('.+')") local cpath = string.match(line, "LUA_CPATH%s*=%s*('.+')") if path ~= nil then - package.path = package.path..";"..path + package.path = package.path..";"..string.sub(path, 2, -2) end if cpath ~= nil then - package.cpath = package.cpath..";"..cpath + package.cpath = package.cpath..";"..string.sub(cpath, 2, -2) end end diff --git a/bruiser/lua-scripts/demo1.lua b/bruiser/lua-scripts/demo1.lua index 964fd81..c0ee9fd 100644 --- a/bruiser/lua-scripts/demo1.lua +++ b/bruiser/lua-scripts/demo1.lua @@ -12,11 +12,13 @@ -- objload("elf_get_func_code", "../bfd/test/test.so", "code_list") -- -------------------------------------------------------------------------------------------------------------- +local pack_name = ... +local Demo1 = {} elf_file = "/home/bloodstalker/devi/hell2/bfd/test/test.so" --elf_file = "/home/bloodstalker/devi/hell2/bfd/test/test.so" --elf_file = "../bfd/test/test" -function getGlobalTable() +function Demo1.getGlobalTable() local return_table = {} local names = objload("elf_get_obj_names", elf_file, "symbol_list") local sizes = objload("elf_get_obj_sizes", elf_file, "bytes") @@ -26,28 +28,28 @@ function getGlobalTable() return return_table end -function printObjNames() +function Demo1.printObjNames() local c = objload("elf_get_obj_names", elf_file, "symbol_list") for k,v in ipairs(c) do print(k,v) end end -function printObjSizes() +function Demo1.printObjSizes() local c = objload("elf_get_obj_sizes", elf_file, "bytes") for k,v in ipairs(c) do print(k,v) end end -function printFuncNames() +function Demo1.printFuncNames() local c = objload("elf_get_func_names", elf_file, "symbol_list") for k,v in ipairs(c) do print(k,v) end end -function printFuncCode() +function Demo1.printFuncCode() local c = objload("elf_get_func_code", elf_file, "code_list") for k,v in ipairs(c) do print(k,v) @@ -60,7 +62,7 @@ function printFuncCode() end end -function findMain() +function Demo1.findMain() local c = objload("elf_get_func_names", elf_file, "symbol_list") for k,v in ipairs(c) do if v == "main" then @@ -70,7 +72,7 @@ function findMain() end end -function codeTables() +function Demo1.codeTables() local return_table = {} local func_name_table = objload("elf_get_func_names", elf_file, "symbol_list") local code_table = objload("elf_get_func_code", elf_file, "code_list") @@ -80,7 +82,7 @@ function codeTables() return return_table end -function codeTableByName(name) +function Demo1.codeTableByName(name) local return_table = {} local func_name_table = objload("elf_get_func_names", elf_file, "symbol_list") local code_table = objload("elf_get_func_code", elf_file, "code_list") @@ -95,7 +97,7 @@ function codeTableByName(name) return nil end -function codeTableByName_number(name) +function Demo1.codeTableByName_number(name) local return_table = {} local func_name_table = objload("elf_get_func_names", elf_file, "symbol_list") local code_table = objload("elf_get_func_code", elf_file, "code_list") @@ -110,7 +112,7 @@ function codeTableByName_number(name) return nil end -function printFuncSizes() +function Demo1.printFuncSizes() local func_name_table = objload("elf_get_func_names", elf_file, "symbol_list") local code_table = objload("elf_get_func_code", elf_file, "code_list") local counter = 1 @@ -121,35 +123,35 @@ function printFuncSizes() end end -function demo1() +function Demo1.demo1() pwd() - printObjNames() - printObjSizes() - printFuncNames() - printFuncCode() - findMain() + Demo1.printObjNames() + Demo1.printObjSizes() + Demo1.printFuncNames() + Demo1.printFuncCode() + Demo1.findMain() - local code_table = codeTables() + local code_table = Demo1.codeTables() print(code_table["'main'"]) for k,v in ipairs(code_table["'main'"]) do io.write(string.format('%02x', v), " ") end io.write("\n") -local C_main_code = codeTableByName("'main'") +local C_main_code = Demo1.codeTableByName("'main'") for k, v in ipairs(C_main_code) do io.write(v, " ") end io.write("\n") - local add2_code = codeTableByName_number("'add2'") - local sub2_code = codeTableByName_number("'sub2'") - local adddouble_code = codeTableByName_number("'adddouble'") - local subdouble_code = codeTableByName_number("'subdouble'") - local triple_code = codeTableByName_number("'triple'") - local quad_code = codeTableByName_number("'quad'") - local passthrough_code = codeTableByName_number("'passthrough'") + local add2_code = Demo1.codeTableByName_number("'add2'") + local sub2_code = Demo1.codeTableByName_number("'sub2'") + local adddouble_code = Demo1.codeTableByName_number("'adddouble'") + local subdouble_code = Demo1.codeTableByName_number("'subdouble'") + local triple_code = Demo1.codeTableByName_number("'triple'") + local quad_code = Demo1.codeTableByName_number("'quad'") + local passthrough_code = Demo1.codeTableByName_number("'passthrough'") - printFuncSizes() + Demo1.printFuncSizes() print("passthrough_code: ") for k,v in pairs(passthrough_code) do @@ -217,6 +219,10 @@ local C_main_code = codeTableByName("'main'") end -demo1() +if type(package.loaded[pack_name]) ~= "userdata" then + Demo1.demo1() +else + return Demo1 +end -------------------------------------------------------------------------------------------------------------- diff --git a/bruiser/wasm.c b/bruiser/wasm.c new file mode 100644 index 0000000..ac5143c --- /dev/null +++ b/bruiser/wasm.c @@ -0,0 +1,32 @@ + +/***************************************************Project Mutator****************************************************/ +/*first line intentionally left blank.*/ +/*bruiser's wasm interface implementation*/ +/*Copyright (C) 2018 Farzad Sadeghi + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 3 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +/**********************************************************************************************************************/ +#include "./lua-5.3.4/src/lua.h" +#include "./lua-5.3.4/src/lauxlib.h" +#include "./lua-5.3.4/src/lualib.h" +#include "wasm.h" +/**********************************************************************************************************************/ + +#pragma weak main +int main(int argc, char** argv) { +} +/**********************************************************************************************************************/ +/*last line intentionally left blank.*/ + diff --git a/bruiser/wasm.h b/bruiser/wasm.h new file mode 100644 index 0000000..af02a20 --- /dev/null +++ b/bruiser/wasm.h @@ -0,0 +1,221 @@ + +/***************************************************Project Mutator****************************************************/ +/*first line intentionally left blank.*/ +/*bruiser's wasm interface implementation*/ +/*Copyright (C) 2018 Farzad Sadeghi + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 3 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +/**********************************************************************************************************************/ +#ifndef WASM_H +#define WASM_H +#include <inttypes.h> +#include "./lua-5.3.4/src/lua.h" +#include "./lua-5.3.4/src/lauxlib.h" +#include "./lua-5.3.4/src/lualib.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//typedef varuint1 uint8_t; +//typedef varuint7 uint8_t; +//typedef varuint32 uint32_t; +//typedef varint1 int8_t; +//typedef varint7 int8_t; +//typedef varint32 int32_t; + +typedef uint8_t varint1; +typedef uint8_t varint7; +typedef uint32_t varint32; +typedef int8_t varuint1; +typedef int8_t varuint7; +typedef int32_t varuint32; + + enum value_type_t {f64_vt = -4, f32_vt, i64_vt, i32_vt}; + enum external_kind_t {Function, Table, Memory, Global}; + enum type_ctor_t {i32_ctor = -1, i64_ctor = -2, f32_ctor = -3, f64_ctor = -4, anyfunc_ctor = -16, func_ctor = -32, block_type_ctor = -64}; + + typedef struct { + varuint32 size; + char* code; + }init_expr_t; + + typedef struct { + varuint1 flags; + varuint32 initial; + varuint32 maximum; + } resizable_limit_t; + + typedef struct { + enum value_type_t value_type; + varuint1 mutability; + }global_type_t; + + typedef struct { + varint7 element_type; + resizable_limit_t* resizable_limit; + }table_type_t; + + typedef struct { + resizable_limit_t* resizable_limit; + }memory_type_t; + + // func_type + typedef struct { + varint7 form; + varuint32 param_count; + varint7* param_types; + varuint1 return_count; + varint7 * return_types; + }W_Type_Section_Entry; + + typedef struct { + varuint32 count; + W_Type_Section_Entry** entries; + }W_Type_Section; + + typedef struct { + varuint32 module_length; + char* module_str; + varuint32 field_len; + char* field_str; + enum external_kind_t kind; + // based on external_kind it can be 4 different types. thats why im casting to void*. + void* type; + }W_Import_Section_Entry; + + typedef struct { + int count; + W_Import_Section_Entry** entries; + }W_Import_Section; + + typedef struct { + varuint32 count; + // indexes into the type section + varuint32* types; + }W_Function_Section; + + typedef struct W_Table_Section { + varuint32 count; + table_type_t** entries; + }W_Table_Section; + + typedef struct { + varuint32 count; + memory_type_t** entries; + }W_Memory_Section; + + typedef struct { + global_type_t* type; + init_expr_t init; + }W_Global_Entry; + + typedef struct { + varuint32 count; + W_Global_Entry** globals; + }W_Global_Section; + + typedef struct { + varuint32 field_len; + char* field_str; + enum external_kind_t kind; + int varuint32; + }W_Export_Entry; + + typedef struct { + int count; + W_Export_Entry** entries; + }W_Export_Section; + + typedef struct { + varuint32 index; + }W_Start_Section; + + typedef struct { + varuint32 index; + init_expr_t offset; + varuint32 num_length; + varuint32* elems; + }W_Elem_Segment; + + typedef struct { + varuint32 count; + W_Elem_Segment** entries; + }W_Element_Section; + + typedef struct { + varuint32 count; + enum value_type_t type; + }W_Local_Entry; + + typedef struct W_Function_Body { + varuint32 body_size; + varuint32 local_count; + W_Local_Entry** locals; + char* code; + //char end = 0x0b; + }W_Function_Body; + + typedef struct { + varuint32 count; + W_Function_Body** bodies; + }W_Code_Section; + + typedef struct { + varuint32 index; + init_expr_t offset; + varuint32 size; + char* data; + }W_Data_Segment; + + typedef struct { + varuint32 count; + struct W_Data_Segment** entries; + }W_Data_Section; + +#if 0 + typedef struct W_Custom_Section {}; + typedef struct W_Name_Section {}; + typedef struct W_Relocation_Section {}; +#endif + + typedef struct Wasm_Module { + W_Import_Section import_section; + W_Function_Section function_section; + W_Table_Section table_section; + W_Memory_Section memory_section; + W_Global_Section global_section; + W_Export_Section export_section; + W_Start_Section start_section; + W_Element_Section element_section; + W_Code_Section code_section; + W_Data_Section data_section; + void** W_Custom_Sections; + char* name; + }Wasm_Module; + + // get the raw binary of the wasm module + // char* getWRaw(); + + // get wasm section raw binary by name + // char* get_W_Section_Raw(const char* section_name); + +#ifdef __cplusplus +} +#endif // end of extern c +#endif // end of header guard +/**********************************************************************************************************************/ +/*last line intentionally left blank.*/ + diff --git a/bruiser/wasm.sh b/bruiser/wasm.sh new file mode 100755 index 0000000..d8d4990 --- /dev/null +++ b/bruiser/wasm.sh @@ -0,0 +1,7 @@ +#!/bin/bash +cd $(dirname $0) +gcc wasm.c -o wasme +./wasme +rm ./wasme + + diff --git a/bruiser/wasm/test/linker/makefile b/bruiser/wasm/test/linker/makefile new file mode 100644 index 0000000..5cffbcc --- /dev/null +++ b/bruiser/wasm/test/linker/makefile @@ -0,0 +1,44 @@ +TARGET=file0 +CC=clang +CC?=clang +CC_FLAGS= +CC_EXTRA?= +CC_FLAGS+=$(CC_EXTRA) + +SRCS=$(wildcard *.c) +WASM=$(patsubst %.c, %.wasm, $(wildcard *.c)) + +.DEFAULT:all + +.PHONY:all clean help + +all:$(TARGET) wasmforce + +depend:.depend + +.depend:$(SRCS) + rm -rf .depend + $(CC) -MM $(CC_FLAGS) $^ > ./.depend + +-include ./.depend + +%.wasm:%.c + ../../../../extra-tools/llvm-wasm $< + +wasmforce:$(WASM) + @echo forcing generation of wasm and wast + +.c.o: + $(CC) $(CC_FLAGS) -c $< -o $@ + +$(TARGET): $(TARGET).o + $(CC) $^ $(LD_FLAGS) -o $@ + +clean: + rm -f *.s *.wasm *.wast *.bc *.o *~ $(TARGET) + rm .depend + +help: + @echo "all is the default target" + @echo "there is delete." + @echo "there is clean." |