MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / FastGetImageCount

Method FastGetImageCount

view/kernelcache/core/KernelCache.cpp:425–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423
424
425uint64_t KernelCache::FastGetImageCount(BinaryNinja::Ref<BinaryNinja::BinaryView> kcView)
426{
427 if (!kcView->GetParentView())
428 return 0;
429 auto reader = BinaryReader(kcView->GetParentView());
430 uint32_t magic = reader.Read32();
431 if (magic != MH_CIGAM_64 && magic != MH_MAGIC_64) // FIXME 32 bit
432 {
433 return 0;
434 }
435 reader.Seek(0xc);
436 uint32_t fileType = reader.Read32();
437 if (fileType != MH_FILESET)
438 {
439 return 0;
440 }
441 uint32_t ncmds = reader.Read32();
442
443 uint64_t imageCount = 0;
444
445 uint64_t off = 0x20; // FIXME 32 bit
446 while (ncmds--)
447 {
448 reader.Seek(off);
449 uint32_t cmd = reader.Read32();
450 uint32_t cmdsize = reader.Read32();
451 if (cmd == LC_FILESET_ENTRY)
452 {
453 imageCount++;
454 }
455 off += cmdsize;
456 }
457
458 return imageCount;
459}
460
461
462const std::unordered_map<std::string, uint64_t>& KernelCache::AllImageStarts() const

Callers

nothing calls this directly

Calls 4

GetParentViewMethod · 0.80
BinaryReaderClass · 0.50
Read32Method · 0.45
SeekMethod · 0.45

Tested by

no test coverage detected