From 8c7229b1a4ccb5b2b48af06b58043f1c8cef5c83 Mon Sep 17 00:00:00 2001 From: zhom <2717306+zhom@users.noreply.github.com> Date: Mon, 28 Jul 2025 05:47:18 +0400 Subject: [PATCH] refactor: better string handling in windows scripts --- src/executable.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/executable.rs b/src/executable.rs index fee5ed8..0b3a6f5 100644 --- a/src/executable.rs +++ b/src/executable.rs @@ -223,14 +223,13 @@ set "TEMP_SCRIPT=%TEMP%\banderole-extract-!CURRENT_PID!.ps1" rem Create PowerShell script file to avoid command line length issues echo $scriptPath = "%~f0" > "!TEMP_SCRIPT!" -echo $content = Get-Content $scriptPath -Raw -Encoding UTF8 >> "!TEMP_SCRIPT!" +echo $content = [System.IO.File]::ReadAllText($scriptPath, [System.Text.Encoding]::UTF8) >> "!TEMP_SCRIPT!" echo $dataMarker = '__DATA__' >> "!TEMP_SCRIPT!" echo $dataStart = $content.IndexOf($dataMarker) >> "!TEMP_SCRIPT!" echo if ($dataStart -eq -1) {{ Write-Error 'Data marker not found'; exit 1 }} >> "!TEMP_SCRIPT!" echo $dataStart += $dataMarker.Length >> "!TEMP_SCRIPT!" -echo $data = $content.Substring($dataStart).Trim() >> "!TEMP_SCRIPT!" -echo $data = $data -replace '\r', '' >> "!TEMP_SCRIPT!" -echo $data = $data -replace '\n', '' >> "!TEMP_SCRIPT!" +echo $rawData = $content.Substring($dataStart) >> "!TEMP_SCRIPT!" +echo $data = ($rawData -split '[\r\n]+' ^| Where-Object {{ $_.Trim() -ne '' }}) -join '' >> "!TEMP_SCRIPT!" echo if ([string]::IsNullOrWhiteSpace($data)) {{ Write-Error 'No data found after marker'; exit 1 }} >> "!TEMP_SCRIPT!" echo try {{ >> "!TEMP_SCRIPT!" echo [System.IO.File]::WriteAllBytes("%TEMP%\banderole-!CURRENT_PID!.zip", [System.Convert]::FromBase64String($data)) >> "!TEMP_SCRIPT!"