Skip to content

PdbFile

Description

Parsed PDB file. Holds the raw bytes (owned or borrowed) plus decoded indices into them.

Fields

Name Description
allocator Allocator backing the byte buffer + functions vec.
data Raw PDB bytes.
data_size Length of data in bytes.
owns_data True if data was allocated via allocator.
block_size MSF page size (read from the superblock; usually 4096 but can be 512/1024/2048).
num_streams Stream count from the directory.
info Decoded PDB Info stream (#1).
functions Sorted-by-rva list of public function names from the Publics stream. Populated by PdbFileOpen[FromMemory].

Usage example (Cross-references)

Usage examples (Cross-references)
        build_msf_blob();
    
        PdbFile pdb;
        bool    ok = PdbFileOpenFromMemory(&pdb, blob, sizeof(blob), base);
        if (!ok) {
        MemSet(garbage, 0xCC, sizeof(garbage));
    
        PdbFile pdb;
        bool    ok = !PdbFileOpenFromMemory(&pdb, garbage, sizeof(garbage), base);
        build_full_pdb_blob();
    
        PdbFile pdb;
        bool    ok = PdbFileOpenFromMemory(&pdb, fblob, sizeof(fblob), base);
        if (!ok) {
    
    // Reconstruct the stream directory into a contiguous buffer.
    static bool reconstruct_directory(PdbFile *self, u32 num_dir_bytes, u32 block_map_addr) {
        // The block_map_addr page holds an array of u32 block indices,
        // one per `block_size` chunk of the directory. The number of
    
    // Parse the reconstructed directory bytes into per-stream metadata.
    static bool parse_directory(PdbFile *self) {
        if (self->stream_dir_size < 4) {
            LOG_ERROR("PDB: directory truncated (no stream count)");
    // ---------------------------------------------------------------------------
    
    static bool parse_pdb_info(PdbFile *self) {
        if (self->num_streams <= 1)
            return true; // no info stream
    } DbiSubstreamInfo;
    
    static DbiSubstreamInfo parse_dbi_header(const PdbFile *self) {
        DbiSubstreamInfo r = {0};
        if (DBI_STREAM_INDEX >= self->num_streams)
    // return a small allocator-backed array of (RVA, VSize) pairs. Caller
    // frees via AllocatorFree.
    static SectionRva *load_section_table(const PdbFile *self, u16 section_hdr_stream, u32 *out_count) {
        *out_count = 0;
        if (section_hdr_stream >= self->num_streams)
    
    static bool walk_publics(
        const PdbFile    *self,
        u16               symrec_stream,
        const SectionRva *sections,
    
    // Top-level: pull DBI -> SectionHdr table + SymRecord stream -> publics.
    static bool parse_pdb_functions(PdbFile *self) {
        DbiSubstreamInfo dbi = parse_dbi_header(self);
        if (!dbi.ok)
    // ---------------------------------------------------------------------------
    
    bool PdbFileOpenFromMemory(PdbFile *out, u8 *data, size data_size, Allocator *alloc) {
        if (!out || !data || !alloc) {
            LOG_ERROR("PdbFileOpenFromMemory: NULL argument");
    }
    
    bool PdbFileOpen(PdbFile *out, const char *path, Allocator *alloc) {
        if (!out || !path || !alloc) {
            LOG_ERROR("PdbFileOpen: NULL argument");
    }
    
    void PdbFileDeinit(PdbFile *self) {
        if (!self)
            return;
    }
    
    const PdbFunction *PdbFileResolveRva(const PdbFile *self, u32 rva) {
        if (!self || self->functions.length == 0)
            return NULL;
        u64     module_base; // last-seen runtime load base
        PeFile  pe;
        PdbFile pdb;
        bool    pe_open;
        bool    pdb_open;
        size  name_pool_size;
        size  name_pool_used;
    } PdbFile;
    
    ///
    /// TAGS: Parser, PDB, File
    ///
    bool PdbFileOpen(PdbFile *out, const char *path, Allocator *alloc);
    
    ///
    /// TAGS: Parser, PDB, Memory
    ///
    bool PdbFileOpenFromMemory(PdbFile *out, u8 *data, size data_size, Allocator *alloc);
    
    ///
    /// Release storage owned by a `PdbFile`. Safe on a zeroed struct.
    ///
    void PdbFileDeinit(PdbFile *self);
    
    ///
    /// FAILURE : Returns NULL.
    ///
    const PdbFunction *PdbFileResolveRva(const PdbFile *self, u32 rva);
    
    #endif // MISRA_PARSERS_PDB_H
Last updated on