# save search # # Save search results to a specified file targets = [FunctionGraphType.NormalFunctionGraph, FunctionGraphType.LowLevelILFunctionGraph, FunctionGraphType.MediumLevelILFunctionGraph, FunctionGraphType.HighLevelILFunctionGraph, FunctionGraphType.HighLevelLanguageRepresentationFunctionGraph] search_text = TextLineField("Search text") search_target = ChoiceField("Search target?", ["Assembly", "LLIL", "MLIL", "HLIL", "Pseudo C"]) search_addresses = ChoiceField("Include addresses in output?", ["No", "Yes"]) output_file = SaveFileNameField("Output filename: ", default_name=bv.file.filename + ".txt") choices = get_form_input(["Saved Search Plugin", search_text, search_target, output_file, search_addresses], "Saved Search") if choices and search_text.result and search_target.result and output_file.result: with open(output_file.result, 'wb') as f: target = targets[search_target.result] for result in bv.find_all_text(bv.start, bv.end, search_text.result, graph_type=target): if search_addresses.result and search_addresses.result == 1: addr = bytes(hex(result[0]) + "\t", 'utf8') else: addr = b"" f.write(addr + bytes(str(result[2]), 'utf8') + b"\n") log_info(f"Search results saved to {output_file.result}") else: log_warn("Search not saved, dialog cancelled or missing selection.")