Esempio n. 1
0
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)
Esempio n. 2
0
def save_svg(bv, function):
    sym = bv.get_symbol_at(function.start)
    if sym:
        offset = sym.name
    else:
        offset = "%x" % function.start
    path = Path(os.path.dirname(bv.file.filename))
    origname = os.path.basename(bv.file.filename)
    filename = path / f'binaryninja-{origname}-{offset}.html'

    functionChoice = TextLineField("Blank to accept default")
    # TODO: implement linear disassembly settings and output
    modeChoices = ["Graph"]
    modeChoiceField = ChoiceField("Mode", modeChoices)
    if Settings().get_bool('ui.debugMode'):
        formChoices = [
            "Assembly", "Lifted IL", "LLIL", "LLIL SSA", "Mapped Medium",
            "Mapped Medium SSA", "MLIL", "MLIL SSA", "HLIL", "HLIL SSA"
        ]
        formChoiceField = ChoiceField("Form", formChoices)
    else:
        formChoices = ["Assembly", "LLIL", "MLIL", "HLIL"]
        formChoiceField = ChoiceField("Form", formChoices)

    showOpcodes = ChoiceField("Show Opcodes", ["Yes", "No"])
    showAddresses = ChoiceField("Show Addresses", ["Yes", "No"])

    saveFileChoices = SaveFileNameField("Output file", 'HTML files (*.html)',
                                        str(filename))
    if not get_form_input([
            f'Current Function: {offset}', functionChoice, formChoiceField,
            modeChoiceField, showOpcodes, showAddresses, saveFileChoices
    ], "SVG Export") or saveFileChoices.result is None:
        return
    if saveFileChoices.result == '':
        outputfile = filename
    else:
        outputfile = saveFileChoices.result
    content = render_svg(function, offset, modeChoices[modeChoiceField.result],
                         formChoices[formChoiceField.result],
                         showOpcodes.result == 0, showAddresses.result == 0,
                         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:
        # might need more testing, latest py3 on windows seems.... broken with these APIs relative to other platforms
        if sys.platform == 'win32':
            webbrowser.open(outputfile)
        else:
            webbrowser.open('file://' + str(outputfile))
Esempio n. 3
0
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())
Esempio n. 4
0
File: ief.py Progetto: etke/ief
def ief_find_library(binview):
    """ run `ief <path> -l <partial library name>` """
    name = TextLineField("Library name (can be partial)")
    directory = DirectoryNameField(
        "Directory to search", dirname(binview.file.filename))
    get_form_input([name, None, directory],
                   "Find binaries that import library")
    if not directory.result:
        directory.result = dirname(binview.file.filename)
    if name.result is None:
        return
    # Assumes `~/.cargo/bin` already exists in PATH
    result = run(["ief", directory.result, "-l",
                  name.result], capture_output=True)
    directory = directory.result
    markdown = f"# Results - binaries in '[{directory}]({directory})'" \
        f"with imported library name containing '_{name.result}_'\n\n"
    for line in result.stdout.split(b"\n")[1:-1]:
        npath = normpath(line.decode('utf-8'))
        markdown += f"* [{npath}]({npath})\n"
    show_markdown_report(f"IEF - {name.result}",
                         markdown, result.stdout.decode('utf-8'))