Skip to content

PeFindSection

Description

Find a section by name (first match; PE allows duplicates but they’re vanishingly rare).

Success

Returns a pointer to the matching PeSection, borrowed from self (valid until PeDeinit).

Failure

Returns NULL when no section matches.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        const PeSection *s  = PeFindSection(&pe, ".debug");
        bool             ok = s != NULL && s->virtual_address == SECTION_VA && s->raw_offset == DEBUG_RAW_OFF;
        ok                  = ok && PeFindSection(&pe, ".nope") == NULL;
        const PeSection *s  = PeFindSection(&pe, ".debug");
        bool             ok = s != NULL && s->virtual_address == SECTION_VA && s->raw_offset == DEBUG_RAW_OFF;
        ok                  = ok && PeFindSection(&pe, ".nope") == NULL;
    
        PeDeinit(&pe);
            return false;
        }
        const PeSection *s  = PeFindSection(&pe, "ABCDEFGH");
        bool             ok = s != NULL && s->virtual_address == 0x2000 && s->raw_offset == 0x321;
        ok                  = ok && PeFindSection(&pe, ".text") != NULL;
        const PeSection *s  = PeFindSection(&pe, "ABCDEFGH");
        bool             ok = s != NULL && s->virtual_address == 0x2000 && s->raw_offset == 0x321;
        ok                  = ok && PeFindSection(&pe, ".text") != NULL;
        ok                  = ok && PeFindSection(&pe, ".absent") == NULL;
        PeDeinit(&pe);
        bool             ok = s != NULL && s->virtual_address == 0x2000 && s->raw_offset == 0x321;
        ok                  = ok && PeFindSection(&pe, ".text") != NULL;
        ok                  = ok && PeFindSection(&pe, ".absent") == NULL;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
    
        // The named sections resolve (sanity), but the empty name does not.
        bool ok = PeFindSection(&pe, ".text") != NULL;
        ok      = ok && PeFindSection(&pe, ".rdata") != NULL;
        ok      = ok && PeFindSection(&pe, "") == NULL; // L580 upper bound
        // The named sections resolve (sanity), but the empty name does not.
        bool ok = PeFindSection(&pe, ".text") != NULL;
        ok      = ok && PeFindSection(&pe, ".rdata") != NULL;
        ok      = ok && PeFindSection(&pe, "") == NULL; // L580 upper bound
        bool ok = PeFindSection(&pe, ".text") != NULL;
        ok      = ok && PeFindSection(&pe, ".rdata") != NULL;
        ok      = ok && PeFindSection(&pe, "") == NULL; // L580 upper bound
    
        PeDeinit(&pe);
Last updated on