From cbc0538e82ac0256f73e9a907aed0c70405c704e Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 19 Oct 2023 20:52:35 -0400 Subject: [PATCH] Call printf with %b to avoid interpreting directives Former-commit-id: f1e812634d538b8e8c412b0c3aa1c43aab1c4f1b Former-commit-id: f95072b8742e752be18dc3fe9cba17c8e82eb41b --- lib/sshyp.py | 10 ++++------ port-jobs/CLIPBOARD.py | 41 +++++++++++++---------------------------- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index 8d4481e..8a89af4 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -553,8 +553,7 @@ def copy_data(): "Set-Clipboard", shell=True, stdout=DEVNULL, stderr=DEVNULL) # Wayland clipboard detection elif 'WAYLAND_DISPLAY' in environ: - run('wl-copy', stdin=Popen(('printf', _copy_subject.replace('\\', '\\\\').replace('%', '%%')), - stdout=PIPE).stdout) + run('wl-copy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\', '\\\\')), stdout=PIPE).stdout) Popen(f"sleep 30; test \'{_hash.hexdigest() + 2*' ' + '-'}\' = \"$(printf \"$(wl-paste)\" | sha512sum)\" " "&& wl-copy -c", shell=True) # Haiku clipboard detection @@ -564,8 +563,7 @@ def copy_data(): "&& clipboard -r", shell=True) # MacOS clipboard detection elif uname()[0] == 'Darwin': - run('pbcopy', stdin=Popen(('printf', _copy_subject.replace('\\', '\\\\').replace('%', '%%')), stdout=PIPE) - .stdout) + run('pbcopy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\', '\\\\')), stdout=PIPE).stdout) Popen(f"sleep 30; test \'{_hash.hexdigest() + 2 * ' ' + '-'}\' = \"$(printf \"$(pbpaste)\" | shasum -a 512)\" " "&& printf '' | pbcopy", shell=True) # Termux (Android) clipboard detection @@ -575,8 +573,8 @@ def copy_data(): f"sha512sum)\" && termux-clipboard-set ''", shell=True) # X11 clipboard detection elif 'DISPLAY' in environ: - run(('xclip', '-sel', 'c'), stdin=Popen(('printf', _copy_subject.replace('\\', '\\\\') - .replace('%', '%%')), stdout=PIPE).stdout) + run(('xclip', '-sel', 'c'), stdin=Popen(('printf', '%b', _copy_subject.replace('\\', '\\\\')), stdout=PIPE) + .stdout) Popen(f"sleep 30; test \'{_hash.hexdigest() + 2*' ' + '-'}\' = \"$(printf \"$(xclip -o -sel c)\" | sha512sum)\"" " && xclip -i /dev/null -sel c", shell=True) else: diff --git a/port-jobs/CLIPBOARD.py b/port-jobs/CLIPBOARD.py index f3b1e9b..6ed5c14 100755 --- a/port-jobs/CLIPBOARD.py +++ b/port-jobs/CLIPBOARD.py @@ -9,45 +9,30 @@ arguments, replacement = argv[1:], None if len(arguments) > 0: if arguments[0] == 'WSL': replacement = """run(('powershell.exe', '-c', "Set-Clipboard '" + _copy_subject.replace("'", "''") + "'")) - Popen("sleep 30; temp=$(echo \\"$(powershell.exe -Command \\'Get-FileHash -InputStream $([IO.MemoryStream]" - "::new([byte[]][char[]]\\"$(Get-Clipboard)\\")) -Algorithm SHA512 | Select-Object -ExpandProperty " - f"Hash\\')\\" | dos2unix); test \\'{_hash.hexdigest().upper()}\\' = \\"$temp\\" && powershell.exe -c " - "Set-Clipboard", shell=True, stdout=DEVNULL, stderr=DEVNULL)""" + Popen(f"sleep 30; temp=$(echo \\"$(powershell.exe -Command \\'Get-FileHash -InputStream $([IO.MemoryStream]::new([byte[]][char[]]\\"$(Get-Clipboard)\\")) -Algorithm SHA512 | Select-Object -ExpandProperty Hash\\')\\" | dos2unix); test \\'{_hash.hexdigest().upper()}\\' = \\"$temp\\" && powershell.exe -c Set-Clipboard", shell=True, stdout=DEVNULL, stderr=DEVNULL)""" elif arguments[0] == 'MAC': - replacement = """run('pbcopy', stdin=Popen(('printf', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\') - .replace('%', '%%')), stdout=PIPE).stdout) - Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2 * ' ' + '-'}\\' = \\"$(printf \\"$(pbpaste)\\" | shasum -a 512)\\" " - "&& printf '' | pbcopy", shell=True)""" + replacement = """run('pbcopy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout) + Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2 * ' ' + '-'}\\' = \\"$(printf \\"$(pbpaste)\\" | shasum -a 512)\\" && printf '' | pbcopy", shell=True)""" elif arguments[0] == 'HAIKU': replacement = """run(('clipboard', '-c', _copy_subject)) - Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2 * ' ' + '-'}\\' = \\"$(printf \\"$(clipboard -p)\\" | sha512sum)\\" " - "&& clipboard -r", shell=True)""" + Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2 * ' ' + '-'}\\' = \\"$(printf \\"$(clipboard -p)\\" | sha512sum)\\" && clipboard -r", shell=True)""" elif arguments[0] == 'TERMUX': replacement = """run(('termux-clipboard-set', _copy_subject)) - Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2 * ' ' + '-'}\\' = \\"$(printf \\"$(termux-clipboard-get)\\" | " - f"sha512sum)\\" && termux-clipboard-set ''", shell=True)""" + Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2 * ' ' + '-'}\\' = \\"$(printf \\"$(termux-clipboard-get)\\" | sha512sum)\\" && termux-clipboard-set ''", shell=True)""" elif arguments[0] == 'LINUX': replacement = """if 'WAYLAND_DISPLAY' in environ: - run('wl-copy', stdin=Popen(('printf', _copy_subject - .replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')), stdout=PIPE).stdout) - Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2*' ' + '-'}\\' = \\"$(printf \\"$(wl-paste)\\" | sha512sum)\\" " - "&& wl-copy -c", shell=True) + run('wl-copy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout) + Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2*' ' + '-'}\\' = \\"$(printf \\"$(wl-paste)\\" | sha512sum)\\" && wl-copy -c", shell=True) else: - run(('xclip', '-sel', 'c'), stdin=Popen(('printf', _copy_subject - .replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')), stdout=PIPE).stdout) - Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2*' ' + '-'}\\' = \\"$(printf \\"$(xclip -o -sel c)\\" | sha512sum)\\" " - "&& xclip -i /dev/null -sel c", shell=True)""" + run(('xclip', '-sel', 'c'), stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout) + Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2*' ' + '-'}\\' = \\"$(printf \\"$(xclip -o -sel c)\\" | sha512sum)\\" && xclip -i /dev/null -sel c", shell=True)""" elif arguments[0] == 'BSD': replacement = """if 'WAYLAND_DISPLAY' in environ: - run('wl-copy', stdin=Popen(('printf', _copy_subject - .replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')), stdout=PIPE).stdout) - Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2*' ' + '-'}\\' = \\"$(printf \\"$(wl-paste)\\" | sha512sum)\\" " - "&& wl-copy -c", shell=True) + run('wl-copy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout) + Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2*' ' + '-'}\\' = \\"$(printf \\"$(wl-paste)\\" | sha512sum)\\" && wl-copy -c", shell=True) else: - run(('xclip', '-sel', 'c'), stdin=Popen(('printf', _copy_subject - .replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')), stdout=PIPE).stdout) - Popen(f"sleep 30; test \\'{_hash.hexdigest()}\\' = \\"$(printf \\"$(xclip -o -sel c)\\" | sha512sum)\\" " - "&& xclip -i /dev/null -sel c", shell=True)""" + run(('xclip', '-sel', 'c'), stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout) + Popen(f"sleep 30; test \\'{_hash.hexdigest()}\\' = \\"$(printf \\"$(xclip -o -sel c)\\" | sha512sum)\\" && xclip -i /dev/null -sel c", shell=True)""" else: s_exit()