Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6.  
  7. namespace verify_redm
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Reading cache list...");
  14.  
  15. var inputFile = File.ReadAllLines("cache.sha1");
  16. var cacheList = new Dictionary<string, string>();
  17.  
  18. foreach (var line in inputFile)
  19. {
  20. var line2 = line.Trim();
  21. line2 = line2.Replace("\"", "");
  22. line2 = line2.Replace("{", "");
  23. line2 = line2.Replace("}", "");
  24.  
  25. if (String.IsNullOrWhiteSpace(line2))
  26. continue;
  27.  
  28. var split = line2.Split(',');
  29.  
  30. var path = split[0].Trim();
  31. var hash = split[1].Trim();
  32.  
  33. cacheList[path] = hash;
  34. }
  35.  
  36. Console.WriteLine($"Got {cacheList.Keys.Count} file keys to check.");
  37.  
  38. var targetDir = @"D:\RedM\cache\game";
  39.  
  40. foreach (var entry in cacheList)
  41. {
  42. Console.ForegroundColor = ConsoleColor.Gray;
  43. var checkPath = Path.Combine(targetDir, entry.Key);
  44. Console.Write($"{checkPath} ...");
  45.  
  46. if (File.Exists(checkPath))
  47. {
  48. var hash = Hash(checkPath);
  49.  
  50. if (String.Equals(hash, entry.Value, StringComparison.InvariantCultureIgnoreCase))
  51. {
  52. Console.ForegroundColor = ConsoleColor.Green;
  53. Console.WriteLine(" -> OK!");
  54. }
  55. else
  56. {
  57. Console.ForegroundColor = ConsoleColor.Red;
  58. Console.WriteLine($" -> Expected {entry.Value}, got {hash}!");
  59. }
  60. }
  61. else
  62. {
  63. Console.ForegroundColor = ConsoleColor.Red;
  64. Console.WriteLine(" -> File missing!");
  65. }
  66. }
  67.  
  68. Console.WriteLine("Checks done.");
  69. Console.ReadKey(true);
  70. }
  71.  
  72. static string Hash(string path)
  73. {
  74. using (FileStream fs = new FileStream(path, FileMode.Open))
  75. using (BufferedStream bs = new BufferedStream(fs))
  76. {
  77. using (SHA1Managed sha1 = new SHA1Managed())
  78. {
  79. byte[] hash = sha1.ComputeHash(bs);
  80. StringBuilder formatted = new StringBuilder(2 * hash.Length);
  81. foreach (byte b in hash)
  82. {
  83. formatted.AppendFormat("{0:X2}", b);
  84. }
  85. return formatted.ToString();
  86. }
  87. }
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement