Changeset 5832 for trunk/src/kernel32/winimagepeldr.cpp
- Timestamp:
- May 30, 2001, 5:31:48 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagepeldr.cpp
r5830 r5832 1 /* $Id: winimagepeldr.cpp,v 1.7 5 2001-05-30 01:34:12 phaller Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.76 2001-05-30 03:28:02 phaller Exp $ */ 2 2 3 3 /* … … 61 61 //otherwise. 62 62 63 // 2001-05-30 PH enabled this again 64 #ifdef DEBUG 63 //#ifdef DEBUG 65 64 #define COMMIT_ALL 66 #endif65 //#endif 67 66 68 67 char szErrorTitle[] = "Odin"; … … 114 113 nrsections(0), imageSize(0), dwFlags(0), section(NULL), 115 114 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) 118 117 { 119 118 HFILE dllfile; … … 168 167 if(realBaseAddress) 169 168 DosFreeMem((PVOID)realBaseAddress); 170 171 if(nameexports)172 free(nameexports);173 174 if(ordexports)175 free(ordexports);176 169 177 170 if(section) … … 1313 1306 nrNameExports = ped->NumberOfNames; 1314 1307 1308 // as we now know the exact size of the export caches, resize them 1309 pLookupName->setSize(nrNameExports); 1310 1315 1311 int ord, RVAExport; 1316 1312 char *name; … … 1365 1361 void Win32PeLdrImage::AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal, BOOL fAbsoluteAddress) 1366 1362 { 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; 1383 1364 1384 1365 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 //****************************************************************************** 1378 void Win32PeLdrImage::AddOrdExport(ULONG virtaddr, ULONG ordinal, BOOL fAbsoluteAddress) 1379 { 1380 ULONG uv; 1381 if(fAbsoluteAddress) 1382 { //forwarders use absolute address 1383 uv = virtaddr; 1387 1384 } 1388 1385 else 1389 1386 { 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); 1426 1388 } 1427 1389 1428 1390 // 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); 1433 1392 } 1434 1393 //****************************************************************************** … … 1848 1807 // ordinal export from the lookup cache 1849 1808 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; 1884 1810 } 1885 1811 //****************************************************************************** … … 1889 1815 // ordinal export from the lookup cache 1890 1816 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; 1917 1818 } 1918 1819 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.