Changeset 1410 for trunk/src/kernel32/winimagepeldr.cpp
- Timestamp:
- Oct 23, 1999, 2:34:48 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagepeldr.cpp
r1284 r1410 1 /* $Id: winimagepeldr.cpp,v 1. 7 1999-10-14 09:57:35sandervl Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.8 1999-10-23 12:34:48 sandervl Exp $ */ 2 2 3 3 /* … … 8 8 * 9 9 * Project Odin Software License can be found in LICENSE.TXT 10 * 11 * 12 * NOTE: RSRC_LOAD is a special flag to only load the resource directory 13 * of a PE image. Processing imports, sections etc is not done. 14 * Nor is it put into the linked list of dlls (if it's a dll). 15 * This is useful for GetVersionSize/Resource in case it wants to 16 * get version info of an image that is not loaded. 17 * So an instance of this type can't be used for anything but resource lookup! 10 18 * 11 19 */ … … 59 67 //****************************************************************************** 60 68 //****************************************************************************** 61 Win32PeLdrImage::Win32PeLdrImage(char *szFileName ) :69 Win32PeLdrImage::Win32PeLdrImage(char *szFileName, int loadtype) : 62 70 Win32ImageBase(-1), 63 71 nrsections(0), imageSize(0), 64 72 imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0), 65 73 nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL), 66 pResSection(NULL) 67 { 74 pResSection(NULL), fImgMapping(0) 75 { 76 loadType = loadtype; 77 68 78 strcpy(this->szFileName, szFileName); 69 79 … … 83 93 sprintf(logname, "pe_%d.log", loadNr); 84 94 fout.open(logname, ios::out | ios::trunc); 95 if(fout.good() == FALSE) { 96 sprintf(logname, "%spe_%d.log", kernel32Path, loadNr); 97 fout.open(logname, ios::out | ios::trunc); 98 } 85 99 dprintf(("PE LOGFILE for %s: %s", szModule, logname)); 86 100 foutInit = TRUE; … … 99 113 if(ordexports) 100 114 free(ordexports); 115 116 //SvL: Only happens for images that aren't really loaded (RSRC_LOAD) 117 if(fImgMapping) CloseHandle(fImgMapping); 118 fImgMapping = 0; 101 119 } 102 120 //****************************************************************************** … … 104 122 BOOL Win32PeLdrImage::init(ULONG reservedMem) 105 123 { 106 HANDLE fImgMapping = 0;107 124 char szErrorMsg[64]; 108 125 LPVOID win32file = NULL; … … 172 189 nSections = NR_SECTIONS(win32file); 173 190 174 if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) { 191 if(loadType == REAL_LOAD) 192 { 193 if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) { 175 194 fout << endl << "*************************PE SECTIONS START**************************" << endl; 176 195 for (i=0; i<nSections; i++) { … … 281 300 goto failure; 282 301 } 283 }284 fout << "*************************PE SECTIONS END **************************" << endl;285 imageSize += imageVirtBase - oh.ImageBase;286 fout << "Total size of Image " << imageSize << endl;287 fout << "imageVirtBase " << imageVirtBase << endl;288 fout << "imageVirtEnd " << imageVirtEnd << endl;289 290 //In case there are any gaps between sections, adjust size291 if(imageSize != imageVirtEnd - oh.ImageBase) {302 } 303 fout << "*************************PE SECTIONS END **************************" << endl; 304 imageSize += imageVirtBase - oh.ImageBase; 305 fout << "Total size of Image " << imageSize << endl; 306 fout << "imageVirtBase " << imageVirtBase << endl; 307 fout << "imageVirtEnd " << imageVirtEnd << endl; 308 309 //In case there are any gaps between sections, adjust size 310 if(imageSize != imageVirtEnd - oh.ImageBase) { 292 311 fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl; 293 312 imageSize = imageVirtEnd - oh.ImageBase; 294 }295 if(allocSections(reservedMem) == FALSE) {313 } 314 if(allocSections(reservedMem) == FALSE) { 296 315 fout << "Failed to allocate image memory, rc " << errorState << endl; 297 316 goto failure; 298 }299 fout << "OS/2 base address " << realBaseAddress << endl;300 if(storeSections((char *)win32file) == FALSE) {317 } 318 fout << "OS/2 base address " << realBaseAddress << endl; 319 if(storeSections((char *)win32file) == FALSE) { 301 320 fout << "Failed to store sections, rc " << errorState << endl; 302 321 goto failure; 303 }304 if(oh.AddressOfEntryPoint) {322 } 323 if(oh.AddressOfEntryPoint) { 305 324 entryPoint = realBaseAddress + oh.AddressOfEntryPoint; 306 }307 else {308 fout << "EntryPoint == NULL" << endl; 325 } 326 else { 327 fout << "EntryPoint == NULL" << endl; 309 328 entryPoint = NULL; 310 }311 312 if(tlsDir != NULL) {313 Section *sect = findSection(SECTION_TLS);329 } 330 331 if(tlsDir != NULL) { 332 Section *sect = findSection(SECTION_TLS); 314 333 315 334 if(sect == NULL) { … … 334 353 } 335 354 setTLSCallBackAddr((PIMAGE_TLS_CALLBACK *)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfCallBacks - sect->virtaddr))); 336 }337 338 if(realBaseAddress != oh.ImageBase) {355 } 356 357 if(realBaseAddress != oh.ImageBase) { 339 358 if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) { 340 359 fout << "Failed to set fixups" << endl; 341 360 goto failure; 342 361 } 343 }344 if(fh.Characteristics & IMAGE_FILE_DLL) {362 } 363 if(fh.Characteristics & IMAGE_FILE_DLL) { 345 364 if(processExports((char *)win32file) == FALSE) { 346 365 fout << "Failed to process exported apis" << endl; 347 366 goto failure; 348 367 } 349 } 350 351 //SvL: Use pointer to image header as module handle now. Some apps needs this 352 hinstance = (HINSTANCE)realBaseAddress; 368 } 369 370 //SvL: Use pointer to image header as module handle now. Some apps needs this 371 hinstance = (HINSTANCE)realBaseAddress; 372 } 353 373 354 374 //PH: get pResDir pointer correct first, since processImports may … … 361 381 } 362 382 363 if(processImports((char *)win32file) == FALSE) { 383 if (loadType == REAL_LOAD) 384 { 385 if(processImports((char *)win32file) == FALSE) { 364 386 fout << "Failed to process imports!" << endl; 365 goto failure;366 }367 368 //set final memory protection flags (storeSections sets them to read/write)369 if(setMemFlags() == FALSE) {387 goto failure; 388 } 389 390 //set final memory protection flags (storeSections sets them to read/write) 391 if(setMemFlags() == FALSE) { 370 392 fout << "Failed to set memory protection" << endl; 371 393 goto failure; 372 } 373 374 CloseHandle(fImgMapping); 394 } 395 CloseHandle(fImgMapping); 396 fImgMapping = 0; 397 } 375 398 return(TRUE); 376 399 failure: 377 400 if(fImgMapping) CloseHandle(fImgMapping); 401 fImgMapping = 0; 378 402 errorState = ERROR_INTERNAL; 379 403 return FALSE;
Note:
See TracChangeset
for help on using the changeset viewer.