void DecodePartMetFile(const CFileDataIO& file) { uint16_t PartCount = 0; uint8_t version = file.ReadUInt8(); cout << "Version : " << VersionInfo(version, PartMetFile) << endl; if (version != PARTFILE_VERSION && version != PARTFILE_SPLITTEDVERSION && version != PARTFILE_VERSION_LARGEFILE) { cerr << "File seems to be corrupt, invalid version!" << endl; return; } bool isnewstyle = (version == PARTFILE_SPLITTEDVERSION); if (!isnewstyle) { uint8_t test[4]; file.Seek(24, wxFromStart); file.Read(test, 4); file.Seek(1, wxFromStart); if (test[0] == 0 && test[1] == 0 && test[2] == 2 && test[3] == 1) { isnewstyle = true; } } if (isnewstyle) { uint32_t temp = file.ReadUInt32(); if (temp == 0) { PrintHashsetFromFile(file); } else { file.Seek(2, wxFromStart); PrintDateFromFile(file); cout << "FileHash : " << file.ReadHash() << '\n'; } } else { PrintDateFromFile(file); PrintHashsetFromFile(file); } uint32_t tagCount = file.ReadUInt32(); cout << "TagCount : " << tagCount << '\n'; for (; tagCount > 0; tagCount--) { CTag tag(file, true); if (tag.GetNameID() == FT_FILESIZE) { PartCount = (tag.GetInt() + (PARTSIZE - 1)) / PARTSIZE; } cout << '\t' << tag << '\n'; } if (isnewstyle && (file.GetPosition() < file.GetLength())) { file.Seek(1, wxFromCurrent); cout << "HashSet : "; for (uint16_t i = 0; i < PartCount && (file.GetPosition() + 16 < file.GetLength()); i++) { if (i) { cout << ", "; } cout << file.ReadHash(); } } cout << '\n'; }
void DecodeClientsMet(const CFileDataIO& file) { uint8_t version = file.ReadUInt8(); cout << "Version : " << VersionInfo(version, CreditFile) << endl; if (version != CREDITFILE_VERSION) { cerr << "File seems to be corrupt, invalid version!" << endl; return; } uint32_t count = file.ReadUInt32(); cout << "Count : " << count << '\n'; for (uint32_t i = 0; i < count; i++) { cout << wxString::Format(wxT("#%u\tKey : "), i) << file.ReadHash(); uint32_t uploaded = file.ReadUInt32(); uint32_t downloaded = file.ReadUInt32(); cout << "\n\tUploaded : " << uploaded; cout << "\n\tDownloaded : " << downloaded; cout << "\n\tLast Seen : " << CTimeT(file.ReadUInt32()); uint32_t uphi = file.ReadUInt32(); uint32_t downhi = file.ReadUInt32(); uint64_t totalup = (static_cast<uint64_t>(uphi) << 32) + uploaded; uint64_t totaldown = (static_cast<uint64_t>(downhi) << 32) + downloaded; cout << "\n\tUploadedHI : " << uphi << " Total : " << totalup << " (" << CastItoXBytes(totalup) << ')'; cout << "\n\tDownloadedHI : " << downhi << " Total : " << totaldown << " (" << CastItoXBytes(totaldown) << ')'; cout << "\n\t(Reserved) : " << file.ReadUInt16(); uint8_t keysize = file.ReadUInt8(); cout << "\n\tKeySize : " << (unsigned)keysize; cout << "\n\tKey Data : "; char buf[MAXPUBKEYSIZE]; file.Read(buf, MAXPUBKEYSIZE); PrintByteArray(buf, MAXPUBKEYSIZE); cout << endl; if (keysize > MAXPUBKEYSIZE) { cerr << "\n*** Corruption found while reading credit file! ***\n" << endl; break; } } }
CTag::CTag(const CFileDataIO& data, bool bOptUTF8) { // Zero variables to allow for safe deletion m_uType = m_uName = m_nSize = m_uVal = 0; m_pData = NULL; try { m_uType = data.ReadUInt8(); if (m_uType & 0x80) { m_uType &= 0x7F; m_uName = data.ReadUInt8(); } else { uint16 length = data.ReadUInt16(); if (length == 1) { m_uName = data.ReadUInt8(); } else { m_uName = 0; m_Name = data.ReadOnlyString(utf8strNone,length); } } // NOTE: It's very important that we read the *entire* packet data, // even if we do not use each tag. Otherwise we will get in trouble // when the packets are returned in a list - like the search results // from a server. If we cannot do this, then we throw an exception. switch (m_uType) { case TAGTYPE_STRING: m_pstrVal = new wxString(data.ReadString(bOptUTF8)); break; case TAGTYPE_UINT32: m_uVal = data.ReadUInt32(); break; case TAGTYPE_UINT64: m_uVal = data.ReadUInt64(); break; case TAGTYPE_UINT16: m_uVal = data.ReadUInt16(); m_uType = TAGTYPE_UINT32; break; case TAGTYPE_UINT8: m_uVal = data.ReadUInt8(); m_uType = TAGTYPE_UINT32; break; case TAGTYPE_FLOAT32: //#warning Endianess problem? data.Read(&m_fVal, 4); break; case TAGTYPE_HASH16: m_hashVal = new CMD4Hash(data.ReadHash()); break; case TAGTYPE_BOOL: printf("***NOTE: %s; Reading BOOL tag\n", __FUNCTION__); data.ReadUInt8(); break; case TAGTYPE_BOOLARRAY: { printf("***NOTE: %s; Reading BOOL Array tag\n", __FUNCTION__); uint16 len = data.ReadUInt16(); // 07-Apr-2004: eMule versions prior to 0.42e.29 used the formula "(len+7)/8"! //#warning This seems to be off by one! 8 / 8 + 1 == 2, etc. data.Seek((len / 8) + 1, wxFromCurrent); break; } case TAGTYPE_BLOB: // 07-Apr-2004: eMule versions prior to 0.42e.29 handled the "len" as int16! m_nSize = data.ReadUInt32(); // Since the length is 32b, this check is needed to avoid // huge allocations in case of bad tags. if (m_nSize > data.GetLength() - data.GetPosition()) { throw CInvalidPacket(wxT("Malformed tag")); } m_pData = new unsigned char[m_nSize]; data.Read(m_pData, m_nSize); break; default: if (m_uType >= TAGTYPE_STR1 && m_uType <= TAGTYPE_STR16) { uint8 length = m_uType - TAGTYPE_STR1 + 1; m_pstrVal = new wxString(data.ReadOnlyString(bOptUTF8, length)); m_uType = TAGTYPE_STRING; } else { // Since we cannot determine the length of this tag, we // simply have to abort reading the file. throw CInvalidPacket(CFormat(wxT("Unknown tag type encounted %x, cannot proceed!")) % m_uType); } } } catch (...) { if (m_uType == TAGTYPE_BLOB) { delete[] m_pData; } throw; } }