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

Method LoadHeaderForAddress

view/kernelcache/core/KernelCache.cpp:639–1042  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637}
638
639std::optional<KernelCacheMachOHeader> KernelCache::LoadHeaderForAddress(Ref<BinaryView> view, uint64_t address, std::string installName)
640{
641 KernelCacheMachOHeader header;
642
643 header.installName = installName;
644 header.identifierPrefix = base_name(installName);
645
646 std::string errorMsg;
647 // address is a Raw file offset
648 BinaryReader reader(view->GetParentView());
649 reader.Seek(address);
650
651 header.ident.magic = reader.Read32();
652
653 BNEndianness endianness;
654 if (header.ident.magic == MH_MAGIC || header.ident.magic == MH_MAGIC_64)
655 endianness = LittleEndian;
656 else if (header.ident.magic == MH_CIGAM || header.ident.magic == MH_CIGAM_64)
657 endianness = BigEndian;
658 else
659 {
660 return {};
661 }
662
663 reader.SetEndianness(endianness);
664 header.ident.cputype = reader.Read32();
665 header.ident.cpusubtype = reader.Read32();
666 header.ident.filetype = reader.Read32();
667 header.ident.ncmds = reader.Read32();
668 header.ident.sizeofcmds = reader.Read32();
669 header.ident.flags = reader.Read32();
670 if ((header.ident.cputype & MachOABIMask) == MachOABI64) // address size == 8
671 {
672 header.ident.reserved = reader.Read32();
673 }
674 header.loadCommandOffset = reader.GetOffset();
675
676 // Parse segment commands
677 try
678 {
679 for (size_t i = 0; i < header.ident.ncmds; i++)
680 {
681 // BNLogInfo("of 0x%llx", reader.GetOffset());
682 load_command load;
683 segment_command_64 segment64;
684 section_64 sect;
685 memset(&sect, 0, sizeof(sect));
686 size_t curOffset = reader.GetOffset();
687 load.cmd = reader.Read32();
688 load.cmdsize = reader.Read32();
689 size_t nextOffset = curOffset + load.cmdsize;
690 if (load.cmdsize < sizeof(load_command))
691 return {};
692
693 switch (load.cmd)
694 {
695 case LC_MAIN:
696 {

Callers

nothing calls this directly

Calls 12

base_nameFunction · 0.85
ReadExceptionClass · 0.85
GetParentViewMethod · 0.80
push_backMethod · 0.80
SeekMethod · 0.45
Read32Method · 0.45
SetEndiannessMethod · 0.45
GetOffsetMethod · 0.45
Read64Method · 0.45
ReadMethod · 0.45
ReadCStringMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected