From fa2930a8ecaaa31ab2cee8ccca06453a9512d273 Mon Sep 17 00:00:00 2001 From: danger Date: Fri, 18 Oct 2024 17:42:24 +0800 Subject: [PATCH] Upload files to "/" --- interface_extract.py | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/interface_extract.py b/interface_extract.py index 658f19a..c806713 100644 --- a/interface_extract.py +++ b/interface_extract.py @@ -70,21 +70,23 @@ def export_local_types_for_struct(): except Exception as msg: mylog("export_local_types_for_struct",msg) -def export_local_types(save_file): +def export_local_types(save_file,flags): struct_list=export_local_types_for_struct()#返回字典列表 if(struct_list is None):return + if flags==0: # # 将结构体信息转换为 JSON 格式 - json_output = json.dumps(struct_list, indent=4) - #print(json_output) - save_file=save_file+"_Estruct.json" - with open(save_file,"w") as f: - f.write(json_output) + json_output = json.dumps(struct_list, indent=4) + #print(json_output) + filepath=save_file+"_Estruct.json" + with open(filepath,"w") as f: + f.write(json_output) + else : # 字符串存储 - # save_file=save_file+"_Estruct.txt" - # with open(save_file,"w") as f: - # for i in struct_list: - # f.write(f"[{i['name']}:struct_size {i['size']} -> {i['info']}]\n") + filepath=save_file+"_Estruct.txt" + with open(filepath,"w") as f: + for i in struct_list: + f.write(f"[{i['name']}:struct_size {i['size']} -> {i['info']}]\n") #函数黑名单 BLACK_LIST={ @@ -97,17 +99,21 @@ STRUCT_BACKLIST={ "Elf64_Sym","Elf64_Rela","Elf64_Dyn","Elf64_Verneed","Elf64_Vernaux" } def main(): - save_dir="result" - extractfile="extract.c" + save_dir="../input" + extractfile="extractelf" filepath="tmp.txt" - if (os.path.exists(filepath) and os.path.isfile(filepath) ): - with open(filepath,"r") as f: - extractfile=f.read() + try: + if(not os.path.exists(save_dir)):os.makedirs(save_dir) + if (os.path.exists(filepath) and os.path.isfile(filepath) ): + with open(filepath,"r") as f: + extractfile=f.read() extractfile=extractfile.split("/")[-1] - extractfile=os.path.join(save_dir,extractfile) - - export_func(extractfile) - export_local_types(extractfile) + extractfile=os.path.join(save_dir,extractfile) + + export_func(extractfile) + export_local_types(extractfile,0) + except Exception as msg: + mylog("main",msg) if __name__ == "__main__": try :