Changeset 2061 for trunk/src/kernel32/winimagepeldr.cpp
- Timestamp:
- Dec 12, 1999, 3:32:38 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagepeldr.cpp
r1893 r2061 1 /* $Id: winimagepeldr.cpp,v 1.2 1 1999-11-30 19:40:26sandervl Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.22 1999-12-12 14:32:38 sandervl Exp $ */ 2 2 3 3 /* … … 33 33 34 34 #include <assert.h> 35 //use a different logfile 36 #define PRIVATE_LOGGING 35 37 #include <misc.h> 36 38 #include <win32type.h> … … 61 63 #endif 62 64 63 BOOL foutInit = FALSE; 64 ofstream fout; 65 static FILE *_privateLogFile = NULL; 65 66 66 67 ULONG MissingApi(); 67 char *hex(ULONG num);68 69 68 extern ULONG flAllocMem; /*Tue 03.03.1998: knut */ 70 69 70 //****************************************************************************** 71 //****************************************************************************** 72 void OpenPrivateLogFilePE() 73 { 74 char logname[CCHMAXPATH]; 75 76 sprintf(logname, "pe_%d.log", loadNr); 77 _privateLogFile = fopen(logname, "w"); 78 if(_privateLogFile == NULL) { 79 sprintf(logname, "%spe_%d.log", kernel32Path, loadNr); 80 _privateLogFile = fopen(logname, "w"); 81 } 82 dprintfGlobal(("PE LOGFILE : %s", logname)); 83 } 84 //****************************************************************************** 85 //****************************************************************************** 86 void ClosePrivateLogFilePE() 87 { 88 if(_privateLogFile) { 89 fclose(_privateLogFile); 90 _privateLogFile = NULL; 91 } 92 } 71 93 //****************************************************************************** 72 94 //****************************************************************************** … … 133 155 if(dot) 134 156 *dot = 0; 135 136 if(foutInit == FALSE) {137 char logname[32];138 sprintf(logname, "pe_%d.log", loadNr);139 fout.open(logname, ios::out | ios::trunc);140 if(fout.good() == FALSE) {141 sprintf(logname, "%spe_%d.log", kernel32Path, loadNr);142 fout.open(logname, ios::out | ios::trunc);143 }144 dprintf(("PE LOGFILE for %s: %s", szModule, logname));145 foutInit = TRUE;146 }147 157 } 148 158 //****************************************************************************** … … 208 218 } 209 219 if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || signature != IMAGE_NT_SIGNATURE) { 210 fout << "Not a valid PE file (probably a 16 bits windows exe/dll)!" << endl;220 dprintf((LOG, "Not a valid PE file (probably a 16 bits windows exe/dll)!")); 211 221 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 212 222 goto failure; … … 218 228 219 229 imageSize = oh.SizeOfImage; 220 //Allocate memory to ldhold the entire image230 //Allocate memory to hold the entire image 221 231 if(allocSections(reservedMem) == FALSE) { 222 fout << "Failed to allocate image memory, rc " << errorState << endl;232 dprintf((LOG, "Failed to allocate image memory, rc %d", errorState));; 223 233 goto failure; 224 234 } … … 236 246 237 247 if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid 238 fout << "Not a valid PE file!" << endl;248 dprintf((LOG, "Not a valid PE file!")); 239 249 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 240 250 goto failure; 241 251 } 242 252 if(fh.Machine != IMAGE_FILE_MACHINE_I386) { 243 fout << "You need a REAL CPU to run this code" << endl;253 dprintf((LOG, "Doesn't run on x86 processors!")); 244 254 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szCPUErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 245 255 goto failure; … … 247 257 //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)? 248 258 if(fh.Characteristics & IMAGE_FILE_SYSTEM) { 249 fout << "Can't convert system files" << endl;259 dprintf((LOG, "Can't convert system files")); 250 260 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szExeErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 251 261 goto failure; … … 253 263 254 264 if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) { 255 fout << "No fixups, might not run!" << endl;256 } 257 258 fout << "PE file : " << szFileName << endl;259 fout << "PE Optional header: " << endl;260 fout << "Preferred address : " << oh.ImageBase << endl;261 fout << "Base Of Code : " << oh.BaseOfCode << endl;262 fout << "CodeSize : " << oh.SizeOfCode << endl;263 fout << "Base Of Data : " << oh.BaseOfData << endl;264 fout << "Data Size (uninit): " << oh.SizeOfUninitializedData << endl;265 fout << "Data Size (init) : " << oh.SizeOfInitializedData << endl;266 fout << "Entry Point : " << oh.AddressOfEntryPoint << endl;267 fout << "Section Alignment : " << oh.SectionAlignment << endl;268 fout << "Stack Reserve size: " << oh.SizeOfStackReserve << endl;269 fout << "Stack Commit size : " << oh.SizeOfStackCommit << endl;270 fout << "SizeOfHeapReserve : " << oh.SizeOfHeapReserve << endl;271 fout << "SizeOfHeapCommit : " << oh.SizeOfHeapCommit << endl;272 fout << "FileAlignment : " << oh.FileAlignment << endl;273 fout << "Subsystem : " << oh.Subsystem << endl;274 fout << "Image Size : " << oh.SizeOfImage << endl;275 fout << "Header Size : " << oh.SizeOfHeaders << endl;276 fout << "MajorImageVersion : " << oh.MajorImageVersion << endl;277 fout << "MinorImageVersion : " << oh.MinorImageVersion << endl;265 dprintf((LOG, "No fixups, might not run!")); 266 } 267 268 dprintf((LOG, "PE file : %s", szFileName)); 269 dprintf((LOG, "PE Optional header: ")); 270 dprintf((LOG, "Preferred address : %d", oh.ImageBase )); 271 dprintf((LOG, "Base Of Code : %d", oh.BaseOfCode )); 272 dprintf((LOG, "CodeSize : %d", oh.SizeOfCode )); 273 dprintf((LOG, "Base Of Data : %d", oh.BaseOfData )); 274 dprintf((LOG, "Data Size (uninit): %d", oh.SizeOfUninitializedData )); 275 dprintf((LOG, "Data Size (init) : %d", oh.SizeOfInitializedData )); 276 dprintf((LOG, "Entry Point : %d", oh.AddressOfEntryPoint )); 277 dprintf((LOG, "Section Alignment : %d", oh.SectionAlignment )); 278 dprintf((LOG, "Stack Reserve size: %d", oh.SizeOfStackReserve )); 279 dprintf((LOG, "Stack Commit size : %d", oh.SizeOfStackCommit )); 280 dprintf((LOG, "SizeOfHeapReserve : %d", oh.SizeOfHeapReserve )); 281 dprintf((LOG, "SizeOfHeapCommit : %d", oh.SizeOfHeapCommit )); 282 dprintf((LOG, "FileAlignment : %d", oh.FileAlignment )); 283 dprintf((LOG, "Subsystem : %d", oh.Subsystem )); 284 dprintf((LOG, "Image Size : %d", oh.SizeOfImage )); 285 dprintf((LOG, "Header Size : %d", oh.SizeOfHeaders )); 286 dprintf((LOG, "MajorImageVersion : %d", oh.MajorImageVersion )); 287 dprintf((LOG, "MinorImageVersion : %d", oh.MinorImageVersion )); 278 288 279 289 //get header page … … 286 296 imageSize = 0; 287 297 if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) { 288 fout << endl << "*************************PE SECTIONS START**************************" << endl;298 dprintf((LOG, "*************************PE SECTIONS START**************************" )); 289 299 for (i=0; i<nSections; i++) { 290 fout << "Raw data size: " << hex(psh[i].SizeOfRawData) << endl;291 fout << "Virtual Address: " << hex(psh[i].VirtualAddress) << endl;292 fout << "Virtual Size: " << hex(psh[i].Misc.VirtualSize) << endl;293 fout << "Pointer to raw data: " << hex(psh[i].PointerToRawData) << endl;294 fout << "Section flags: " << hex(psh[i].Characteristics) << endl << endl;300 dprintf((LOG, "Raw data size: %x", psh[i].SizeOfRawData )); 301 dprintf((LOG, "Virtual Address: %x", psh[i].VirtualAddress )); 302 dprintf((LOG, "Virtual Size: %x", psh[i].Misc.VirtualSize )); 303 dprintf((LOG, "Pointer to raw data: %x", psh[i].PointerToRawData )); 304 dprintf((LOG, "Section flags: %x\n\n", psh[i].Characteristics )); 295 305 if(strcmp(psh[i].Name, ".reloc") == 0) { 296 fout << ".reloc" << endl << endl;306 dprintf((LOG, ".reloc" )); 297 307 addSection(SECTION_RELOC, psh[i].PointerToRawData, 298 308 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 301 311 } 302 312 if(strcmp(psh[i].Name, ".edata") == 0) { 303 fout << ".edata" << endl << endl;313 dprintf((LOG, ".edata" )); 304 314 addSection(SECTION_EXPORT, psh[i].PointerToRawData, 305 315 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 308 318 } 309 319 if(strcmp(psh[i].Name, ".rsrc") == 0) { 310 fout << ".rsrc" << endl << endl;320 dprintf((LOG, ".rsrc" )); 311 321 addSection(SECTION_RESOURCE, psh[i].PointerToRawData, 312 322 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 326 336 327 337 if(strcmp(psh[i].Name, ".debug") == 0) { 328 fout << ".rdebug" << endl << endl;338 dprintf((LOG, ".rdebug" )); 329 339 addSection(SECTION_DEBUG, psh[i].PointerToRawData, 330 340 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 335 345 { 336 346 int type = SECTION_IMPORT; 337 fout << "Import Data Section" << endl << endl;347 dprintf((LOG, "Import Data Section" )); 338 348 if(psh[i].Characteristics & IMAGE_SCN_CNT_CODE) { 339 fout << "Also Code Section" << endl << endl;349 dprintf((LOG, "Also Code Section")); 340 350 type |= SECTION_CODE; 341 351 } … … 352 362 ) 353 363 { 354 fout << "Code Section" << endl << endl;364 dprintf((LOG, "Code Section")); 355 365 addSection(SECTION_CODE, psh[i].PointerToRawData, 356 366 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 359 369 } 360 370 if(!(psh[i].Characteristics & IMAGE_SCN_MEM_WRITE)) { //read only data section 361 fout << "Read Only Data Section" << endl << endl;371 dprintf((LOG, "Read Only Data Section" )); 362 372 addSection(SECTION_READONLYDATA, psh[i].PointerToRawData, 363 373 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 366 376 } 367 377 if(psh[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) { 368 fout << "Uninitialized Data Section" << endl << endl;378 dprintf((LOG, "Uninitialized Data Section" )); 369 379 addSection(SECTION_UNINITDATA, psh[i].PointerToRawData, 370 380 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 373 383 } 374 384 if(psh[i].Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA) { 375 fout << "Initialized Data Section" << endl << endl;385 dprintf((LOG, "Initialized Data Section" )); 376 386 addSection(SECTION_INITDATA, psh[i].PointerToRawData, 377 387 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 380 390 } 381 391 if(psh[i].Characteristics & (IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_READ)) { 382 fout << "Other Section, stored as read/write uninit data" << endl << endl;392 dprintf((LOG, "Other Section, stored as read/write uninit data" )); 383 393 addSection(SECTION_UNINITDATA, psh[i].PointerToRawData, 384 394 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, … … 386 396 continue; 387 397 } 388 fout << "Unknown section" << endl;398 dprintf((LOG, "Unknown section" )); 389 399 goto failure; 390 400 } … … 399 409 } 400 410 } 401 fout << "*************************PE SECTIONS END **************************" << endl;411 dprintf((LOG, "*************************PE SECTIONS END **************************" )); 402 412 imageSize += imageVirtBase - oh.ImageBase; 403 fout << "Total size of Image " << imageSize << endl;404 fout << "imageVirtBase " << imageVirtBase << endl;405 fout << "imageVirtEnd " << imageVirtEnd << endl;413 dprintf((LOG, "Total size of Image %x", imageSize )); 414 dprintf((LOG, "imageVirtBase %x", imageVirtBase )); 415 dprintf((LOG, "imageVirtEnd %x", imageVirtEnd )); 406 416 407 417 //In case there are any gaps between sections, adjust size 408 418 if(imageSize != imageVirtEnd - oh.ImageBase) { 409 fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;419 dprintf((LOG, "imageSize != imageVirtEnd - oh.ImageBase!" )); 410 420 imageSize = imageVirtEnd - oh.ImageBase; 411 421 } … … 414 424 } 415 425 416 fout << "OS/2 base address " << realBaseAddress << endl;426 dprintf((LOG, "OS/2 base address %x", realBaseAddress )); 417 427 if(oh.AddressOfEntryPoint) { 418 428 entryPoint = realBaseAddress + oh.AddressOfEntryPoint; 419 429 } 420 430 else { 421 fout << "EntryPoint == NULL" << endl;431 dprintf((LOG, "EntryPoint == NULL" )); 422 432 entryPoint = NULL; 423 433 } … … 425 435 //set memory protection flags 426 436 if(setMemFlags() == FALSE) { 427 fout << "Failed to set memory protection" << endl;437 dprintf((LOG, "Failed to set memory protection" )); 428 438 goto failure; 429 439 } … … 435 445 436 446 if(sect == NULL) { 437 fout << "Couldn't find TLS section!!" << endl;447 dprintf((LOG, "Couldn't find TLS section!!" )); 438 448 goto failure; 439 449 } 440 fout << "TLS Directory" << endl;441 fout << "TLS Address of Index " << hex((ULONG)tlsDir->AddressOfIndex) << endl;442 fout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl;443 fout << "TLS SizeOfZeroFill " << hex(tlsDir->SizeOfZeroFill) << endl;444 fout << "TLS Characteristics " << hex(tlsDir->Characteristics) << endl;450 dprintf((LOG, "TLS Directory" )); 451 dprintf((LOG, "TLS Address of Index %x", tlsDir->AddressOfIndex )); 452 dprintf((LOG, "TLS Address of Callbacks %x", tlsDir->AddressOfCallBacks )); 453 dprintf((LOG, "TLS SizeOfZeroFill %x", tlsDir->SizeOfZeroFill )); 454 dprintf((LOG, "TLS Characteristics %x", tlsDir->Characteristics )); 445 455 setTLSAddress((char *)sect->realvirtaddr); 446 456 setTLSInitSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData); … … 449 459 sect = findSectionByAddr((ULONG)tlsDir->AddressOfIndex); 450 460 if(sect == NULL) { 451 fout << "Couldn't find TLS AddressOfIndex section!!" << endl;461 dprintf((LOG, "Couldn't find TLS AddressOfIndex section!!" )); 452 462 goto failure; 453 463 } … … 457 467 sect = findSectionByAddr((ULONG)tlsDir->AddressOfCallBacks); 458 468 if(sect == NULL) { 459 fout << "Couldn't find TLS AddressOfCallBacks section!!" << endl;469 dprintf((LOG, "Couldn't find TLS AddressOfCallBacks section!!" )); 460 470 goto failure; 461 471 } … … 470 480 // if(fh.Characteristics & IMAGE_FILE_DLL) { 471 481 if(processExports((char *)win32file) == FALSE) { 472 fout << "Failed to process exported apis" << endl;482 dprintf((LOG, "Failed to process exported apis" )); 473 483 goto failure; 474 484 } … … 497 507 { 498 508 if(processImports((char *)win32file) == FALSE) { 499 fout << "Failed to process imports!" << endl;509 dprintf((LOG, "Failed to process imports!" )); 500 510 goto failure; 501 511 } … … 528 538 rc = DosQueryMem((PVOID)virtAddress, &range, &attr); 529 539 if(rc) { 530 dprintf(( "Win32PeLdrImage::commitPage: DosQueryMem returned %d", rc));540 dprintf((LOG, "Win32PeLdrImage::commitPage: DosQueryMem returned %d", rc)); 531 541 return FALSE; 532 542 } 533 543 if(attr & PAG_COMMIT) { 534 dprintf(( "Win32PeLdrImage::commitPage: Memory at 0x%x already committed!", virtAddress));544 dprintf((LOG, "Win32PeLdrImage::commitPage: Memory at 0x%x already committed!", virtAddress)); 535 545 return FALSE; 536 546 } … … 564 574 } 565 575 if(fWriteAccess & !(section->pageflags & PAG_WRITE)) { 566 dprintf(( "Win32PeLdrImage::commitPage: No write access to 0%x!", virtAddress));576 dprintf((LOG, "Win32PeLdrImage::commitPage: No write access to 0%x!", virtAddress)); 567 577 return FALSE; 568 578 } … … 583 593 rc = DosSetMem((PVOID)virtAddress, sectionsize, PAG_READ|PAG_WRITE|PAG_COMMIT); 584 594 if(rc) { 585 dprintf(( "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));595 dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc)); 586 596 return FALSE; 587 597 } 588 598 589 599 if(DosSetFilePtr(hFile, fileoffset, FILE_BEGIN, &ulNewPos) == -1) { 590 dprintf(( "Win32PeLdrImage::commitPage: DosSetFilePtr failed for 0x%x!", fileoffset));600 dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetFilePtr failed for 0x%x!", fileoffset)); 591 601 return FALSE; 592 602 } 593 603 if(DosRead(hFile, (PVOID)virtAddress, size, &ulRead)) { 594 dprintf(( "Win32PeLdrImage::commitPage: DosRead failed for 0x%x!", virtAddress));604 dprintf((LOG, "Win32PeLdrImage::commitPage: DosRead failed for 0x%x!", virtAddress)); 595 605 return FALSE; 596 606 } 597 607 if(ulRead != size) { 598 dprintf(( "Win32PeLdrImage::commitPage: DosRead failed to read %x (%x) bytes for 0x%x!", size, ulRead, virtAddress));608 dprintf((LOG, "Win32PeLdrImage::commitPage: DosRead failed to read %x (%x) bytes for 0x%x!", size, ulRead, virtAddress)); 599 609 return FALSE; 600 610 } … … 605 615 rc = DosSetMem((PVOID)virtAddress, sectionsize, protflags); 606 616 if(rc) { 607 dprintf(( "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));617 dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc)); 608 618 return FALSE; 609 619 } … … 612 622 rc = DosSetMem((PVOID)virtAddress, sectionsize, PAG_READ|PAG_WRITE|PAG_COMMIT); 613 623 if(rc) { 614 dprintf(( "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));624 dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc)); 615 625 return FALSE; 616 626 } … … 620 630 rc = DosSetMem((PVOID)virtAddress, sectionsize, protflags); 621 631 if(rc) { 622 dprintf(( "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));632 dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc)); 623 633 return FALSE; 624 634 } … … 660 670 rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ | PAG_WRITE | flAllocMem); 661 671 if(rc) { 662 dprintf(( "Win32PeLdrImage::allocSections, DosAllocMem returned %d", rc));672 dprintf((LOG, "Win32PeLdrImage::allocSections, DosAllocMem returned %d", rc)); 663 673 errorState = rc; 664 674 return(FALSE); … … 747 757 memallocs = (ULONG *)malloc(4096*sizeof(ULONG *)); 748 758 if(memallocs == NULL) { 749 fout << "allocFixedMem: MALLOC FAILED for memallocs" << endl;759 dprintf((LOG, "allocFixedMem: MALLOC FAILED for memallocs" )); 750 760 return FALSE; 751 761 } … … 758 768 if(rc) break; 759 769 760 fout << "DosAllocMem returned " << address << endl;770 dprintf((LOG, "DosAllocMem returned %x", address )); 761 771 if(address + FALLOC_SIZE >= oh.ImageBase) { 762 772 if(address > oh.ImageBase) {//we've passed it! … … 881 891 if(section == NULL) { 882 892 //should never happen 883 dprintf(( "::setFixups -> section == NULL!!"));893 dprintf((LOG, "::setFixups -> section == NULL!!")); 884 894 return FALSE; 885 895 } … … 920 930 } 921 931 else { 922 dprintf(( "Win32PeLdrImage::setFixups, no fixups at %x, %d", virtAddress, size));932 dprintf((LOG, "Win32PeLdrImage::setFixups, no fixups at %x, %d", virtAddress, size)); 923 933 return(FALSE); 924 934 } … … 942 952 page = (char *)((char *)prel + (ULONG)prel->VirtualAddress); 943 953 count = (prel->SizeOfBlock - 8)/2; 944 fout.setf(ios::hex, ios::basefield); 945 fout << "Page " << j << " Address " << (ULONG)prel->VirtualAddress << " Count " << count << endl; 946 fout.setf(ios::dec, ios::basefield); 954 dprintf((LOG, "Page %d Address %x Count %d", j, prel->VirtualAddress, count )); 947 955 j++; 948 956 for(i=0;i<count;i++) { … … 951 959 switch(type) { 952 960 case IMAGE_REL_BASED_ABSOLUTE: 953 //// fout << "absolute fixup; unused" << endl;961 //// dprintf((LOG, "absolute fixup; unused" )); 954 962 break; //skip 955 963 case IMAGE_REL_BASED_HIGHLOW: 956 //// fout << "address " << offset << " type " << type << endl;964 //// dprintf((LOG, "address ", offset << " type ", type )); 957 965 AddOff32Fixup(prel->VirtualAddress + offset); 958 966 break; … … 966 974 case IMAGE_REL_BASED_MIPS_JMPADDR: 967 975 default: 968 fout << "Unknown/unsupported fixup type!" << endl;976 dprintf((LOG, "Unknown/unsupported fixup type!" )); 969 977 break; 970 978 } … … 974 982 } 975 983 else { 976 fout << "No internal fixups found!\n" << endl;984 dprintf((LOG, "No internal fixups found!" )); 977 985 errorState = ERROR_INTERNAL; 978 986 return(FALSE); … … 989 997 fixup = (ULONG *)(fixupaddr + realBaseAddress); 990 998 orgaddr = *fixup; 991 // dprintf(( "AddOff32Fixup 0x%x org 0x%x -> new 0x%x", fixup, orgaddr, realBaseAddress + (*fixup - oh.ImageBase)));999 // dprintf((LOG, "AddOff32Fixup 0x%x org 0x%x -> new 0x%x", fixup, orgaddr, realBaseAddress + (*fixup - oh.ImageBase))); 992 1000 *fixup = realBaseAddress + (*fixup - oh.ImageBase); 993 1001 } … … 1003 1011 if(fHighFixup) { 1004 1012 *fixup += (USHORT)((realBaseAddress - oh.ImageBase) >> 16); 1005 // dprintf(( "AddOff16FixupH 0x%x org 0x%x -> new 0x%x", fixup, orgaddr, *fixup));1013 // dprintf((LOG, "AddOff16FixupH 0x%x org 0x%x -> new 0x%x", fixup, orgaddr, *fixup)); 1006 1014 } 1007 1015 else { 1008 1016 *fixup += (USHORT)((realBaseAddress - oh.ImageBase) & 0xFFFF); 1009 // dprintf(( "AddOff16FixupL 0x%x org 0x%x -> new 0x%x", fixup, orgaddr, *fixup));1017 // dprintf((LOG, "AddOff16FixupL 0x%x org 0x%x -> new 0x%x", fixup, orgaddr, *fixup)); 1010 1018 } 1011 1019 } … … 1021 1029 if(apiaddr == 0) 1022 1030 { 1023 dprintf(( "KERNEL32:Win32PeLdrImage - %s.%u not found\n",1031 dprintf((LOG, "KERNEL32:Win32PeLdrImage - %s.%u not found\n", 1024 1032 WinDll->getName(), 1025 1033 ordinal)); 1026 1034 1027 fout << "--->>> NOT FOUND!" << endl;1035 dprintf((LOG, "--->>> NOT FOUND!" )); 1028 1036 *import = (ULONG)MissingApi; 1029 1037 } … … 1041 1049 if(apiaddr == 0) 1042 1050 { 1043 dprintf(( "KERNEL32:Win32PeLdrImage - %s.%s not found\n",1051 dprintf((LOG, "KERNEL32:Win32PeLdrImage - %s.%s not found\n", 1044 1052 WinDll->getName(), 1045 1053 impname)); 1046 1054 1047 fout << "--->>> NOT FOUND!" << endl;1055 dprintf((LOG, "--->>> NOT FOUND!" )); 1048 1056 *import = (ULONG)MissingApi; 1049 1057 } … … 1065 1073 GetSectionHdrByImageDir(win32file, IMAGE_DIRECTORY_ENTRY_EXPORT, &sh) ) { 1066 1074 1067 fout << "Exported Functions: " << endl;1075 dprintf((LOG, "Exported Functions: " )); 1068 1076 ptrOrd = (USHORT *)((ULONG)ped->AddressOfNameOrdinals + 1069 1077 (ULONG)win32file); … … 1086 1094 //points to code (virtual address relative to oh.ImageBase 1087 1095 AddNameExport(oh.ImageBase + RVAExport, name, ord); 1088 fout << "address 0x"; 1089 fout.setf(ios::hex, ios::basefield); 1090 fout << RVAExport; 1091 fout.setf(ios::dec, ios::basefield); 1092 fout << " " << name << "@" << ord << endl; 1096 dprintf((LOG, "address 0x%x %s @%d", RVAExport, name, ord)); 1093 1097 #ifdef FORWARDERS 1094 1098 … … 1096 1100 else {//forwarder 1097 1101 char *forward = (char *)((ULONG)RVAExport + (ULONG)win32file); 1098 fout << RVAExport << " " << name << " @" << ord << " is forwarder to " << (int)forward << endl;1102 fout << RVAExport << " ", name << " @", ord << " is forwarder to ", (int)forward )); 1099 1103 } 1100 1104 #endif … … 1108 1112 if(RVAExport) { 1109 1113 //points to code (virtual address relative to oh.ImageBase 1110 fout << "ord " << ord << " at 0x"; 1111 fout.setf(ios::hex, ios::basefield); 1112 fout << RVAExport << endl; 1113 fout.setf(ios::dec, ios::basefield); 1114 dprintf((LOG, "ord %d at 0x%x", ord, RVAExport)); 1114 1115 AddOrdExport(oh.ImageBase + RVAExport, ord); 1115 1116 } … … 1118 1119 else {//forwarder or empty 1119 1120 char *forward = (char *)((ULONG)RVAExport + (ULONG)win32file); 1120 fout << "ord " << ord << " at 0x"; 1121 fout.setf(ios::hex, ios::basefield); 1122 fout << RVAExport << " is forwarder to 0x" << (int)forward << endl; 1123 fout.setf(ios::dec, ios::basefield); 1121 dprintf((LOG, "ord ", ord << " at 0x"; 1122 fout << RVAExport << " is forwarder to 0x", (int)forward )); 1124 1123 } 1125 1124 #endif … … 1262 1261 j += strlen(pszTmp) + 1; 1263 1262 } 1264 fout << endl;1265 1263 if (fBorland) 1266 fout << "Borland-styled PE-File." << endl;1264 dprintf((LOG, "Borland-styled PE-File." )); 1267 1265 //Store modules 1268 fout << cModules << " imported Modules: " << endl;1266 dprintf((LOG, "%d imported Modules: ", cModules )); 1269 1267 1270 1268 /* 2) functions */ … … 1273 1271 for (i = 0; i < cModules; i++) 1274 1272 { 1275 fout << "Module " << pszCurModule << endl;1273 dprintf((LOG, "Module %s", pszCurModule )); 1276 1274 // a) check that OriginalFirstThunk not is 0 and look for Borland-styled PE 1277 1275 if (i == 0) … … 1295 1293 // b) check if RVA ok 1296 1294 if (!(pulImport > 0 && (ULONG)pulImport < pOH->SizeOfImage)) { 1297 fout << "Invalid RVA " << hex((ULONG)pulImport) << endl;1295 dprintf((LOG, "Invalid RVA %x", pulImport )); 1298 1296 break; 1299 1297 } … … 1303 1301 if (!GetSectionHdrByRVA(win32file, &shExtra, (ULONG)pulImport)) 1304 1302 { 1305 fout << "warning: could not find section for Thunk RVA " << hex((ULONG)pulImport) << endl;1303 dprintf((LOG, "warning: could not find section for Thunk RVA %x", pulImport )); 1306 1304 break; 1307 1305 } … … 1309 1307 1310 1308 //SvL: Load dll if needed 1311 fout << "**********************************************************************" << endl;1312 fout << "************** Import Module " << pszCurModule << endl;1313 fout << "**********************************************************************" << endl;1309 dprintf((LOG, "**********************************************************************" )); 1310 dprintf((LOG, "************** Import Module %s ", pszCurModule )); 1311 dprintf((LOG, "**********************************************************************" )); 1314 1312 WinDll = (Win32PeLdrDll *)Win32DllBase::findModule(pszCurModule); 1315 1313 … … 1335 1333 rc = DosLoadModule(szModuleFailure, sizeof(szModuleFailure), modname, (HMODULE *)&hInstanceNewDll); 1336 1334 if(rc) { 1337 dprintf(( "DosLoadModule returned %X for %s\n", rc, szModuleFailure));1335 dprintf((LOG, "DosLoadModule returned %X for %s\n", rc, szModuleFailure)); 1338 1336 sprintf(szErrorModule, "%s.DLL", szModuleFailure); 1339 1337 errorState = rc; … … 1342 1340 WinDll = (Win32PeLdrDll *)Win32DllBase::findModule(hInstanceNewDll); 1343 1341 if(WinDll == NULL) {//shouldn't happen! 1344 dprintf(( "Just loaded the dll, but can't find it anywhere?!!?"));1342 dprintf((LOG, "Just loaded the dll, but can't find it anywhere?!!?")); 1345 1343 errorState = ERROR_INTERNAL; 1346 1344 return(FALSE); … … 1351 1349 1352 1350 if(WinDll == NULL) { 1353 fout << "WinDll: Error allocating memory" << endl;1351 dprintf((LOG, "WinDll: Error allocating memory" )); 1354 1352 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 1355 1353 errorState = ERROR_INTERNAL; 1356 1354 return(FALSE); 1357 1355 } 1358 fout << "**********************************************************************" << endl;1359 fout << "********************** Loading Module *********************" << endl;1360 fout << "**********************************************************************" << endl;1356 dprintf((LOG, "**********************************************************************" )); 1357 dprintf((LOG, "********************** Loading Module *********************" )); 1358 dprintf((LOG, "**********************************************************************" )); 1361 1359 if(WinDll->init(0) == FALSE) { 1362 fout << "Internal WinDll error " << WinDll->getError() << endl;1360 dprintf((LOG, "Internal WinDll error ", WinDll->getError() )); 1363 1361 strcpy(szErrorModule, OSLibStripPath(modname)); 1364 1362 return(FALSE); 1365 1363 } 1366 1364 if(WinDll->attachProcess() == FALSE) { 1367 fout << "attachProcess failed!" << endl;1365 dprintf((LOG, "attachProcess failed!" )); 1368 1366 errorState = ERROR_INTERNAL; 1369 1367 return(FALSE); … … 1371 1369 WinDll->AddRef(); 1372 1370 } 1373 fout << "**********************************************************************" << endl;1374 fout << "********************** Finished Loading Module *********************" << endl;1375 fout << "**********************************************************************" << endl;1371 dprintf((LOG, "**********************************************************************" )); 1372 dprintf((LOG, "********************** Finished Loading Module *********************" )); 1373 dprintf((LOG, "**********************************************************************" )); 1376 1374 } 1377 else fout << "Already found " << pszCurModule << endl;1375 else dprintf((LOG, "Already found ", pszCurModule )); 1378 1376 1379 1377 WinDll->AddRef(); … … 1385 1383 section = findSectionByOS2Addr(ulCurFixup); 1386 1384 if(section == NULL) { 1387 fout.setf(ios::hex, ios::basefield); 1388 fout << "Unable to find section for " << ulCurFixup << endl; 1385 dprintf((LOG, "Unable to find section for %x", ulCurFixup )); 1389 1386 return FALSE; 1390 1387 } … … 1397 1394 while (pulImport[j] != 0) { 1398 1395 if (pulImport[j] & IMAGE_ORDINAL_FLAG) { //ordinal 1399 fout.setf(ios::hex, ios::basefield); 1400 fout << "0x" << ulCurFixup << " Imported function " << pszCurModule << "@" << (pulImport[j] & ~IMAGE_ORDINAL_FLAG) << endl; 1401 fout.setf(ios::dec, ios::basefield); 1396 dprintf((LOG, "0x%08x Imported function %s @%d", ulCurFixup , pszCurModule, (pulImport[j] & ~IMAGE_ORDINAL_FLAG) )); 1402 1397 StoreImportByOrd(WinDll, pulImport[j] & ~IMAGE_ORDINAL_FLAG, ulCurFixup); 1403 1398 } … … 1407 1402 if (!GetSectionHdrByRVA(win32file, &shExtra, pulImport[j])) 1408 1403 { 1409 fout << "warning: could not find section for Import Name RVA " << hex(pulImport[j]) << endl;1404 dprintf((LOG, "warning: could not find section for Import Name RVA ", pulImport[j] )); 1410 1405 break; 1411 1406 } … … 1413 1408 //KSO - Aug 6 1998 1:15am:this eases comparing... 1414 1409 char *pszFunctionName = (char*)(pulImport[j] + (ULONG)win32file + 2); 1415 fout.setf(ios::hex, ios::basefield); 1416 fout << "0x" << ulCurFixup << " Imported function " << pszFunctionName << endl; 1417 fout.setf(ios::dec, ios::basefield); 1410 dprintf((LOG, "0x%08x Imported function %s", ulCurFixup, pszFunctionName )); 1418 1411 StoreImportByName(WinDll, pszFunctionName, ulCurFixup); 1419 1412 } … … 1430 1423 DosSetMem((PVOID)(ulCurFixup & ~0xfff), PAGE_SIZE*nrPages, section->pageflags); 1431 1424 1432 fout << "**********************************************************************" << endl;1433 fout << "************** End Import Module " << pszCurModule << endl;1434 fout << "**********************************************************************" << endl;1425 dprintf((LOG, "**********************************************************************" )); 1426 dprintf((LOG, "************** End Import Module %s ", pszCurModule )); 1427 dprintf((LOG, "**********************************************************************" )); 1435 1428 1436 1429 pszCurModule += strlen(pszCurModule) + 1; 1437 fout << endl;1438 1430 }//for (i = 0; i < cModules; i++) 1439 1431 … … 1511 1503 int r; 1512 1504 1513 dprintf(( "Missing api called!\n"));1505 dprintf((LOG, "Missing api called!\n")); 1514 1506 if(fIgnore) 1515 1507 return(0); … … 1529 1521 /******************************************************************************/ 1530 1522 /******************************************************************************/ 1531 /*heximal(decimal) KSO Sun 24.05.1998*/1532 char szHexBuffer[30];1533 1534 char *hex(ULONG num)1535 {1536 sprintf(szHexBuffer, "0x%+08x (%lu)",num,num);1537 return szHexBuffer;1538 }1539 //******************************************************************************1540 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.