Changeset 5837 for trunk/src/kernel32/winimagepeldr.cpp
- Timestamp:
- May 30, 2001, 10:23:22 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagepeldr.cpp
r5832 r5837 1 /* $Id: winimagepeldr.cpp,v 1.7 6 2001-05-30 03:28:02 phallerExp $ */1 /* $Id: winimagepeldr.cpp,v 1.77 2001-05-30 08:23:21 sandervl Exp $ */ 2 2 3 3 /* … … 55 55 #include <wprocess.h> 56 56 57 #include <ccollection.h>58 59 57 //Define COMMIT_ALL to let the pe loader commit all sections of the image 60 58 //This is very useful during debugging as you'll get lots of exceptions 61 59 //otherwise. 62 63 60 //#ifdef DEBUG 64 61 #define COMMIT_ALL … … 113 110 nrsections(0), imageSize(0), dwFlags(0), section(NULL), 114 111 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) 117 114 { 118 115 HFILE dllfile; … … 142 139 strcpy(szModule, OSLibStripPath(szFileName)); 143 140 strupr(szModule); 144 145 // create objects for fast API lookup146 pLookupOrdinal = new CIndexLookupLimit(0, 65535);147 pLookupName = new CHashtableLookup(79);148 141 } 149 142 //****************************************************************************** … … 151 144 Win32PeLdrImage::~Win32PeLdrImage() 152 145 { 153 if (pLookupName)154 delete pLookupName;155 156 if (pLookupOrdinal)157 delete pLookupOrdinal;158 159 146 if(memmap) 160 147 delete memmap; … … 167 154 if(realBaseAddress) 168 155 DosFreeMem((PVOID)realBaseAddress); 156 157 if(nameexports) 158 free(nameexports); 159 160 if(ordexports) 161 free(ordexports); 169 162 170 163 if(section) … … 1306 1299 nrNameExports = ped->NumberOfNames; 1307 1300 1308 // as we now know the exact size of the export caches, resize them1309 pLookupName->setSize(nrNameExports);1310 1311 1301 int ord, RVAExport; 1312 1302 char *name; … … 1350 1340 } 1351 1341 } 1352 1353 // resize the caches1354 pLookupOrdinal->shrink();1355 pLookupName->rehash();1356 1357 1342 return(TRUE); 1358 1343 } … … 1361 1346 void Win32PeLdrImage::AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal, BOOL fAbsoluteAddress) 1362 1347 { 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); 1375 1377 } 1376 1378 //****************************************************************************** … … 1378 1380 void Win32PeLdrImage::AddOrdExport(ULONG virtaddr, ULONG ordinal, BOOL fAbsoluteAddress) 1379 1381 { 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++; 1392 1393 } 1393 1394 //****************************************************************************** … … 1805 1806 ULONG Win32PeLdrImage::getApi(char *name) 1806 1807 { 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); 1810 1836 } 1811 1837 //****************************************************************************** … … 1813 1839 ULONG Win32PeLdrImage::getApi(int ordinal) 1814 1840 { 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); 1818 1860 } 1819 1861 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.