Ignore:
Timestamp:
May 30, 2001, 8:33:00 PM (24 years ago)
Author:
phaller
Message:

.

File:
1 edited

Legend:

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

    r5837 r5841  
    1 /* $Id: winimagepeldr_new.cpp,v 1.1 2001-05-30 08:23:21 sandervl Exp $ */
     1/* $Id: winimagepeldr_new.cpp,v 1.2 2001-05-30 18:32:15 phaller Exp $ */
    22
    33/*
     
    6060//This is very useful during debugging as you'll get lots of exceptions
    6161//otherwise.
    62 
    6362//#ifdef DEBUG
    6463#define COMMIT_ALL
     
    114113    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    115114    nrNameExports(0), nrOrdExports(0),
     115#ifdef VERIFY_LOADER
     116    nameexports(NULL), ordexports(NULL),
     117    curnameexport(NULL), curordexport(NULL),
     118#endif
    116119    memmap(NULL), pFixups(NULL), dwFixupSize(0)
    117120{
     
    145148    // create objects for fast API lookup
    146149    pLookupOrdinal = new CIndexLookupLimit(0, 65535);
    147     pLookupName    = new CHashtableLookup(79);
     150    pLookupName    = new CHashtableLookup(503);
    148151}
    149152//******************************************************************************
     
    167170    if(realBaseAddress)
    168171        DosFreeMem((PVOID)realBaseAddress);
     172
     173#ifdef VERIFY_LOADER
     174    if(nameexports)
     175        free(nameexports);
     176
     177    if(ordexports)
     178        free(ordexports);
     179#endif
    169180
    170181    if(section)
     
    13731384    // also add the ordinal export to the lookup cache
    13741385    pLookupOrdinal->addElement(ordinal, (void*)uv);
     1386
     1387#ifdef VERIFY_LOADER
     1388    ULONG nsize;
     1389
     1390    if(nameexports == NULL) {
     1391        nameExportSize= 4096;
     1392        nameexports   = (NameExport *)malloc(nameExportSize);
     1393        curnameexport = nameexports;
     1394    }
     1395    nsize = (ULONG)curnameexport - (ULONG)nameexports;
     1396    if(nsize + sizeof(NameExport) + strlen(apiname) > nameExportSize) {
     1397        nameExportSize += 4096;
     1398        char *tmp = (char *)nameexports;
     1399        nameexports = (NameExport *)malloc(nameExportSize);
     1400        memcpy(nameexports, tmp, nsize);
     1401        curnameexport = (NameExport *)((ULONG)nameexports + nsize);
     1402        free(tmp);
     1403    }
     1404    if(fAbsoluteAddress) {//forwarders use absolute address
     1405        curnameexport->virtaddr = virtaddr;
     1406    }
     1407    else curnameexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1408    curnameexport->ordinal  = ordinal;
     1409    *(ULONG *)curnameexport->name = 0;
     1410    strcpy(curnameexport->name, apiname);
     1411
     1412    curnameexport->nlength = strlen(apiname) + 1;
     1413    if(curnameexport->nlength < sizeof(curnameexport->name))
     1414        curnameexport->nlength = sizeof(curnameexport->name);
     1415
     1416    curnameexport = (NameExport *)((ULONG)curnameexport->name + curnameexport->nlength);
     1417#endif
    13751418}
    13761419//******************************************************************************
     
    13901433    // add ordinal export to the lookup cache
    13911434    pLookupOrdinal->addElement((int)ordinal, (void*)uv);
     1435
     1436
     1437#ifdef VERIFY_LOADER
     1438    if(ordexports == NULL) {
     1439        ordexports   = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));
     1440        curordexport = ordexports;
     1441    }
     1442    if(fAbsoluteAddress) {//forwarders use absolute address
     1443        curordexport->virtaddr = virtaddr;
     1444    }
     1445    else curordexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
     1446
     1447    curordexport->ordinal  = ordinal;
     1448    curordexport++;
     1449#endif
    13921450}
    13931451//******************************************************************************
     
    18031861//******************************************************************************
    18041862//******************************************************************************
     1863#ifdef VERIFY_LOADER
     1864ULONG Win32PeLdrImage::new_getApi(char *name)
     1865#else
    18051866ULONG Win32PeLdrImage::getApi(char *name)
     1867#endif
    18061868{
    18071869    // ordinal export from the lookup cache
    1808     void* pNamed = pLookupName->getElement(name);
    1809     return (ULONG)pNamed;
    1810 }
    1811 //******************************************************************************
    1812 //******************************************************************************
     1870    return (ULONG)pLookupName->getElement(name);
     1871}
     1872//******************************************************************************
     1873//******************************************************************************
     1874#ifdef VERIFY_LOADER
     1875ULONG Win32PeLdrImage::new_getApi(int ordinal)
     1876#else
    18131877ULONG Win32PeLdrImage::getApi(int ordinal)
     1878#endif
    18141879{
    18151880    // ordinal export from the lookup cache
    1816     void* pOrdinal = pLookupOrdinal->getElement(ordinal);
    1817     return (ULONG)pOrdinal;
    1818 }
     1881    return (ULONG)pLookupOrdinal->getElement(ordinal);
     1882}
     1883//******************************************************************************
     1884//******************************************************************************
     1885#ifdef VERIFY_LOADER
     1886ULONG Win32PeLdrImage::getApi(char *name)
     1887{
     1888    ULONG ulVerify1 = new_getApi(name);
     1889    ULONG ulVerify2 = old_getApi(name);
     1890
     1891    if (ulVerify1 != ulVerify2)
     1892        dprintf((LOG,
     1893                 "WinImagePeLdr::getApi(%s) difference: ulVerify1=%08xh, ulVerify2=%08xh\n",
     1894                 name,
     1895                 ulVerify1,
     1896                 ulVerify2));
     1897
     1898    return ulVerify2;
     1899}
     1900
     1901
     1902ULONG Win32PeLdrImage::getApi(int ordinal)
     1903{
     1904    ULONG ulVerify1 = new_getApi(ordinal);
     1905    ULONG ulVerify2 = old_getApi(ordinal);
     1906
     1907    if (ulVerify1 != ulVerify2)
     1908        dprintf((LOG,
     1909                 "WinImagePeLdr::getApi(%d) difference: ulVerify1=%08xh, ulVerify2=%08xh\n",
     1910                 ordinal,
     1911                 ulVerify1,
     1912                 ulVerify2));
     1913
     1914    return ulVerify2;
     1915}
     1916
     1917
     1918
     1919
     1920ULONG Win32PeLdrImage::old_getApi(char *name)
     1921{
     1922  ULONG       apiaddr, i, apilen;
     1923  char       *apiname;
     1924  char        tmp[4];
     1925  NameExport *curexport;
     1926  ULONG       ulAPIOrdinal;                      /* api requested by ordinal */
     1927
     1928    apilen = strlen(name) + 1;
     1929    if(apilen < 4)
     1930    {
     1931        *(ULONG *)tmp = 0;
     1932        strcpy(tmp, name);
     1933        apiname = tmp;
     1934        apilen  = 4;
     1935    }
     1936    else  apiname = name;
     1937
     1938    curexport = nameexports;
     1939    for(i=0; i<nrNameExports; i++)
     1940    {
     1941        if(apilen == curexport->nlength &&
     1942           *(ULONG *)curexport->name == *(ULONG *)apiname)
     1943        {
     1944            if(strcmp(curexport->name, apiname) == 0)
     1945                return(curexport->virtaddr);
     1946        }
     1947        curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
     1948    }
     1949    return(0);
     1950}
     1951//******************************************************************************
     1952//******************************************************************************
     1953ULONG Win32PeLdrImage::old_getApi(int ordinal)
     1954{
     1955 ULONG       apiaddr, i;
     1956 OrdExport  *curexport;
     1957 NameExport *nexport;
     1958
     1959    curexport = ordexports;
     1960    for(i=0;i<nrOrdExports;i++) {
     1961        if(curexport->ordinal == ordinal)
     1962            return(curexport->virtaddr);
     1963        curexport++;
     1964    }
     1965    //Name exports also contain an ordinal, so check this
     1966    nexport = nameexports;
     1967    for(i=0;i<nrNameExports;i++) {
     1968        if(nexport->ordinal == ordinal)
     1969            return(nexport->virtaddr);
     1970
     1971        nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
     1972    }
     1973    return(0);
     1974}
     1975#endif
    18191976//******************************************************************************
    18201977//Returns required OS version for this image
Note: See TracChangeset for help on using the changeset viewer.