aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser
diff options
context:
space:
mode:
Diffstat (limited to 'bruiser')
-rw-r--r--bruiser/bruiser.cpp17
-rw-r--r--bruiser/bruisercapstone.c2
-rw-r--r--bruiser/lua-scripts/asmrw.lua2
-rw-r--r--bruiser/lua-scripts/df-demo.lua46
-rw-r--r--bruiser/makefile2
-rwxr-xr-xbruiser/run.sh2
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