Ignore:
Timestamp:
May 30, 2001, 3:36:07 AM (24 years ago)
Author:
phaller
Message:

.

File:
1 edited

Legend:

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

    r5545 r5830  
    1 /* $Id: winimagepeldr.cpp,v 1.74 2001-04-19 08:32:49 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.75 2001-05-30 01:34:12 phaller Exp $ */
    22
    33/*
     
    5555#include <wprocess.h>
    5656
     57#include <ccollection.h>
     58
    5759//Define COMMIT_ALL to let the pe loader commit all sections of the image
    5860//This is very useful during debugging as you'll get lots of exceptions
    5961//otherwise.
    60 //#ifdef DEBUG
     62
     63// 2001-05-30 PH enabled this again
     64#ifdef DEBUG
    6165#define COMMIT_ALL
    62 //#endif
     66#endif
    6367
    6468char szErrorTitle[]     = "Odin";
     
    139143    strcpy(szModule, OSLibStripPath(szFileName));
    140144    strupr(szModule);
     145
     146    // create objects for fast API lookup
     147    pLookupOrdinal = new CIndexLookupLimit(0, 65535);
     148    pLookupName    = new CHashtableLookup(79);
    141149}
    142150//******************************************************************************
     
    144152Win32PeLdrImage::~Win32PeLdrImage()
    145153{
     154    if (pLookupName)
     155        delete pLookupName;
     156
     157    if (pLookupOrdinal)
     158        delete pLookupOrdinal;
     159
    146160    if(memmap)
    147161        delete memmap;
     
    13401354    }
    13411355  }
     1356
     1357  // resize the caches
     1358  pLookupOrdinal->shrink();
     1359  pLookupName->rehash();
     1360
    13421361  return(TRUE);
    13431362}
     
    13461365void Win32PeLdrImage::AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal, BOOL fAbsoluteAddress)
    13471366{
    1348  ULONG nsize;
     1367    ULONG nsize;
    13491368
    13501369    if(nameexports == NULL) {
     
    13621381        free(tmp);
    13631382    }
    1364     if(fAbsoluteAddress) {//forwarders use absolute address
     1383
     1384    if(fAbsoluteAddress) //forwarders use absolute address
     1385    {
    13651386        curnameexport->virtaddr = virtaddr;
    13661387    }
    1367     else curnameexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1388    else
     1389    {
     1390        curnameexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1391    }
     1392
     1393    // add named export to the lookup cache
     1394    pLookupName->addElement(apiname, (void*)curnameexport->virtaddr);
     1395
     1396    // also add the ordinal export to the lookup cache
     1397    pLookupOrdinal->addElement(ordinal, (void*)curnameexport->virtaddr);
     1398
    13681399    curnameexport->ordinal  = ordinal;
    13691400    *(ULONG *)curnameexport->name = 0;
     
    13801411void Win32PeLdrImage::AddOrdExport(ULONG virtaddr, ULONG ordinal, BOOL fAbsoluteAddress)
    13811412{
    1382     if(ordexports == NULL) {
     1413    if(ordexports == NULL)
     1414    {
    13831415        ordexports   = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));
    13841416        curordexport = ordexports;
    13851417    }
    1386     if(fAbsoluteAddress) {//forwarders use absolute address
     1418
     1419    if(fAbsoluteAddress)
     1420    {   //forwarders use absolute address
    13871421        curordexport->virtaddr = virtaddr;
    13881422    }
    1389     else curordexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1423    else
     1424    {
     1425        curordexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1426    }
     1427
     1428    // add ordinal export to the lookup cache
     1429    pLookupOrdinal->addElement((int)ordinal, (void*)curordexport->virtaddr);
    13901430
    13911431    curordexport->ordinal  = ordinal;
     
    18061846ULONG Win32PeLdrImage::getApi(char *name)
    18071847{
    1808   ULONG       apiaddr, i, apilen;
    1809   char       *apiname;
    1810   char        tmp[4];
    1811   NameExport *curexport;
    1812   ULONG       ulAPIOrdinal;                      /* api requested by ordinal */
     1848    // ordinal export from the lookup cache
     1849    void* pNamed = pLookupName->getElement(name);
     1850    if (pNamed != NULL)
     1851        return (ULONG)pNamed;
     1852
     1853
     1854    ULONG       apiaddr, i, apilen;
     1855    char       *apiname;
     1856    char        tmp[4];
     1857    NameExport *curexport;
     1858    ULONG       ulAPIOrdinal;                    /* api requested by ordinal */
    18131859
    18141860    apilen = strlen(name) + 1;
     
    18291875        {
    18301876            if(strcmp(curexport->name, apiname) == 0)
     1877            {
    18311878                return(curexport->virtaddr);
     1879            }
    18321880        }
    18331881        curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
     
    18391887ULONG Win32PeLdrImage::getApi(int ordinal)
    18401888{
    1841  ULONG       apiaddr, i;
    1842  OrdExport  *curexport;
    1843  NameExport *nexport;
     1889    // ordinal export from the lookup cache
     1890    void* pOrdinal = pLookupOrdinal->getElement(ordinal);
     1891    if (pOrdinal != NULL)
     1892        return (ULONG)pOrdinal;
     1893
     1894    ULONG       apiaddr, i;
     1895    OrdExport  *curexport;
     1896    NameExport *nexport;
    18441897
    18451898    curexport = ordexports;
    1846     for(i=0;i<nrOrdExports;i++) {
     1899    for(i=0;i<nrOrdExports;i++)
     1900    {
    18471901        if(curexport->ordinal == ordinal)
    18481902            return(curexport->virtaddr);
     
    18511905    //Name exports also contain an ordinal, so check this
    18521906    nexport = nameexports;
    1853     for(i=0;i<nrNameExports;i++) {
     1907    for(i=0;i<nrNameExports;i++)
     1908    {
    18541909        if(nexport->ordinal == ordinal)
     1910        {
    18551911            return(nexport->virtaddr);
     1912        }
    18561913
    18571914        nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
Note: See TracChangeset for help on using the changeset viewer.