From 82dff3bff1b0d97585a2cbd574879057405cf363 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Thu, 19 Jul 2018 04:39:20 +0430 Subject: a fix for the luatablegen json file, added a new option to load.py, minor cosmetic changes --- bruiser/bruiser.cpp | 12 ++++++++---- bruiser/ffs.c | 2 +- bruiser/lua-scripts/demo1.lua | 2 +- bruiser/lua-scripts/demo3.lua | 6 ++++++ bruiser/lua-scripts/regtest.lua | 17 +++++++++++++---- bruiser/luatablegen/W_Import_Section_tablegen.c | 2 +- bruiser/luatablegen/makefile | 2 +- bruiser/makefile | 2 +- bruiser/wasm.c | 13 +------------ bruiser/wasm.h | 1 + bruiser/wasm/parse.py | 7 +++---- bruiser/wasmtablegen.json | 2 +- 12 files changed, 38 insertions(+), 30 deletions(-) (limited to 'bruiser') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 99f7731..56ea865 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -345,7 +345,7 @@ class LuaEngine /**********************************************************************************************************************/ class PyExec { public: - PyExec(std::string __py_script_name, std::string __py_func_name, std::string __obj_path ) : + PyExec(std::string __py_script_name, std::string __py_func_name, std::string __obj_path ) : py_script_name(__py_script_name), py_func_name(__py_func_name), obj_path(__obj_path) {} ~PyExec() { Py_Finalize(); @@ -531,6 +531,9 @@ class PyExec { return 0; } + int getWasmModule(void) { + } + void killPyObj(void) { Py_DECREF(pValue); } @@ -1454,6 +1457,8 @@ class LuaWrapper lua_pushinteger(__ls, iter); lua_settable(__ls, -3); } + } else if (action == "wasm_module") { + py.getWasmModule(); } if (Verbose) PRINT_WITH_COLOR_LB(GREEN, "done."); @@ -1529,7 +1534,7 @@ class LuaWrapper // 2-table of strings std::string ffi_ret_type_string = lua_tostring(__ls, 3); - void* x_ptr; + void* x_ptr; if (lua_type(__ls, 4) == LUA_TNUMBER) { if (vptrs.size() - 1 > lua_tointeger(__ls, 4)) x_ptr = std::get<0>(vptrs[lua_tointeger(__ls, 4)]); } else if (lua_type(__ls, 4) == LUA_TSTRING) { @@ -1627,7 +1632,6 @@ class LuaWrapper if (x_ptr != nullptr) { result = ffi_callX(argc, args, ret_type, x_ptr, values); if (result == nullptr) {PRINT_WITH_COLOR_LB(RED, "ffi_callX returned null.");return 0;} - if (std::strcmp(ffi_ret_type_string.c_str(), "void") == 0) {lua_pushnil(__ls);} else if (std::strcmp(ffi_ret_type_string.c_str(), "uint8") == 0) {lua_pushinteger(__ls, ffi_reinterpret_uint8_t(result));} else if (std::strcmp(ffi_ret_type_string.c_str(), "sint8") == 0) {lua_pushinteger(__ls, ffi_reinterpret_int8_t(result));} @@ -2052,7 +2056,7 @@ class LuaWrapper int BruiserLuaGetPath(lua_State* __ls) { unsigned int returncount = 0; - for (auto &iter : ShellGlobalInstance.PATH){ + for (auto &iter : ShellGlobalInstance.PATH){ lua_pushstring(__ls, iter.c_str()); std::cout << BLUE << iter.c_str() << NORMAL << "\n"; returncount++; diff --git a/bruiser/ffs.c b/bruiser/ffs.c index 940ae47..bda5e3f 100644 --- a/bruiser/ffs.c +++ b/bruiser/ffs.c @@ -19,7 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ /**********************************************************************************************************************/ #include "ffs.h" -// @DEVI-the acceptable indexes right now are 0 and 19 since we are only reserving 2 void* slots in luaconf.h. +// @DEVI-the acceptable indexes right now are 0 and 19 since we are only reserving 20 void* slots in luaconf.h. void* lua_getextraspace_wrapper(lua_State* __ls, int index) { return lua_getextraspace(__ls) + sizeof(void*)*index; } diff --git a/bruiser/lua-scripts/demo1.lua b/bruiser/lua-scripts/demo1.lua index c349c36..c768687 100644 --- a/bruiser/lua-scripts/demo1.lua +++ b/bruiser/lua-scripts/demo1.lua @@ -65,7 +65,7 @@ end function Demo1.findMain() local c = objload("load", "elf_get_func_names", elf_file, "symbol_list") for k,v in ipairs(c) do - if v == "main" then + if v == "main" then io.write("main index is".." "..k.."\n") return k end diff --git a/bruiser/lua-scripts/demo3.lua b/bruiser/lua-scripts/demo3.lua index 89dde81..0e8e309 100644 --- a/bruiser/lua-scripts/demo3.lua +++ b/bruiser/lua-scripts/demo3.lua @@ -10,4 +10,10 @@ function demo3.init() table_type:set_resizable_limit(resizable_limit) end +function demo3.getmodule_py() + local wasm = require("wasm") + local wasm_module = Wasm_Module() + local wasm_module = objload("dwasm", "elf_get_obj_names", elf_file, "symbol_list") +end + return demo3 diff --git a/bruiser/lua-scripts/regtest.lua b/bruiser/lua-scripts/regtest.lua index f7ec461..9cb1250 100644 --- a/bruiser/lua-scripts/regtest.lua +++ b/bruiser/lua-scripts/regtest.lua @@ -3,10 +3,19 @@ --local posix = require("posix") function reg_test() - local demo1 = require("demo1") - local demo2 = require("demo2") - local demo3 = require("asmtest") - print("yo") + local xobj = require("demo1") + local jmp_table = require("demo2") + local asm_rewriter = require("asmtest") + local wasm_import = require("demo3") + + local argparse = require("argparse") + + local parser = argparse("regtest", "bruiser's regression test script") + parser:flag("-x --xobj") + parser:flag("-j --jmpt") + parser:flag("-a --asm") + parser:flag("-w --wasm") + end reg_test() diff --git a/bruiser/luatablegen/W_Import_Section_tablegen.c b/bruiser/luatablegen/W_Import_Section_tablegen.c index 5286c75..b56c81b 100644 --- a/bruiser/luatablegen/W_Import_Section_tablegen.c +++ b/bruiser/luatablegen/W_Import_Section_tablegen.c @@ -41,7 +41,7 @@ int W_Import_Section_push_args(lua_State* __ls, W_Import_Section* _st) { int new_W_Import_Section(lua_State* __ls) { lua_checkstack(__ls, 2); varuint32 count = luaL_optinteger(__ls,-2,0); - W_Import_Section** entries = lua_touserdata(__ls,-1); + W_Import_Section_Entry** entries = lua_touserdata(__ls,-1); W_Import_Section* dummy = push_W_Import_Section(__ls); dummy->count = count; dummy->entries = entries; diff --git a/bruiser/luatablegen/makefile b/bruiser/luatablegen/makefile index 937902b..a4ecdaf 100644 --- a/bruiser/luatablegen/makefile +++ b/bruiser/luatablegen/makefile @@ -1,6 +1,6 @@ CC=clang CC?=clang -CC_FLAGS= +CC_FLAGS=$(shell $(PY_CONF) --includes) CC_EXTRA?= CC_FLAGS+=$(CC_EXTRA) SRCS=$(wildcard *.c) diff --git a/bruiser/makefile b/bruiser/makefile index 31dff92..b0cac30 100644 --- a/bruiser/makefile +++ b/bruiser/makefile @@ -6,7 +6,7 @@ CC=clang CC?=clang CXX_FLAGS+=-I/usr/include -g CXX_FLAGS+=$(shell $(PY_CONF) --includes) -CC_FLAGS+=-g +CC_FLAGS+=-g $(shell $(PY_CONF) --includes) BRUISER=bruiser LUA?=JIT LIB_LUA=./lua-5.3.4/src/liblua.a diff --git a/bruiser/wasm.c b/bruiser/wasm.c index c517269..689083a 100644 --- a/bruiser/wasm.c +++ b/bruiser/wasm.c @@ -22,20 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #include "./lua-5.3.4/src/lauxlib.h" #include "./lua-5.3.4/src/lualib.h" #include "./wasm.h" +#include /**********************************************************************************************************************/ -static Wasm_Module* convert_wasm_module(lua_State* ls, int index) { - Wasm_Module* dummy = lua_touserdata(ls, index); - if (dummy == NULL) {printf("convert_wasm_module: bad userdata.\n");} - return dummy; -} -static Wasm_Module* check_wasm_module(lua_State* ls, int index) { - Wasm_Module* dummy; - luaL_checktype(ls, index, LUA_TUSERDATA); - dummy = (Wasm_Module*)luaL_checkudata(ls, index, "wasm_module"); - if (dummy == NULL) {printf("check_wasm_module: bad userdata.\n");} - return dummy; -} #pragma weak main int main(int argc, char** argv) { diff --git a/bruiser/wasm.h b/bruiser/wasm.h index 5c21c99..7a716ba 100644 --- a/bruiser/wasm.h +++ b/bruiser/wasm.h @@ -24,6 +24,7 @@ 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 #ifdef __cplusplus extern "C" { diff --git a/bruiser/wasm/parse.py b/bruiser/wasm/parse.py index 424a2b6..9d7140d 100755 --- a/bruiser/wasm/parse.py +++ b/bruiser/wasm/parse.py @@ -25,14 +25,12 @@ class ParsedStruct: self.version_number = int() self.section_list = [] - # like the above. currently unused class ParsedStructV2: def __init__(self, version_number, section_list): self.version_number = version_number self.section_list = section_list - # @DEVI-Deprecated-convert a bytearray to int def Conver2Int(little_endian, size, bytelist): modifier = size - 1 @@ -971,6 +969,7 @@ def premain(argparser): if argparser.args.wasm: for file_path in argparser.args.wasm: module = interpreter.parse(file_path) + print(type(module)) interpreter.appendmodule(module) if argparser.args.dbg or argparser.args.dbgsection: interpreter.dump_sections(module, argparser.args.dbgsection) @@ -988,8 +987,8 @@ def premain(argparser): DumpLinearMems(ms.Linear_Memory, argparser.getMEMDUMP()) if argparser.args.run: vm.run() - # merklizer = Merklizer(ms.Linear_Memory[0][0:512], module) - # treelength, hashtree = merklizer.run() + #merklizer = Merklizer(ms.Linear_Memory[0][0:512], module) + #treelength, hashtree = merklizer.run() if argparser.args.interactive: variables = globals().copy() diff --git a/bruiser/wasmtablegen.json b/bruiser/wasmtablegen.json index 38fe5a7..cb7899c 100644 --- a/bruiser/wasmtablegen.json +++ b/bruiser/wasmtablegen.json @@ -15,7 +15,7 @@ "W_Import_Section_Entry": {"field_name":["module_length", "module_str", "field_len", "field_str", "kind", "type"], "field_type":["varuint32", "char*", "varuint32", "char*", "enum external_kind_t", "void*"], "lua_type": ["integer", "string", "integer", "string", "integer", "lightuserdata"], "methods": ["convert", "check", "push_self", "push_args", "new"]}, "W_Import_Section": - {"field_name":["count", "entries"], "field_type":["varuint32","W_Import_Section**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, + {"field_name":["count", "entries"], "field_type":["varuint32","W_Import_Section_Entry**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, "W_Function_Section": {"field_name":["count", "types"], "field_type":["varuint32", "varuint32*"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]}, "W_Table_Section": -- cgit v1.2.3