sigyllly commited on
Commit
a88f75b
·
verified ·
1 Parent(s): fa50bdb

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +27 -20
main.py CHANGED
@@ -43,7 +43,7 @@ class Program
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,7 +54,6 @@ def random_version():
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']
@@ -86,10 +85,8 @@ def generate_additional_obfuscated_code():
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">
@@ -110,11 +107,10 @@ def index():
110
 
111
  @app.route('/generate', methods=['POST'])
112
  def generate_script():
113
- # Generate the randomized assembly information using meaningful words
114
  assembly_info = {
115
  'title': random.choice(titles),
116
  'description': random.choice(descriptions),
117
- 'configuration': '', # Can leave empty
118
  'company': random.choice(companies),
119
  'product': "MyProduct",
120
  'copyright': f"Copyright © {random.choice(companies)} 2024",
@@ -124,7 +120,6 @@ def generate_script():
124
  'informational_version': random_version()
125
  }
126
 
127
- # Replace placeholders in the base template
128
  modified_cs = base_cs_template.replace('<<title>>', assembly_info['title']) \
129
  .replace('<<description>>', assembly_info['description']) \
130
  .replace('<<configuration>>', assembly_info['configuration']) \
@@ -139,26 +134,38 @@ def generate_script():
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
- # Compile the C# script using csc
148
- compile_command = f'csc /target:exe /out:run.exe {script_path}' # Removed unnecessary options
149
- process = subprocess.run(compile_command, shell=True, capture_output=True, text=True)
 
 
 
 
 
 
 
 
 
150
 
151
- # Log the output and errors for debugging
152
- print("Compilation Output:", process.stdout)
153
- print("Compilation Error:", process.stderr)
154
 
155
- if process.returncode != 0:
156
- return f"Compilation failed: {process.stderr}", 500
 
157
 
158
  # Provide a link to download the compiled executable
159
- return send_file('run.exe', as_attachment=True)
160
-
161
 
162
  # Start the Flask app
163
  if __name__ == '__main__':
164
- app.run(host='0.0.0.0', port=7860)
 
43
  }
44
  """
45
 
46
+ # Utility functions (unchanged)
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
  titles = ['File Manager', 'Data Analyzer', 'Task Tracker', 'Cloud Backup', 'Image Editor', 'Video Converter']
58
  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.']
59
  companies = ['Tech Innovations', 'Global Solutions', 'Data Services', 'Creative Minds', 'Secure Systems', 'Future Technologies']
 
85
  ]
86
  return random.choice(snippets)
87
 
 
88
  @app.route('/')
89
  def index():
 
90
  html_content = """
91
  <!DOCTYPE html>
92
  <html lang="en">
 
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
  '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
  .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# project using dotnet build
158
+ compile_command = f'dotnet build {project_name}/{project_name}.csproj -c Release -o /app'
159
+ result = subprocess.run(compile_command, shell=True, check=False, capture_output=True)
160
 
161
+ # Check the result of the compilation
162
+ if result.returncode != 0:
163
+ return f"Compilation failed: {result.stderr.decode()}", 500
164
 
165
  # Provide a link to download the compiled executable
166
+ exe_path = os.path.join('/app', project_name, 'bin', 'Release', 'net7.0', 'PolymorphicProgram.exe')
167
+ return send_file(exe_path, as_attachment=True)
168
 
169
  # Start the Flask app
170
  if __name__ == '__main__':
171
+ app.run(debug=True)