# Compiles PyInstaller's bootloader from source and installs it into the PyInstaller this PC uses. # # Why: the stock bootloader (the small launcher inside openhop.exe) is byte-for-byte the same one that # thousands of malware samples are packed with, so antivirus engines flag anything that contains it. # A bootloader compiled here is unique to openhop, which removes most of those false positives. # # Needs: Visual Studio Build Tools (C++ workload). Run once per PyInstaller version; build.ps1 warns # when the installed bootloader is still the stock one. # .\tools\build_bootloader.ps1 $ErrorActionPreference = "Stop" $ver = (& python -m PyInstaller --version).Trim() $inst = (& python -c "import PyInstaller,os;print(os.path.join(os.path.dirname(PyInstaller.__file__),'bootloader','Windows-64bit-intel'))").Trim() $work = Join-Path $env:TEMP "openhop-bootloader-$ver" New-Item -ItemType Directory -Force $work | Out-Null # 1. PyInstaller source from PyPI, checked against PyPI's own hash $meta = Invoke-RestMethod "https://pypi.org/pypi/pyinstaller/$ver/json" $sdist = $meta.urls | Where-Object packagetype -eq "sdist" | Select-Object -First 1 $tgz = Join-Path $work $sdist.filename if (-not (Test-Path $tgz)) { Invoke-WebRequest $sdist.url -OutFile $tgz } if ((Get-FileHash $tgz -Algorithm SHA256).Hash.ToLower() -ne $sdist.digests.sha256) { throw "Downloaded source doesn't match PyPI's hash" } tar -xzf $tgz -C $work 2>$null # a few test files fail to unpack on Windows; the bootloader doesn't need them $src = Join-Path $work "pyinstaller-$ver\bootloader" if (-not (Test-Path (Join-Path $src "wscript"))) { throw "Bootloader source not found in $src" } # 2. Compile (waf finds MSVC by itself) Push-Location $src try { & python ./waf all --target-arch=64bit | Select-Object -Last 3 } finally { Pop-Location } $built = Join-Path $work "pyinstaller-$ver\PyInstaller\bootloader\Windows-64bit-intel" # 3. Install, keeping the stock files as *.stock foreach ($f in "run.exe", "runw.exe", "run_d.exe", "runw_d.exe") { $dst = Join-Path $inst $f if (-not (Test-Path "$dst.stock")) { Copy-Item $dst "$dst.stock" } Copy-Item (Join-Path $built $f) $dst -Force } "PyInstaller $ver, compiled $(Get-Date -Format s)" | Set-Content (Join-Path $inst "openhop-custom.txt") Write-Host "Custom bootloader installed in $inst"