-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecodeSafelinks.sh
25 lines (18 loc) · 1.07 KB
/
decodeSafelinks.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# This script cleans up the garbage URLs generated by Microsoft's Advanced Threat Protection.
# Isaac Nelson <[email protected]> 12 November 2018
# Rewritten 29 January 2020
# 3 April 2020 - Updated path to jsc for Catalina, I guess?
#set -x
# Input URL
safeLink="${1}"
# JavaScriptCore binary
#jsc="/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc" #Pre-Catalina?
jsc="/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Helpers/jsc"
# Cut the SafeLinks garbage out (first 53 characters, and then the first '&' and everything after it)
trimmedURL=$(/bin/echo "$safeLink" | /usr/bin/cut -c 53- | /usr/bin/cut -f1 -d"&")
# Use the JavaScriptCore binary to decode and print the URL
url=$($jsc -e "print(decodeURIComponent(\"$trimmedURL\"))")
if /usr/bin/osascript -e "display dialog \"${url}\" with title \"Open URL?\" buttons {\"Cancel\", \"Open\"} default button 2 cancel button 1 with icon file (POSIX file \"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns\")"; then
open "${url}"
fi