Ignore:
Timestamp:
Dec 12, 1999, 3:32:38 PM (26 years ago)
Author:
sandervl
Message:

added support for private logfiles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/winimagepeldr.cpp

    r1893 r2061  
    1 /* $Id: winimagepeldr.cpp,v 1.21 1999-11-30 19:40:26 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.22 1999-12-12 14:32:38 sandervl Exp $ */
    22
    33/*
     
    3333
    3434#include <assert.h>
     35//use a different logfile
     36#define PRIVATE_LOGGING
    3537#include <misc.h>
    3638#include <win32type.h>
     
    6163#endif
    6264
    63 BOOL foutInit = FALSE;
    64 ofstream fout;
     65static FILE *_privateLogFile = NULL;
    6566
    6667ULONG MissingApi();
    67 char *hex(ULONG num);
    68 
    6968extern ULONG flAllocMem;    /*Tue 03.03.1998: knut */
    7069
     70//******************************************************************************
     71//******************************************************************************
     72void 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//******************************************************************************
     86void ClosePrivateLogFilePE()
     87{
     88        if(_privateLogFile) {
     89                fclose(_privateLogFile);
     90                _privateLogFile = NULL;
     91        }
     92}
    7193//******************************************************************************
    7294//******************************************************************************
     
    133155  if(dot)
    134156        *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   }
    147157}
    148158//******************************************************************************
     
    208218  }
    209219  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)!"));
    211221        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    212222        goto failure;
     
    218228
    219229  imageSize = oh.SizeOfImage;
    220   //Allocate memory told hold the entire image
     230  //Allocate memory to hold the entire image
    221231  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));;
    223233        goto failure;
    224234  }
     
    236246
    237247  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!"));
    239249        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    240250        goto failure;
    241251  }
    242252  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!"));
    244254        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szCPUErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    245255        goto failure;
     
    247257  //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)?
    248258  if(fh.Characteristics & IMAGE_FILE_SYSTEM) {
    249         fout << "Can't convert system files" << endl;
     259        dprintf((LOG, "Can't convert system files"));
    250260        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szExeErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    251261        goto failure;
     
    253263
    254264  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 ));
    278288
    279289  //get header page
     
    286296   imageSize = 0;
    287297   if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) {
    288     fout << endl << "*************************PE SECTIONS START**************************" << endl;
     298    dprintf((LOG, "*************************PE SECTIONS START**************************" ));
    289299    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 ));
    295305        if(strcmp(psh[i].Name, ".reloc") == 0) {
    296             fout << ".reloc" << endl << endl;
     306            dprintf((LOG, ".reloc" ));
    297307            addSection(SECTION_RELOC, psh[i].PointerToRawData,
    298308                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    301311        }
    302312        if(strcmp(psh[i].Name, ".edata") == 0) {
    303             fout << ".edata" << endl << endl;
     313            dprintf((LOG, ".edata" ));
    304314            addSection(SECTION_EXPORT, psh[i].PointerToRawData,
    305315                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    308318        }
    309319        if(strcmp(psh[i].Name, ".rsrc") == 0) {
    310             fout << ".rsrc" << endl << endl;
     320            dprintf((LOG, ".rsrc" ));
    311321            addSection(SECTION_RESOURCE, psh[i].PointerToRawData,
    312322                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    326336
    327337        if(strcmp(psh[i].Name, ".debug") == 0) {
    328             fout << ".rdebug" << endl << endl;
     338            dprintf((LOG, ".rdebug" ));
    329339            addSection(SECTION_DEBUG,  psh[i].PointerToRawData,
    330340                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    335345        {
    336346          int type = SECTION_IMPORT;
    337             fout << "Import Data Section" << endl << endl;
     347            dprintf((LOG, "Import Data Section" ));
    338348            if(psh[i].Characteristics & IMAGE_SCN_CNT_CODE) {
    339                 fout << "Also Code Section" << endl << endl;
     349                dprintf((LOG, "Also Code Section"));
    340350                type |= SECTION_CODE;
    341351            }
     
    352362            )
    353363        {
    354             fout << "Code Section" << endl << endl;
     364            dprintf((LOG, "Code Section"));
    355365            addSection(SECTION_CODE, psh[i].PointerToRawData,
    356366                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    359369        }
    360370        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" ));
    362372            addSection(SECTION_READONLYDATA, psh[i].PointerToRawData,
    363373                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    366376        }
    367377        if(psh[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) {
    368             fout << "Uninitialized Data Section" << endl << endl;
     378            dprintf((LOG, "Uninitialized Data Section" ));
    369379            addSection(SECTION_UNINITDATA, psh[i].PointerToRawData,
    370380                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    373383        }
    374384        if(psh[i].Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA) {
    375             fout << "Initialized Data Section" << endl << endl;
     385            dprintf((LOG, "Initialized Data Section" ));
    376386            addSection(SECTION_INITDATA, psh[i].PointerToRawData,
    377387                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    380390        }
    381391        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" ));
    383393            addSection(SECTION_UNINITDATA, psh[i].PointerToRawData,
    384394                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     
    386396            continue;
    387397        }
    388         fout << "Unknown section" << endl;
     398        dprintf((LOG, "Unknown section" ));
    389399        goto failure;
    390400     }
     
    399409        }
    400410  }
    401   fout << "*************************PE SECTIONS END **************************" << endl;
     411  dprintf((LOG, "*************************PE SECTIONS END **************************" ));
    402412  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 ));
    406416
    407417  //In case there are any gaps between sections, adjust size
    408418  if(imageSize != imageVirtEnd - oh.ImageBase) {
    409         fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
     419        dprintf((LOG, "imageSize != imageVirtEnd - oh.ImageBase!" ));
    410420        imageSize = imageVirtEnd - oh.ImageBase;
    411421  }
     
    414424  }
    415425
    416   fout << "OS/2 base address " << realBaseAddress << endl;
     426  dprintf((LOG, "OS/2 base address %x", realBaseAddress ));
    417427  if(oh.AddressOfEntryPoint) {
    418428        entryPoint = realBaseAddress + oh.AddressOfEntryPoint;
    419429  }
    420430  else {
    421         fout << "EntryPoint == NULL" << endl;
     431        dprintf((LOG, "EntryPoint == NULL" ));
    422432        entryPoint = NULL;
    423433  }
     
    425435  //set memory protection flags
    426436  if(setMemFlags() == FALSE) {
    427         fout << "Failed to set memory protection" << endl;
     437        dprintf((LOG, "Failed to set memory protection" ));
    428438        goto failure;
    429439  }
     
    435445
    436446        if(sect == NULL) {
    437                 fout << "Couldn't find TLS section!!" << endl;
     447                dprintf((LOG, "Couldn't find TLS section!!" ));
    438448                goto failure;
    439449        }
    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 ));
    445455        setTLSAddress((char *)sect->realvirtaddr);
    446456        setTLSInitSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData);
     
    449459        sect = findSectionByAddr((ULONG)tlsDir->AddressOfIndex);
    450460        if(sect == NULL) {
    451                 fout << "Couldn't find TLS AddressOfIndex section!!" << endl;
     461                dprintf((LOG, "Couldn't find TLS AddressOfIndex section!!" ));
    452462                goto failure;
    453463        }
     
    457467                sect = findSectionByAddr((ULONG)tlsDir->AddressOfCallBacks);
    458468                if(sect == NULL) {
    459                         fout << "Couldn't find TLS AddressOfCallBacks section!!" << endl;
     469                        dprintf((LOG, "Couldn't find TLS AddressOfCallBacks section!!" ));
    460470                        goto failure;
    461471                }
     
    470480//   if(fh.Characteristics & IMAGE_FILE_DLL) {
    471481        if(processExports((char *)win32file) == FALSE) {
    472                 fout << "Failed to process exported apis" << endl;
     482                dprintf((LOG, "Failed to process exported apis" ));
    473483                goto failure;
    474484        }
     
    497507  {
    498508   if(processImports((char *)win32file) == FALSE) {
    499         fout << "Failed to process imports!" << endl;
     509        dprintf((LOG, "Failed to process imports!" ));
    500510        goto failure;
    501511   }
     
    528538  rc = DosQueryMem((PVOID)virtAddress, &range, &attr);
    529539  if(rc) {
    530         dprintf(("Win32PeLdrImage::commitPage: DosQueryMem returned %d", rc));
     540        dprintf((LOG, "Win32PeLdrImage::commitPage: DosQueryMem returned %d", rc));
    531541        return FALSE;
    532542  }
    533543  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));
    535545        return FALSE;
    536546  }
     
    564574        }
    565575        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));
    567577                return FALSE;
    568578        }
     
    583593        rc = DosSetMem((PVOID)virtAddress, sectionsize, PAG_READ|PAG_WRITE|PAG_COMMIT);
    584594        if(rc) {
    585                 dprintf(("Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));
     595                dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));
    586596                return FALSE;
    587597        }
    588598
    589599        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));
    591601                return FALSE;
    592602        }
    593603        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));
    595605                return FALSE;
    596606        }
    597607        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));
    599609                return FALSE;
    600610        }
     
    605615        rc = DosSetMem((PVOID)virtAddress, sectionsize, protflags);
    606616        if(rc) {
    607                 dprintf(("Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));
     617                dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));
    608618                return FALSE;
    609619        }
     
    612622        rc = DosSetMem((PVOID)virtAddress, sectionsize, PAG_READ|PAG_WRITE|PAG_COMMIT);
    613623        if(rc) {
    614                 dprintf(("Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));
     624                dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));
    615625                return FALSE;
    616626        }
     
    620630        rc = DosSetMem((PVOID)virtAddress, sectionsize, protflags);
    621631        if(rc) {
    622                 dprintf(("Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));
     632                dprintf((LOG, "Win32PeLdrImage::commitPage: DosSetMem failed (%d)!", rc));
    623633                return FALSE;
    624634        }
     
    660670  rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ | PAG_WRITE | flAllocMem);
    661671  if(rc) {
    662         dprintf(("Win32PeLdrImage::allocSections, DosAllocMem returned %d", rc));
     672        dprintf((LOG, "Win32PeLdrImage::allocSections, DosAllocMem returned %d", rc));
    663673        errorState = rc;
    664674        return(FALSE);
     
    747757  memallocs = (ULONG *)malloc(4096*sizeof(ULONG *));
    748758  if(memallocs == NULL) {
    749         fout << "allocFixedMem: MALLOC FAILED for memallocs" << endl;
     759        dprintf((LOG, "allocFixedMem: MALLOC FAILED for memallocs" ));
    750760        return FALSE;
    751761  }
     
    758768        if(rc) break;
    759769
    760         fout << "DosAllocMem returned " << address << endl;
     770        dprintf((LOG, "DosAllocMem returned %x", address ));
    761771        if(address + FALLOC_SIZE >= oh.ImageBase) {
    762772                if(address > oh.ImageBase) {//we've passed it!
     
    881891                                if(section == NULL) {
    882892                                        //should never happen
    883                                         dprintf(("::setFixups -> section == NULL!!"));
     893                                        dprintf((LOG, "::setFixups -> section == NULL!!"));
    884894                                        return FALSE;
    885895                                }
     
    920930  }
    921931  else {
    922         dprintf(("Win32PeLdrImage::setFixups, no fixups at %x, %d", virtAddress, size));
     932        dprintf((LOG, "Win32PeLdrImage::setFixups, no fixups at %x, %d", virtAddress, size));
    923933        return(FALSE);
    924934  }
     
    942952      page = (char *)((char *)prel + (ULONG)prel->VirtualAddress);
    943953      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 ));
    947955      j++;
    948956      for(i=0;i<count;i++) {
     
    951959        switch(type) {
    952960            case IMAGE_REL_BASED_ABSOLUTE:
    953 ////                fout << "absolute fixup; unused" << endl;
     961////                dprintf((LOG, "absolute fixup; unused" ));
    954962                break;  //skip
    955963            case IMAGE_REL_BASED_HIGHLOW:
    956 ////                fout << "address " << offset << " type " << type << endl;
     964////                dprintf((LOG, "address ", offset << " type ", type ));
    957965                AddOff32Fixup(prel->VirtualAddress + offset);
    958966                break;
     
    966974            case IMAGE_REL_BASED_MIPS_JMPADDR:
    967975            default:
    968                 fout << "Unknown/unsupported fixup type!" << endl;
     976                dprintf((LOG, "Unknown/unsupported fixup type!" ));
    969977                break;
    970978        }
     
    974982  }
    975983  else {
    976     fout << "No internal fixups found!\n" << endl;
     984    dprintf((LOG, "No internal fixups found!" ));
    977985    errorState = ERROR_INTERNAL;
    978986    return(FALSE);
     
    989997  fixup   = (ULONG *)(fixupaddr + realBaseAddress);
    990998  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)));
    9921000  *fixup  = realBaseAddress + (*fixup - oh.ImageBase);
    9931001}
     
    10031011  if(fHighFixup) {
    10041012        *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));
    10061014  }
    10071015  else {
    10081016        *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));
    10101018  }
    10111019}
     
    10211029  if(apiaddr == 0)
    10221030  {
    1023         dprintf(("KERNEL32:Win32PeLdrImage - %s.%u not found\n",
     1031        dprintf((LOG, "KERNEL32:Win32PeLdrImage - %s.%u not found\n",
    10241032                 WinDll->getName(),
    10251033                 ordinal));
    10261034
    1027         fout << "--->>> NOT FOUND!" << endl;
     1035        dprintf((LOG, "--->>> NOT FOUND!" ));
    10281036        *import = (ULONG)MissingApi;
    10291037  }
     
    10411049  if(apiaddr == 0)
    10421050  {
    1043         dprintf(("KERNEL32:Win32PeLdrImage - %s.%s not found\n",
     1051        dprintf((LOG, "KERNEL32:Win32PeLdrImage - %s.%s not found\n",
    10441052                WinDll->getName(),
    10451053                impname));
    10461054
    1047         fout << "--->>> NOT FOUND!" << endl;
     1055        dprintf((LOG, "--->>> NOT FOUND!" ));
    10481056        *import = (ULONG)MissingApi;
    10491057  }
     
    10651073     GetSectionHdrByImageDir(win32file, IMAGE_DIRECTORY_ENTRY_EXPORT, &sh) ) {
    10661074
    1067         fout << "Exported Functions: " << endl;
     1075        dprintf((LOG, "Exported Functions: " ));
    10681076    ptrOrd     = (USHORT *)((ULONG)ped->AddressOfNameOrdinals +
    10691077                            (ULONG)win32file);
     
    10861094            //points to code (virtual address relative to oh.ImageBase
    10871095            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));
    10931097#ifdef FORWARDERS
    10941098
     
    10961100        else {//forwarder
    10971101            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 ));
    10991103        }
    11001104#endif
     
    11081112            if(RVAExport) {
    11091113              //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));
    11141115              AddOrdExport(oh.ImageBase + RVAExport, ord);
    11151116            }
     
    11181119        else {//forwarder or empty
    11191120            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 ));
    11241123        }
    11251124#endif
     
    12621261    j += strlen(pszTmp) + 1;
    12631262  }
    1264   fout << endl;
    12651263  if (fBorland)
    1266     fout << "Borland-styled PE-File." << endl;
     1264    dprintf((LOG, "Borland-styled PE-File." ));
    12671265  //Store modules
    1268   fout << cModules << " imported Modules: " << endl;
     1266  dprintf((LOG, "%d imported Modules: ", cModules ));
    12691267
    12701268  /* 2) functions */
     
    12731271  for (i = 0; i < cModules; i++)
    12741272  {
    1275     fout << "Module " << pszCurModule << endl;
     1273    dprintf((LOG, "Module %s", pszCurModule ));
    12761274    //  a) check that OriginalFirstThunk not is 0 and look for Borland-styled PE
    12771275    if (i == 0)
     
    12951293    //  b) check if RVA ok
    12961294    if (!(pulImport > 0 && (ULONG)pulImport < pOH->SizeOfImage)) {
    1297         fout << "Invalid RVA " << hex((ULONG)pulImport) << endl;
     1295        dprintf((LOG, "Invalid RVA %x", pulImport ));
    12981296        break;
    12991297    }
     
    13031301        if (!GetSectionHdrByRVA(win32file, &shExtra, (ULONG)pulImport))
    13041302        {
    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 ));
    13061304            break;
    13071305        }
     
    13091307
    13101308    //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, "**********************************************************************" ));
    13141312    WinDll = (Win32PeLdrDll *)Win32DllBase::findModule(pszCurModule);
    13151313
     
    13351333                rc = DosLoadModule(szModuleFailure, sizeof(szModuleFailure), modname, (HMODULE *)&hInstanceNewDll);
    13361334                if(rc) {
    1337                         dprintf(("DosLoadModule returned %X for %s\n", rc, szModuleFailure));
     1335                        dprintf((LOG, "DosLoadModule returned %X for %s\n", rc, szModuleFailure));
    13381336                        sprintf(szErrorModule, "%s.DLL", szModuleFailure);
    13391337                        errorState = rc;
     
    13421340                WinDll = (Win32PeLdrDll *)Win32DllBase::findModule(hInstanceNewDll);
    13431341                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?!!?"));
    13451343                        errorState = ERROR_INTERNAL;
    13461344                        return(FALSE);
     
    13511349
    13521350                if(WinDll == NULL) {
    1353                     fout << "WinDll: Error allocating memory" << endl;
     1351                    dprintf((LOG, "WinDll: Error allocating memory" ));
    13541352                    WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    13551353                    errorState = ERROR_INTERNAL;
    13561354                    return(FALSE);
    13571355                }
    1358                 fout << "**********************************************************************" << endl;
    1359                 fout << "**********************     Loading Module        *********************" << endl;
    1360                 fout << "**********************************************************************" << endl;
     1356                dprintf((LOG, "**********************************************************************" ));
     1357                dprintf((LOG, "**********************     Loading Module        *********************" ));
     1358                dprintf((LOG, "**********************************************************************" ));
    13611359                if(WinDll->init(0) == FALSE) {
    1362                     fout << "Internal WinDll error " << WinDll->getError() << endl;
     1360                    dprintf((LOG, "Internal WinDll error ", WinDll->getError() ));
    13631361                    strcpy(szErrorModule, OSLibStripPath(modname));
    13641362                    return(FALSE);
    13651363                }
    13661364                if(WinDll->attachProcess() == FALSE) {
    1367                     fout << "attachProcess failed!" << endl;
     1365                    dprintf((LOG, "attachProcess failed!" ));
    13681366                    errorState = ERROR_INTERNAL;
    13691367                    return(FALSE);
     
    13711369                WinDll->AddRef();
    13721370        }
    1373         fout << "**********************************************************************" << endl;
    1374         fout << "**********************  Finished Loading Module  *********************" << endl;
    1375         fout << "**********************************************************************" << endl;
     1371        dprintf((LOG, "**********************************************************************" ));
     1372        dprintf((LOG, "**********************  Finished Loading Module  *********************" ));
     1373        dprintf((LOG, "**********************************************************************" ));
    13761374    }
    1377     else    fout << "Already found " << pszCurModule << endl;
     1375    else    dprintf((LOG, "Already found ", pszCurModule ));
    13781376
    13791377    WinDll->AddRef();
     
    13851383    section    = findSectionByOS2Addr(ulCurFixup);
    13861384    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 ));
    13891386        return FALSE;
    13901387    }
     
    13971394    while (pulImport[j] != 0) {
    13981395        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) ));
    14021397            StoreImportByOrd(WinDll, pulImport[j] & ~IMAGE_ORDINAL_FLAG, ulCurFixup);
    14031398        }
     
    14071402                if (!GetSectionHdrByRVA(win32file, &shExtra, pulImport[j]))
    14081403                {
    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] ));
    14101405                    break;
    14111406                }
     
    14131408            //KSO - Aug 6 1998 1:15am:this eases comparing...
    14141409            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 ));
    14181411            StoreImportByName(WinDll, pszFunctionName, ulCurFixup);
    14191412        }
     
    14301423    DosSetMem((PVOID)(ulCurFixup & ~0xfff), PAGE_SIZE*nrPages, section->pageflags);
    14311424
    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, "**********************************************************************" ));
    14351428
    14361429    pszCurModule += strlen(pszCurModule) + 1;
    1437     fout << endl;
    14381430  }//for (i = 0; i < cModules; i++)
    14391431
     
    15111503 int r;
    15121504
    1513   dprintf(("Missing api called!\n"));
     1505  dprintf((LOG, "Missing api called!\n"));
    15141506  if(fIgnore)
    15151507    return(0);
     
    15291521/******************************************************************************/
    15301522/******************************************************************************/
    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.