Skip to content

ElfFileOpen

Description

Open and parse an ELF file from disk.

Parameters

Name Direction Description
out out Populated on success.
path in Filesystem path.
alloc in Allocator for the read-in byte buffer and the section / symbol vectors. Must outlive the ElfFile.

Success

Returns true; out is fully populated and out->owns_data is true.

Failure

Returns false; logs the failing step (open / read / magic / class / decoding). out is left zeroed.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        ElfFile elf;
        if (!ElfFileOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
    
        ElfFile elf;
        if (!ElfFileOpen(&elf, r.module_path, base)) {
            SymbolResolverDeinit(&res);
            DefaultAllocatorDeinit(&alloc);
        ElfFile          elf;
    
        bool opened = ElfFileOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc));
        if (!opened) {
            DefaultAllocatorDeinit(&alloc);
        ElfFile          elf;
    
        if (!ElfFileOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ElfFile          elf;
    
        if (!ElfFileOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        entry.path      = path;
        entry.load_base = load_base;
        if (!ElfFileOpen(&entry.elf, path, self->allocator)) {
            return NULL;
        }
    }
    
    bool ElfFileOpen(ElfFile *out, const char *path, Allocator *alloc) {
        if (!out || !path || !alloc) {
            LOG_ERROR("ElfFileOpen: NULL argument");
    bool ElfFileOpen(ElfFile *out, const char *path, Allocator *alloc) {
        if (!out || !path || !alloc) {
            LOG_ERROR("ElfFileOpen: NULL argument");
            return false;
        }
        u64   capacity = 0;
        if (!ReadCompleteFile(path, &buf, &bytes, &capacity, alloc)) {
            LOG_ERROR("ElfFileOpen: failed to read {}", path);
            return false;
        }
Last updated on