Skip to content

Commit

Permalink
feature(telescope): option to set min repeating values before skipping
Browse files Browse the repository at this point in the history
Buffer all repeating lines and check the minimum value when to start
marking them with skip lines. In case the minimum value is not hit, just
unroll the buffer.

To stop skipping any lines, there is the existing bool config
telescope-skip-repeat-val so we avoid adding special values to minimum
like -1 and keep the setting separated.

Fixes Gallopsled#803
  • Loading branch information
anthraxx authored and disconnect3d committed Apr 6, 2021
1 parent 14325af commit baf3fe7
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions pwndbg/commands/telescope.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
telescope_lines = pwndbg.config.Parameter('telescope-lines', 8, 'number of lines to printed by the telescope command')
skip_repeating_values = pwndbg.config.Parameter('telescope-skip-repeating-val', True,
'whether to skip repeating values of the telescope command')
skip_repeating_values_minimum = pwndbg.config.Parameter('telescope-skip-repeating-val-minimum', 3,
'minimum amount of repeated values before skipping lines')

offset_separator = theme.Parameter('telescope-offset-separator', '│', 'offset separator of the telescope command')
offset_delimiter = theme.Parameter('telescope-offset-delimiter', ':', 'offset delimiter of the telescope command')
Expand Down Expand Up @@ -94,28 +96,40 @@ def telescope(address=None, count=telescope_lines, to_string=False):

# Print everything out
result = []
last = None
skip = False
for i,addr in enumerate(range(start, stop, step)):
last = None
collapse_buffer = []

# Collapse repeating values exceeding minimum delta.
def collapse_repeating_values():
# The first line was already printed, hence increment by 1
if collapse_buffer and len(collapse_buffer) + 1 >= skip_repeating_values_minimum:
result.append(T.repeating_marker('%s' % repeating_marker))
else:
result.extend(collapse_buffer)
collapse_buffer.clear()

for i, addr in enumerate(range(start, stop, step)):
if not pwndbg.memory.peek(addr):
collapse_repeating_values()
result.append("<Could not read memory at %#x>" % addr)
break

# Collapse repeating values.
value = pwndbg.memory.pvoid(addr)
if skip_repeating_values and last == value:
if not skip:
result.append(T.repeating_marker('%s' % repeating_marker))
skip = True
continue
last = value
skip = False

line = ' '.join((T.offset("%02x%s%04x%s" % (i + telescope.offset, delimiter,
addr - start + (telescope.offset * ptrsize), separator)),
T.register(regs[addr].ljust(longest_regs)),
pwndbg.chain.format(addr)))

# Buffer repeating values.
if skip_repeating_values:
value = pwndbg.memory.pvoid(addr)
if last == value:
collapse_buffer.append(line)
continue
collapse_repeating_values()
last = value

result.append(line)

telescope.offset += i
telescope.last_address = addr

Expand Down

0 comments on commit baf3fe7

Please sign in to comment.