Skip to content

Commit fe66791

Browse files
committed
fix: split current iterm window during gdb.debug process
1 parent bf7abc0 commit fe66791

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pwnlib/util/misc.py

+25-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.')
@@ -382,6 +385,27 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
382385
if terminal == 'tmux':
383386
args += ['-F' '#{pane_pid}', '-P']
384387

388+
# if we're on a Mac and use iTerm
389+
# we use `osascript` to split the current window
390+
if terminal == 'osascript':
391+
osa_script = """
392+
tell application "iTerm"
393+
tell current session of current window
394+
set newSession to (split horizontally with default profile)
395+
end tell
396+
tell newSession
397+
write text "{gdb_command}"
398+
end tell
399+
end tell
400+
"""
401+
osa_script = osa_script.format(gdb_command=" ".join(command)).lstrip()
402+
with tempfile.NamedTemporaryFile(delete=False, mode='wt+') as tmp:
403+
tmp.write(osa_script)
404+
tmp.flush()
405+
os.chmod(tmp.name, 0o700)
406+
args = [tmp.name]
407+
408+
385409
argv = [which(terminal)] + args
386410

387411
if isinstance(command, six.string_types):

0 commit comments

Comments
 (0)