From 413d2f9ff5f72369097a92fc0697f71070913d1d Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Tue, 11 Sep 2018 02:18:16 +0430 Subject: update --- main.py | 56 ++++++++++++------- run.sh | 2 +- test/autowasm.c | 171 ++++++++++++++++++++++++++++---------------------------- text.py | 13 ++--- 4 files changed, 130 insertions(+), 112 deletions(-) diff --git a/main.py b/main.py index 524a1ac..1802529 100755 --- a/main.py +++ b/main.py @@ -329,10 +329,10 @@ class CodeGen(object): read_source.write(text.c_void_manager_proto.replace("XXX", "dummy->" + cond.attrib["name"])); self.malloc_list.append(C_Obj(ref_node.attrib["name"], [elem.tag, child.tag])) if child_count == 1: - for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"]) + ";\n" + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"]).replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n" read_source.write(for_read) elif child_count > 1: - for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]") + ";\n" + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]").replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n" read_source.write(for_read) else: # child_count == -1 count_name_str = cond.attrib["count"][6:] @@ -340,7 +340,7 @@ class CodeGen(object): read_source.write("dummy->" + cond.attrib["name"] + " = " + "malloc(sizeof(void*)*" + "dummy->" + get_node_name(count_name_str, child) + ");\n") read_source.write(text.c_void_manager_proto.replace("XXX", "dummy->" + cond.attri["name"])); self.malloc_list.append(C_Obj("sizeof(void*)*dummy->"+get_node_name(count_name_str, child), [elem.attrib["name"], child.attrib["name"], cond.arrtib["name"]])) - for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]") + ";\n" + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + cond.attrib["name"] + "[i]").replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n" read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, child))) read_source.write("}\n") else: @@ -385,17 +385,17 @@ class CodeGen(object): if ref_node: ref_node_name = pointer_remover(ref_node.attrib["name"]) if child_count == 1: - for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"]) + ";\n" + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"]).replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n" read_source.write("dummy->" + child.attrib["name"] + "=" + for_read) elif child_count > 1: - for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]") + ";\n" + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]").replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n" read_source.write("dummy->" + child.attrib["name"] + "=" + for_read) else: # child_count == -1 count_name_str = child.attrib["count"][6:] read_source.write("if (" + "dummy->" + get_node_name(count_name_str, elem) + ")\n") read_source.write("dummy->" + child.attrib["name"] + " = " + "malloc(sizeof(void*)*" + "dummy->" + get_node_name(count_name_str, elem) + ");\n") read_source.write(text.c_void_manager_proto.replace("XXX", "dummy->" + child.attrib["name"])); - for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]") + ";\n" + for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]").replace("ZZZ", self.argparser.args.name + "_lib_ret->void_train") + ";\n" read_source.write(text.simple_loop.replace("YYY", "dummy->" + child.attrib["name"] + "[i]=" + for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, elem))) else: for_read = str() @@ -464,29 +464,40 @@ class CodeGen(object): void_source = open(self.aggregate_source, "w") void_source_h = open(self.aggregate_source_h, "w") void_source.write("\n// automatically generated by faultreiber\n") + void_source_h.write("\n// automatically generated by faultreiber\n") void_source.write("// " + self.dnt + "\n") + void_source_h.write("// " + self.dnt + "\n") void_source.write('#include "./structs.h"\n') void_source.write('#include "./read.h"\n') void_source.write("#include \n") - void_source.write("void** void_train;\n") - void_source.write("uint64_t current_void_size = 0U;\n") - void_source.write("uint64_t current_void_count = 0U;\n") + #void_source.write("void** void_train;\n") + #void_source.write("uint64_t current_void_size = 0U;\n") + #void_source.write("uint64_t current_void_count = 0U;\n") void_source_h.write('#ifndef FT_AGGREGATE_H\n#define FT_AGGREGATE_H\n') void_source_h.write('#ifdef __cplusplus\nextern "C" {\n#endif\n') void_source_h.write('#include "./structs.h"\n') # generating the extern declarations and definitions + void_source_h.write("typedef struct {\n") for elem in self.read_elems: count = get_elem_count(elem) size = get_elem_size(elem) if count != 1: - void_source_h.write("extern " + elem.attrib["name"] + "** " + elem.attrib["name"] + "_container;\n") - void_source.write(elem.attrib["name"] + "** " + elem.attrib["name"] + "_container;\n") + void_source_h.write(elem.attrib["name"] + "** " + elem.attrib["name"] + "_container;\n") + #void_source.write(elem.attrib["name"] + "** " + elem.attrib["name"] + "_container;\n") else: - void_source_h.write("extern " + elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n") - void_source.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n") + void_source_h.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n") + #void_source.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n") + void_source_h.write("}" + self.argparser.args.name + "_obj_t;\n") + #void_source_h.write(self.argparser.args.name + "_obj_t* obj;\n") + void_source_h.write("typedef struct {\n") + void_source_h.write(self.argparser.args.name + "_obj_t* obj;\n") + void_source_h.write("void** void_train;\n") + void_source_h.write("uint64_t* current_void_size;\n") + void_source_h.write("uint64_t* current_void_count;\n") + void_source_h.write("}" + self.argparser.args.name + "_lib_ret_t;\n") # end - void_source.write("void malloc_all(void) {\n") - void_source_h.write("void malloc_all(void);\n") + #void_source.write("void malloc_all(void) {\n") + #void_source_h.write("void malloc_all(void);\n") count_int = int() count_void = int() read_count = len(self.read_elems) @@ -524,7 +535,11 @@ class CodeGen(object): count_int = 0 count_void = 0 void_source.write("}\n") - void_source.write("void read_aggr_"+self.argparser.args.name+"(int _fd) {\n") + void_source.write(self.argparser.args.name + "_lib_ret_t* read_aggr_"+self.argparser.args.name+"(int _fd) {\n") + void_source.write(self.argparser.args.name + "_lib_ret_t* lib_ret = malloc(sizeof("+self.argparser.args.name+"_lib_ret_t"+"));\n") + void_source.write("lib_ret->obj = malloc(sizeof("+self.argparser.args.name+"_obj_t"+"));\n") + void_source.write("lib_ret->current_void_size = malloc(sizeof(uint64_t*));\n") + void_source.write("lib_ret->current_void_count = malloc(sizeof(uint64_t*));\n") for elem in self.read_elems: if "isaggregate" in elem.attrib: for child in elem: @@ -538,7 +553,7 @@ class CodeGen(object): agg_source = open(self.aggregate_source, "a") agg_source_h = open(self.aggregate_source_h, "a") print(self.argparser.args.name) - agg_source_h.write("void read_aggr_"+self.argparser.args.name+"(int _fd);\n") + agg_source_h.write(self.argparser.args.name + "_lib_ret_t* read_aggr_"+self.argparser.args.name+"(int _fd);\n") agg_source.write("uint8_t eof = 0U;") for elem in self.read_elems: if "unorderedbegin" in elem.attrib: @@ -554,11 +569,12 @@ class CodeGen(object): agg_source.write(text.c_read_gen.replace("XXX", sign_name).replace("YYY", sign_type)) agg_source.write("lseek(_fd, -sizeof(" + sign_type + "), SEEK_CUR);\n") agg_source.write("if (" + sign_name + "==" + child.text + "){\n") - agg_source.write(elem.attrib["name"] + "_container = " + "ft_read_" + elem.attrib["name"] + "(_fd," + elem.attrib["name"] + "_container" + ");\n") + agg_source.write("lib_ret->obj->"+elem.attrib["name"] + "_container = " + "ft_read_" + elem.attrib["name"] + "(_fd, lib_ret->obj->" + elem.attrib["name"] + "_container" + "lib_ret->void_train);\n") if "unordered" in elem.attrib: agg_source.write("}\n") if "unorderedend" in elem.attrib: agg_source.write("}while(0);\n") + agg_source.write("return lib_ret;\n") agg_source.write("}\n") #FIXME-not handling double pointers @@ -571,6 +587,8 @@ class CodeGen(object): agg_source.write("free(void_train[i]);\n}\n") agg_source.write("free(void_train);\n") agg_source.write("}\n") + agg_source_h.write('#ifdef __cplusplus\n}\n#endif\n') + agg_source_h.write("#endif //end of header guard\n\n") def gen_return(self): agg_source = open(self.aggregate_source, "a") @@ -692,7 +710,7 @@ class CodeGen(object): self.gen_void_train() self.gen_aggregate_read() self.gen_release() - self.gen_return() + #self.gen_return() # write code here def premain(argparser): diff --git a/run.sh b/run.sh index 66e117f..a0f030e 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,5 @@ #!/bin/sh cd $(dirname $0) -#"./faultreiber.py" --targetname autowasm --outdir ./test/ --structs ./test/struct.json --datetime --structsinclude ./resources/structsinclude.h --xml ./resources/wasm.xml "./faultreiber.py" --targetname autowasm --outdir ./test/ --structs ./test/struct.json --xml ./resources/wasm.xml --name wasm +#"./faultreiber.py" --targetname autowasm --outdir ./test/ --structs ./test/struct.json --xml ./resources/wasm2.xml --name wasm "clang-format" -i ./test/read.c ./test/structs.c ./test/structs.h ./test/aggregate.c ./test/aggregate.h ./test/read.h diff --git a/test/autowasm.c b/test/autowasm.c index 02b034c..769cc1e 100644 --- a/test/autowasm.c +++ b/test/autowasm.c @@ -9,127 +9,128 @@ #include "./read.h" #include "./aggregate.h" + #pragma weak main int main (int argc, char** argv) { int wasm = open("./test.wasm", O_RDONLY); - read_aggr_wasm(wasm); - - printf("magic_number:%x\n", magic_number_container->magic_number); - printf("version:%x\n", version_container->version); - - printf("type section id:%d\n", W_Type_Section_container->id); - printf("type section payloadlength:%d\n", W_Type_Section_container->payloadlength); - printf("type_section entry count:%d\n", W_Type_Section_container->count); - for (int i=0; i < W_Type_Section_container->count; ++i) { - printf("param_count:%d\n",W_Type_Section_container->entries[i]->param_count); - for (int j = 0; j < W_Type_Section_container->entries[i]->param_count; ++j) - printf("param_types:%d\n",W_Type_Section_container->entries[i]->param_types[j]); - printf("return_count:%d\n", W_Type_Section_container->entries[i]->return_count); - for (int j = 0; j < W_Type_Section_container->entries[i]->return_count; ++j) - printf("param_types:%d\n",W_Type_Section_container->entries[i]->return_types[j]); + wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm); + + printf("magic_number:%x\n", lib_ret->obj->magic_number_container->magic_number); + printf("version:%x\n", lib_ret->obj->version_container->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); + printf("type_section entry count:%d\n", lib_ret->obj->W_Type_Section_container->count); + for (int i=0; i < lib_ret->obj->W_Type_Section_container->count; ++i) { + printf("param_count:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->param_count); + for (int j = 0; j < lib_ret->obj->W_Type_Section_container->entries[i]->param_count; ++j) + printf("param_types:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->param_types[j]); + printf("return_count:%d\n", lib_ret->obj->W_Type_Section_container->entries[i]->return_count); + for (int j = 0; j < lib_ret->obj->W_Type_Section_container->entries[i]->return_count; ++j) + printf("param_types:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->return_types[j]); } - printf("import_section_id:%d\n", W_Import_Section_container->id); - printf("import_section_payloadlength:%d\n", W_Import_Section_container->payloadlength); - printf("import_section_count:%d\n", W_Import_Section_container->count); - for(int i = 0; i < W_Import_Section_container->count; ++i) { - printf("module_length:%d\n", W_Import_Section_container->entries[i]->module_length); - printf("module_str:%s\n", W_Import_Section_container->entries[i]->module_str); - printf("field_length:%d\n", W_Import_Section_container->entries[i]->field_len); - printf("field_str:%s\n", W_Import_Section_container->entries[i]->field_str); - printf("kind:%d\n", W_Import_Section_container->entries[i]->kind); - if (W_Import_Section_container->entries[i]->kind == 0) - printf("type:%d\n", W_Import_Section_container->entries[i]->kind); + printf("import_section_id:%d\n", lib_ret->obj->W_Import_Section_container->id); + printf("import_section_payloadlength:%d\n", lib_ret->obj->W_Import_Section_container->payloadlength); + printf("import_section_count:%d\n", lib_ret->obj->W_Import_Section_container->count); + for(int i = 0; i < lib_ret->obj->W_Import_Section_container->count; ++i) { + printf("module_length:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->module_length); + printf("module_str:%s\n", lib_ret->obj->W_Import_Section_container->entries[i]->module_str); + printf("field_length:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->field_len); + printf("field_str:%s\n", lib_ret->obj->W_Import_Section_container->entries[i]->field_str); + printf("kind:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->kind); + if (lib_ret->obj->W_Import_Section_container->entries[i]->kind == 0) + printf("type:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->kind); printf("\n"); } - printf("function_section_id:%d\n", W_Function_Section_container->id); - printf("function_section_payloadlength:%d\n", W_Function_Section_container->payloadlength); - printf("function_section_count:%d\n", W_Function_Section_container->count); - for (int i = 0; i < W_Function_Section_container->count; ++i) - printf("type:%d\n", W_Function_Section_container->types[i]); - - printf("table_section_id:%d\n", W_Table_Section_container->id); - printf("table_section_payloadlength:%d\n", W_Table_Section_container->payloadlength); - printf("table_section_count:%d\n", W_Table_Section_container->count); - for (int i = 0; i < W_Table_Section_container->count; ++i) { - printf("element_type:%d\n", W_Table_Section_container->entries[i]->element_type); - printf("rl_flags:%d\n", W_Table_Section_container->entries[i]->resizable_limit->flags); - printf("rl_initial:%d\n", W_Table_Section_container->entries[i]->resizable_limit->initial); - printf("rl_maximum:%d\n", W_Table_Section_container->entries[i]->resizable_limit->maximum); + printf("function_section_id:%d\n", lib_ret->obj->W_Function_Section_container->id); + printf("function_section_payloadlength:%d\n", lib_ret->obj->W_Function_Section_container->payloadlength); + printf("function_section_count:%d\n", lib_ret->obj->W_Function_Section_container->count); + for (int i = 0; i < lib_ret->obj->W_Function_Section_container->count; ++i) + printf("type:%d\n", lib_ret->obj->W_Function_Section_container->types[i]); + + printf("table_section_id:%d\n", lib_ret->obj->W_Table_Section_container->id); + printf("table_section_payloadlength:%d\n", lib_ret->obj->W_Table_Section_container->payloadlength); + printf("table_section_count:%d\n", lib_ret->obj->W_Table_Section_container->count); + for (int i = 0; i < lib_ret->obj->W_Table_Section_container->count; ++i) { + printf("element_type:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->element_type); + printf("rl_flags:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->flags); + printf("rl_initial:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->initial); + printf("rl_maximum:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->maximum); } - printf("memory_section_id:%d\n", W_Memory_Section_container->id); - printf("memory_section_payload_length:%d\n", W_Memory_Section_container->payloadlength); - printf("rl_flags:%d\n", W_Memory_Section_container->entries->resizable_limit->flags); - printf("rl_initial:%d\n", W_Memory_Section_container->entries->resizable_limit->initial); - printf("rl_maximum:%d\n", W_Memory_Section_container->entries->resizable_limit->maximum); + printf("memory_section_id:%d\n", lib_ret->obj->W_Memory_Section_container->id); + printf("memory_section_payload_length:%d\n", lib_ret->obj->W_Memory_Section_container->payloadlength); + printf("rl_flags:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->flags); + printf("rl_initial:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->initial); + printf("rl_maximum:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->maximum); - if (W_Global_Section_container == NULL) printf("global section doesnt exist.\n"); + if (lib_ret->obj->W_Global_Section_container == NULL) printf("global section doesnt exist.\n"); - printf("export_section_id:%d\n", W_Export_Section_container->id); - printf("export_section_payloadlength:%d\n", W_Export_Section_container->payloadlength); - printf("entry count:%d\n", W_Export_Section_container->count); + printf("export_section_id:%d\n", lib_ret->obj->W_Export_Section_container->id); + printf("export_section_payloadlength:%d\n", lib_ret->obj->W_Export_Section_container->payloadlength); + printf("entry count:%d\n", lib_ret->obj->W_Export_Section_container->count); - for (int i = 0; i < W_Export_Section_container->count; ++i) { - printf("field_len:%d\n", W_Export_Section_container->entries[i]->field_len); - printf("field_str:%s\n", W_Export_Section_container->entries[i]->field_str); - printf("kind:%d\n", W_Export_Section_container->entries[i]->kind); - printf("index:%d\n", W_Export_Section_container->entries[i]->index); + for (int i = 0; i < lib_ret->obj->W_Export_Section_container->count; ++i) { + printf("field_len:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->field_len); + printf("field_str:%s\n", lib_ret->obj->W_Export_Section_container->entries[i]->field_str); + printf("kind:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->kind); + printf("index:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->index); } - if (W_Start_Section_container == NULL) printf("start section doesnt exist.\n"); + if (lib_ret->obj->W_Start_Section_container == NULL) printf("start section doesnt exist.\n"); - printf("element_seciton_id:%d\n", W_Element_Section_container->id); - printf("element_section_payloadlength:%d\n", W_Element_Section_container->payloadlength); - printf("entry count:%d\n", W_Element_Section_container->count); + printf("element_seciton_id:%d\n", lib_ret->obj->W_Element_Section_container->id); + printf("element_section_payloadlength:%d\n", lib_ret->obj->W_Element_Section_container->payloadlength); + printf("entry count:%d\n", lib_ret->obj->W_Element_Section_container->count); - for (int i = 0; i < W_Element_Section_container->count; ++i) { - printf("index:%d\n", W_Element_Section_container->entries[i]->index); + for (int i = 0; i < lib_ret->obj->W_Element_Section_container->count; ++i) { + printf("index:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->index); for (int j = 0; j < 3; ++j) { - printf("code:%d\n", W_Element_Section_container->entries[i]->init->code[j]); + printf("code:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->init->code[j]); } - printf("num_length:%d\n", W_Element_Section_container->entries[i]->num_length); - for (int j = 0; j < W_Element_Section_container->entries[i]->num_length; ++j) { - printf("elems:%d\n", W_Element_Section_container->entries[i]->elems[j]); + printf("num_length:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->num_length); + for (int j = 0; j < lib_ret->obj->W_Element_Section_container->entries[i]->num_length; ++j) { + printf("elems:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->elems[j]); } } - printf("code_section_id:%d\n", W_Code_Section_container->id); - printf("code_section_payloadlength:%d\n", W_Code_Section_container->payloadlength); - printf("count:%d\n", W_Code_Section_container->count); + printf("code_section_id:%d\n", lib_ret->obj->W_Code_Section_container->id); + printf("code_section_payloadlength:%d\n", lib_ret->obj->W_Code_Section_container->payloadlength); + printf("count:%d\n", lib_ret->obj->W_Code_Section_container->count); - for (int i = 0; i < W_Code_Section_container->count; ++i) { - printf("body_size:%d\n", W_Code_Section_container->bodies[i]->body_size); - printf("local_count:%d\n", W_Code_Section_container->bodies[i]->local_count); - if (W_Code_Section_container->bodies[i]->local_count > 0) { - for (int j =0; j < W_Code_Section_container->bodies[i]->local_count; ++j) { - for (int k = 0; k < W_Code_Section_container->bodies[i]->locals[j]->count; ++k) { + for (int i = 0; i < lib_ret->obj->W_Code_Section_container->count; ++i) { + printf("body_size:%d\n", lib_ret->obj->W_Code_Section_container->bodies[i]->body_size); + printf("local_count:%d\n", lib_ret->obj->W_Code_Section_container->bodies[i]->local_count); + if (lib_ret->obj->W_Code_Section_container->bodies[i]->local_count > 0) { + for (int j =0; j < lib_ret->obj->W_Code_Section_container->bodies[i]->local_count; ++j) { + for (int k = 0; k < lib_ret->obj->W_Code_Section_container->bodies[i]->locals[j]->count; ++k) { } } } printf("code:\n"); - for (int j = 0; j < W_Code_Section_container->bodies[i]->body_size; ++j) { - printf("%02x ", W_Code_Section_container->bodies[i]->code[j]); + for (int j = 0; j < lib_ret->obj->W_Code_Section_container->bodies[i]->body_size; ++j) { + printf("%02x ", lib_ret->obj->W_Code_Section_container->bodies[i]->code[j]); } printf("\n"); } - printf("data_section_id:%d\n", W_Data_Section_container->id); - printf("data_section_payloadlength:%d\n", W_Data_Section_container->payloadlength); - printf("data seg count:%d\n", W_Data_Section_container->count); + printf("data_section_id:%d\n", lib_ret->obj->W_Data_Section_container->id); + printf("data_section_payloadlength:%d\n", lib_ret->obj->W_Data_Section_container->payloadlength); + printf("data seg count:%d\n", lib_ret->obj->W_Data_Section_container->count); - for (int i = 0; i < W_Data_Section_container->count; ++i) { - printf("index:%d\n", W_Data_Section_container->entries[i]->index); - printf("size:%d\n", W_Data_Section_container->entries[i]->size); + for (int i = 0; i < lib_ret->obj->W_Data_Section_container->count; ++i) { + printf("index:%d\n", lib_ret->obj->W_Data_Section_container->entries[i]->index); + printf("size:%d\n", lib_ret->obj->W_Data_Section_container->entries[i]->size); printf("code:\n"); - for (int j = 0; j < W_Data_Section_container->entries[i]->size; ++j) { - printf("%c ", W_Data_Section_container->entries[i]->data[j]); + for (int j = 0; j < lib_ret->obj->W_Data_Section_container->entries[i]->size; ++j) { + printf("%c ", lib_ret->obj->W_Data_Section_container->entries[i]->data[j]); } printf("\n"); int j = 0; printf("offset:\n"); while(1) { - printf("%02x ", W_Data_Section_container->entries[i]->offset->code[j]); - if (W_Data_Section_container->entries[i]->offset->code[j] == 11) { + printf("%02x ", lib_ret->obj->W_Data_Section_container->entries[i]->offset->code[j]); + if (lib_ret->obj->W_Data_Section_container->entries[i]->offset->code[j] == 11) { break; } j++; diff --git a/text.py b/text.py index ae18de1..f64e478 100644 --- a/text.py +++ b/text.py @@ -15,11 +15,10 @@ class text(): #c_read_elem_sig = "void ft_read_YYY(int _fd, XXX* dummyZZZ) {\n" #c_read_elem_sig = "void ft_read_YYY(int _fd, XXX* dummy) {\n" #c_read_elem_sig_h = "void ft_read_YYY(int _fd, XXX* dummy);\n" - c_read_elem_sig = "void* ft_read_YYY(int _fd, XXX* dummy) {\n" - c_read_elem_sig_h = "void* ft_read_YYY(int _fd, XXX* dummy);\n" + c_read_elem_sig = "void* ft_read_YYY(int _fd, XXX* dummy, void** void_train) {\n" + c_read_elem_sig_h = "void* ft_read_YYY(int _fd, XXX* dummy, void** void_train);\n" c_read_elem_sig_1 = "ft_read_XXX(_fd)" - c_read_elem_sig_2 = "ft_read_XXX(_fd, YYY)" - #c_read_elem_sig_2 = "ft_read_XXX(_fd, &YYY)" + c_read_elem_sig_2 = "ft_read_XXX(_fd, YYY, ZZZ)" c_open_file = "int ft_read_file = open(_ft_file_path, RDONLY);\n" c_function_close = "}\n" c_function_dummy_dec = "XXX dummy;\n" @@ -84,7 +83,7 @@ int32_t read_until_delimiter(int _fd, uint8_t delimiter) { }""" c_void_manager = """ -void void_manager(void* ptr) { +void void_manager(void* ptr, void** void_train) { if (current_void_size == 0) { void_train = malloc(100*sizeof(void*)); current_void_size = 100; @@ -104,8 +103,8 @@ void void_manager(void* ptr) { c_read_leb_128_u_sig = "uint64_t read_leb_128_u(int _fd, int max_size);\n" c_read_until_delimiter_sig = "int32_t read_until_delimiter(int _fd, uint8_t delimiter);\n" c_read_until_delimiter_proto = "read_until_delimiter(_fd, XXX)" - c_void_manager_sig = "void void_manager(void* ptr);" - c_void_manager_proto = "void_manager(XXX);" + c_void_manager_sig = "void void_manager(void* ptr, void** void_train);" + c_void_manager_proto = "void_manager(XXX, void_train);" c_read_leb_macro_defs = """ #define READ_VAR_UINT_1(FD) read_leb128_u(FD, 1) -- cgit v1.2.3