aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bruiser/bruiser.cpp6
-rw-r--r--bruiser/defaults.lua3
-rw-r--r--bruiser/lua-scripts/asmtest.lua4
-rw-r--r--bruiser/luatablegen/makefile34
-rw-r--r--bruiser/makefile11
-rw-r--r--bruiser/wasm.h13
-rwxr-xr-xbruiser/wasm/dwasm.py38
7 files changed, 62 insertions, 47 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index 7b3864d..b38327e 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
#include "asmrewriter.h"
#include "ramdump.h"
#include "ffs.h"
+#include "./luatablegen/wasm_tables.h"
/*standard headers*/
#include <exception>
#include <fstream>
@@ -254,6 +255,10 @@ class LuaEngine
lua_pop(LS, 1);
}
+ void registerAutogenTables(void) {
+ reg_tablegen_tables(LS);
+ }
+
void RunLuaDefaults(void) {
char buf[500];
std::string bruiser_path;
@@ -2305,6 +2310,7 @@ int main(int argc, const char **argv) {
LE.LoadEverylib();
LE.RunLuaDefaults();
LE.registerJMPTable();
+ LE.registerAutogenTables();
void* lua_e_p = lua_getextraspace_wrapper(LE.GetLuaState(), 0);
void* lua_e_p2 = lua_getextraspace_wrapper(LE.GetLuaState(), 1);
RunLoop runloop(LE.GetLuaState(), LE);
diff --git a/bruiser/defaults.lua b/bruiser/defaults.lua
index d0e91d4..8f1692b 100644
--- a/bruiser/defaults.lua
+++ b/bruiser/defaults.lua
@@ -1,5 +1,8 @@
-- bruiser default script.
-- This is run everytime bruiser is called.
+-- By default bruiser will look for a file named defaults.lua in the same
+-- directory as its executable. you can change the file using the --luadefault
+-- option.
-- adds luarocks' path and cpath to bruiser
function default_luarocks_modules()
diff --git a/bruiser/lua-scripts/asmtest.lua b/bruiser/lua-scripts/asmtest.lua
index ac5730e..d7c0583 100644
--- a/bruiser/lua-scripts/asmtest.lua
+++ b/bruiser/lua-scripts/asmtest.lua
@@ -1,6 +1,6 @@
-xobj = require("lua-scripts.xobj")
-asmrw = require("lua-scripts.asmrw")
+xobj = require("xobj")
+asmrw = require("asmrw")
function test()
local elf_exe = "../bfd/test/test"
diff --git a/bruiser/luatablegen/makefile b/bruiser/luatablegen/makefile
new file mode 100644
index 0000000..937902b
--- /dev/null
+++ b/bruiser/luatablegen/makefile
@@ -0,0 +1,34 @@
+CC=clang
+CC?=clang
+CC_FLAGS=
+CC_EXTRA?=
+CC_FLAGS+=$(CC_EXTRA)
+SRCS=$(wildcard *.c)
+TBG_OBJLIST=$(patsubst %.c, %.o , $(wildcard *.c))
+
+.DEFAULT:all
+
+.PHONY:all clean help
+
+all:$(TBG_OBJLIST)
+ @echo $(TBG_OBJLIST)
+ @echo $(TBG_OBJLIST_INC)
+
+depend:.depend
+
+.depend:$(SRCS)
+ rm -rf .depend
+ $(CC) -MM $(CC_FLAGS) $^ > ./.depend
+
+-include ./.depend
+
+.c.o:
+ $(CC) $(CC_FLAGS) -c $< -o $@
+
+clean:
+ rm -f *.o *~ $(TARGET)
+ rm .depend
+
+help:
+ @echo "all is the default target"
+ @echo "there is clean."
diff --git a/bruiser/makefile b/bruiser/makefile
index d6682c9..3f38539 100644
--- a/bruiser/makefile
+++ b/bruiser/makefile
@@ -17,10 +17,11 @@ 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 -L./lua-5.3.4/src -llua
+TBG_OBJLIST_INC=$(patsubst ./luatablegen/%.c, ./luatablegen/%.o, $(wildcard ./luatablegen/*.c))
######################################RULES####################################
.DEFAULT: all
-.PHONY: all clean help
+.PHONY: all clean help tablegen
all: $(BRUISER)
@@ -45,6 +46,10 @@ dependc:.dependc
linenoise.o:
$(CC) $(CC_FLAGS) linenoise/linenoise.c -c -o linenoise.o
+tablegen:
+ ../extra-tools/tablegen-test/run.sh
+ $(MAKE) -C luatablegen
+
$(LIB_LUA):
$(MAKE) -C lua-5.3.4/src linux a
@echo "building with vanilla"
@@ -53,13 +58,14 @@ $(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 asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA)
+$(BRUISER): $(BRUISER).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC)
$(CXX) $^ $(LD_FLAGS) -o $@
clean:
rm -f *.o *~ $(BRUISER)
rm .depend
rm .dependc
+ $(MAKE) -C luatablegen clean
deepclean:
rm -f *.o *~ $(BRUISER)
@@ -67,6 +73,7 @@ deepclean:
rm .dependc
$(MAKE) -C lua-5.3.4 clean
$(MAKE) -C LuaJIT clean
+ $(MAKE) -C luatablegen clean
help:
@echo 'there is help.'
diff --git a/bruiser/wasm.h b/bruiser/wasm.h
index ec68553..5c21c99 100644
--- a/bruiser/wasm.h
+++ b/bruiser/wasm.h
@@ -97,7 +97,7 @@ typedef int32_t varuint32;
}W_Import_Section_Entry;
typedef struct {
- int count;
+ varuint32 count;
W_Import_Section_Entry** entries;
}W_Import_Section;
@@ -119,7 +119,7 @@ typedef int32_t varuint32;
typedef struct {
global_type_t* type;
- init_expr_t init;
+ init_expr_t* init;
}W_Global_Entry;
typedef struct {
@@ -131,7 +131,7 @@ typedef int32_t varuint32;
varuint32 field_len;
char* field_str;
enum external_kind_t kind;
- int varuint32;
+ varuint32 index;
}W_Export_Entry;
typedef struct {
@@ -145,7 +145,7 @@ typedef int32_t varuint32;
typedef struct {
varuint32 index;
- init_expr_t offset;
+ init_expr_t* offset;
varuint32 num_length;
varuint32* elems;
}W_Elem_Segment;
@@ -175,14 +175,14 @@ typedef int32_t varuint32;
typedef struct {
varuint32 index;
- init_expr_t offset;
+ init_expr_t* offset;
varuint32 size;
char* data;
}W_Data_Segment;
typedef struct {
varuint32 count;
- struct W_Data_Segment** entries;
+ W_Data_Segment** entries;
}W_Data_Section;
#if 0
@@ -192,6 +192,7 @@ typedef int32_t varuint32;
#endif
typedef struct Wasm_Module {
+ W_Type_Section* type_section;
W_Import_Section* import_section;
W_Function_Section* function_section;
W_Table_Section* table_section;
diff --git a/bruiser/wasm/dwasm.py b/bruiser/wasm/dwasm.py
index 93217b4..28f3c4d 100755
--- a/bruiser/wasm/dwasm.py
+++ b/bruiser/wasm/dwasm.py
@@ -5,45 +5,9 @@ import code
import readline
import signal
import sys
-from parse import premain
+from parse import Argparser, premain, SigHandler_SIGINT
from utils import ParseFlags
-def SigHandler_SIGINT(signum, frame):
- print()
- sys.exit(0)
-
-class Argparser(object):
- def __init__(self):
- parser = argparse.ArgumentParser()
- parser.add_argument("--wast", type=str, help="path to the wasm text file")
- parser.add_argument("--wasm", type=str, nargs='+', help="path to the wasm object file")
- parser.add_argument("--asb", type=str, help="path to the wast file to assemble")
- parser.add_argument("--dis", type=str, help="path to the wasm file to disassemble")
- parser.add_argument("-o", type=str, help="the path to the output file")
- parser.add_argument("--dbg", action='store_true', help="print debug info", default=False)
- parser.add_argument("--unval", action='store_true', help="skips validation tests", default=False)
- parser.add_argument("--memdump", type=int, help="dumps the linear memory")
- parser.add_argument("--idxspc", action='store_true', help="print index space data", default=False)
- parser.add_argument("--run", action='store_true', help="runs the start function", default=False)
- parser.add_argument("--metric", action='store_true', help="print metrics", default=False)
- parser.add_argument("--gas", action='store_true', help="print gas usage", default=False)
- parser.add_argument("--entry", type=str, help="name of the function that will act as the entry point into execution")
- parser.add_argument("--link", type=str, nargs="+", help="link the following wasm modules")
- parser.add_argument("--sectiondump", type=str, help="dumps the section provided")
- parser.add_argument("--hexdump", type=int, help="dumps all sections")
- parser.add_argument("--dbgsection", type=str, help="dumps the parsed section provided", default="")
- parser.add_argument("--interactive", action='store_true', help="open in cli mode", default=False)
- parser.add_argument("--rawdump", type=int, nargs=2, help="dumps all sections")
- self.args = parser.parse_args()
- if self.args.wasm is not None and self.args.wast is not None:
- raise Exception("the --wast option and the --wasm option cannot\
- be set at the same time. you need to choose one.")
-
- def getParseFlags(self):
- return(ParseFlags(self.args.wast, self.args.wasm, self.args.asb, self.args.dis,
- self.args.o, self.args.dbg, self.args.unval, self.args.memdump,
- self.args.idxspc, self.args.run, self.args.metric, self.args.gas, self.args.entry))
-
def main():
signal.signal(signal.SIGINT, SigHandler_SIGINT)
argparser = Argparser()