Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -6,12 +6,13 @@ 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;
|
13 |
using System.IO;
|
14 |
using System.Reflection;
|
|
|
15 |
[assembly: AssemblyTitle("<<title>>")]
|
16 |
[assembly: AssemblyDescription("<<description>>")]
|
17 |
[assembly: AssemblyConfiguration("<<configuration>>")]
|
@@ -22,11 +23,13 @@ using System.Reflection;
|
|
22 |
[assembly: AssemblyVersion("<<version>>")]
|
23 |
[assembly: AssemblyFileVersion("<<file_version>>")]
|
24 |
[assembly: AssemblyInformationalVersion("<<informational_version>>")]
|
|
|
25 |
class Program
|
26 |
{
|
27 |
static void Main()
|
28 |
{
|
29 |
string originalFilePath = Path.Combine(Directory.GetCurrentDirectory(), "runtime.dll");
|
|
|
30 |
if (File.Exists(originalFilePath))
|
31 |
{
|
32 |
<<control_flow_junk>>
|
@@ -35,11 +38,12 @@ class Program
|
|
35 |
Environment.Exit(0); // Exit immediately
|
36 |
}
|
37 |
}
|
|
|
38 |
<<obfuscated_methods>>
|
39 |
}
|
40 |
"""
|
41 |
|
42 |
-
# Utility functions
|
43 |
def random_string(length):
|
44 |
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
|
45 |
|
@@ -50,6 +54,12 @@ def random_version():
|
|
50 |
revision = random.randint(0, 99)
|
51 |
return f"{major}.{minor}.{build}.{revision}"
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
def generate_control_flow_junk():
|
54 |
conditions = [
|
55 |
"if (DateTime.Now.Day % 2 == 0) { Console.WriteLine(\"Even day\"); }",
|
@@ -76,8 +86,10 @@ def generate_additional_obfuscated_code():
|
|
76 |
]
|
77 |
return random.choice(snippets)
|
78 |
|
|
|
79 |
@app.route('/')
|
80 |
def index():
|
|
|
81 |
html_content = """
|
82 |
<!DOCTYPE html>
|
83 |
<html lang="en">
|
@@ -96,9 +108,12 @@ def index():
|
|
96 |
"""
|
97 |
return render_template_string(html_content)
|
98 |
|
|
|
|
|
|
|
99 |
@app.route('/generate', methods=['POST'])
|
100 |
def generate_script():
|
101 |
-
# Generate assembly
|
102 |
assembly_info = {
|
103 |
'title': random.choice(titles),
|
104 |
'description': random.choice(descriptions),
|
@@ -112,7 +127,7 @@ def generate_script():
|
|
112 |
'informational_version': random_version()
|
113 |
}
|
114 |
|
115 |
-
# Replace placeholders
|
116 |
modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
|
117 |
.replace('<<description>>', assembly_info['description']) \
|
118 |
.replace('<<configuration>>', assembly_info['configuration']) \
|
@@ -127,30 +142,38 @@ def generate_script():
|
|
127 |
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
|
128 |
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
|
129 |
|
130 |
-
# Generate random names
|
131 |
-
script_name = random_string(10) + '.cs'
|
132 |
-
exe_name = random_string(10) + '.exe'
|
133 |
|
134 |
-
#
|
135 |
with open(script_name, 'w') as file:
|
136 |
file.write(modified_cs)
|
137 |
|
138 |
-
#
|
139 |
compile_command = [
|
140 |
-
'csc',
|
|
|
|
|
|
|
|
|
|
|
141 |
]
|
142 |
|
|
|
143 |
try:
|
144 |
result = subprocess.run(compile_command, capture_output=True, text=True, check=True)
|
145 |
except subprocess.CalledProcessError as e:
|
146 |
-
error_message = e.stderr.strip()
|
147 |
return f"Compilation failed: {error_message}", 500
|
148 |
except FileNotFoundError:
|
149 |
return "Compiler 'csc' not found. Make sure it is installed and in the PATH.", 500
|
150 |
|
151 |
-
# Provide a link to download the executable
|
152 |
return send_file(exe_name, as_attachment=True)
|
153 |
|
154 |
-
|
|
|
155 |
if __name__ == '__main__':
|
156 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
|
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;
|
13 |
using System.IO;
|
14 |
using System.Reflection;
|
15 |
+
|
16 |
[assembly: AssemblyTitle("<<title>>")]
|
17 |
[assembly: AssemblyDescription("<<description>>")]
|
18 |
[assembly: AssemblyConfiguration("<<configuration>>")]
|
|
|
23 |
[assembly: AssemblyVersion("<<version>>")]
|
24 |
[assembly: AssemblyFileVersion("<<file_version>>")]
|
25 |
[assembly: AssemblyInformationalVersion("<<informational_version>>")]
|
26 |
+
|
27 |
class Program
|
28 |
{
|
29 |
static void Main()
|
30 |
{
|
31 |
string originalFilePath = Path.Combine(Directory.GetCurrentDirectory(), "runtime.dll");
|
32 |
+
|
33 |
if (File.Exists(originalFilePath))
|
34 |
{
|
35 |
<<control_flow_junk>>
|
|
|
38 |
Environment.Exit(0); // Exit immediately
|
39 |
}
|
40 |
}
|
41 |
+
|
42 |
<<obfuscated_methods>>
|
43 |
}
|
44 |
"""
|
45 |
|
46 |
+
# Utility functions to generate random text and versions
|
47 |
def random_string(length):
|
48 |
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
|
49 |
|
|
|
54 |
revision = random.randint(0, 99)
|
55 |
return f"{major}.{minor}.{build}.{revision}"
|
56 |
|
57 |
+
# Lists of meaningful words for assembly info
|
58 |
+
titles = ['File Manager', 'Data Analyzer', 'Task Tracker', 'Cloud Backup', 'Image Editor', 'Video Converter']
|
59 |
+
descriptions = ['This application helps in managing files efficiently.', 'Analyze data with advanced algorithms and insights.', 'Keep track of your tasks and deadlines easily.', 'Backup your data securely to the cloud.', 'Edit your images with powerful tools and filters.', 'Convert videos to various formats quickly.']
|
60 |
+
companies = ['Tech Innovations', 'Global Solutions', 'Data Services', 'Creative Minds', 'Secure Systems', 'Future Technologies']
|
61 |
+
trademarks = ['Innovative Solutions', 'Smart Technology', 'NextGen Apps', 'Empowering Users', 'Reliable Services', 'Creative Design']
|
62 |
+
|
63 |
def generate_control_flow_junk():
|
64 |
conditions = [
|
65 |
"if (DateTime.Now.Day % 2 == 0) { Console.WriteLine(\"Even day\"); }",
|
|
|
86 |
]
|
87 |
return random.choice(snippets)
|
88 |
|
89 |
+
# Route to display the button and trigger C# script generation
|
90 |
@app.route('/')
|
91 |
def index():
|
92 |
+
# HTML embedded directly in the app using render_template_string
|
93 |
html_content = """
|
94 |
<!DOCTYPE html>
|
95 |
<html lang="en">
|
|
|
108 |
"""
|
109 |
return render_template_string(html_content)
|
110 |
|
111 |
+
|
112 |
+
# Other existing code remains unchanged...
|
113 |
+
|
114 |
@app.route('/generate', methods=['POST'])
|
115 |
def generate_script():
|
116 |
+
# Generate the randomized assembly information using meaningful words
|
117 |
assembly_info = {
|
118 |
'title': random.choice(titles),
|
119 |
'description': random.choice(descriptions),
|
|
|
127 |
'informational_version': random_version()
|
128 |
}
|
129 |
|
130 |
+
# Replace placeholders in the base template
|
131 |
modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
|
132 |
.replace('<<description>>', assembly_info['description']) \
|
133 |
.replace('<<configuration>>', assembly_info['configuration']) \
|
|
|
142 |
.replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
|
143 |
.replace('<<obfuscated_methods>>', generate_obfuscated_methods())
|
144 |
|
145 |
+
# Generate random file names for the script and executable
|
146 |
+
script_name = random_string(10) + '.cs' # Random name for the C# script
|
147 |
+
exe_name = random_string(10) + '.exe' # Random name for the executable
|
148 |
|
149 |
+
# Save the modified C# script to a file
|
150 |
with open(script_name, 'w') as file:
|
151 |
file.write(modified_cs)
|
152 |
|
153 |
+
# Use 'csc' compiler (Roslyn) with the right path
|
154 |
compile_command = [
|
155 |
+
'/usr/local/roslyn/Microsoft.Net.Compilers.4.0.1/tools/csc', # Full path to Roslyn's csc
|
156 |
+
'-target:winexe',
|
157 |
+
'-out:' + exe_name,
|
158 |
+
script_name,
|
159 |
+
'-win32icon:app.ico',
|
160 |
+
'-win32manifest:app.manifest'
|
161 |
]
|
162 |
|
163 |
+
# Run the compilation command
|
164 |
try:
|
165 |
result = subprocess.run(compile_command, capture_output=True, text=True, check=True)
|
166 |
except subprocess.CalledProcessError as e:
|
167 |
+
error_message = e.stderr.strip() # Capture the standard error output
|
168 |
return f"Compilation failed: {error_message}", 500
|
169 |
except FileNotFoundError:
|
170 |
return "Compiler 'csc' not found. Make sure it is installed and in the PATH.", 500
|
171 |
|
172 |
+
# Provide a link to download the compiled executable
|
173 |
return send_file(exe_name, as_attachment=True)
|
174 |
|
175 |
+
|
176 |
+
# Start the Flask app
|
177 |
if __name__ == '__main__':
|
178 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
179 |
+
|