Пример #1
0
 def addEntry(self, header, hdr_color, log_entry):
     lines = log_entry.splitlines()
     header = COLSTR(header, hdr_color)
     self.AddLine(header + COLSTR(": " + str(lines[0]), SCOLOR_AUTOCMT))
     del lines[0]
     for line in lines:
         self.AddLine(COLSTR(str(line), SCOLOR_AUTOCMT))
Пример #2
0
 def setContent(self, backtrace):
     self.ClearLines()
     if backtrace is None:
         return
     hdr_title = COLSTR("  Backtrace for [ ", SCOLOR_AUTOCMT)
     hdr_title += COLSTR("0x%X: " % self.view_id, SCOLOR_DREF)
     hdr_title += COLSTR(backtrace.getEntry(0).sym_name, SCOLOR_DEMNAME)
     hdr_title += COLSTR(" ]", SCOLOR_AUTOCMT)
     self.AddLine(str(hdr_title))
     self.AddLine("")
     for idx in range(backtrace.getCount()):
         if idx == 0:
             continue
         entry = backtrace.getEntry(idx)
         if entry is None:
             continue
         call = COLSTR(" %4d: " % idx, SCOLOR_AUTOCMT)
         call += COLSTR(entry.mod_name.ljust(30), SCOLOR_SEGNAME) + " "
         if entry.idb_addr:
             addr_color = SCOLOR_NUMBER
         else:
             addr_color = SCOLOR_CREFTAIL
         call += COLSTR(str("0x%.12X" % entry.sym_addr),
                        addr_color) + COLSTR(" + ", SCOLOR_AUTOCMT)
         call += COLSTR(
             str("0x%.6X" % (entry.sym_call - entry.sym_addr)) + " ",
             addr_color)
         call += COLSTR(entry.sym_name, SCOLOR_DEMNAME)
         self.AddLine(str(call))
     self.Refresh()
Пример #3
0
    def setContent(self, content):
        global gSettings_CpuCtxCols

        arch = content["arch"]
        context = content["context"]

        self.ClearLines()

        hdr_title = COLSTR("  CPU context for [ ", SCOLOR_AUTOCMT)
        hdr_title += COLSTR("0x%X: " % self.view_id, SCOLOR_DREF)
        hdr_title += COLSTR(self.command, SCOLOR_INSN)
        hdr_title += COLSTR(" ]", SCOLOR_AUTOCMT)
        self.AddLine(hdr_title)
        self.AddLine("")

        if len(context) == 0 or arch == "":
            self.Refresh()
            return

        if self.columns is None:
            cols = FrLSettings().getCpuContextColumns()
        else:
            cols = self.columns
        regList = self.getRegisterOrder(arch)
        reg_cnt = len(regList)
        lines = reg_cnt / cols if reg_cnt % cols == 0 else (reg_cnt / cols) + 1
        line = ""
        for i in range(lines):
            if i != 0:
                self.AddLine(line)
                line = ""

            for j in xrange(i, reg_cnt, lines):
                reg = regList[j]
                line = line + COLSTR(" %4s: " % str(reg), SCOLOR_REG)
                if self.lastContext is not None:
                    if self.lastContext[reg] != context[reg]:
                        line += COLSTR(str(context[reg]), SCOLOR_VOIDOP)
                    else:
                        line += COLSTR(str(context[reg]), SCOLOR_NUMBER)
                else:
                    line += COLSTR(str(context[reg]), SCOLOR_NUMBER)

                line = line.ljust(35 * ((j / lines) + 1))

        self.AddLine(line)

        self.Refresh()
        self.lastContext = context
        self.lastArch = arch
Пример #4
0
 def disasm(self, inst):
     """A simple local disassembler. In reality one can use a full-blown disassembler to render the text"""
     opbyte = ord(inst[0])
     op     = opbyte >> 4
     if not (1<=op<=5):
         return None
     r1     = (opbyte & 0xf) >> 2
     r2     = opbyte & 3
     sz     = 0
     if r2 == 0:
         if len(inst) != 5:
             return None
         imm = struct.unpack_from('L', inst, 1)[0]
         sz  = 5
     else:
         imm = None
         sz  = 1
     text = "%s %s, %s" % (
         COLSTR(simplevm_data_format.INST[op], idaapi.SCOLOR_INSN),
         COLSTR(simplevm_data_format.REGS[r1], idaapi.SCOLOR_REG),
         COLSTR("0x%08X" % imm, idaapi.SCOLOR_NUMBER) if imm is not None else COLSTR(simplevm_data_format.REGS[r2], idaapi.SCOLOR_REG))
     return (sz, text)
Пример #5
0
    def printf(self, value, current_ea, operand_num, dtid):
        # Is it already cached?
        val = self.cache_node.supval(current_ea)

        # Not cached?
        if val == None:
            # Retrieve it
            num = idaapi.struct_unpack(value)
            val = self.get_rsrc_string(idaapi.get_input_file_path(), num)
            # Cache it
            self.cache_node.supset(current_ea, val)

        # Failed to retrieve?
        if val == "" or val == "\x00":
            return None
        # Return the format
        return "RSRC_STR(\"%s\")" % COLSTR(val, idaapi.SCOLOR_IMPNAME)
Пример #6
0
    def setContent(self, stack):
        self.ClearLines()
        if stack is None:
            return
        hdr_title = COLSTR("  Stack for [ ", SCOLOR_AUTOCMT)
        hdr_title += COLSTR("0x%X: " % self.view_id, SCOLOR_DREF)
        hdr_title += COLSTR(self.command, SCOLOR_INSN)
        hdr_title += COLSTR(" ]", SCOLOR_AUTOCMT)
        self.AddLine(hdr_title)
        self.AddLine("")

        num = stack.getCount()
        for i in xrange(0, num):
            addr, data, symbol, sp = stack.getEntry(i)
            line = " "
            if sp:
                line += COLSTR("%.16X" % addr, SCOLOR_DREF)
            else:
                line += COLSTR("%.16X" % addr, SCOLOR_AUTOCMT)
            line += "  "
            if addr in self.lastContent and self.lastContent[addr] != data:
                line += COLSTR("%.16X" % data, SCOLOR_VOIDOP)
            else:
                line += COLSTR("%.16X" % data, SCOLOR_NUMBER)
            info = self.engine.resolveStackAddress(data, symbol)
            if info is not None:
                if 'module' in info:
                    line += "  "
                    line += COLSTR(info['module'], SCOLOR_SEGNAME)
                    if 'symbol' in info:
                        line += COLSTR(":", SCOLOR_AUTOCMT)
                        line += COLSTR(info['symbol'], SCOLOR_DEMNAME)

            self.AddLine(line)
            self.lastContent[addr] = data

        self.Refresh()
Пример #7
0
    def setContent(self, memory):
        self.ClearLines()
        if memory is None:
            return
        size = len(memory)

        hdr_title = COLSTR("  Memory for [ ", SCOLOR_AUTOCMT)
        hdr_title += COLSTR("0x%X: %d byte(s)" % (self.address, len(memory)),
                            SCOLOR_DREF)
        hdr_title += COLSTR(" ]", SCOLOR_AUTOCMT)
        self.AddLine(str(hdr_title))
        self.AddLine("")
        self.AddLine(
            COLSTR(
                "                0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F",
                SCOLOR_AUTOCMT))

        startAddress = self.address
        line = ""
        chars = ""
        get_char = lambda byte: chr(byte) if 0x20 <= byte <= 0x7E else '.'

        if size != 0:
            for x in range(size):
                if x % 16 == 0:
                    line += COLSTR(" %.12X: " % startAddress, SCOLOR_AUTOCMT)
                if len(self.lastContent) == len(memory):
                    if memory[x] != self.lastContent[x]:
                        line += COLSTR(str("%.2X " % memory[x]), SCOLOR_VOIDOP)
                        chars += COLSTR(get_char(memory[x]), SCOLOR_VOIDOP)
                    else:
                        line += COLSTR(str("%.2X " % memory[x]), SCOLOR_NUMBER)
                        chars += COLSTR(get_char(memory[x]), SCOLOR_NUMBER)
                else:
                    line += COLSTR(str("%.2X " % memory[x]), SCOLOR_NUMBER)
                    chars += COLSTR(get_char(memory[x]), SCOLOR_NUMBER)

                if (x + 1) % 16 == 0:
                    line += "  " + chars
                    self.AddLine(line)
                    startAddress += 16
                    line = ""
                    chars = ""

            # add padding
            tail = 16 - size % 16
            if tail != 0:
                for x in range(tail):
                    line += "   "
                line += "  " + chars
                self.AddLine(line)

        self.Refresh()
        self.lastContent = memory