From 381a95e59c2e8d03d609fdb8945ba09ecaee405c Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 6 Oct 2018 15:17:25 +0330 Subject: fixed more bugs on ft and ltg side. i had some fundamental misunderstandings on how clang encodes wasm objects. todo: test custom section getters and setters, garbage collection, repacking --- bruiser/autogen/wasm/ft/autowasm.c | 14 +- bruiser/autogen/wasm/test/aggregate.wasm | Bin 0 -> 6668 bytes bruiser/autogen/wasm/test/read.wasm | Bin 0 -> 21963 bytes bruiser/autogen/wasm/wasm.xml | 33 +---- bruiser/bruiser.cpp | 15 +- bruiser/faultreiber | 2 +- bruiser/lua-scripts/wasmtest.lua | 226 +------------------------------ 7 files changed, 23 insertions(+), 267 deletions(-) create mode 100644 bruiser/autogen/wasm/test/aggregate.wasm create mode 100644 bruiser/autogen/wasm/test/read.wasm (limited to 'bruiser') diff --git a/bruiser/autogen/wasm/ft/autowasm.c b/bruiser/autogen/wasm/ft/autowasm.c index a766d2a..043f220 100644 --- a/bruiser/autogen/wasm/ft/autowasm.c +++ b/bruiser/autogen/wasm/ft/autowasm.c @@ -30,7 +30,7 @@ int main(int argc, char **argv) { wasm_lib_ret_t *lib_ret = read_aggr_wasm(wasm); printf("finished reading\n"); -#if 1 +#if 0 printf("magic_number:%x\n", lib_ret->obj->magic_number_container->magic_number); printf("version:%x\n", lib_ret->obj->version_container->version); @@ -229,12 +229,12 @@ int main(int argc, char **argv) { } #endif - printf("sizeof magic:%d\n", sizeof(magic_number)); - printf("sizeof version:%d\n", sizeof(version)); - printf("current void count:%d\n", lib_ret->current_void_count); - printf("void_train first:0x%x\n", lib_ret->void_train[0]); - printf("void_train first:0x%x\n", lib_ret->void_train[1]); - printf("void_train self address:0x%x\n", lib_ret->void_train); + //printf("sizeof magic:%d\n", sizeof(magic_number)); + //printf("sizeof version:%d\n", sizeof(version)); + //printf("current void count:%d\n", lib_ret->current_void_count); + //printf("void_train first:0x%x\n", lib_ret->void_train[0]); + //printf("void_train first:0x%x\n", lib_ret->void_train[1]); + //printf("void_train self address:0x%x\n", lib_ret->void_train); // free(lib_ret->void_train[0]); // release_all(lib_ret->void_train, lib_ret->current_void_count); // free(lib_ret->void_train[2]); diff --git a/bruiser/autogen/wasm/test/aggregate.wasm b/bruiser/autogen/wasm/test/aggregate.wasm new file mode 100644 index 0000000..615e33b Binary files /dev/null and b/bruiser/autogen/wasm/test/aggregate.wasm differ diff --git a/bruiser/autogen/wasm/test/read.wasm b/bruiser/autogen/wasm/test/read.wasm new file mode 100644 index 0000000..838851e Binary files /dev/null and b/bruiser/autogen/wasm/test/read.wasm differ diff --git a/bruiser/autogen/wasm/wasm.xml b/bruiser/autogen/wasm/wasm.xml index db68ed7..e1b9b32 100644 --- a/bruiser/autogen/wasm/wasm.xml +++ b/bruiser/autogen/wasm/wasm.xml @@ -2,91 +2,68 @@ - + 1 - - 2 - - 3 - - 4 - - 5 - - - 6 - - 7 - - 8 - - 9 - - 10 - - 11 - - @@ -154,15 +131,15 @@ - + - - - + + + diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 048dc54..6e73a44 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -1422,10 +1422,9 @@ class LuaWrapper { else { if (Verbose) PRINT_WITH_COLOR_LB(GREEN, "good file"); } + PRINT_WITH_COLOR_LB(RED, "before"); wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm_file); - //std::cout << RED << std::hex << lib_ret->obj->magic_number_container->magic_number << "\n"; - //std::cout << lib_ret->obj->version_container->version << NORMAL << "\n"; - //std::cout << "die die die\n"; + PRINT_WITH_COLOR_LB(RED, "after"); close(wasm_file); #pragma clang diagnostic push @@ -1433,7 +1432,7 @@ class LuaWrapper { #pragma clang diagnostic ignored "-Wextra" if (Verbose) { printf("magic_number:%x\n", lib_ret->obj->magic_number_container->magic_number); - printf("version:%x\n", lib_ret->obj->version_container->version); + printf("version:%x\n", lib_ret->obj->w32_version_container->w32_version); printf("type section id:%d\n", lib_ret->obj->W_Type_Section_container->id); printf("type section payloadlength:%d\n", lib_ret->obj->W_Type_Section_container->payloadlength); @@ -1567,10 +1566,10 @@ class LuaWrapper { } //PRINT_WITH_COLOR_LB(BLUE, "magic"); - if (lib_ret->obj->version_container != NULL) { + if (lib_ret->obj->w32_version_container != NULL) { lua_pushstring(__ls, "version"); - version_push_args(__ls, lib_ret->obj->version_container); - new_version(__ls); + w32_version_push_args(__ls, lib_ret->obj->w32_version_container); + new_w32_version(__ls); lua_settable(__ls, -3); } //PRINT_WITH_COLOR_LB(BLUE, "version"); @@ -1662,6 +1661,8 @@ class LuaWrapper { lua_settable(__ls, -3); } //PRINT_WITH_COLOR_LB(BLUE, "data section"); + if (lib_ret->obj->W_Custom_Section_container != NULL) { + } return 1; } diff --git a/bruiser/faultreiber b/bruiser/faultreiber index bddc410..da65d18 160000 --- a/bruiser/faultreiber +++ b/bruiser/faultreiber @@ -1 +1 @@ -Subproject commit bddc4103d3f56cd25017f6948ea6a5eaa146bef6 +Subproject commit da65d18f0ebf28cb8a829a946d51d7111f6b493a diff --git a/bruiser/lua-scripts/wasmtest.lua b/bruiser/lua-scripts/wasmtest.lua index f005448..df59773 100644 --- a/bruiser/lua-scripts/wasmtest.lua +++ b/bruiser/lua-scripts/wasmtest.lua @@ -8,8 +8,6 @@ function libwasm.dump_type_section(a) if a["type_section"] ~= nil then io.write(tostring("id:"..a["type_section"]:id()).."\n") io.write(tostring("payloadlength:"..a["type_section"]:payloadlength()).."\n") - io.write(tostring("namelength:"..a["type_section"]:namelength()).."\n") - io.write(tostring("name:"..a["type_section"]:name()).."\n") io.write(tostring("count:"..a["type_section"]:count()).."\n") io.write("entries"..tostring(a["type_section"]:entries()).."\n") for k, v in pairs(a["type_section"]:entries()) do @@ -29,8 +27,6 @@ function libwasm.dump_import_section(a) if a["import_section"] ~= nil then io.write("id:"..tostring(a["import_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["import_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["import_section"]:namelength()).."\n") - io.write("name:"..tostring(a["import_section"]:name()).."\n") io.write("count:"..tostring(a["import_section"]:count()).."\n") io.write("entries"..tostring(a["import_section"]:entries()).."\n") for k, v in pairs(a["import_section"]:entries()) do @@ -52,8 +48,6 @@ function libwasm.dump_function_section(a) if a["function_section"] ~= nil then io.write("id:"..tostring(a["function_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["function_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["function_section"]:namelength()).."\n") - io.write("name:"..tostring(a["function_section"]:name()).."\n") io.write("count:"..tostring(a["function_section"]:count()).."\n") io.write("types:"..tostring(a["function_section"]:types()).."\n") for k,v in pairs(a["function_section"]:types()) do @@ -69,8 +63,6 @@ function libwasm.dump_table_section(a) if a["table_section"] ~= nil then io.write("id:"..tostring(a["table_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["table_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["table_section"]:namelength()).."\n") - io.write("name:"..tostring(a["table_section"]:name()).."\n") io.write("count:"..tostring(a["table_section"]:count()).."\n") io.write("entries:"..tostring(a["table_section"]:entries()).."\n") for k, v in pairs(a["table_section"]:entries()) do @@ -91,8 +83,6 @@ function libwasm.dump_memory_section(a) if a["memory_section"] ~= nil then io.write("id:"..tostring(a["memory_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["memory_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["memory_section"]:namelength()).."\n") - io.write("name:"..tostring(a["memory_section"]:name()).."\n") --for wasm v.1.0. memory section count is 1 --io.write("count:"..tostring(a["memory_section"]:count()).."\n") io.write("entries:"..tostring(a["memory_section"]:entries()).."\n") @@ -109,8 +99,6 @@ function libwasm.dump_global_section(a) if (a["global_section"] ~= nil) then io.write("id:"..tostring(a["global_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["global_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["global_section"]:namelength()).."\n") - io.write("name:"..tostring(a["global_section"]:name()).."\n") io.write("count:"..tostring(a["global_section"]:count()).."\n") io.write("globals:"..tostring(a["global_section"]:globals()).."\n") for k, v in pairs(a["global_section"]:globals()) do @@ -128,8 +116,6 @@ function libwasm.dump_export_section(a) if (a["export_section"] ~= nil) then io.write("id:"..tostring(a["export_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["export_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["export_section"]:namelength()).."\n") - io.write("name:"..tostring(a["export_section"]:name()).."\n") io.write("count:"..tostring(a["export_section"]:count()).."\n") io.write("entries:"..tostring(a["export_section"]:entries()).."\n") for k, v in pairs(a["export_section"]:entries()) do @@ -148,8 +134,6 @@ function libwasm.dump_start_section(a) if (a["start_section"] ~= nil) then io.write("id:"..tostring(a["start_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["start_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["start_section"]:namelength()).."\n") - io.write("name:"..tostring(a["start_section"]:name()).."\n") io.write("index:"..tostring(a["start_section"]:index()).."\n") else print(colors("%{red}".."section doesnt exist.")) @@ -161,8 +145,6 @@ function libwasm.dump_element_section(a) if (a["element_section"] ~= nil) then io.write("id:"..tostring(a["element_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["element_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["element_section"]:namelength()).."\n") - io.write("name:"..tostring(a["element_section"]:name()).."\n") io.write("count:"..tostring(a["element_section"]:count()).."\n") io.write(colors("%{cyan}".."entries:"..tostring(a["element_section"]:entries()).."\n")) for k, v in pairs(a["element_section"]:entries()) do @@ -190,8 +172,6 @@ function libwasm.dump_code_section(a) if (a["code_section"] ~= nil) then io.write("id:"..tostring(a["code_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["code_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["code_section"]:namelength()).."\n") - io.write("name:"..tostring(a["code_section"]:name()).."\n") io.write("count:"..tostring(a["code_section"]:count()).."\n") io.write("bodies:"..tostring(a["code_section"]:bodies()).."\n") for k,v in pairs(a["code_section"]:bodies()) do @@ -219,8 +199,6 @@ function libwasm.dump_data_section(a) if (a["data_section"] ~= nil) then io.write("id:"..tostring(a["data_section"]:id()).."\n") io.write("payloadlength:"..tostring(a["data_section"]:payloadlength()).."\n") - io.write("namelength:"..tostring(a["data_section"]:namelength()).."\n") - io.write("name:"..tostring(a["data_section"]:name()).."\n") io.write("count:"..tostring(a["data_section"]:count()).."\n") io.write("entries:"..tostring(a["data_section"]:entries()).."\n") if type(a["data_section"]:entries()) == "table" then @@ -314,26 +292,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."type_section:payloadlength:pass\n")) end - pre = a["type_section"]:namelength() - a["type_section"]:set_namelength(10) - post = a["type_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."type_section:namelength:failure\n")) - success = false - else - io.write(colors("%{green}".."type_section:namelength:pass\n")) - end - - pre = a["type_section"]:name() - a["type_section"]:set_name("type_section") - post = a["type_section"]:name() - if pre == post then - io.write(colors("%{red}".."type_section:name:failure\n")) - success = false - else - io.write(colors("%{green}".."type_section:name:pass\n")) - end - pre = a["type_section"]:count() a["type_section"]:set_count(13) post = a["type_section"]:count() @@ -402,24 +360,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."import_section:payloadlength:pass\n")) end - pre = a["import_section"]:namelength() - a["import_section"]:set_namelength(17) - post = a["import_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."import_section:namelength:failure\n")) - else - io.write(colors("%{green}".."import_section:namelength:pass\n")) - end - - pre = a["import_section"]:name() - a["import_section"]:set_name("import_section") - post = a["import_section"]:name() - if pre == post then - io.write(colors("%{red}".."import_section:name:failure\n")) - else - io.write(colors("%{green}".."import_section:name:pass\n")) - end - pre = a["import_section"]:count() a["import_section"]:set_count(13) post = a["import_section"]:count() @@ -456,24 +396,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."function_section:payloadlength:pass\n")) end - pre = a["function_section"]:namelength() - a["function_section"]:set_namelength(17) - post = a["function_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."function_section:namelength:failure\n")) - else - io.write(colors("%{green}".."function_section:namelength:pass\n")) - end - - pre = a["function_section"]:name() - a["function_section"]:set_name("function_section") - post = a["function_section"]:name() - if pre == post then - io.write(colors("%{red}".."function_section:name:failure\n")) - else - io.write(colors("%{green}".."function_section:name:pass\n")) - end - pre = a["function_section"]:count() a["function_section"]:set_count(13) post = a["function_section"]:count() @@ -523,24 +445,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."table_section:payloadlength:pass\n")) end - pre = a["table_section"]:namelength() - a["table_section"]:set_namelength(17) - post = a["table_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."table_section:namelength:failure\n")) - else - io.write(colors("%{green}".."table_section:namelength:pass\n")) - end - - pre = a["table_section"]:name() - a["table_section"]:set_name("table_section") - post = a["table_section"]:name() - if pre == post then - io.write(colors("%{red}".."table_section:name:failure\n")) - else - io.write(colors("%{green}".."table_section:name:pass\n")) - end - pre = a["table_section"]:count() a["table_section"]:set_count(13) post = a["table_section"]:count() @@ -605,24 +509,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."memory_section:payloadlength:pass\n")) end - pre = a["memory_section"]:namelength() - a["memory_section"]:set_namelength(17) - post = a["memory_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."memory_section:namelength:failure\n")) - else - io.write(colors("%{green}".."memory_section:namelength:pass\n")) - end - - pre = a["memory_section"]:name() - a["memory_section"]:set_name("memory_section") - post = a["memory_section"]:name() - if pre == post then - io.write(colors("%{red}".."memory_section:name:failure\n")) - else - io.write(colors("%{green}".."memory_section:name:pass\n")) - end - --for wasm v1.0. memory section count is 1 so this part doesnt make any sense --[[ pre = a["memory_section"]:count() @@ -675,24 +561,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."global_section:payloadlength:pass\n")) end - pre = a["global_section"]:namelength() - a["global_section"]:set_namelength(17) - post = a["global_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."global_section:namelength:failure\n")) - else - io.write(colors("%{green}".."global_section:namelength:pass\n")) - end - - pre = a["global_section"]:name() - a["global_section"]:set_name("global_section") - post = a["global_section"]:name() - if pre == post then - io.write(colors("%{red}".."global_section:name:failure\n")) - else - io.write(colors("%{green}".."global_section:name:pass\n")) - end - pre = a["global_section"]:count() a["global_section"]:set_count(13) post = a["global_section"]:count() @@ -744,24 +612,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."export_section:payloadlength:pass\n")) end - pre = a["export_section"]:namelength() - a["export_section"]:set_namelength(17) - post = a["export_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."export_section:namelength:failure\n")) - else - io.write(colors("%{green}".."export_section:namelength:pass\n")) - end - - pre = a["export_section"]:name() - a["export_section"]:set_name("export_section") - post = a["export_section"]:name() - if pre == post then - io.write(colors("%{red}".."export_section:name:failure\n")) - else - io.write(colors("%{green}".."export_section:name:pass\n")) - end - pre = a["export_section"]:count() a["export_section"]:set_count(13) post = a["export_section"]:count() @@ -821,24 +671,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."start_section:payloadlength:pass\n")) end - pre = a["start_section"]:namelength() - a["start_section"]:set_namelength(17) - post = a["start_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."start_section:namelength:failure\n")) - else - io.write(colors("%{green}".."start_section:namelength:pass\n")) - end - - pre = a["start_section"]:name() - a["start_section"]:set_name("start_section") - post = a["start_section"]:name() - if pre == post then - io.write(colors("%{red}".."start_section:name:failure\n")) - else - io.write(colors("%{green}".."start_section:name:pass\n")) - end - pre = a["start_section"]:index() a["start_section"]:set_index(13) post = a["start_section"]:index() @@ -873,24 +705,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."element_section:payloadlength:pass\n")) end - pre = a["element_section"]:namelength() - a["element_section"]:set_namelength(17) - post = a["element_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."element_section:namelength:failure\n")) - else - io.write(colors("%{green}".."element_section:namelength:pass\n")) - end - - pre = a["element_section"]:name() - a["element_section"]:set_name("element_section") - post = a["element_section"]:name() - if pre == post then - io.write(colors("%{red}".."element_section:name:failure\n")) - else - io.write(colors("%{green}".."element_section:name:pass\n")) - end - pre = a["element_section"]:count() a["element_section"]:set_count(13) post = a["element_section"]:count() @@ -973,24 +787,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."code_section:payloadlength:pass\n")) end - pre = a["code_section"]:namelength() - a["code_section"]:set_namelength(17) - post = a["code_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."code_section:namelength:failure\n")) - else - io.write(colors("%{green}".."code_section:namelength:pass\n")) - end - - pre = a["code_section"]:name() - a["code_section"]:set_name("code_section") - post = a["code_section"]:name() - if pre == post then - io.write(colors("%{red}".."code_section:name:failure\n")) - else - io.write(colors("%{green}".."code_section:name:pass\n")) - end - pre = a["code_section"]:count() a["code_section"]:set_count(13) post = a["code_section"]:count() @@ -1062,24 +858,6 @@ function libwasm.demo_setters(wasm_path) io.write(colors("%{green}".."data_section:payloadlength:pass\n")) end - pre = a["data_section"]:namelength() - a["data_section"]:set_namelength(17) - post = a["data_section"]:namelength() - if pre == post then - io.write(colors("%{red}".."data_section:namelength:failure\n")) - else - io.write(colors("%{green}".."data_section:namelength:pass\n")) - end - - pre = a["data_section"]:name() - a["data_section"]:set_name("data_section") - post = a["data_section"]:name() - if pre == post then - io.write(colors("%{red}".."data_section:name:failure\n")) - else - io.write(colors("%{green}".."data_section:name:pass\n")) - end - pre = a["data_section"]:count() a["data_section"]:set_count(13) post = a["data_section"]:count() @@ -1131,8 +909,8 @@ function libwasm.demo_setters(wasm_path) end --libwasm.dev("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") ---libwasm.demo_getters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") -libwasm.demo_getters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/aggregate.wasm") +--libwasm.demo_getters("/home/bloodstalker/extra/faultreiber/test/read.wasm") +libwasm.demo_getters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/test/read.wasm") --libwasm.demo_setters("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") --libwasm.dump_all("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm") -- cgit v1.2.3