Skip to content
PeOpenFromMemory

PeOpenFromMemory

Description

Parse a PE image from an in-memory byte range – L-value / ownership-transfer form (mirrors VecInsertL).

Takes the caller’s Buf by pointer. The parser snapshots the Buf and zeroes the caller’s *in so any post-call use sees an empty Buf instead of a stale alias. Allocator comes from the Buf. The zero-on-take invariant holds on success and failure.

Usage example (from documentation)

  Buf buf = BufInit(&alloc);
  FileRead(&f, &buf);
  PeOpenFromMemory(&pe, &buf);
  // buf is now zeroed.

Success

Returns true; out owns the bytes; *in is zeroed.

Failure

Returns false; the bytes have been freed through the Buf’s allocator; *in is zeroed; out is left zeroed.

Usage example (Cross-references)

Usage examples (Cross-references)
    // MemSets the caller's view. Anything that fails past the snapshot
    // cleans up via PeDeinit -- the buffer never leaks.
    bool PeOpenFromMemory(Pe *out, Buf *in) {
        if (!out || !in || !BufData(in) || !BufAllocator(in)) {
            LOG_FATAL("PeOpenFromMemory: NULL argument (contract violation)");
    bool PeOpenFromMemory(Pe *out, Buf *in) {
        if (!out || !in || !BufData(in) || !BufAllocator(in)) {
            LOG_FATAL("PeOpenFromMemory: NULL argument (contract violation)");
        }
        Buf taken = *in;
        MemCopy(BufData(&copy), data, data_size);
        BufResize(&copy, (size)data_size);
        return PeOpenFromMemory(out, &copy);
    }
            return false;
        }
        return PeOpenFromMemory(out, &data);
    }
Last updated on