Changeset 9997 for trunk/src/kernel32/winimagepeldr.cpp
- Timestamp:
- Apr 9, 2003, 12:39:41 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagepeldr.cpp
r9963 r9997 1 /* $Id: winimagepeldr.cpp,v 1.10 6 2003-03-31 11:54:28sandervl Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.107 2003-04-09 10:39:40 sandervl Exp $ */ 2 2 3 3 /* … … 112 112 nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL), 113 113 memmap(NULL), pFixups(NULL), dwFixupSize(0), curnameexport(NULL), curordexport(NULL), 114 nrOrdExportsRegistered(0) 114 nrOrdExportsRegistered(0), peview(NULL) 115 115 { 116 116 HFILE dllfile; … … 148 148 { 149 149 if(memmap) 150 { 151 if(peview) { 152 memmap->unmapViewOfFile(peview); 153 peview = NULL; 154 } 150 155 memmap->Release(); 156 memmap = NULL; 157 } 151 158 152 159 if(hFile) { … … 171 178 DWORD Win32PeLdrImage::init(ULONG reservedMem, ULONG ulPEOffset) 172 179 { 173 LPVOID win32file = NULL;174 180 ULONG filesize, ulRead, ulNewPos; 175 181 PIMAGE_SECTION_HEADER psh; … … 252 258 goto failure; 253 259 } 254 win32file= memmap->mapViewOfFile(0, 0, 2);260 peview = memmap->mapViewOfFile(0, 0, 2); 255 261 256 262 if(DosQueryPathInfo(szFileName, FIL_QUERYFULLNAME, szFullPath, sizeof(szFullPath)) == 0) { … … 303 309 commitPage(realBaseAddress, FALSE); 304 310 305 nSections = NR_SECTIONS( win32file);311 nSections = NR_SECTIONS(peview); 306 312 section = (Section *)malloc(nSections*sizeof(Section)); 307 313 if(section == NULL) { … … 313 319 314 320 imageSize = 0; 315 if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF ( win32file)) != NULL)321 if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (peview)) != NULL) 316 322 { 317 323 dprintf((LOG, "*************************PE SECTIONS START**************************" )); … … 327 333 dprintf((LOG, "Section flags: %x\n\n", psh[i].Characteristics )); 328 334 329 if(IsSectionType( win32file, &psh[i], IMAGE_DIRECTORY_ENTRY_BASERELOC))335 if(IsSectionType(peview, &psh[i], IMAGE_DIRECTORY_ENTRY_BASERELOC)) 330 336 { 331 337 dprintf((LOG, ".reloc" )); … … 335 341 continue; 336 342 } 337 if(IsSectionType( win32file, &psh[i], IMAGE_DIRECTORY_ENTRY_EXPORT))343 if(IsSectionType(peview, &psh[i], IMAGE_DIRECTORY_ENTRY_EXPORT)) 338 344 { 339 345 //SvL: Angus.exe has empty export section that's really an … … 347 353 } 348 354 } 349 if(IsSectionType( win32file, &psh[i], IMAGE_DIRECTORY_ENTRY_RESOURCE))355 if(IsSectionType(peview, &psh[i], IMAGE_DIRECTORY_ENTRY_RESOURCE)) 350 356 { 351 357 dprintf((LOG, ".rsrc" )); … … 355 361 continue; 356 362 } 357 if(IsSectionType( win32file, &psh[i], IMAGE_DIRECTORY_ENTRY_TLS))363 if(IsSectionType(peview, &psh[i], IMAGE_DIRECTORY_ENTRY_TLS)) 358 364 { 359 365 dprintf((LOG, "TLS section")); 360 tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset( win32file, IMAGE_DIRECTORY_ENTRY_TLS);366 tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(peview, IMAGE_DIRECTORY_ENTRY_TLS); 361 367 if(tlsDir) { 362 368 addSection(SECTION_TLS, psh[i].PointerToRawData, … … 366 372 continue; 367 373 } 368 if(IsSectionType( win32file, &psh[i], IMAGE_DIRECTORY_ENTRY_DEBUG))374 if(IsSectionType(peview, &psh[i], IMAGE_DIRECTORY_ENTRY_DEBUG)) 369 375 { 370 376 dprintf((LOG, ".rdebug" )); … … 374 380 continue; 375 381 } 376 if(IsSectionType( win32file, &psh[i], IMAGE_DIRECTORY_ENTRY_IMPORT))382 if(IsSectionType(peview, &psh[i], IMAGE_DIRECTORY_ENTRY_IMPORT)) 377 383 { 378 384 int type = SECTION_IMPORT; … … 465 471 466 472 if(realBaseAddress != oh.ImageBase && !(dwFlags & FLAG_PELDR_LOADASDATAFILE)) { 467 pFixups = (PIMAGE_BASE_RELOCATION)ImageDirectoryOffset( win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC);468 dwFixupSize = ImageDirectorySize( win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC);473 pFixups = (PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(peview, IMAGE_DIRECTORY_ENTRY_BASERELOC); 474 dwFixupSize = ImageDirectorySize(peview, IMAGE_DIRECTORY_ENTRY_BASERELOC); 469 475 commitPage((ULONG)pFixups, FALSE); 470 476 } … … 475 481 if(!(dwFlags & FLAG_PELDR_LOADASDATAFILE)) 476 482 { 477 if(tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset( win32file, IMAGE_DIRECTORY_ENTRY_TLS))483 if(tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(peview, IMAGE_DIRECTORY_ENTRY_TLS)) 478 484 { 479 485 Section *sect; … … 620 626 } 621 627 #endif 622 if(processExports( (char *)win32file) == FALSE) {628 if(processExports() == FALSE) { 623 629 dprintf((LOG, "Failed to process exported apis" )); 624 630 lasterror = LDRERROR_EXPORTS; … … 655 661 if(!(dwFlags & (FLAG_PELDR_LOADASDATAFILE | FLAG_PELDR_SKIPIMPORTS))) 656 662 { 657 if(processImports( (char *)win32file) == FALSE) {663 if(processImports() == FALSE) { 658 664 dprintf((LOG, "Failed to process imports!" )); 659 665 lasterror = LDRERROR_IMPORTS; … … 1381 1387 //****************************************************************************** 1382 1388 //****************************************************************************** 1383 BOOL Win32PeLdrImage::processExports( char *win32file)1389 BOOL Win32PeLdrImage::processExports() 1384 1390 { 1385 1391 IMAGE_SECTION_HEADER sh; … … 1392 1398 /* get section header and pointer to data directory for .edata section */ 1393 1399 if((ped = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryOffset 1394 (win32file, IMAGE_DIRECTORY_ENTRY_EXPORT)) != NULL && 1395 GetSectionHdrByImageDir(win32file, IMAGE_DIRECTORY_ENTRY_EXPORT, &sh) ) { 1396 1397 dprintf((LOG, "Exported Functions: " )); 1400 (peview, IMAGE_DIRECTORY_ENTRY_EXPORT)) != NULL && 1401 GetSectionHdrByImageDir(peview, IMAGE_DIRECTORY_ENTRY_EXPORT, &sh) ) 1402 { 1403 1404 dprintf((LOG, "Exported Functions: " )); 1398 1405 ptrOrd = (USHORT *)((ULONG)ped->AddressOfNameOrdinals + 1399 (ULONG) win32file);1406 (ULONG)peview); 1400 1407 ptrNames = (ULONG *)((ULONG)ped->AddressOfNames + 1401 (ULONG) win32file);1408 (ULONG)peview); 1402 1409 ptrAddress = (ULONG *)((ULONG)ped->AddressOfFunctions + 1403 (ULONG) win32file);1410 (ULONG)peview); 1404 1411 nrOrdExports = ped->NumberOfFunctions; 1405 1412 nrNameExports = ped->NumberOfNames; … … 1409 1416 for(i=0;i<ped->NumberOfNames;i++) 1410 1417 { 1411 fForwarder = FALSE;1418 fForwarder = FALSE; 1412 1419 ord = ptrOrd[i] + ped->Base; 1413 name = (char *)((ULONG)ptrNames[i] + (ULONG) win32file);1420 name = (char *)((ULONG)ptrNames[i] + (ULONG)peview); 1414 1421 RVAExport = ptrAddress[ptrOrd[i]]; 1415 1422 … … 1421 1428 fForwarder = AddForwarder(oh.ImageBase + RVAExport, name, ord); 1422 1429 } 1423 if(!fForwarder) {1430 if(!fForwarder) { 1424 1431 //points to code (virtual address relative to oh.ImageBase 1425 1432 AddNameExport(oh.ImageBase + RVAExport, name, ord); … … 1429 1436 for(i=0;i<max(ped->NumberOfNames,ped->NumberOfFunctions);i++) 1430 1437 { 1431 fForwarder = FALSE;1438 fForwarder = FALSE; 1432 1439 ord = ped->Base + i; //Correct?? 1433 1440 RVAExport = ptrAddress[i]; … … 1439 1446 fForwarder = AddForwarder(oh.ImageBase + RVAExport, NULL, ord); 1440 1447 } 1441 if(!fForwarder && RVAExport) {1448 if(!fForwarder && RVAExport) { 1442 1449 //points to code (virtual address relative to oh.ImageBase 1443 1450 dprintf((LOG, "ord %d at 0x%08x (0x%08x)", ord, RVAExport, realBaseAddress + RVAExport)); … … 1675 1682 **/ 1676 1683 //****************************************************************************** 1677 BOOL Win32PeLdrImage::processImports( char *win32file)1684 BOOL Win32PeLdrImage::processImports() 1678 1685 { 1679 1686 PIMAGE_IMPORT_DESCRIPTOR pID; … … 1707 1714 1708 1715 /* 1) get module names */ 1709 pID = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryOffset( win32file, IMAGE_DIRECTORY_ENTRY_IMPORT);1716 pID = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryOffset(peview, IMAGE_DIRECTORY_ENTRY_IMPORT); 1710 1717 if (pID == NULL) 1711 1718 return TRUE; 1712 if (!GetSectionHdrByImageDir( win32file, IMAGE_DIRECTORY_ENTRY_IMPORT, &shID))1719 if (!GetSectionHdrByImageDir(peview, IMAGE_DIRECTORY_ENTRY_IMPORT, &shID)) 1713 1720 return TRUE; 1714 1721 … … 1719 1726 //test RVA inside ID-Section 1720 1727 if (pID[i].Name >= shID.VirtualAddress && pID[i].Name < shID.VirtualAddress + max(shID.Misc.VirtualSize, shID.SizeOfRawData)) { 1721 pszTmp = (char*)(pID[i].Name + (ULONG) win32file);1728 pszTmp = (char*)(pID[i].Name + (ULONG)peview); 1722 1729 } 1723 1730 else { 1724 1731 //is the "Extra"-section already found or do we have to find it? 1725 1732 if (pID[i].Name < shExtra.VirtualAddress || pID[i].Name >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData)) { 1726 if (!GetSectionHdrByRVA( win32file, &shExtra, pID[i].Name))1733 if (!GetSectionHdrByRVA(peview, &shExtra, pID[i].Name)) 1727 1734 return FALSE; 1728 1735 } 1729 pszTmp = (char*)(pID[i].Name + (ULONG) win32file);1736 pszTmp = (char*)(pID[i].Name + (ULONG)peview); 1730 1737 } 1731 1738 Size += strlen(pszTmp) + 1; … … 1744 1751 //test RVA inside ID-Section 1745 1752 if (pID[i].Name >= shID.VirtualAddress && pID[i].Name < shID.VirtualAddress + max(shID.Misc.VirtualSize, shID.SizeOfRawData)) { 1746 pszTmp = (char*)(pID[i].Name + (ULONG) win32file);1753 pszTmp = (char*)(pID[i].Name + (ULONG)peview); 1747 1754 } 1748 1755 else { … … 1751 1758 if (pID[i].Name < shExtra.VirtualAddress || pID[i].Name >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData)) 1752 1759 { 1753 if (GetSectionHdrByRVA( win32file, &shExtra, pID[i].Name)) {1760 if (GetSectionHdrByRVA(peview, &shExtra, pID[i].Name)) { 1754 1761 return FALSE; 1755 1762 } 1756 1763 } 1757 pszTmp = (char*)(pID[i].Name + (ULONG) win32file);1764 pszTmp = (char*)(pID[i].Name + (ULONG)peview); 1758 1765 } 1759 1766 … … 1770 1777 /* 2) functions */ 1771 1778 pszCurModule = pszModules; 1772 pOH = (PIMAGE_OPTIONAL_HEADER)OPTHEADEROFF( win32file);1779 pOH = (PIMAGE_OPTIONAL_HEADER)OPTHEADEROFF(peview); 1773 1780 for (i = 0; i < cModules; i++) 1774 1781 { … … 1804 1811 if ((ULONG)pulImport < shExtra.VirtualAddress || (ULONG)pulImport >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData)) 1805 1812 { 1806 if (!GetSectionHdrByRVA( win32file, &shExtra, (ULONG)pulImport))1813 if (!GetSectionHdrByRVA(peview, &shExtra, (ULONG)pulImport)) 1807 1814 { 1808 1815 dprintf((LOG, "warning: could not find section for Thunk RVA %x", pulImport )); … … 1849 1856 } 1850 1857 1851 pulImport = (PULONG)((ULONG)pulImport + (ULONG) win32file);1858 pulImport = (PULONG)((ULONG)pulImport + (ULONG)peview); 1852 1859 j = 0; 1853 ulCurFixup = (ULONG)pID[i].FirstThunk + (ULONG) win32file;1860 ulCurFixup = (ULONG)pID[i].FirstThunk + (ULONG)peview; 1854 1861 1855 1862 section = findSectionByOS2Addr(ulCurFixup); … … 1873 1880 if (pulImport[j] < shExtra.VirtualAddress || pulImport[j] >= shExtra.VirtualAddress + max(shExtra.Misc.VirtualSize, shExtra.SizeOfRawData)) 1874 1881 { 1875 if (!GetSectionHdrByRVA( win32file, &shExtra, pulImport[j]))1882 if (!GetSectionHdrByRVA(peview, &shExtra, pulImport[j])) 1876 1883 { 1877 1884 dprintf((LOG, "warning: could not find section for Import Name RVA ", pulImport[j] )); … … 1880 1887 } 1881 1888 //KSO - Aug 6 1998 1:15am:this eases comparing... 1882 char *pszFunctionName = (char*)(pulImport[j] + (ULONG) win32file+ 2);1889 char *pszFunctionName = (char*)(pulImport[j] + (ULONG)peview + 2); 1883 1890 dprintf((LOG, "0x%08x Imported function %s (0x%08x)", ulCurFixup, pszFunctionName, WinImage->getApi(pszFunctionName))); 1884 1891 StoreImportByName(WinImage, pszFunctionName, ulCurFixup);
Note:
See TracChangeset
for help on using the changeset viewer.