From 8a34f6082fe639f59927a523aab9fb275ef6e6e0 Mon Sep 17 00:00:00 2001 From: Zach Riggle Date: Wed, 23 Nov 2016 11:44:43 -0700 Subject: [PATCH] Add configfile and themefile commands These allow the user to access all configuration points, with their *current* user-set values, and view the defaults / edit the values. Fixes pwndbg/pwndbg#137 --- pwndbg/commands/config.py | 22 ++++++++++++++++++++++ pwndbg/config.py | 6 +++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pwndbg/commands/config.py b/pwndbg/commands/config.py index 134632d73..1f9d758b7 100644 --- a/pwndbg/commands/config.py +++ b/pwndbg/commands/config.py @@ -41,3 +41,25 @@ def config(): for v in sorted(values): print_row(v.optname, repr(v.value), repr(v.default), v.docstring, longest_optname, longest_value) + +@pwndbg.commands.Command +def configfile(): + """Generates a configuration file for the current Pwndbg options""" + configfile_print_scope('config') + +@pwndbg.commands.Command +def themefile(): + """Generates a configuration file for the current Pwndbg theme options""" + configfile_print_scope('theme') + +def configfile_print_scope(scope): + values = [v for k, v in pwndbg.config.__dict__.items() + if isinstance(v, pwndbg.config.Parameter) and v.scope == scope] + longest_optname = max(map(len, [v.optname for v in values])) + longest_value = max(map(len, [extend_value_with_default(repr(v.value), repr(v.default)) for v in values])) + + for v in sorted(values): + print('# %s: %s' % (v.optname, v.docstring)) + print('# default: %r' % v.default) + print('py pwndbg.config.%s=%r' % (v.name, v.value)) + print() diff --git a/pwndbg/config.py b/pwndbg/config.py index b36fd6d3b..8f2fe2e77 100644 --- a/pwndbg/config.py +++ b/pwndbg/config.py @@ -72,9 +72,9 @@ class Parameter(gdb.Parameter): def __init__(self, name, default, docstring, scope='config'): self.docstring = docstring.strip() - self.optname = name - self.name = name.replace('-','_') - self.default = default + self.optname = name + self.name = name.replace('-','_') + self.default = default self.set_doc = 'Set ' + docstring self.show_doc = docstring + ':' super(Parameter, self).__init__(name,