forked from nottherealtar/PyObfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyob.py
64 lines (48 loc) · 2.05 KB
/
pyob.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
import os
import sys
import random
import string
ERROR = "\x1b[38;5;255m[\x1b[31m-\x1b[38;5;255m]"
SUCCESS = "\x1b[38;5;255m[\x1b[32m+\x1b[38;5;255m]"
def set_terminal_properties():
os.system("mode 80,18 & title goinggone & powershell $H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=80;$B.height=9999;$W.buffersize=$B;")
def exit_program():
input("Press any key to continue...")
sys.exit()
def generate_dummy_code():
func_name = "".join(random.choices(string.ascii_lowercase, k=5))
var_name = "".join(random.choices(string.ascii_lowercase, k=5))
dummy_code = f'''
import random
class DummyClass_{func_name.capitalize()}:
def __init__(self, {var_name}):
self.{var_name} = {var_name}
def dummy_method(self):
data = [random.randint(0, 100) for _ in range(10)]
return sum(data) / len(data)
def dummy_function_{func_name}({var_name}):
dummy_obj = DummyClass_{func_name.capitalize()}({var_name})
result = dummy_obj.dummy_method()
print(f'Dummy result: {{result}}')
dummy_variable_{var_name} = dummy_function_{func_name}(random.randint(0, 100))
'''
return dummy_code
def intersperse_dummy_code(original_code):
dummy_code_start = '\n'.join([generate_dummy_code() for _ in range(15)]) # Generating 15 dummy code blocks
dummy_code_end = '\n'.join([generate_dummy_code() for _ in range(15)]) # Generating 15 dummy code blocks
obfuscated_code = f"{dummy_code_start}\n{original_code}\n{dummy_code_end}"
return obfuscated_code
def main():
set_terminal_properties()
if not os.path.exists("main.py"):
print(f"{ERROR} Please locate file main.py\n")
exit_program()
with open("main.py", "r") as file:
original_code = file.read()
obfuscated_code = intersperse_dummy_code(original_code)
with open("final.py", "w") as file:
file.write(obfuscated_code)
print(f"{SUCCESS} Obfuscation complete. Obfuscated code saved as final.py\n")
exit_program()
if __name__ == "__main__":
main()