Changeset 4097 for trunk/src


Ignore:
Timestamp:
Aug 27, 2000, 5:20:37 AM (25 years ago)
Author:
bird
Message:

Temporary Resource section fix.
Added getSectionIndexFromRVA.

Location:
trunk/src/kernel32
Files:
2 edited

Legend:

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

    r4047 r4097  
    1 /* $Id: winimagepe2lx.cpp,v 1.12 2000-08-19 17:22:52 bird Exp $ */
     1/* $Id: winimagepe2lx.cpp,v 1.13 2000-08-27 03:20:37 bird Exp $ */
    22
    33/*
     
    260260        ulRVAResourceSection = pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
    261261        pResRootDir = (PIMAGE_RESOURCE_DIRECTORY)getPointerFromRVA(ulRVAResourceSection);
    262 
    263         /*
    264          * Temporary fix.
    265          * Make resource section writable.
    266          * Make 64 KB before the resource section present.
     262        /* _temporary_ fix:
     263         *  We'll have to make the resource section writable.
     264         *  And we'll have to make the pages before it readable.
    267265         */
    268         int iSection;
    269         if (pResRootDir != NULL && (iSection = getSectionIndexFromRVA(ulRVAResourceSection)) != -1)
     266        ULONG iSection = getSectionIndexFromRVA(ulRVAResourceSection);
     267        if (iSection >= 0)
    270268        {
    271             ULONG ulAddr = paSections[iSection].ulAddress;
    272             rc = DosSetMem((PVOID)ulAddr, paSections[iSection].cbVirtual, PAG_WRITE | PAG_READ);
    273             ulAddr -= 0x10000;
     269            rc = DosSetMem((PVOID)paSections[iSection].ulAddress, paSections[iSection].cbVirtual, PAG_WRITE | PAG_READ);
     270
     271            ULONG ulAddr = paSections[iSection].ulAddress - 0x10000; //64KB
    274272            while (ulAddr < paSections[iSection].ulAddress)
    275273            {
    276                 ULONG   fl = ~0UL;
    277                 ULONG   cb = ~0UL;
    278                 if ((rc = DosQueryMem((PVOID)ulAddr, &cb, &fl)) == NO_ERROR)
     274                ULONG fl = ~0UL;
     275                ULONG cb = ~0UL;
     276                rc = DosQueryMem((PVOID)ulAddr, &cb, &fl);
     277                if (rc == NO_ERROR)
    279278                {
    280                     if ((fl & PAG_COMMIT) == 0)
    281                     {
    282                         fl &= PAG_WRITE & PAG_READ & PAG_GUARD;
    283                         if ((fl & PAG_READ) == 0)
    284                             fl |= PAG_READ;
    285                         rc = DosSetMem((PVOID)ulAddr, cb, fl | PAG_COMMIT);
    286                     }
    287 
    288                     ulAddr += cb;
     279                    if (fl & PAG_GUARD)
     280                        rc = -1;
     281                    else if (fl & PAG_COMMIT)
     282                        fl &= ~(PAG_COMMIT);
     283                    else
     284                        fl |= PAG_COMMIT;
     285                    cb = (cb + 0xfffUL) & ~0xfffUL;
    289286                }
    290             }
    291             rc = NO_ERROR;
     287                else
     288                {
     289                    fl = PAG_COMMIT;
     290                    cb = 0x1000;
     291                }
     292                fl &= PAG_READ | PAG_COMMIT | PAG_WRITE | PAG_GUARD;
     293                fl |= PAG_READ;
     294                if (cb > paSections[iSection].ulAddress - ulAddr)
     295                    cb = paSections[iSection].ulAddress - ulAddr;
     296                if (rc == NO_ERROR)
     297                    rc = DosSetMem((PVOID)ulAddr, cb, fl);
     298
     299                ulAddr += cb;
     300            }
    292301        }
    293302    }
     
    336345            }
    337346            setTLSIndexAddr((LPDWORD)pv);
    338             pv = getPointerFromRVA((ULONG)pTLSDir->AddressOfCallBacks - ulBorlandRVAFix);
    339             if (pv == NULL)
    340             {
    341                 eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOffIndex - %#8x.\n",
    342                          pTLSDir->AddressOfIndex));
    343                 return FALSE;
    344             }
    345             setTLSCallBackAddr((PIMAGE_TLS_CALLBACK*)pv);
     347            if (pTLSDir->AddressOfCallBacks != 0)
     348            {
     349                pv = getPointerFromRVA((ULONG)pTLSDir->AddressOfCallBacks - ulBorlandRVAFix);
     350                if (pv == NULL)
     351                {
     352                    eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOffIndex - %#8x.\n",
     353                             pTLSDir->AddressOfIndex));
     354                    return FALSE;
     355                }
     356                setTLSCallBackAddr((PIMAGE_TLS_CALLBACK*)pv);
     357            }
    346358        }
    347359        else
     
    587599
    588600/**
    589  * Converts a RVA to an pointer.
     601 * Converts a RVA into a pointer.
    590602 * @returns   Pointer matching the given RVA, NULL on error.
    591603 * @param     ulRVA  An address relative to the imagebase of the original PE image.
     
    626638
    627639/**
    628  * Gets the (0-based) index into paSection of the section holding the
    629  * given ulRVA.
    630  * @returns     Section index (0 based).
     640 * Converts a RVA into a paSections index.
     641 * @returns     Index into paSections for the section containing the RVA.
    631642 *              -1 on error.
    632  * @param       ulRVA       Relative Virtual Address.
    633  * @sketch      DEBUG: validate state, paSections != NULL
    634  *              IF ulRVA is 0 THEN return NULL
    635  *              LOOP while more section left and ulRVA is not within section
    636  *                  next section
    637  *              IF section matching ulRVA is not found THEN fail.
    638  *              The index.
    639  * @status
    640  * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
    641  * @remark
    642  */
    643 LONG Win32Pe2LxImage::getSectionIndexFromRVA(ULONG ulRVA)
     643 * @param       ulRVA   An address relative to the imagebase of the original PE image.
     644 *                      If this is 0UL -1 is returned.
     645 * @sketch    DEBUG: validate state, paSections != NULL
     646 *            IF ulRVA is 0 THEN return -1
     647 *            LOOP while more section left and ulRVA is not within section
     648 *                next section
     649 *            IF section matching ulRVA is found THEN return index ELSE fail.
     650 * @status    completely implemented.
     651 * @author    knut st. osmundsen
     652 * @remark    Should not be called until getSections has returned successfully.
     653 *            RVA == 0 is ignored.
     654 */
     655ULONG Win32Pe2LxImage::getSectionIndexFromRVA(ULONG ulRVA)
    644656{
    645657    int i;
    646658    #ifdef DEBUG
    647659        if (paSections == NULL)
    648             return NULL;
     660            return -1;
    649661    #endif
    650662
    651663    if (ulRVA == 0UL)
    652         return NULL;
     664        return -1;
    653665
    654666    i = 0;
     
    657669        i++;
    658670
    659     if (i >= cSections)
    660         return -1;
    661 
    662     return i;
     671    return i < cSections ? i : -1;
    663672}
    664673
  • trunk/src/kernel32/winimagepe2lx.h

    r4047 r4097  
    1 /* $Id: winimagepe2lx.h,v 1.2 2000-08-19 17:22:52 bird Exp $ */
     1/* $Id: winimagepe2lx.h,v 1.3 2000-08-27 03:20:37 bird Exp $ */
    22
    33/*
     
    5555protected:
    5656    /** @cat RVA -> pointer */
    57     /* this should be moved to winimagebase some day... */
    58     PVOID   getPointerFromRVA(ULONG ulRVA);
    59     LONG    getSectionIndexFromRVA(ULONG ulRVA);
     57    /* these should be moved to winimagebase some day... */
     58    PVOID    getPointerFromRVA(ULONG ulRVA);
     59    ULONG    getSectionIndexFromRVA(ULONG ulRVA);
    6060
    6161    PSECTION            paSections; /* Used by getPointerFromRVA and created by getSections and
Note: See TracChangeset for help on using the changeset viewer.