This commit is contained in:
2025-08-15 20:12:35 -07:00
parent c686e60ec5
commit 387c694efe
14 changed files with 2724 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
import argparse
import sys
from pathlib import Path
from obfuscator import AdvancedObfuscator
def main():
parser = argparse.ArgumentParser(description="OMG-Fuscator: Advanced Python Code Obfuscator")
parser.add_argument("-i", "--input", type=str, help="Input Python file path")
parser.add_argument("-o", "--output", type=str, help="Output file path (default: input_obfuscated.py)")
parser.add_argument("--test", action="store_true", help="Run test with sample code")
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output")
args = parser.parse_args()
obfuscator = AdvancedObfuscator()
if args.test:
# Example test code that includes a top-level function
test_code = r'''
def my_top_level_func(a, b):
return a + b
def compare_versions(v1, v2):
return (v1 > v2) - (v1 < v2)
def main():
print("my_top_level_func(2,3) =", my_top_level_func(2,3))
version = 2
latest = 1
if compare_versions(version, latest) > 0:
print("version is higher")
else:
print("version is not higher")
main()
'''
if args.verbose:
print("Running in test mode with sample code...")
obfuscated = obfuscator.obfuscate(test_code)
print("Obfuscated test code:")
print(obfuscated)
print("\nExecuting obfuscated code:")
exec_namespace = {}
exec(obfuscated, exec_namespace, exec_namespace)
sys.exit(0)
if not args.input:
parser.error("Please provide an input file with -i or use --test")
in_path = Path(args.input)
if not in_path.exists():
parser.error(f"Input file not found: {in_path}")
if in_path.suffix != '.py':
parser.error("Input file must be a .py file")
out_path = Path(args.output) if args.output else in_path.parent / f"{in_path.stem}_obfuscated.py"
try:
if args.verbose:
print(f"Reading file: {in_path}")
with open(in_path, "r", encoding="utf-8") as fin:
src_code = fin.read()
if args.verbose:
print("Obfuscating...")
final_code = obfuscator.obfuscate(src_code)
if args.verbose:
print(f"Writing obfuscated code to: {out_path}")
with open(out_path, "w", encoding="utf-8") as fout:
fout.write(final_code)
print(f"Obfuscated code written to: {out_path}")
except Exception as e:
print(f"Error during obfuscation: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()