PatchSolution4-generic.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "PatchSolutions.hpp"
  2. #undef NKG_CURRENT_SOURCE_FILE
  3. #undef NKG_CURRENT_SOURCE_LINE
  4. #define NKG_CURRENT_SOURCE_FILE() TEXT(".\\navicat-patcher\\PatchSolution4-generic.cpp")
  5. #define NKG_CURRENT_SOURCE_LINE() __LINE__
  6. namespace nkg {
  7. bool PatchSolution4::CheckKey(const RSACipher& Cipher) const noexcept {
  8. auto szPublicKey = Cipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
  9. for (auto pos = szPublicKey.find("-----BEGIN PUBLIC KEY-----"); pos != std::string::npos; pos = szPublicKey.find("-----BEGIN PUBLIC KEY-----", pos)) {
  10. szPublicKey.erase(pos, literal_length("-----BEGIN PUBLIC KEY-----"));
  11. }
  12. for (auto pos = szPublicKey.find("-----END PUBLIC KEY-----"); pos != std::string::npos; pos = szPublicKey.find("-----END PUBLIC KEY-----", pos)) {
  13. szPublicKey.erase(pos, literal_length("-----END PUBLIC KEY-----"));
  14. }
  15. for (auto pos = szPublicKey.find("\n"); pos != std::string::npos; pos = szPublicKey.find("\n", pos)) {
  16. szPublicKey.erase(pos, literal_length("\n"));
  17. }
  18. return szPublicKey.length() == 0x188;
  19. }
  20. void PatchSolution4::MakePatch(const RSACipher& Cipher) const {
  21. if (_pbPatchMachineCode == nullptr || _pbPatchNewPublicKey == nullptr || _NewMachineCode.empty()) {
  22. throw Exception(NKG_CURRENT_SOURCE_FILE(), NKG_CURRENT_SOURCE_LINE(), TEXT("PatchSolution4 has not been ready yet."));
  23. }
  24. auto szPublicKey = Cipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
  25. for (auto pos = szPublicKey.find("-----BEGIN PUBLIC KEY-----"); pos != std::string::npos; pos = szPublicKey.find("-----BEGIN PUBLIC KEY-----", pos)) {
  26. szPublicKey.erase(pos, literal_length("-----BEGIN PUBLIC KEY-----"));
  27. }
  28. for (auto pos = szPublicKey.find("-----END PUBLIC KEY-----"); pos != std::string::npos; pos = szPublicKey.find("-----END PUBLIC KEY-----", pos)) {
  29. szPublicKey.erase(pos, literal_length("-----END PUBLIC KEY-----"));
  30. }
  31. for (auto pos = szPublicKey.find("\n"); pos != std::string::npos; pos = szPublicKey.find("\n", pos)) {
  32. szPublicKey.erase(pos, literal_length("\n"));
  33. }
  34. _putts(TEXT("*******************************************************"));
  35. _putts(TEXT("* PatchSolution4 *"));
  36. _putts(TEXT("*******************************************************"));
  37. LOG_HINT(0, "Previous:");
  38. PrintMemory(_pbPatchMachineCode, _NewMachineCode.size(), _Image.ImageBase());
  39. memcpy(_pbPatchMachineCode, _NewMachineCode.data(), _NewMachineCode.size());
  40. LOG_HINT(0, "After:");
  41. PrintMemory(_pbPatchMachineCode, _NewMachineCode.size(), _Image.ImageBase());
  42. _putts(TEXT(""));
  43. LOG_HINT(0, "Previous:");
  44. PrintMemory(_pbPatchNewPublicKey, szPublicKey.size(), _Image.ImageBase());
  45. memcpy(_pbPatchNewPublicKey, szPublicKey.data(), szPublicKey.size());
  46. LOG_HINT(0, "After:");
  47. PrintMemory(_pbPatchNewPublicKey, szPublicKey.size(), _Image.ImageBase());
  48. _putts(TEXT(""));
  49. }
  50. }