我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用idaapi.msg()。
def init(self): """Read directory and load as many plugins as possible.""" import os import bap.plugins import bap.utils.run import idaapi idaapi.msg("BAP Loader activated\n") bap.utils.run.check_and_configure_bap() plugin_path = os.path.dirname(bap.plugins.__file__) idaapi.msg("Loading plugins from {}\n".format(plugin_path)) for plugin in sorted(os.listdir(plugin_path)): path = os.path.join(plugin_path, plugin) if not plugin.endswith('.py') or plugin.startswith('__'): continue # Skip non-plugins idaapi.load_plugin(path) return idaapi.PLUGIN_SKIP # The loader will be called whenever needed
def init(self): """ This is called by IDA when it is loading the plugin. """ # initialize the menu actions our plugin will inject self._init_action_bulk() self._init_action_clear() self._init_action_recursive() # initialize plugin hooks self._init_hooks() # done idaapi.msg("%s %s initialized...\n" % (self.wanted_name, VERSION)) return idaapi.PLUGIN_KEEP
def term(self): """ This is called by IDA when it is unloading the plugin. """ # unhook our plugin hooks self._hooks.unhook() # unregister our actions & free their resources self._del_action_bulk() self._del_action_clear() self._del_action_recursive() # done idaapi.msg("%s terminated...\n" % self.wanted_name) #-------------------------------------------------------------------------- # Plugin Hooks #--------------------------------------------------------------------------
def activate(self, ctx): ea = ScreenEA() str_id = idaapi.get_highlighted_identifier() if str_id[-1] == 'h': addr = int(str_id[:-1], 16) elif str_id[-1] == 'o': addr = int(str_id[:-1], 8) elif str_id[-1] == 'b': addr = int(str_id[:-1], 2) else: addr = int(str_id) temp = self.find_nearest_function(addr) if temp != None: n = GetFunctionName(ea) n_addr = int(n[4:],16) idaapi.msg(temp) idc.MakeName(n_addr, temp)
def term(self): if not hasattr(self, '_hooks'): return # unhook our plugin hooks self._hooks.unhook() # unregister our actions & free their resources self._del_action_bulk() self._del_action_copy() # done idaapi.msg("%s terminated...\n" % self.wanted_name) #-------------------------------------------------------------------------- # Plugin Hooks #--------------------------------------------------------------------------
def run(self, arg): """ This is called by IDA when this file is loaded as a script. """ idaapi.msg("%s cannot be run as a script.\n" % self.wanted_name)
def Message(msg): """ Display a message in the message window @param msg: message to print (formatting is done in Python) This function can be used to debug IDC scripts """ idaapi.msg(msg)
def Warning(msg): """ Display a message in a message box @param msg: message to print (formatting is done in Python) This function can be used to debug IDC scripts The user will be able to hide messages if they appear twice in a row on the screen """ idaapi.warning(msg)
def main(): idaapi.msg("Loading IDASEC\n") global IDASEC try: IDASEC IDASEC.OnClose(IDASEC) idaapi.msg("reloading IDASec\n") IDASEC = IDASecForm() return except Exception: IDASEC = IDASecForm() IDASEC.Show("Idasec")
def init(self): # just go when we have hexrays if not idaapi.init_hexrays_plugin(): return idaapi.PLUGIN_SKIP # initialize the menu actions our plugin will inject self._init_action_bulk() self._init_action_copy() # initialize plugin hooks self._init_hooks() # done idaapi.msg("%s %s initialized...\n" % (self.wanted_name, VERSION)) return idaapi.PLUGIN_KEEP
def run(self, arg): idaapi.msg("%s cannot be run as a script.\n" % self.wanted_name)
def _init_hooks(self): self._hooks = Hooks() self._hooks.hook() if not idaapi.init_hexrays_plugin(): idaapi.msg("[ERROR] Failed to initialize Hex-Rays SDK") else: idaapi.install_hexrays_callback(self._hooks.hxe_callback) #-------------------------------------------------------------------------- # IDA Actions #--------------------------------------------------------------------------
def copy_function_cursor(): # get the function reference under the user cursor (if there is one) target = get_cursor_func_ref() if target == idaapi.BADADDR: return # execute the recursive prefix functionPtrDef = copy_function(target) copy_to_clip(functionPtrDef) idaapi.msg(functionPtrDef + "\n")
def bulk_function(): functionPtrs = "" for func_name in get_selected_funcs(): functionPtrDef = copy_function(idc.LocByName(func_name)) functionPtrs = functionPtrs + functionPtrDef + "\n" copy_to_clip(functionPtrs) idaapi.msg(functionPtrs)
def init(self): idaapi.msg('devirtualize_plugin:init\n') if not idaapi.init_hexrays_plugin(): idaapi.msg('No decompiler. Skipping\n') return idaapi.PLUGIN_SKIP return idaapi.PLUGIN_OK
def run(self, arg): import traceback try: idaapi.msg('devirtualize_plugin:starting\n') idaapi.require('devirtualize') idaapi.require('devirtualize.type') idaapi.require('devirtualize.view') idaapi.require('devirtualize.graph') devirtualize.type.build_types() devirtualize.view.register_vptr_translator() devirtualize.graph.register_actions() idaapi.msg('devirtualize_plugin:finished\n') except: idaapi.msg(traceback.format_exc())
def recursive_prefix(addr): """ Recursively prefix a function tree with a user defined string. """ func_addr = idaapi.get_name_ea(idaapi.BADADDR, idaapi.get_func_name(addr)) if func_addr == idaapi.BADADDR: idaapi.msg("Prefix: 0x%08X does not belong to a defined function\n" % addr) return # NOTE / COMPAT: # prompt the user for a prefix to apply to the selected functions if using_ida7api: tag = idaapi.ask_str(PREFIX_DEFAULT, 0, "Function Tag") else: tag = idaapi.askstr(0, PREFIX_DEFAULT, "Function Tag") # the user closed the window... ignore if tag == None: return # the user put a blank string and hit 'okay'... notify & ignore elif tag == '': idaapi.warning("[ERROR] Tag cannot be empty [ERROR]") return # recursively collect all the functions called by this function nodes_xref_down = graph_down(func_addr, path=set([])) # graph_down returns the int address needs to be converted tmp = [] tmp1 = '' for func_addr in nodes_xref_down: tmp1 = idaapi.get_func_name(func_addr) if tmp1: tmp.append(tmp1) nodes_xref_down = tmp # prefix the tree of functions for rename in nodes_xref_down: func_addr = idaapi.get_name_ea(idaapi.BADADDR, rename) if tag not in rename: idaapi.set_name(func_addr,'%s%s%s' % (str(tag), PREFIX_SEPARATOR, rename), idaapi.SN_NOWARN) # refresh the IDA views refresh_views()