def m(self, begin=None, end=None): if begin is None: begin = self.memory_position begin = self.meta[begin] if end is None: end = begin + vm.PAGE_SIZE - 1 end = self.meta[end] for line in memory.inspect(self.mem, begin, end): print line self.memory_position = vm.mask16(end + 1)
def f(self, pattern=None): if pattern is None: pattern = '.*' symbols = sorted(list(self.meta.labels.keys())) lines = list() for symbol in symbols: if not re.search(pattern, symbol) is None: lines.append(vm.hex16(vm.mask16(self.meta[symbol])) + " = " + symbol) print '\n'.join(lines)
def d(self, begin=None, end=None): if begin is not None: self.dsm.position = vm.mask16(self.meta[begin]) if end is not None: for result in self.dsm(begin, self.meta[end]): print str(result) else: line_count = 0 done = False while not done: lines = str(self.dsm.next()).splitlines() for line in lines: print line line_count += 1 if line_count > self.config.lines: done = True break
def test_mask16_mask(self): self.assertEquals(0xffff, vm.mask16(0x1234ffff))
def inspect(mem, start, stop): """ Provides a hex dump of memory, *mem*, from *start* to *stop* address. A generator of strings is returned that provides one line of dump per iteration. Each line contains 16 bytes of memory which shows the current line address, hex values, and then ASCII values. ASCII values are shown if the byte value is in the range of (0x20, 0x7f], otherwise a '.' is shown. Full lines are always shown on paragraph boundaries. A dump with the range of ``0x08`` to ``0x09`` will show the line for ``0x00`` to ``0x0f``. Bytes not in the range are omitted with blanks. Values for *start* and *stop* that are out of range are truncated to 16-bits. If *start* is greater than *stop*, no values are returned. For memory with the following:: >>> mem[0x00:0x10] = vm.bstr('ABCDEFGHIJKLMNOP') >>> mem[0x10:0x20] = vm.bstr('abcdefghijklmnop') Calling ``inspect(mem, 0x00, 0x10)`` returns the following two strings:: $0000: 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 ABCDEFGHIJKLMNOP $0010: 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop Calling ``inspect(mem, 0x08, 0x18)`` returns the following:: $0000: 49 4a 4b 4c 4d 4e 4f 50 IJKLMNOP $0010: 61 62 63 64 65 66 67 68 abcdefgh """ columns = 16 # Always start at and print a 'full' line. pos = start - (start % columns) column_stop = stop - (stop % columns) + columns while pos < column_stop and stop >= start: line = ['${:04x}:'.format(vm.mask16(pos))] # Hex portion for i in xrange(columns): # Put a spacer after 8 bytes for readability if i == columns / 2: line += [' '] value = mem[vm.mask16(pos)] # Print if within range, otherwise print blanks if pos >= start and pos <= stop: line += [' {:02x}'.format(value)] else: line += [' '] pos += 1 # Rewind for ASCII portion pos -= columns line += [' '] for i in xrange(columns): value = mem[vm.mask16(pos)] # Print if within range, otherwise print blanks if pos >= start and pos <= stop: if not _is_ascii_printable(value): strv = '.' else: strv = chr(value) line += [strv] else: line += [' '] pos += 1 yield ''.join(line).strip()