From 82ae86ce3d649835e451510b4b69c2e90680c49e Mon Sep 17 00:00:00 2001 From: hugsy Date: Wed, 30 Oct 2024 08:59:21 -0700 Subject: [PATCH 1/2] allow clear screen command to be customized --- gef.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gef.py b/gef.py index c31ee9009..d8b4adcad 100644 --- a/gef.py +++ b/gef.py @@ -3900,7 +3900,8 @@ def clear_screen(tty: str = "") -> None: """Clear the screen.""" global gef if not tty: - gdb.execute("shell clear -x") + cmd: str = gef.config["gef.clear_screen_command"] + gdb.execute(f"shell {cmd}") return # Since the tty can be closed at any time, a PermissionError exception can @@ -9944,6 +9945,7 @@ def __init__(self) -> None: gef.config["gef.libc_version"] = GefSetting("", str, "Specify libc version when auto-detection fails") gef.config["gef.main_arena_offset"] = GefSetting("", str, "Offset from libc base address to main_arena symbol (int or hex). Set to empty string to disable.") gef.config["gef.propagate_debug_exception"] = GefSetting(False, bool, "If true, when debug mode is enabled, Python exceptions will be propagated all the way.") + gef.config["gef.clear_screen_command"] = GefSetting("clear -x", str, "Command to use to clear the screen.") self.commands : Dict[str, GenericCommand] = collections.OrderedDict() self.functions : Dict[str, GenericFunction] = collections.OrderedDict() From a9930ea99616c494bf406ed0c82c9c7dbbb6d7af Mon Sep 17 00:00:00 2001 From: hugsy Date: Thu, 31 Oct 2024 08:51:19 -0700 Subject: [PATCH 2/2] K.I.S.S --- gef.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/gef.py b/gef.py index d8b4adcad..20cea2914 100644 --- a/gef.py +++ b/gef.py @@ -3899,17 +3899,12 @@ def get_memory_alignment(in_bits: bool = False) -> int: def clear_screen(tty: str = "") -> None: """Clear the screen.""" global gef - if not tty: - cmd: str = gef.config["gef.clear_screen_command"] - gdb.execute(f"shell {cmd}") - return - # Since the tty can be closed at any time, a PermissionError exception can - # occur when `clear_screen` is called. We handle this scenario properly try: - with open(tty, "wt") as f: - f.write("\x1b[H\x1b[J") + sys.stdout.write("\x1b[H\x1b[J") except PermissionError: + # Since the tty can be closed at any time, a PermissionError exception can + # occur when `clear_screen` is called. We handle this scenario properly gef.ui.redirect_fd = None gef.config["context.redirect"] = "" return @@ -9945,7 +9940,6 @@ def __init__(self) -> None: gef.config["gef.libc_version"] = GefSetting("", str, "Specify libc version when auto-detection fails") gef.config["gef.main_arena_offset"] = GefSetting("", str, "Offset from libc base address to main_arena symbol (int or hex). Set to empty string to disable.") gef.config["gef.propagate_debug_exception"] = GefSetting(False, bool, "If true, when debug mode is enabled, Python exceptions will be propagated all the way.") - gef.config["gef.clear_screen_command"] = GefSetting("clear -x", str, "Command to use to clear the screen.") self.commands : Dict[str, GenericCommand] = collections.OrderedDict() self.functions : Dict[str, GenericFunction] = collections.OrderedDict()