33
44#include < iostream>
55#include < Windows.h>
6+ #include < fstream>
67#include " ../include/UltimateDRM.hpp"
78
89#ifdef _M_X64
1314#endif
1415#else
1516#ifdef _RELEASE
16- #pragma comment(lib, "../Debug/UltimateDRM.libUltimateDRM-d. lib")
17+ #pragma comment(lib, "../Debug/UltimateDRM.lib")
1718#else
1819#pragma comment(lib, "../Release/UltimateDRM.lib")
1920#endif
@@ -46,9 +47,10 @@ int main(int argc, char** argv)
4647
4748 std::list<std::wstring> lAllowedParents = { L" steam.exe" , L" explorer.exe" , L" VsDebugConsole.exe" , L" powershell.exe" , L" pwsh.exe" , L" cmd.exe" };
4849
49- const std::string LicenseServerEndpoint = " https://example.com/api/license" ; // replace with your actual license server endpoint
50+ const std::string LicenseServerEndpoint = " http://localhost:5002/Verify" ; // replace with your actual license server endpoint
51+ const std::string LicenseFilePath = " license.jwt" ; // path to license file
5052 const bool bAllowOfflineUsage = true ;
51- const bool bUsingLicensing = false ;
53+ const bool bUsingLicensing = true ;
5254 const bool bEnforceHypervisorCheck = false ; // having this set to true will cause Github Actions tests to fail, since they run on a VM
5355 const bool bRequireCodeSigning = false ; // in production code, this should be set to true
5456 const bool bShutdownOnViolation = false ; // throws runtime error if integrity violation is found
@@ -60,7 +62,7 @@ int main(int argc, char** argv)
6062 const bool bCheckHypervisor = true ;
6163 const bool bForceRunAsAdmin = false ;
6264
63- Settings * s = new Settings (LicenseServerEndpoint, bShutdownOnViolation, bAllowOfflineUsage, bUsingLicensing, bRequireCodeSigning, bEnforceSecureBoot,
65+ DRMSettings * s = new DRMSettings (LicenseServerEndpoint, bShutdownOnViolation, bAllowOfflineUsage, bUsingLicensing, bRequireCodeSigning, bEnforceSecureBoot,
6466 bEnforceDSE, bEnforceNoKdb, bUseAntiDebugging, bCheckModulesIntegrity, bCheckHypervisor, bForceRunAsAdmin, lAllowedParents);
6567
6668 UltimateDRM* drm = new UltimateDRM (s);
@@ -88,6 +90,27 @@ int main(int argc, char** argv)
8890 return 3 ;
8991 }
9092
93+ std::string licenseJWTString;
94+ std::string line;
95+ std::ifstream licenseFile (LicenseFilePath);
96+
97+ while (std::getline (licenseFile, line))
98+ {
99+ licenseJWTString += line;
100+ }
101+
102+ if (licenseFile.is_open ())
103+ licenseFile.close ();
104+
105+ if (drm->CheckLicenseVerified (licenseJWTString, bAllowOfflineUsage))
106+ {
107+ printf (" License OK\n " );
108+ }
109+ else
110+ {
111+ printf (" License fail\n " );
112+ }
113+
91114 DWORD dwOldProt = 0 ;
92115
93116#ifdef _M_X64 // no self remapping in x86
@@ -115,12 +138,20 @@ int main(int argc, char** argv)
115138
116139 const HMODULE k32hMod = GetModuleHandleW (L" kernel32.dll" );
117140 const uintptr_t k32_text = GetSectionStart (k32hMod, " .text" );
141+
142+ const HMODULE wintrustMod = GetModuleHandleW (L" wintrust.dll" );
143+ const uintptr_t wintrust_text = GetSectionStart (wintrustMod, " .text" );
118144
119145 if (k32_text && VirtualProtect ((LPVOID )k32_text, 1024 , PAGE_EXECUTE_READWRITE , &dwOldProt))
120146 {
121147 *(uint8_t *)k32_text = 0xC3 ; // patch over k32's .text section to show integrity checks work
122148 }
123149
150+ if (wintrust_text && VirtualProtect ((LPVOID )wintrust_text, 1024 , PAGE_EXECUTE_READWRITE , &dwOldProt))
151+ {
152+ *(uint8_t *)wintrust_text = 0xC3 ; // patch over k32's .text section to show integrity checks work
153+ }
154+
124155 for (int i = 0 ; i < 10 ; i++)
125156 {
126157 const auto drmViolation = drm->GetViolations ();
0 commit comments