Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "RegKey.h"
- using namespace std;
- string RegKey::ProSerial;
- VOID RegKey::EncryptDecrypt(std::string& data) {
- unsigned char key = 0x55;
- for (size_t i = 0; i < data.size(); i++) {
- data[i] ^= key;
- }
- }
- VOID RegKey::SetRegValue() {
- std::string path = "C:\\ProgramData\\ZFPro";
- if (!CreateDirectoryA(path.c_str(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
- return;
- }
- SetFileAttributesA(path.c_str(), FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN);
- std::string filePath = path + "\\serial.txt";
- ProSerial = API::CFunctions::GetRandomString(MAX_SERIAL_LENGTH);
- EncryptDecrypt(ProSerial);
- std::ofstream file(filePath, std::ios::binary);
- if (file.is_open()) {
- file << ProSerial;
- file.close();
- PSECURITY_DESCRIPTOR pSD = NULL;
- EXPLICIT_ACCESSA ea = {};
- PACL pACL = NULL;
- ea.grfAccessPermissions = GENERIC_READ | GENERIC_WRITE;
- ea.grfAccessMode = SET_ACCESS;
- ea.grfInheritance = NO_INHERITANCE;
- ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
- ea.Trustee.TrusteeType = TRUSTEE_IS_USER;
- ea.Trustee.ptstrName = (LPSTR)"EVERYONE";
- if (SetEntriesInAclA(1, &ea, NULL, &pACL) == ERROR_SUCCESS) {
- pSD = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
- if (pSD && InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) {
- SetSecurityDescriptorDacl(pSD, TRUE, pACL, FALSE);
- SetFileSecurityA(filePath.c_str(), DACL_SECURITY_INFORMATION, pSD);
- }
- }
- if (pSD) LocalFree(pSD);
- if (pACL) LocalFree(pACL);
- }
- }
- VOID RegKey::Read() {
- std::string filePath = "C:\\ProgramData\\ZFPro\\serial.txt";
- std::ifstream file(filePath, std::ios::binary);
- if (file.is_open()) {
- std::getline(file, ProSerial);
- file.close();
- EncryptDecrypt(ProSerial);
- }
- if (ProSerial.empty()) {
- SetRegValue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement