forked from asdcorp/ohook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sppc.c
105 lines (87 loc) · 2.41 KB
/
sppc.c
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#define _WIN32_WINNT _WIN32_WINNT_WIN10
#include <windows.h>
#include <shlwapi.h>
#include "sl.h"
#ifdef PLUS_BUILD
BOOL bIsHeartbeatRegistryModified = FALSE;
#endif
BOOL IsGracePeriodProduct(HSLC hSLC, SLID *pProductSkuId) {
PBYTE pBuffer = 0;
UINT cbSize = 0;
if(SLGetProductSkuInformation(hSLC, pProductSkuId, L"Name", NULL, &cbSize, &pBuffer) != S_OK) {
LocalFree(pBuffer);
return FALSE;
}
if(StrStrNIW((PWSTR)pBuffer, L"Grace", cbSize) != NULL) {
LocalFree(pBuffer);
return TRUE;
}
LocalFree(pBuffer);
return FALSE;
}
#ifdef PLUS_BUILD
VOID ModifyHeartbeatRegistry() {
HKEY hKey = 0;
LSTATUS lStatus = RegOpenKeyExW(
HKEY_CURRENT_USER,
L"Software\\Microsoft\\Office\\16.0",
0,
KEY_ALL_ACCESS,
&hKey
);
if(lStatus != ERROR_SUCCESS) return;
RegSetKeyValueW(
hKey,
L"Common\\Licensing\\Resiliency",
L"TimeOfLastHeartbeatFailure",
REG_SZ,
L"2040-01-01T00:00:00Z",
42
);
RegCloseKey(hKey);
}
#endif
HRESULT WINAPI SLGetLicensingStatusInformationHook(
HSLC hSLC,
SLID *pAppID,
SLID *pProductSkuId,
PWSTR pwszRightName,
UINT *pnStatusCount,
SL_LICENSING_STATUS **ppLicensingStatus
) {
HRESULT hResult = SLGetLicensingStatusInformation(
hSLC,
pAppID,
pProductSkuId,
pwszRightName,
pnStatusCount,
ppLicensingStatus
);
if(hResult != S_OK)
return hResult;
for(int i = 0; i < *pnStatusCount; i++) {
if((*ppLicensingStatus+i)->eStatus == SL_LICENSING_STATUS_UNLICENSED)
continue;
if(IsGracePeriodProduct(hSLC, &((*ppLicensingStatus+i)->SkuId)))
continue;
(*ppLicensingStatus+i)->eStatus = SL_LICENSING_STATUS_LICENSED;
(*ppLicensingStatus+i)->dwGraceTime = 0;
(*ppLicensingStatus+i)->dwTotalGraceDays = 0;
(*ppLicensingStatus+i)->hrReason = 0;
(*ppLicensingStatus+i)->qwValidityExpiration = 0;
}
#ifdef PLUS_BUILD
if(!bIsHeartbeatRegistryModified) {
ModifyHeartbeatRegistry();
bIsHeartbeatRegistryModified = TRUE;
}
#endif
return hResult;
}
BOOL APIENTRY WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved
) {
return TRUE;
}