def print_vars_type(self): idx = 0 for sz in self.ctx.local_vars_size: name = self.ctx.local_vars_name[idx] print_tabbed( color_type("int%d_t " % (sz * 8)) + color_var(name), 1) idx += 1
def print_vars_type(self): idx = 0 for sz in self.ctx.local_vars_size: name = self.ctx.local_vars_name[idx] print_tabbed(color_type("int%d_t " % (sz*8)) + color_var(name), 1) idx += 1
def print_operand(self, i, num_op, hexa=False, show_deref=True): def inv(n): return n == X86_OP_INVALID op = i.operands[num_op] if op.type == X86_OP_IMM: imm = op.value.imm sec_name, is_data = self.binary.is_address(imm) if sec_name is not None: print_no_end(hex(imm)) if self.ctx.sectionsname: print_no_end(" (" + color_section(sec_name) + ")") if is_data: s = self.binary.get_string(imm, self.ctx.max_data_size) print_no_end(" " + color_string(s)) if imm in self.binary.reverse_symbols: print_no_end(" ") self.print_symbol(imm) elif op.size == 1: print_no_end(color_string("'%s'" % get_char(imm))) elif hexa: print_no_end(hex(imm)) else: print_no_end(str(imm)) if imm > 0: packed = struct.pack("<L", imm) if set(packed).issubset(BYTES_PRINTABLE_SET): print_no_end(color_string(" \"")) print_no_end(color_string("".join(map(chr, packed)))) print_no_end(color_string("\"")) return False # returns True because capstone print immediate in hexa # it will be printed in a comment, sometimes it better # to have the value in hexa return True return False elif op.type == X86_OP_REG: print_no_end(i.reg_name(op.value.reg)) return False elif op.type == X86_OP_FP: print_no_end("%f" % op.value.fp) return False elif op.type == X86_OP_MEM: mm = op.mem if not inv(mm.base) and mm.disp != 0 \ and inv(mm.segment) and inv(mm.index): if (mm.base == X86_REG_RBP or mm.base == X86_REG_EBP) and \ self.var_name_exists(i, num_op): print_no_end(color_var(self.get_var_name(i, num_op))) return True elif mm.base == X86_REG_RIP or mm.base == X86_REG_EIP: addr = i.address + i.size + mm.disp print_no_end("*({0})".format( self.binary.reverse_symbols.get(addr, hex(addr)))) return True printed = False if show_deref: print_no_end("*(") if not inv(mm.base): print_no_end("%s" % i.reg_name(mm.base)) printed = True elif not inv(mm.segment): print_no_end("%s" % i.reg_name(mm.segment)) printed = True if not inv(mm.index): if printed: print_no_end(" + ") if mm.scale == 1: print_no_end("%s" % i.reg_name(mm.index)) else: print_no_end("(%s*%d)" % (i.reg_name(mm.index), mm.scale)) printed = True if mm.disp != 0: if mm.disp < 0: if printed: print_no_end(" - ") print_no_end(-mm.disp) else: if printed: print_no_end(" + ") print_no_end(mm.disp) else: if mm.disp in self.binary.reverse_symbols: print_no_end(hex(mm.disp) + " ") self.print_symbol(mm.disp) else: print_no_end(hex(mm.disp)) if show_deref: print_no_end(")") return True