Ejemplo n.º 1
0
    def run(self):
        if self.context == None:
            log_warn("Cannot run snippets outside of the UI at this time.")
            return
        if self.snippetChanged():
            question = QMessageBox.question(
                self, self.tr("Confirm"),
                self.tr("You have unsaved changes, must save first. Save?"))
            if (question == QMessageBox.StandardButton.No):
                return
            else:
                self.save()
        actionText = actionFromSnippet(self.currentFile,
                                       self.snippetDescription.text())
        UIActionHandler.globalActions().executeAction(actionText, self.context)

        log_debug("Saving snippet %s" % self.currentFile)
        outputSnippet = codecs.open(self.currentFile, "w", "utf-8")
        outputSnippet.write("#" + self.snippetDescription.text() + "\n")
        outputSnippet.write("#" +
                            self.keySequenceEdit.keySequence().toString() +
                            "\n")
        outputSnippet.write(self.edit.toPlainText())
        outputSnippet.close()
        self.registerAllSnippets()
Ejemplo n.º 2
0
def add_commands(plugin):
    DbgAction = namedtuple('DbgAction', 'name, key_seq, handler')
    plugin_actions = (DbgAction("SyncEnable", QKeySequence(Qt.ALT + Qt.Key_S),
                                UIAction(plugin.cmd_sync)),
                      DbgAction("SyncDisable",
                                QKeySequence(Qt.ALT + Qt.SHIFT + Qt.Key_S),
                                UIAction(plugin.cmd_syncoff)),
                      DbgAction("SyncGo", QKeySequence(Qt.ALT + Qt.Key_F5),
                                UIAction(plugin.cmd_go)),
                      DbgAction("SyncStepOver", QKeySequence(Qt.Key_F10),
                                UIAction(plugin.cmd_so)),
                      DbgAction("SyncStepInto", QKeySequence(Qt.Key_F11),
                                UIAction(plugin.cmd_si)),
                      DbgAction("SyncTranslate",
                                QKeySequence(Qt.ALT + Qt.Key_F2),
                                UIAction(plugin.cmd_translate)),
                      DbgAction("SyncBp", QKeySequence(Qt.Key_F2),
                                UIAction(plugin.cmd_bp)),
                      DbgAction("SyncHwBp", QKeySequence(Qt.CTRL + Qt.Key_F2),
                                UIAction(plugin.cmd_hwbp)),
                      DbgAction("SyncBpOneShot",
                                QKeySequence(Qt.ALT + Qt.Key_F3),
                                UIAction(plugin.cmd_bp1)),
                      DbgAction("SyncHwBpOneShot",
                                QKeySequence(Qt.CTRL + Qt.Key_F3),
                                UIAction(plugin.cmd_hwbp1)))

    for action in plugin_actions:
        UIAction.registerAction(action.name, action.key_seq)
        UIActionHandler.globalActions().bindAction(action.name, action.handler)

    rs_log('commands added')
Ejemplo n.º 3
0
    def registerAllSnippets():
        for action in list(
                filter(lambda x: x.startswith("Snippets\\"),
                       UIAction.getAllRegisteredActions())):
            if action == "Snippets\\Snippet Editor...":
                continue
            UIActionHandler.globalActions().unbindAction(action)
            Menu.mainMenu("Tools").removeAction(action)
            UIAction.unregisterAction(action)

        for snippet in includeWalk(snippetPath, ".py"):
            snippetKeys = None
            (snippetDescription, snippetKeys,
             snippetCode) = loadSnippetFromFile(snippet)
            if not snippetDescription:
                actionText = "Snippets\\" + os.path.basename(snippet).rstrip(
                    ".py")
            else:
                actionText = "Snippets\\" + snippetDescription
            if snippetCode:
                if snippetKeys == None:
                    UIAction.registerAction(actionText)
                else:
                    UIAction.registerAction(actionText, snippetKeys)
                UIActionHandler.globalActions().bindAction(
                    actionText, UIAction(makeSnippetFunction(snippetCode)))
                Menu.mainMenu("Tools").addAction(actionText, actionText)
Ejemplo n.º 4
0
    def registerAllSnippets(self):
        for action in list(filter(lambda x: x.startswith("Snippet\\"), UIAction.getAllRegisteredActions())):
            UIActionHandler.globalActions().unbindAction(action)
            UIAction.unregisterAction(action)

        for snippet in includeWalk(snippetPath, ".py"):
            (snippetDescription, snippetKey, snippetCode) = loadSnippetFromFile(snippet)
            if not snippetDescription:
                actionText = "Snippet\\" + snippet
            else:
                actionText = "Snippet\\" + snippetDescription
            UIAction.registerAction(actionText, snippetKey)
            UIActionHandler.globalActions().bindAction(actionText, UIAction(makeSnippetFunction(snippetCode)))
Ejemplo n.º 5
0
    def _init_ui(self):
        # config dialog
        configure_binsync_id = "BinSync: Configure"
        UIAction.registerAction(configure_binsync_id)
        UIActionHandler.globalActions().bindAction(
            configure_binsync_id, UIAction(self._launch_config))
        Menu.mainMenu("Tools").addAction(configure_binsync_id, "BinSync")

        # control panel (per BV)
        dock_handler = DockHandler.getActiveDockHandler()
        dock_handler.addDockWidget(
            "BinSync: Control Panel", lambda n, p, d: create_widget(
                ControlPanelDockWidget, n, p, d, self.controllers),
            Qt.RightDockWidgetArea, Qt.Vertical, True)
Ejemplo n.º 6
0
    def run(self):
        if self.context == None:
            log_warn("Cannot run snippets outside of the UI at this time.")
            return
        if self.snippetChanged():
            self.save()
        actionText = actionFromSnippet(self.currentFile, self.snippetDescription.text())
        UIActionHandler.globalActions().executeAction(actionText, self.context)

        log_debug("Saving snippet %s" % self.currentFile)
        outputSnippet = codecs.open(self.currentFile, "w", "utf-8")
        outputSnippet.write("#" + self.snippetDescription.text() + "\n")
        outputSnippet.write("#" + self.keySequenceEdit.keySequence().toString() + "\n")
        outputSnippet.write(self.edit.toPlainText())
        outputSnippet.close()
        self.registerAllSnippets()
Ejemplo n.º 7
0
		"description" : "Controls the amount of analysis performed on functions when opening for triage.",
		"enum" : ["controlFlow", "basic", "full"],
		"enumDescriptions" : [
			"Only perform control flow analysis on the binary. Cross references are valid only for direct function calls.",
			"Perform fast initial analysis of the binary. This mode does not analyze types or data flow through stack variables.",
			"Perform full analysis of the binary." ]
	}
	""")

Settings().register_setting("triage.linearSweep", """
	{
		"title" : "Triage Linear Sweep Mode",
		"type" : "string",
		"default" : "partial",
		"description" : "Controls the level of linear sweep performed when opening for triage.",
		"enum" : ["none", "partial", "full"],
		"enumDescriptions" : [
			"Do not perform linear sweep of the binary.",
			"Perform linear sweep on the binary, but skip the control flow graph analysis phase.",
			"Perform full linear sweep on the binary." ]
	}
	""")

UIAction.registerAction("Open for Triage...", QKeySequence("Ctrl+Alt+O"))
UIAction.registerAction("Open Selected Files")

UIActionHandler.globalActions().bindAction("Open for Triage...", UIAction(openForTriage))
Menu.mainMenu("File").addAction("Open for Triage...", "Open")

UIContext.registerFileOpenMode("Triage...", "Open file(s) for quick analysis in the Triage Summary view.", "Open for Triage...")
Ejemplo n.º 8
0
 def addToolMenuAction(self, name, function):
     """ Adds an item to the tool menu (at the top of the window) without registering a plugin command """
     UIAction.registerAction(name)
     UIActionHandler.globalActions().bindAction(name, UIAction(function))
     self._tool_menu.addAction(name, function)
Ejemplo n.º 9
0
        if size > 0 and size < 400 and i + size < len(data):
            byte_key = data[i:i+4]
            decrypted = bytearray()
            valid = True
            for j in range(size):
                char = data[i+8+j] ^ byte_key[j % 4]
                if char not in printables:
                    valid = False
                    break
                decrypted.append(char)
            if valid:
                sym_addr = data_section.start + i
                s = bytes(decrypted).decode()
                sym_name = s[:20].strip()
                for c in " \t\r\n":
                    sym_name = sym_name.replace(c, "_")
                sym_name = "str_" + sym_name
                symbol = Symbol(SymbolType.DataSymbol, sym_addr, sym_name)
                bv.define_user_symbol(symbol)
                bv.write(sym_addr, s + "\x00")


def launch_plugin(context):
    bv = context.binaryView
    decrypt_strings(bv)
    find_dynamic_apis(bv)


UIAction.registerAction("Emotet Deobufscator")
UIActionHandler.globalActions().bindAction("Emotet Deobufscator", UIAction(launch_plugin))
Menu.mainMenu("Tools").addAction("Emotet Deobufscator", "Emotet Deobufscator")
Ejemplo n.º 10
0
try:
    from binaryninjaui import (UIAction, UIActionHandler, Menu)

    from . import keypatch

    UIAction.registerAction("KEYPATCH")
    UIActionHandler.globalActions().bindAction(
        "KEYPATCH", UIAction(keypatch.launch_keypatch))
    Menu.mainMenu("Tools").addAction("KEYPATCH", "KEYPATCH")
except ModuleNotFoundError:
    # probably being loaded by headless BinaryNinja
    pass
Ejemplo n.º 11
0
def _registerUIActions():
    UIAction.registerAction("SENinja\\Setup argv...")
    UIActionHandler.globalActions().bindAction("SENinja\\Setup argv...",
                                               UIAction(_launchArgvDialog))
    Menu.mainMenu("Tools").addAction("SENinja\\Setup argv...", "Setup argv...")
Ejemplo n.º 12
0
        # Update UI according to the active frame
        if frame:
            self.datatype.setText(frame.getCurrentView())
            view = frame.getCurrentViewInterface()
            self.data = view.getData()
            self.offset.setText(hex(view.getCurrentOffset()))
        else:
            self.datatype.setText("None")
            self.data = None

    def contextMenuEvent(self, event):
        self.m_contextMenuManager.show(self.m_menu, self.actionHandler)

    @staticmethod
    def createPane(context):
        if context.context and context.binaryView:
            widget = HelloPaneWidget(context.binaryView)
            pane = WidgetPane(widget, "Hello")
            context.context.openPane(pane)

    @staticmethod
    def canCreatePane(context):
        return context.context and context.binaryView


UIAction.registerAction("Hello Pane")
UIActionHandler.globalActions().bindAction(
    "Hello Pane",
    UIAction(HelloPaneWidget.createPane, HelloPaneWidget.canCreatePane))
Menu.mainMenu("Tools").addAction("Hello Pane", "Hello")
Ejemplo n.º 13
0
 def _install_load_batch(self):
     action = self.ACTION_LOAD_BATCH
     UIAction.registerAction(action)
     UIActionHandler.globalActions().bindAction(action, UIAction(self._interactive_load_batch))
     Menu.mainMenu("Tools").addAction(action, "Loading", 1)
     logger.info("Installed the 'Code coverage batch' menu entry")
Ejemplo n.º 14
0
    def function_updated(self, view, func):
        self._controller.push_function(func)


def start_patch_monitor(view):
    notification = PatchDataNotification(view, controller)
    view.register_notification(notification)


def start_function_monitor(view):
    notification = EditFunctionNotification(view, controller)
    view.register_notification(notification)


UIAction.registerAction("Configure BinSync...")
UIActionHandler.globalActions().bindAction("Configure BinSync...",
                                           UIAction(launch_binsync_configure))
Menu.mainMenu("Tools").addAction("Configure BinSync...", "BinSync")

open_control_panel_id = "BinSync: Open control panel"
UIAction.registerAction(open_control_panel_id)
UIActionHandler.globalActions().bindAction(open_control_panel_id,
                                           UIAction(open_control_panel))
Menu.mainMenu("Tools").addAction(open_control_panel_id, "BinSync")

# register the control panel dock widget
dock_handler = DockHandler.getActiveDockHandler()
dock_handler.addDockWidget(
    "BinSync: Control Panel",
    lambda n, p, d: create_widget(ControlPanelDockWidget, n, p, d, controller),
    Qt.RightDockWidgetArea, Qt.Vertical, True)
Ejemplo n.º 15
0

def make_code(bv: BinaryView, start: int, end: int) -> None:
    if bv.get_basic_blocks_at(start):
        return
    if end - start <= 1:
        # find the next basic block, data variable, or segment/section end
        data_var = bv.get_next_data_var_after(start)
        if data_var is not None:
            end = data_var.address
        else:
            end = bv.end
        end = min(bv.get_next_basic_block_start_after(start), end)
        seg = bv.get_segment_at(start)
        if seg is not None:
            end = min(seg.end, end)
        section_ends = [s.end for s in bv.get_sections_at(start)]
        end = min(*section_ends, end)
    bv.define_data_var(start, Type.array(Type.int(1, False), end - start),
                       f"CODE_{start:08x}")


def make_code_helper(ctx: UIActionContext):
    make_code(ctx.binaryView, ctx.address, ctx.address + ctx.length)


CodeDataRenderer().register_type_specific()
UIAction.registerAction("Make Code", QKeySequence("C"))
UIActionHandler.globalActions().bindAction("Make Code",
                                           UIAction(make_code_helper))
Ejemplo n.º 16
0
        if len(snippetKey) != 0 and snippetKey[0] != self.keySequenceEdit.keySequence():
            return True
        return self.edit.toPlainText() != snippetCode or \
               self.snippetDescription.text() != snippetDescription

    def save(self):
        log_debug("Saving snippet %s" % self.currentFile)
        outputSnippet = open(self.currentFile, "w")
        outputSnippet.write("#" + self.snippetDescription.text() + "\n")
        outputSnippet.write("#" + self.keySequenceEdit.keySequence().toString() + "\n")
        outputSnippet.write(self.edit.toPlainText())
        outputSnippet.close()
        self.registerAllSnippets()

    def clearHotkey(self):
        self.keySequenceEdit.clear()

def launchPlugin(context):
    snippets = Snippets()
    snippets.exec_()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    snippets = Snippets()
    snippets.show()
    sys.exit(app.exec_())
else:
    UIAction.registerAction("Snippet Editor...")
    UIActionHandler.globalActions().bindAction("Snippet Editor...", UIAction(launchPlugin))
    Menu.mainMenu("Tools").addAction("Snippet Editor...", "Snippet")
Ejemplo n.º 17
0
 def _install_open_coverage_overview(self):
     action = self.ACTION_COVERAGE_OVERVIEW
     UIAction.registerAction(action)
     UIActionHandler.globalActions().bindAction(action, UIAction(self._open_coverage_overview))
     Menu.mainMenu("Tools").addAction(action, "Windows", 0)
     logger.info("Installed the 'Open Coverage Overview' menu entry")
Ejemplo n.º 18
0
from .types.libimport import browse_type_library
from binaryninja import PluginCommand
from binaryninjaui import UIAction, UIActionHandler, Menu, ViewType

from .types.export import export_type_library
from .types.make_struct import make_struct_here
from .functions.callgraph import CallGraphViewType

UIAction.registerAction(
    "Reverse Engineer's Toolkit\\Types\\Export Type Library")
UIActionHandler.globalActions().bindAction(
    "Reverse Engineer's Toolkit\\Types\\Export Type Library",
    UIAction(export_type_library, lambda ctx: ctx.binaryView is not None),
)
Menu.mainMenu("Tools").addAction(
    "Reverse Engineer's Toolkit\\Types\\Export Type Library",
    "Export Type Library")

UIAction.registerAction(
    "Reverse Engineer's Toolkit\\Types\\Import Type Library")
UIActionHandler.globalActions().bindAction(
    "Reverse Engineer's Toolkit\\Types\\Import Type Library",
    UIAction(browse_type_library, lambda ctx: ctx.binaryView is not None),
)
Menu.mainMenu("Tools").addAction(
    "Reverse Engineer's Toolkit\\Types\\Import Type Library",
    "Import Type Library")

PluginCommand.register_for_range(
    "Make Structure Here",
    "Make a structure from this range of data variables",