Advertisement
KidaCoding

Untitled

Jan 13th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | Source Code | 0 0
  1.  
  2. #include "RegKey.h"
  3.  
  4. using namespace std;
  5.  
  6. string RegKey::ProSerial;
  7.  
  8. VOID RegKey::EncryptDecrypt(std::string& data) {
  9. unsigned char key = 0x55;
  10. for (size_t i = 0; i < data.size(); i++) {
  11. data[i] ^= key;
  12. }
  13. }
  14.  
  15. VOID RegKey::SetRegValue() {
  16. std::string path = "C:\\ProgramData\\ZFPro";
  17. if (!CreateDirectoryA(path.c_str(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
  18. return;
  19. }
  20. SetFileAttributesA(path.c_str(), FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN);
  21.  
  22. std::string filePath = path + "\\serial.txt";
  23.  
  24. ProSerial = API::CFunctions::GetRandomString(MAX_SERIAL_LENGTH);
  25.  
  26. EncryptDecrypt(ProSerial);
  27.  
  28. std::ofstream file(filePath, std::ios::binary);
  29. if (file.is_open()) {
  30. file << ProSerial;
  31. file.close();
  32.  
  33. PSECURITY_DESCRIPTOR pSD = NULL;
  34. EXPLICIT_ACCESSA ea = {};
  35. PACL pACL = NULL;
  36.  
  37. ea.grfAccessPermissions = GENERIC_READ | GENERIC_WRITE;
  38. ea.grfAccessMode = SET_ACCESS;
  39. ea.grfInheritance = NO_INHERITANCE;
  40. ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
  41. ea.Trustee.TrusteeType = TRUSTEE_IS_USER;
  42. ea.Trustee.ptstrName = (LPSTR)"EVERYONE";
  43.  
  44. if (SetEntriesInAclA(1, &ea, NULL, &pACL) == ERROR_SUCCESS) {
  45. pSD = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
  46. if (pSD && InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) {
  47. SetSecurityDescriptorDacl(pSD, TRUE, pACL, FALSE);
  48. SetFileSecurityA(filePath.c_str(), DACL_SECURITY_INFORMATION, pSD);
  49. }
  50. }
  51.  
  52. if (pSD) LocalFree(pSD);
  53. if (pACL) LocalFree(pACL);
  54. }
  55. }
  56.  
  57. VOID RegKey::Read() {
  58. std::string filePath = "C:\\ProgramData\\ZFPro\\serial.txt";
  59. std::ifstream file(filePath, std::ios::binary);
  60.  
  61. if (file.is_open()) {
  62. std::getline(file, ProSerial);
  63. file.close();
  64.  
  65. EncryptDecrypt(ProSerial);
  66. }
  67.  
  68. if (ProSerial.empty()) {
  69. SetRegValue();
  70. }
  71. }
  72.  
Tags: MS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement