static bool spGetAssetTreeInfoFromExecutable(const string& iName, int& oFD, size_t& oStart, size_t& oLength) { ZRef<ZFileLoc_POSIX> theFileLoc = ZFileLoc_POSIX::sGet_App(); if (!theFileLoc) return false; string thePath = theFileLoc->pGetPath(); oFD = ::open(thePath.c_str(), O_RDONLY); if (oFD < 0) return false; try { // We don't want theStream to adopt the file descriptor \a oFD. ZStreamRPos_File_POSIX theStream(oFD, false); size_t theSize = theStream.GetSize(); const size_t trailerSize = spMagicTextSize + sizeof(int32) + sizeof(int32); // Check for there being at least enough room for an empty trailer. if (theSize >= trailerSize) { // There's enough space for our trailer, consisting of the magic text // and the two 32 bit offsets to asset data and the table of contents. theStream.SetPosition(theSize - trailerSize); size_t offsetOfData = theStream.ReadInt32(); size_t offsetOfTOC = theStream.ReadInt32(); if (theSize >= trailerSize + offsetOfData) { // The data offset is within the file. char checkedText[spMagicTextSize]; theStream.Read(checkedText, spMagicTextSize); if (0 == memcmp(checkedText, spMagicText, spMagicTextSize)) { // The magic text matches. if (theSize >= trailerSize + offsetOfTOC) { // The table of contents is also within the file. theStream.SetPosition(theSize - trailerSize - offsetOfTOC); size_t countOfChunks = theStream.ReadInt32(); for (size_t x = 0; x < countOfChunks; ++x) { oStart = theStream.ReadInt32() + theSize - trailerSize - offsetOfData; oLength = theStream.ReadInt32(); string currentName; if (size_t nameLength = theStream.ReadInt32()) { currentName.resize(nameLength); theStream.Read(¤tName[0], nameLength); } if (iName == currentName) return true; } } } } } } catch (...) {} ::close(oFD); return false; }