Exemplo n.º 1
0
def save_svg(bv, function):
    address = hex(function.start).replace('L', '')
    path = os.path.dirname(bv.file.filename)
    origname = os.path.basename(bv.file.filename)
    filename = os.path.join(
        path,
        'binaryninja-{filename}-{function}.html'.format(filename=origname,
                                                        function=address))
    outputfile = get_save_filename_input('File name for export_svg',
                                         'HTML files (*.html)', filename)
    if sys.platform == "win32":
        outputfile = outputfile.replace('/', '\\')
    if outputfile is None:
        return
    content = render_svg(function, origname)
    output = open(outputfile, 'w')
    output.write(content)
    output.close()
    result = show_message_box("Open SVG",
                              "Would you like to view the exported SVG?",
                              buttons=MessageBoxButtonSet.YesNoButtonSet,
                              icon=MessageBoxIcon.QuestionIcon)
    if result == MessageBoxButtonResult.YesButton:
        url = 'file:{}'.format(pathname2url(bytes(outputfile)))
        webbrowser.open(url)
Exemplo n.º 2
0
def run_harness_generation(view, func):
    """ Experimental automatic fuzzer harness generation support """

    template_file = os.path.join(binaryninja.user_plugin_path(), "fuzzable")
    if view.view_type == "ELF":
        template_file += "/templates/linux.cpp"
    else:
        interaction.show_message_box(
            "Error",
            "Experimental harness generation is only supported for ELFs at the moment",
        )
        return

    # parse out template based on executable format, and start replacing
    with open(template_file, "r") as fd:
        template = fd.read()

    log.log_info("Replacing elements in template")
    template = template.replace("{NAME}", func.name)
    template = template.replace("{RET_TYPE}", str(func.return_type))

    harness = interaction.get_save_filename_input("Filename to write to?",
                                                  "cpp")
    harness = csv_file.decode("utf-8") + ".cpp"

    log.log_info("Writing new template to workspace")
    with open(harness, "w+") as fd:
        fd.write(template)

    interaction.show_message_box("Success",
                                 f"Done, wrote fuzzer harness to {harness}")
Exemplo n.º 3
0
def save_svg(bv, function):
	address = hex(function.start).replace('L', '')
	path = os.path.dirname(bv.file.filename)
	origname = os.path.basename(bv.file.filename)
	filename = os.path.join(path, 'binaryninja-{filename}-{function}.html'.format(filename=origname, function=address))
	outputfile = get_save_filename_input('File name for export_svg', 'HTML files (*.html)', filename)
	if outputfile is None:
		return
	content = render_svg(function)
	output = open(outputfile, 'w')
	output.write(content)
	output.close()
	result = show_message_box("Open SVG", "Would you like to view the exported SVG?",
							buttons = MessageBoxButtonSet.YesNoButtonSet, icon = MessageBoxIcon.QuestionIcon)
	if result == MessageBoxButtonResult.YesButton:
		url = 'file:{}'.format(pathname2url(outputfile))
		webbrowser.open(url)
 def save_data(self, bv):
     if(self.start == self.end or self.start == None or self.end == None):
         show_message_box("Afl-Unicorn", "Start and End addresses not set!",
                                         MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.ErrorIcon)
         return
     try:
         data = json.dumps({'start': self.start, 'end': self.end,
                            'avoid_addresses': self.avoid_addresses}, ensure_ascii=False)
         prompt_file = get_save_filename_input('filename', 'json')
         if(not prompt_file):
             return
         output_file = open(prompt_file.decode("utf-8")+'.json', 'w')
         output_file.write(data)
         output_file.close()
         show_message_box("Afl-Unicorn", "Data saved you can start harness test",
                          MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.InformationIcon)
     except:
         show_message_box("Afl-Unicorn", "Error please open git issue !",
                          MessageBoxButtonSet.OKButtonSet, MessageBoxIcon.ErrorIcon)
Exemplo n.º 5
0
def run_export_report(view):
    """ Generate a report from a previous analysis, and export as CSV """
    log.log_info("Attempting to export results to CSV")
    try:
        csv_output = view.query_metadata("csv")
    except KeyError:
        interaction.show_message_box(
            "Error", "Cannot export without running an analysis first.")
        return

    # write last analysis to filepath
    csv_file = interaction.get_save_filename_input(
        "Filename to export as CSV?", "csv")
    csv_file = csv_file.decode("utf-8") + ".csv"

    log.log_info(f"Writing to filepath {csv_file}")
    with open(csv_file, "w+") as fd:
        fd.write(csv_output)

    interaction.show_message_box("Success", f"Done, exported to {csv_file}")