From 3c907000ceab18dcf3ed9b35b9bf6c84a2782eee Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Fri, 12 Jan 2018 16:27:44 +0100 Subject: [PATCH] context: bring back args section (default off) (#397) This allows to use args section via the context-sections config setting (default off). Additionally introduce a nearpc-show-args config value making it possible to disable showing it trice while using the args section. --- pwndbg/arguments.py | 11 +++++++++++ pwndbg/commands/context.py | 26 +++++++++++--------------- pwndbg/commands/nearpc.py | 7 +++---- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pwndbg/arguments.py b/pwndbg/arguments.py index f4104068b..a010c70ac 100644 --- a/pwndbg/arguments.py +++ b/pwndbg/arguments.py @@ -15,6 +15,8 @@ from capstone import CS_GRP_INT import pwndbg.abi import pwndbg.arch +import pwndbg.chain +import pwndbg.color.nearpc as N import pwndbg.constants import pwndbg.disasm import pwndbg.funcparser @@ -192,3 +194,12 @@ def arguments(abi=None): for i in range(len(regs)): yield argname(i, abi), argument(i, abi) + + +def format_args(instruction): + result = [] + for arg, value in get(instruction): + code = arg.type != 'char' + pretty = pwndbg.chain.format(value, code=code) + result.append('%-10s %s' % (N.argument(arg.name) + ':', pretty)) + return result diff --git a/pwndbg/commands/context.py b/pwndbg/commands/context.py index 28fc6db2c..d014634d7 100644 --- a/pwndbg/commands/context.py +++ b/pwndbg/commands/context.py @@ -331,22 +331,17 @@ def context_backtrace(frame_count=10, with_banner=True): return result -def context_args(): - result = [] +def context_args(with_banner=True): + args = pwndbg.arguments.format_args(pwndbg.disasm.one()) - ################################################## - # DISABLED FOR NOW, I LIKE INLINE DISPLAY BETTER - ################################################## - # # For call instructions, attempt to resolve the target and - # # determine the number of arguments. - # for arg, value in pwndbg.arguments.arguments(pwndbg.disasm.one()): - # code = False if arg.type == 'char' else True - # pretty = pwndbg.chain.format(value, code=code) - # result.append('%-10s %s' % (arg.name+':', pretty)) - # if not result: - # return [] - # result.insert(0, pwndbg.ui.banner("arguments")) - return result + # early exit to skip section if no arg found + if not args: + return [] + + if with_banner: + args.insert(0, pwndbg.ui.banner("arguments")) + + return args last_signal = [] @@ -386,6 +381,7 @@ def context_signal(): context_sections = { 'r': context_regs, 'd': context_disasm, + 'a': context_args, 'c': context_code, 's': context_stack, 'b': context_backtrace diff --git a/pwndbg/commands/nearpc.py b/pwndbg/commands/nearpc.py index 8ccc0f479..4f4587f70 100644 --- a/pwndbg/commands/nearpc.py +++ b/pwndbg/commands/nearpc.py @@ -38,6 +38,7 @@ pwndbg.color.theme.Parameter('highlight-pc', True, 'whether to highlight the cur pwndbg.color.theme.Parameter('nearpc-prefix', '►', 'prefix marker for nearpc command') pwndbg.config.Parameter('left-pad-disasm', True, 'whether to left-pad disassembly') nearpc_lines = pwndbg.config.Parameter('nearpc-lines', 10, 'number of additional lines to print for the nearpc command') +show_args = pwndbg.config.Parameter('nearpc-show-args', True, 'show call arguments below instruction') @pwndbg.commands.ParsedCommand @pwndbg.commands.OnlyWhenRunning @@ -152,10 +153,8 @@ def nearpc(pc=None, lines=None, to_string=False, emulate=False): # For call instructions, attempt to resolve the target and # determine the number of arguments. - for arg, value in pwndbg.arguments.get(i): - code = False if arg.type == 'char' else True - pretty = pwndbg.chain.format(value, code=code) - result.append('%8s%-10s %s' % ('', N.argument(arg.name) + ':', pretty)) + if show_args.value: + result.extend(['%8s%s' % ('', arg) for arg in pwndbg.arguments.format_args(instruction=i)]) prev = i