Helper.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include <windows.h>
  3. #include <string>
  4. #include <sys/types.h>
  5. #include "NavicatCrypto.hpp"
  6. #undef __BASE_FILE__
  7. #define __BASE_FILE__ "Helper.hpp"
  8. namespace Helper {
  9. extern Navicat11Crypto NavicatCipher;
  10. //
  11. // Print memory data in [from, to) at least
  12. // If `base` is not nullptr, print address as offset. Otherwise, as absolute address.
  13. // NOTICE:
  14. // `base` must <= `from`
  15. //
  16. void PrintMemory(const void* from, const void* to, const void* base = nullptr);
  17. void PrintSomeBytes(const void* p, size_t s);
  18. template<typename _Type, bool _Ascending = true>
  19. void QuickSort(_Type* pArray, off_t begin, off_t end) {
  20. if (end - begin <= 1)
  21. return;
  22. off_t i = begin;
  23. off_t j = end - 1;
  24. _Type seperator = static_cast<_Type&&>(pArray[begin]);
  25. while (i < j) {
  26. if (_Ascending) {
  27. while (i < j && seperator <= pArray[j])
  28. --j;
  29. if (i < j)
  30. pArray[i++] = static_cast<_Type&&>(pArray[j]);
  31. while (i < j && pArray[i] <= seperator)
  32. ++i;
  33. if (i < j)
  34. pArray[j--] = static_cast<_Type&&>(pArray[i]);
  35. } else {
  36. while (i < j && seperator >= pArray[j])
  37. --j;
  38. if (i < j)
  39. pArray[i++] = static_cast<_Type&&>(pArray[j]);
  40. while (i < j && pArray[i] >= seperator)
  41. ++i;
  42. if (i < j)
  43. pArray[j--] = static_cast<_Type&&>(pArray[i]);
  44. }
  45. }
  46. pArray[i] = static_cast<_Type&&>(seperator);
  47. QuickSort<_Type, _Ascending>(pArray, begin, i);
  48. QuickSort<_Type, _Ascending>(pArray, i + 1, end);
  49. }
  50. std::string ConvertToUTF8(PCSTR From, DWORD CodePage = CP_ACP);
  51. std::string ConvertToUTF8(PCWSTR From);
  52. bool IsPrintable(const uint8_t* p, size_t s);
  53. void ReplaceSubString(std::string& Str,
  54. const std::string& OldSubStr,
  55. const std::string& NewSubStr);
  56. }