diff options
| author | bloodstalker <thabogre@gmail.com> | 2018-03-02 20:40:16 +0000 | 
|---|---|---|
| committer | bloodstalker <thabogre@gmail.com> | 2018-03-02 20:40:16 +0000 | 
| commit | 75fb62903425f19d0519c45a4c9ec7dc5f986f59 (patch) | |
| tree | 0f748b8f446c803db9c4ee177d88ae2eba2a4b26 /bruiser | |
| parent | some fixes for the jump table lua module (diff) | |
| download | mutator-75fb62903425f19d0519c45a4c9ec7dc5f986f59.tar.gz mutator-75fb62903425f19d0519c45a4c9ec7dc5f986f59.zip | |
the skeletion code for the jump table struct is now working
Diffstat (limited to 'bruiser')
| -rwxr-xr-x | bruiser/asm.sh | 2 | ||||
| -rw-r--r-- | bruiser/asmrewriter.c | 14 | ||||
| -rw-r--r-- | bruiser/asmrewriter.h | 8 | ||||
| -rw-r--r-- | bruiser/bruiser.cpp | 6 | ||||
| -rw-r--r-- | bruiser/bruisercapstone.h | 2 | ||||
| -rw-r--r-- | bruiser/lua-scripts/asmtest.lua | 6 | ||||
| -rw-r--r-- | bruiser/lua-scripts/demo2.lua | 8 | ||||
| -rw-r--r-- | bruiser/makefile | 8 | 
8 files changed, 41 insertions, 13 deletions
| diff --git a/bruiser/asm.sh b/bruiser/asm.sh index e45f022..a34f9c9 100755 --- a/bruiser/asm.sh +++ b/bruiser/asm.sh @@ -1,5 +1,5 @@  #!/bin/bash  cd $(dirname $0)  clang ./asmrewriter.c -llua -o asmrewriter -./asmrewriter || exit 1 +./asmrewriter ./lua-scripts/asmtest.lua || exit 1  rm ./asmrewriter diff --git a/bruiser/asmrewriter.c b/bruiser/asmrewriter.c index b677a1d..6226419 100644 --- a/bruiser/asmrewriter.c +++ b/bruiser/asmrewriter.c @@ -1,5 +1,4 @@ -  /***************************************************Project Mutator****************************************************/  /*first line intentionally left blank.*/  /*bruiser's lua asmrewriter implementation for jump tables*/ @@ -149,9 +148,9 @@ static const luaL_Reg jmpt_meta[] = {  };  int jmpt_register(lua_State* __ls) { -  luaL_newlib(__ls, jmpt_methods); +  luaL_openlib(__ls, "jmp_s_t", jmpt_methods, 0);    luaL_newmetatable(__ls, "jmp_s_t"); -  luaL_newlib(__ls, jmpt_meta); +  luaL_openlib(__ls, 0, jmpt_meta, 0);    lua_pushliteral(__ls, "__index");    lua_pushvalue(__ls, -3);    lua_rawset(__ls, -3); @@ -166,6 +165,15 @@ int jmpt_register(lua_State* __ls) {  //@DEVI-the main is only meant for testing  #pragma weak main  int main(int argc, char** argv) { +  lua_State* L = luaL_newstate(); +  luaL_openlibs(L); + +  jmpt_register(L); +  lua_pop(L, 1); + +  if (argc > 1) luaL_dofile(L, argv[1]); +  lua_close(L); +    return 0;  }  /**********************************************************************************************************************/ diff --git a/bruiser/asmrewriter.h b/bruiser/asmrewriter.h index 048b6ec..e8cd3c7 100644 --- a/bruiser/asmrewriter.h +++ b/bruiser/asmrewriter.h @@ -18,19 +18,19 @@ 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.*/  /**********************************************************************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif  #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 "./bruisercapstone.h" +//#include "./bruisercapstone.h"  #include <inttypes.h>  /**********************************************************************************************************************/  #ifndef ASM_REWRITER_H  #define ASM_REWRITER_H +#ifdef __cplusplus +extern "C" { +#endif  static JMP_S_T* convert_jmpt(lua_State* __ls, int index);  static JMP_S_T* check_jmpt(lua_State* __ls, int index);  static JMP_S_T* push_jmpt(lua_State* __ls); diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 6056da8..b7db84a 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -229,6 +229,11 @@ class LuaEngine        luaL_openlibs(LS);      } +    void registerJMPTable(void) { +      jmpt_register(LS); +      lua_pop(LS, 1); +    } +      void RunLuaDefaults(void) {        luaL_dofile(LS, LuaDefault.c_str());      } @@ -2197,6 +2202,7 @@ int main(int argc, const char **argv) {      LuaEngine LE;      LE.LoadEverylib();      LE.RunLuaDefaults(); +    LE.registerJMPTable();      *static_cast<LuaWrapper**>(lua_getextraspace(LE.GetLuaState())) = &LW;      /*@DEVI-this part is just registering our LuaWrapper member functions with lua so we can call them from lua.*/ diff --git a/bruiser/bruisercapstone.h b/bruiser/bruisercapstone.h index 13ed37f..6f9707e 100644 --- a/bruiser/bruisercapstone.h +++ b/bruiser/bruisercapstone.h @@ -33,7 +33,7 @@ extern "C" {  enum jmp_type {NONE=0, JMP=1, JNE=2, JE=3};  #define JMP_T enum jmp_type -struct jmp_s_t { +typedef struct jmp_s_t {    JMP_T type;    uint64_t location;    uint8_t size; diff --git a/bruiser/lua-scripts/asmtest.lua b/bruiser/lua-scripts/asmtest.lua new file mode 100644 index 0000000..529b7a7 --- /dev/null +++ b/bruiser/lua-scripts/asmtest.lua @@ -0,0 +1,6 @@ +function test() +  print("running asmtest.lua") +  for k,v in pairs(jmp_s_t) do print(k,v) end +end + +test() diff --git a/bruiser/lua-scripts/demo2.lua b/bruiser/lua-scripts/demo2.lua index c8de8aa..03d6089 100644 --- a/bruiser/lua-scripts/demo2.lua +++ b/bruiser/lua-scripts/demo2.lua @@ -55,7 +55,13 @@ function asm_rewriter()    freejmptable(haed)  end +function jmp_t_test() +  for k,v in pairs(jmp_s_t) do print(k,v) end +  local t = jmp_s_t.new() +end +  --main()  --pretty_dump()  --test() -asm_rewriter() +--asm_rewriter() +jmp_t_test() diff --git a/bruiser/makefile b/bruiser/makefile index b429ae7..62c954b 100644 --- a/bruiser/makefile +++ b/bruiser/makefile @@ -2,18 +2,20 @@  ######################################INCLUDES#################################  include ../macros.mk  #######################################VARS#################################### +CC=clang +CC?=clang  CXX_FLAGS+=-I/usr/include  CXX_FLAGS+=$(shell $(PY_CONF) --includes)  BRUISER=bruiser  LUA?=JIT  LIB_LUA=./lua-5.3.4/src/liblua.a  LIB_LUA_JIT=./LuaJIT/src/libluajit.a -HEADER_LIST=bruiser.h bruiser-extra.h CompletionHints.h +HEADER_LIST=  SRCS=$(wildcard *.cpp)  C_SRCS=$(wildcard *.c)  #for some reason without ld the build fails on ubuntu trusty on travis  #EXTRA_LD_FLAGS+=-lpthread -ldl -lutil -lm -Xlinker -lpython3 -EXTRA_LD_FLAGS+=$(shell $(PY_CONF) --ldflags) -lffi -lcapstone -lkeystone +EXTRA_LD_FLAGS+=$(shell $(PY_CONF) --ldflags) -lffi -lcapstone -lkeystone -L./lua-5.3.4/src -llua  ######################################RULES####################################  .DEFAULT: all @@ -50,7 +52,7 @@ $(LIB_LUA_JIT):  	$(MAKE) -C LuaJIT  	@echo "building with jit" -$(BRUISER): $(BRUISER).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o bruisercapstone.o asmrewriter.o $(LIB_LUA) +$(BRUISER): $(BRUISER).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o bruisercapstone.o $(LIB_LUA) asmrewriter.o  	$(CXX) $^ $(LD_FLAGS) -o $@  clean: | 
