Skip to content
ElfFindSection

ElfFindSection

Description

Find a section by name (first match). Returns NULL if absent.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        const ElfSection *text = ElfFindSection(&elf, ".text");
        bool              ok   = text != NULL && text->size > 0 && (text->flags & 0x4); // SHF_EXECINSTR = 0x4
        out->string_pool = StrInit(alloc);
    
        const ElfSection *line_section = ElfFindSection(elf, ".debug_line");
        if (!line_section || line_section->size == 0) {
            // No debug info — empty result is still success.
    
    static void elf_decode_debug_metadata(Elf *self) {
        const ElfSection *note = ElfFindSection(self, ".note.gnu.build-id");
        if (note) {
            elf_decode_build_id(self, note);
            elf_decode_build_id(self, note);
        }
        const ElfSection *dl = ElfFindSection(self, ".gnu_debuglink");
        if (dl) {
            elf_decode_debug_link(self, dl);
    }
    
    const ElfSection *ElfFindSection(const Elf *self, const char *name) {
        if (!self || !name)
            return NULL;
        out->fdes      = VecInitT(out->fdes, alloc);
    
        const ElfSection *eh = ElfFindSection(elf, ".eh_frame");
        if (!eh || eh->size == 0) {
            return true; // No CFI in this binary — still success, just empty.
            LOG_FATAL("DwarfFunctionsBuildFromElf: NULL argument");
        }
        const ElfSection *info_sec   = ElfFindSection(elf, ".debug_info");
        const ElfSection *abbrev_sec = ElfFindSection(elf, ".debug_abbrev");
        const ElfSection *str_sec    = ElfFindSection(elf, ".debug_str");
        }
        const ElfSection *info_sec   = ElfFindSection(elf, ".debug_info");
        const ElfSection *abbrev_sec = ElfFindSection(elf, ".debug_abbrev");
        const ElfSection *str_sec    = ElfFindSection(elf, ".debug_str");
        const ElfSection *info_sec   = ElfFindSection(elf, ".debug_info");
        const ElfSection *abbrev_sec = ElfFindSection(elf, ".debug_abbrev");
        const ElfSection *str_sec    = ElfFindSection(elf, ".debug_str");
    
        const u8 *info_b   = info_sec ? BufData(&elf->data) + info_sec->offset : NULL;
Last updated on