def add_hook(self): emulator = self.parent().view.session_data['emulator'] ctx = UIContext.activeContext() content = ctx.contentActionHandler() action_context = content.actionContext() llil = action_context.lowLevelILFunction instr_index = action_context.instrIndex if None in (llil, instr_index) or instr_index == 0xffffffffffffffff: log.log_alert('LLIL Function/Instruction not selected!') return add_hook(emulator, llil[instr_index])
def add_hook(emulator, instruction): ctx = UIContext.activeContext() handler = ctx.globalActions() hook_options = [ a for a in handler.getAllValidActions() if "Snippets\\" in a and "emulator" in a.lower() ] snippets = ChoiceField("Snippets:", hook_options) get_form_input([snippets], "Add Hook") choice = hook_options[snippets.result] emulator.add_hook(instruction, choice) instruction.function.source_function.set_auto_instr_highlight( instruction.address, HighlightStandardColor.BlackHighlightColor )
def executeSnippet(code, description): #Get UI context, try currently selected otherwise default to the first one if the snippet widget is selected. ctx = UIContext.activeContext() dummycontext = {'binaryView': None, 'address': None, 'function': None, 'token': None, 'lowLevelILFunction': None, 'mediumLevelILFunction': None} if not ctx: ctx = UIContext.allContexts()[0] if not ctx: #There is no tab open at all but we still want other snippest to run that don't rely on context. context = namedtuple("context", dummycontext.keys())(*dummycontext.values()) else: handler = ctx.contentActionHandler() if handler: context = handler.actionContext() else: context = namedtuple("context", dummycontext.keys())(*dummycontext.values()) snippetGlobals = setupGlobals(context) SnippetTask(code, snippetGlobals, context, snippetName=description).start()