Skip to content

PeDeinit

Description

Release storage owned by a Pe. Frees the data Buf through its carried allocator (unconditional – parser always owns its bytes) and tears down the sections vector. Safe on a zeroed struct.

Success

Returns to the caller. *self is zeroed.

Failure

Function cannot fail. NULL self is a no-op.

Usage example (Cross-references)

Usage examples (Cross-references)
                PdbDeinit(&e->pdb);
            if (e->pe_open)
                PeDeinit(&e->pe);
            StrDeinit(&e->module_path);
        }
    
    fail:
        PeDeinit(out);
        return false;
    }
    }
    
    void PeDeinit(Pe *self) {
        if (!self)
            return;
        ok = ok && pe.codeview.pdb_path && ZstrCompare(pe.codeview.pdb_path, kPdbPath) == 0;
    
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok          = ok && !PeRvaToOffset(&pe, 0xdead0000, &garbage);
    
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok                  = ok && PeFindSection(&pe, ".nope") == NULL;
    
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok      = ok && !PeRvaToOffset(&pe, 0x100, &low);
    
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool             opened = PeOpenFromMemoryCopy(&pe, bytes, len, ALLOCATOR_OF(&alloc));
        if (opened)
            PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return !opened;
        ok      = ok && pe.image_base == PE_IMAGE_BASE; // L230 assign, image_base assembly
        ok      = ok && pe.size_of_image == PE_SIZE_OF_IMAGE;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.image_base == 0x7766554433221100ull;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok      = ok && pe.size_of_image == PE_SIZE_OF_IMAGE;
        ok      = ok && pe.machine == PE_MACHINE_I386;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.image_base == 0x00410000ull;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool ok = PeOpenFromMemoryCopy(&pe, blob, sizeof(blob), ALLOCATOR_OF(&alloc));
        if (ok)
            PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool opened = PeOpenFromMemoryCopy(&pe, bad, sizeof(bad), ALLOCATOR_OF(&alloc));
        if (opened)
            PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return !opened;
        if (ok) {
            ok = ok && pe.size_of_image == PE_SIZE_OF_IMAGE;
            PeDeinit(&pe);
        }
        DefaultAllocatorDeinit(&alloc);
        }
        bool ok = pe.codeview.present && pe.codeview.age == CV_AGE;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false; // no debug dir -> absent
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok      = ok && pe.codeview.age == CV_AGE;
        ok      = ok && pe.codeview.pdb_path && ZstrCompare(pe.codeview.pdb_path, kPdbPath) == 0;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false; // L424 default must survive
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false; // unterminated -> rejected
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == true && ZstrCompare(pe.codeview.pdb_path, "ABCD") == 0;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == true && pe.codeview.age == CV_AGE && ZstrCompare(pe.codeview.pdb_path, "") == 0;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == true && pe.codeview.age == CV_AGE && MemCompare(pe.codeview.guid, kGuid, 16) == 0;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == true && pe.codeview.age == CV_AGE && MemCompare(pe.codeview.guid, kGuid, 16) == 0;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false; // real rejects the overrun
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == true && pe.codeview.age == CV_AGE && MemCompare(pe.codeview.guid, kGuid, 16) == 0;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false; // NUL past region_end ignored
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == false; // only index 0 may be read
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = pe.codeview.present == true && pe.codeview.age == CV_AGE && MemCompare(pe.codeview.guid, kGuid, 16) == 0;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok      = ok && VecPtrAt(&pe.sections, 1)->virtual_address == 0x2000;
    
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = VecLen(&pe.sections) == 2;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok                  = ok && ZstrLen(s->name) == 8;
        ok                  = ok && ZstrCompare(s->name, "ABCDEFGH") == 0;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool opened = PeOpenFromMemoryCopy(&pe, blob, total, ALLOCATOR_OF(&alloc));
        if (opened)
            PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return !opened;
        u64  off = 0;
        bool ok  = PeRvaToOffset(&pe, 0x2040, &off) && off == 0x340;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && !PeRvaToOffset(&pe, 0x0FFF, &tmp);                // just below start
    
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && !PeRvaToOffset(&pe, 0x1010, &past);
    
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        u64  off = 0xdead;
        bool ok  = !PeRvaToOffset(&pe, 0x9000, &off);
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok                  = ok && PeFindSection(&pe, ".text") != NULL;
        ok                  = ok && PeFindSection(&pe, ".absent") == NULL;
        PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok      = ok && PeFindSection(&pe, "") == NULL; // L580 upper bound
    
        PeDeinit(&pe);
        DebugAllocatorDeinit(&alloc);
        return ok;
        bool ok = !opened && BufData(&pe.data) == NULL && BufLength(&pe.data) == 0 && VecLen(&pe.sections) == 0;
        if (opened)
            PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            ok = pe.machine == PE_MACHINE_X86_64 && VecLen(&pe.sections) == 1 &&
                 ZstrCompare(VecPtrAt(&pe.sections, 0)->name, ".text") == 0;
            PeDeinit(&pe);
        }
        bool opened = PeOpen(&pe, (Zstr)StrBegin(&path), base);
        if (opened)
            PeDeinit(&pe);
    
        FileRemove(&path);
        bool ok = PeOpenFromMemoryCopy(&pe, blob, sizeof(blob), ALLOCATOR_OF(&alloc));
        if (ok)
            PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool opened = PeOpenFromMemoryCopy(&pe, blob, sizeof(blob), ALLOCATOR_OF(&alloc));
        if (opened)
            PeDeinit(&pe);
        DefaultAllocatorDeinit(&alloc);
        return !opened;
Last updated on