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 |
-
#
|
10 |
base_cs_template = """
|
11 |
using System;
|
12 |
using System.Diagnostics;
|
@@ -110,6 +110,10 @@ def index():
|
|
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,25 +143,18 @@ def generate_script():
|
|
139 |
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
|
140 |
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
|
141 |
|
142 |
-
#
|
143 |
-
script_path = os.path.join(
|
144 |
-
|
145 |
-
|
146 |
-
file.write(modified_cs)
|
147 |
-
except PermissionError:
|
148 |
-
return "Permission denied. Could not write the script file.", 500
|
149 |
|
150 |
# Step 10: Compile the C# script using csc
|
151 |
-
|
152 |
-
|
153 |
-
subprocess.run(compile_command, shell=False, check=True)
|
154 |
-
except subprocess.CalledProcessError as e:
|
155 |
-
return f"Compilation failed: {e}", 500
|
156 |
|
157 |
# Provide a link to download the compiled executable
|
158 |
return send_file('run.exe', as_attachment=True)
|
159 |
|
160 |
-
|
161 |
# Start the Flask app
|
162 |
if __name__ == '__main__':
|
163 |
-
|
|
|
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 |
|
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 |
.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 in the uploads directory
|
147 |
+
script_path = os.path.join(uploads_dir, 'polymorphic_program.cs')
|
148 |
+
with open(script_path, 'w') as file:
|
149 |
+
file.write(modified_cs)
|
|
|
|
|
|
|
150 |
|
151 |
# Step 10: Compile the C# script using csc
|
152 |
+
compile_command = f'csc /target:winexe /platform:x64 /out:run.exe {script_path} /win32icon:app.ico /win32manifest:app.manifest'
|
153 |
+
subprocess.run(compile_command, shell=True, check=False)
|
|
|
|
|
|
|
154 |
|
155 |
# Provide a link to download the compiled executable
|
156 |
return send_file('run.exe', as_attachment=True)
|
157 |
|
|
|
158 |
# Start the Flask app
|
159 |
if __name__ == '__main__':
|
160 |
+
app.run(host='0.0.0.0', port=7860)
|