Ignore:
Timestamp:
Oct 2, 2000, 6:00:36 AM (25 years ago)
Author:
bird
Message:

Made corrections for Borland TLS. (Beyond Compare works now)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/winimagepe2lx.cpp

    r4304 r4357  
    1 /* $Id: winimagepe2lx.cpp,v 1.15 2000-09-22 04:35:09 bird Exp $ */
     1/* $Id: winimagepe2lx.cpp,v 1.16 2000-10-02 04:00:35 bird Exp $ */
    22
    33/*
     
    270270         *  And we'll have to make the pages before it readable.
    271271         */
    272         ULONG iSection = getSectionIndexFromRVA(ulRVAResourceSection);
     272        LONG iSection = getSectionIndexFromRVA(ulRVAResourceSection);
    273273        if (iSection >= 0)
    274274        {
     
    313313    {
    314314        PIMAGE_TLS_DIRECTORY pTLSDir;
     315        LONG                 iSection;
     316        iSection = getSectionIndexFromRVA(pNtHdrs->OptionalHeader.
     317                                          DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].
     318                                          VirtualAddress);
    315319        pTLSDir = (PIMAGE_TLS_DIRECTORY)getPointerFromRVA(pNtHdrs->OptionalHeader.
    316320                                                          DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].
    317321                                                          VirtualAddress);
    318322
    319         if (pTLSDir != NULL)
     323        if (pTLSDir != NULL && iSection != -1)
    320324        {
    321325            PVOID pv;
    322326            ULONG ulBorlandRVAFix = 0UL;
    323327
    324             pv = getPointerFromRVA(pTLSDir->StartAddressOfRawData);
    325328            /*
    326329             * Borland seems to have problems getting things right...
    327              * Needs to subtract image base to make the TLSDir "RVA"s real
    328              * RVAs before converting them to pointers.
     330             *      Uses real pointers with baserelocations.
     331             * Needs to subtract image loadaddress to make the TLSDir them RVAs.
     332             *
     333             * We'll check if the StartAddressOfRawData pointer is an RVA or an real address by
     334             * check if it is within the TLS section or not.
     335             * ASSUMES: StartAddressOfRawData is in the same section as the TLS Directory.
    329336             */
    330             if ((pv == NULL || pTLSDir->StartAddressOfRawData == 0UL)
    331                 && pTLSDir->StartAddressOfRawData > this->pNtHdrs->OptionalHeader.ImageBase)
    332                 {
    333                 ulBorlandRVAFix = this->pNtHdrs->OptionalHeader.ImageBase;
    334                 pv = getPointerFromRVA(pTLSDir->StartAddressOfRawData - ulBorlandRVAFix);
    335                 }
     337            if (paSections[iSection].ulRVA > pTLSDir->StartAddressOfRawData ||
     338                paSections[iSection].ulRVA + paSections[iSection].cbVirtual <= pTLSDir->StartAddressOfRawData)
     339                { /* StartAddressOfRawData was not an RVA within the same section as the TLS directory */
     340                ulBorlandRVAFix = paSections[iSection].ulAddress - paSections[iSection].ulRVA;
     341                }
     342            pv = getPointerFromRVA(pTLSDir->StartAddressOfRawData - ulBorlandRVAFix);
    336343            if (pv == NULL || pTLSDir->StartAddressOfRawData == 0UL)
    337344            {
     
    729736 *            RVA == 0 is ignored.
    730737 */
    731 ULONG Win32Pe2LxImage::getSectionIndexFromRVA(ULONG ulRVA)
    732 {
    733     int i;
     738LONG Win32Pe2LxImage::getSectionIndexFromRVA(ULONG ulRVA)
     739{
     740    LONG i;
    734741    #ifdef DEBUG
    735742        if (paSections == NULL)
Note: See TracChangeset for help on using the changeset viewer.