Python idaapi.msg() Examples

The following are 30 code examples for showing how to use idaapi.msg(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module idaapi , or try the search function .

Example 1
Project: ida2pwntools   Author: anic   File: ida2pwntools.py    License: Apache License 2.0 6 votes vote down vote up
def prepare_debug_ui(self):
		if idaapi.is_debugger_on():
			idaapi.warning("[%s] the debugger is currently running" % PLUGNAME)
			return

		wd = WaitDialog()
		idaapi.msg("[%s] waiting...\n" % (PLUGNAME))
		wd.thread.start()
		wd.exec_()

		target_pid = wd.get_target_pid()
		if target_pid != -1:
			ida_dbg.attach_process(target_pid,-1)
			ida_dbg.wait_for_next_event(ida_dbg.WFNE_SUSP, -1)
			ida_dbg.continue_process()
		else:
			idaapi.msg("[%s] exit waiting\n" % (PLUGNAME)) 
Example 2
Project: Malware_Scripts   Author: sysopfb   File: find_functions.py    License: MIT License 6 votes vote down vote up
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) 
Example 3
Project: DIE   Author: ynvb   File: DebugAPI.py    License: MIT License 6 votes vote down vote up
def profile_stop(self):
        """
        Stop profiling the application and display results.
        @return:
        """
        # If profiling is activated:
        if self.pr is None:
            return False

        self.pr.disable()
        s = StringIO.StringIO()
        sortby = 'tottime'
        ps = pstats.Stats(self.pr, stream=s).sort_stats(sortby)
        ps.print_stats()

        idaapi.msg("%s\n" % (s.getvalue(), )) 
Example 4
Project: DIE   Author: ynvb   File: ValueViewEx.py    License: MIT License 6 votes vote down vote up
def clear_highlights(self):
        """
        Clear all highlighted items
        @return:
        """
        try:
            self.valueTreeView.collapseAll()

            for persistent_index in self.highligthed_items:
                if persistent_index.isValid():
                    item = self.valueModel.itemFromIndex(persistent_index)
                    item.setBackground(QtCore.Qt.white)
                    cur_font = item.font()
                    cur_font.setBold(False)
                    item.setFont(cur_font)

            self.highligthed_items = []

        except Exception as ex:
            idaapi.msg("Error while clearing highlights: %s\n" % ex)

###############################################################################################
#  Find Items
#
############################################################################################### 
Example 5
Project: DIE   Author: ynvb   File: ValueViewEx.py    License: MIT License 6 votes vote down vote up
def itemDoubleClickSlot(self, index):
        """
        TreeView DoubleClicked Slot.
        @param index: QModelIndex object of the clicked tree index item.
        @return:
        """

        func_context_list = index.data(role=DIE.UI.ContextList_Role)
        try:
            if self.function_view is None:
                self.function_view = DIE.UI.FunctionViewEx.get_view()

            if func_context_list is not None and len(func_context_list) > 0:
                if not self.function_view.isVisible():
                    self.function_view.Show()

                self.function_view.find_context_list(func_context_list)

        except Exception as ex:
            idaapi.msg("Error while loading function view: %s\n" % ex) 
Example 6
Project: DIE   Author: ynvb   File: FunctionViewEx.py    License: MIT License 6 votes vote down vote up
def clear_highlights(self):
        """
        Clear all highlighted items
        @return:
        """
        try:
            self.functionTreeView.collapseAll()

            for persistent_index in self.highligthed_items:
                if persistent_index.isValid():
                    item = self.functionModel.itemFromIndex(persistent_index)
                    item.setBackground(QtCore.Qt.white)
                    cur_font = item.font()
                    cur_font.setBold(False)
                    item.setFont(cur_font)

            self.highligthed_items = []

        except Exception as ex:
            idaapi.msg("Error while clearing highlights: %s\n" % ex)


###############################################################################################
#  Find Items. 
Example 7
Project: DIE   Author: ynvb   File: FunctionViewEx.py    License: MIT License 6 votes vote down vote up
def on_show_callgraph(self, function_context):

        if not isinstance(function_context, DIE.Lib.DIEDb.dbFunction_Context):
            if function_context is not None:
                raise ValueError("Wrong value sent to 'on_show_callgraph': %s. excpected dbFunction_Context" % function_context.__class__)
            else:
                raise ValueError("Wrong value sent to 'on_show_callgraph'")

        graph = nx.DiGraph()

        call_graph = self.die_db.get_call_graph_to(function_context)
        if not call_graph:
            idaapi.msg("No Execution Graph")
            return

        for ctxt_node in call_graph:
            (from_address, to_address) = ctxt_node
            graph.add_edge(from_address, to_address)

        function_name = self.die_db.get_function_name(function_context.function)
        viewer = sark.ui.NXGraph(graph, "Callgraph for {}".format(function_name), handler=sark.ui.AddressNodeHandler())
        viewer.Show()

        return 
Example 8
Project: DIE   Author: ynvb   File: DIE.py    License: MIT License 6 votes vote down vote up
def load_db(self):
        try:
            db_file = idc.AskFile(0, "*.ddb", "Load DIE Db File")
            if db_file is not None:
                self.die_db.load_db(db_file)

            if self.die_db is not None:
                self.show_db_details()

        except DbFileMismatch as mismatch:
            idaapi.msg("Error while loading DIE DB: %s\n" % mismatch)

        except Exception as ex:
            logging.exception("Error while loading DB: %s", ex)
            return False


    ###########################################################################
    # Function View 
Example 9
Project: DIE   Author: ynvb   File: DIE.py    License: MIT License 6 votes vote down vote up
def show_db_details(self):
        """
        Print DB details
        """
        (start_time,
         end_time,
         filename,
         num_of_functions,
         num_of_threads,
         numof_parsed_val) = self.die_db.get_run_info()

        idaapi.msg("Die DB Loaded.\n")
        idaapi.msg("Start Time: %s, End Time %s\n" % (ctime(start_time), ctime(end_time)))
        idaapi.msg("Functions: %d, Threads: %d\n" % (num_of_functions, num_of_threads))
        idaapi.msg("Parsed Values: %d\n" % numof_parsed_val)

    ###########################################################################
    # Mark\Unmark Execution Flow 
Example 10
Project: DIE   Author: ynvb   File: DIE.py    License: MIT License 6 votes vote down vote up
def show_cfg(self):
        """
        Show execution Call flow graph
        """
        cfg = self.die_db.get_call_graph_complete()
        graph = nx.DiGraph()

        if not cfg:
            idaapi.msg("No CFG to display")
            return

        for ctxt_node in cfg:
            (from_address, to_address) = ctxt_node
            graph.add_edge(from_address, to_address)

        viewer = sark.ui.NXGraph(graph, "Callgraph for {}".format("Exection CFG"), handler=sark.ui.AddressNodeHandler())
        viewer.Show() 
Example 11
Project: Sark   Author: tmr232   File: meaningful.py    License: MIT License 6 votes vote down vote up
def show_highlighted_function_meaningful():
    line = sark.Line()
    meaningful_displayed = False
    for xref in line.xrefs_from:
        try:
            if xref.type.is_flow:
                continue

            function = sark.Function(xref.to)
            show_meaningful_in_function(function)
            meaningful_displayed = True

        except sark.exceptions.SarkNoFunction:
            pass

    if not meaningful_displayed:
        idaapi.msg("[FunctionStrings] No function referenced by current line: 0x{:08X}.\n".format(idc.here())) 
Example 12
Project: prefix   Author: gaasedelen   File: ida_prefix.py    License: MIT License 6 votes vote down vote up
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 
Example 13
Project: prefix   Author: gaasedelen   File: ida_prefix.py    License: MIT License 6 votes vote down vote up
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
    #-------------------------------------------------------------------------- 
Example 14
Project: bap-ida-python   Author: BinaryAnalysisPlatform   File: plugin_loader_bap.py    License: MIT License 6 votes vote down vote up
def init(self):
        """Read directory and load as many plugins as possible."""
        self.plugins = []

        idaapi.msg("BAP Loader activated\n")

        bap.utils.run.check_and_configure_bap()

        plugin_path = os.path.dirname(bap.plugins.__file__)
        idaapi.msg("BAP> 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.msg('BAP> Loading {}\n'.format(plugin))
            self.plugins.append(idaapi.load_plugin(path))
        return idaapi.PLUGIN_KEEP 
Example 15
Project: idasec   Author: RobinDavid   File: idasec.py    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
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") 
Example 16
Project: ida2pwntools   Author: anic   File: ida2pwntools.py    License: Apache License 2.0 5 votes vote down vote up
def start_debug(self, text):
		idaapi.msg("[%s] %s\n" % (PLUGNAME, text))
		self.hide() 
Example 17
Project: ida2pwntools   Author: anic   File: ida2pwntools.py    License: Apache License 2.0 5 votes vote down vote up
def __call__(self):
		target_pid = -1

		if idaapi.is_debugger_on():
			idaapi.msg("[%s] the debugger is currently running\n" % PLUGNAME)
			return -1

		if not self.times%5:
			idaapi.msg("[%s] waiting for the process (%ds left)...\n" % \
				(PLUGNAME, self.times))

		filename = ida_nalt.get_root_filename()
		pis = ida_idd.procinfo_vec_t()
		ida_dbg.get_processes(pis)

		for proc in pis:
			proc_name = proc.name.split(" ")[1]
			idx = proc_name.rfind("/")

			if idx != -1:
				proc_name = proc_name[idx+1:]

			if filename == proc_name:
				target_pid = proc.pid
				break

		if target_pid != -1:
			idaapi.msg("[%s] found. start debug (PID: %d)\n" % (PLUGNAME, target_pid))
			ida_dbg.attach_process(target_pid, -1)
			ida_dbg.wait_for_next_event(ida_dbg.WFNE_SUSP, -1)
			ida_dbg.continue_process()
			return -1

		self.times -= 1
		return -1 if self.times == 0 else self.interval 
Example 18
Project: ida2pwntools   Author: anic   File: ida2pwntools.py    License: Apache License 2.0 5 votes vote down vote up
def term(self):
		idaapi.msg("[%s] terminated\n" % (PLUGNAME))
		self.menu.deleteLater() 
Example 19
Project: heap-viewer   Author: danigargu   File: misc.py    License: GNU General Public License v3.0 5 votes vote down vote up
def log(msg):
    idaapi.msg("[%s] %s\n" % (PLUGNAME, msg))

# -------------------------------------------------------------------------- 
Example 20
Project: heap-viewer   Author: danigargu   File: heap_viewer.py    License: GNU General Public License v3.0 5 votes vote down vote up
def term(self):
        idaapi.msg("[%s] terminated" % (PLUGNAME))

# ----------------------------------------------------------------------- 
Example 21
Project: DIE   Author: ynvb   File: DataPluginBase.py    License: MIT License 5 votes vote down vote up
def initPlugin(self, type_norm_callback=None):
        """
        Plguin Initialization
        @param type_norm_callback: a type name normalization callback function
        """
        idaapi.msg("Initializing plugin %s\n" % self.__class__)

        # Set type name normalization callback function
        if type_norm_callback is not None:
            self.typeName_norm_cb = type_norm_callback

        # Register supported types
        self.registerSupportedTypes() 
Example 22
Project: DIE   Author: ynvb   File: DbgImports.py    License: MIT License 5 votes vote down vote up
def print_debug_imports(self):
        """
        Print the debug imports
        """
        for dbgImp in self.rt_import_table:
            (module_name, ea, name, ord) = self.rt_import_table[dbgImp]
            idaapi.msg("ModuleName - %s,\t\tFunctionName - %s,\t\t Address in IAT - %s,\t\t Real address - %s\n" % (module_name, name, hex(ea), hex(dbgImp))) 
Example 23
Project: DIE   Author: ynvb   File: DataParser.py    License: MIT License 5 votes vote down vote up
def loadPlugins(self):
        """
        Load\Reload all plugins found in the plugin location.
        """
        self.logger.info("Loading Plugins from %s", self.pluginLocation)

        self.pManager.collectPlugins()

        all_plugins = self.pManager.getAllPlugins()
        if len(all_plugins) == 0:
            idaapi.msg("Warning - No Plugins were loaded!\n")
            self.logger.error("No plugins were loaded")

        for pluginInfo in all_plugins:

            # TODO: Validate plugins!
            self.logger.info("Loading plugin %s", pluginInfo.name)

            if pluginInfo.name == "headers":
                # headers is an illegal plugin name (see get_parser_list)
                continue

            # Set a type name normalizing function
            pluginInfo.plugin_object.initPlugin(self.typeName_norm)
            self.pManager.activatePluginByName(pluginInfo.name)

            # Add type to type_parser dict for quick lookups
            suported_types = pluginInfo.plugin_object.getSupportedTypes()

            if suported_types is not None:
                self.addTypeParser(suported_types, pluginInfo.plugin_object) 
Example 24
Project: DIE   Author: ynvb   File: ValueViewEx.py    License: MIT License 5 votes vote down vote up
def highlight_item(self, item):
        """
        Highlight a single item
        @param item: module item
        """
        try:
            item.setBackground(QtCore.Qt.yellow)
            cur_font = item.font()
            cur_font.setBold(True)
            item.setFont(cur_font)

        except Exception as ex:
            idaapi.msg("Error while highlighting item: %s\n" % ex) 
Example 25
Project: DIE   Author: ynvb   File: ValueViewEx.py    License: MIT License 5 votes vote down vote up
def highlight_item_row(self, item):
        """
        highlight the entire row containing a table item
        @param item: table item
        """
        try:
            if not item.index().isValid():
                return

            parent = item.parent()
            if parent is None:
                parent = item

            if not parent.hasChildren():
                self.highlight_item(parent)
                return

            row = item.row()
            column_num = parent.columnCount()

            for column in xrange(0, column_num):
                if self.valueModel.hasIndex(row, column, parent.index()):
                    cur_index = self.valueModel.index(row, column, parent.index())

                    self.highlight_item(self.valueModel.itemFromIndex(cur_index))
                    persistent_index = QtCore.QPersistentModelIndex(cur_index)
                    self.highligthed_items.append(persistent_index)

        except Exception as ex:
            idaapi.msg("Error while highlighting item row: %s\n" % ex) 
Example 26
Project: DIE   Author: ynvb   File: ValueViewEx.py    License: MIT License 5 votes vote down vote up
def find_value(self, value):
        """
        Find and highlight a function in current module
        @param value object (of type dbParsed_Value)
        """
        try:
            root_index = self.valueModel.index(0, 0)
            if not root_index.isValid():
                return

            matched_items = self.valueModel.match(root_index, DIE.UI.Value_Role, value.__hash__(), -1,
                                                  QtCore.Qt.MatchRecursive | QtCore.Qt.MatchExactly)

            for index in matched_items:
                if not index.isValid():
                    continue

                item = self.valueModel.itemFromIndex(index)
                self.valueTreeView.expand(index)
                self.valueTreeView.scrollTo(index, QtWidgets.QAbstractItemView.ScrollHint.PositionAtTop)
                self.highlight_item_row(item)

        except Exception as ex:
            idaapi.msg("Error while finding value: %s\n" % ex)


###############################################################################################
#  Slots
#
###############################################################################################


    #@QtCore.Slot(QtCore.QModelIndex) 
Example 27
Project: DIE   Author: ynvb   File: FunctionViewEx.py    License: MIT License 5 votes vote down vote up
def OnClose(self, form):
        idaapi.msg("Closed\n") 
Example 28
Project: DIE   Author: ynvb   File: FunctionViewEx.py    License: MIT License 5 votes vote down vote up
def _insert_thread_data(self, item, thread_id):
        """
        Insert thread_id data into a model item.
        The value found in thread_id argument will be delimited by the _make_thread_id_data function
        (e.g: thread_id 123 will become 't123t')
        the delimited value will then be appended to a string of concatenated (unique) child-item thread-ids
        (for example a item data value can be "a123aa5672aa11112a") for threads 123, 5672 and 111112
        @param item: the model item to add the data to
        @param thread_id: thread_id number
        @return: True if thread data was successfully added to item, otherwise False
        """
        try:
            current_thread_id = self._make_thread_id_data(thread_id)
            thread_data = item.data(role=DIE.UI.ThreadId_Role)


            if thread_data is None:
                item.setData(current_thread_id, role=DIE.UI.ThreadId_Role)

            elif not current_thread_id in thread_data:
                item.setData(thread_data + current_thread_id, role=DIE.UI.ThreadId_Role)

            return True

        except Exception as ex:
            idaapi.msg("Error while inserting thread data: %s\n" %ex)
            return False 
Example 29
Project: DIE   Author: ynvb   File: FunctionViewEx.py    License: MIT License 5 votes vote down vote up
def highlight_item(self, item):
        """
        Highlight a single item
        @param item: module item
        """
        try:
            item.setBackground(QtCore.Qt.yellow)
            cur_font = item.font()
            cur_font.setBold(True)
            item.setFont(cur_font)

        except Exception as ex:
            idaapi.msg("Error while highlighting item: %s\n" %ex) 
Example 30
Project: DIE   Author: ynvb   File: FunctionViewEx.py    License: MIT License 5 votes vote down vote up
def highlight_item_row(self, item):
        """
        highlight the entire row containing a table item
        @param item: table item
        """
        try:
            if not item.index().isValid():
                return

            parent = item.parent()
            if parent is None:
                parent = item

            if not parent.hasChildren():
                self.highlight_item(parent)
                return

            row = item.row()
            column_num = parent.columnCount()

            for column in xrange(0, column_num):
                if self.functionModel.hasIndex(row, column, parent.index()):
                    cur_index = self.functionModel.index(row, column, parent.index())

                    self.highlight_item(self.functionModel.itemFromIndex(cur_index))
                    persistent_index = QtCore.QPersistentModelIndex(cur_index)
                    self.highligthed_items.append(persistent_index)

        except Exception as ex:
            idaapi.msg("Error while highlighting item row: %s\n" % ex)