sigyllly commited on
Commit
7320811
·
verified ·
1 Parent(s): f521c80

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +18 -28
main.py CHANGED
@@ -107,10 +107,11 @@ def index():
107
 
108
  @app.route('/generate', methods=['POST'])
109
  def generate_script():
 
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",
@@ -120,6 +121,7 @@ def generate_script():
120
  'informational_version': random_version()
121
  }
122
 
 
123
  modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
124
  .replace('<<description>>', assembly_info['description']) \
125
  .replace('<<configuration>>', assembly_info['configuration']) \
@@ -134,42 +136,30 @@ def generate_script():
134
  .replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
135
  .replace('<<obfuscated_methods>>', generate_obfuscated_methods())
136
 
137
- # Save the modified C# script to a temporary project folder
138
- project_name = 'PolymorphicProgram'
139
- os.makedirs(project_name, exist_ok=True)
140
- script_path = os.path.join(project_name, 'Program.cs')
141
  with open(script_path, 'w') as file:
142
  file.write(modified_cs)
143
 
144
- # Create a project file
145
- project_file_content = f"""
146
- <Project Sdk="Microsoft.NET.Sdk">
147
- <PropertyGroup>
148
- <OutputType>WinExe</OutputType>
149
- <TargetFramework>net7.0</TargetFramework>
150
- </PropertyGroup>
151
- </Project>
152
- """
153
- project_file_path = os.path.join(project_name, f"{project_name}.csproj")
154
- with open(project_file_path, 'w') as file:
155
- file.write(project_file_content)
156
-
157
- # Step 10: Compile the C# script using dotnet
158
- compile_command = f'dotnet build {script_path.replace(".cs", ".csproj")} -c Release -o /app'
159
-
160
  try:
161
- result = subprocess.run(compile_command, shell=True, check=True, text=True, capture_output=True)
162
- print(f"Compilation succeeded: {result.stdout}") # Log the successful output
163
- except subprocess.CalledProcessError as e:
164
- print(f"Compilation failed with return code {e.returncode}") # Log the return code
165
- print(f"stdout: {e.stdout}") # Log the standard output
166
- print(f"stderr: {e.stderr}") # Log the standard error
167
- return f"Compilation failed: {e.stderr.strip()}", 500
 
 
 
 
168
 
169
  # Provide a link to download the compiled executable
170
  return send_file('run.exe', as_attachment=True)
171
 
172
 
 
173
  # Start the Flask app
174
  if __name__ == '__main__':
175
  app.run(host='0.0.0.0', port=7860, debug=True)
 
107
 
108
  @app.route('/generate', methods=['POST'])
109
  def generate_script():
110
+ # Step 7: Generate the randomized assembly information using meaningful words
111
  assembly_info = {
112
  'title': random.choice(titles),
113
  'description': random.choice(descriptions),
114
+ 'configuration': '', # Can leave empty
115
  'company': random.choice(companies),
116
  'product': "MyProduct",
117
  'copyright': f"Copyright © {random.choice(companies)} 2024",
 
121
  'informational_version': random_version()
122
  }
123
 
124
+ # Step 8: Replace placeholders in the base template
125
  modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
126
  .replace('<<description>>', assembly_info['description']) \
127
  .replace('<<configuration>>', assembly_info['configuration']) \
 
136
  .replace('<<additional_obfuscated_code>>', generate_additional_obfuscated_code()) \
137
  .replace('<<obfuscated_methods>>', generate_obfuscated_methods())
138
 
139
+ # Save the modified C# script to a file
140
+ script_path = 'polymorphic_program.cs'
 
 
141
  with open(script_path, 'w') as file:
142
  file.write(modified_cs)
143
 
144
+ # Step 10: Locate csc and compile the C# script
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  try:
146
+ # Find the path to csc
147
+ csc_path = subprocess.run(['which', 'csc'], capture_output=True, text=True, check=True).stdout.strip()
148
+ except subprocess.CalledProcessError:
149
+ return "csc not found. Make sure the .NET SDK is installed.", 500
150
+
151
+ # Compile the C# script
152
+ compile_command = f'{csc_path} /target:winexe /platform:x64 /out:run.exe {script_path} /win32icon:app.ico /win32manifest:app.manifest'
153
+ compile_result = subprocess.run(compile_command, shell=True, check=True, capture_output=True)
154
+
155
+ if compile_result.returncode != 0:
156
+ return f"Compilation failed: {compile_result.stderr.decode()}", 500
157
 
158
  # Provide a link to download the compiled executable
159
  return send_file('run.exe', as_attachment=True)
160
 
161
 
162
+
163
  # Start the Flask app
164
  if __name__ == '__main__':
165
  app.run(host='0.0.0.0', port=7860, debug=True)