/
smuggler.py
executable file
·155 lines (137 loc) · 3.82 KB
/
smuggler.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
import os
import sys
from slimit import minify
# Lookup table
symbols = {
'a': '((!!+[]+"")[+!![]])',
'b': '((({})+"")[(+!![])+(+!![])])',
'c': '((({})+"")[(+!![])+(+!![])+(+!![])+(+!![])+(+!![])])',
'd': '((({})[""]+"")[(+!![])+(+!![])])',
'e': '((!!+[]+"")[(+!![])+(+!![])+(+!![])+(+!![])])',
'f': '((!!+[]+"")[+[]])',
'g': '"\\x67"',
'h': '"\\x68"',
'i': '((+!![]/+[]+"")[(+!![])+(+!![])+(+!![])])',
'j': '((({})+"")[(+!![])+(+!![])+(+!![])])',
'k': '"\\x6B"',
'l': '((!!+[]+"")[(+!![])+(+!![])])',
'm': '"\\x6D"',
'n': '((+!![]/+[]+"")[+!![]])',
'o': '((({})+"")[+!![]])',
'p': '"\\x70"',
'q': '"\\x71"',
'r': '((!+[]+"")[+!![]])',
's': '((!!+[]+"")[(+!![])+(+!![])+(+!![])])',
't': '((!+[]+"")[+[]])',
'u': '((!+[]+"")[(+!![])+(+!![])])',
'v': '"\\x76"',
'w': '"\\x77"',
'x': "'x'",
'y': '((+!![]/+[]+"")[(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])])',
'z': '"\\x7A"',
'A': '"\\x41"',
'B': '"\\x42"',
'C': '"\\x43"',
'D': '"\\x44"',
'E': '"\\x45"',
'F': '"\\x46"',
'G': '"\\x47"',
'H': '"\\x48"',
'I': '((+!![]/+[]+"")[+[]])',
'J': '"\\x4A"',
'K': '"\\x4B"',
'L': '"\\x4C"',
'M': '"\\x4D"',
'N': '((+[]/+[]+"")[+[]])',
'O': '((({})+"")[(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])])',
'P': '"\\x50"',
'Q': '"\\x51"',
'R': '"\\x52"',
'S': '"\\x53"',
'T': '"\\x54"',
'U': '"\\x55"',
'V': '"\\x56"',
'W': '"\\x57"',
'X': '"\\x58"',
'Y': '"\\x59"',
'Z': '"\\x5A"',
"(": "'('",
")": "')'",
"{": "'{'",
"}": "'}'",
"[": "'['",
"]": "']'",
".": "'.'",
";": "';'",
"@": "'@'",
"*": "'*'",
'"': "'\"'",
"/": "'/'",
":": "':'",
",": "','",
"'": '"\'"',
"=": "'='",
">": "'>'",
"<": "'<'",
"!": "'!'",
"$": "'$'",
"_": "'_'",
"#": "'#'",
"+": "'+'",
"-": "'-'",
"%": "'%'",
" ": "' '",
"?": "'?'",
"|": "'|'",
"^": "'^'",
"&": "'&'",
"~": "'~'",
"`": "'`'",
"\\": "'\\\\'",
"0": "(+[])",
"1": "(+!![])",
"2": "((+!![])+(+!![]))",
"3": "((+!![])+(+!![])+(+!![]))",
"4": "((+!![])+(+!![])+(+!![])+(+!![]))",
"5": "((+!![])+(+!![])+(+!![])+(+!![])+(+!![]))",
"6": "((+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![]))",
"7": "((+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![]))",
"8": "((+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![]))",
"9": "((+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![])+(+!![]))"
}
def absFilePaths(dir):
for basename, dirs, files in os.walk(dir):
for f in files:
yield os.path.abspath(os.path.join(basename, f))
def convert_str(code, wrap=False):
out = []
minified = minify(code)
for i in range(len(minified) - 1):
out.append(symbols[minified[i]] + "+") # All
out.append(symbols[minified[-1]]) # Last char
out = "".join(out)
if wrap:
out = "".join(["eval(", out, ");"])
return out
def convert_file(script, rename=True):
filename, extension = os.path.splitext(script)
if extension != ".js":
return False
with open(script, "r") as in_script:
src = in_script.read()
out = convert_str(src, True)
new_filename = "".join([filename, "-smug" if rename else "", extension])
with open(new_filename, "w") as out_script:
out_script.write(out)
def convert_dir(dir, rename=True):
for filename in absFilePaths(dir):
convert_file(filename, rename)
if __name__ == "__main__":
if len(sys.argv) < 2:
exit("No Input file...")
source = sys.argv[1]
if os.path.isfile(source):
convert_file(source)
elif os.path.isdir(source):
convert_dir(source)