def get_string(self, addr, max_data_size=-1, s=None): if s is None: s = self.get_section(addr) if s is None: return None data = s.data off = addr - s.start txt = [] c = 0 i = 0 while (i < max_data_size or max_data_size == -1) and off < len(data): c = data[off] if c == 0: break if c not in BYTES_PRINTABLE_SET: break txt.append(get_char(c)) off += 1 i += 1 if i == max_data_size: if c != 0: txt.append("...") elif c != 0 or i == 0: return None return ''.join(txt)
def get_string(self, addr, max_data_size): s = self.get_section(addr) if s is None: return None data = s.data off = addr - s.start txt = ['"'] c = 0 i = 0 while i < max_data_size and off < len(data): c = data[off] if c == 0: break if c not in BYTES_PRINTABLE_SET: break txt.append(get_char(c)) off += 1 i += 1 if i == max_data_size: if c != 0: txt.append("...") elif c != 0 or i == 0: return None return ''.join(txt) + '"'
def _imm(self, imm, op_size, hexa, section=None, print_data=True, force_dont_print_data=False): if self.gctx.capstone_string: hexa = True label_printed = self._label(imm, print_colon=False) if label_printed: ty = self._dis.mem.get_type(imm) # ty == -1 : from the terminal (with -x) there are no xrefs if imm in self._dis.xrefs and ty != MEM_UNK or ty == -1: return True if section is None: section = self._binary.get_section(imm) # For a raw file, if the raw base is 0 the immediate is considered # as an address only if it's in the symbols list. raw_base_zero = self._binary.type == T_BIN_RAW and self.gctx.raw_base == 0 if section is not None and not raw_base_zero: if not label_printed: self._address(imm, print_colon=False, notprefix=True) if not force_dont_print_data and \ print_data and imm not in self._binary.reverse_symbols and \ section is not None and section.is_data: s = self._binary.get_string(imm, self.gctx.max_data_size) if s != "\"\"": self._add(" ") self._string(s) return True elif op_size == 1: self._string("'%s'" % get_char(imm)) elif hexa: self._add(hex(imm)) else: self._add(str(imm)) if imm > 0: if op_size == 4: packed = struct.pack("<L", imm) elif op_size == 8: packed = struct.pack("<Q", imm) else: return True if set(packed).issubset(BYTES_PRINTABLE_SET): self._string(" \"" + "".join(map(chr, packed)) + "\"") return False # returns True because capstone print immediate in hexa and # it will be printed in a comment, sometimes it's better # to have the value in hexa return True return False
def get_string(self, addr, max_data_size): s = self.get_section(addr) if s is None: return "" data = s.data off = addr - s.start txt = ['"'] c = 0 i = 0 while i < max_data_size and \ off < len(data): c = data[off] if c == 0: break txt.append(get_char(c)) off += 1 i += 1 if c != 0 and off != len(data): txt.append("...") return ''.join(txt) + '"'