Skip to content

Commit 71f8f14

Browse files
committed
use the previously sanitized command to run the osascript
1 parent fc070d0 commit 71f8f14

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

pwnlib/util/misc.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -385,27 +385,6 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
385385
if terminal == 'tmux':
386386
args += ['-F' '#{pane_pid}', '-P']
387387

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-
gdb_command = " ".join(command).replace('"', '\\"').replace("'", "\\'")
402-
osa_script = osa_script.format(gdb_command=gdb_command).lstrip()
403-
with tempfile.NamedTemporaryFile(delete=False, mode='wt+') as tmp:
404-
tmp.write(osa_script)
405-
tmp.flush()
406-
os.chmod(tmp.name, 0o700)
407-
args = [tmp.name]
408-
409388

410389
argv = [which(terminal)] + args
411390

@@ -435,6 +414,27 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
435414
argv += [tmp.name]
436415

437416

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

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

0 commit comments

Comments
 (0)