Advertisement
FlyFar

utils.cpp

Mar 21st, 2023
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | Cybersecurity | 0 0
  1. #include "memz.h"
  2.  
  3. HCRYPTPROV prov;
  4.  
  5. int random() {
  6.     if (prov == NULL)
  7.         if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_SILENT | CRYPT_VERIFYCONTEXT))
  8.             ExitProcess(1);
  9.  
  10.     int out;
  11.     CryptGenRandom(prov, sizeof(out), (BYTE *)(&out));
  12.     return out & 0x7fffffff;
  13. }
  14.  
  15. void strReverseW(LPWSTR str) {
  16.     int len = lstrlenW(str);
  17.  
  18.     if (len <= 1)
  19.         return;
  20.  
  21.     WCHAR c;
  22.     int i, j;
  23.     for (i = 0, j = len - 1; i < j; i++, j--) {
  24.         c = str[i];
  25.         str[i] = str[j];
  26.         str[j] = c;
  27.     }
  28.  
  29.     // Fix Newlines
  30.     for (i = 0; i < len - 1; i++) {
  31.         if (str[i] == L'\n' && str[i + 1] == L'\r') {
  32.             str[i] = L'\r';
  33.             str[i + 1] = L'\n';
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement