FileHexEditor.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using RevokeMsgPatcher.Model;
  2. using RevokeMsgPatcher.Utils;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace RevokeMsgPatcher.Modifier
  10. {
  11. public class FileHexEditor
  12. {
  13. public string FileName { get; set; }
  14. public string FilePath { get; set; }
  15. public string FileBakPath { get; set; }
  16. private string version;
  17. public string FileVersion
  18. {
  19. get
  20. {
  21. if (version == null)
  22. {
  23. version = FileUtil.GetFileVersion(FilePath);
  24. }
  25. return version;
  26. }
  27. }
  28. public string sha1;
  29. public string FileSHA1
  30. {
  31. get
  32. {
  33. if (sha1 == null)
  34. {
  35. sha1 = FileUtil.ComputeFileSHA1(FilePath);
  36. }
  37. return sha1;
  38. }
  39. }
  40. public TargetInfo FileTargetInfo { get; set; }
  41. public ModifyInfo FileModifyInfo { get; set; }
  42. public FileHexEditor(string installPath, TargetInfo target)
  43. {
  44. FileTargetInfo = target.Clone();
  45. FileName = FileTargetInfo.Name;
  46. FilePath = Path.Combine(installPath, FileTargetInfo.RelativePath);
  47. FileBakPath = FilePath + ".h.bak";
  48. }
  49. public void Backup()
  50. {
  51. File.Copy(FilePath, FileBakPath, true);
  52. }
  53. public bool Patch()
  54. {
  55. FileUtil.EditMultiHex(FilePath, FileModifyInfo.Changes);
  56. return true;
  57. }
  58. public void Restore()
  59. {
  60. File.Copy(FileBakPath, FilePath, true);
  61. }
  62. }
  63. }