I am building a desktop app for windows 10 that checks whether windows is activated. I am using a method found on another thread to check the activation state, which works but only when it is called within a few seconds of creating a window. Weird, I know. Does anyone know what might cause this, and if there is anything I can do to fix it? Any help is appreciated.
bool isGenuineWindows()
{
//WindowsAppId
unsigned char uuid_bytes[] = {0x35, 0x35, 0x63, 0x39, 0x32, 0x37, 0x33, 0x34, 0x2d, 0x64, 0x36,
0x38, 0x32, 0x2d, 0x34, 0x64, 0x37, 0x31, 0x2d, 0x39, 0x38, 0x33,
0x65, 0x2d, 0x64, 0x36, 0x65, 0x63, 0x33, 0x66, 0x31, 0x36, 0x30,
0x35, 0x39, 0x66};
GUID uuid;
SL_GENUINE_STATE state;
UuidFromStringA(uuid_bytes, &uuid);
SLIsGenuineLocal(&uuid, &state, nullptr);
return state == SL_GEN_STATE_IS_GENUINE;
}
int main(void)
{
/*creates GUI and all that boring stuff*/
MessageBox(NULL, "Some random message", "message", MB_ICONERROR);
printf("%d", isGenuineWindows()); //works
Sleep(5000); //wait a bit for the magic to wear off
printf("%d", isGenuineWindows()); //always returns true regardless of activation state
MessageBox(NULL, "Some random message", "message", MB_ICONERROR);
printf("%d", isGenuineWindows()); //works again
}
The 1st parameter's type of UuidFromStringA
is RPC_CSTR, which is defined in rpcdce.h:
typedef _Null_terminated_ unsigned char __RPC_FAR * RPC_CSTR;
It's a NULL-Terminated string although it is not documented. If the parameter is not NULL-Terminated, the function will fail. The string you have passed is not NULL-Terminated which will causes undefined behavior(depends on the original value of uuid_bytes[36]).
Use the plaintext string instead of ASCII, which is default NULL-Terminated string:
unsigned char uuid_bytes[] = "55c92734-d682-4d71-983e-d6ec3f16059f";