VirtualBox

Changeset 97875 in vbox


Ignore:
Timestamp:
Dec 27, 2022 10:08:00 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154965
Message:

IPRT/ldrPE: Corrections to mke tstLdr-4 pass.

File:
1 edited

Legend:

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

    r96777 r97875  
    122122    /** Size of the header (IMAGE_OPTIONAL_HEADER32::SizeOfHeaders). */
    123123    uint32_t                cbHeaders;
     124    /** Section alignment (IMAGE_OPTIONAL_HEADER32::SectionAlignment). */
     125    uint32_t                uSectionAlign;
    124126    /** The image timestamp. */
    125127    uint32_t                uTimestamp;
     
    16721674    SegInfo.cbFile      = pModPe->cbHeaders;
    16731675    SegInfo.cbMapped    = pModPe->cbHeaders;
    1674     if ((pModPe->paSections[0].Characteristics & IMAGE_SCN_TYPE_NOLOAD))
     1676    if (!(pModPe->paSections[0].Characteristics & IMAGE_SCN_TYPE_NOLOAD))
    16751677        SegInfo.cbMapped = pModPe->paSections[0].VirtualAddress;
    16761678    int rc = pfnCallback(pMod, &SegInfo, pvUser);
     
    17091711        if (SegInfo.Alignment > 0)
    17101712            SegInfo.Alignment   = RT_BIT_64(SegInfo.Alignment - 1);
     1713        else
     1714            SegInfo.Alignment   = pModPe->uSectionAlign;
    17111715        if (pSh->Characteristics & IMAGE_SCN_TYPE_NOLOAD)
    17121716        {
    17131717            SegInfo.LinkAddress = NIL_RTLDRADDR;
    17141718            SegInfo.RVA         = NIL_RTLDRADDR;
    1715             SegInfo.cbMapped    = pSh->Misc.VirtualSize;
     1719            SegInfo.cbMapped    = 0;
    17161720        }
    17171721        else
     
    17191723            SegInfo.LinkAddress = pSh->VirtualAddress + pModPe->uImageBase;
    17201724            SegInfo.RVA         = pSh->VirtualAddress;
    1721             SegInfo.cbMapped    = RT_ALIGN(SegInfo.cb, SegInfo.Alignment);
     1725            SegInfo.cbMapped    = RT_ALIGN(pSh->Misc.VirtualSize, SegInfo.Alignment);
    17221726            if (i + 1 < pModPe->cSections && !(pSh[1].Characteristics & IMAGE_SCN_TYPE_NOLOAD))
    17231727                SegInfo.cbMapped = pSh[1].VirtualAddress - pSh->VirtualAddress;
     
    18081812    if (iSeg == 0)
    18091813        *pRva = offSeg;
    1810     else if (pModPe->paSections[iSeg].Characteristics & IMAGE_SCN_TYPE_NOLOAD)
     1814    else if (!(pModPe->paSections[iSeg - 1].Characteristics & IMAGE_SCN_TYPE_NOLOAD))
     1815        *pRva = offSeg + pModPe->paSections[iSeg - 1].VirtualAddress;
     1816    else
    18111817        return VERR_LDR_INVALID_SEG_OFFSET;
    1812     else
    1813         *pRva = offSeg + pModPe->paSections[iSeg - 1].VirtualAddress;
    18141818    return VINF_SUCCESS;
    18151819}
     
    42974301    }
    42984302#endif
     4303    if (!RT_IS_POWER_OF_TWO(pOptHdr->SectionAlignment))
     4304        return RTERRINFO_LOG_SET_F(pErrInfo, VERR_BAD_EXE_FORMAT,
     4305                                   "SectionAlignment=%#x - not a power of two", pOptHdr->SectionAlignment);
     4306    if (pOptHdr->SectionAlignment < 16 || pOptHdr->SectionAlignment > _128K)
     4307        return RTERRINFO_LOG_SET_F(pErrInfo, VERR_BAD_EXE_FORMAT,
     4308                                   "SectionAlignment=%#x - unsupported value, not between 16 and 128KB", pOptHdr->SectionAlignment);
    42994309    if (pOptHdr->SizeOfHeaders >= cbImage)
    43004310    {
     
    51155125                pModPe->cbImage       = OptHdr.SizeOfImage;
    51165126                pModPe->cbHeaders     = OptHdr.SizeOfHeaders;
     5127                pModPe->uSectionAlign = OptHdr.SectionAlignment;
    51175128                pModPe->uTimestamp    = FileHdr.TimeDateStamp;
    51185129                pModPe->cImports      = UINT32_MAX;
Note: See TracChangeset for help on using the changeset viewer.

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