def term(self): self.hooks.unhook() self.add_to_search_handler.unregister() self.clear_search_handler.unregister() for hotkey in self.hotkeys: idaapi.del_hotkey(hotkey)
def map(cls, key, callable): '''Map a specific `key` to a python `callable`.''' # check to see if the key is stored within our cache and remove it if so if key in cls.hotkey: idaapi.del_hotkey(cls.hotkey[key]) # now we can add the hotkey and stash it in our cache # XXX: I'm not sure if the key needs to be utf8 encoded or not cls.hotkey[key] = res = idaapi.add_hotkey(key, callable) return res
def uninit_hotkeys(self): if not self.hotkeys_ctx: return for ctx in self.hotkeys_ctx: if idaapi.del_hotkey(ctx): del ctx
def uninit_hotkeys(self): if not self.hotkeys_ctx: return for ctx in self.hotkeys_ctx: if idaapi.del_hotkey(ctx): del ctx self.hotkeys_ctx = []
def uninit_hotkeys(self): if not self.hotkeys_ctx: return # delete registered context and restore original action for ctx, key, conflict in self.hotkeys_ctx: if idaapi.del_hotkey(ctx): del ctx else: print("[sync] failed to delete hotkey %s" % key) if conflict: ida_kernwin.update_action_shortcut(conflict, key) self.hotkeys_ctx = []
def main(): global hotkey_ctx try: hotkey_ctx if idaapi.del_hotkey(hotkey_ctx): print("Hotkey unregistered!") del hotkey_ctx else: print("Failed to delete hotkey!") except: pass hotkey_ctx = idaapi.add_hotkey("F5", show_decompiler) if hotkey_ctx is None: print("Failed to register hotkey!") del hotkey_ctx else: print("Press F5 to decompile a function.")
def main(): global hotkey_ctx try: hotkey_ctx if idaapi.del_hotkey(hotkey_ctx): print "Hotkey unregistered!" del hotkey_ctx else: print "Failed to delete hotkey!" except: pass hotkey_ctx = idaapi.add_hotkey("F5", show_decompiler) if hotkey_ctx is None: print "Failed to register hotkey!" del hotkey_ctx else: print "Press F5 to decompile a function."
def uninit_hotkeys(self): # disable ida_kernwin.UI_Hooks if self.cmd_hooks.minver74sp1(): self.cmd_hooks.unhook() if not self.hotkeys_ctx: return # delete registered context and restore original action for ctx, key, conflict in self.hotkeys_ctx: if idaapi.del_hotkey(ctx): del ctx else: rs_log("failed to delete hotkey %s" % key) if conflict and not self.cmd_hooks.minver74sp1(): ida_kernwin.update_action_shortcut(conflict, key) self.hotkeys_ctx = []
def term(self): for hotkey in self.hotkeys: idaapi.del_hotkey(hotkey)
def unmap(cls, key): '''Unmap the specified `key` from its callable.''' idaapi.del_hotkey(cls.hotkey[key]) del(cls.hotkey[key])
def unmap(cls, key): '''Unmap the specified `key` from IDA and return the callable that it was assigned to.''' frepr = lambda hotkey: internal.utils.string.repr( cls.__of_key__(hotkey)) # First check to see whether we were given a callable or a hotkey. If # we were given a callable, then we need to look through our cache for # the actual key that it was. Once found, then we normalize it like usual. if callable(key): try: hotkey = cls.__normalize_key__( next(item for item, (_, fcallback) in cls.__cache__.items() if fcallback == key)) except StopIteration: raise internal.exceptions.InvalidParameterError( u"{:s}.unmap({:s}) : Unable to locate the callable {!r} in the current list of keyboard mappings." .format( '.'.join((__name__, cls.__name__)), "{!r}".format(key) if callable(key) else "{!s}".format( internal.utils.string.repr(key)), key)) else: logging.warn( u"{:s}.unmap({:s}) : Discovered the hotkey {!s} being currently mapped to the callable {!r}." .format( '.'.join((__name__, cls.__name__)), "{!r}".format(key) if callable(key) else "{!s}".format( internal.utils.string.repr(key)), frepr(hotkey), key)) # We need to normalize the hotkey we were given, and convert it back # into IDA's format. This way we can locate it in our cache, and prevent # sloppy user input from interfering. else: hotkey = cls.__normalize_key__(key) # Check to see if the hotkey is cached and warn the user if it isn't. if hotkey not in cls.__cache__: logging.warn( u"{:s}.unmap({:s}) : Refusing to unmap the hotkey {!s} as it is not currently mapped to anything." .format( '.'.join((__name__, cls.__name__)), "{!r}".format(key) if callable(key) else "{!s}".format( internal.utils.string.repr(key)), frepr(hotkey))) return # Grab the keymapping context from our cache, and then ask IDA to remove # it for us. If we weren't successful, then raise an exception so the # user knows what's up. ctx, _ = cls.__cache__[hotkey] ok = idaapi.del_hotkey(ctx) if not ok: raise internal.exceptions.DisassemblerError( u"{:s}.unmap({:s}) : Unable to unmap the specified hotkey ({!s}) from the current list of keyboard mappings." .format( '.'.join((__name__, cls.__name__)), "{!r}".format(key) if callable(key) else "{!s}".format( internal.utils.string.repr(key)), frepr(hotkey))) # Now we can pop off the callable that was mapped to the hotkey context # in order to return it, and remove the hotkey from our cache. _, res = cls.__cache__.pop(hotkey) return res
def rm(cls, key): """unmap a key""" idaapi.del_hotkey(cls.hotkey[key]) del(cls.hotkey[key])
def rm(cls, key): """unmap a key""" idaapi.del_hotkey(cls.hotkey[key]) del (cls.hotkey[key])
def add(cls, key, fn): """map a key to a python function""" if key in cls.hotkey: idaapi.del_hotkey(cls.hotkey[key]) cls.hotkey[key] = res = idaapi.add_hotkey(key, fn) return res
def create_pattern(ea): curSig, len = AddInsToSig("", ea) ea = ea + len while not IsUniquePattern(curSig): curSig, len = AddInsToSig(curSig, ea) ea = ea + len return curSig def hotkey_pressed(): CreatePattern() try: hotkey_ctx if idaapi.del_hotkey(hotkey_ctx): print("CreateSignature hotkey unregistered!") del hotkey_ctx else: print("Failed to delete CreateSignature hotkey!") except: hotkey_ctx = idaapi.add_hotkey("Ctrl+Shift+Alt+S", hotkey_pressed) if hotkey_ctx is None: print("Failed to register CreateSignature hotkey!") del hotkey_ctx else: print("CreateSignature hotkey registered to Ctrl+Shift+Alt+S!") try: hotkey_scs if idaapi.del_hotkey(hotkey_scs):
hotkey_mappings = { "Shift-S", save_function, "Shift-L", load_function, "Shift-A", save_all_functions, "Shift-H", print_hash, } hotkey_contexts = [] try: hotkey_context_S if idaapi.del_hotkey(hotkey_context_S): print("FunctionSimSearch: Hotkey S unregistered.") del hotkey_context_S else: print("FunctionSimSearch: Failed to unregister hotkey S.") hotkey_context_L if idaapi.del_hotkey(hotkey_context_L): print("FunctionSimSearch: Hotkey L unregistered.") del hotkey_context_L else: print("FunctionSimSearch: Failed to unregister hotkey L.") hotkey_context_H if idaapi.del_hotkey(hotkey_context_H): print("FunctionSimSearch: Hotkey H unregistered.") del hotkey_context_H else:
def map(cls, key, callable): '''Map a specific `key` to a python `callable`.''' if key in cls.hotkey: idaapi.del_hotkey(cls.hotkey[key]) cls.hotkey[key] = res = idaapi.add_hotkey(key, callable) return res
from __future__ import print_function #--------------------------------------------------------------------- # This script demonstrates the usage of hotkeys. # # # Author: IDAPython team #--------------------------------------------------------------------- import idaapi def hotkey_pressed(): print("hotkey pressed!") try: hotkey_ctx if idaapi.del_hotkey(hotkey_ctx): print("Hotkey unregistered!") del hotkey_ctx else: print("Failed to delete hotkey!") except: hotkey_ctx = idaapi.add_hotkey("Shift-A", hotkey_pressed) if hotkey_ctx is None: print("Failed to register hotkey!") del hotkey_ctx else: print("Hotkey registered!")
def map(cls, key, callable): """Map the specified `key` combination to a python `callable` in IDA. If the provided `key` is being re-mapped due to the mapping already existing, then return the previous callable that it was assigned to. """ # First we'll normalize the hotkey that we were given, and convert it # back into a format that IDA can understand. This way we can prevent # users from giving us a sloppy hotkey combination that we won't be # able to search for in our cache. hotkey = cls.__normalize_key__(key) keystring = cls.__of_key__(hotkey) # The hotkey we normalized is now a tuple, so check to see if it's # already within our cache. If it is, then we need to unmap it prior to # re-creating the mapping. if hotkey in cls.__cache__: logging.warn( u"{:s}.map({!s}, {!r}) : Remapping the hotkey combination {!s} with the callable {!r}." .format('.'.join((__name__, cls.__name__)), internal.utils.string.repr(key), callable, internal.utils.string.repr(keystring), callable)) ctx, _ = cls.__cache__[hotkey] ok = idaapi.del_hotkey(ctx) if not ok: raise internal.exceptions.DisassemblerError( u"{:s}.map({!s}, {!r}) : Unable to remove the hotkey combination {!s} from the list of current keyboard mappings." .format('.'.join((__name__, cls.__name__)), internal.utils.string.repr(key), callable, internal.utils.string.repr(keystring))) # Pop the callable that was mapped out of the cache so that we can # return it to the user. _, res = cls.__cache__.pop(hotkey) # If the user is mapping a new key, then there's no callable to return. else: res = None # Define a closure that calls the user's callable as it seems that IDA's # hotkey functionality doesn't deal too well when the same callable is # mapped to different hotkeys. def closure(*args, **kwargs): return callable(*args, **kwargs) # Now we can add the hotkey to IDA using the closure that we generated. # XXX: I'm not sure if the key needs to be utf8 encoded or not ctx = idaapi.add_hotkey(keystring, closure) if not ctx: raise internal.exceptions.DisassemblerError( u"{:s}.map({!s}, {!r}) : Unable to map the callable {!r} to the hotkey combination {!s}." .format('.'.join((__name__, cls.__name__)), internal.utils.string.repr(key), callable, callable, internal.utils.string.repr(keystring))) # Last thing to do is to stash it in our cache with the user's callable # in order to keep track of it for removal. cls.__cache__[hotkey] = ctx, callable return res