Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

static void kldrModPEDoOptionalHeaderConversion ( PIMAGE_OPTIONAL_HEADER64  pOptHdr  )  [static]

Converts a 32-bit optional header to a 64-bit one

pOptHdr The optional header to convert.

Definition at line 433 of file kLdrModPE.c.

References while().

Referenced by kldrModPEDoCreate().

    /* volatile everywhere! */
    IMAGE_OPTIONAL_HEADER32 volatile *pOptHdr32 = (IMAGE_OPTIONAL_HEADER32 volatile *)pOptHdr;
    IMAGE_OPTIONAL_HEADER64 volatile *pOptHdr64 = pOptHdr;
    KU32 volatile                    *pu32Dst;
    KU32 volatile                    *pu32Src;
    KU32 volatile                    *pu32SrcLast;
    KU32                              u32;

    /* From LoaderFlags and out the difference is 4 * 32-bits. */
    pu32Dst     = (KU32 *)&pOptHdr64->DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] - 1;
    pu32Src     = (KU32 *)&pOptHdr32->DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] - 1;
    pu32SrcLast = (KU32 *)&pOptHdr32->LoaderFlags;
    while (pu32Src >= pu32SrcLast)
        *pu32Dst-- = *pu32Src--;

    /* The previous 4 fields are 32/64 and needs special attention. */
    pOptHdr64->SizeOfHeapCommit   = pOptHdr32->SizeOfHeapCommit;
    pOptHdr64->SizeOfHeapReserve  = pOptHdr32->SizeOfHeapReserve;
    pOptHdr64->SizeOfStackCommit  = pOptHdr32->SizeOfStackCommit;
    u32 = pOptHdr32->SizeOfStackReserve;
    pOptHdr64->SizeOfStackReserve = u32;

     * The rest matches except for BaseOfData which has been merged into ImageBase in the 64-bit version.
     * Thus, ImageBase needs some special treatement. It will probably work fine assigning one to the
     * other since this is all declared volatile, but taking now chances, we'll use a temp variable.
    u32 = pOptHdr32->ImageBase;
    pOptHdr64->ImageBase = u32;

Generated by  Doxygen 1.6.0   Back to index