uint64 CFileDataIO::GetIntTagValue() const { uint8 type = ReadUInt8(); ReadString(false); switch (type) { case TAGTYPE_UINT64: return ReadUInt64(); break; case TAGTYPE_UINT32: return ReadUInt32(); break; case TAGTYPE_UINT16: return ReadUInt16(); break; case TAGTYPE_UINT8: return ReadUInt8(); break; default: throw wxString(wxT("Wrong tag type reading int tag")); } }
OSCL_EXPORT_REF uint16 BitStreamParser::ReadUInt16(void) { uint16 read; ((uint8*)&read)[0] = ReadUInt8(); ((uint8*)&read)[1] = ReadUInt8(); big_endian_to_host((char*)&read, sizeof(read)); return read; }
bool AtomAFRT::ReadData() { //FINEST("AFRT"); if (!ReadUInt32(_timeScale)) { FATAL("Unable to read _timeScale"); return false; } //FINEST("_timeScale: %"PRIu32, _timeScale); if (!ReadUInt8(_qualityEntryCount)) { FATAL("Unable to read _qualityEntryCount"); return false; } //FINEST("_qualityEntryCount: %"PRIu8, _qualityEntryCount); for (uint8_t i = 0; i < _qualityEntryCount; i++) { string temp; if (!ReadNullTerminatedString(temp)) { FATAL("Unable to read QualitySegmentUrlModifiers"); return false; } //FINEST("%"PRIu8": QualitySegmentUrlModifiers: %s", i, STR(temp)); ADD_VECTOR_END(_qualitySegmentUrlModifiers, temp); } if (!ReadUInt32(_fragmentRunEntryCount)) { FATAL("Unable to read _fragmentRunEntryCount"); return false; } //FINEST("_fragmentRunEntryCount: %"PRIu32, _fragmentRunEntryCount); for (uint32_t i = 0; i < _fragmentRunEntryCount; i++) { FRAGMENTRUNENTRY temp = {0, 0, 0, 0}; if (!ReadUInt32(temp.firstFragment)) { FATAL("Unable to read FRAGMENTRUNENTRY.FirstFragment"); return false; } if (!ReadUInt64(temp.firstFragmentTimestamp)) { FATAL("Unable to read FRAGMENTRUNENTRY.FirstFragmentTimestamp"); return false; } if (!ReadUInt32(temp.fragmentDuration)) { FATAL("Unable to read FRAGMENTRUNENTRY.FragmentDuration"); return false; } if (temp.fragmentDuration == 0) { if (!ReadUInt8(temp.discontinuityIndicator)) { FATAL("Unable to read FRAGMENTRUNENTRY.DiscontinuityIndicator"); return false; } } //FINEST("%"PRIu32": FRAGMENTRUNENTRY.FirstFragment: %"PRIu32"; FRAGMENTRUNENTRY.FirstFragmentTimestamp: %"PRIu64"; FRAGMENTRUNENTRY.FragmentDuration: %"PRIu32"; FRAGMENTRUNENTRY.DiscontinuityIndicator: %"PRIu8, // i, temp.firstFragment, temp.firstFragmentTimestamp, temp.fragmentDuration, temp.discontinuityIndicator); ADD_VECTOR_END(_fragmentRunEntryTable, temp); } return true; }
std::string BinaryStream::ReadSmallString() { if(myGetPos+1 > myBuffer.size()) { myGetPos = myBuffer.size(); return ""; } uint8_t size = ReadUInt8(); if(myGetPos+size+1 > myBuffer.size()) { myGetPos = myBuffer.size(); return ""; } bool nowrite = false; std::string ret; for(uint8_t i = 0; i < size; i++) { if(myBuffer[myGetPos] == 0) nowrite = true; else if(!nowrite) ret += myBuffer[myGetPos]; myGetPos++; } myGetPos++; return ret; }
unsigned char* CFileDataIO::ReadBsob(uint8* puSize) const { MULE_VALIDATE_PARAMS(puSize, wxT("NULL pointer argument in ReadBsob")); *puSize = ReadUInt8(); CScopedArray<unsigned char> bsob(*puSize); Read(bsob.get(), *puSize); return bsob.release(); }
void CFileDataIO::ReadTagPtrList(TagPtrList* taglist, bool bOptACP) const { MULE_VALIDATE_PARAMS(taglist, wxT("NULL pointer argument in ReadTagPtrList")); uint32 count = ReadUInt8(); for (uint32 i = 0; i < count; i++) { CTag* tag = ReadTag(bOptACP); taglist->push_back(tag); } }
bool BaseAtom::ReadNullTerminatedString(string &val) { val = ""; uint8_t c = 0; do { if (!ReadUInt8(c)) { FATAL("Unable to read character"); return false; } if (c != 0) val += (char) c; } while (c != 0); return true; }
bool VersionedAtom::Read() { if (!ReadUInt8(_version)) { FATAL("Unable to read version"); return false; } //FINEST("_version: %"PRIu8, _version); if (!ReadArray(_flags, 3)) { FATAL("Unable to read flags"); return false; } //FINEST("_flags: %"PRIx8"%"PRIx8"%"PRIx8, _flags[0], _flags[1], _flags[2]); return ReadData(); }
Int32 BinaryReader::Read7BitEncodedInt32() { // TODO: Protect against forever while loop (ref: .NET impl) int count = 0; int shift = 0; int b; do { b = ReadUInt8(); count |= (b & 0x7F) << shift; shift += 7; } while ((b & 0x80) != 0); return count; }
bool VersionedBoxAtom::Read() { if (!ReadUInt8(_version)) { FATAL("Unable to read version"); return false; } if (!ReadArray(_flags, 3)) { FATAL("Unable to read flags"); return false; } if (!ReadData()) { FATAL("Unable to read data"); return false; } return BoxAtom::Read(); }
MR_UInt32 ClassicObjStream::ReadStringLength() { MR_UInt8 b; ReadUInt8(b); if (b < 0xff) return b; MR_UInt16 w; ReadUInt16(w); if (w == 0xfffe) { // Unicode (length follows). ASSERT(FALSE); throw std::exception(); } else if (w == 0xffff) { MR_UInt32 dw; ReadUInt32(dw); return dw; } else { return w; } }
CTag *CFileDataIO::ReadTag(bool bOptACP) const { CTag *retVal = NULL; wxString name; byte type = 0; try { type = ReadUInt8(); name = ReadString(false); switch (type) { // NOTE: This tag data type is accepted and stored only to give us the possibility to upgrade // the net in some months. // // And still.. it doesnt't work this way without breaking backward compatibility. To properly // do this without messing up the network the following would have to be done: // - those tag types have to be ignored by any client, otherwise those tags would also be sent (and // that's really the problem) // // - ignoring means, each client has to read and right throw away those tags, so those tags get // get never stored in any tag list which might be sent by that client to some other client. // // - all calling functions have to be changed to deal with the 'nr. of tags' attribute (which was // already parsed) correctly.. just ignoring those tags here is not enough, any taglists have to // be built with the knowledge that the 'nr. of tags' attribute may get decreased during the tag // reading.. // // If those new tags would just be stored and sent to remote clients, any malicious or just bugged // client could let send a lot of nodes "corrupted" packets... // case TAGTYPE_HASH16: { retVal = new CTagHash(name, ReadHash()); break; } case TAGTYPE_STRING: retVal = new CTagString(name, ReadString(bOptACP)); break; case TAGTYPE_UINT64: retVal = new CTagInt64(name, ReadUInt64()); break; case TAGTYPE_UINT32: retVal = new CTagInt32(name, ReadUInt32()); break; case TAGTYPE_UINT16: retVal = new CTagInt16(name, ReadUInt16()); break; case TAGTYPE_UINT8: retVal = new CTagInt8(name, ReadUInt8()); break; case TAGTYPE_FLOAT32: retVal = new CTagFloat(name, ReadFloat()); break; // NOTE: This tag data type is accepted and stored only to give us the possibility to upgrade // the net in some months. // // And still.. it doesnt't work this way without breaking backward compatibility case TAGTYPE_BSOB: { uint8 size = 0; CScopedArray<unsigned char> value(ReadBsob(&size)); retVal = new CTagBsob(name, value.get(), size); break; } default: throw wxString(CFormat(wxT("Invalid Kad tag type; type=0x%02x name=%s\n")) % type % name); } } catch(const CMuleException& e) { AddLogLineN(e.what()); delete retVal; throw; } catch(const wxString& e) { AddLogLineN(e); throw; } return retVal; }
int8_t ReadInt8() { return (int8_t)ReadUInt8(); }
bool AtomAFRA::ReadData() { //FINEST("AFRA"); if (!ReadUInt8(_flags)) { FATAL("Unable to read flags"); return false; } //FINEST("flags: %" PRIu8, _flags); if (!ReadUInt32(_timeScale)) { FATAL("Unable to read timeScale"); return false; } //FINEST("_timeScale: %" PRIu32, _timeScale); if (!ReadUInt32(_entryCount)) { FATAL("Unable to read entryCount"); return false; } //FINEST("_entryCount: %" PRIu32, _entryCount); bool longOffsets = (_flags >> 6)&0x01; bool longIds = (_flags >> 7)&0x01; bool globalEntries = (_flags >> 5)&0x01; for (uint32_t i = 0; i < _entryCount; i++) { AFRAENTRY temp = {0, 0}; if (!ReadUInt64(temp.time)) { FATAL("Unable to read AFRAENTRY.Time"); return false; } if (longOffsets) { if (!ReadUInt64(temp.offset)) { FATAL("Unable to read AFRAENTRY.Offset"); return false; } } else { uint32_t ui32; if (!ReadUInt32(ui32)) { FATAL("Unable to read AFRAENTRY.Offset"); return false; } temp.offset = ui32; } //FINEST("%" PRIu32 ": AFRAENTRY.Time: %" PRIu64 "; AFRAENTRY.Offset: %" PRIu64, i, temp.time, temp.offset); ADD_VECTOR_END(_localAccessEntries, temp); } if (globalEntries) { if (!ReadUInt32(_globalEntryCount)) { FATAL("Unable to read globalEntryCount"); return false; } for (uint32_t i = 0; i < _entryCount; i++) { GLOBALAFRAENTRY temp = {0, 0, 0, 0, 0}; if (!ReadUInt64(temp.time)) { FATAL("Unable to read AFRAENTRY.Time"); return false; } //Segment,fragment if (longIds) { if (!ReadUInt32(temp.segment)) { FATAL("Unable to read GLOBALAFRAENTRY.Segment"); return false; } if (!ReadUInt32(temp.fragment)) { FATAL("Unable to read GLOBALAFRAENTRY.Fragment"); return false; } } else { uint16_t ui16; if (!ReadUInt16(ui16)) { FATAL("Unable to read GLOBALAFRAENTRY.Segment"); return false; } temp.segment = ui16; if (!ReadUInt16(ui16)) { FATAL("Unable to read GLOBALAFRAENTRY.Fragment"); return false; } temp.fragment = ui16; } //AfraOffset, OffsetFromAfra if (longOffsets) { if (!ReadUInt64(temp.afraOffset)) { FATAL("Unable to read GLOBALAFRAENTRY.AfraOffset"); return false; } if (!ReadUInt64(temp.offsetFromAfra)) { FATAL("Unable to read GLOBALAFRAENTRY.OffsetFromAfra"); return false; } } else { uint32_t ui32; if (!ReadUInt32(ui32)) { FATAL("Unable to read GLOBALAFRAENTRY.AfraOffset"); return false; } temp.afraOffset = ui32; if (!ReadUInt32(ui32)) { FATAL("Unable to read GLOBALAFRAENTRY.OffsetFromAfra"); return false; } temp.offsetFromAfra = ui32; } // FINEST("%" PRIu32 ": GLOBALAFRAENTRY.Time: %" PRIu64 "; GLOBALAFRAENTRY.Segment: %" PRIu32 "; GLOBALAFRAENTRY.Fragment: %" PRIu32 "; GLOBALAFRAENTRY.AfraOffset: %" PRIu64 "; GLOBALAFRAENTRY.OffsetFromAfra: %" PRIu64, // i, temp.time, temp.segment, temp.fragment, temp.afraOffset, temp.offsetFromAfra); ADD_VECTOR_END(_globalAccessEntries, temp); } } //FINEST("%02" PRIx8 "; timeScale: %" PRIu32 "; entryCount: %" PRIu32 "; globalEntryCount: %" PRIu32, // _flags, _timeScale, _entryCount, _globalEntryCount); return true; }
void BinaryStream::ReadData(void* where, uint32_t size) { uint8_t* data = (uint8_t*)where; for(uint32_t i = 0; i < size; i++) data[i] = ReadUInt8(); }
bool AtomDATA::Read() { //1. Read the type if (!ReadUInt32(_type)) { FATAL("Unable to read type"); return false; } //2. Read unknown 4 bytes if (!ReadUInt32(_unknown)) { FATAL("Unable to read type"); return false; } switch (_type) { case 1: { //Single string if (!ReadString(_dataString, GetSize() - 8 - 8)) { FATAL("Unable to read string"); return false; } return true; } case 0: { //many uint16_t uint64_t count = (GetSize() - 8 - 8) / 2; for (uint64_t i = 0; i < count; i++) { uint16_t val; if (!ReadUInt16(val)) { FATAL("Unable to read value"); return false; } ADD_VECTOR_END(_dataUI16, val); } return true; } case 21: { //many uint8_t uint64_t count = GetSize() - 8 - 8; for (uint64_t i = 0; i < count; i++) { uint8_t val; if (!ReadUInt8(val)) { FATAL("Unable to read value"); return false; } ADD_VECTOR_END(_dataUI8, val); } return true; } case 14: case 15: { if (!ReadString(_dataImg, GetSize() - 8 - 8)) { FATAL("Unable to read data"); return false; } return true; } default: { FATAL("Type %u not yet implemented", _type); return false; } } }
bool BinaryFP::ReadBool() { return ReadUInt8() != 0; }
char BinaryFP::ReadInt8() { return (char)ReadUInt8(); }