first_look: clear stale exe json report before pe_inspect runs

This commit is contained in:
kirigayakazima
2026-11-27 20:02:34 +08:00
parent 18a9ec373c
commit f43076b07f
2 changed files with 10 additions and 3 deletions

View File

@ -36,6 +36,8 @@ $hash = (Get-FileHash -LiteralPath $Exe -Algorithm SHA256).Hash.ToLower()
"sha256 $hash size $size" | Tee-Object -LiteralPath (Join-Path $out "hash.txt")
Write-Host "`n== PE inspection"
$reportPath = Join-Path $out "$([IO.Path]::GetFileName($Exe)).json"
if (Test-Path -LiteralPath $reportPath -PathType Leaf) { Remove-Item -LiteralPath $reportPath -Force }
python -I (Join-Path $root "tools\pe_inspect.py") $Exe --game-dir $GameDir --out $out
if ($LASTEXITCODE -ne 0) { throw "pe_inspect failed" }
@ -116,7 +118,6 @@ Write-Host "`n== Loader dry run (map, relocate, bind imports; nothing executes)"
$dryRunExitCode = $LASTEXITCODE
# Shim to-do list, grouped by DLL, most functions first.
$reportPath = Join-Path $out "$([IO.Path]::GetFileName($Exe)).json"
if (-not (Test-Path -LiteralPath $reportPath -PathType Leaf)) { throw "pe_inspect did not write $reportPath" }
$report = Get-Content -LiteralPath $reportPath -Raw | ConvertFrom-Json
$todo = $report.imports | Where-Object { $_.where -eq "shim" } | Sort-Object { -$_.functions.Count }

View File

@ -44,6 +44,7 @@ class FirstLookSafetyTests(unittest.TestCase):
self.assertIn("$read -ne 2", text)
self.assertIn("$global:LASTEXITCODE = 0", text)
self.assertIn("build_runtime.ps1 failed ($LASTEXITCODE)", text)
self.assertIn("Remove-Item -LiteralPath $reportPath -Force", text)
self.assertIn("Test-Path -LiteralPath $reportPath -PathType Leaf", text)
self.assertIn("pe_inspect did not write $reportPath", text)
@ -144,11 +145,16 @@ class FirstLookSafetyTests(unittest.TestCase):
now = time.time() + 10
os.utime(loader, (now, now))
# 7. Missing pe_inspect JSON report fails before ConvertFrom-Json.
(out_dir / "game.exe.json").unlink()
# 7. Stale report from a prior run is cleared before pe_inspect runs, so skipping output fails.
(out_dir / "game.exe.json").write_text(
'{"imports":[{"where":"shim","dll":"stale_old.dll","functions":["Foo"]}],"sections":[]}',
encoding="utf-8",
newline="\n",
)
res = run_ps("-Exe", str(exe), extra_env={"LEONIDA_SKIP_PE_REPORT": "1"})
self.assertNotEqual(res.returncode, 0, res.stdout + res.stderr)
self.assertIn("pe_inspect did not write", res.stdout + res.stderr)
self.assertNotIn("stale_old.dll", res.stdout + res.stderr)
if __name__ == "__main__":