aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-07-19 00:09:20 +0000
committerbloodstalker <thabogre@gmail.com>2018-07-19 00:09:20 +0000
commit82dff3bff1b0d97585a2cbd574879057405cf363 (patch)
tree6b058fa70eb5176e21e6e51c80ff7d281801f565
parentfixing travis (diff)
downloadmutator-82dff3bff1b0d97585a2cbd574879057405cf363.tar.gz
mutator-82dff3bff1b0d97585a2cbd574879057405cf363.zip
a fix for the luatablegen json file, added a new option to load.py, minor cosmetic changes
-rwxr-xr-xbfd/load.py31
-rw-r--r--bruiser/bruiser.cpp12
-rw-r--r--bruiser/ffs.c2
-rw-r--r--bruiser/lua-scripts/demo1.lua2
-rw-r--r--bruiser/lua-scripts/demo3.lua6
-rw-r--r--bruiser/lua-scripts/regtest.lua17
-rw-r--r--bruiser/luatablegen/W_Import_Section_tablegen.c2
-rw-r--r--bruiser/luatablegen/makefile2
-rw-r--r--bruiser/makefile2
-rw-r--r--bruiser/wasm.c13
-rw-r--r--bruiser/wasm.h1
-rwxr-xr-xbruiser/wasm/parse.py7
-rw-r--r--bruiser/wasmtablegen.json2
13 files changed, 60 insertions, 39 deletions
diff --git a/bfd/load.py b/bfd/load.py
index 73ff05e..791f7ee 100755
--- a/bfd/load.py
+++ b/bfd/load.py
@@ -84,7 +84,8 @@ class CLIArgParser(object):
parser.add_argument("--reladyn", action='store_true', help=".rela.dyn entries", default=False)
parser.add_argument("--relaplt", action='store_true', help=".rela.plt entries", default=False)
parser.add_argument("--rodata", action='store_true', help="dump .rodata", default=False)
- parser.add_argument("--disass", type=str, help="disassemblt a section")
+ parser.add_argument("--disass", type=str, help="disassembls a section by name in section headers")
+ parser.add_argument("--disassp", type=int, help="disassembls a section by index in program headers")
self.args = parser.parse_args()
if self.args.obj is None:
raise Exception("no object file provided. please specify an object with --obj.")
@@ -167,11 +168,11 @@ def ffs(offset,header_list, numbered, *args):
if numbered:
numbers_f.extend(range(1, len(args[-1])+1))
- max_column_width.append(max([len(repr(number)) for number in numbers_f]))
+ max_column_width.append(max([len(repr(number)) for number in numbers_f]) if numbers_f else 6)
header_list.insert(0, "idx")
for arg in args:
- max_column_width.append(max([len(repr(argette)) for argette in arg]))
+ max_column_width.append(max([len(repr(argette)) for argette in arg]) if arg else 6)
index = range(0, len(header_list))
for header, width, i in zip(header_list, max_column_width, index):
@@ -1205,12 +1206,13 @@ class ELF(object):
section_whole = self.so.read(byte2int(section.sh_size))
size = byte2int(section.sh_size)
entsize = byte2int(section.sh_entsize)
- for i in range(0, int(size/entsize)):
- dummy["r_offset"] = byte2int(section_whole[i*entsize:i*entsize+step])
- dummy["r_info"] = byte2int(section_whole[i*entsize+step:i*entsize+(step*2)])
- dummy["r_addend"] = byte2int(section_whole[i*entsize+(step*2):i*entsize+(step*3)], sign=True)
- to_pop.append(dummy)
- dummy = {}
+ if entsize != 0:
+ for i in range(0, int(size/entsize)):
+ dummy["r_offset"] = byte2int(section_whole[i*entsize:i*entsize+step])
+ dummy["r_info"] = byte2int(section_whole[i*entsize+step:i*entsize+(step*2)])
+ dummy["r_addend"] = byte2int(section_whole[i*entsize+(step*2):i*entsize+(step*3)], sign=True)
+ to_pop.append(dummy)
+ dummy = {}
def pop_rel(self, section_name, section_whole, to_pop):
size = int()
@@ -1438,6 +1440,17 @@ def premain(argparser):
md = Cs(CS_ARCH_X86, CS_MODE_64)
for i in md.disasm(bytes(code), 0x0):
print(hex(i.address).ljust(7), i.mnemonic.ljust(7), i.op_str)
+ elif argparser.args.disassp != None:
+ index = argparser.args.disassp
+ # section not executable message
+ if byte2int(elf.phdr[index].p_flags) & 0x1 != 1: print("program header section is not executable but since you asked...")
+ header_offset = elf.phdr[index].p_offset
+ header_size = elf.phdr[index].p_filesz
+ elf.so.seek(byte2int(header_offset))
+ code = elf.so.read(byte2int(header_size))
+ md = Cs(CS_ARCH_X86, CS_MODE_64)
+ for i in md.disasm(bytes(code), 0x0):
+ print(hex(i.address).ljust(7), i.mnemonic.ljust(7), i.op_str)
elif argparser.args.textasm:
md = Cs(CS_ARCH_X86, CS_MODE_64)
for i in md.disasm(bytes(elf.text_section), 0x0):
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index 99f7731..56ea865 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -345,7 +345,7 @@ class LuaEngine
/**********************************************************************************************************************/
class PyExec {
public:
- PyExec(std::string __py_script_name, std::string __py_func_name, std::string __obj_path ) :
+ PyExec(std::string __py_script_name, std::string __py_func_name, std::string __obj_path ) :
py_script_name(__py_script_name), py_func_name(__py_func_name), obj_path(__obj_path) {}
~PyExec() {
Py_Finalize();
@@ -531,6 +531,9 @@ class PyExec {
return 0;
}
+ int getWasmModule(void) {
+ }
+
void killPyObj(void) {
Py_DECREF(pValue);
}
@@ -1454,6 +1457,8 @@ class LuaWrapper
lua_pushinteger(__ls, iter);
lua_settable(__ls, -3);
}
+ } else if (action == "wasm_module") {
+ py.getWasmModule();
}
if (Verbose) PRINT_WITH_COLOR_LB(GREEN, "done.");
@@ -1529,7 +1534,7 @@ class LuaWrapper
// 2-table of strings
std::string ffi_ret_type_string = lua_tostring(__ls, 3);
- void* x_ptr;
+ void* x_ptr;
if (lua_type(__ls, 4) == LUA_TNUMBER) {
if (vptrs.size() - 1 > lua_tointeger(__ls, 4)) x_ptr = std::get<0>(vptrs[lua_tointeger(__ls, 4)]);
} else if (lua_type(__ls, 4) == LUA_TSTRING) {
@@ -1627,7 +1632,6 @@ class LuaWrapper
if (x_ptr != nullptr) {
result = ffi_callX(argc, args, ret_type, x_ptr, values);
if (result == nullptr) {PRINT_WITH_COLOR_LB(RED, "ffi_callX returned null.");return 0;}
-
if (std::strcmp(ffi_ret_type_string.c_str(), "void") == 0) {lua_pushnil(__ls);}
else if (std::strcmp(ffi_ret_type_string.c_str(), "uint8") == 0) {lua_pushinteger(__ls, ffi_reinterpret_uint8_t(result));}
else if (std::strcmp(ffi_ret_type_string.c_str(), "sint8") == 0) {lua_pushinteger(__ls, ffi_reinterpret_int8_t(result));}
@@ -2052,7 +2056,7 @@ class LuaWrapper
int BruiserLuaGetPath(lua_State* __ls) {
unsigned int returncount = 0;
- for (auto &iter : ShellGlobalInstance.PATH){
+ for (auto &iter : ShellGlobalInstance.PATH){
lua_pushstring(__ls, iter.c_str());
std::cout << BLUE << iter.c_str() << NORMAL << "\n";
returncount++;
diff --git a/bruiser/ffs.c b/bruiser/ffs.c
index 940ae47..bda5e3f 100644
--- a/bruiser/ffs.c
+++ b/bruiser/ffs.c
@@ -19,7 +19,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
/**********************************************************************************************************************/
#include "ffs.h"
-// @DEVI-the acceptable indexes right now are 0 and 19 since we are only reserving 2 void* slots in luaconf.h.
+// @DEVI-the acceptable indexes right now are 0 and 19 since we are only reserving 20 void* slots in luaconf.h.
void* lua_getextraspace_wrapper(lua_State* __ls, int index) {
return lua_getextraspace(__ls) + sizeof(void*)*index;
}
diff --git a/bruiser/lua-scripts/demo1.lua b/bruiser/lua-scripts/demo1.lua
index c349c36..c768687 100644
--- a/bruiser/lua-scripts/demo1.lua
+++ b/bruiser/lua-scripts/demo1.lua
@@ -65,7 +65,7 @@ end
function Demo1.findMain()
local c = objload("load", "elf_get_func_names", elf_file, "symbol_list")
for k,v in ipairs(c) do
- if v == "main" then
+ if v == "main" then
io.write("main index is".." "..k.."\n")
return k
end
diff --git a/bruiser/lua-scripts/demo3.lua b/bruiser/lua-scripts/demo3.lua
index 89dde81..0e8e309 100644
--- a/bruiser/lua-scripts/demo3.lua
+++ b/bruiser/lua-scripts/demo3.lua
@@ -10,4 +10,10 @@ function demo3.init()
table_type:set_resizable_limit(resizable_limit)
end
+function demo3.getmodule_py()
+ local wasm = require("wasm")
+ local wasm_module = Wasm_Module()
+ local wasm_module = objload("dwasm", "elf_get_obj_names", elf_file, "symbol_list")
+end
+
return demo3
diff --git a/bruiser/lua-scripts/regtest.lua b/bruiser/lua-scripts/regtest.lua
index f7ec461..9cb1250 100644
--- a/bruiser/lua-scripts/regtest.lua
+++ b/bruiser/lua-scripts/regtest.lua
@@ -3,10 +3,19 @@
--local posix = require("posix")
function reg_test()
- local demo1 = require("demo1")
- local demo2 = require("demo2")
- local demo3 = require("asmtest")
- print("yo")
+ local xobj = require("demo1")
+ local jmp_table = require("demo2")
+ local asm_rewriter = require("asmtest")
+ local wasm_import = require("demo3")
+
+ local argparse = require("argparse")
+
+ local parser = argparse("regtest", "bruiser's regression test script")
+ parser:flag("-x --xobj")
+ parser:flag("-j --jmpt")
+ parser:flag("-a --asm")
+ parser:flag("-w --wasm")
+
end
reg_test()
diff --git a/bruiser/luatablegen/W_Import_Section_tablegen.c b/bruiser/luatablegen/W_Import_Section_tablegen.c
index 5286c75..b56c81b 100644
--- a/bruiser/luatablegen/W_Import_Section_tablegen.c
+++ b/bruiser/luatablegen/W_Import_Section_tablegen.c
@@ -41,7 +41,7 @@ int W_Import_Section_push_args(lua_State* __ls, W_Import_Section* _st) {
int new_W_Import_Section(lua_State* __ls) {
lua_checkstack(__ls, 2);
varuint32 count = luaL_optinteger(__ls,-2,0);
- W_Import_Section** entries = lua_touserdata(__ls,-1);
+ W_Import_Section_Entry** entries = lua_touserdata(__ls,-1);
W_Import_Section* dummy = push_W_Import_Section(__ls);
dummy->count = count;
dummy->entries = entries;
diff --git a/bruiser/luatablegen/makefile b/bruiser/luatablegen/makefile
index 937902b..a4ecdaf 100644
--- a/bruiser/luatablegen/makefile
+++ b/bruiser/luatablegen/makefile
@@ -1,6 +1,6 @@
CC=clang
CC?=clang
-CC_FLAGS=
+CC_FLAGS=$(shell $(PY_CONF) --includes)
CC_EXTRA?=
CC_FLAGS+=$(CC_EXTRA)
SRCS=$(wildcard *.c)
diff --git a/bruiser/makefile b/bruiser/makefile
index 31dff92..b0cac30 100644
--- a/bruiser/makefile
+++ b/bruiser/makefile
@@ -6,7 +6,7 @@ CC=clang
CC?=clang
CXX_FLAGS+=-I/usr/include -g
CXX_FLAGS+=$(shell $(PY_CONF) --includes)
-CC_FLAGS+=-g
+CC_FLAGS+=-g $(shell $(PY_CONF) --includes)
BRUISER=bruiser
LUA?=JIT
LIB_LUA=./lua-5.3.4/src/liblua.a
diff --git a/bruiser/wasm.c b/bruiser/wasm.c
index c517269..689083a 100644
--- a/bruiser/wasm.c
+++ b/bruiser/wasm.c
@@ -22,20 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
#include "./lua-5.3.4/src/lauxlib.h"
#include "./lua-5.3.4/src/lualib.h"
#include "./wasm.h"
+#include <Python.h>
/**********************************************************************************************************************/
-static Wasm_Module* convert_wasm_module(lua_State* ls, int index) {
- Wasm_Module* dummy = lua_touserdata(ls, index);
- if (dummy == NULL) {printf("convert_wasm_module: bad userdata.\n");}
- return dummy;
-}
-static Wasm_Module* check_wasm_module(lua_State* ls, int index) {
- Wasm_Module* dummy;
- luaL_checktype(ls, index, LUA_TUSERDATA);
- dummy = (Wasm_Module*)luaL_checkudata(ls, index, "wasm_module");
- if (dummy == NULL) {printf("check_wasm_module: bad userdata.\n");}
- return dummy;
-}
#pragma weak main
int main(int argc, char** argv) {
diff --git a/bruiser/wasm.h b/bruiser/wasm.h
index 5c21c99..7a716ba 100644
--- a/bruiser/wasm.h
+++ b/bruiser/wasm.h
@@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
#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 <Python.h>
#ifdef __cplusplus
extern "C" {
diff --git a/bruiser/wasm/parse.py b/bruiser/wasm/parse.py
index 424a2b6..9d7140d 100755
--- a/bruiser/wasm/parse.py
+++ b/bruiser/wasm/parse.py
@@ -25,14 +25,12 @@ class ParsedStruct:
self.version_number = int()
self.section_list = []
-
# like the above. currently unused
class ParsedStructV2:
def __init__(self, version_number, section_list):
self.version_number = version_number
self.section_list = section_list
-
# @DEVI-Deprecated-convert a bytearray to int
def Conver2Int(little_endian, size, bytelist):
modifier = size - 1
@@ -971,6 +969,7 @@ def premain(argparser):
if argparser.args.wasm:
for file_path in argparser.args.wasm:
module = interpreter.parse(file_path)
+ print(type(module))
interpreter.appendmodule(module)
if argparser.args.dbg or argparser.args.dbgsection:
interpreter.dump_sections(module, argparser.args.dbgsection)
@@ -988,8 +987,8 @@ def premain(argparser):
DumpLinearMems(ms.Linear_Memory, argparser.getMEMDUMP())
if argparser.args.run:
vm.run()
- # merklizer = Merklizer(ms.Linear_Memory[0][0:512], module)
- # treelength, hashtree = merklizer.run()
+ #merklizer = Merklizer(ms.Linear_Memory[0][0:512], module)
+ #treelength, hashtree = merklizer.run()
if argparser.args.interactive:
variables = globals().copy()
diff --git a/bruiser/wasmtablegen.json b/bruiser/wasmtablegen.json
index 38fe5a7..cb7899c 100644
--- a/bruiser/wasmtablegen.json
+++ b/bruiser/wasmtablegen.json
@@ -15,7 +15,7 @@
"W_Import_Section_Entry":
{"field_name":["module_length", "module_str", "field_len", "field_str", "kind", "type"], "field_type":["varuint32", "char*", "varuint32", "char*", "enum external_kind_t", "void*"], "lua_type": ["integer", "string", "integer", "string", "integer", "lightuserdata"], "methods": ["convert", "check", "push_self", "push_args", "new"]},
"W_Import_Section":
- {"field_name":["count", "entries"], "field_type":["varuint32","W_Import_Section**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]},
+ {"field_name":["count", "entries"], "field_type":["varuint32","W_Import_Section_Entry**"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]},
"W_Function_Section":
{"field_name":["count", "types"], "field_type":["varuint32", "varuint32*"], "lua_type":["integer", "lightuserdata"], "methods":["convert", "check", "push_self", "push_args", "new"]},
"W_Table_Section":