def install_hotkey(item): global INSTALLED_HOTKEYS hotkey, func = item handler = ida_kernwin.add_hotkey(hotkey, func) if handler: INSTALLED_HOTKEYS[handler] = (hotkey, func) return handler != None
def install_hotkey(self): ida_kernwin.add_hotkey(self.TOGGLE_HOTKEY, self.toggle_hooks)
def sr_main(): global sr if sr: del sr sr = None print("Stopped recording") else: w = ida_kernwin.get_current_widget() title = "IDA View-A" if w: title = ida_kernwin.get_widget_title(w) title = ida_kernwin.ask_str( title, 0, "Please specify title of widget to capture") if title: path = ida_kernwin.ask_str("", ida_kernwin.HIST_DIR, "Please specify destination path") if path and os.path.exists(path): sr = screen_record_t(title, path) print("Started recording") try: sr ida_kernwin.info("Already installed. Press %s to start/stop recording." % HOTKEY) except: sr = None sr_hotkey = ida_kernwin.add_hotkey(HOTKEY, sr_main) print("Press %s to start/stop recording" % HOTKEY)
def launch_depgraph(): global graphs, comments, sol_nb, settings, addr, ir_arch # Init machine = guess_machine() mn, dis_engine, ira = machine.mn, machine.dis_engine, machine.ira bs = bin_stream_ida() mdis = dis_engine(bs, dont_dis_nulstart_bloc=True) ir_arch = ira(mdis.symbol_pool) # Populate symbols with ida names for ad, name in idautils.Names(): if name is None: continue mdis.symbol_pool.add_label(name, ad) # Get the current function addr = idc.ScreenEA() func = ida_funcs.get_func(addr) blocks = mdis.dis_multiblock(func.startEA) # Generate IR for block in blocks: ir_arch.add_block(block) # Get settings settings = depGraphSettingsForm(ir_arch) settings.Execute() label, elements, line_nb = settings.label, settings.elements, settings.line_nb # Simplify affectations for irb in ir_arch.blocks.values(): irs = [] fix_stack = irb.label.offset is not None and settings.unalias_stack for assignblk in irb.irs: if fix_stack: stk_high = m2_expr.ExprInt(idc.GetSpd(assignblk.instr.offset), ir_arch.sp.size) fix_dct = {ir_arch.sp: mn.regs.regs_init[ir_arch.sp] + stk_high} new_assignblk = {} for dst, src in assignblk.iteritems(): if fix_stack: src = src.replace_expr(fix_dct) if dst != ir_arch.sp: dst = dst.replace_expr(fix_dct) dst, src = expr_simp(dst), expr_simp(src) new_assignblk[dst] = src irs.append(AssignBlock(new_assignblk, instr=assignblk.instr)) ir_arch.blocks[irb.label] = IRBlock(irb.label, irs) # Get dependency graphs dg = settings.depgraph graphs = dg.get(label, elements, line_nb, set([ir_arch.symbol_pool.getby_offset(func.startEA)])) # Display the result comments = {} sol_nb = 0 # Register and launch ida_kernwin.add_hotkey("Shift-N", next_element) treat_element()
def launch_depgraph(): global graphs, comments, sol_nb, settings, addr, ir_arch, ircfg # Get the current function addr = idc.ScreenEA() func = ida_funcs.get_func(addr) # Init machine = guess_machine(addr=func.startEA) mn, dis_engine, ira = machine.mn, machine.dis_engine, machine.ira bs = bin_stream_ida() mdis = dis_engine(bs, dont_dis_nulstart_bloc=True) ir_arch = ira(mdis.loc_db) # Populate symbols with ida names for ad, name in idautils.Names(): if name is None: continue mdis.loc_db.add_location(name, ad) asmcfg = mdis.dis_multiblock(func.startEA) # Generate IR ircfg = ir_arch.new_ircfg_from_asmcfg(asmcfg) # Get settings settings = depGraphSettingsForm(ir_arch, ircfg) settings.Execute() loc_key, elements, line_nb = settings.loc_key, settings.elements, settings.line_nb # Simplify affectations for irb in ircfg.blocks.values(): irs = [] offset = ir_arch.loc_db.get_location_offset(irb.loc_key) fix_stack = offset is not None and settings.unalias_stack for assignblk in irb: if fix_stack: stk_high = m2_expr.ExprInt(idc.GetSpd(assignblk.instr.offset), ir_arch.sp.size) fix_dct = {ir_arch.sp: mn.regs.regs_init[ir_arch.sp] + stk_high} new_assignblk = {} for dst, src in assignblk.iteritems(): if fix_stack: src = src.replace_expr(fix_dct) if dst != ir_arch.sp: dst = dst.replace_expr(fix_dct) dst, src = expr_simp(dst), expr_simp(src) new_assignblk[dst] = src irs.append(AssignBlock(new_assignblk, instr=assignblk.instr)) ircfg.blocks[irb.loc_key] = IRBlock(irb.loc_key, irs) # Get dependency graphs dg = settings.depgraph graphs = dg.get(loc_key, elements, line_nb, set([ir_arch.loc_db.get_offset_location(func.startEA)])) # Display the result comments = {} sol_nb = 0 # Register and launch ida_kernwin.add_hotkey("Shift-N", next_element) treat_element()
def install_hotkey(self): if not ida_kernwin.add_hotkey(self.TOGGLE_HOTKEY, self.toggle_hooks): log.warn("Failed to add hotkey %s", self.TOGGLE_HOTKEY) return False return True
It imports `color.py`, `nop.py` and `p.py`, defines an `init()` method and registers the `Ctrl+Enter` hotkey to it.""" import sys import ida_kernwin import ida_loader import idaapi # I like to store my idapython scripts on the Desktop sys.path.insert(1, r"C:\Users\user\Desktop\idapython") import color import nop import p import decode def init(): """It colors the database, loads capa explorer (running its analysis) and reactivate the `IDA View-A` view. Call this method after IDA initial autoanalysis has been finished.""" color.apply() ida_loader.load_and_run_plugin("capa_explorer", 1) # 1 = analyze widget = idaapi.find_widget("IDA View-A") if widget: idaapi.activate_widget(widget, True) print("ANA: Initialization finished") ida_kernwin.add_hotkey("Ctrl+Enter", init) print("ANA: Registered 'Ctrl+Enter' hotkey to init()")
callback. keywords: actions see_also: actions """ from __future__ import print_function import ida_kernwin def hotkey_pressed(): print("hotkey pressed!") try: hotkey_ctx if ida_kernwin.del_hotkey(hotkey_ctx): print("Hotkey unregistered!") del hotkey_ctx else: print("Failed to delete hotkey!") except: hotkey_ctx = ida_kernwin.add_hotkey("Shift-A", hotkey_pressed) if hotkey_ctx is None: print("Failed to register hotkey!") del hotkey_ctx else: print("Hotkey registered!")
def launch_depgraph(): global graphs, comments, sol_nb, settings, addr, ir_arch, ircfg # Get the current function addr = idc.get_screen_ea() func = ida_funcs.get_func(addr) # Init machine = guess_machine(addr=func.start_ea) mn, dis_engine, ira = machine.mn, machine.dis_engine, machine.ira bs = bin_stream_ida() mdis = dis_engine(bs, dont_dis_nulstart_bloc=True) ir_arch = ira(mdis.loc_db) # Populate symbols with ida names for ad, name in idautils.Names(): if name is None: continue mdis.loc_db.add_location(name, ad) asmcfg = mdis.dis_multiblock(func.start_ea) # Generate IR ircfg = ir_arch.new_ircfg_from_asmcfg(asmcfg) # Get settings settings = depGraphSettingsForm(ir_arch, ircfg, mn) settings.Execute() loc_key, elements, line_nb = settings.loc_key, settings.elements, settings.line_nb # Simplify assignments for irb in list(viewvalues(ircfg.blocks)): irs = [] offset = ir_arch.loc_db.get_location_offset(irb.loc_key) fix_stack = offset is not None and settings.unalias_stack for assignblk in irb: if fix_stack: stk_high = m2_expr.ExprInt(idc.get_spd(assignblk.instr.offset), ir_arch.sp.size) fix_dct = {ir_arch.sp: mn.regs.regs_init[ir_arch.sp] + stk_high} new_assignblk = {} for dst, src in viewitems(assignblk): if fix_stack: src = src.replace_expr(fix_dct) if dst != ir_arch.sp: dst = dst.replace_expr(fix_dct) dst, src = expr_simp(dst), expr_simp(src) new_assignblk[dst] = src irs.append(AssignBlock(new_assignblk, instr=assignblk.instr)) ircfg.blocks[irb.loc_key] = IRBlock(irb.loc_key, irs) # Get dependency graphs dg = settings.depgraph graphs = dg.get(loc_key, elements, line_nb, set([ir_arch.loc_db.get_offset_location(func.start_ea)])) # Display the result comments = {} sol_nb = 0 # Register and launch ida_kernwin.add_hotkey("Shift-N", next_element) treat_element()
self.transform = True """workaround! widget.render() causes widget to be repainted. In order to deal with this situation, we'll issue another repaint() and transform the widget""" self.target.repaint() elif event.type() in [QtCore.QEvent.Close, QtCore.QEvent.Hide]: self.die() return QtCore.QObject.eventFilter(self, receiver, event) def coffee_main(): global coffee if coffee and not coffee.is_dead(): coffee.die() coffee = None return coffee = painter_t() ida_kernwin.msg("Caffeinated\n") try: coffee ida_kernwin.info("Already installed. Press %s" % HOTKEY) except: coffee = None print("Press %s for coffee overload" % HOTKEY) ida_kernwin.add_hotkey(HOTKEY, coffee_main)
def run(self, arg): for keystroke, method in self.hotkeys: ida_kernwin.del_hotkey(keystroke) ida_kernwin.add_hotkey(keystroke, method)
pp = None return w = ida_kernwin.get_current_widget() title = "IDA View-A" if w: title = ida_kernwin.get_widget_title(w) title = ida_kernwin.ask_str(title, 0, "Please specify title of widget") if title: path = ida_kernwin.ask_str( "", ida_kernwin.HIST_DIR, "Please specify path containing png files to play back") if path and os.path.exists(path): files = find_files(path, "*.png") print("found %d files" % len(files)) if len(files): interval = ida_kernwin.ask_long( 100, "Please specify timer interval") if interval: pp = png_player_t(title, files, interval=interval) print("PNGs playing in widget %s" % title) try: pp ida_kernwin.info("Already installed. Press %s to start/stop playback." % HOTKEY) except: pp = None print("Press %s to start/stop playing PNG files" % HOTKEY) ida_kernwin.add_hotkey(HOTKEY, pp_main)
import webbrowser import ida_kernwin as kw __author__ = "https://github.com/patois" def arachno(): """gets textual representation of currently selected identifier from any current IDA view, opens a new browser tab and googles for it """ r = kw.get_highlight(kw.get_current_viewer()) if r: webbrowser.open("https://google.com/search?q=%s" % r[0], new=2) kw.add_hotkey("Ctrl-Shift-F", arachno)
import webbrowser import ida_kernwin as kw def google_highlighted(): """gets textual representation of currently selected identifier from any current IDA view, opens a new browser tab and googles for it cerdit: https://github.com/patois """ r = kw.get_highlight(kw.get_current_viewer()) if r: webbrowser.open("https://google.com/search?q=%s" % r[0], new=2) kw.add_hotkey("Ctrl-Shift-F", google_highlighted)
"""Provides a `nop()` method and registers the `Ctrl+N` hotkey to it.""" import ida_bytes import ida_kernwin import idaapi import idc def nop(): """Nops-out the current instruction and advance the cursor to the next instruction.""" ea = idaapi.get_screen_ea() num_bytes = idc.get_item_size(ea) for i in range(num_bytes): ida_bytes.patch_byte(ea, 0x90) ea += 1 ida_kernwin.refresh_idaview_anyway() ida_kernwin.jumpto(ea) ida_kernwin.add_hotkey("Ctrl+N", nop) print("ANA nop: Registered 'Ctrl+N' hotkey to nop()")