From 6a65c5fc04d0ded8dc8946396304a84f0336922b Mon Sep 17 00:00:00 2001 From: AkariiinMKII <6019344+AkariiinMKII@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:21:13 +0800 Subject: [PATCH] feat(autoupdate): Add base64 decoding for hash values fetched in json mode --- lib/autoupdate.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index 5cef1622a0..84f79d90b8 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -129,6 +129,19 @@ function find_hash_in_json([String] $url, [Hashtable] $substitutions, [String] $ if (!$hash) { $hash = json_path_legacy $json $jsonpath $substitutions } + + # convert base64 encoded hash values + if ($hash -match '^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$') { + $base64 = $matches[0] + if (!($hash -match '^[a-fA-F0-9]+$') -and $hash.Length -notin @(32, 40, 64, 128)) { + try { + $hash = ([System.Convert]::FromBase64String($base64) | ForEach-Object { $_.ToString('x2') }) -join '' + } catch { + $hash = $hash + } + } + } + return format_hash $hash }