Ignore:
Timestamp:
May 30, 2001, 10:23:22 AM (24 years ago)
Author:
sandervl
Message:

put back old lookup code; renamed new files

File:
1 edited

Legend:

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

    r5832 r5837  
    1 /* $Id: winimagepeldr.cpp,v 1.76 2001-05-30 03:28:02 phaller Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.77 2001-05-30 08:23:21 sandervl Exp $ */
    22
    33/*
     
    5555#include <wprocess.h>
    5656
    57 #include <ccollection.h>
    58 
    5957//Define COMMIT_ALL to let the pe loader commit all sections of the image
    6058//This is very useful during debugging as you'll get lots of exceptions
    6159//otherwise.
    62 
    6360//#ifdef DEBUG
    6461#define COMMIT_ALL
     
    113110    nrsections(0), imageSize(0), dwFlags(0), section(NULL),
    114111    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    115     nrNameExports(0), nrOrdExports(0),
    116     memmap(NULL), pFixups(NULL), dwFixupSize(0)
     112    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
     113    memmap(NULL), pFixups(NULL), dwFixupSize(0), curnameexport(NULL), curordexport(NULL)
    117114{
    118115 HFILE  dllfile;
     
    142139    strcpy(szModule, OSLibStripPath(szFileName));
    143140    strupr(szModule);
    144 
    145     // create objects for fast API lookup
    146     pLookupOrdinal = new CIndexLookupLimit(0, 65535);
    147     pLookupName    = new CHashtableLookup(79);
    148141}
    149142//******************************************************************************
     
    151144Win32PeLdrImage::~Win32PeLdrImage()
    152145{
    153     if (pLookupName)
    154         delete pLookupName;
    155 
    156     if (pLookupOrdinal)
    157         delete pLookupOrdinal;
    158 
    159146    if(memmap)
    160147        delete memmap;
     
    167154    if(realBaseAddress)
    168155        DosFreeMem((PVOID)realBaseAddress);
     156
     157    if(nameexports)
     158        free(nameexports);
     159
     160    if(ordexports)
     161        free(ordexports);
    169162
    170163    if(section)
     
    13061299    nrNameExports = ped->NumberOfNames;
    13071300
    1308     // as we now know the exact size of the export caches, resize them
    1309     pLookupName->setSize(nrNameExports);
    1310 
    13111301    int   ord, RVAExport;
    13121302    char *name;
     
    13501340    }
    13511341  }
    1352 
    1353   // resize the caches
    1354   pLookupOrdinal->shrink();
    1355   pLookupName->rehash();
    1356 
    13571342  return(TRUE);
    13581343}
     
    13611346void Win32PeLdrImage::AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal, BOOL fAbsoluteAddress)
    13621347{
    1363     ULONG uv;
    1364 
    1365     if(fAbsoluteAddress) //forwarders use absolute address
    1366         uv = virtaddr;
    1367     else
    1368         uv = realBaseAddress + (virtaddr - oh.ImageBase);
    1369 
    1370     // add named export to the lookup cache
    1371     pLookupName->addElement(apiname, (void*)uv);
    1372 
    1373     // also add the ordinal export to the lookup cache
    1374     pLookupOrdinal->addElement(ordinal, (void*)uv);
     1348 ULONG nsize;
     1349
     1350    if(nameexports == NULL) {
     1351        nameExportSize= 4096;
     1352        nameexports   = (NameExport *)malloc(nameExportSize);
     1353        curnameexport = nameexports;
     1354    }
     1355    nsize = (ULONG)curnameexport - (ULONG)nameexports;
     1356    if(nsize + sizeof(NameExport) + strlen(apiname) > nameExportSize) {
     1357        nameExportSize += 4096;
     1358        char *tmp = (char *)nameexports;
     1359        nameexports = (NameExport *)malloc(nameExportSize);
     1360        memcpy(nameexports, tmp, nsize);
     1361        curnameexport = (NameExport *)((ULONG)nameexports + nsize);
     1362        free(tmp);
     1363    }
     1364    if(fAbsoluteAddress) {//forwarders use absolute address
     1365        curnameexport->virtaddr = virtaddr;
     1366    }
     1367    else curnameexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1368    curnameexport->ordinal  = ordinal;
     1369    *(ULONG *)curnameexport->name = 0;
     1370    strcpy(curnameexport->name, apiname);
     1371
     1372    curnameexport->nlength = strlen(apiname) + 1;
     1373    if(curnameexport->nlength < sizeof(curnameexport->name))
     1374        curnameexport->nlength = sizeof(curnameexport->name);
     1375
     1376    curnameexport = (NameExport *)((ULONG)curnameexport->name + curnameexport->nlength);
    13751377}
    13761378//******************************************************************************
     
    13781380void Win32PeLdrImage::AddOrdExport(ULONG virtaddr, ULONG ordinal, BOOL fAbsoluteAddress)
    13791381{
    1380     ULONG uv;
    1381     if(fAbsoluteAddress)
    1382     {   //forwarders use absolute address
    1383         uv = virtaddr;
    1384     }
    1385     else
    1386     {
    1387         uv = realBaseAddress + (virtaddr - oh.ImageBase);
    1388     }
    1389 
    1390     // add ordinal export to the lookup cache
    1391     pLookupOrdinal->addElement((int)ordinal, (void*)uv);
     1382    if(ordexports == NULL) {
     1383        ordexports   = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));
     1384        curordexport = ordexports;
     1385    }
     1386    if(fAbsoluteAddress) {//forwarders use absolute address
     1387        curordexport->virtaddr = virtaddr;
     1388    }
     1389    else curordexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1390
     1391    curordexport->ordinal  = ordinal;
     1392    curordexport++;
    13921393}
    13931394//******************************************************************************
     
    18051806ULONG Win32PeLdrImage::getApi(char *name)
    18061807{
    1807     // ordinal export from the lookup cache
    1808     void* pNamed = pLookupName->getElement(name);
    1809     return (ULONG)pNamed;
     1808  ULONG       apiaddr, i, apilen;
     1809  char       *apiname;
     1810  char        tmp[4];
     1811  NameExport *curexport;
     1812  ULONG       ulAPIOrdinal;                      /* api requested by ordinal */
     1813
     1814    apilen = strlen(name) + 1;
     1815    if(apilen < 4)
     1816    {
     1817        *(ULONG *)tmp = 0;
     1818        strcpy(tmp, name);
     1819        apiname = tmp;
     1820        apilen  = 4;
     1821    }
     1822    else  apiname = name;
     1823
     1824    curexport = nameexports;
     1825    for(i=0; i<nrNameExports; i++)
     1826    {
     1827        if(apilen == curexport->nlength &&
     1828           *(ULONG *)curexport->name == *(ULONG *)apiname)
     1829        {
     1830            if(strcmp(curexport->name, apiname) == 0)
     1831                return(curexport->virtaddr);
     1832        }
     1833        curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
     1834    }
     1835    return(0);
    18101836}
    18111837//******************************************************************************
     
    18131839ULONG Win32PeLdrImage::getApi(int ordinal)
    18141840{
    1815     // ordinal export from the lookup cache
    1816     void* pOrdinal = pLookupOrdinal->getElement(ordinal);
    1817     return (ULONG)pOrdinal;
     1841 ULONG       apiaddr, i;
     1842 OrdExport  *curexport;
     1843 NameExport *nexport;
     1844
     1845    curexport = ordexports;
     1846    for(i=0;i<nrOrdExports;i++) {
     1847        if(curexport->ordinal == ordinal)
     1848            return(curexport->virtaddr);
     1849        curexport++;
     1850    }
     1851    //Name exports also contain an ordinal, so check this
     1852    nexport = nameexports;
     1853    for(i=0;i<nrNameExports;i++) {
     1854        if(nexport->ordinal == ordinal)
     1855            return(nexport->virtaddr);
     1856
     1857        nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
     1858    }
     1859    return(0);
    18181860}
    18191861//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.