Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -6,7 +6,7 @@ from flask import Flask, render_template_string, send_file
|
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
-
# Define the base C# template without AssemblyCulture
|
10 |
base_cs_template = """
|
11 |
using System;
|
12 |
using System.Diagnostics;
|
@@ -110,10 +110,6 @@ def index():
|
|
110 |
|
111 |
@app.route('/generate', methods=['POST'])
|
112 |
def generate_script():
|
113 |
-
# Create uploads directory if it doesn't exist
|
114 |
-
uploads_dir = 'uploads'
|
115 |
-
os.makedirs(uploads_dir, exist_ok=True)
|
116 |
-
|
117 |
# Step 7: Generate the randomized assembly information using meaningful words
|
118 |
assembly_info = {
|
119 |
'title': random.choice(titles),
|
@@ -143,25 +139,25 @@ def generate_script():
|
|
143 |
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
|
144 |
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
|
145 |
|
146 |
-
# Save the modified C# script to a file
|
147 |
-
script_path =
|
148 |
with open(script_path, 'w') as file:
|
149 |
file.write(modified_cs)
|
150 |
|
151 |
-
# Step 10: Compile the C# script using
|
152 |
-
compile_command = f'
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
if result.returncode != 0:
|
158 |
-
#
|
159 |
-
|
160 |
-
|
|
|
161 |
|
162 |
# Provide a link to download the compiled executable
|
163 |
-
return send_file('
|
164 |
|
165 |
# Start the Flask app
|
166 |
if __name__ == '__main__':
|
167 |
-
|
|
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
+
# Step 1: Define the base C# template without AssemblyCulture
|
10 |
base_cs_template = """
|
11 |
using System;
|
12 |
using System.Diagnostics;
|
|
|
110 |
|
111 |
@app.route('/generate', methods=['POST'])
|
112 |
def generate_script():
|
|
|
|
|
|
|
|
|
113 |
# Step 7: Generate the randomized assembly information using meaningful words
|
114 |
assembly_info = {
|
115 |
'title': random.choice(titles),
|
|
|
139 |
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
|
140 |
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
|
141 |
|
142 |
+
# Save the modified C# script to a file
|
143 |
+
script_path = 'polymorphic_program.cs'
|
144 |
with open(script_path, 'w') as file:
|
145 |
file.write(modified_cs)
|
146 |
|
147 |
+
# Step 10: Compile the C# script using dotnet
|
148 |
+
compile_command = f'dotnet build {script_path} -o /app/out'
|
149 |
+
print(f"Running compile command: {compile_command}") # Debugging line
|
150 |
+
result = subprocess.run(compile_command, shell=True, check=False)
|
151 |
+
|
|
|
152 |
if result.returncode != 0:
|
153 |
+
print("Compilation failed!") # Debugging line
|
154 |
+
return "Compilation failed!", 500
|
155 |
+
|
156 |
+
print("Compilation succeeded!") # Debugging line
|
157 |
|
158 |
# Provide a link to download the compiled executable
|
159 |
+
return send_file('/app/out/polymorphic_program.dll', as_attachment=True)
|
160 |
|
161 |
# Start the Flask app
|
162 |
if __name__ == '__main__':
|
163 |
+
app.run(debug=True)
|