Ignore:
Timestamp:
May 30, 2001, 5:31:48 AM (24 years ago)
Author:
phaller
Message:

.

File:
1 edited

Legend:

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

    r5830 r5832  
    1 /* $Id: winimagepeldr.cpp,v 1.75 2001-05-30 01:34:12 phaller Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.76 2001-05-30 03:28:02 phaller Exp $ */
    22
    33/*
     
    6161//otherwise.
    6262
    63 // 2001-05-30 PH enabled this again
    64 #ifdef DEBUG
     63//#ifdef DEBUG
    6564#define COMMIT_ALL
    66 #endif
     65//#endif
    6766
    6867char szErrorTitle[]     = "Odin";
     
    114113    nrsections(0), imageSize(0), dwFlags(0), section(NULL),
    115114    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    116     nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    117     memmap(NULL), pFixups(NULL), dwFixupSize(0), curnameexport(NULL), curordexport(NULL)
     115    nrNameExports(0), nrOrdExports(0),
     116    memmap(NULL), pFixups(NULL), dwFixupSize(0)
    118117{
    119118 HFILE  dllfile;
     
    168167    if(realBaseAddress)
    169168        DosFreeMem((PVOID)realBaseAddress);
    170 
    171     if(nameexports)
    172         free(nameexports);
    173 
    174     if(ordexports)
    175         free(ordexports);
    176169
    177170    if(section)
     
    13131306    nrNameExports = ped->NumberOfNames;
    13141307
     1308    // as we now know the exact size of the export caches, resize them
     1309    pLookupName->setSize(nrNameExports);
     1310
    13151311    int   ord, RVAExport;
    13161312    char *name;
     
    13651361void Win32PeLdrImage::AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal, BOOL fAbsoluteAddress)
    13661362{
    1367     ULONG nsize;
    1368 
    1369     if(nameexports == NULL) {
    1370         nameExportSize= 4096;
    1371         nameexports   = (NameExport *)malloc(nameExportSize);
    1372         curnameexport = nameexports;
    1373     }
    1374     nsize = (ULONG)curnameexport - (ULONG)nameexports;
    1375     if(nsize + sizeof(NameExport) + strlen(apiname) > nameExportSize) {
    1376         nameExportSize += 4096;
    1377         char *tmp = (char *)nameexports;
    1378         nameexports = (NameExport *)malloc(nameExportSize);
    1379         memcpy(nameexports, tmp, nsize);
    1380         curnameexport = (NameExport *)((ULONG)nameexports + nsize);
    1381         free(tmp);
    1382     }
     1363    ULONG uv;
    13831364
    13841365    if(fAbsoluteAddress) //forwarders use absolute address
    1385     {
    1386         curnameexport->virtaddr = virtaddr;
     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);
     1375}
     1376//******************************************************************************
     1377//******************************************************************************
     1378void Win32PeLdrImage::AddOrdExport(ULONG virtaddr, ULONG ordinal, BOOL fAbsoluteAddress)
     1379{
     1380    ULONG uv;
     1381    if(fAbsoluteAddress)
     1382    {   //forwarders use absolute address
     1383        uv = virtaddr;
    13871384    }
    13881385    else
    13891386    {
    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 
    1399     curnameexport->ordinal  = ordinal;
    1400     *(ULONG *)curnameexport->name = 0;
    1401     strcpy(curnameexport->name, apiname);
    1402 
    1403     curnameexport->nlength = strlen(apiname) + 1;
    1404     if(curnameexport->nlength < sizeof(curnameexport->name))
    1405         curnameexport->nlength = sizeof(curnameexport->name);
    1406 
    1407     curnameexport = (NameExport *)((ULONG)curnameexport->name + curnameexport->nlength);
    1408 }
    1409 //******************************************************************************
    1410 //******************************************************************************
    1411 void Win32PeLdrImage::AddOrdExport(ULONG virtaddr, ULONG ordinal, BOOL fAbsoluteAddress)
    1412 {
    1413     if(ordexports == NULL)
    1414     {
    1415         ordexports   = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));
    1416         curordexport = ordexports;
    1417     }
    1418 
    1419     if(fAbsoluteAddress)
    1420     {   //forwarders use absolute address
    1421         curordexport->virtaddr = virtaddr;
    1422     }
    1423     else
    1424     {
    1425         curordexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1387        uv = realBaseAddress + (virtaddr - oh.ImageBase);
    14261388    }
    14271389
    14281390    // add ordinal export to the lookup cache
    1429     pLookupOrdinal->addElement((int)ordinal, (void*)curordexport->virtaddr);
    1430 
    1431     curordexport->ordinal  = ordinal;
    1432     curordexport++;
     1391    pLookupOrdinal->addElement((int)ordinal, (void*)uv);
    14331392}
    14341393//******************************************************************************
     
    18481807    // ordinal export from the lookup cache
    18491808    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 */
    1859 
    1860     apilen = strlen(name) + 1;
    1861     if(apilen < 4)
    1862     {
    1863         *(ULONG *)tmp = 0;
    1864         strcpy(tmp, name);
    1865         apiname = tmp;
    1866         apilen  = 4;
    1867     }
    1868     else  apiname = name;
    1869 
    1870     curexport = nameexports;
    1871     for(i=0; i<nrNameExports; i++)
    1872     {
    1873         if(apilen == curexport->nlength &&
    1874            *(ULONG *)curexport->name == *(ULONG *)apiname)
    1875         {
    1876             if(strcmp(curexport->name, apiname) == 0)
    1877             {
    1878                 return(curexport->virtaddr);
    1879             }
    1880         }
    1881         curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
    1882     }
    1883     return(0);
     1809    return (ULONG)pNamed;
    18841810}
    18851811//******************************************************************************
     
    18891815    // ordinal export from the lookup cache
    18901816    void* pOrdinal = pLookupOrdinal->getElement(ordinal);
    1891     if (pOrdinal != NULL)
    1892         return (ULONG)pOrdinal;
    1893 
    1894     ULONG       apiaddr, i;
    1895     OrdExport  *curexport;
    1896     NameExport *nexport;
    1897 
    1898     curexport = ordexports;
    1899     for(i=0;i<nrOrdExports;i++)
    1900     {
    1901         if(curexport->ordinal == ordinal)
    1902             return(curexport->virtaddr);
    1903         curexport++;
    1904     }
    1905     //Name exports also contain an ordinal, so check this
    1906     nexport = nameexports;
    1907     for(i=0;i<nrNameExports;i++)
    1908     {
    1909         if(nexport->ordinal == ordinal)
    1910         {
    1911             return(nexport->virtaddr);
    1912         }
    1913 
    1914         nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
    1915     }
    1916     return(0);
     1817    return (ULONG)pOrdinal;
    19171818}
    19181819//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.