From e4cbb42e64843e53b5b24de92f43062bca98c474 Mon Sep 17 00:00:00 2001 From: Richard Kuhnt Date: Mon, 9 Jul 2018 13:14:38 +0200 Subject: [PATCH] Show first 8 bytes of file in the hash check error message --- lib/install.ps1 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/install.ps1 b/lib/install.ps1 index 781bd070a..7894d860d 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -443,8 +443,9 @@ function hash_for_url($manifest, $url, $arch) { # returns (ok, err) function check_hash($file, $hash, $app_name) { + $file = fullpath $file if(!$hash) { - warn "Warning: No hash in manifest. SHA256 is:`n $(compute_hash (fullpath $file) 'sha256')" + warn "Warning: No hash in manifest. SHA256 is:`n $(compute_hash $file) 'sha256')" return $true, $null } @@ -459,18 +460,21 @@ function check_hash($file, $hash, $app_name) { return $false, "Hash type '$type' isn't supported." } - $actual = compute_hash (fullpath $file) $type - + $actual = (compute_hash $file $type).ToLower() $expected = $expected.ToLower() - $actual = $actual.ToLower() if($actual -ne $expected) { $msg = "Hash check failed!`n" - $msg += "App: $app_name`n" - $msg += "URL: $url`n" + $msg += "App: $app_name`n" + $msg += "URL: $url`n" + if(Test-Path $file) { + $hexbytes = Get-Content $file -Encoding byte -TotalCount 8 | ForEach-Object { $_.tostring('x2') } + $hexbytes = [string]::join(' ', $hexbytes).ToUpper() + $msg += "First bytes: $hexbytes`n" + } if($expected -or $actual) { - $msg += "Expected: $expected`n" - $msg += "Actual: $actual" + $msg += "Expected: $expected`n" + $msg += "Actual: $actual" } return $false, $msg }