Python idaapi.warning() Examples

The following are 30 code examples of idaapi.warning(). 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 also want to check out all available functions/classes of the module idaapi , or try the search function .
Example #1
Source File: registers.py    From deREferencing with GNU General Public License v3.0 6 votes vote down vote up
def switch_value(self):
        lineno = self.GetLineNo()
        if lineno > len(dbg.registers.flags):
            return

        line = self.GetLine(lineno)
        line = idaapi.tag_remove(line[0])
        flag = line[:4].strip()
        new_val = not self.flag_vals[flag]

        rc = idc.set_reg_value(int(new_val), flag)
        if not rc:
            idaapi.warning("Unable to update the register value")
            return

        self.parent.reload_view() 
Example #2
Source File: lib.py    From GhIDA with Apache License 2.0 6 votes vote down vote up
def ghida_finalize(use_ghidra_server, ghidra_server_url):
    """
    Remove temporary files and
    checkout from Ghidraaas server.
    """
    try:
        remove_temporary_files()

        if use_ghidra_server:
            ghidraaas_checkout(ghidra_server_url)

    except Exception:
        print("GhIDA:: [!] Finalization error")
        idaapi.warning("GhIDA finalization error")


# ------------------------------------------------------------
#   GHIDRA LOCAL
# ------------------------------------------------------------ 
Example #3
Source File: registers.py    From deREferencing with GNU General Public License v3.0 6 votes vote down vote up
def modify_value(self):
        reg = self.get_selected_reg()
        if not reg:
            return

        reg_val = idc.get_reg_value(reg)
        b = idaapi.ask_str("0x%X" % reg_val, 0, "Modify register value")
        if b is not None:
            try:
                value = int(idaapi.str2ea(b))
                idc.set_reg_value(value, reg)
                self.reload_info()

                if reg == dbg.registers.flags:
                    self.reload_flags_view()
            except:
                idaapi.warning("Invalid expression") 
Example #4
Source File: ida2pwntools.py    From ida2pwntools with 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 #5
Source File: tracer.py    From heap-viewer with GNU General Public License v3.0 6 votes vote down vote up
def btn_villoc_on_click(self):
        if self.tbl_traced_chunks.rowCount() == 0:
            idaapi.warning("Empty table")
            return

        try:
            villoc.Block.header = config.ptr_size*2
            villoc.Block.round  = self.parent.heap.malloc_alignment
            villoc.Block.minsz  = self.parent.heap.min_chunk_size

            result = self.dump_table_for_villoc()
            html = villoc.build_html(result)

            h, filename = tempfile.mkstemp(suffix='.html')

            with open(filename, 'wb') as f:
                f.write(html.encode("utf-8"))

            url = QtCore.QUrl.fromLocalFile(filename)
            QtGui.QDesktopServices.openUrl(url)

        except Exception as e:
            idaapi.warning(traceback.format_exc()) 
Example #6
Source File: config.py    From heap-viewer with GNU General Public License v3.0 6 votes vote down vote up
def update_config(self):
        try:
            config.start_tracing_at_startup = self.opt1.isChecked()
            config.stop_during_tracing = self.opt2.isChecked()
            config.detect_double_frees_and_overlaps = self.opt3.isChecked()
            config.filter_library_calls = self.opt4.isChecked()
            config.hexdump_limit = int(self.t_hexdump_limit.text())
            config.libc_offsets = self.get_offsets()

            config.save()
            idaapi.info("Config updated")

            self.parent.init_heap()
            self.parent.reload_gui_info()

        except Exception as e:
            idaapi.warning("ERROR: " + str(e)) 
Example #7
Source File: chunk.py    From heap-viewer with GNU General Public License v3.0 6 votes vote down vote up
def next_on_click(self):
        chunk_addr = self.get_chunk_address()
        if chunk_addr is None:
            idaapi.warning("Invalid address / expression")
            return
        try:
            chunk = self.heap.get_chunk(chunk_addr)
            chunk_size = chunk.norm_size
            next_addr = chunk_addr+chunk_size
            if idaapi.is_loaded(next_addr):
                self.show_chunk("%#x" % next_addr)
            else:
                idaapi.warning("%#x: next chunk (%#x) is not loaded" % \
                    (chunk_addr, next_addr))

        except Exception as e:
            idaapi.warning("ERROR: " + str(e)) 
Example #8
Source File: ida_prefix.py    From prefix with MIT License 5 votes vote down vote up
def bulk_prefix():
    """
    Prefix the Functions window selection with a user defined string.
    """

    # prompt the user for a prefix to apply to the selected functions
    tag = idaapi.ask_str(PREFIX_DEFAULT, 0, "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

    #
    # loop through all the functions selected in the 'Functions window' and
    # apply the user defined prefix tag to each one.
    #

    for func_name in get_selected_funcs():

        # ignore functions that already have the specified prefix applied
        if func_name.startswith(tag):
            continue

        # apply the user defined prefix to the function (rename it)
        new_name  = '%s%s%s' % (str(tag), PREFIX_SEPARATOR, func_name)
        func_addr = idaapi.get_name_ea(idaapi.BADADDR, func_name)
        idaapi.set_name(func_addr, new_name, idaapi.SN_NOWARN)

    # refresh the IDA views
    refresh_views() 
Example #9
Source File: heap_viewer.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def run(self, arg=0):
        try:
            if "ELF" not in idaapi.get_file_type_name():
                raise Exception("Executable must be ELF fomat")

            if not idaapi.is_debugger_on() or not is_process_suspended():
                raise Exception("The debugger must be active and suspended before using this plugin")

            f = plugin_gui.HeapPluginForm()
            f.Show()

        except Exception as e:
            idaapi.warning("[%s] %s" % (PLUGNAME, str(e))) 
Example #10
Source File: ida_prefix.py    From prefix with MIT License 5 votes vote down vote up
def get_selected_funcs():
    """
    Return the list of function names selected in the Functions window.
    """
    import sip
    twidget = idaapi.find_widget("Functions window")
    widget  = sip.wrapinstance(int(twidget), QtWidgets.QWidget)

    # TODO: test this
    if not widget:
        idaapi.warning("Unable to find 'Functions window'")
        return

    #
    # locate the table widget within the Functions window that actually holds
    # all the visible function metadata
    #

    table = widget.findChild(QtWidgets.QTableView)

    #
    # scrape the selected function names from the Functions window table
    #

    selected_funcs = [str(s.data()) for s in table.selectionModel().selectedRows()]

    #
    # re-map the scraped names as they appear in the function table, to their true
    # names as they are saved in the IDB. See the match_funcs(...) function
    # comment for more details
    #

    return match_funcs(selected_funcs) 
Example #11
Source File: ida_loader.py    From lighthouse with MIT License 5 votes vote down vote up
def run(self, arg):
        """
        This is called by IDA when this file is loaded as a script.
        """
        idaapi.warning("Lighthouse cannot be run as a script in IDA.") 
Example #12
Source File: ida_api.py    From lighthouse with MIT License 5 votes vote down vote up
def warning(self, text):
        super(IDACoreAPI, self).warning(text) 
Example #13
Source File: ida_api.py    From lighthouse with MIT License 5 votes vote down vote up
def show_dockable(self, dockable_name):
        try:
            make_dockable = self._dockable_factory[dockable_name]
        except KeyError:
            return False

        parent, dctx = None, None # not used for IDA's integration
        widget = make_dockable(dockable_name, parent, dctx)

        # get the original twidget, so we can use it with the IDA API's
        #twidget = idaapi.TWidget__from_ptrval__(widget) NOTE: IDA 7.2+ only...
        twidget = self._dockable_widgets.pop(dockable_name)
        if not twidget:
            self.warning("Could not open dockable window, because its reference is gone?!?")
            return

        # show the dockable widget
        flags = idaapi.PluginForm.WOPN_TAB | idaapi.PluginForm.WOPN_RESTORE | idaapi.PluginForm.WOPN_PERSIST
        idaapi.display_widget(twidget, flags)
        widget.visible = True

        # attempt to 'dock' the widget in a reasonable location
        for target in ["IDA View-A", "Pseudocode-A"]:
            dwidget = idaapi.find_widget(target)
            if dwidget:
                idaapi.set_dock_pos(dockable_name, 'IDA View-A', idaapi.DP_RIGHT)
                break 
Example #14
Source File: casc_plugin.py    From CASC with GNU General Public License v2.0 5 votes vote down vote up
def _add_signature(self, sig):
        signature = parse_signature(sig)
        if signature is None:
            idaapi.warning("Error parsing signature")
            return False
        signature.target_type = 0 #Don't check for PE header
        item = QtWidgets.QListWidgetItem(sig)
        item.parsed_signature = signature
        item.yara_rule = self.yara_scanner.compile(self.yara_scanner.convert(signature))
        if isinstance(signature, LdbSignature):
            pass
        self.signatures_list.addItem(item)
        return True 
Example #15
Source File: custom.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def jump_in_disassembly(self):
        ea = self.get_current_expr_ea()
        if not ea or not idaapi.is_loaded(ea):
            idaapi.warning("Unable to resolve current expression\n")
            return

        widget = self.find_disass_view()
        if not widget:
            idaapi.warning("Unable to find disassembly view")
            return

        self.jumpto_in_view(widget, ea) 
Example #16
Source File: custom.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def jump_in_new_window(self):
        ea = self.get_current_expr_ea()
        if not ea or not idaapi.is_loaded(ea):
            return
        
        window_name = "D-0x%x" % ea
        widget = idaapi.open_disasm_window(window_name)
        if widget:
            self.jumpto_in_view(widget, ea)
        else:
            idaapi.warning("Unable to create the new window") 
Example #17
Source File: custom.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def jump_in_hex(self):
        ea = self.get_current_expr_ea()
        if not ea or not idaapi.is_loaded(ea):
            idaapi.warning("Unable to resolve current expression\n")

        widget = self.find_hex_view()
        if not widget:
            idaapi.warning("Unable to find hex view")
            return
        self.jumpto_in_view(widget, ea) 
Example #18
Source File: stack.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def jump_to(self):
        current = self.base_expr if self.base_expr is not None else ""
        b = idaapi.ask_str(current, 0, "Sync with")
        if b and len(b) > 0:
            try:
                self.base_expr = b
                self.reload_info()
            except:
                idaapi.warning("Invalid expression")
        else:
            self.base_addr = None 
Example #19
Source File: stack.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def set_stack_entries(self):
        value = idaapi.ask_long(config.n_stack_entries, "Set the number of stack entries to show")
        if value is not None:
            if value <= 0:
                idaapi.warning("Negative values are not allowed")
                return False
            config.n_stack_entries = value
            self.reload_info()
            return True
        return False 
Example #20
Source File: stack.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def reload_info(self):
        if not dbg.is_process_suspended():
            return False

        base_addr = None
        if self.base_expr is None:
            base_addr = idc.get_reg_value(dbg.registers.stack)
        else:
            base_addr = idaapi.str2ea(self.base_expr)
            if base_addr == idc.BADADDR:
                idaapi.warning("Invalid base expr: %s" % self.base_expr)
                return False

            if not idaapi.is_loaded(base_addr):
                idaapi.warning("Memory address is not loaded: $#x" % base_addr)
                return False

        self.ClearLines()
        dbg.set_thread_info()

        try:
            segm_end = idc.get_segm_end(base_addr)
            n_entries = config.n_stack_entries or ((segm_end-base_addr) // dbg.ptr_size)

            for i in range(n_entries):
                offset = i * dbg.ptr_size
                ptr = base_addr + offset

                if not idaapi.is_loaded(ptr):
                    break

                value = dbg.get_ptr(ptr)
                self.add_line("%02d:%04X  %s" % (i, offset, self.parse_value(ptr)))

        except Exception as e:
            idaapi.warning(str(e))
            return False
        return True 
Example #21
Source File: registers.py    From deREferencing with GNU General Public License v3.0 5 votes vote down vote up
def set_deref_levels(self):
        value = idaapi.ask_long(config.max_deref_levels, "Set current dereferencing levels to show")
        if value is not None:
            if value < 0:
                idaapi.warning("Negative values are not allowed")
                return False

            if value > config.deref_limit:
                idaapi.warning("Value should not exceed the dereferencing limit: %d" % config.deref_limit)
                return False

            config.max_deref_levels = value
            self.reload_info()
            return True
        return False 
Example #22
Source File: ida_prefix.py    From prefix with MIT License 5 votes vote down vote up
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

    # prompt the user for a prefix to apply to the selected functions
    tag = idaapi.ask_str(PREFIX_DEFAULT, 0, "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() 
Example #23
Source File: magic.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def show_struct_on_click(self):
        try:
            address = int(self.t_struct_addr.text(), 16)
            self.show_struct(address, "_IO_FILE")
        except:
            idaapi.warning("ERROR: Invalid address") 
Example #24
Source File: chunk.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def edit_chunk_on_click(self):
        chunk_addr = self.get_chunk_address()
        if chunk_addr is None:
            idaapi.warning("Invalid address / expression")
            return

        w = ChunkEditor(chunk_addr, self)
        if w.exec_() == 1:
            self.view_chunk_info()

# ----------------------------------------------------------------------- 
Example #25
Source File: chunk.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def prev_on_click(self):
        chunk_addr = self.get_chunk_address()
        if chunk_addr is None:
            idaapi.warning("Invalid address / expression")
            return
        try:
            chunk = self.heap.get_chunk(chunk_addr)
            if chunk.prev_inuse == 0:
                prev_addr = chunk_addr-chunk.prev_size
                self.show_chunk("%#x" % prev_addr)
            else:
                idaapi.warning("%#x: prev_chunk in use" % chunk_addr)
        except Exception as e:
            idaapi.warning("ERROR: " + str(e)) 
Example #26
Source File: chunk.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def jump_on_click(self):
        chunk_addr = self.get_chunk_address()
        if chunk_addr is None:
            idaapi.warning("Invalid address / expression")
            return
        idc.jumpto(chunk_addr) 
Example #27
Source File: tracer.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def btn_dump_trace_on_click(self):
        if self.tbl_traced_chunks.rowCount() == 0:
            idaapi.warning("Empty table")
            return

        filename = AskFile(1, "*.csv", "Select the file to store tracing results")
        if not filename:
            return            
        try:
            result = self.tbl_traced_chunks.dump_table_as_csv()
            with open(filename, 'wb') as f:
                f.write(result)

        except Exception as e:
            idaapi.warning(traceback.format_exc()) 
Example #28
Source File: plugin_gui.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def init_heap(self):
        try:
            self.config_widget.load_config()
            self.heap = Heap()
            self.btn_reload.setEnabled(True)
            self.tabs.setTabEnabled(3, self.heap.tcache_enabled)

        except Exception as e:
            self.show_warning("Please, fix the config file")
            idaapi.warning(traceback.format_exc()) 
Example #29
Source File: plugin_gui.py    From heap-viewer with GNU General Public License v3.0 5 votes vote down vote up
def reload_gui_info(self, from_arena_cb=False):
        if self.heap is None:
            return

        try:
            if not misc.is_process_suspended():
                answer = idaapi.ask_yn(
                    idaapi.ASKBTN_YES, 
                    "HIDECANCEL\nThe process must be suspended to reload the info.\n\
                    Do you want to suspend it?")

                if answer == idaapi.ASKBTN_NO:
                    return

                if not idaapi.suspend_process():
                    warning("Unable to suspend the process")
                    return
        
            idaapi.refresh_debugger_memory()
            if not self.heap.get_heap_base():
                self.show_warning("Heap not initialized")
                return

            if not config.libc_base:
                self.show_warning("Unable to resolve glibc base address.")
                return

            self.hide_warning()
            self.arenas_widget.setVisible(True)

            if not from_arena_cb:
                self.populate_arenas()

            self.arena_widget.populate_table()
            self.tcache_widget.populate_table()
            self.bins_widget.populate_tables()

        except Exception as e:
            self.show_warning(str(e))
            idaapi.warning(traceback.format_exc()) 
Example #30
Source File: autostruct.py    From Sark with MIT License 4 votes vote down vote up
def run(self, arg):
        start, end = sark.get_selection()

        if not sark.structure.selection_has_offsets(start, end):
            message('No structure offsets in selection. Operation cancelled.')
            idaapi.warning('No structure offsets in selection. Operation cancelled.')
            return

        struct_name = idaapi.ask_str(self._prev_struct_name, 0, "Struct Name")
        if not struct_name:
            message("No structure name provided. Operation cancelled.")
            return
        self._prev_struct_name = struct_name

        common_reg = sark.structure.get_common_register(start, end)
        reg_name = idaapi.ask_str(common_reg, 0, "Register")
        if not reg_name:
            message("No offsets found. Operation cancelled.")
            return

        try:
            offsets, operands = sark.structure.infer_struct_offsets(start, end, reg_name)
        except sark.exceptions.InvalidStructOffset:
            message("Invalid offset found. Cannot create structure.",
                    "Make sure there are no negative offsets in the selection.")
            return

        except sark.exceptions.SarkInvalidRegisterName:
            message("Invalid register name {!r}. Cannot create structs.".format(reg_name))
            return

        try:
            sark.structure.create_struct_from_offsets(struct_name, offsets)
        except sark.exceptions.SarkStructAlreadyExists:
            yes_no_cancel = idaapi.ask_yn(idaapi.ASKBTN_NO,
                                      "Struct already exists. Modify?\n"
                                      "Cancel to avoid applying the struct.")
            if yes_no_cancel == idaapi.ASKBTN_CANCEL:
                return

            elif yes_no_cancel == idaapi.ASKBTN_YES:
                sid = sark.structure.get_struct(struct_name)
                sark.structure.set_struct_offsets(offsets, sid)

            else:  # yes_no_cancel == idaapi.ASKBTN_NO:
                pass

        sark.structure.apply_struct(start, end, reg_name, struct_name)