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

Method InitializeHeader

view/macho/machoview.cpp:1550–2363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1548
1549
1550bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_t preferredImageBase,
1551 std::string preferredImageBaseDesc, bool platformSetByUser)
1552{
1553 Ref<Settings> settings = GetLoadSettings(GetTypeName());
1554
1555 for (auto& i : header.segments)
1556 i.vmaddr += m_imageBaseAdjustment;
1557
1558 for (auto& i : header.sections)
1559 i.addr += m_imageBaseAdjustment;
1560
1561 for (auto& i : header.symbolStubSections)
1562 i.addr += m_imageBaseAdjustment;
1563
1564 for (auto& i : header.symbolPointerSections)
1565 i.addr += m_imageBaseAdjustment;
1566
1567 for (auto& entryPoint : header.entryPoints)
1568 entryPoint.first += (entryPoint.second ? 0 : m_imageBaseAdjustment);
1569
1570 if (header.routinesPresent)
1571 header.routines64.init_address += m_imageBaseAdjustment;
1572
1573 for (auto& segment : header.segments)
1574 {
1575 if ((segment.initprot == MACHO_VM_PROT_NONE) || (!segment.vmsize))
1576 continue;
1577
1578 if ((segment.initprot & MACHO_VM_PROT_EXECUTE) == MACHO_VM_PROT_EXECUTE)
1579 {
1580 if ((segment.fileoff == (0 + m_universalImageOffset)) && (segment.filesize != 0))
1581 header.textBase = segment.vmaddr;
1582 for (auto& entryPoint : header.entryPoints)
1583 {
1584 uint64_t val = entryPoint.first + (entryPoint.second ? header.textBase : 0);
1585 if (find(header.m_entryPoints.begin(), header.m_entryPoints.end(), val) == header.m_entryPoints.end())
1586 header.m_entryPoints.push_back(val);
1587 }
1588 }
1589 }
1590
1591 if (!(m_header.ident.filetype == MH_FILESET && isMainHeader)) \
1592 {
1593 BeginBulkAddSegments();
1594 for (auto &segment: header.segments) {
1595 if ((segment.initprot == MACHO_VM_PROT_NONE) || (!segment.vmsize))
1596 continue;
1597
1598 uint32_t flags = 0;
1599 if (segment.initprot & MACHO_VM_PROT_READ)
1600 flags |= SegmentReadable;
1601 if (segment.initprot & MACHO_VM_PROT_WRITE)
1602 flags |= SegmentWritable;
1603 if (segment.initprot & MACHO_VM_PROT_EXECUTE)
1604 flags |= SegmentExecutable;
1605 if (((segment.initprot & MACHO_VM_PROT_WRITE) == 0) &&
1606 ((segment.maxprot & MACHO_VM_PROT_WRITE) == 0))
1607 flags |= SegmentDenyWrite;

Callers

nothing calls this directly

Calls 15

ArrayTypeClass · 0.85
IntegerTypeClass · 0.85
push_backMethod · 0.80
LogAlertMethod · 0.80
c_strMethod · 0.80
GetStandalonePlatformMethod · 0.80
SetVirtualBaseMethod · 0.80
Get<bool>Method · 0.80
LogDebugMethod · 0.80
resizeMethod · 0.80

Tested by

no test coverage detected