Files
pyhumor/源码/source/gen-attachment.ps1
2025-04-15 10:38:51 +08:00

64 lines
2.0 KiB
PowerShell

# 确保工作目录为脚本所在目录
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $scriptDir
# 确保 Python 版本为 3.10
$pythonVersion = & python --version 2>&1
if ($pythonVersion -notlike "Python 3.10*") {
Write-Host "`n[!] Python 版本不是 3.10,当前版本为 $pythonVersion" -ForegroundColor Red
exit 1
}
# 编译混淆器运行时
Set-Location "obfuscator"
Write-Host "`n[+] 正在编译混淆器运行时...`n" -ForegroundColor Cyan
$env:INCLUDE="$env:INCLUDE;C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared"
$env:LIB="$env:LIB;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64"
& python setup.py build
if ($LASTEXITCODE -ne 0) {
Write-Host "`n[!] 编译混淆器运行时失败!" -ForegroundColor Red
exit 1
}
# 确保存在 pycryptodome 库
$pycryptodome = & pip list 2>&1 | Select-String "pycryptodome"
if (-not $pycryptodome) {
Write-Host "`n[!] pycryptodome 库未安装,正在安装..." -ForegroundColor Yellow
& pip install pycryptodome
if ($LASTEXITCODE -ne 0) {
Write-Host "`n[!] 安装 pycryptodome 库失败!" -ForegroundColor Red
exit 1
}
}
# 生成混淆脚本
Set-Location "../task-src"
Write-Host "`n[+] 正在生成混淆脚本..." -ForegroundColor Cyan
& python get-obfuscated.py
if ($LASTEXITCODE -ne 0) {
Write-Host "`n[!] 生成混淆脚本失败!" -ForegroundColor Red
exit 1
}
# 生成 pyc 附件
& python get-task-pyc.py
if ($LASTEXITCODE -ne 0) {
Write-Host "`n[!] 生成 pyc 附件失败!" -ForegroundColor Red
exit 1
}
# 打包附件
Write-Host "`n[+] 正在打包附件..." -ForegroundColor Cyan
$zipFile = "../attachment.zip"
if (Test-Path $zipFile) {
Remove-Item $zipFile
}
Compress-Archive -Path pyhumor.pyc,pyhumor_runtime.cp310-win_amd64.pyd -DestinationPath $zipFile
if ($LASTEXITCODE -ne 0) {
Write-Host "`n[!] 打包附件失败!" -ForegroundColor Red
exit 1
}
Write-Host "`n[+] 附件生成成功!可以运行 clean.ps1 清理临时文件。" -ForegroundColor Green
Set-Location $scriptDir