Skip to content

MachoSection

Description

Decoded section_64. Each segment contains zero or more sections; DWARF lives in the __DWARF segment, code lives in __TEXT.

Usage example (Cross-references)

Usage examples (Cross-references)
        u32  offset; // file offset
        u32  flags;
    } MachoSection;
    
    ///
    
    typedef Vec(MachoSegment) MachoSegments;
    typedef Vec(MachoSection) MachoSections;
    typedef Vec(MachoSymbol) MachoSymbols;
            return false;
    
        const MachoSection *info_sec   = MachoFindSection(&e->dsym, "__DWARF", "__debug_info");
        const MachoSection *abbrev_sec = MachoFindSection(&e->dsym, "__DWARF", "__debug_abbrev");
        const MachoSection *str_sec    = MachoFindSection(&e->dsym, "__DWARF", "__debug_str");
    
        const MachoSection *info_sec   = MachoFindSection(&e->dsym, "__DWARF", "__debug_info");
        const MachoSection *abbrev_sec = MachoFindSection(&e->dsym, "__DWARF", "__debug_abbrev");
        const MachoSection *str_sec    = MachoFindSection(&e->dsym, "__DWARF", "__debug_str");
        const MachoSection *info_sec   = MachoFindSection(&e->dsym, "__DWARF", "__debug_info");
        const MachoSection *abbrev_sec = MachoFindSection(&e->dsym, "__DWARF", "__debug_abbrev");
        const MachoSection *str_sec    = MachoFindSection(&e->dsym, "__DWARF", "__debug_str");
    
        const u8 *info_b   = info_sec ? BufData(MachoBuf(&e->dsym)) + info_sec->offset : NULL;
            // 16-byte moves below stay inside its window.
            BufIter      sec_it = IterCarve(cmd, SECT64_SIZE);
            MachoSection sec;
            MemSet(&sec, 0, sizeof(sec));
            MemCopy(sec.section, IterDataAt(&sec_it, IterIndex(&sec_it)), 16);
    }
    
    const MachoSection *macho_find_section(const Macho *self, Zstr segment, Zstr section) {
        if (!self || !segment || !section)
            return NULL;
            return NULL;
        for (size i = 0; i < VecLen(&self->sections); ++i) {
            const MachoSection *s = VecPtrAt(&self->sections, i);
            if (ZstrCompare(s->segment, segment) == 0 && ZstrCompare(s->section, section) == 0) {
                return s;
        }
    
        const MachoSection *hit = MachoFindSection(&m, "__TEXT", "__text");
        bool                ok  = hit != NULL && hit->addr == 0x100000000ull && hit->size == 0x100;
        // Right section name in the wrong segment -> no match.
            return false;
        }
        const MachoSection *hit = MachoFindSection(&m, "__TEXT", "__text");
        ok = ok && hit != NULL && hit->addr == 0x100000000ull && hit->size == 0x100 && hit->offset == 0;
        ok = ok && MachoFindSection(&m, "__DATA", "__text") == NULL;
        ok       = ok && VecLen(&m.sections) == 2;
        // The target at index 1 must be found (real ++i reaches it).
        const MachoSection *hit = MachoFindSection(&m, "__TEXT", "__cstring");
        ok = ok && hit != NULL && hit->addr == 0x100000100ull && hit->size == 0x80 && hit->offset == 0x100;
        if (ok)
Last updated on