Skip to content

Commit 73f2a31

Browse files
teddavpeace-maker
andauthored
fix: split current iterm window during gdb.debug process (#2341)
* fix: split current iterm window during gdb.debug process * add change to changelog * escape cmd before writing osascript file * use the previously sanitized command to run the osascript --------- Co-authored-by: peace-maker <[email protected]>
1 parent 604b98c commit 73f2a31

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ The table below shows which release corresponds to each branch, and what date th
9292
- [#2160][2161] Fix invalid shellcraft.mov on arm64
9393
- [#2284][2161] Fix invalid shellcraft.pushstr_array on arm64
9494
- [#2345][2345] Fix pwn constgrep when it matches a non-constant type
95+
- [#2338][2338] Fix: follow symlink for libs on ssh connection
96+
- [#2341][2341] Launch GDB correctly in iTerm on Mac
9597

9698
[2242]: https://github.com/Gallopsled/pwntools/pull/2242
9799
[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
112114
[2336]: https://github.com/Gallopsled/pwntools/pull/2336
113115
[2161]: https://github.com/Gallopsled/pwntools/pull/2161
114116
[2345]: https://github.com/Gallopsled/pwntools/pull/2345
117+
[2338]: https://github.com/Gallopsled/pwntools/pull/2338
118+
[2341]: https://github.com/Gallopsled/pwntools/pull/2341
115119

116120
## 4.12.0 (`beta`)
117121

pwnlib/util/misc.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
307307
elif 'STY' in os.environ and which('screen'):
308308
terminal = 'screen'
309309
args = ['-t','pwntools-gdb','bash','-c']
310+
elif 'TERM_PROGRAM' in os.environ and os.environ['TERM_PROGRAM'] == "iTerm.app" and which('osascript'):
311+
# if we're on a mac, and using iTerm
312+
terminal = "osascript"
313+
args = []
310314
elif 'TERM_PROGRAM' in os.environ and which(os.environ['TERM_PROGRAM']):
311315
terminal = os.environ['TERM_PROGRAM']
312316
args = []
@@ -366,7 +370,6 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
366370
args.extend(['wsl.exe', '-d', distro_name, 'bash', '-c'])
367371
else:
368372
args.extend(['bash.exe', '-c'])
369-
370373

371374
if not terminal:
372375
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
410413
argv += [tmp.name]
411414

412415

416+
# if we're on a Mac and use iTerm, we use `osascript` to split the current window
417+
# `command` was sanitized on the previous step. It is now either a string, or was written to a tmp file
418+
# we run the command, which is now `argv[-1]`
419+
if terminal == 'osascript':
420+
osa_script = f"""
421+
tell application "iTerm"
422+
tell current session of current window
423+
set newSession to (split horizontally with default profile)
424+
end tell
425+
tell newSession
426+
write text "{argv[-1]}"
427+
end tell
428+
end tell
429+
"""
430+
with tempfile.NamedTemporaryFile(delete=False, mode='wt+') as tmp:
431+
tmp.write(osa_script.lstrip())
432+
tmp.flush()
433+
os.chmod(tmp.name, 0o700)
434+
argv = [which(terminal), tmp.name]
435+
413436
log.debug("Launching a new terminal: %r" % argv)
414437

415438
stdin = stdout = stderr = open(os.devnull, 'r+b')

0 commit comments

Comments
 (0)