bool ElfReader::readSectionHeader() { u4 sec = getSectionOff(); if (!sec) return false; assert(phdrs.get() != NULL); if (!is64()) { Elf32_Shdr *st = (Elf32_Shdr *) reader.seekg(sec); Elf32_Phdr *pt = phdrs.get()->_32; return readSectionHeader(ehdr._32, st, pt); } else { Elf64_Shdr *st = (Elf64_Shdr *) reader.seekg(sec); Elf64_Phdr *pt = phdrs.get()->_64; return readSectionHeader(ehdr._64, st, pt); } }
//--------------------------------------------------------------------- void BackgroundFileSerializer::readPallete( Ogre::DataStreamPtr &stream ,BackgroundFile *pDest ) { readSectionHeader( stream, SECTION_NAME_PALETTE ); stream->read( pDest->getPalette().data(), BackgroundFile::PALETTE_ENTRY_COUNT ); }
bool readSections(BigEndianView &in, Header &header, std::vector<Section> §ions) { sections.resize(header.shnum); for (auto i = 0u; i < sections.size(); ++i) { auto §ion = sections[i]; // Read section header in.seek(header.shoff + header.shentsize * i); readSectionHeader(in, section.header); if ((section.header.type == SHT_NOBITS) || !section.header.size) { continue; } // Read section data if (section.header.flags & SHF_DEFLATED) { auto stream = z_stream {}; auto ret = Z_OK; // Read the original size in.seek(section.header.offset); section.data.resize(in.read<uint32_t>()); // Inflate memset(&stream, 0, sizeof(stream)); stream.zalloc = Z_NULL; stream.zfree = Z_NULL; stream.opaque = Z_NULL; ret = inflateInit(&stream); if (ret != Z_OK) { gLog->error("Couldn't decompress .rpx section because inflateInit returned {}", ret); section.data.clear(); } else { stream.avail_in = section.header.size; stream.next_in = in.readRaw<Bytef>(section.header.size); stream.avail_out = static_cast<uInt>(section.data.size()); stream.next_out = reinterpret_cast<Bytef*>(section.data.data()); ret = inflate(&stream, Z_FINISH); if (ret != Z_OK && ret != Z_STREAM_END) { gLog->error("Couldn't decompress .rpx section because inflate returned {}", ret); section.data.clear(); } inflateEnd(&stream); } } else { section.data.resize(section.header.size); in.seek(section.header.offset); in.read(section.data.data(), section.header.size); } } return true; }
//--------------------------------------------------------------------- void BackgroundFileSerializer::readTexture( Ogre::DataStreamPtr &stream ,BackgroundFile *pDest ) { readSectionHeader( stream, SECTION_NAME_TEXTURE ); for (auto& page : pDest->getPages()) { readObject(stream, page); } }
size_t QuickDC::Hash::CacheStorage::readSection(uint32_t magic, Samurai::IO::Buffer& buffer) { size_t size = readSectionHeader(magic); if (!size) return 0; ssize_t got = file.read(&buffer, size); if (got < (ssize_t) size) { QERR("Unexpected end of file"); return 0; } position += got; return size; }
bool readSectionHeaders(BigEndianView &in, Header &header, std::vector<XSection>& sections) { sections.resize(header.shnum); for (auto i = 0u; i < sections.size(); ++i) { auto §ionHeader = sections[i].header; in.seek(header.shoff + header.shentsize * i); if (!readSectionHeader(in, sectionHeader)) { return false; } } return true; }
//--------------------------------------------------------------------- void BackgroundFileSerializer::readBackground( Ogre::DataStreamPtr &stream ,BackgroundFile *pDest ) { readSectionHeader( stream, SECTION_NAME_BACK ); auto& layers( pDest->getLayers() ); for( size_t i( 0 ); i < BackgroundFile::LAYER_COUNT; ++i ) { if( i != 0 ) { read1ByteBool( stream, layers[i].enabled ); } readLayer(stream, &layers[i], i); } }
size_t QuickDC::Hash::CacheStorage::readSection(uint32_t magic, void* ptr, size_t sz) { size_t size = readSectionHeader(magic); if (!size) return 0; if (size != sz) { QERR("readSection: unexpected record size. Expected %zu, but have %zu!", sz, size); return 0; } ssize_t got = file.read((char*) ptr, size); if (got < (ssize_t) size) { QERR("Unexpected end of file"); return 0; } position += got; return size; }