@echo off setlocal EnableExtensions if "%~2"=="" ( echo Usage: %~nx0 archive.zip destination [force] exit /b 2 ) set "ARCHIVE=%~1" set "DEST=%~2" set "MODE=%~3" if not exist "%ARCHIVE%" ( echo Archive not found: %ARCHIVE% exit /b 1 ) where 7z >nul 2>&1 if errorlevel 1 ( echo 7-Zip not found. Add 7z.exe to PATH. exit /b 1 ) powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; Add-Type -AssemblyName System.IO.Compression.FileSystem; $z=[IO.Compression.ZipFile]::OpenRead($env:ARCHIVE); $bad=@($z.Entries | Where-Object { $n=$_.FullName.Replace('\','/'); $n.StartsWith('/') -or $n -match '^[A-Za-z]:' -or $n -match '(^|/)\.\.(/|$)' }); $z.Dispose(); if ($bad.Count -gt 0) { Write-Error ('Unsafe path: ' + $bad[0].FullName); exit 2 }" if errorlevel 1 ( echo Archive contains unsafe paths or cannot be read. exit /b 1 ) if not exist "%DEST%\" mkdir "%DEST%" >nul set "OVERWRITE=-aos" if /i "%MODE%"=="force" set "OVERWRITE=-aoa" 7z x "%ARCHIVE%" -o"%DEST%" %OVERWRITE% >nul if errorlevel 1 ( echo Extraction failed. exit /b 1 ) echo Extracted to "%DEST%" exit /b 0