This repository was archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathppobject.cpp
More file actions
73 lines (57 loc) · 2.08 KB
/
ppobject.cpp
File metadata and controls
73 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "ppobject.h"
#include "list"
#include "malloc.h"
#include "memory.h"
#include "windows.h"
#include "winreg.h"
const wchar_t* const PPObject::REG_KEY = L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions";
const wchar_t* const PPObject::REG_VALUE = L"ProductPolicy";
PPObject::PPObject()
{
initialiseData();
}
void PPObject::initialiseData()
{
std::list<PPRecord>* policies = new std::list<PPRecord>;
HKEY keyHandle;
DWORD bufferSize = 8192;
DWORD dataSize = bufferSize;
byte* registryValue = (byte*)malloc(bufferSize);
if(RegOpenKey(HKEY_LOCAL_MACHINE, PPObject::REG_KEY, &keyHandle) == ERROR_SUCCESS)
{
DWORD retVal = RegQueryValueEx(keyHandle, PPObject::REG_VALUE, NULL, NULL, registryValue, &dataSize);
while(retVal == ERROR_MORE_DATA)
{
bufferSize += 4096;
dataSize = bufferSize;
registryValue = (byte*)realloc(registryValue, bufferSize);
retVal = RegQueryValueEx(keyHandle, PPObject::REG_VALUE, NULL, NULL, registryValue, &dataSize);
}
RegCloseKey(keyHandle);
}
else
{
// ERROR HANDLING HERE
return;
}
memcpy(&Header, registryValue, sizeof(PPHeader));
unsigned int position = (unsigned int)sizeof(PPHeader);
while((dataSize - Header.EndMarker) > position)
{
unsigned int startPosition = position;
PPRecord* policy = new PPRecord();
PPValue* policyVal = (PPValue*)(registryValue + position);
memcpy(&policy->Record, policyVal, sizeof(PPValue));
position += sizeof(PPValue);
wchar_t* policyName = (wchar_t*)(registryValue + position);
policy->Name = (wchar_t*)malloc(policyVal->NameSize);
memcpy(policy->Name, policyName, policyVal->NameSize);
position += policyVal->NameSize;
policy->Data = malloc(policyVal->DataSize);
memcpy(policy->Data, (void*)(registryValue + position), policyVal->DataSize);
position = startPosition += policyVal->Size;
policies->push_front(*policy);
}
Records = *policies;
free(registryValue);
}