diff --git a/CHANGELOG.md b/CHANGELOG.md index cd39c6c3c..2a0ce6c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,8 @@ The table below shows which release corresponds to each branch, and what date th - [#2160][2161] Fix invalid shellcraft.mov on arm64 - [#2284][2161] Fix invalid shellcraft.pushstr_array on arm64 - [#2345][2345] Fix pwn constgrep when it matches a non-constant type +- [#2338][2338] Fix: follow symlink for libs on ssh connection +- [#2341][2341] Launch GDB correctly in iTerm on Mac [2242]: https://github.com/Gallopsled/pwntools/pull/2242 [2277]: https://github.com/Gallopsled/pwntools/pull/2277 @@ -112,6 +114,8 @@ The table below shows which release corresponds to each branch, and what date th [2336]: https://github.com/Gallopsled/pwntools/pull/2336 [2161]: https://github.com/Gallopsled/pwntools/pull/2161 [2345]: https://github.com/Gallopsled/pwntools/pull/2345 +[2338]: https://github.com/Gallopsled/pwntools/pull/2338 +[2341]: https://github.com/Gallopsled/pwntools/pull/2341 ## 4.12.0 (`beta`) diff --git a/pwnlib/util/misc.py b/pwnlib/util/misc.py index 22dff501a..188be3457 100644 --- a/pwnlib/util/misc.py +++ b/pwnlib/util/misc.py @@ -307,6 +307,10 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr elif 'STY' in os.environ and which('screen'): terminal = 'screen' args = ['-t','pwntools-gdb','bash','-c'] + elif 'TERM_PROGRAM' in os.environ and os.environ['TERM_PROGRAM'] == "iTerm.app" and which('osascript'): + # if we're on a mac, and using iTerm + terminal = "osascript" + args = [] elif 'TERM_PROGRAM' in os.environ and which(os.environ['TERM_PROGRAM']): terminal = os.environ['TERM_PROGRAM'] args = [] @@ -366,7 +370,6 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr args.extend(['wsl.exe', '-d', distro_name, 'bash', '-c']) else: args.extend(['bash.exe', '-c']) - if not terminal: log.error('Could not find a terminal binary to use. Set context.terminal to your terminal.') @@ -410,6 +413,26 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr argv += [tmp.name] + # if we're on a Mac and use iTerm, we use `osascript` to split the current window + # `command` was sanitized on the previous step. It is now either a string, or was written to a tmp file + # we run the command, which is now `argv[-1]` + if terminal == 'osascript': + osa_script = f""" +tell application "iTerm" + tell current session of current window + set newSession to (split horizontally with default profile) + end tell + tell newSession + write text "{argv[-1]}" + end tell +end tell +""" + with tempfile.NamedTemporaryFile(delete=False, mode='wt+') as tmp: + tmp.write(osa_script.lstrip()) + tmp.flush() + os.chmod(tmp.name, 0o700) + argv = [which(terminal), tmp.name] + log.debug("Launching a new terminal: %r" % argv) stdin = stdout = stderr = open(os.devnull, 'r+b')