Check if override built-in command (#543)

* Check if override built-in command

* Abort on non-whitelisted command override

* Fixes according to PR discussion

* Check if override built-in command

* Abort on non-whitelisted command override

* Fixes according to PR discussion

* Clearer parsing of gdb output

Co-Authored-By: ZetaTwo <calle.svensson@zeta-two.com>
pull/552/head
Calle Svensson 7 years ago committed by Disconnect3d
parent ab46a7943f
commit 631c932731

@ -23,10 +23,29 @@ import pwndbg.ui
commands = []
def list_current_commands():
current_pagination = gdb.execute('show pagination', to_string=True)
current_pagination = current_pagination.split()[-1].rstrip('.') # Take last word and skip period
gdb.execute('set pagination off')
command_list = gdb.execute('help all', to_string=True).strip().split('\n')
existing_commands = set()
for line in command_list:
line = line.strip()
# Skip non-command entries
if len(line) == 0 or line.startswith('Command class:') or line.startswith('Unclassified commands'):
continue
command = line.split()[0]
existing_commands.add(command)
gdb.execute('set pagination %s' % current_pagination) # Restore original setting
return existing_commands
GDB_BUILTIN_COMMANDS = list_current_commands()
class Command(gdb.Command):
"""Generic command wrapper"""
command_names = set()
builtin_override_whitelist = {'up', 'down', 'search', 'pwd', 'start'}
history = {}
def __init__(self, function, prefix=False):
@ -37,6 +56,8 @@ class Command(gdb.Command):
if command_name in self.command_names:
raise Exception('Cannot add command %s: already exists.' % command_name)
if command_name in GDB_BUILTIN_COMMANDS and command_name not in self.builtin_override_whitelist:
raise Exception('Cannot override non-whitelisted built-in command "%s"' % command_name)
self.command_names.add(command_name)
commands.append(self)

Loading…
Cancel
Save