diff --git a/pwnlib/context/__init__.py b/pwnlib/context/__init__.py index cad7c1f00..94a550d71 100644 --- a/pwnlib/context/__init__.py +++ b/pwnlib/context/__init__.py @@ -150,7 +150,7 @@ class _Tls_DictStack(threading.local, _DictStack): def _validator(validator): """ - Validator that tis tightly coupled to the implementation + Validator that is tightly coupled to the implementation of the classes here. This expects that the object has a ._tls property which @@ -340,6 +340,7 @@ class ContextType(object): 'delete_corefiles': False, 'device': os.getenv('ANDROID_SERIAL', None) or None, 'endian': 'little', + 'gdbinit': "", 'kernel': None, 'log_level': logging.INFO, 'log_file': _devnull(), @@ -1231,6 +1232,23 @@ def rename_corefiles(self, v): """ return bool(v) + + @_validator + def gdbinit(self, value): + """Path to the gdbinit that is used when running GDB locally. + + This is useful if you want pwntools-launched GDB to include some additional modules, + like PEDA but you do not want to have GDB include them by default. + + The setting will only apply when GDB is launched locally since remote hosts may not have + the necessary requirements for the gdbinit. + + If set to an empty string, GDB will use the default `~/.gdbinit`. + + Default value is ``""``. + """ + return str(value) + #************************************************************************* # ALIASES #************************************************************************* diff --git a/pwnlib/gdb.py b/pwnlib/gdb.py index d659ca268..4f545786d 100644 --- a/pwnlib/gdb.py +++ b/pwnlib/gdb.py @@ -646,6 +646,10 @@ def findexe(): cmd += ' ' cmd += ' '.join(gdb_args) + if context.gdbinit: + cmd += ' -nh ' # ignore ~/.gdbinit + cmd += ' -x %s ' % context.gdbinit # load custom gdbinit + cmd += ' -q ' if exe and context.native: