Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added modules/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added modules/__pycache__/m_decoder.cpython-310.pyc
Binary file not shown.
Binary file added modules/__pycache__/m_encoder.cpython-310.pyc
Binary file not shown.
Binary file added modules/__pycache__/m_obfuscate.cpython-310.pyc
Binary file not shown.
21 changes: 12 additions & 9 deletions modules/m_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __write(
value: str
) -> None:

d_path = os.path.join(self.output_dir_path, file_path)

with open(d_path, 'a+') as f:
with open(file_path, 'a+') as f:
f.write(value)

def __get_program_struct(
Expand All @@ -43,30 +41,35 @@ def str_to_hex(

def execute(
self,
file_path: str,
input_file_path: str,
program_struct: Dict,
encoding_method: str
) -> None:

# Set program_struct as class vars
self.program_struct = program_struct

# Determine the output file path
input_filename = os.path.basename(input_file_path)
output_filename = os.path.splitext(input_filename)[0] + "_obfuscated.py"
output_file_path = os.path.join(self.output_dir_path, output_filename)

# Write the necessary libraries
self.__write(
file_path,
output_file_path,
"import base64, codecs \n"
)

# Write the encoding program's parts
for k, _ in program_struct.items():
encode_part = self.__get_program_struct(k, 'base64_encode')
to_write = f"{k} = '{encode_part}'\n"
self.__write(file_path, to_write)
self.__write(output_file_path, to_write)

# Write custom encoding method var
hex_name = self.str_to_hex(encoding_method)
to_write = f"{self.encoding_var} = '{hex_name}' \n"
self.__write( file_path, to_write)
self.__write(output_file_path, to_write)

# Write encoding program var
to_write = f"{self.execute_var} = \\\n"
Expand All @@ -81,10 +84,10 @@ def execute(
if ith != len(program_struct) - 1:
to_write += f" + \\\n"

self.__write(file_path, to_write)
self.__write(output_file_path, to_write)

# Write cmd to decode program
hex_name = self.str_to_hex(self.execute_var)
cmd = f"base64.b64decode(eval('{hex_name}')).decode('utf-8')"
to_write = f"\neval(compile({cmd},'<app>', 'exec'))"
self.__write(file_path, to_write)
self.__write(output_file_path, to_write)
2 changes: 1 addition & 1 deletion py_obfuscator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3.9
#!/usr/bin/env python3

import argparse
from modules.m_obfuscate import Obfuscate
Expand Down
1 change: 1 addition & 0 deletions testing_files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><body><script>console.log("Hello, World!");</script></body></html>
1 change: 1 addition & 0 deletions testing_files/sample-file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, World!")
4 changes: 4 additions & 0 deletions testing_files/test-lamba.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import json
def lambda_handler(event, context):
for i in range(1, 21):
print(i)
1 change: 1 addition & 0 deletions testing_files/test1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello, World!");
1 change: 1 addition & 0 deletions testing_files/test2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <iostream> int main() { std::cout << "Hello, World!"; return 0; }