Files
mandy/scripts/first_look.ps1
Tomgamer 41cb7c541c pe_inspect.py: one report per input image (same-stem inputs overwrote each other)
Reports were named after the image's stem, so game.exe + game.dll, or a/x.exe +
b/x.exe, in one call wrote the same <out>/<stem>.json/.md and the last one won,
with exit 0. Reports are now named after the full file name (game.exe.json,
game.dll.md); a second image with the same file name from another directory
gets a numbered suffix (x.exe-2.json), compared case-insensitively, and the
name used is printed to stderr. The same path given twice is inspected once.

scripts/first_look.ps1, the only consumer of the report name, reads
<exe file name>.json. Tests cover the exe/dll pair and the two-directory case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 00:49:13 +01:00

42 lines
2.1 KiB
PowerShell

# Day-one report for the game executable: PE inspection, encryption check, import surface and a loader dry run.
# Reads the exe only; no game code runs.
param(
[Parameter(Mandatory)][string]$Exe,
[string]$GameDir = (Split-Path $Exe -Parent)
)
$ErrorActionPreference = "Stop"
$root = Split-Path $PSScriptRoot -Parent
$name = [IO.Path]::GetFileNameWithoutExtension($Exe)
$out = Join-Path $root "reports\exe\$name"
New-Item -ItemType Directory -Force $out | Out-Null
if (-not (Test-Path $Exe)) { throw "$Exe not found" }
$fs = [IO.File]::OpenRead($Exe); $mz = New-Object byte[] 2; [void]$fs.Read($mz, 0, 2); $fs.Close()
if ([Text.Encoding]::ASCII.GetString($mz) -ne "MZ") {
throw "$Exe doesn't start with an MZ header. It's still packaged or encrypted, so there's nothing to inspect."
}
$size = (Get-Item $Exe).Length
$hash = (Get-FileHash $Exe -Algorithm SHA256).Hash.ToLower()
"sha256 $hash size $size" | Tee-Object (Join-Path $out "hash.txt")
Write-Host "`n== PE inspection"
python -I (Join-Path $root "tools\pe_inspect.py") $Exe --game-dir $GameDir --out $out
if ($LASTEXITCODE -ne 0) { throw "pe_inspect failed" }
$rt = Join-Path $root "runtime\build\gta6rt.exe"
if (-not (Test-Path $rt)) { & (Join-Path $PSScriptRoot "build_runtime.ps1") }
Write-Host "`n== Loader dry run (map, relocate, bind imports; nothing executes)"
& $rt --dry-run $Exe --game-dir $GameDir 2>&1 | Tee-Object (Join-Path $out "dryrun.txt") | Select-Object -Last 40
# Shim to-do list, grouped by DLL, most functions first.
$report = Get-Content (Join-Path $out "$([IO.Path]::GetFileName($Exe)).json") -Raw | ConvertFrom-Json
$todo = $report.imports | Where-Object { $_.where -eq "shim" } | Sort-Object { -$_.functions.Count }
$lines = foreach ($t in $todo) { "{0,-40} {1,5}" -f $t.dll, $t.functions.Count }
$lines | Set-Content (Join-Path $out "shim-todo.txt")
Write-Host "`n== Shim to-do (DLL, function count)"
$lines
$enc = $report.sections | Where-Object { $_.looks_encrypted } | ForEach-Object { $_.name }
if ($enc) { Write-Warning "High-entropy sections (still encrypted or packed): $($enc -join ', ')" }
Write-Host "`nReports: $out"