// EGPublicKey::EncryptData // Encrypts a block of specified length into the specified queue. Determines the // number of individual blocks to be encrypted. Adds block count to queue. Then // calls EncryptBlock() to encrypt each block into the queue. Note that mCryptP // must be valid before this method is called. void EGPublicKey::EncryptData(BufferedTransformation& aQueue, const unsigned char* theMsgP, unsigned long theLen) const { WTRACE("EGPublicKey::EncryptData"); WDBG_LL("EGPublicKey::EncryptData, len=" << theLen); // Determine block length and number of blocks unsigned long aBlockLen = mCryptP->MaxPlainTextLength(); unsigned long aNumBlock = theLen / aBlockLen; if ((theLen % aBlockLen) != 0) aNumBlock++; WDBG_LL("EGPublicKey::EncryptBlock NumBlocks=" << aNumBlock << ", BlockLen=" << aBlockLen); // A num blocks to output unsigned long tmpNumBlock = getLittleEndian(aNumBlock); aQueue.Put(reinterpret_cast<unsigned char*>(&tmpNumBlock), sizeof(tmpNumBlock)); // Encrypt the data, one block at a time while (theLen > aBlockLen) { EncryptBlock(aQueue, theMsgP, aBlockLen); theMsgP += aBlockLen; theLen -= aBlockLen; } // Encrypt the last block and close the queue EncryptBlock(aQueue, theMsgP, theLen); aQueue.Close(); }
// SMsgDirG2PeerDataBase::UnpackPeerData // Hook to unpack the peer data if needed. Only reads peer data if peer // data is present. Note that mPeerUser was added later and may or may not be // present. void SMsgDirG2PeerDataBase::UnpackPeerData(void) { WTRACE("SMsgDirG2PeerDataBase::UnpackPeerData"); if (BytesLeftToRead() > 0) { WDBG_LL("SMsgDirG2PeerDataBase::UnpackPeerData Reading peer data."); ReadString(mPeerKey); mPeerIndex = ReadLong(); if (BytesLeftToRead() > 0) { WDBG_LL("SMsgDirG2PeerDataBase::UnpackPeerData Reading user id."); mPeerUser = ReadLong(); } else mPeerUser = 0; } else { WDBG_LL("SMsgDirG2PeerDataBase::UnpackPeerData No peer data to read."); mPeerKey = string(); mPeerIndex = 0; mPeerUser = 0; } }
// TMsgDirGetDirContents::Unpack // Virtual method from TMessage. Extracts data from message buffer. void TMsgDirGetDirContentsReply::Unpack(void) { WTRACE("TMsgDirGetDirContentsReply::Unpack"); TMessage::Unpack(); if ((GetServiceType() != WONMsg::DirServer) || (GetMessageType() != WONMsg::DirGetDirContentsReply)) { WDBG_AH("TMsgDirGetDirContentsReply::Unpack Not a DirGetDirContentsReply message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a DirGetDirContentsReply message."); } WDBG_LL("TMsgDirGetDirContentsReply::Unpack Reading message data"); mStatus = static_cast<ServerStatus>(static_cast<short>(ReadShort())); unsigned short anEntryCt = ReadShort(); WDBG_LL("TMsgDirGetDirContentsReply::Unpack Reading " << anEntryCt << "entries."); mEntries.clear(); for (int i=0; i < anEntryCt; i++) { DirServerEntry anEntry; UnpackEntry(anEntry); mEntries.push_back(anEntry); } }
// TMessage ctor from WONException BadMsgException::BadMsgException(const BaseMessage& theMsgR, int theLine, const char* theFileP, const char* addTextP) throw() : WONException(WONCommon::ExBadTitanMessage, theLine, theFileP) { WTRACE("BadMsgException::ctor(TMessage)"); // Add header type info or header corrupt message if (theMsgR.GetDataLen() >= theMsgR.GetHeaderLength()) { WDBG_LL("BadMsgException::ctor(TMessage) Add header info."); GetStream() << "MessageClass=" << (int)theMsgR.GetMessageClass() << " MessageType=" << theMsgR.GetMessageType() << " ServiceType=" << theMsgR.GetServiceType(); } else { WDBG_LH("BadMsgException::ctor(TMessage) Corrupt header!"); GetStream() << HDRCORRUPT_MSG; } // Add message length and data length WDBG_LL("BadMsgException::ctor(TMessage) Add length info."); GetStream() << " DataLength=" << theMsgR.GetDataLen(); // Add additional text if defined if (addTextP) GetStream() << " " << addTextP; }
// ClientCDKey::BuildVChar // Extracts a V from buffer starting at offset theOffset. Extracted V is appened // to mStrKey. Vs use 2 bits. Value of theOffset is incremented by 2. void ClientCDKey::BuildVChar(const __int64& theBuf, unsigned int& theOffset) const { WTRACE("ClientCDKey::BuildVChar"); WDBG_LL("ClientCDKey::BuildVChar offset=" << theOffset); char aChar = 0; // Determine mask based on char switch (ValFromBits(theBuf, theOffset, 2)) { case 0: aChar = 'A'; break; case 1: aChar = 'E'; break; case 2: aChar = 'U'; break; case 3: aChar = 'Y'; break; #ifdef _DEBUG default: throw WONCommon::WONException(WONCommon::ExSoftwareFail, __LINE__, __FILE__, "ClientCDKey::BuildVChar ValFromBits returned invalid char!"); break; #endif } // Add char to buf and update offset WDBG_LL("ClientCDKey::BuildVChar Char=" << aChar); mStrKey += aChar; theOffset += 2; }
// SMsgDirG2GetNumEntities::Unpack // Virtual method from SmallMessage. Extracts data from message buffer. void SMsgDirG2GetNumEntities::Unpack(void) { WTRACE("SMsgDirG2GetNumEntities::Unpack"); SmallMessage::Unpack(); if ((GetServiceType() != WONMsg::SmallDirServerG2) || (GetMessageType() != WONMsg::DirG2GetNumEntities)) { WDBG_AH("SMsgDirG2GetNumEntities::Unpack Not a DirG2GetNumEntities message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a DirG2GetNumEntities message."); } WDBG_LL("SMsgDirG2GetNumEntities::Unpack Reading message data"); unsigned short aPathCt = ReadShort(); WDBG_LL("SMsgDirG2GetNumEntities::Unpack Reading " << aPathCt << " entries."); mPaths.clear(); for (int i=0; i < aPathCt; i++) { DirPathData anEntry; mPaths.push_back(anEntry); ReadWString(mPaths.back().mPath); mPaths.back().mMode = static_cast<DirGetMode>(ReadShort()); } }
// ClientCDKey::BuildStringKey // Build string representation of CD-Key from internal form. void ClientCDKey::BuildStringKey() const { WTRACE("ClientCDKey::BuildStringKey"); __int64 aBuf = BufferFromFields(); unsigned int anOffset = 0; // Extract each char from 8 byte vuffer and add to mStrKey WDBG_LL("ClientCDKey::BuildStringKey Buf=" << hex << aBuf << dec); mStrKey.erase(); for (int i=0; i < STRINGKEY_LEN;) { switch (STRINGKEY_MAP[i]) { case 'C': BuildCChar(aBuf, anOffset); break; case 'V': BuildVChar(aBuf, anOffset); break; case 'N': BuildNChar(aBuf, anOffset); break; #ifdef _DEBUG default: throw WONCommon::WONException(WONCommon::ExSoftwareFail, __LINE__, __FILE__, "ClientCDKey::BuildStringKey Unknown char is STRINGKEY_MAP!"); break; #endif } // Add dash every four chars if ((((++i) % DASH_OFFSET) == 0) && (i < STRINGKEY_LEN)) mStrKey += '-'; } WDBG_LL("ClientCDKey::BuildStringKey StrKey=" << mStrKey); }
// ClientCDKey::CreateSymmetricKey // Creates a symmetric key from product name used to save/load CD-Key to/from // the registry. Symmetric key is created via a series of CRCs on the product. void ClientCDKey::CreateSymmetricKey(BFSymmetricKey& theSymKeyR) const { WTRACE("ClientCDKey::CreateSymmetricKey"); WDBG_LL("ClientCDKey::CreateSymmetricKey from product=" << mProduct); CRC16 aCRC; RawBuffer aBuf; // CRC the product and use it as 1st 2 bytes of key aCRC.Put(mProduct); unsigned short aCheckSum = aCRC.GetCRC(); WDBG_LL("ClientCDKey::CreateSymmetricKey First CRC=" << aCheckSum); aBuf.assign(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum)); // CRC each of 1st 3 chars of product and add them to key. for (int i=0; (i < 3) && (i < mProduct.size()); i++) { aCRC.Put(static_cast<unsigned char>(mProduct[i])); aCheckSum = aCRC.GetCRC(); WDBG_LL("ClientCDKey::CreateSymmetricKey Add CRC=" << aCheckSum); aBuf.append(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum)); } // Create the key WDBG_LL("ClientCDKey::CreateSymmetricKey Buf=" << aBuf); theSymKeyR.Create(aBuf.size(), aBuf.data()); }
// ClientCDKey::DecryptKey // Decrypt 16 byte binary key into 8 byte buffer. Uses symmetric key built from product // name for decryption. bool ClientCDKey::DecryptKey(__int64& theBufR) { WTRACE("ClientCDKey::DecryptKey"); try { // Build symmetric key from product WDBG_LL("ClientCDKey::DecryptKey Creating symmetric key from product=" << mProduct); BFSymmetricKey aSymKey; CreateSymmetricKey(aSymKey); // Decrypt the key WDBG_LL("ClientCDKey::DecryptKey Decrypting CDKey."); BFSymmetricKey::CryptReturn aDecrypt(aSymKey.Decrypt(mBinKey.data(), mBinKey.size())); auto_ptr<unsigned char> aDelP(aDecrypt.first); if (aDecrypt.second != sizeof(theBufR)) { WDBG_LM("ClientCDKey::DecryptKey Decrypt of key has bad length."); return false; } // Fill buffer with decrypted key memcpy(static_cast<void*>(&theBufR), aDecrypt.first, sizeof(theBufR)); } catch (WONCrypt::CryptException& anExR) { WDBG_LH("ClientCDKey::DecryptKey exception decrypting key: " << anExR); return false; } return true; }
// ClientCDKey::EncryptKey // Encrypts into 8 byte buffer in 16 byte binary. Uses symmetric key built from product // name for encryption. bool ClientCDKey::EncryptKey(const __int64& theBufR) const { WTRACE("ClientCDKey::EncryptKey"); try { // Build symmetric key from product WDBG_LL("ClientCDKey::EncryptKey Creating symmetric key from product=" << mProduct); BFSymmetricKey aSymKey; CreateSymmetricKey(aSymKey); // Decrypt the key WDBG_LL("ClientCDKey::EncryptKey Encrypting CDKey."); BFSymmetricKey::CryptReturn anEncrypt(aSymKey.Encrypt(reinterpret_cast<const unsigned char*>(&theBufR), sizeof(theBufR))); auto_ptr<unsigned char> aDelP(anEncrypt.first); if (anEncrypt.second != BINARYKEY_LEN) { WDBG_LM("ClientCDKey::EncryptKey Encrypt of key has bad length."); return false; } // Fill BinKey with encrypted key mBinKey.assign(anEncrypt.first, anEncrypt.second); } catch (WONCrypt::CryptException& anExR) { WDBG_LH("ClientCDKey::EncryptKey exception encrypting key: " << anExR); return false; } return true; }
// TMsgAuth1Complete::Pack // Virtual method from TMessage. Packs data into message buffer and // sets the new message length. void* TMsgAuth1Complete::Pack(void) { WTRACE("TMsgAuth1Complete::Pack"); SetServiceType(WONMsg::Auth1PeerToPeer); SetMessageType(WONMsg::Auth1Complete); TMsgAuthRawBufferBase::Pack(); WDBG_LL("TMsgAuth1Complete::Pack Appending message data"); AppendShort(static_cast<short>(mStatus)); // Append error info if status implies failure if (mStatus < 0) { WDBG_LL("TMsgAuth1Complete::Pack Failure status, append error info"); AppendShort(mErrList.size()); ErrorList::iterator anItr(mErrList.begin()); for (; anItr != mErrList.end(); anItr++) Append_PA_STRING(*anItr); } // Otherwise append success info else { WDBG_LL("TMsgAuth1Complete::Pack Success status, append secret and optional session"); PackRawBuf(); if (mSessionId != 0) AppendShort(mSessionId); } return GetDataPtr(); }
// Auth1PublicKeyBlock::PackData // Packs member data into raw buffer in base class. Returns true on success and // false on failure. Makes sure keyList is not empty. Appends number of keys // in key list. For each key, appends key length and the key. bool Auth1PublicKeyBlock::PackData() { WTRACE("Auth1PublicKeyBlock::PackData"); if (! AuthPublicKeyBlockBase::PackData()) return false; // KeyList cannot be empty. WDBG_LL("Auth1PublicKeyBlock::PackData Validating..."); if (mKeyList.empty()) { WDBG_LH("Auth1PublicKeyBlock::PackData KeySet is empty, pack fails."); return false; } // Append fixed length data WDBG_LL("Auth1PublicKeyBlock::PackData Packing..."); unsigned short aNumKeys = mKeyList.size(); makeLittleEndian(aNumKeys); mRawBuf.append(reinterpret_cast<unsigned char*>(&aNumKeys), sizeof(aNumKeys)); // Append each key (length and binary data) WDBG_LL("Auth1PublicKeyBlock::PackData Packing keys (" << mKeyList.size() << ')'); PublicKeyList::iterator anItr(mKeyList.begin()); for (; anItr != mKeyList.end(); anItr++) { unsigned short aKeyLen = anItr->GetKeyLen(); unsigned short tmpKeyLen = getLittleEndian(aKeyLen); mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpKeyLen), sizeof(tmpKeyLen)); mRawBuf.append(anItr->GetKey(), aKeyLen); } return true; }
// SMsgDirG2GetNumEntitiesReply::Unpack // Virtual method from SmallMessage. Extracts data from message buffer. void SMsgDirG2GetNumEntitiesReply::Unpack(void) { WTRACE("SMsgDirG2GetNumEntitiesReply::Unpack"); SmallMessage::Unpack(); if ((GetServiceType() != WONMsg::SmallDirServerG2) || (GetMessageType() != WONMsg::DirG2GetNumEntitiesReply)) { WDBG_AH("SMsgDirG2GetNumEntitiesReply::Unpack Not a DirG2GetNumEntitiesReply message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a DirG2GetNumEntitiesReply message."); } WDBG_LL("SMsgDirG2GetNumEntitiesReply::Unpack Reading message data"); unsigned short anEntryCt = ReadShort(); WDBG_LL("SMsgDirG2GetNumEntitiesReply::Unpack Reading " << anEntryCt << " entries."); mEntries.clear(); for (int i=0; i < anEntryCt; i++) { NumEntriesData anEntry; mEntries.push_back(anEntry); mEntries.back().first = static_cast<short>(ReadShort()); mEntries.back().second = ReadShort(); } }
// Randomizer::AllocatePool // Generates a seed from noise as follows: // 1) Initial seed is larger of BytesLeft and BytesUsed on current hard disk // 2) Seed high 2 bytes are replaced by low 2 bytes of system ticks // 3) Seed is xored with current time. __int64 Randomizer::GenerateSeed() { __int64 aSeed = 0; #ifdef WIN32 WTRACE("Randomizer::GenerateSeed"); ULARGE_INTEGER aSysTime; // Calc bytesUsed and use larger of used/left as start of seed // (3rd param of GetDiskFreeSpaceEx returns total bytes on disk.) // GetDiskFreeSpaceEx is not available in all versions of Windows. Use // LoadLibrary/GetProcAddress to determine if it's available. HMODULE hKernel = ::LoadLibrary("kernel32"); pfnGetDiskFreeSpaceEx fnGetDiskFreeSpaceEx = reinterpret_cast<pfnGetDiskFreeSpaceEx> (::GetProcAddress(hKernel, "GetDiskFreeSpaceExA")); if (fnGetDiskFreeSpaceEx != NULL) { WDBG_LM("Randomizer::GenerateSeed - using GetDiskFreeSpaceEx"); ULARGE_INTEGER aBytesLeft, aBytesUsed; fnGetDiskFreeSpaceEx(NULL, &aSysTime, &aBytesUsed, &aBytesLeft); aBytesUsed.QuadPart -= aBytesLeft.QuadPart; aSeed = (aBytesLeft.QuadPart < aBytesUsed.QuadPart ? aBytesUsed.QuadPart : aBytesLeft.QuadPart); } else { WDBG_LM("Randomizer::GenerateSeed - using GetDiskFreeSpace"); unsigned long sectorsPerCluster, bytesPerSector, freeClusters, usedClusters; GetDiskFreeSpace(NULL, §orsPerCluster, &bytesPerSector, &freeClusters, &usedClusters); usedClusters -= freeClusters; aSeed = (usedClusters < freeClusters ? freeClusters : usedClusters) * sectorsPerCluster * bytesPerSector; } ::FreeLibrary(hKernel); // Use the low bytes from sys tick as high bytes in seed WDBG_LM("Randomizer::GenerateSeed Initial Seed=" << aSeed); unsigned long aSysTick = GetTickCount(); *(reinterpret_cast<unsigned short*>(&aSeed)) = *(reinterpret_cast<unsigned short*>(&aSysTick) + 1); WDBG_LL("Randomizer::GenerateSeed Use low bytes from SysTicks=" << aSysTick); // Now xor seed with current time GetSystemTimeAsFileTime(reinterpret_cast<FILETIME*>(&aSysTime)); WDBG_LL("Randomizer::GenerateSeed XOR Seed with current time."); aSeed ^= aSysTime.QuadPart; // Seed the pool WDBG_LM("Randomizer::GenerateSeed Seed=" << aSeed); #else//if defined(_LINUX) time_t t; time(&t); aSeed = t; #endif return aSeed; }
// Auth1PrivateKeyBlock::PackData // Packs member data into raw buffer in base class. Returns true on success and // false on failure. Makes sure keyList is not empty. Appends number of keys // in key list. For each key, appends key length and the key. bool Auth1PrivateKeyBlock::PackData() { WTRACE("Auth1PrivateKeyBlock::PackData"); if (! AuthPublicKeyBlockBase::PackData()) return false; // KeyList cannot be empty. WDBG_LL("Auth1PrivateKeyBlock::PackData Validating..."); if (mKeyList.empty()) { WDBG_LH("Auth1PrivateKeyBlock::PackData KeySet is empty, pack fails."); return false; } // Append fixed length data WDBG_LL("Auth1PrivateKeyBlock::PackData Packing..."); unsigned short aNumKeys = mKeyList.size(); unsigned short tmpNumKeys = getLittleEndian(aNumKeys); mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpNumKeys), sizeof(tmpNumKeys)); // Append each key (length and binary data) WDBG_LL("Auth1PrivateKeyBlock::PackData Packing keys (" << mKeyList.size() << ')'); PrivateKeyList::iterator anItr(mKeyList.begin()); for (; anItr != mKeyList.end(); anItr++) { unsigned short aKeyLen = (*anItr)->GetKeyLen(); unsigned short tmpKeyLen = getLittleEndian(tmpKeyLen); mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpKeyLen), sizeof(tmpKeyLen)); mRawBuf.append((*anItr)->GetKey(), aKeyLen); // count and record which BlockId's map to this key. PrivateKeyMap::iterator aMapIter(mKeyMap.begin()); unsigned short aBlockIDCount=0; std::list<unsigned short> aBlockIdList; for(; aMapIter != mKeyMap.end(); aMapIter++) { if( aMapIter->second == *anItr ) { aBlockIDCount++; aBlockIdList.push_back( aMapIter->first ); } } unsigned short tmpBlockIDCount = getLittleEndian(aBlockIDCount); // pack BlockId count and BlockIds mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpBlockIDCount), sizeof(tmpBlockIDCount)); while( aBlockIdList.size() ) { unsigned short aBlockId = aBlockIdList.front(); makeLittleEndian(aBlockId); mRawBuf.append(reinterpret_cast<unsigned char*>(& aBlockId), sizeof(unsigned short)); aBlockIdList.pop_front(); } } return true; }
// ClientCDKey::BuildCChar // Extracts a C from buffer starting at offset theOffset. Extracted C is appended // to mStrKey. Cs use 4 bits. Value of theOffset is incremented by 4. void ClientCDKey::BuildCChar(const __int64& theBuf, unsigned int& theOffset) const { WTRACE("ClientCDKey::BuildCChar"); WDBG_LL("ClientCDKey::BuildCChar offset=" << theOffset); char aChar = 0; // Determine mask based on char switch (ValFromBits(theBuf, theOffset, 4)) { case 0: aChar = 'B'; break; case 1: aChar = 'C'; break; case 2: aChar = 'D'; break; case 3: aChar = 'F'; break; case 4: aChar = 'G'; break; case 5: aChar = 'J'; break; case 6: aChar = 'L'; break; case 7: aChar = 'M'; break; case 8: aChar = 'N'; break; case 9: aChar = 'P'; break; case 10: aChar = 'R'; break; case 11: aChar = 'S'; break; case 12: aChar = 'T'; break; case 13: aChar = 'W'; break; case 14: aChar = 'X'; break; case 15: aChar = 'Z'; break; #ifdef _DEBUG default: throw WONCommon::WONException(WONCommon::ExSoftwareFail, __LINE__, __FILE__, "ClientCDKey::BuildCChar ValFromBits returned invalid char!"); break; #endif } // Add char to buf and update offset WDBG_LL("ClientCDKey::BuildCChar Char=" << aChar); mStrKey += aChar; theOffset += 4; }
void SMsgDirG2UpdateExtendBase::UnpackExtended(void) { WTRACE("SMsgDirG2UpdateExtendBase::UnpackExtended"); WDBG_LL("SMsgDirG2UpdateExtendBase::UnpackExtended enableDataObjects=" << mEnableDataObjects << " enableACLs=" << mEnableACLs); mDataObjects.clear(); mACLs.clear(); if (mEnableDataObjects) { unsigned short aCt = ReadShort(); WDBG_LL("SMsgDirG2UpdateExtendBase::UnpackExtended Reading " << aCt << " data objects."); for (int i=0; i < aCt; i++) { DataObject anObj; unsigned char aTypeLen = ReadByte(); if (aTypeLen > 0) anObj.GetDataType().assign(reinterpret_cast<const unsigned char*>(ReadBytes(aTypeLen)), aTypeLen); unsigned short aDataLen = ReadShort(); if (aDataLen > 0) anObj.GetData().assign(reinterpret_cast<const unsigned char*>(ReadBytes(aDataLen)), aDataLen); mDataObjects.insert(anObj); } } if (mEnableACLs) { unsigned short aCt = ReadShort(); WDBG_LL("SMsgDirG2UpdateExtendBase::UnpackExtended Reading " << aCt << " ACLs."); for (int i=0; i < aCt; i++) { DirACL anACL; anACL.mType = static_cast<WONMsg::DirG2ACLType>(ReadByte()); unsigned short aPermCt = ReadShort(); for (int j=0; j < aPermCt; j++) { Permission aPerm; aPerm.mUserId = ReadLong(); aPerm.mCommunityId = ReadLong(); aPerm.mTrustLevel = ReadShort(); anACL.mACL.insert(aPerm); } mACLs.push_back(anACL); } } }
// TMsgDirPeerDataBase::PackPeerData // Hook to pack the peer data if needed. Only appends peer data if peer // data is defined. void TMsgDirPeerDataBase::PackPeerData(void) { WTRACE("TMsgDirPeerDataBase::PackPeerData"); if (mPeerKey.size() > 0) { WDBG_LL("TMsgDirPeerDataBase::PackPeerData Appending peer data."); Append_PA_STRING(mPeerKey); AppendLong(mPeerIndex); } else WDBG_LL("TMsgDirPeerDataBase::PackPeerData No peer data to append."); }
void MMsgRoutingGetUserListReply::Unpack(void) { WTRACE("MMsgRoutingGetUserListReply::Unpack"); RoutingServerMessage::Unpack(); if (GetServiceType() != WONMsg::MiniRoutingServer || GetMessageType() != WONMsg::RoutingGetUserListReply) { WDBG_AH("MMsgRoutingGetUserListReply::Unpack Not a RoutingGetUserListReply message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a RoutingGetUserListReply message."); } WDBG_LL("MMsgRoutingGetUserListReply::Unpack Reading message data"); // read in the status mStatus = ReadShort(); // read in the user count unsigned short aNumUsers = ReadShort(); // read in the user list mUserList.clear(); for (int iUser = 0; iUser < aNumUsers; iUser++) { UserData aUser; ReadUserName(aUser.mUserName); mUserList.push_back(aUser); } }
// Auth2Certificate::PackData // Packs member data into raw buffer in base class. Returns true on success and // false on failure. Verifies member data and appends member data to buffer. bool Auth2Certificate::PackData() { WTRACE("Auth2Certificate::PackData"); if (! AuthCertificateBase::PackData()) return false; // UserId and be non-zero and at least one community's info must be known. WDBG_LL("Auth2Certificate::PackData Validating..."); if ( mDataList.size() == 0 ) { WDBG_LH("Auth2Certificate::PackData DataList is empty, pack fails."); return false; } unsigned short tmpDataListSize = mDataList.size(); mRawBuf.append(reinterpret_cast<unsigned char*>(&tmpDataListSize), sizeof(tmpDataListSize)); Auth2Certificate::DataListCIter anIter = mDataList.begin(); while( anIter != mDataList.end() ) { if( ! (*anIter)->Serialize( mRawBuf ) ) return false; ++anIter; } return true; }
void DirEntity::PackDataObjects(BaseMessage& theMsgR, const DataObjectTypeSet& theSetR, unsigned long theFlags) { WTRACE("DirEntity::PackDataObjects"); WDBG_LL("DirEntity::PackDataObject Packing data objects, size=" << theSetR.size()); theMsgR.AppendShort(theSetR.size()); bool packType = ((theFlags & WONMsg::GF_ADDDOTYPE) != 0); bool packData = ((theFlags & WONMsg::GF_ADDDODATA) != 0); DataObjectTypeSet::const_iterator anItr(theSetR.begin()); for (; anItr != theSetR.end(); anItr++) { if (packType) { unsigned char aTypeLen = anItr->GetDataType().size(); theMsgR.AppendByte(aTypeLen); theMsgR.AppendBytes(aTypeLen, anItr->GetDataType().data()); } if (packData) { unsigned short aDataLen = anItr->GetData().size(); theMsgR.AppendShort(aDataLen); theMsgR.AppendBytes(aDataLen, anItr->GetData().data()); } } }
// TMsgCommPingReply::unpack // Virtual method from TMessage. Extracts data from message buffer. void TMsgCommQueryOptReply::Unpack(void) { WTRACE("TMsgCommQueryOptReply::Unpack"); mOptionMap.clear(); TMessage::Unpack(); if ((GetServiceType() != WONMsg::CommonService) || (GetMessageType() != WONMsg::CommQueryOptionsReply)) { WDBG_AH("TMsgCommQueryOptReply::Unpack Not a CommQueryOptionsReply message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a CommQueryOptionsReply message."); } unsigned short aCt = ReadShort(); WDBG_LL("TMsgCommQueryOptReply::Unpack reading " << aCt << " entries"); for (int i=0; i < aCt; i++) { OptionDef aDef; string anOpt; ReadString(anOpt); aDef.first = static_cast<OptionStatus>(ReadByte()); ReadWString(aDef.second); mOptionMap[anOpt] = aDef; } if (BytesLeftToRead() >= 2) mStatus = static_cast<WONMsg::ServerStatus>(static_cast<short>(ReadShort())); }
// ClientCDKey::FieldsFromBuffer // Fill in internal fields from 8 byte buffer. Light check is byte 3, key is bytes // 0-2 and 4-7. void ClientCDKey::FieldsFromBuffer(const __int64& theBuf) { WTRACE("ClientCDKey::FieldsFromBuffer"); WDBG_LL("ClientCDKey::FieldsFromBuffer Buffer=" << hex << theBuf << dec); const unsigned char* aP = reinterpret_cast<const unsigned char*>(&theBuf); // Extract lightCheck, byte 3 mLightCheck = *(aP+3); WDBG_LL("ClientCDKey::FieldsFromBuffer lightCheck=" << hex << mLightCheck << dec); // Key value is rest of bytes (0-2, 4-7) mKey.assign(aP, 3); mKey.append(aP+4, 4); WDBG_LL("ClientCDKey::FieldsFromBuffer key=" << mKey); }
// TMsgCommQueryOptions::unpack // Virtual method from TMessage. Extracts data from message buffer. void TMsgCommQueryOptions::Unpack(void) { WTRACE("TMsgCommQueryOptions::Unpack"); mOptionList.clear(); TMessage::Unpack(); if ((GetServiceType() != WONMsg::CommonService) || (GetMessageType() != WONMsg::CommQueryOptions)) { WDBG_AH("TMsgCommRehupOptions::Unpack Not a CommQueryOptions message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a CommQueryOptions message."); } // Get num options unsigned short aCt = ReadShort(); WDBG_LL("TMsgCommQueryOptions::Unpack Reading " << aCt << "entries."); for (int i=0; i < aCt; i++) { string aBuf; ReadString(aBuf); mOptionList.push_back(aBuf); } }
// TMsgDirFindServiceReply::Pack // Virtual method from TMessage. Packs data into message buffer and // sets the new message length. void* TMsgDirFindServiceReply::Pack(void) { WTRACE("TMsgDirFindServiceReply::Pack"); SetServiceType(WONMsg::DirServer); SetMessageType(WONMsg::DirFindServiceReply); TMessage::Pack(); WDBG_LL("TMsgDirFindServiceReply::Pack Appending message data"); AppendShort(static_cast<short>(mStatus)); // Service info only sent if status is ok if (mStatus == WONMsg::StatusCommon_Success) { Append_PW_STRING(mService.mPath); Append_PW_STRING(mService.mName); Append_PW_STRING(mService.mDisplayName); Append_PW_STRING(mService.mVersion); Append_PW_STRING(mService.mProtoName); Append_PW_STRING(mService.mProtoVersion); Append_PW_STRING(mService.mNetAddress); AppendLong(mService.mLifespan); AppendLong(mService.mCreated); AppendShort(mService.mBlobLen); AppendBytes(mService.mBlobLen, mService.mBlob); } return GetDataPtr(); }
// TMsgDirFindServiceReply::Unpack // Virtual method from TMessage. Extracts data from message buffer. void TMsgDirFindServiceReply::Unpack(void) { WTRACE("TMsgDirFindServiceReply::Unpack"); TMessage::Unpack(); if ((GetServiceType() != WONMsg::DirServer) || (GetMessageType() != WONMsg::DirFindServiceReply)) { WDBG_AH("TMsgDirFindServiceReply::Unpack Not a DirFindServiceReply message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a DirFindServiceReply message."); } WDBG_LL("TMsgDirFindServiceReply::Unpack Reading message data"); mStatus = static_cast<ServerStatus>(static_cast<short>(ReadShort())); // Service data only present if status is success if (mStatus == WONMsg::StatusCommon_Success) { mService.mType = DirServerEntry::EntryTypeService; ReadWString(mService.mPath); ReadWString(mService.mName); ReadWString(mService.mDisplayName); ReadWString(mService.mVersion); ReadWString(mService.mProtoName); ReadWString(mService.mProtoVersion); ReadWString(mService.mNetAddress); mService.mLifespan = ReadLong(); mService.mCreated = ReadLong(); unsigned short aLen = ReadShort(); mService.SetBlob(ReadBytes(aLen), aLen); } }
// ClientCDKey::ProcessVChar // Places a V into 8 byte buffer starting at theOffset. Vs use 2 bits. Value of // theOffset is incremented by 2. bool ClientCDKey::ProcessVChar(__int64& theBuf, unsigned int& theOffset, char theChar) { WTRACE("ClientCDKey::ProcessVChar"); WDBG_LL("ClientCDKey::ProcessVChar char=" << theChar << " offset=" << theOffset); bool aRet = true; __int64 aMask = 0; // Determine mask based on char switch (toupper(theChar)) { case 'A': aMask = 0; break; case 'E': aMask = 1; break; case 'U': aMask = 2; break; case 'Y': aMask = 3; break; default: WDBG_LH("ClientCDKey::ProcessVChar Bad input, char=" << theChar); return false; } // Shift mask by offset and or with buffer. Update offset theBuf |= (aMask << theOffset); theOffset += 2; return aRet; }
// SMsgDirG2ModifyService::Unpack // Virtual method from SmallMessage. Extracts data from message buffer. void SMsgDirG2ModifyService::Unpack(void) { WTRACE("SMsgDirG2ModifyService::Unpack"); SetKeyType(KT_SERVICE); SetExtended((GetMessageType() != WONMsg::DirG2ModifyService), (GetMessageType() == WONMsg::DirG2ModifyServiceEx)); SMsgDirG2UpdateExtendBase::Unpack(); if ((GetServiceType() != WONMsg::SmallDirServerG2) || ((GetMessageType() != WONMsg::DirG2ModifyService) && (GetMessageType() != WONMsg::DirG2ModifyServiceEx) && (GetMessageType() != WONMsg::DirG2ModifyServiceExObsolete))) { WDBG_AH("SMsgDirG2ModifyService::Unpack Not a DirG2ModifyService(Ex) message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a DirG2ModifyService(Ex) message."); } mEntityFlags = ReadByte(); UnpackKey(*this); ReadWString(mNewName); unsigned char aLen = ReadByte(); WDBG_LL("SMsgDirG2ModifyService::Unpack Read New Addr len=" << aLen); if (aLen > 0) mNewNetAddress.assign(reinterpret_cast<const unsigned char*>(ReadBytes(aLen)), aLen); ReadWString(mNewDisplayName); mNewLifespan = ReadLong(); UnpackExtended(); UnpackPeerData(); }
void MMsgRoutingCreateGroup::Unpack(void) { WTRACE("MMsgRoutingCreateGroup::Unpack"); RoutingServerMessage::Unpack(); if (GetServiceType() != WONMsg::MiniRoutingServer || GetMessageType() != WONMsg::RoutingCreateGroup) { WDBG_AH("MMsgRoutingCreateGroup::Unpack Not a RoutingCreateGroup message!"); throw WONMsg::BadMsgException(*this, __LINE__, __FILE__, "Not a RoutingCreateGroup message."); } WDBG_LL("MMsgRoutingCreateGroup::Unpack Reading message data"); // read in group name ReadGroupName(mGroupName); // read in flags unsigned char aFlags = ReadByte(); mIsPublic = ((aFlags & 0x01) != 0); mAnnounceGroupChanges = ((aFlags & 0x02) != 0); // read in client count unsigned short aNumClients = ReadShort(); // read in client list mClientList.clear(); for (int iClient = 0; iClient < aNumClients; iClient++) mClientList.push_back(ReadClientId()); }
void* MMsgRoutingCreateGroup::Pack(void) { WTRACE("MMsgRoutingCreateGroup::Pack"); SetServiceType(WONMsg::MiniRoutingServer); SetMessageType(WONMsg::RoutingCreateGroup); RoutingServerMessage::Pack(); WDBG_LL("MMsgRoutingCreateGroup::Pack Appending message data"); // append group name AppendGroupName(mGroupName); // append flags unsigned char aFlags = 0; if (mIsPublic) aFlags |= 0x01; if (mAnnounceGroupChanges) aFlags |= 0x02; AppendByte(aFlags); // append client count _ASSERT(mClientList.size() <= USHRT_MAX); AppendShort(mClientList.size()); // append client list std::list<unsigned short>::iterator itr = mClientList.begin(); while (itr != mClientList.end()) AppendClientId(*(itr++)); return GetDataPtr(); }