Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3.  
  4. #include "SHA1.h"
  5.  
  6. using namespace std;
  7.  
  8. /* 00000136 */ char patch1[1] = {0x22};
  9. /* 00000148 */ char patch2[3] = {0x20, 0xA6, 0x07};
  10. /* 00000178 */ char patch3[3][3] =
  11. {
  12. // {0xB6, 0x75, 0xFD}, {0x00, 0x41, 0xFD}, {0x8D, 0xBE, 0xFC},
  13. {0x3E, 0xF9, 0xFC}, {0x88, 0xC4, 0xFC}, {0x15, 0x43, 0xFD}
  14. };
  15. /* 00F57277 */ char patch4[6] = {0xE8, 0x04, 0xFD, 0x06, 0x00, 0x90};
  16. /* 00F57385 */ char patch5[5] = {0xE9, 0x56, 0xFC, 0x06, 0x00};
  17. /* 00FC6F80 */ char patch6[149] =
  18. {
  19. 0x90, 0x50, 0x50, 0x8B, 0xC4, 0x50, 0xB8, 0x40,
  20. 0x00, 0x00, 0x00, 0x50, 0xB8, 0x04, 0x00, 0x00,
  21. 0x00, 0x50, 0x8B, 0x85, 0x0C, 0xFC, 0xFF, 0xFF,
  22. 0x05, 0x0C, 0x02, 0x00, 0x00, 0x50, 0xFF, 0x55,
  23. 0x9C, 0x8B, 0x85, 0x0C, 0xFC, 0xFF, 0xFF, 0x05,
  24. 0x0C, 0x02, 0x00, 0x00, 0xC6, 0x00, 0x74, 0x8B,
  25. 0xC4, 0x50, 0x8B, 0x44, 0x24, 0x04, 0x50, 0xB8,
  26. 0x04, 0x00, 0x00, 0x00, 0x50, 0x8B, 0x85, 0x0C,
  27. 0xFC, 0xFF, 0xFF, 0x05, 0x0C, 0x02, 0x00, 0x00,
  28. 0x50, 0xFF, 0x55, 0x9C, 0x58, 0x58, 0xFF, 0xA5,
  29. 0x0C, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
  30. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  31. 0x50, 0x68, 0x00, 0xA6, 0x47, 0x01, 0xFF, 0x15,
  32. 0xB0, 0xF0, 0xFD, 0x00, 0x58, 0x5D, 0x5F, 0x5E,
  33. 0x5A, 0x59, 0x5B, 0xFF, 0xE0, 0x00, 0x00, 0x00,
  34. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35. 0x6E, 0x76, 0x73, 0x65, 0x5F, 0x73, 0x74, 0x65,
  36. 0x61, 0x6D, 0x5F, 0x6C, 0x6F, 0x61, 0x64, 0x65,
  37. 0x72, 0x2E, 0x64, 0x6C, 0x6C
  38. };
  39. /* 00FC7020 */ char patch7[39] =
  40. {
  41. 0x60, 0x68, 0xC8, 0xA6, 0x47, 0x01, 0x68, 0xE0,
  42. 0xA6, 0x47, 0x01, 0xFF, 0x15, 0xF4, 0xF1, 0xFD,
  43. 0x00, 0x68, 0xC8, 0xA6, 0x47, 0x01, 0x68, 0xD0,
  44. 0xA6, 0x47, 0x01, 0xFF, 0x15, 0xF4, 0xF1, 0xFD,
  45. 0x00, 0x61, 0xE9, 0xA7, 0xEC, 0xF8, 0xFF
  46. };
  47. /* 00FC70C8 */ char patch8[3][4] =
  48. {
  49. {0x32, 0x32, 0x33, 0x38},
  50. {0x32, 0x32, 0x33, 0x38},
  51. {0x32, 0x32, 0x34, 0x39}
  52. };
  53. /* 00FC70CC */ char patch9[31] =
  54. {
  55. 0x30, 0x00, 0x00, 0x00, 0x53, 0x74, 0x65, 0x61,
  56. 0x6D, 0x41, 0x70, 0x70, 0x49, 0x64, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x00, 0x53, 0x74, 0x65, 0x61,
  58. 0x6D, 0x47, 0x61, 0x6D, 0x65, 0x49, 0x64
  59. };
  60.  
  61. /* 00000148 */ char patchG1[3] = {0x90, 0xE5, 0xBD};
  62. /* 00000178 */ char patchG2[3] = {0xD0, 0x4B, 0xF6};
  63. /* 00BDD990 */ char patchG3[37] =
  64. {
  65. 0x68, 0xA0, 0xE5, 0xFD, 0x00, 0xFF, 0x15, 0xB0,
  66. 0xF0, 0xFD, 0x00, 0xE9, 0x3B, 0xDF, 0xEE, 0xFF,
  67. 0x6E, 0x76, 0x73, 0x65, 0x5F, 0x73, 0x74, 0x65,
  68. 0x61, 0x6D, 0x5F, 0x6C, 0x6F, 0x61, 0x64, 0x65,
  69. 0x72, 0x2E, 0x64, 0x6C, 0x6C
  70. };
  71. void applyPatch(char* data, unsigned long offset, char* patch, unsigned short length)
  72. {
  73. for(int i = 0; i < length; i++) data[offset + i] = patch[i];
  74. }
  75.  
  76. int main(int argc, char** argv)
  77. {
  78. ifstream ifile;
  79. ofstream ofile;
  80. unsigned short version = 5;
  81. ifile.open("FalloutNV.exe", ios::binary);
  82. if(ifile.good())
  83. {
  84. CSHA1 filehash;
  85. char hash[41] = {};
  86. filehash.HashFile("FalloutNV.exe");
  87. filehash.Final();
  88. filehash.ReportHash(hash, CSHA1::REPORT_HEX_SHORT);
  89. if(!strcmp(hash, "D068F394521A67C6E74FE572F59BD1BE71E855F3")) version = 0;
  90. if(!strcmp(hash, "3980940522F0264ED9AF14AEA1773BB19F5160AB")) version = 1;
  91. if(!strcmp(hash, "5394B94A18FFA6FA846E1D6033AD7F81919F13AC")) version = 2;
  92. if(!strcmp(hash, "07AFFDA66C89F09B0876A50C77759640BC416673")) version = 0;
  93. if(!strcmp(hash, "F65049B0957D83E61ECCCACC730015AE77FB4C8B")) version = 1;
  94. if(!strcmp(hash, "ACA83D5A12A64AF8854E381752FE989692D46E04")) version = 2;
  95. if(!strcmp(hash, "946D2EABA04A75FF361B8617C7632B49F1EDE9D3")) version = 3;
  96. if(version == 5)
  97. {
  98. if( !strcmp(hash, "0021023E37B1AF143305A61B7B29A1811CC7C5FB") ||
  99. !strcmp(hash, "37CAE4E713B6B182311F66E31668D5005D1B9F5B") ||
  100. !strcmp(hash, "600CD576CDE7746FB2CD152FDD24DB97453ED135") ||
  101. !strcmp(hash, "34B65096CAEF9374DD6AA39AF855E43308B417F2"))
  102. cout << "FalloutNV.exe is already patched!" << endl;
  103. else cout << "INVALID EXE VERSION: " << hash << endl;
  104. system("pause");
  105. return 1;
  106.  
  107. }
  108. streampos len = 0;
  109. len = ifile.tellg();
  110. ifile.seekg(0, ios::end);
  111. len = ifile.tellg() - len;
  112. cout << "Patching FalloutNV.exe [" << (version == 3 ? "GOG" : version == 2 ? "RU" : version == 1 ? "DE" : "US") << "]..." << endl;
  113. char* data = new char[len];
  114.  
  115. ifile.seekg(0);
  116. ifile.read(data, len);
  117. ifile.close();
  118.  
  119. rename("FalloutNV.exe", "FalloutNV_backup.exe");
  120.  
  121. if(version == 3)
  122. {
  123. applyPatch(data, 0x00000148, patchG1, 3);
  124. applyPatch(data, 0x00000178, patchG2, 3);
  125. applyPatch(data, 0x00BDD990, patchG3, 37);
  126. }
  127. else
  128. {
  129. applyPatch(data, 0x00000136, patch1, 1);
  130. applyPatch(data, 0x00000148, patch2, 3);
  131. applyPatch(data, 0x00000178, patch3[version], 3);
  132. applyPatch(data, 0x00F57277, patch4, 6);
  133. applyPatch(data, 0x00F57385, patch5, 5);
  134. applyPatch(data, 0x00FC6F80, patch6, 149);
  135. applyPatch(data, 0x00FC7020, patch7, 39);
  136. applyPatch(data, 0x00FC70C8, patch8[version], 4);
  137. applyPatch(data, 0x00FC70CC, patch9, 31);
  138. }
  139.  
  140. ofile.open("FalloutNV.exe", ios::binary);
  141. ofile.write(data, len);
  142. ofile.close();
  143. cout << "FalloutNV.exe patched!" << endl;
  144. } else cout << "FalloutNV.exe not found!" << endl;
  145. system("pause");
  146. return 0;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement