_tmain.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include <tchar.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <Exception.hpp>
  5. #include <ExceptionUser.hpp>
  6. #include <RSACipher.hpp>
  7. #include "SerialNumberGenerator.hpp"
  8. #undef NKG_CURRENT_SOURCE_FILE
  9. #undef NKG_CURRENT_SOURCE_LINE
  10. #define NKG_CURRENT_SOURCE_FILE() TEXT(".\\navicat-keygen\\_tmain.cpp")
  11. #define NKG_CURRENT_SOURCE_LINE() __LINE__
  12. namespace nkg {
  13. using fnCollectInformation = SerialNumberGenerator();
  14. using fnGenerateLicense = void(const RSACipher& Cipher, const SerialNumberGenerator& Generator);
  15. SerialNumberGenerator CollectInformationNormal();
  16. SerialNumberGenerator CollectInformationAdvanced();
  17. void GenerateLicenseText(const RSACipher& Cipher, const SerialNumberGenerator& Generator);
  18. void GenerateLicenseBinary(const RSACipher& Cipher, const SerialNumberGenerator& Generator);
  19. }
  20. static void Welcome() {
  21. _putts(TEXT("***************************************************"));
  22. _putts(TEXT("* Navicat Keygen by @DoubleLabyrinth *"));
  23. _putts(TEXT("* Version: 4.0 *"));
  24. _putts(TEXT("***************************************************"));
  25. _putts(TEXT(""));
  26. }
  27. static void Help() {
  28. _putts(TEXT("Usage:"));
  29. _putts(TEXT(" navicat-keygen.exe <-bin|-text> [-adv] <RSA-2048 Private Key File>"));
  30. _putts(TEXT(""));
  31. _putts(TEXT(" <-bin|-text> Specify \"-bin\" to generate \"license_file\" used by Navicat 11."));
  32. _putts(TEXT(" Specify \"-text\" to generate base64-encoded activation code."));
  33. _putts(TEXT(" This parameter must be specified."));
  34. _putts(TEXT(""));
  35. _putts(TEXT(" [-adv] Enable advance mode."));
  36. _putts(TEXT(" This parameter is optional."));
  37. _putts(TEXT(""));
  38. _putts(TEXT(" <RSA-2048 Private Key File> A path to an RSA-2048 private key file."));
  39. _putts(TEXT(" This parameter must be specified."));
  40. _putts(TEXT(""));
  41. _putts(TEXT("Example:"));
  42. _putts(TEXT(" navicat-keygen.exe -text .\\RegPrivateKey.pem"));
  43. }
  44. int _tmain(int argc, PTSTR argv[]) {
  45. Welcome();
  46. if (argc == 3 || argc == 4) {
  47. nkg::fnCollectInformation* lpfnCollectInformation = nullptr;
  48. nkg::fnGenerateLicense* lpfnGenerateLicense = nullptr;
  49. if (_tcsicmp(argv[1], TEXT("-bin")) == 0) {
  50. lpfnGenerateLicense = nkg::GenerateLicenseBinary;
  51. } else if (_tcsicmp(argv[1], TEXT("-text")) == 0) {
  52. lpfnGenerateLicense = nkg::GenerateLicenseText;
  53. } else {
  54. Help();
  55. return -1;
  56. }
  57. if (argc == 4) {
  58. if (_tcsicmp(argv[2], TEXT("-adv")) == 0) {
  59. lpfnCollectInformation = nkg::CollectInformationAdvanced;
  60. } else {
  61. Help();
  62. return -1;
  63. }
  64. } else {
  65. lpfnCollectInformation = nkg::CollectInformationNormal;
  66. }
  67. try {
  68. nkg::RSACipher Cipher;
  69. Cipher.ImportKeyFromFile<nkg::RSAKeyType::PrivateKey, nkg::RSAKeyFormat::PEM>(argv[argc - 1]);
  70. if (Cipher.Bits() != 2048) {
  71. throw nkg::Exception(NKG_CURRENT_SOURCE_FILE(), NKG_CURRENT_SOURCE_LINE(), TEXT("RSA key length mismatches."))
  72. .AddHint(TEXT("You must provide an RSA key whose modulus length is 2048 bits."));
  73. }
  74. auto Generator = lpfnCollectInformation();
  75. Generator.Generate();
  76. Generator.ShowInConsole();
  77. lpfnGenerateLicense(Cipher, Generator);
  78. return 0;
  79. } catch (nkg::UserAbortionError&) {
  80. return -1;
  81. } catch (nkg::Exception& e) {
  82. _tprintf_s(TEXT("[-] %s:%zu ->\n"), e.File(), e.Line());
  83. _tprintf_s(TEXT(" %s\n"), e.Message());
  84. if (e.HasErrorCode()) {
  85. _tprintf_s(TEXT(" %s (0x%zx)\n"), e.ErrorString(), e.ErrorCode());
  86. }
  87. for (auto& Hint : e.Hints()) {
  88. _tprintf_s(TEXT(" Hints: %s\n"), Hint.c_str());
  89. }
  90. return -1;
  91. } catch (std::exception& e) {
  92. _tprintf_s(TEXT("[-] %hs\n"), e.what());
  93. return -1;
  94. }
  95. } else {
  96. Help();
  97. return -1;
  98. }
  99. }