Skip to content

Commit a3465bb

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

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

pwnlib/util/misc.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -385,28 +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-
409-
410388
argv = [which(terminal)] + args
411389

412390
if isinstance(command, six.string_types):
@@ -435,6 +413,26 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
435413
argv += [tmp.name]
436414

437415

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+
438436
log.debug("Launching a new terminal: %r" % argv)
439437

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

0 commit comments

Comments
 (0)