/* too small to be a ZIP archive? */ if (fileLength < EndOfCentralDir::kEOCDLen) {
LOG("Length is %lld -- too small\n", (longlong) fileLength); return -1;
}
off_t seekStart;
size_t readAmount; if (fileLength > EndOfCentralDir::kMaxEOCDSearch) {
seekStart = fileLength - EndOfCentralDir::kMaxEOCDSearch;
readAmount = EndOfCentralDir::kMaxEOCDSearch;
} else {
seekStart = 0;
readAmount = fileLength;
} if (fseeko(mZipFp, seekStart, SEEK_SET) != 0) {
LOG("Failure seeking to end of zip at %lld", (longlong) seekStart); return -1;
}
/* read the last part of the file into the buffer */
uint8_t buf[EndOfCentralDir::kMaxEOCDSearch]; if (fread(buf, 1, readAmount, mZipFp) != readAmount) {
LOG("short file? wanted %zu\n", readAmount); return -1;
}
/* find the end-of-central-dir magic */ int i; for (i = readAmount - 4; i >= 0; i--) { if (buf[i] == 0x50 &&
ZipEntry::getLongLE(&buf[i]) == EndOfCentralDir::kSignature)
{ break;
}
} if (i < 0) {
LOG("EOCD not found, not Zip\n"); return -1;
}
/* extract eocd values */
status_t result = mEOCD.readBuf(buf + i, readAmount - i); if (result != 0) {
LOG("Failure reading %zu bytes of EOCD values", readAmount - i); return result;
}
/* *Sofarsogood."mCentralDirSize"isthesizeinbytesofthe *centraldirectory,sowecanjustseekbackthatfartofindit. *WecanalsoseekforwardmCentralDirOffsetbytesfromthe *startofthefile. * *We'renotguaranteedtohavetherestofthecentraldirinthe *buffer,norareweguaranteedthatthecentraldirwillhaveany *sortofconvenientsize.Weneedtoskiptothestartofitand *readtheheader,thentheothergoodies. * *Theonlythingwereallyneedrightnowisthefilecomment,which *we'rehopingtopreserve.
*/ if (fseeko(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
LOG("Failure seeking to central dir offset %" PRIu32 "\n",
mEOCD.mCentralDirOffset); return -1;
}
/* *Loopthroughandreadthecentraldirentries.
*/ for (int entry = 0; entry < mEOCD.mTotalNumEntries; entry++) {
ZipEntry* pEntry = new ZipEntry;
result = pEntry->initAndRewriteFromCDE(mZipFp); delete pEntry; if (result != 0) {
LOG("initFromCDE failed\n"); return -1;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.