def gen_mod_graph(module_list, suffix): c = 0 g = set() while (c < len(module_list)): m = module_list[c] f = m.start while (f <= m.end): for xref in basicutils.FuncXrefsFrom(f): target = locate_module(module_list, xref) if (target): g.add((m.name, target.name)) f = basicutils.NextFunction(f) c += 1 root_name = basicutils.GetRootName() file = open(root_name + "_" + suffix + "_mod_graph.gv", "wb") file.write("digraph g {\n") for (node1, node2) in g: line = "%s -> %s\n" % (escape_for_graphviz(node1), escape_for_graphviz(node2)) file.write(line) file.write("}\n") file.close()
def print_results(function_list, module_list1, module_list2): c = 0 root_name = basicutils.GetRootName() file = open(root_name + "_cc_results.csv", "w") #write header file.write( "Function,Function #,LFA Score 1,LFA Score 2,LFA Total,LFA Edge,MC Edge,Function Name,Suggested Mod Name (LFA), Suggested Mod Name(MC),Source Str Ref\n" ) while (c < len(function_list)): f = function_list[c] fname = basicutils.GetFunctionName(f.loc) m1 = locate_module(module_list1, f.loc) m2 = locate_module(module_list2, f.loc) mname1 = m1.name mname2 = m2.name #hacky - should actually find the extent of the function #for now we'll just skip the last one if (c < (len(function_list) - 1)): nf = basicutils.NextFunction(f.loc) func_str_ref, score = modnaming.source_file_strings(f.loc, nf - 1) else: func_str_ref = "" line = "0x%08x, %d , %f, %f, %f, %d, %d, %s, %s, %s, %s\n" % ( f.loc, c + 1, f.score1, f.score2, f.total_score, f.edge[0], f.edge[1], fname, mname1, mname2, func_str_ref) file.write(line) c += 1
def gen_map_file(module_list, suffix): c = 0 root_name = basicutils.GetRootName() file = open(root_name + "_" + suffix + "_map.map", "wb") while (c < len(module_list)): m = module_list[c] mlen = basicutils.NextFunction(m.end) - m.start mlen_str = "0x%x" % mlen file.write("%s0x%016x%s %s\n" % (" .text".ljust(16), m.start, mlen_str.rjust(11), m.name)) c += 1 file.close()
def print_results(function_list, module_list1, module_list2): c = 0 root_name = basicutils.GetRootName() file = open(root_name + "_cc_results.csv", "wb") #write header file.write( "Function,Function #,LFA Score 1,LFA Score 2,LFA Total,LFA Edge,MC Edge,Function Name,Suggested Mod Name (LFA), Suggested Mod Name(MC)\n" ) while (c < len(function_list)): f = function_list[c] fname = basicutils.GetFunctionName(f.loc) m1 = locate_module(module_list1, f.loc) m2 = locate_module(module_list2, f.loc) mname1 = m1.name mname2 = m2.name line = "0x%08x, %d , %f, %f, %f, %d, %d, %s, %s, %s\n" % ( f.loc, c + 1, f.score1, f.score2, f.total_score, f.edge[0], f.edge[1], fname, mname1, mname2) file.write(line) c += 1
def gen_rename_script(module_list, suffix): c = 0 root_name = basicutils.GetRootName() file = open(root_name + "_" + suffix + "_labels.py", "wb") #if (IDA_VERSION < 7): # file.write("import basicutils_6x as basicutils\n"); #else: file.write("import basicutils_7x as basicutils\n") file.write("\ndef go():\n") while (c < len(module_list)): m = module_list[c] file.write("\tbasicutils.RenameRangeWithAddr(0x%x,0x%x,%r)\n" % (m.start, m.end, m.name)) c += 1 file.write("\n") file.write("if __name__ == \"__main__\":\n") file.write("\treload(basicutils)\n") file.write("\tgo()\n") file.close()