-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompress_python_scripts.py
More file actions
62 lines (49 loc) · 2.14 KB
/
compress_python_scripts.py
File metadata and controls
62 lines (49 loc) · 2.14 KB
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
import argparse
import os
import sys
def banner():
print('<<< PythonScript-Compressor v1.0>>>')
print(r'''
_
| |
| |___
| _ \ _ _
| |_) | (_) |
\____/ \__, |
__/ |
|___/
_ _
| | (_)
____ ____ ___| | ___ _ ______ ______ ___ _ ______ ______ _ _ ____
/ ___\ / \ / _ | / _ | | / ____| / ____| / _ | | / ____| / ____| | | | | | \
| |____ | () | | (_| | | (_|| | \_____ \ \_____ \ | (_|| | \_____ \ \_____ \ | | | | | |
\____/ \____/ \____/ \___|_| |______/ |______/ \___|_| |______/ |______/ |_| |_| |_|
''')
if __name__ == '__main__':
banner()
try:
parser = argparse.ArgumentParser()
parser.add_argument("script", type=str)
args = parser.parse_args()
if not os.path.exists(args.script):
sys.stderr.write(f"'{args.script}' not a file")
with open(args.script, "rb") as h:
contents = h.read().decode('utf-8')
code = "+".join([f"chr({ord(x)})" for x in contents])
code = f"{code}"
script = "+".join([f"chr({ord(x)})" for x in "<script>"])
script = f"{script}"
executable = "+".join([f"chr({ord(x)})" for x in "exec"])
executable = f"{executable}"
compressedCommand = f'python -c "exec(compile({code}, {script}, {executable}))"'
with open('scripts.csv', 'r+') as f:
myDataList = f.readlines()
nameList = []
for line in myDataList:
entry = line.split(',')
nameList.append(entry[0])
if args.script not in nameList:
f.writelines(f'\n{args.script},{compressedCommand}')
print("[+] The compressed command is: (just copy the command and run)\n\t" + compressedCommand)
except Exception as e:
print(f"[-] ERROR: {e}")