-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
102 lines (82 loc) · 2.98 KB
/
Copy pathbuild.ps1
File metadata and controls
102 lines (82 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
param (
[string]$SourceFolder = "$PSScriptRoot",
[string]$OutputFile = "$PSScriptRoot\WinSwift-Standalone.ps1"
)
Write-Host "Building WinSwift Standalone..." -ForegroundColor Cyan
# 1. Zip the required files
$TempZip = "$env:TEMP\WinSwift_Build.zip"
if (Test-Path $TempZip) { Remove-Item $TempZip -Force }
$IncludeItems = @(
"Assets",
"Config",
"Regfiles",
"Schemas",
"Scripts",
"WinSwift.ps1",
"Run.bat"
)
Write-Host "Compressing files..."
$ItemsToZip = $IncludeItems | ForEach-Object { Join-Path $SourceFolder $_ }
Compress-Archive -Path $ItemsToZip -DestinationPath $TempZip -Force
# 2. Convert Zip to Base64
Write-Host "Converting to Base64..."
$Bytes = [System.IO.File]::ReadAllBytes($TempZip)
$Base64String = [System.Convert]::ToBase64String($Bytes)
# 3. Create the Standalone Script Wrapper
Write-Host "Generating Standalone Wrapper..."
$WrapperCode = @"
<#
.SYNOPSIS
WinSwift Standalone Executable
.DESCRIPTION
This script extracts the WinSwift payload to a temporary directory and executes it.
#>
`$VerbosePreference = 'SilentlyContinue'
function Format-StandaloneArg {
param([AllowEmptyString()][string]`$Value)
`$escaped = `$Value -replace '(\\*)"', '`$1`$1\"'
`$escaped = `$escaped -replace '(\\+)$', '`$1`$1'
return '"' + `$escaped + '"'
}
# Payload (Base64 Zip)
`$processExitCode = 1
`$Payload = "$Base64String"
# Extraction Path
`$ExtractPath = Join-Path `$env:TEMP "WinSwift_Run_`$([Guid]::NewGuid().ToString().Substring(0,8))"
if (-not (Test-Path `$ExtractPath)) {
New-Item -ItemType Directory -Path `$ExtractPath -Force | Out-Null
}
`$ZipPath = Join-Path `$ExtractPath "payload.zip"
try {
# Decode and save
`$Bytes = [System.Convert]::FromBase64String(`$Payload)
[System.IO.File]::WriteAllBytes(`$ZipPath, `$Bytes)
# Extract
Expand-Archive -Path `$ZipPath -DestinationPath `$ExtractPath -Force
# Run the real script
`$ScriptPath = Join-Path `$ExtractPath "WinSwift.ps1"
if (Test-Path `$ScriptPath) {
`$ArgsList = @("-ExecutionPolicy", "Bypass", "-NoProfile", "-File", (Format-StandaloneArg `$ScriptPath))
foreach (`$argument in `$args) {
`$ArgsList += (Format-StandaloneArg ([string]`$argument))
}
Write-Host "Launching WinSwift..." -ForegroundColor Cyan
`$process = Start-Process -FilePath "powershell.exe" -ArgumentList `$ArgsList -NoNewWindow -Wait -PassThru
`$processExitCode = `$process.ExitCode
} else {
Write-Error "Failed to locate WinSwift.ps1 in extracted payload."
}
} catch {
Write-Error "An error occurred while launching WinSwift: `$_"
} finally {
# Cleanup
if (Test-Path `$ExtractPath) {
Remove-Item `$ExtractPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
exit `$processExitCode
"@
# 4. Save to Output File
[System.IO.File]::WriteAllText($OutputFile, $WrapperCode)
Remove-Item $TempZip -Force
Write-Host "Build complete! Standalone script saved to: $OutputFile" -ForegroundColor Green