param([string]$Src, [string]$Out, [string[]]$Exec) $Exec = @($Exec | ForEach-Object { $_ -split ',' } | Where-Object { $_ }) Add-Type -AssemblyName System.IO.Compression, System.IO.Compression.FileSystem if (Test-Path $Out) { Remove-Item $Out -Force } $root = (Resolve-Path $Src).Path.TrimEnd('\') $parent = Split-Path $root -Parent $zip = [IO.Compression.ZipFile]::Open($Out, 'Create') try { $dirEntry = $zip.CreateEntry((Split-Path $root -Leaf) + '/') $dirEntry.ExternalAttributes = [BitConverter]::ToInt32([BitConverter]::GetBytes(([uint32]0x41ED -shl 16) -bor 0x10), 0) Get-ChildItem $root -Recurse -File | ForEach-Object { $name = $_.FullName.Substring($parent.Length + 1).Replace('\', '/') $e = [IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $_.FullName, $name, 'Optimal') $mode = if ($Exec -contains $_.Name) { 0x81ED } else { 0x81A4 } $e.ExternalAttributes = [BitConverter]::ToInt32([BitConverter]::GetBytes([uint32]$mode -shl 16), 0) } } finally { $zip.Dispose() } $b = [IO.File]::ReadAllBytes($Out) $n = 0 for ($i = $b.Length - 22; $i -ge 0; $i--) { if ($b[$i] -eq 0x50 -and $b[$i + 1] -eq 0x4B -and $b[$i + 2] -eq 0x05 -and $b[$i + 3] -eq 0x06) { $cd = [BitConverter]::ToUInt32($b, $i + 16) $count = [BitConverter]::ToUInt16($b, $i + 10) $p = [int]$cd for ($k = 0; $k -lt $count; $k++) { if ([BitConverter]::ToUInt32($b, $p) -ne 0x02014b50) { throw "bad central directory at $p" } $b[$p + 4] = 30 $b[$p + 5] = 3 $n++ $fl = [BitConverter]::ToUInt16($b, $p + 28); $xl = [BitConverter]::ToUInt16($b, $p + 30); $cl = [BitConverter]::ToUInt16($b, $p + 32) $p += 46 + $fl + $xl + $cl } break } } [IO.File]::WriteAllBytes($Out, $b) Write-Host "$(Split-Path $Out -Leaf): $n entries marked as Unix"