From 46fba8bdba532d64505e4714d444233c2421d372 Mon Sep 17 00:00:00 2001 From: Grazfather Date: Sat, 26 Aug 2023 11:38:15 -0400 Subject: [PATCH] Tiny cleanup (#994) Small cleanup --- gef.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gef.py b/gef.py index feb4c3114..bd2e1df87 100644 --- a/gef.py +++ b/gef.py @@ -5987,16 +5987,16 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None: # qemu-user support qemu_binary: Optional[pathlib.Path] = None - try: - if args.qemu_user: + if args.qemu_user: + try: qemu_binary = pathlib.Path(args.qemu_binary).expanduser().absolute() if args.qemu_binary else gef.session.file if not qemu_binary or not qemu_binary.exists(): raise FileNotFoundError(f"{qemu_binary} does not exist") - except Exception as e: - err(f"Failed to initialize qemu-user mode, reason: {str(e)}") - return + except Exception as e: + err(f"Failed to initialize qemu-user mode, reason: {str(e)}") + return - # try to establish the remote session, throw on error + # Try to establish the remote session, throw on error # Set `.remote_initializing` to True here - `GefRemoteSessionManager` invokes code which # calls `is_remote_debug` which checks if `remote_initializing` is True or `.remote` is None # This prevents some spurious errors being thrown during startup @@ -11195,8 +11195,9 @@ def reset_caches(self) -> None: # `target remote` commands cannot be disabled, so print a warning message instead errmsg = "Using `target remote` with GEF does not work, use `gef-remote` instead. You've been warned." - gdb.execute(f"define target hook-remote\n pi if calling_function() != \"connect\": err(\"{errmsg}\") \nend") - gdb.execute(f"define target hook-extended-remote\n pi if calling_function() != \"connect\": err(\"{errmsg}\") \nend") + hook = f"""pi if calling_function() != "connect": err("{errmsg}")""" + gdb.execute(f"define target hook-remote\n{hook}\nend") + gdb.execute(f"define target hook-extended-remote\n{hook}\nend") # restore saved breakpoints (if any) bkp_fpath = pathlib.Path(gef.config["gef.autosave_breakpoints_file"]).expanduser().absolute()