aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser
diff options
context:
space:
mode:
Diffstat (limited to 'bruiser')
-rwxr-xr-xbruiser/asm.sh5
-rw-r--r--bruiser/asmrewriter.c60
-rw-r--r--bruiser/asmrewriter.h41
-rw-r--r--bruiser/bruiser.cpp1
-rw-r--r--bruiser/bruisercapstone.h2
-rw-r--r--bruiser/makefile2
6 files changed, 63 insertions, 48 deletions
diff --git a/bruiser/asm.sh b/bruiser/asm.sh
new file mode 100755
index 0000000..e45f022
--- /dev/null
+++ b/bruiser/asm.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+cd $(dirname $0)
+clang ./asmrewriter.c -llua -o asmrewriter
+./asmrewriter || exit 1
+rm ./asmrewriter
diff --git a/bruiser/asmrewriter.c b/bruiser/asmrewriter.c
index 2bfdcf1..b677a1d 100644
--- a/bruiser/asmrewriter.c
+++ b/bruiser/asmrewriter.c
@@ -19,7 +19,9 @@ 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.hpp"
+#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 "./asmrewriter.h"
@@ -27,38 +29,38 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
/**********************************************************************************************************************/
static JMP_S_T* convert_jmpt(lua_State* __ls, int index) {
JMP_S_T* dummy = (JMP_S_T*)lua_touserdata(__ls, index);
- if (dummy == NULL) luaL_typerror(__ls, index, dummy);
+ //if (dummy == NULL) luaL_typerror(__ls, index, dummy);
return dummy;
}
static JMP_S_T* check_jmpt(lua_State* __ls, int index) {
JMP_S_T* dummy;
luaL_checktype(__ls, index, LUA_TUSERDATA);
- dummy = (JMP_S_T*)luaL_checkudata(__ls, index, JMP_S_T);
- if (dummy == NULL) luaL_typerror(__ls, index, dummy);
+ dummy = (JMP_S_T*)luaL_checkudata(__ls, index, "jmp_s_t");
+ //if (dummy == NULL) luaL_typerror(__ls, index, dummy);
return dummy;
}
static JMP_S_T* push_jmpt(lua_State* __ls) {
JMP_S_T* dummy = (JMP_S_T*)lua_newuserdata(__ls, sizeof(JMP_S_T));
- luaL_getmetatable(__ls, JMP_S_T);
+ luaL_getmetatable(__ls, "jmp_s_t");
lua_setmetatable(__ls, -2);
return dummy;
}
static int new_jmpt(lua_State* __ls) {
- JMP_T jmp_t = luaL_optint(__ls, 1, 0);
- uint64_t location = luaL_optint(__ls, 2, 0);
- uint8_t size = luaL_optint(__ls, 3, 0);
+ JMP_T jmp_t = luaL_optinteger(__ls, 1, 0);
+ uint64_t location = luaL_optinteger(__ls, 2, 0);
+ uint8_t size = luaL_optinteger(__ls, 3, 0);
//
//
//
- uint64_t address = luaL_optint(__ls, 7, 0);
- uint64_t address_y = luaL_optint(__ls, 8, 0);
- uint64_t address_n = luaL_optint(__ls, 9, 0);
- unsigned char y = luaL_optint(__ls, 10, 0);
- unsigned char n = luaL_optint(__ls, 11, 0);
- unsigned char z = luaL_optint(__ls, 12, 0);
+ uint64_t address = luaL_optinteger(__ls, 7, 0);
+ uint64_t address_y = luaL_optinteger(__ls, 8, 0);
+ uint64_t address_n = luaL_optinteger(__ls, 9, 0);
+ unsigned char y = luaL_optinteger(__ls, 10, 0);
+ unsigned char n = luaL_optinteger(__ls, 11, 0);
+ unsigned char z = luaL_optinteger(__ls, 12, 0);
JMP_S_T* dummy = push_jmpt(__ls);
dummy->type = jmp_t;
dummy->location = location;
@@ -96,7 +98,7 @@ static int jmpt_custom(lua_State* __ls) {
#define SET_GENERATOR(X) \
static int jmpt_set_##X(lua_State* __ls) {\
JMP_S_T* dummy = check_jmpt(__ls,1);\
- dummy->type = luaL_checkint(__ls, 2);\
+ dummy->type = luaL_checkinteger(__ls, 2);\
lua_settop(__ls, 1);\
return 1;\
}
@@ -124,10 +126,32 @@ static int jmpt_set_next_n(lua_State* __ls) {}
static int jmpt_gc(lua_State* __ls) {}
+static const luaL_Reg jmpt_methods[] = {
+ {"new", new_jmpt},
+ {"set_type", jmpt_set_type},
+ {"set_location", jmpt_set_location},
+ {"set_size", jmpt_set_size},
+ {"set_address", jmpt_set_address},
+ {"set_address_y", jmpt_set_address_y},
+ {"set_address_n", jmpt_set_address_n},
+ {"set_next", jmpt_set_next},
+ {"set_next_y", jmpt_set_next_y},
+ {"set_next_n", jmpt_set_next_n},
+ {"set_y", jmpt_set_y},
+ {"set_n", jmpt_set_n},
+ {"set_z", jmpt_set_z},
+ {0,0}
+};
+
+static const luaL_Reg jmpt_meta[] = {
+ {"__gc", jmpt_gc},
+ {0, 0}
+};
+
int jmpt_register(lua_State* __ls) {
- luaL_openlib(__ls, JMP_S_T, jmpt_methods, 0);
- luaL_newmetatable(__ls, JMP_S_T);
- luaL_openlib(__ls, 0, jmpt_meta, 0);
+ luaL_newlib(__ls, jmpt_methods);
+ luaL_newmetatable(__ls, "jmp_s_t");
+ luaL_newlib(__ls, jmpt_meta);
lua_pushliteral(__ls, "__index");
lua_pushvalue(__ls, -3);
lua_rawset(__ls, -3);
diff --git a/bruiser/asmrewriter.h b/bruiser/asmrewriter.h
index ce28dcd..048b6ec 100644
--- a/bruiser/asmrewriter.h
+++ b/bruiser/asmrewriter.h
@@ -1,5 +1,4 @@
-
/***************************************************Project Mutator****************************************************/
/*first line intentionally left blank.*/
/*bruiser's lua asmrewriter implementation for jump tables*/
@@ -19,7 +18,12 @@ 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.hpp"
+#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 <inttypes.h>
@@ -53,36 +57,17 @@ X_LIST_GEN
#undef X_LIST_GEN
#undef SET_GENERATOR
-static int jmpt_set_next(lua_State* __ls) {}
-static int jmpt_set_next_y(lua_State* __ls) {}
-static int jmpt_set_next_n(lua_State* __ls) {}
+static int jmpt_set_next(lua_State* __ls);
+static int jmpt_set_next_y(lua_State* __ls);
+static int jmpt_set_next_n(lua_State* __ls);
-static const luaL_reg jmpt_methods[] = {
- {"new", new_jmpt},
- {"set_type", jmpt_set_type},
- {"set_location", jmpt_set_location},
- {"set_size", jmpt_set_size},
- {"set_address", jmpt_set_address},
- {"set_address_y", jmpt_set_address_y},
- {"set_address_n", jmpt_set_address_n},
- {"set_next", jmpt_set_next},
- {"set_next_y", jmpt_set_next_y},
- {"set_next_n", jmpt_set_next_n},
- {"set_y", jmpt_set_y},
- {"set_n", jmpt_set_n},
- {"set_z", jmpt_set_z},
- {0,0}
-};
+static int jmpt_gc(lua_State* __ls);
-static int jmpt_gc(lua_State* __ls) {}
+int jmpt_register(lua_State* __ls);
-static const luaL_reg jmpt_meta[] = {
- {"__gc", jmpt_gc},
- {0, 0}
+#endif
+#ifdef __cplusplus
}
-
-int jmpt_register(lua_State* __ls) {
-
#endif
/**********************************************************************************************************************/
/*last line intentionally left blank.*/
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index e6a3520..6056da8 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
#include "executioner.h"
#include "bruiserffi.h"
#include "bruisercapstone.h"
+#include "asmrewriter.h"
/*standard headers*/
#include <fstream>
#include <string>
diff --git a/bruiser/bruisercapstone.h b/bruiser/bruisercapstone.h
index d10db70..13ed37f 100644
--- a/bruiser/bruisercapstone.h
+++ b/bruiser/bruisercapstone.h
@@ -46,7 +46,7 @@ struct jmp_s_t {
bool y;
bool n;
bool z;
-};
+}jmp_s_t;
#define JMP_S_T struct jmp_s_t
JMP_S_T* iter_next(JMP_S_T* arg);
JMP_S_T* iter_next_y(JMP_S_T* arg);
diff --git a/bruiser/makefile b/bruiser/makefile
index a50faf4..b429ae7 100644
--- a/bruiser/makefile
+++ b/bruiser/makefile
@@ -50,7 +50,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 $(LIB_LUA)
+$(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)
$(CXX) $^ $(LD_FLAGS) -o $@
clean: