def test_harness(self, bv): form_menu = False dumped_memory = DirectoryNameField( 'Select folder with dumped memory') input_file = OpenFileNameField('Select input file') json_file = OpenFileNameField('Select json data file') harness_file = OpenFileNameField('Select harness test file') if(self.dumped_memory != None or self.json_file != None or self.input_file != None or self.harness_file != None): form_menu = self._display_menu([self.dumped_memory.result, self.input_file.result, self.harness_file.result, self.json_file.result], "Afl-unicorn Harness Test Menu") if form_menu == True: self._start_unicorn_emulation( self.harness_file, self.json_file, self.dumped_memory, self.input_file) else: result = show_message_box("Afl-Unicorn", "Do you want to clear test data ?", MessageBoxButtonSet.YesNoButtonSet, MessageBoxIcon.WarningIcon) if(result == 1): self._clear_harness_data() else: form_menu = self._display_menu( [dumped_memory, input_file, harness_file, json_file], "Afl-unicorn Harness Test Menu") if(dumped_memory.result == None or input_file.result == None or harness_file.result == None or json_file == None): return if(len(dumped_memory.result) <= 0 or len(input_file.result) <= 0 or len(harness_file.result) <= 0 or len(json_file.result) <= 0): show_message_box("Afl-Unicorn", "All fields are required !", MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.ErrorIcon) return binja.log_info("Selected dumped memory folder: {0}".format( dumped_memory.result)) binja.log_info("Selected input file: {0}".format( input_file.result)) binja.log_info("Selected json data file: {0}".format( json_file.result)) binja.log_info("Selected harness test file: {0}".format( harness_file.result)) self.dumped_memory = dumped_memory self.input_file = input_file self.json_file = json_file self.harness_file = harness_file if form_menu == True: self._start_unicorn_emulation( self.harness_file, self.json_file, self.dumped_memory, self.input_file)
def __init__(self, interactive=False): if interactive: csv_file = OpenFileNameField("Import csv file") get_form_input([csv_file], "Polypyus Import Options") self.verbose = True if csv_file.result == "": self.csv_file = None else: self.csv_file = csv_file.result self.output_name = None return # headless descr = "Export functions from a Polypyus csv into an existing Binary Ninja database." parser = ArgumentParser(description=descr) parser.add_argument("csv", type=FileType("w"), help="Path to Polypyus csv.") parser.add_argument("bndb", type=FileType("r"), help="Path to Binary Ninja database.") args = parser.parse_args() self.csv_file = args.csv self.input_file = args.csv self.output_name = args.bndb
def generate_all_platforms(bv): platforms = [i.name for i in list(Platform)] header_file = OpenFileNameField("Select Header File") lib_name = TextLineField("Type Library Name") file_name = TextLineField("File Name") get_form_input([header_file, lib_name, file_name], "Generate Type Library") try: for p in list(Platform): typelib = generate_typelib(p, header_file.result, lib_name.result) path = typelib_path / p.name / "{}.bntl".format(file_name.result) typelib.write_to_file(str(path.resolve())) except SyntaxError as e: show_message_box("Error", e.msg)
def generate_single_platform(bv): arch_choices = [i.name for i in list(Platform)] header_file = OpenFileNameField("Select Header File") arch = ChoiceField("Select Architecture", arch_choices) name = TextLineField("Type Library Name") save_file = SaveFileNameField("Save Type Library", ext="bntl") get_form_input([header_file, arch, name, save_file], "Generate Type Library") arch = arch_choices[arch.result] platform = Platform[arch] try: typelib = generate_typelib(platform, header_file.result, name.result) typelib.write_to_file(save_file.result) except SyntaxError as e: show_message_box("Error", e.msg.decode())
def __init__(self, interactive=False): if interactive: import_strings_choice = ChoiceField("Import Strings", ["Yes", "No"]) import_string_name_choice = ChoiceField("Import String Names", ["Yes", "No"]) import_function_choice = ChoiceField("Import Functions", ["Yes", "No"]) import_comment_choice = ChoiceField("Import Comments", ["Yes", "No"]) json_file = OpenFileNameField("Import json file") get_form_input([json_file, import_strings_choice, import_string_name_choice, import_function_choice, import_comment_choice], "IDA Import Options") self.import_strings = import_strings_choice.result == 0 self.import_strings_names = import_string_name_choice.result == 0 self.import_functions = import_function_choice.result == 0 self.import_comments = import_comment_choice.result == 0 self.verbose = True if json_file.result == '': self.json_file = None else: self.json_file = json_file.result self.output_name = None else: usage = "usage: %prog [options] <ida_export.json> <file|bndb>" parser = OptionParser(usage=usage) parser.add_option("-q", "--quiet", dest="verbose", action="store_false", default=True, help="Don't display automatic actions") parser.add_option("-s", "--no-strings", dest="import_strings", action="store_false", default=True, help="Don't import string data") parser.add_option("-n", "--no-string-names", dest="import_strings_names", action="store_false", default=True, help="Don't import string names") parser.add_option("-o", "--output-name", dest="output_name", action="store", default=None, help="Specify output name of bndb. Defaults to <file_name>.bndb") parser.add_option("-f", "--no-functions", dest="import_functions", action="store_false", default=True, help="Don't import function starts") parser.add_option("-c", "--no-comments", dest="import_comments", action="store_false", default=True, help="Don't import comments") (options, args) = parser.parse_args() self.import_strings = options.import_strings self.import_strings_names = options.import_strings_names self.import_functions = options.import_functions self.import_comments = options.import_comments self.verbose = options.verbose self.json_file = args[0] self.input_file = args[0] self.output_name = options.output_name if self.output_name is None: self.output_name = self.input_file + ".bndb" self.usage = parser.get_usage()
def start_afl_fuzzing(self, bv): global process if process != None: show_message_box("Afl-Unicorn", "Afl-unicorn fuzzing process is running already, stop it first", MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.WarningIcon) return form_menu = False binja.log_info("Starting afl-unicorn fuzzing") afl_binary = OpenFileNameField('Select afl-fuzz') dumped_memory = DirectoryNameField('Select folder with dumped memory') inputs = DirectoryNameField('Select inputs folder') outputs = DirectoryNameField('Select outputs folder') harness_file = OpenFileNameField('Select harness test file') json_file = OpenFileNameField('Select json data file') afl_runner = AflUnicornRunner() if(self.afl_dumped_memory != None or self.afl_json_file != None or self.afl_inputs != None or self.afl_harness_file != None or self.afl_outputs != None or self.afl_binary != None): form_menu = self._display_menu([self.afl_binary.result, self.afl_dumped_memory.result, self.afl_json_file.result, self.afl_inputs.result, self.afl_outputs.result, self.afl_harness_file.result], "Afl-unicorn Fuzzing Menu") if form_menu == True: afl_runner.fuzz(afl_runner, self.afl_binary, self.afl_dumped_memory, self.afl_json_file, self.afl_inputs, self.afl_outputs, self.afl_harness_file) else: result = show_message_box("Afl-Unicorn", "Do you want to clear test data ?", MessageBoxButtonSet.YesNoButtonSet, MessageBoxIcon.WarningIcon) if(result == 1): self._clear_fuzz_data() else: form_menu = self._display_menu( [afl_binary, dumped_memory, json_file, inputs, outputs, harness_file], "Afl-unicorn Fuzzing Menu") if(inputs.result == None or afl_binary.result == None or dumped_memory.result == None or outputs.result == None or harness_file.result == None or json_file.result == None): return if(len(afl_binary.result) <= 0 or len(dumped_memory.result) <= 0 or len(inputs.result) <= 0 or len(outputs.result) <= 0 or len(harness_file.result) <= 0 or len(json_file.result) <= 0): show_message_box("Afl-Unicorn", "All fields are required !", MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.ErrorIcon) return binja.log_info( "Selected afl-fuzz binary: {0}".format(afl_binary.result)) binja.log_info("Selected dumped memory folder: {0}".format( dumped_memory.result)) binja.log_info("Selected inputs folder: {0}".format(inputs.result)) binja.log_info("Selected outputs folder: {0}".format(outputs.result)) binja.log_info("Selected json data file: {0}".format(json_file.result)) binja.log_info( "Selected harness test file: {0}".format(harness_file.result)) self.afl_binary = afl_binary self.afl_dumped_memory = dumped_memory self.afl_inputs = inputs self.afl_outputs = outputs self.afl_harness_file = harness_file self.afl_json_file = json_file if form_menu == True: afl_runner.fuzz(afl_runner, self.afl_binary, self.afl_dumped_memory, self.afl_json_file, self.afl_inputs, self.afl_outputs, self.afl_harness_file)