VirtualBox

Changeset 53818 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jan 15, 2015 1:49:51 PM (10 years ago)
Author:
vboxsync
Message:

RTLdr: Added RTLDR_O_IGNORE_ARCH_IF_NO_CODE for PE resource dlls and RTLDR_O_WHATEVER_ARCH for future mach-O hacking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp

    r52839 r53818  
    32173217 * @param   cbRawImage  The raw image size.
    32183218 * @param   fFlags      Loader flags, RTLDR_O_XXX.
     3219 * @param   fNoCode     Verify that the image contains no code.
    32193220 */
    32203221static int rtldrPEValidateSectionHeaders(const IMAGE_SECTION_HEADER *paSections, unsigned cSections, const char *pszLogName,
    3221                                          const IMAGE_OPTIONAL_HEADER64 *pOptHdr, RTFOFF cbRawImage, uint32_t fFlags)
     3222                                         const IMAGE_OPTIONAL_HEADER64 *pOptHdr, RTFOFF cbRawImage, uint32_t fFlags, bool fNoCode)
    32223223{
    32233224    const uint32_t              cbImage  = pOptHdr->SizeOfImage;
     
    33053306        uRvaPrev = pSH->VirtualAddress + pSH->Misc.VirtualSize;
    33063307    }
     3308
     3309    /*
     3310     * Do a separate run if we need to validate the no-code claim from the
     3311     * optional header.
     3312     */
     3313    if (fNoCode)
     3314    {
     3315        pSH = &paSections[0];
     3316        for (unsigned cSHdrsLeft = cSections; cSHdrsLeft > 0; cSHdrsLeft--, pSH++)
     3317            if (pSH->Characteristics & (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE))
     3318                return VERR_LDR_ARCH_MISMATCH;
     3319    }
     3320
    33073321
    33083322    /** @todo r=bird: more sanity checks! */
     
    36183632     * Match the CPU architecture.
    36193633     */
    3620     if (    enmArch != RTLDRARCH_WHATEVER
    3621         &&  enmArch != enmArchImage)
    3622         return VERR_LDR_ARCH_MISMATCH;
     3634    bool fArchNoCodeCheckPending = false;
     3635    if (    enmArch != enmArchImage
     3636        &&  (   enmArch != RTLDRARCH_WHATEVER
     3637             && !(fFlags & RTLDR_O_WHATEVER_ARCH)) )
     3638    {
     3639        if (!(fFlags & RTLDR_O_IGNORE_ARCH_IF_NO_CODE))
     3640            return VERR_LDR_ARCH_MISMATCH;
     3641        fArchNoCodeCheckPending = true;
     3642    }
    36233643
    36243644    /*
     
    36343654    if (RT_FAILURE(rc))
    36353655        return rc;
     3656    if (fArchNoCodeCheckPending && OptHdr.SizeOfCode != 0)
     3657        return VERR_LDR_ARCH_MISMATCH;
    36363658
    36373659    /*
     
    36473669    {
    36483670        rc = rtldrPEValidateSectionHeaders(paSections, FileHdr.NumberOfSections, pszLogName,
    3649                                            &OptHdr, pReader->pfnSize(pReader), fFlags);
     3671                                           &OptHdr, pReader->pfnSize(pReader), fFlags, fArchNoCodeCheckPending);
    36503672        if (RT_SUCCESS(rc))
    36513673        {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette