MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / CascImportKeysFromString

Function CascImportKeysFromString

src/External/CascLib/src/CascDecrypt.cpp:840–896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

838}
839
840bool WINAPI CascImportKeysFromString(HANDLE hStorage, LPCSTR szKeyList)
841{
842 // Verify parameters
843 if(TCascStorage::IsValid(hStorage) == NULL || szKeyList == NULL || szKeyList[0] == 0)
844 {
845 SetCascError(ERROR_INVALID_PARAMETER);
846 return false;
847 }
848
849 // Parse text file
850 while(szKeyList[0])
851 {
852 ULONGLONG KeyName = 0;
853 DWORD dwErrCode;
854 BYTE KeyValue[CASC_KEY_LENGTH];
855
856 // Capture key name
857 dwErrCode = ConvertStringToInt(szKeyList, 0, KeyName, &szKeyList);
858 if(dwErrCode != ERROR_SUCCESS)
859 {
860 SetCascError(dwErrCode);
861 return false;
862 }
863
864 // TACT key list downloaded from https://wow.tools/api.php?type=tactkeys ends with a single zero
865 if(KeyName == 0)
866 break;
867
868 // We only expect spaces and tabs at this point. Anything else will lead
869 // to end of the loop.
870 while(szKeyList[0] == 0x09 || szKeyList[0] == 0x20)
871 szKeyList++;
872 if(szKeyList[0] == 0x0A || szKeyList[0] == 0x0D)
873 break;
874
875 // Convert the string to binary
876 dwErrCode = BinaryFromString(szKeyList, CASC_KEY_LENGTH * 2, KeyValue);
877 if(dwErrCode != ERROR_SUCCESS)
878 {
879 SetCascError(dwErrCode);
880 return false;
881 }
882
883 // Add the encryption key. Note that if the key already exists with the same value,
884 // CascAddEncryptionKey will consider it success.
885 if(!CascAddEncryptionKey(hStorage, KeyName, KeyValue))
886 return false;
887
888 // Move to the next key
889 while(szKeyList[0] != 0 && szKeyList[0] != 0x0A && szKeyList[0] != 0x0D)
890 szKeyList++;
891 while(szKeyList[0] == 0x0A || szKeyList[0] == 0x0D)
892 szKeyList++;
893 }
894
895 return true;
896}
897

Callers 1

CascImportKeysFromFileFunction · 0.85

Calls 4

SetCascErrorFunction · 0.85
ConvertStringToIntFunction · 0.85
BinaryFromStringFunction · 0.85
CascAddEncryptionKeyFunction · 0.85

Tested by

no test coverage detected