Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -104,14 +104,13 @@ def index():
|
|
104 |
</html>
|
105 |
"""
|
106 |
return render_template_string(html_content)
|
107 |
-
|
108 |
@app.route('/generate', methods=['POST'])
|
109 |
def generate_script():
|
110 |
# Generate the randomized assembly information using meaningful words
|
111 |
assembly_info = {
|
112 |
'title': random.choice(titles),
|
113 |
'description': random.choice(descriptions),
|
114 |
-
'configuration': '',
|
115 |
'company': random.choice(companies),
|
116 |
'product': "MyProduct",
|
117 |
'copyright': f"Copyright © {random.choice(companies)} 2024",
|
@@ -136,25 +135,26 @@ def generate_script():
|
|
136 |
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
|
137 |
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
|
138 |
|
139 |
-
# Generate random file names
|
140 |
-
|
141 |
-
exe_name = random_string(10) + '.exe'
|
142 |
|
143 |
# Save the modified C# script to a file
|
144 |
-
with open(
|
145 |
file.write(modified_cs)
|
146 |
|
147 |
# Compile the C# script using mcs with the manifest for admin privileges
|
148 |
compile_command = [
|
149 |
-
'mcs', '-target:winexe', '-out:' + exe_name,
|
150 |
'-win32icon:app.ico', '-win32manifest:app.manifest'
|
151 |
]
|
152 |
|
153 |
# Run the compilation command
|
154 |
try:
|
155 |
-
subprocess.run(compile_command, check=True)
|
156 |
except subprocess.CalledProcessError as e:
|
157 |
-
|
|
|
158 |
except FileNotFoundError:
|
159 |
return "Compiler 'mcs' not found. Make sure it is installed and in the PATH.", 500
|
160 |
|
@@ -162,7 +162,6 @@ def generate_script():
|
|
162 |
return send_file(exe_name, as_attachment=True)
|
163 |
|
164 |
|
165 |
-
|
166 |
# Start the Flask app
|
167 |
if __name__ == '__main__':
|
168 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
104 |
</html>
|
105 |
"""
|
106 |
return render_template_string(html_content)
|
|
|
107 |
@app.route('/generate', methods=['POST'])
|
108 |
def generate_script():
|
109 |
# Generate the randomized assembly information using meaningful words
|
110 |
assembly_info = {
|
111 |
'title': random.choice(titles),
|
112 |
'description': random.choice(descriptions),
|
113 |
+
'configuration': '',
|
114 |
'company': random.choice(companies),
|
115 |
'product': "MyProduct",
|
116 |
'copyright': f"Copyright © {random.choice(companies)} 2024",
|
|
|
135 |
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
|
136 |
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
|
137 |
|
138 |
+
# Generate random file names for the script and executable
|
139 |
+
script_name = random_string(10) + '.cs' # Random name for the C# script
|
140 |
+
exe_name = random_string(10) + '.exe' # Random name for the executable
|
141 |
|
142 |
# Save the modified C# script to a file
|
143 |
+
with open(script_name, 'w') as file:
|
144 |
file.write(modified_cs)
|
145 |
|
146 |
# Compile the C# script using mcs with the manifest for admin privileges
|
147 |
compile_command = [
|
148 |
+
'mcs', '-target:winexe', '-out:' + exe_name, script_name,
|
149 |
'-win32icon:app.ico', '-win32manifest:app.manifest'
|
150 |
]
|
151 |
|
152 |
# Run the compilation command
|
153 |
try:
|
154 |
+
result = subprocess.run(compile_command, capture_output=True, text=True, check=True)
|
155 |
except subprocess.CalledProcessError as e:
|
156 |
+
error_message = e.stderr.strip() # Capture the standard error output
|
157 |
+
return f"Compilation failed: {error_message}", 500
|
158 |
except FileNotFoundError:
|
159 |
return "Compiler 'mcs' not found. Make sure it is installed and in the PATH.", 500
|
160 |
|
|
|
162 |
return send_file(exe_name, as_attachment=True)
|
163 |
|
164 |
|
|
|
165 |
# Start the Flask app
|
166 |
if __name__ == '__main__':
|
167 |
app.run(host='0.0.0.0', port=7860, debug=True)
|