diff options
author | bloodstalker <thabogre@gmail.com> | 2018-04-08 06:28:07 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-04-08 06:28:07 +0000 |
commit | adc7bcd0697131e1067763e9d1b96d6ece6f1e9f (patch) | |
tree | b065ea10ccd4dbe3c91454ed588a2d81953c0426 /bruiser | |
parent | added some more features, a lil bit closer to getting the nested function cal... (diff) | |
download | mutator-adc7bcd0697131e1067763e9d1b96d6ece6f1e9f.tar.gz mutator-adc7bcd0697131e1067763e9d1b96d6ece6f1e9f.zip |
added some more cli options to load.py. added a new test file for bruiser to see how it fares against bigger files.
Diffstat (limited to 'bruiser')
-rw-r--r-- | bruiser/bruiser.cpp | 17 | ||||
-rw-r--r-- | bruiser/bruisercapstone.c | 2 | ||||
-rw-r--r-- | bruiser/lua-scripts/asmrw.lua | 2 | ||||
-rw-r--r-- | bruiser/lua-scripts/df-demo.lua | 46 | ||||
-rw-r--r-- | bruiser/makefile | 2 | ||||
-rwxr-xr-x | bruiser/run.sh | 2 |
6 files changed, 66 insertions, 5 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 82cd632..cdb4ef4 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -166,7 +166,10 @@ template <typename T> std::vector<T> getLuaTableInt(lua_State* __ls, int numargs, int argnum) { std::vector<T> ret; int table_length = lua_rawlen(__ls, argnum); - lua_checkstack(__ls, table_length); + if (!lua_checkstack(__ls, table_length)) { + std::cout << RED << "need to grow lua stack by " << table_length << ":"; + PRINT_WITH_COLOR_LB(RED, "cant grow lua stack by that much."); + } for (int i = 1; i <= table_length; ++i) { lua_rawgeti(__ls, argnum, i); ret.push_back(lua_tointeger(__ls, i + numargs)); @@ -177,7 +180,10 @@ std::vector<T> getLuaTableInt(lua_State* __ls, int numargs, int argnum) { std::vector<std::string> getLuaTableString(lua_State* __ls, int numargs, int argnum) { std::vector<std::string> ret; int table_length = lua_rawlen(__ls, argnum); - lua_checkstack(__ls, table_length); + if (!lua_checkstack(__ls, table_length)) { + std::cout << RED << "need to grow lua stack by " << table_length << ":"; + PRINT_WITH_COLOR_LB(RED, "cant grow lua stack by that much."); + } for (int i = 1; i <= table_length; ++i) { lua_rawgeti(__ls, argnum, i); ret.push_back(lua_tostring(__ls, i + numargs)); @@ -189,7 +195,10 @@ template <typename T> std::vector<T> getLuaTableNumber(lua_State* __ls, int numargs, int argnum) { std::vector<T> ret; int table_length = lua_rawlen(__ls, argnum); - lua_checkstack(__ls, table_length); + if (!lua_checkstack(__ls, table_length)) { + std::cout << RED << "need to grow lua stack by " << table_length << ":"; + PRINT_WITH_COLOR_LB(RED, "cant grow lua stack by that much."); + } for (int i = 1; i <= table_length; ++i) { lua_rawgeti(__ls, argnum, i); ret.push_back(lua_tonumber(__ls, i + numargs)); @@ -1605,7 +1614,9 @@ class LuaWrapper if (numargs != 2) {PRINT_WITH_COLOR_LB(RED, "expected exactly two args. did not get that.");return 0;} uint64_t size = lua_tointeger(__ls, 1); std::vector<uint8_t> code_v = getLuaTableInt<uint8_t>(__ls, 2, 2); + if (Verbose) PRINT_WITH_COLOR_LB(BLUE, "making jump table..."); auto head = makejmptable(size, code_v.data(), Verbose, __ls); + if (Verbose) PRINT_WITH_COLOR_LB(GREEN, "finished makejmptable call."); jmpt_push_args(__ls, head); new_jmpt_2(__ls); return 1; diff --git a/bruiser/bruisercapstone.c b/bruiser/bruisercapstone.c index 8edc7ad..abb21aa 100644 --- a/bruiser/bruisercapstone.c +++ b/bruiser/bruisercapstone.c @@ -234,7 +234,9 @@ JMP_S_T* makejmptable(size_t size, uint8_t* obj, bool Verbose, lua_State* __ls) if (cs_open(CS_ARCH_X86, CS_MODE_64, &handle) != CS_ERR_OK) return NULL; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpointer-sign" + printf("starting to disassemble...\n"); count = cs_disasm(handle, obj, size, 0x0, 0, &insn); + printf("finished disassembling.\n"); #pragma GCC diagnostic pop if (Verbose) printf("number of instructions: %zu.\n\n", count); cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON); diff --git a/bruiser/lua-scripts/asmrw.lua b/bruiser/lua-scripts/asmrw.lua index 2f68d2b..68603fa 100644 --- a/bruiser/lua-scripts/asmrw.lua +++ b/bruiser/lua-scripts/asmrw.lua @@ -19,6 +19,8 @@ --start of asmrewriter module local asmrw = {} xobj = require("lua-scripts.xobj") +-- this will hold a copy of the original text section +local text_buffer = {} setmetatable(jmp_s_t, {__call = function(self, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) diff --git a/bruiser/lua-scripts/df-demo.lua b/bruiser/lua-scripts/df-demo.lua new file mode 100644 index 0000000..35a6b7a --- /dev/null +++ b/bruiser/lua-scripts/df-demo.lua @@ -0,0 +1,46 @@ + +xobj = require("lua-scripts.xobj") +asmrw = require("lua-scripts.asmrw") +colors = require("ansicolors") + +df_exe = "/home/bloodstalker/df/df_44_09_linux/df_linux/libs/Dwarf_Fortress" + +function main() + local text_section = xobj.getTextSection(df_exe) +end + +function pretty_dump() + count = 0 + local text_section = xobj.getTextSection(df_exe) + io.write(colors("%{blue}".." ".."\t".."00 ".."01 ".."02 ".."03 ".."04 ".."05 ".."06 ".."07 ".."08 ".."09 ".."0A ".."0B ".."0C ".."0D ".."0E ".."0F")) + for k,v in pairs(text_section) do + if count % 16 == 0 then + print() + io.write(colors("%{blue}".."0x"..string.format("%03x",count)), "\t") + end + io.write(colors("%{green}"..string.format("%02x", v)), " ") + count = count + 1 + end + count = 0 + print() +end + +function jmp_table_test() + local text_section = xobj.getTextSection(df_exe) + local head = jmp_s_t() + -- messes up the stack. I could fix it but not sure why i would want to keep this in + --local head2 = jmp_s_t:new() + io.write("lua:calling getjmptable\n") + head = getjmptable(#text_section, text_section) + + while head:inext() ~= nil do + head:dump("entry") + io.write("type:", head:type(), "\tlocation:", "0x"..string.format("%x", head:location())) + print() + head = head:inext() + end +end + +--main() +--pretty_dump() +jmp_table_test() diff --git a/bruiser/makefile b/bruiser/makefile index 31a6892..60c90c6 100644 --- a/bruiser/makefile +++ b/bruiser/makefile @@ -71,5 +71,5 @@ help: @echo 'there is help.' @echo 'all is the defualt target.' @echo 'clean runs clean.' - @echo 'deepclean will also clean the lua build' + @echo 'deepclean will also clean lua and luajit' @echo 'for a more complete and detaild list of BUILD_MODE and other things look at the main makefiles help under project root.' diff --git a/bruiser/run.sh b/bruiser/run.sh index 226271b..955fc70 100755 --- a/bruiser/run.sh +++ b/bruiser/run.sh @@ -1,4 +1,4 @@ #!/bin/bash cd $(dirname $0) -"./bruiser" ../test/bruisertest/test.cpp +"./bruiser" ../test/bruisertest/test.cpp --verbose |