From d06fd220d7cf35aab4d06605e8891e622c022929 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Fri, 30 Aug 2019 13:27:58 +0430 Subject: do not pull this commit [ci skip] --- README.md | 3 +- bruiser/CompletionHints.cpp | 86 ------------- bruiser/CompletionHints.h | 257 ++++++++++++++++++++++++++++++++++++++- bruiser/bruiser-extra.h | 232 +---------------------------------- bruiser/bruiser.cpp | 64 +++++++++- bruiser/lua-scripts/wasmtest.lua | 28 ++++- 6 files changed, 339 insertions(+), 331 deletions(-) delete mode 100644 bruiser/CompletionHints.cpp diff --git a/README.md b/README.md index 3547c3e..087f36a 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Excluding SaferCpp and other 3rd party code/libraries, everything else under pro ## How to get project mutator Before you run make, make sure you have all the dependencies:
-* You need LLVM 5, 6 or 8.
+* You need LLVM/Clang(for supported versions see the section under building).
* For `safercpp` you will need to have LLVM RTTI also.
* For `bruiser` you will need the python 3.5 or higher's dev package(source code and libpython), libcapstone, libkeystone and libffi.
* The other libraries used are either submodules or copied inside.
@@ -417,6 +417,7 @@ For a list of things that need to be done, take a look at the list of issues.
+You can also choose to contact me directly if you want to.
### Support Well, I don't have the Misra-C:2012 Document. If you or your organization/company are willing to donate a copy to mutator, hit me up.
diff --git a/bruiser/CompletionHints.cpp b/bruiser/CompletionHints.cpp deleted file mode 100644 index 7ff9b18..0000000 --- a/bruiser/CompletionHints.cpp +++ /dev/null @@ -1,86 +0,0 @@ - -/***************************************************Project Mutator****************************************************/ -//-*-c++-*- -/*first line intentionally left blank.*/ -/*the source code for bruiser's auto-completion and suggestions.*/ -/*Copyright (C) 2017 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.*/ -/**********************************************************************************************************************/ -/*included modules*/ -#include "bruiser-extra.h" -/*project headers*/ -/*standard headers*/ -#include -#include -/*other*/ -#include "linenoise/linenoise.h" -/**********************************************************************************************************************/ -namespace bruiser { - void ShellCompletion(const char* __buf, linenoiseCompletions* __lc) { - if (__buf != NULL) { - for(auto &iter : LUA_FUNCS) { - //if (iter.find(__buf) != std::string::npos) { - if (iter.find(__buf) == 0U) { - linenoiseAddCompletion(__lc, iter.c_str()); - } - } - } - } - - char* ShellHints(const char* __buf, int* __color, int* __bold) - { - if (__buf != NULL) { - auto dummy = std::string(__buf); - - for(auto &iter : LUA_FUNCS) { - if (dummy == "") break; - - if (iter.find(__buf) != std::string::npos) { - *__color = 35; - *__bold = 1; - int sizet = dummy.length(); - - std::string dummy2 = iter.substr(sizet, std::string::npos); - - /*@DEVI-apparently linenoise expects the return value to live past the hints callback function returning, - * i mean that's why our vector version returns junk. linenoise later frees the returned hint so there - * should be no leaked memory(it calls freeHintsCallback).*/ - char* returnchar = new char[dummy2.size() + 1]; - std::copy(dummy2.begin(), dummy2.end(), returnchar); - returnchar[dummy2.size()] = '\0'; - -#if 0 - std::vector retchar(dummy2.begin(), dummy2.end()); - retchar.push_back('\0'); - //std::cout << "\n" << retchar.data() << "\n"; - char* c = (char*)retchar.data(); - std::cout << "\n" << c << "\n"; -#endif - - return returnchar; - //return c; - //return retchar.data(); - //return &retchar[0]; - } - } - } - - return NULL; - } -} //end of namespace bruiser -/**********************************************************************************************************************/ -/*last line intentionally left blank*/ - diff --git a/bruiser/CompletionHints.h b/bruiser/CompletionHints.h index 6d1db84..953e9b1 100644 --- a/bruiser/CompletionHints.h +++ b/bruiser/CompletionHints.h @@ -25,20 +25,265 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #define COMPLETION_SUGGESTIONS_H /**********************************************************************************************************************/ /*included modules*/ -#include "linenoise/linenoise.h" /*project headers*/ +#include "./linenoise/linenoise.h" /*standard library headers*/ /*clang headers*/ /*llvm headers*/ /**********************************************************************************************************************/ /*using*/ /**********************************************************************************************************************/ -namespace bruiser -{ - void ShellCompletion(const char* __buf, linenoiseCompletions* __lc); - char* ShellHints(const char* __buf, int* __color, int* __bold); -} +#ifdef __cplusplus +extern "C" { +#endif + +#define NELEMS(x) (sizeof(x)/sizeof(x[0])) + +typedef struct{ + size_t begin; + size_t end; +}word_pos_t; + +void shell_completion(const char* buf, linenoiseCompletions* lc, size_t pos); +char* shell_hint(const char* buf, int* color, int* bold); + +char* LUA_FUNCS[] = + { + "help()", + "quit()", + "exit()", + "history()", + "version()", + "clear()", + "m0()", + "Funcs()", + "Vars()", + "Arrays()", + "Structs()", + "Unions()", + "Classes()", + "hijackmain()", + "make", + "historysize", + "showsource", + "readxmlfile", + "extractmutagen", + "strainrecognition()", + "setmakepath", + "run", + "setbinpath", + "getbinpath()", + "getmakepath()", + "getsourcefiles()", + "getpaths()", + "changedirectory", + "yolo", + "pwd()", + "objload()", + "listObjects", + "xobjregister", + "xobjwrapper", + "xcall(", + "xobjlist()", + "xallocglobal(", + "xallocallglobals()", + "getjmptable(", + "freejmptable(", + "dumpjmptable(", + "ramdump(", + "xsize()", + "xclear()", + "xmemusage()", + "getwasmobj(", + "_G", + "_VERSION", + "assert", + "collectgarbage", + "dofile", + "error", + "getmetatable", + "ipairs", + "load", + "loadfile", + "next", + "pairs", + "pcall", + "print", + "rawequal", + "rawget", + "rawlen", + "rawset", + "require", + "select", + "setmetatable", + "tonumber", + "tostring", + "type", + "xpcall", + "coroutine", + "coroutine.create", + "coroutine.isyieldable", + "coroutine.resume", + "coroutine.running", + "coroutine.status", + "coroutine.wrap", + "coroutine.yield", + "debug", + "debug.debug", + "debug.gethook", + "debug.getinfo", + "debug.getlocal", + "debug.getmetatable", + "debug.getregistry", + "debug.getupvalue", + "debug.getuservalue", + "debug.sethook", + "debug.setlocal", + "debug.setmetatable", + "debug.setupvalue", + "debug.setuservalue", + "debug.traceback", + "debug.upvalueid", + "debug.upvaluejoin", + "io", + "io.close", + "io.flush", + "io.input", + "io.lines", + "io.open", + "io.output", + "io.popen", + "io.read", + "io.stderr", + "io.stdin", + "io.stdout", + "io.tmpfile", + "io.type", + "io.write", + "file:close", + "file:flush", + "file:lines", + "file:read", + "file:seek", + "file:setvbuf", + "file:write", + "math", + "math.abs", + "math.acos", + "math.asin", + "math.atan", + "math.ceil", + "math.cos", + "math.deg", + "math.exp", + "math.floor", + "math.fmod", + "math.huge", + "math.log", + "math.max", + "math.maxinteger", + "math.min", + "math.mininteger", + "math.modf", + "math.pi", + "math.rad", + "math.random", + "math.randomseed", + "math.sin", + "math.sqrt", + "math.tan", + "math.tointeger", + "math.type", + "math.ult", + "os", + "os.clock", + "os.date", + "os.difftime", + "os.execute", + "os.exit", + "os.getenv", + "os.remove", + "os.rename", + "os.setlocale", + "os.time", + "os.tmpname", + "package", + "package.config", + "package.cpath", + "package.loaded", + "package.loadlib", + "package.path", + "package.preload", + "package.searchers", + "package.searchpath", + "string", + "string.byte", + "string.char", + "string.dump", + "string.find", + "string.format", + "string.gmatch", + "string.gsub", + "string.len", + "string.lower", + "string.match", + "string.pack", + "string.packsize", + "string.rep", + "string.reverse", + "string.sub", + "string.unpack", + "string.upper", + "table", + "table.concat", + "table.insert", + "table.move", + "table.pack", + "table.remove", + "table.sort", + "table.unpack", + "utf8", + "utf8.char", + "utf8.charpattern", + "utf8.codepoint", + "utf8.codes", + "utf8.len", + "utf8.offset", + "LUA_CPATH", + "LUA_CPATH_5_3", + "LUA_INIT", + "LUA_INIT_5_3", + "LUA_PATH", + "LUA_PATH_5_3", + "and", + "break", + "do", + "else", + "elseif", + "end", + "false", + "for", + "function", + "if", + "in", + "local", + "nil", + "not", + "or", + "repeat", + "return", + "then", + "true", + "until", + "while" +}; + +char ID_BREAKERS[] = {'{','}','[',']','(',')','+','=','-','.','*','/','\t',' ','.','<','>','|','?','&', '"', '\''}; /**********************************************************************************************************************/ +#ifdef __cplusplus +} +#endif + #endif /*last line intentionally left blank*/ diff --git a/bruiser/bruiser-extra.h b/bruiser/bruiser-extra.h index c50e5e3..285eeb3 100644 --- a/bruiser/bruiser-extra.h +++ b/bruiser/bruiser-extra.h @@ -2,7 +2,7 @@ /***************************************************Project Mutator****************************************************/ //-*-c++-*- /*first line intentionally left blank.*/ -/*the header for mutator's code breaker.*/ +/*the header for anything extra for bruiser that needs to get shared between different files.*/ /*Copyright (C) 2017 Farzad Sadeghi This program is free software; you can redistribute it and/or @@ -91,236 +91,6 @@ std::vector BRUISR_COMMANDS = "m0" }; -std::vector LUA_FUNCS = - { - "help()", - "quit()", - "exit()", - "history()", - "version()", - "clear()", - "m0()", - "Funcs()", - "Vars()", - "Arrays()", - "Structs()", - "Unions()", - "Classes()", - "hijackmain()", - "make", - "historysize", - "showsource", - "readxmlfile", - "extractmutagen", - "strainrecognition()", - "setmakepath", - "run", - "setbinpath", - "getbinpath()", - "getmakepath()", - "getsourcefiles()", - "getpaths()", - "changedirectory", - "yolo", - "pwd()", - "objload()", - "listObjects", - "xobjregister", - "xobjwrapper", - "xcall(", - "xobjlist()", - "xallocglobal(", - "xallocallglobals()", - "getjmptable(", - "freejmptable(", - "dumpjmptable(", - "ramdump(", - "xsize()", - "xclear()", - "xmemusage()", - "getwasmobj(", - "_G", - "_VERSION", - "assert", - "collectgarbage", - "dofile", - "error", - "getmetatable", - "ipairs", - "load", - "loadfile", - "next", - "pairs", - "pcall", - "print", - "rawequal", - "rawget", - "rawlen", - "rawset", - "require", - "select", - "setmetatable", - "tonumber", - "tostring", - "type", - "xpcall", - "coroutine", - "coroutine.create", - "coroutine.isyieldable", - "coroutine.resume", - "coroutine.running", - "coroutine.status", - "coroutine.wrap", - "coroutine.yield", - "debug", - "debug.debug", - "debug.gethook", - "debug.getinfo", - "debug.getlocal", - "debug.getmetatable", - "debug.getregistry", - "debug.getupvalue", - "debug.getuservalue", - "debug.sethook", - "debug.setlocal", - "debug.setmetatable", - "debug.setupvalue", - "debug.setuservalue", - "debug.traceback", - "debug.upvalueid", - "debug.upvaluejoin", - "io", - "io.close", - "io.flush", - "io.input", - "io.lines", - "io.open", - "io.output", - "io.popen", - "io.read", - "io.stderr", - "io.stdin", - "io.stdout", - "io.tmpfile", - "io.type", - "io.write", - "file:close", - "file:flush", - "file:lines", - "file:read", - "file:seek", - "file:setvbuf", - "file:write", - "math", - "math.abs", - "math.acos", - "math.asin", - "math.atan", - "math.ceil", - "math.cos", - "math.deg", - "math.exp", - "math.floor", - "math.fmod", - "math.huge", - "math.log", - "math.max", - "math.maxinteger", - "math.min", - "math.mininteger", - "math.modf", - "math.pi", - "math.rad", - "math.random", - "math.randomseed", - "math.sin", - "math.sqrt", - "math.tan", - "math.tointeger", - "math.type", - "math.ult", - "os", - "os.clock", - "os.date", - "os.difftime", - "os.execute", - "os.exit", - "os.getenv", - "os.remove", - "os.rename", - "os.setlocale", - "os.time", - "os.tmpname", - "package", - "package.config", - "package.cpath", - "package.loaded", - "package.loadlib", - "package.path", - "package.preload", - "package.searchers", - "package.searchpath", - "string", - "string.byte", - "string.char", - "string.dump", - "string.find", - "string.format", - "string.gmatch", - "string.gsub", - "string.len", - "string.lower", - "string.match", - "string.pack", - "string.packsize", - "string.rep", - "string.reverse", - "string.sub", - "string.unpack", - "string.upper", - "table", - "table.concat", - "table.insert", - "table.move", - "table.pack", - "table.remove", - "table.sort", - "table.unpack", - "utf8", - "utf8.char", - "utf8.charpattern", - "utf8.codepoint", - "utf8.codes", - "utf8.len", - "utf8.offset", - "LUA_CPATH", - "LUA_CPATH_5_3", - "LUA_INIT", - "LUA_INIT_5_3", - "LUA_PATH", - "LUA_PATH_5_3", - "and", - "break", - "do", - "else", - "elseif", - "end", - "false", - "for", - "function", - "if", - "in", - "local", - "nil", - "not", - "or", - "repeat", - "return", - "then", - "true", - "until", - "while" -}; /**********************************************************************************************************************/ #endif /*last line intentionally left balnk*/ diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 7081b2b..7493372 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -1589,6 +1589,64 @@ class LuaWrapper { W_Import_Section_push_args(__ls, lib_ret->obj->W_Import_Section_container); new_W_Import_Section(__ls); lua_settable(__ls, -3); + for (uint32_t ii = 0; ii < lib_ret->obj->W_Import_Section_container->count; ++ii) { + W_Import_Section_Entry_push_args(__ls, lib_ret->obj->W_Import_Section_container->entries[ii]); + new_W_Import_Section_Entry(__ls); + lua_pushlightuserdata(__ls, lib_ret->obj->W_Import_Section_container->entries[ii]); + lua_pushvalue(__ls, -2); + lua_settable(__ls, LUA_REGISTRYINDEX); + lua_pop(__ls, 1); + if (lib_ret->obj->W_Import_Section_container->entries[ii]->kind == 1) { + table_type_t_push_args(__ls, (table_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type)); + new_table_type_t(__ls); + lua_pushlightuserdata(__ls, lib_ret->obj->W_Import_Section_container->entries[ii]->type); + lua_pushvalue(__ls, -2); + lua_settable(__ls, LUA_REGISTRYINDEX); + lua_pop(__ls, 1); + resizable_limit_t_push_args(__ls, ((table_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->resizable_limit); + new_resizable_limit_t(__ls); + std::cout << "YYYYYY" << ((void*)(((table_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->resizable_limit)) << "YYYYYY" << "\n"; + std::cout << "YYYYYY:element_type:" << (((table_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->element_type) << "YYYYYY" << "\n"; + lua_pushlightuserdata(__ls, ((void*)(((table_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->resizable_limit))); + lua_pushvalue(__ls, -2); + lua_settable(__ls, LUA_REGISTRYINDEX); + lua_pop(__ls, 1); + } + else if (lib_ret->obj->W_Import_Section_container->entries[ii]->kind == 2) { + memory_type_t_push_args(__ls, ((memory_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))); + new_memory_type_t(__ls); + std::cout << "ZZZZZZmemory_type:" << lib_ret->obj->W_Import_Section_container->entries[ii]->type << "ZZZZZZ\n"; + lua_pushlightuserdata(__ls, lib_ret->obj->W_Import_Section_container->entries[ii]->type); + lua_pushvalue(__ls, -2); + lua_settable(__ls, LUA_REGISTRYINDEX); + lua_pop(__ls, 1); + resizable_limit_t_push_args(__ls, ((memory_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->resizable_limit); + new_resizable_limit_t(__ls); + std::cout << "YYYYYYmemory_type rsz:" << ((void*)(((memory_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->resizable_limit)) << "YYYYYY" << "\n"; + lua_pushlightuserdata(__ls, ((void*)(((memory_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->resizable_limit))); + lua_pushvalue(__ls, -2); + lua_settable(__ls, LUA_REGISTRYINDEX); + lua_pop(__ls, 1); + } + else if (lib_ret->obj->W_Import_Section_container->entries[ii]->kind == 3) { + global_type_t_push_args(__ls, (global_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type)); + std::cout << "set value: " << (uint32_t)((global_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->value_type << "\n"; + std::cout << "set mutability: " << (uint32_t)((global_type_t*)(lib_ret->obj->W_Import_Section_container->entries[ii]->type))->mutability << "\n"; + std::cout << "set type: " << lib_ret->obj->W_Import_Section_container->entries[ii]->type << "\n"; + new_global_type_t(__ls); + lua_pushlightuserdata(__ls, lib_ret->obj->W_Import_Section_container->entries[ii]->type); + lua_pushvalue(__ls, -2); + lua_settable(__ls, LUA_REGISTRYINDEX); + lua_pop(__ls, 1); + lua_pushlightuserdata(__ls, lib_ret->obj->W_Import_Section_container->entries[ii]->type); + lua_gettable(__ls, LUA_REGISTRYINDEX); + global_type_t* fuck = (global_type_t*)lua_touserdata(__ls, -1); + std::cout << "get after set type: " << fuck << "\n"; + std::cout << "get after set value: " << (uint32_t)(fuck->value_type) << "\n"; + std::cout << "get after set mutability: " << (uint32_t)(fuck->mutability) << "\n"; + lua_pop(__ls, 1); + } + } } PRINT_WITH_COLOR_LB(BLUE, "import section"); @@ -1656,7 +1714,7 @@ class LuaWrapper { lua_pushvalue(__ls, -2); lua_settable(__ls, LUA_REGISTRYINDEX); #if 1 - for (int ii = 0; ii < lib_ret->obj->W_Code_Section_container->count; ++ii) { + for (uint32_t ii = 0; ii < lib_ret->obj->W_Code_Section_container->count; ++ii) { W_Function_Body_push_args(__ls, lib_ret->obj->W_Code_Section_container->bodies[ii]); new_W_Function_Body(__ls); lua_pushlightuserdata(__ls, lib_ret->obj->W_Code_Section_container->bodies[ii]); @@ -2312,8 +2370,8 @@ int main(int argc, const char** argv) { //bruiser::BruiserReport BruiserLog; /*linenoise init*/ - linenoiseSetCompletionCallback(bruiser::ShellCompletion); - linenoiseSetHintsCallback(bruiser::ShellHints); + linenoiseSetCompletionCallback(shell_completion); + linenoiseSetHintsCallback(shell_hint); /*setting up the initial history size to SHELL_HISTORY_SIZE*/ linenoiseHistorySetMaxLen(SHELL_HISTORY_SIZE); linenoiseHistoryLoad(SHELL_HISTORY_FILE.c_str()); diff --git a/bruiser/lua-scripts/wasmtest.lua b/bruiser/lua-scripts/wasmtest.lua index c568b31..0c2e04f 100644 --- a/bruiser/lua-scripts/wasmtest.lua +++ b/bruiser/lua-scripts/wasmtest.lua @@ -35,7 +35,26 @@ function libwasm.dump_import_section(a) io.write("field len:"..v:field_len().."\t") io.write("field str:"..v:field_str().."\t") io.write("kind:"..v:kind().."\t") - io.write("kind:"..type(v:type()).."\t") + io.write("kind:"..tostring(v:type()).."\t") + if v:kind() == 0 then + print() + io.write("kind:"..tostring(v:type()).."\n") + elseif v:kind() == 1 then + io.write("element_type:"..v:type():element_type().."\n") + --io.write("rsz:"..v:type():resizable_limit().."\t") + --io.write("flags:"..v:type():resizable_limit():flags().."\t") + --io.write("init:"..v:type():resizable_limit():init().."\t") + --io.write("max:"..v:type():resizable_limit():maximum().."\n") + elseif v:kind() == 2 then + --io.write("rsz:"..v:type():resizable_limit().."\t") + --io.write("flags:"..v:type():resizable_limit():flags().."\t") + --io.write("init:"..v:type():resizable_limit():init().."\t") + --io.write("max:"..v:type():resizable_limit():maximum().."\n") + print() + elseif v:kind() == 3 then + io.write("value_type:"..v:type():value_type().."\t") + io.write("mutability:"..v:type():mutability().."\n") + end end else print(colors("%{red}".."section doesnt exist.")) @@ -1045,10 +1064,11 @@ end --libwasm.demo_setters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm") --libwasm.dev("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") -libwasm.demo_getters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm") ---libwasm.demo_setters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") +libwasm.demo_getters("/home/bloodstalker/extra/faultreiber/test//read.wasm") +--libwasm.demo_getters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm") +libwasm.demo_setters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") --libwasm.dump_all("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") --libwasm.dump_all("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm") ---libwasm.demo_setter_aux() +libwasm.demo_setter_aux() return libwasm -- cgit v1.2.3