Fix the address padding issue in nearpc()

pull/72/head
MengHuan Yu 10 years ago
parent 28a065b7a4
commit a8559fed13

@ -18,6 +18,9 @@ import pwndbg.symbol
import pwndbg.ui import pwndbg.ui
import pwndbg.vmmap import pwndbg.vmmap
def ljust_padding(lst):
longest_len = max(map(len, lst)) if lst else 0
return [s.ljust(longest_len) for s in lst]
@pwndbg.commands.ParsedCommand @pwndbg.commands.ParsedCommand
@pwndbg.commands.OnlyWhenRunning @pwndbg.commands.OnlyWhenRunning
@ -64,27 +67,17 @@ def nearpc(pc=None, lines=None, to_string=False, emulate=False):
pwndbg.vmmap.find(pc) pwndbg.vmmap.find(pc)
# Find all of the symbols for the addresses # Find all of the symbols for the addresses
symbols = [] symbols = [pwndbg.symbol.get(i.address) for i in instructions]
for i in instructions: symbols = ['<%s> ' % sym if sym else '' for sym in symbols]
symbol = pwndbg.symbol.get(i.address) symbols = ljust_padding(symbols)
if symbol:
symbol = '<%s> ' % symbol addresses = ["%#x" % i.address for i in instructions]
symbols.append(symbol) addresses = ljust_padding(addresses)
# Find the longest symbol name so we can adjust
if symbols:
longest_sym = max(map(len, symbols))
else:
longest_sym = ''
# Pad them all out
for i,s in enumerate(symbols):
symbols[i] = s.ljust(longest_sym)
prev = None prev = None
# Print out each instruction # Print out each instruction
for i,s in zip(instructions, symbols): for address_str, s, i in zip(addresses, symbols, instructions):
asm = pwndbg.disasm.color.instruction(i) asm = pwndbg.disasm.color.instruction(i)
prefix = ' =>' if i.address == pc else ' ' prefix = ' =>' if i.address == pc else ' '
@ -95,7 +88,7 @@ def nearpc(pc=None, lines=None, to_string=False, emulate=False):
# for line in pc_to_linenos[i.address]: # for line in pc_to_linenos[i.address]:
# result.append('%s %s' % (line, lineno_to_src[line].strip())) # result.append('%s %s' % (line, lineno_to_src[line].strip()))
line = ' '.join((prefix, "%#x" % i.address, s or '', asm)) line = ' '.join((prefix, address_str, s, asm))
# If there was a branch before this instruction which was not # If there was a branch before this instruction which was not
# contiguous, put in some ellipses. # contiguous, put in some ellipses.

Loading…
Cancel
Save