Changeset 4047 for trunk/src


Ignore:
Timestamp:
Aug 19, 2000, 7:22:52 PM (25 years ago)
Author:
bird
Message:

Tempfix which makes the resource section writeable and commits the 64KB
preceding the resource section commited and readable.

Location:
trunk/src/kernel32
Files:
2 edited

Legend:

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

    r3765 r4047  
    1 /* $Id: winimagepe2lx.cpp,v 1.11 2000-06-28 18:08:35 sandervl Exp $ */
     1/* $Id: winimagepe2lx.cpp,v 1.12 2000-08-19 17:22:52 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.
     267         */
     268        int iSection;
     269        if (pResRootDir != NULL && (iSection = getSectionIndexFromRVA(ulRVAResourceSection)) != -1)
     270        {
     271            ULONG ulAddr = paSections[iSection].ulAddress;
     272            rc = DosSetMem((PVOID)ulAddr, paSections[iSection].cbVirtual, PAG_WRITE | PAG_READ);
     273            ulAddr -= 0x10000;
     274            while (ulAddr < paSections[iSection].ulAddress)
     275            {
     276                ULONG   fl = ~0UL;
     277                ULONG   cb = ~0UL;
     278                if ((rc = DosQueryMem((PVOID)ulAddr, &cb, &fl)) == NO_ERROR)
     279                {
     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;
     289                }
     290            }
     291            rc = NO_ERROR;
     292        }
    262293    }
    263294
     
    593624}
    594625
     626
     627/**
     628 * Gets the (0-based) index into paSection of the section holding the
     629 * given ulRVA.
     630 * @returns     Section index (0 based).
     631 *              -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 */
     643LONG Win32Pe2LxImage::getSectionIndexFromRVA(ULONG ulRVA)
     644{
     645    int i;
     646    #ifdef DEBUG
     647        if (paSections == NULL)
     648            return NULL;
     649    #endif
     650
     651    if (ulRVA == 0UL)
     652        return NULL;
     653
     654    i = 0;
     655    while (i < cSections &&
     656           !(paSections[i].ulRVA <= ulRVA && paSections[i].ulRVA + paSections[i].cbVirtual > ulRVA)) /* ALIGN on page too? */
     657        i++;
     658
     659    if (i >= cSections)
     660        return -1;
     661
     662    return i;
     663}
     664
     665
    595666/**
    596667 * Gets pointer to an exported procedure by procedure name.
  • trunk/src/kernel32/winimagepe2lx.h

    r3074 r4047  
    1 /* $Id: winimagepe2lx.h,v 1.1 2000-03-10 16:12:03 sandervl Exp $ */
     1/* $Id: winimagepe2lx.h,v 1.2 2000-08-19 17:22:52 bird Exp $ */
    22
    33/*
     
    5656    /** @cat RVA -> pointer */
    5757    /* this should be moved to winimagebase some day... */
    58     PVOID    getPointerFromRVA(ULONG ulRVA);
     58    PVOID   getPointerFromRVA(ULONG ulRVA);
     59    LONG    getSectionIndexFromRVA(ULONG ulRVA);
    5960
    6061    PSECTION            paSections; /* Used by getPointerFromRVA and created by getSections and
Note: See TracChangeset for help on using the changeset viewer.