Пример #1
0
def add_action(action):
    """
    Add an ida-action
    :param action: action given as the `Action` namedtuple
    :return: None
    """
    class Handler(ida_kernwin.action_handler_t):
        def __init__(self):
            ida_kernwin.action_handler_t.__init__(self)

        def activate(self, ctx):
            action.handler()
            return 1

        def update(self, ctx):
            return ida_kernwin.AST_ENABLE_FOR_WIDGET

    act_icon = -1
    if action.icon_filename:
        icon_full_filename = \
            pkg_resources.resource_filename('fa',
                                            os.path.join(
                                                'res',
                                                'icons',
                                                action.icon_filename))
        with open(icon_full_filename, 'rb') as f:
            icon_data = f.read()
        act_icon = ida_kernwin.load_custom_icon(data=icon_data, format="png")

    act_name = action.name

    ida_kernwin.unregister_action(act_name)
    if ida_kernwin.register_action(ida_kernwin.action_desc_t(
            act_name,  # Name. Acts as an ID. Must be unique.
            action.label,  # Label. That's what users see.
            Handler(),  # Handler. Called when activated, and for updating
            action.hotkey,  # Shortcut (optional)
            None,  # Tooltip (optional)
            act_icon)):  # Icon ID (optional)

        # Insert the action in the menu
        if not ida_kernwin.attach_action_to_menu(
                "FA/", act_name, ida_kernwin.SETMENU_APP):
            print("Failed attaching to menu.")

        # Insert the action in a toolbar
        if not ida_kernwin.attach_action_to_toolbar("fa", act_name):
            print("Failed attaching to toolbar.")

        class Hooks(ida_kernwin.UI_Hooks):
            def finish_populating_widget_popup(self, widget, popup):
                if ida_kernwin.get_widget_type(widget) == \
                        ida_kernwin.BWN_DISASM:
                    ida_kernwin.attach_action_to_popup(widget,
                                                       popup,
                                                       act_name,
                                                       None)

        hooks = Hooks()
        hooks.hook()
Пример #2
0
 def unregister(self):
     """
         Unregister the action in IDA, if this action was not register this
         function does nothing. Unregistering should also delete the entry
         from the menu if any.
     """
     if not self.is_register:
         return  # nothing to do
     ida_kernwin.unregister_action(self._name)
     self.is_register = False
Пример #3
0
Файл: xray.py Проект: neoni/xray
 def term(self):
     if self.xray_hooks:
         self.xray_hooks.unhook()
         kw.unregister_action(XRAY_FILTER_ACTION_ID)
         kw.unregister_action(XRAY_LOADCFG_ACTION_ID)
         kw.unregister_action(XRAY_QUERY_ACTION_ID)
         kw.unregister_action(XRAY_COLOR_ACTION_ID)
     return
Пример #4
0
def main(): # type: () -> None
    if hr.init_hexrays_plugin():
        existing = ida_kernwin.unregister_action(ACTION_NAME)
        ida_kernwin.register_action(
            ida_kernwin.action_desc_t(ACTION_NAME, "sead::SafeString", sead_string_ah_t(), "F12"))
        if not existing:
            hr.install_hexrays_callback(cb)
Пример #5
0
    def uninstall(self):
        if not ida_kernwin.detach_action_from_menu(self._menu, self._action_name):
            self._plugin.logger.error('Failed to detach action save to server from menu')
            return False

        if not ida_kernwin.unregister_action(self._action_name):
            self._plugin.logger.error('Failed to unregister action save to server')
            return False

        return True
def main():
    show_banner()

    print "Unregistering old action..."
    ida_kernwin.unregister_action(ACTION_NAME)

    if ida_hexrays.init_hexrays_plugin():
        ida_kernwin.register_action(
            ida_kernwin.action_desc_t(ACTION_NAME,
                                      "Keep sanity (stack strings)",
                                      stack_strings_ah_t(), None))

        print "Registered new action"

        idaapi.install_hexrays_callback(cb)

    else:
        print "[x] No decompiler found!"
        return
Пример #7
0
    def _uninstall_action(self, action, icon_id=ida_idaapi.BADADDR):

        result = ida_kernwin.unregister_action(action)
        if not result:
            logger.warning(f"Failed to unregister {action}...")
            return False

        if icon_id != ida_idaapi.BADADDR:
            ida_kernwin.free_custom_icon(icon_id)

        logger.info(f"Uninstalled the {action} menu entry")
        return True
Пример #8
0
    def finish_populating_widget_popup(self, widget, popup):
        widget_type = idaapi.get_widget_type(widget)
        if ((idaapi.BWN_FUNCS == widget_type) and self.taintinfo.showing_taint()):
            # about to show context menu for "Functions window" - as taint is
            # shown, add item to show window of tainted functions
            ida_kernwin.unregister_action(ShowTaintedFuncs.ACTION_NAME)

            # could also provide a shortcut and icon in the action_desc_t, if helpful
            if ida_kernwin.register_action(
                ida_kernwin.action_desc_t(
                    ShowTaintedFuncs.ACTION_NAME,
                    ShowTaintedFuncs.ACTION_LABEL,
                    ShowTaintedFuncs(self.taintinfo),
                    None,
                    ShowTaintedFuncs.ACTION_TOOLTIP)):
                    # if middle arg is None, this item is added permanently to the popup menu
                    # if it lists a TPopupMenu* handle, then this action is added just for this invocation
                    ida_kernwin.attach_action_to_popup(widget, popup, ShowTaintedFuncs.ACTION_NAME)
        elif ((idaapi.BWN_DISASM == widget_type) and self.taintinfo.have_taint_info()):
            # about to show context menu for a disassembly window - as taint
            # information is available, add either a Show or Hide item
            ida_kernwin.unregister_action(ShowHideTaint.ACTION_NAME)
            if (self.taintinfo.showing_taint()):
                if ida_kernwin.register_action(
                    ida_kernwin.action_desc_t(
                        ShowHideTaint.ACTION_NAME,
                        ShowHideTaint.HIDE_ACTION_LABEL,
                        ShowHideTaint(self.taintinfo),
                        None,
                        ShowHideTaint.HIDE_ACTION_TOOLTIP)):
                        ida_kernwin.attach_action_to_popup(widget, popup, ShowHideTaint.ACTION_NAME)
            else:
                if ida_kernwin.register_action(
                    ida_kernwin.action_desc_t(
                        ShowHideTaint.ACTION_NAME,
                        ShowHideTaint.SHOW_ACTION_LABEL,
                        ShowHideTaint(self.taintinfo),
                        None,
                        ShowHideTaint.SHOW_ACTION_TOOLTIP)):
                        ida_kernwin.attach_action_to_popup(widget, popup, ShowHideTaint.ACTION_NAME)
Пример #9
0
    def uninstall(self):
        # Detach the action from the chosen menu
        result = ida_kernwin.detach_action_from_menu(self._menu,
                                                     self._ACTION_ID)
        if not result:
            return False

        # Un-register the action using its id
        result = ida_kernwin.unregister_action(self._ACTION_ID)
        if not result:
            return False

        # Free the custom icon using its id
        ida_kernwin.free_custom_icon(self._icon_id)
        self._icon_id = ida_idaapi.BADADDR

        self._plugin.logger.debug("Uninstalled the action")
        return True
Пример #10
0
def init_hooks(idausr):
    _setter = IdausrTemporarySetter(idausr)

    class ActionHandler(ida_kernwin.action_handler_t):
        def __init__(self, handler):
            ida_kernwin.action_handler_t.__init__(self)
            self.handler = handler

        def activate(self, ctx):
            with _setter:
                self.handler()

        def update(self, ctx):
            return ida_kernwin.AST_ENABLE_ALWAYS

    for name, label, handler, before in _HOOKS:
        if ida_kernwin.unregister_action(name):
            action = ida_kernwin.action_desc_t(name, label,
                                               ActionHandler(handler))
            ida_kernwin.register_action(action)
            ida_kernwin.attach_action_to_menu(before, name,
                                              ida_kernwin.SETMENU_INS)
Пример #11
0
    def _uninstall_load_trace(self):

        logger.info("Removing the 'Tenet trace file...' menu entry...")

        # remove the entry from the File-> menu
        result = ida_kernwin.detach_action_from_menu("File/Load file/",
                                                     self.ACTION_LOAD_TRACE)
        if not result:
            logger.warning("Failed to detach action from menu...")
            return False

        # unregister the action
        result = ida_kernwin.unregister_action(self.ACTION_LOAD_TRACE)
        if not result:
            logger.warning("Failed to unregister action...")
            return False

        # delete the entry's icon
        #ida_kernwin.free_custom_icon(self._icon_id_file) # TODO
        self._icon_id_file = ida_idaapi.BADADDR

        logger.info("Successfully removed the menu entry!")
        return True
Пример #12
0
    args = convert_args_to_long(xref_args)
    if args:
        try:
            key = idaapi.get_many_bytes(args[2], args[3] if idc.Dword(args[3]) == 0xffffffff else idc.Dword(args[3]))
            data = idaapi.get_many_bytes(args[0], args[1] if idc.Dword(args[1]) == 0xffffffff else idc.Dword(args[1]))
        except TypeError:
            print("Couldn't retrieve the cipher or the key.")
            print(xref_args)
        else:
            key = null_pad(key, 0x20)
            if args[4] == 1:
                data = custom_b64decode(data)
            plain = PKCS7_unpad(AES.new(key, AES.MODE_CBC, "\x00"*16).decrypt(data))
            #add_comment(cfunc, plain, xref)
            print(plain)
    else:
        print("Not all args are numbers")
        print(xref_args)

CUSTOM_B64_ALPHA = "IJKLMNOPABCDEFGHQRSTUVWXghijklmnYZabcdefopqrstuv456789+/wxyz0123"
ACTION_NAME = "extract-decrypt-arguments-var-prop"
ida_kernwin.unregister_action(ACTION_NAME)
if idaapi.init_hexrays_plugin():
    ida_kernwin.register_action(ida_kernwin.action_desc_t(ACTION_NAME, "Extract and decrypt arguments", extract_args_t(decrypt_data, True), None))
class popup_hooks_t(ida_kernwin.UI_Hooks):
    def finish_populating_widget_popup(self, w, popup):
        if ida_kernwin.get_widget_type(w) == ida_kernwin.BWN_FUNCS:
            ida_kernwin.attach_action_to_popup(w, popup, ACTION_NAME, None)
hooks = popup_hooks_t()
hooks.hook()
Пример #13
0
 def _uninstall(self):
     self.ui_hooks.unhook()
     for desc in self._registered_actions:
         ida_kernwin.unregister_action(desc)
Пример #14
0
 def term(self):
     if self.xray_hooks:
         self.xray_hooks.unhook()
         kw.unregister_action(XRAY_FILTER_AID)
         kw.unregister_action(XRAY_LOADCFG_AID)
     return
Пример #15
0
 def term():
     unregister_action(SyncLocalTypes.name)
     unregister_action(PrintEfiGuid.name)
Пример #16
0
                loc.set_place(idaplace)
                loc.renderer_info().pos.cx = found[2]
                ida_kernwin.custom_viewer_jump(v, loc, ida_kernwin.CVNF_LAZY)
                break

            ea = ida_bytes.next_head(ea, ida_idaapi.BADADDR)


class jump_next_comment_ah_t(ida_kernwin.action_handler_t):
    def activate(self, ctx):
        jump_next_comment(ctx.widget)

    def update(self, ctx):
        return ida_kernwin.AST_ENABLE_FOR_WIDGET \
            if ctx.widget_type == ida_kernwin.BWN_DISASM \
            else ida_kernwin.AST_DISABLE_FOR_WIDGET


ACTION_NAME = "jump_next_comment:jump"
ACTION_LABEL = "Jump to the next comment"
ACTION_SHORTCUT = "Ctrl+Alt+C"
ACTION_HELP = "Press %s to jump to the next comment" % ACTION_SHORTCUT

if ida_kernwin.unregister_action(ACTION_NAME):
    print("Unregistered previously-registered action \"%s\"" % ACTION_LABEL)

if ida_kernwin.register_action(
        ida_kernwin.action_desc_t(ACTION_NAME, ACTION_LABEL,
                                  jump_next_comment_ah_t(), ACTION_SHORTCUT)):
    print("Registered action \"%s\". %s" % (ACTION_LABEL, ACTION_HELP))
Пример #17
0
def unregister(action):
    ida_kernwin.unregister_action(action.name)
Пример #18
0
    @staticmethod
    def compose_action_name(v):
        return "dump_extra_comments:%s" % v


# -----------------------------------------------------------------------
# create actions (and attach them to IDA View-A's context menu if possible)
widget_title = "IDA View-A"
ida_view = ida_kernwin.find_widget(widget_title)

actions_variants = [
    ("previous", ida_lines.E_PREV, "Ctrl+Shift+Y"),
    ("next", ida_lines.E_NEXT, "Ctrl+Shift+Z"),
]
for label, anchor, shortcut in actions_variants:
    actname = dump_at_point_handler_t.compose_action_name(label)
    if ida_kernwin.unregister_action(actname):
        print("Unregistered previously-registered action \"%s\"" % actname)

    desc = ida_kernwin.action_desc_t(
        actname,
        "Dump %s extra comments" % label,
        dump_at_point_handler_t(anchor),
        shortcut)
    if ida_kernwin.register_action(desc):
        print("Registered action \"%s\"" % actname)

    if ida_view and ida_kernwin.attach_action_to_popup(ida_view, None, actname):
        print("Permanently attached action \"%s\" to \"%s\"" % (actname, widget_title))
Пример #19
0
 def _del_action_view_microcode(self):
     """
     Delete the 'View microcode' action from IDA.
     """
     ida_kernwin.unregister_action(self.ACTION_VIEW_MICROCODE)
Пример #20
0
        ida_kernwin.action_handler_t.__init__(self)

    def activate(self, ctx):
        for idx in ctx.chooser_selection:
            addr, _, _, s = ida_kernwin.get_chooser_data(ctx.widget_title, idx)
            print("%s: '%s'" % (addr, s))
        return 0

    def update(self, ctx):
        if ctx.widget_type == ida_kernwin.BWN_STRINGS:
            return ida_kernwin.AST_ENABLE_FOR_WIDGET
        return ida_kernwin.AST_DISABLE_FOR_WIDGET


klasses = [copy_only_string, print_string]

sw = ida_kernwin.find_widget("Strings window")
if not sw:
    sw = ida_kernwin.open_strings_window(ida_idaapi.BADADDR)

for klass in klasses:
    ida_kernwin.unregister_action(klass.ACTION_NAME)

    if ida_kernwin.register_action(
            ida_kernwin.action_desc_t(klass.ACTION_NAME, klass.ACTION_LABEL,
                                      klass(), klass.ACTION_SHORTCUT)):
        if sw:
            ida_kernwin.attach_action_to_popup(sw, None, klass.ACTION_NAME)
            print("Permanently added '%s' action to 'String window's popup" %
                  klass.ACTION_LABEL)
Пример #21
0
 def unregisterAction(self):
     ida_kernwin.detach_action_from_menu(self.menuPath, self.id)
     ida_kernwin.unregister_action(self.id)