浏览代码

Logging SHA-256 of WinSCP.exe, when its product version does not match .NET assembly

(cherry picked from commit 8b3bcbd3ff8729f373e562084eb3cc3a6551dfcc)

Source commit: a22ba21b802e84176cb6a8bff30eda9685c4aa00
Martin Prikryl 5 年之前
父节点
当前提交
9875f708f3
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      dotnet/internal/ExeSessionProcess.cs

+ 16 - 0
dotnet/internal/ExeSessionProcess.cs

@@ -11,6 +11,7 @@ using System.Reflection;
 using System.Security.Principal;
 using System.Security.AccessControl;
 using System.ComponentModel;
+using System.Security.Cryptography;
 
 namespace WinSCP
 {
@@ -1055,6 +1056,21 @@ namespace WinSCP
                     }
                     else if (assemblyVersion.ProductVersion != version.ProductVersion)
                     {
+                        try
+                        {
+                            using (SHA256 SHA256 = SHA256.Create())
+                            using (FileStream stream = File.OpenRead(exePath))
+                            {
+                                string sha256 = Convert.ToBase64String(SHA256.ComputeHash(stream));
+                                _logger.WriteLine($"SHA-256 of the executable file is {sha256}");
+                            }
+                        }
+                        catch (Exception e)
+                        {
+                            _logger.WriteLine("Calculating SHA-256 of the executable file failed");
+                            _logger.WriteException(e);
+                        }
+
                         string message;
                         if (string.IsNullOrEmpty(version.ProductVersion) && (accessException != null))
                         {