def.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <tchar.h>
  3. #include <windows.h>
  4. #include <string>
  5. #include <openssl/err.h>
  6. #include <openssl/bio.h>
  7. #include <openssl/rsa.h>
  8. #include <openssl/pem.h>
  9. // OpenSSL precompiled lib, download from https://www.npcglib.org/~stathis/blog/precompiled-openssl/, MSVC2015 version
  10. // direct link https://www.npcglib.org/~stathis/downloads/openssl-1.1.0f-vs2015.7z
  11. // x86: "D:\openssl-1.1.0f-vs2015\include" has been add to include path. (modify it at project properties if necessary)
  12. // "D:\openssl-1.1.0f-vs2015\lib" has been add to library path. (modify it at project properties if necessary)
  13. // x64: "D:\openssl-1.1.0f-vs2015\include64" has been add to include path. (modify it at project properties if necessary)
  14. // "D:\openssl-1.1.0f-vs2015\lib64" has been add to library path. (modify it at project properties if necessary)
  15. #ifdef _DEBUG
  16. #pragma comment(lib, "libcryptoMTd.lib")
  17. #else
  18. #pragma comment(lib, "libcryptoMT.lib")
  19. #endif
  20. #pragma comment(lib, "WS2_32.lib") // some symbol are used in OpenSSL static lib
  21. #pragma comment(lib, "Crypt32.lib") // some symbol are used in OpenSSL static lib
  22. #pragma comment(lib, "version.lib") // GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue are in this lib
  23. namespace patcher {
  24. BOOL BackupFile(LPCTSTR file_path);
  25. RSA* GenerateRSAKey(int bits = 2048);
  26. BOOL WriteRSAPrivateKeyToFile(LPCTSTR filename, RSA* PrivateKey);
  27. RSA* ReadRSAPrivateKeyFromFile(LPCTSTR filename);
  28. BOOL GetNavicatVerion(LPCTSTR exe_path, DWORD* major_ver, DWORD* minor_ver);
  29. std::string EncryptPublicKey(const char* public_key, size_t len);
  30. BOOL Check_libcc_Hash(LPCTSTR libcc_dll_path, const uint8_t expected_hash[SHA256_DIGEST_LENGTH]);
  31. char* GetPEMText(RSA* PrivateKey);
  32. namespace Solution0 {
  33. BOOL Do(LPCTSTR navicat_exe_path, LPCTSTR prepared_key_file = nullptr);
  34. }
  35. namespace Solution1 {
  36. BOOL Do(LPCTSTR libcc_dll_path, LPCTSTR prepared_key_file = nullptr);
  37. }
  38. }