MCPcopy Create free account
hub / github.com/MJx0/KittyMemoryEx / findCentralDirectory

Function findCentralDirectory

KittyMemoryEx/KittyUtils.cpp:413–478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411 }
412
413 bool findCentralDirectory(const uint8_t *data, uint64_t fileSize, uint64_t *cdOffset, uint64_t *totalEntries)
414 {
415 if (fileSize < KT_MIN_EOCD_SIZE)
416 return false;
417
418 uint64_t searchStart = (fileSize > KT_MAX_EOCD_SEARCH) ? fileSize - KT_MAX_EOCD_SEARCH : 0;
419
420 for (int64_t offset = fileSize - 4; offset >= (int64_t)searchStart; --offset)
421 {
422 uint32_t sig;
423 if (!read32(data, fileSize, offset, sig))
424 continue;
425
426 if (sig == KT_EOCD_SIGNATURE)
427 {
428 uint16_t entries16;
429 uint32_t cdOff32;
430
431 if (!read16(data, fileSize, offset + 10, entries16))
432 return false;
433 if (!read32(data, fileSize, offset + 16, cdOff32))
434 return false;
435
436 if (totalEntries)
437 *totalEntries = entries16;
438
439 if (cdOffset)
440 *cdOffset = cdOff32;
441
442 return true;
443 }
444
445 if (sig == KT_ZIP64_EOCD_LOCATOR)
446 {
447 uint64_t zip64EOCDOffset;
448 if (!read64(data, fileSize, offset + 8, zip64EOCDOffset))
449 return false;
450
451 uint32_t zip64sig;
452 if (!read32(data, fileSize, zip64EOCDOffset, zip64sig))
453 return false;
454
455 if (zip64sig != KT_ZIP64_EOCD_SIGNATURE)
456 return false;
457
458 uint64_t entries64;
459 uint64_t cdOff64;
460
461 if (!read64(data, fileSize, zip64EOCDOffset + 24, entries64))
462 return false;
463
464 if (!read64(data, fileSize, zip64EOCDOffset + 48, cdOff64))
465 return false;
466
467 if (totalEntries)
468 *totalEntries = entries64;
469
470 if (cdOffset)

Callers 1

listEntriesInZipFunction · 0.85

Calls 3

read32Function · 0.85
read16Function · 0.85
read64Function · 0.85

Tested by

no test coverage detected