Skip to content

PeOpen

Description

Open and parse a PE file from disk.

Parameters

Name Direction Description
out out Populated on success.
path in Filesystem path. Str * preferred; Zstr accepted.
alloc in Allocator for the read-in buffer and the sections vector. Must outlive the Pe.

Success

Returns true; out owns the read-in buffer.

Failure

Returns false; logs the failing step. out is left zeroed.

Usage example (Cross-references)

Usage examples (Cross-references)
    static bool entry_open(PdbCacheEntry *entry, Allocator *alloc) {
        if (!entry->pe_open) {
            if (!PeOpen(&entry->pe, &entry->module_path, alloc))
                return false;
            entry->pe_open = true;
    bool pe_open(Pe *out, Zstr path, Allocator *alloc) {
        if (!out || !path || !alloc) {
            LOG_FATAL("PeOpen: NULL argument (contract violation)");
        }
        Buf data = BufInit(alloc);
        if (FileReadAndClose(path, &data) < 0) {
            BufDeinit(&data);
            LOG_ERROR("PeOpen: failed to read {}", path);
            return false;
        }
    
        Pe   pe;
        bool ok = PeOpen(&pe, (Zstr)StrBegin(&path), base);
        if (ok) {
            ok = pe.machine == PE_MACHINE_X86_64 && VecLen(&pe.sections) == 1 &&
    
        Pe   pe;
        bool opened = PeOpen(&pe, (Zstr)StrBegin(&path), base);
        if (opened)
            PeDeinit(&pe);
Last updated on