-
Notifications
You must be signed in to change notification settings - Fork 0
/
route-decoder.py
executable file
·85 lines (67 loc) · 2.54 KB
/
route-decoder.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import base64
import sys
import json
from biplist import readPlistFromString, writePlistToString
from colorama import Fore, init
# Initialize colorama
init(autoreset=True)
def decode_streisand_url(encoded_text):
# Remove prefix "streisand://"
if encoded_text.startswith("streisand://"):
encoded_text = encoded_text[len("streisand://"):]
# First base64 decoding
decoded_step1 = base64.b64decode(encoded_text).decode('utf-8')
# Remove prefix "import/route://"
if decoded_step1.startswith("import/route://"):
decoded_step1 = decoded_step1[len("import/route://"):]
# Second base64 decoding
decoded_step2 = base64.b64decode(decoded_step1)
# Decode from bplist
try:
plist_data = readPlistFromString(decoded_step2)
# Convert and format JSON for validation
json_data = json.loads(json.dumps(plist_data)) # Convert to JSON and back
formatted_json = json.dumps(json_data, ensure_ascii=False, indent=4)
return formatted_json
except Exception as e:
print(f"Error decoding bplist: {e}")
return None
def encode_streisand_url(data):
# Convert data to bplist format
try:
plist_data = writePlistToString(data)
except Exception as e:
print(f"Error encoding to bplist: {e}")
return None
# First base64 encoding
encoded_step1 = base64.b64encode(plist_data).decode('utf-8')
# Add prefix "import/route://"
encoded_step1 = "import/route://" + encoded_step1
# Second base64 encoding
encoded_step2 = base64.b64encode(encoded_step1.encode('utf-8')).decode('utf-8')
# Add prefix "streisand://"
encoded_text = "streisand://" + encoded_step2
return encoded_text
if __name__ == "__main__":
if len(sys.argv) != 3 or sys.argv[1] not in ("-d", "-e"):
print("Usage: python script.py -d '<encoded_text>' or python script.py -e '<json_data>'")
sys.exit(1)
mode = sys.argv[1]
text = sys.argv[2]
if mode == "-d":
result = decode_streisand_url(text)
if result is not None:
# Print decoded JSON in green
print(Fore.YELLOW + "Decoded result:\n", result)
else:
print("Error decoding")
elif mode == "-e":
try:
data = json.loads(text)
result = encode_streisand_url(data)
if result is not None:
print(Fore.YELLOW + "Encoded result:\n", result)
else:
print("Error encoding")
except json.JSONDecodeError:
print("Error: invalid JSON format.")