From 6b32cdb5915e892661ced8765e6aa583938d9c6f Mon Sep 17 00:00:00 2001 From: "A.Watchara" Date: Fri, 14 Aug 2026 00:54:24 +0700 Subject: [PATCH 1/2] Parse wrapped Linux apksigner output --- scripts/update-minimum-device.ps1 | 8 ++++++-- tests/update-minimum-device.Tests.ps1 | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/update-minimum-device.ps1 b/scripts/update-minimum-device.ps1 index 8a4f4e1c..f48eac10 100644 --- a/scripts/update-minimum-device.ps1 +++ b/scripts/update-minimum-device.ps1 @@ -358,8 +358,12 @@ function Find-ApkSignerInSdkRoots { function Parse-ApkSignerOutput { param([string]$Text) - $digests = @([regex]::Matches($Text, - '(?im)^Signer #\d+ certificate SHA-256 digest:\s*([0-9a-f]{64})\s*$') | + # PowerShell 7 wraps some extensionless native-command output as ErrorRecord text on Linux, + # which can prefix the original line. Strip terminal control sequences and locate the exact + # apksigner label without requiring it to begin the rendered PowerShell line. + $normalized = [regex]::Replace($Text, '\x1B\[[0-?]*[ -/]*[@-~]', '') + $digests = @([regex]::Matches($normalized, + '(?i)Signer #\d+ certificate SHA-256 digest:\s*([0-9a-f]{64})(?![0-9a-f])') | ForEach-Object { $_.Groups[1].Value.ToUpperInvariant() }) if ($digests.Count -eq 0) { Throw-UpdateError "APK_SIGNATURE_INVALID" "apksigner did not report a verified signing certificate." diff --git a/tests/update-minimum-device.Tests.ps1 b/tests/update-minimum-device.Tests.ps1 index acf697da..bfa619e6 100644 --- a/tests/update-minimum-device.Tests.ps1 +++ b/tests/update-minimum-device.Tests.ps1 @@ -111,6 +111,8 @@ Test-Case "returning target switches to its correlated ADB port" { Test-Case "apksigner output parser requires verified signer digest" { $digest = "168F42ED412DA80ADAF27BED0984DBEE191168E9DF04F08AFA240A3F9DE45972" Assert-Equal $digest (Parse-ApkSignerOutput "Signer #1 certificate SHA-256 digest: $digest") "apksigner digest" + $linuxWrapped = "NativeCommandError: `e[36mSigner #1 certificate SHA-256 digest: $($digest.ToLowerInvariant())`e[0m" + Assert-Equal $digest (Parse-ApkSignerOutput $linuxWrapped) "PowerShell Linux wrapped digest" Assert-ThrowsCode { Parse-ApkSignerOutput "DOES NOT VERIFY" } "APK_SIGNATURE_INVALID" "missing signer digest" } From 841ac6fa066a113c36fd244adedce3926d4a3353 Mon Sep 17 00:00:00 2001 From: "A.Watchara" Date: Fri, 14 Aug 2026 00:54:51 +0700 Subject: [PATCH 2/2] Fix PowerShell 5.1 ANSI fixture --- tests/update-minimum-device.Tests.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/update-minimum-device.Tests.ps1 b/tests/update-minimum-device.Tests.ps1 index bfa619e6..f2f1d91d 100644 --- a/tests/update-minimum-device.Tests.ps1 +++ b/tests/update-minimum-device.Tests.ps1 @@ -111,7 +111,8 @@ Test-Case "returning target switches to its correlated ADB port" { Test-Case "apksigner output parser requires verified signer digest" { $digest = "168F42ED412DA80ADAF27BED0984DBEE191168E9DF04F08AFA240A3F9DE45972" Assert-Equal $digest (Parse-ApkSignerOutput "Signer #1 certificate SHA-256 digest: $digest") "apksigner digest" - $linuxWrapped = "NativeCommandError: `e[36mSigner #1 certificate SHA-256 digest: $($digest.ToLowerInvariant())`e[0m" + $escape = [char]27 + $linuxWrapped = "NativeCommandError: ${escape}[36mSigner #1 certificate SHA-256 digest: $($digest.ToLowerInvariant())${escape}[0m" Assert-Equal $digest (Parse-ApkSignerOutput $linuxWrapped) "PowerShell Linux wrapped digest" Assert-ThrowsCode { Parse-ApkSignerOutput "DOES NOT VERIFY" } "APK_SIGNATURE_INVALID" "missing signer digest" }