Merge pull request #70 from pottzman/master

Universal ConfirmationID
This commit is contained in:
WitherOrNot 2023-09-07 13:34:10 -04:00 committed by GitHub
commit 72c42f66c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,10 +32,7 @@
QWORD MOD = 0; QWORD MOD = 0;
QWORD NON_RESIDUE = 0; QWORD NON_RESIDUE = 0;
QWORD f[6] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; QWORD f[6] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
int productID1; int productID[4];
int productID2;
int productID3;
int productID4;
int activationMode; int activationMode;
int ConfirmationID::calculateCheckDigit(int pid) int ConfirmationID::calculateCheckDigit(int pid)
@ -889,11 +886,11 @@ int ConfirmationID::Generate(const char* installation_id_str, char confirmation_
case 1: case 1:
case 4: case 4:
memcpy(&parsed, installation_id, sizeof(parsed)); memcpy(&parsed, installation_id, sizeof(parsed));
productID1 = parsed.ProductIDLow & ((1 << 17) - 1); productID[0] = parsed.ProductIDLow & ((1 << 17) - 1);
productID2 = (parsed.ProductIDLow >> 17) & ((1 << 10) - 1); productID[1] = (parsed.ProductIDLow >> 17) & ((1 << 10) - 1);
productID3 = (parsed.ProductIDLow >> 27) & ((1 << 24) - 1); productID[2] = (parsed.ProductIDLow >> 27) & ((1 << 24) - 1);
version = (parsed.ProductIDLow >> 51) & 15; version = (parsed.ProductIDLow >> 51) & 15;
productID4 = (parsed.ProductIDLow >> 55) | (parsed.ProductIDHigh << 9); productID[3] = (parsed.ProductIDLow >> 55) | (parsed.ProductIDHigh << 9);
switch (activationMode) { switch (activationMode) {
case 0: case 0:
if (version != (totalCount == 41 ? 9 : 10)) if (version != (totalCount == 41 ? 9 : 10))
@ -911,21 +908,6 @@ int ConfirmationID::Generate(const char* installation_id_str, char confirmation_
case 2: case 2:
case 3: case 3:
decode_iid_new_version(installation_id, hardwareID, &version); decode_iid_new_version(installation_id, hardwareID, &version);
productID1 = stoi(productid.substr(0,5));
std::string channelid = productid.substr(6,3);
char *p = &channelid[0];
for (; *p; p++) {
*p = toupper((unsigned char)*p);
}
if (strcmp(&channelid[0], "OEM") == 0) {
productID2 = stoi(productid.substr(12,3));
productID3 = calculateCheckDigit((stoi(productid.substr(15,1)) * 100000) + (stoi(productid.substr(18,5))));
productID4 = (stoi((productid.substr(10,2))) / 100000) * 1000;
} else {
productID2 = stoi(productid.substr(6,3));
productID3 = stoi(productid.substr(10,7));
productID4 = stoi(productid.substr(18,5));
}
switch (activationMode) { switch (activationMode) {
case 2: case 2:
if (version != 3) if (version != 3)
@ -936,13 +918,28 @@ int ConfirmationID::Generate(const char* installation_id_str, char confirmation_
return ERR_UNKNOWN_VERSION; return ERR_UNKNOWN_VERSION;
} }
memcpy(&parsed, hardwareID, 8); memcpy(&parsed, hardwareID, 8);
break; productID[0] = stoi(productid.substr(0,5));
std::string channelid = productid.substr(6,3);
char *p = &channelid[0];
for (; *p; p++) {
*p = toupper((unsigned char)*p);
}
if (strcmp(&channelid[0], "OEM") == 0) {
productID[1] = stoi(productid.substr(12,3));
productID[2] = (stoi(productid.substr(15,1)) * 100000) + stoi(productid.substr(18,5));
productID[2] = calculateCheckDigit(productID[2]);
productID[3] = ((stoi(productid.substr(10,2))) * 1000) + productID[3];
} else {
productID[1] = stoi(productid.substr(6,3));
productID[2] = stoi(productid.substr(10,7));
productID[3] = stoi(productid.substr(18,5));
}
//fmt::print("ProductID: {}-{}-{}-{} \n", productID[0], productID[1], productID[2], productID[3]);
} }
//printf("Product ID: %05u-%03u-%07u-%05u\n", productId1, productId2, productId3, productId4);
unsigned char keybuf[16]; unsigned char keybuf[16];
memcpy(keybuf, &parsed.HardwareID, 8); memcpy(keybuf, &parsed.HardwareID, 8);
QWORD productIdMixed = (QWORD)productID1 << 41 | (QWORD)productID2 << 58 | (QWORD)productID3 << 17 | productID4; QWORD productIdMixed = (QWORD)productID[0] << 41 | (QWORD)productID[1] << 58 | (QWORD)productID[2] << 17 | productID[3];
memcpy(keybuf + 8, &productIdMixed, 8); memcpy(keybuf + 8, &productIdMixed, 8);
TDivisor d; TDivisor d;