Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.1 KiB

  1. // dll.cpp - written and placed in the public domain by Wei Dai
  2. #define CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
  3. #define CRYPTOPP_DEFAULT_NO_DLL
  4. #include "dll.h"
  5. #pragma warning(default: 4660)
  6. #if defined(CRYPTOPP_EXPORTS) && defined(CRYPTOPP_WIN32_AVAILABLE)
  7. #include <windows.h>
  8. #endif
  9. #ifndef CRYPTOPP_IMPORTS
  10. NAMESPACE_BEGIN(CryptoPP)
  11. template<> const byte PKCS_DigestDecoration<SHA1>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14};
  12. template<> const unsigned int PKCS_DigestDecoration<SHA1>::length = sizeof(PKCS_DigestDecoration<SHA1>::decoration);
  13. template<> const byte PKCS_DigestDecoration<SHA224>::decoration[] = {0x30,0x2d,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x04,0x05,0x00,0x04,0x1c};
  14. template<> const unsigned int PKCS_DigestDecoration<SHA224>::length = sizeof(PKCS_DigestDecoration<SHA224>::decoration);
  15. template<> const byte PKCS_DigestDecoration<SHA256>::decoration[] = {0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20};
  16. template<> const unsigned int PKCS_DigestDecoration<SHA256>::length = sizeof(PKCS_DigestDecoration<SHA256>::decoration);
  17. template<> const byte PKCS_DigestDecoration<SHA384>::decoration[] = {0x30,0x41,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,0x05,0x00,0x04,0x30};
  18. template<> const unsigned int PKCS_DigestDecoration<SHA384>::length = sizeof(PKCS_DigestDecoration<SHA384>::decoration);
  19. template<> const byte PKCS_DigestDecoration<SHA512>::decoration[] = {0x30,0x51,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,0x05,0x00,0x04,0x40};
  20. template<> const unsigned int PKCS_DigestDecoration<SHA512>::length = sizeof(PKCS_DigestDecoration<SHA512>::decoration);
  21. template<> const byte EMSA2HashId<SHA>::id = 0x33;
  22. template<> const byte EMSA2HashId<SHA224>::id = 0x38;
  23. template<> const byte EMSA2HashId<SHA256>::id = 0x34;
  24. template<> const byte EMSA2HashId<SHA384>::id = 0x36;
  25. template<> const byte EMSA2HashId<SHA512>::id = 0x35;
  26. NAMESPACE_END
  27. #endif
  28. #ifdef CRYPTOPP_EXPORTS
  29. USING_NAMESPACE(CryptoPP)
  30. #if !(defined(_MSC_VER) && (_MSC_VER < 1300))
  31. using std::set_new_handler;
  32. #endif
  33. static PNew s_pNew = NULL;
  34. static PDelete s_pDelete = NULL;
  35. static void * New (size_t size)
  36. {
  37. void *p;
  38. while (!(p = malloc(size)))
  39. CallNewHandler();
  40. return p;
  41. }
  42. static void SetNewAndDeleteFunctionPointers()
  43. {
  44. void *p = NULL;
  45. HMODULE hModule = NULL;
  46. MEMORY_BASIC_INFORMATION mbi;
  47. while (true)
  48. {
  49. VirtualQuery(p, &mbi, sizeof(mbi));
  50. if (p >= (char *)mbi.BaseAddress + mbi.RegionSize)
  51. break;
  52. p = (char *)mbi.BaseAddress + mbi.RegionSize;
  53. if (!mbi.AllocationBase || mbi.AllocationBase == hModule)
  54. continue;
  55. hModule = HMODULE(mbi.AllocationBase);
  56. PGetNewAndDelete pGetNewAndDelete = (PGetNewAndDelete)GetProcAddress(hModule, "GetNewAndDeleteForCryptoPP");
  57. if (pGetNewAndDelete)
  58. {
  59. pGetNewAndDelete(s_pNew, s_pDelete);
  60. return;
  61. }
  62. PSetNewAndDelete pSetNewAndDelete = (PSetNewAndDelete)GetProcAddress(hModule, "SetNewAndDeleteFromCryptoPP");
  63. if (pSetNewAndDelete)
  64. {
  65. s_pNew = &New;
  66. s_pDelete = &free;
  67. pSetNewAndDelete(s_pNew, s_pDelete, &set_new_handler);
  68. return;
  69. }
  70. }
  71. // try getting these directly using mangled names of new and delete operators
  72. hModule = GetModuleHandle("msvcrtd");
  73. if (!hModule)
  74. hModule = GetModuleHandle("msvcrt");
  75. if (hModule)
  76. {
  77. // 32-bit versions
  78. s_pNew = (PNew)GetProcAddress(hModule, "??2@YAPAXI@Z");
  79. s_pDelete = (PDelete)GetProcAddress(hModule, "??3@YAXPAX@Z");
  80. if (s_pNew && s_pDelete)
  81. return;
  82. // 64-bit versions
  83. s_pNew = (PNew)GetProcAddress(hModule, "??2@YAPEAX_K@Z");
  84. s_pDelete = (PDelete)GetProcAddress(hModule, "??3@YAXPEAX@Z");
  85. if (s_pNew && s_pDelete)
  86. return;
  87. }
  88. OutputDebugString("Crypto++ was not able to obtain new and delete function pointers.\n");
  89. throw 0;
  90. }
  91. void * operator new (size_t size)
  92. {
  93. if (!s_pNew)
  94. SetNewAndDeleteFunctionPointers();
  95. return s_pNew(size);
  96. }
  97. void operator delete (void * p)
  98. {
  99. s_pDelete(p);
  100. }
  101. void * operator new [] (size_t size)
  102. {
  103. return operator new (size);
  104. }
  105. void operator delete [] (void * p)
  106. {
  107. operator delete (p);
  108. }
  109. #endif // #ifdef CRYPTOPP_EXPORTS