Ignore:
Timestamp:
Oct 23, 1999, 2:34:48 PM (26 years ago)
Author:
sandervl
Message:

Changes for logging & getversionsize/struct

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:35 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.8 1999-10-23 12:34:48 sandervl Exp $ */
    22
    33/*
     
    88 *
    99 * 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!
    1018 *
    1119 */
     
    5967//******************************************************************************
    6068//******************************************************************************
    61 Win32PeLdrImage::Win32PeLdrImage(char *szFileName) :
     69Win32PeLdrImage::Win32PeLdrImage(char *szFileName, int loadtype) :
    6270    Win32ImageBase(-1),
    6371    nrsections(0), imageSize(0),
    6472    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    6573    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    66     pResSection(NULL)
    67 {
     74    pResSection(NULL), fImgMapping(0)
     75{
     76  loadType = loadtype;
     77
    6878  strcpy(this->szFileName, szFileName);
    6979
     
    8393        sprintf(logname, "pe_%d.log", loadNr);
    8494        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        }
    8599        dprintf(("PE LOGFILE for %s: %s", szModule, logname));
    86100        foutInit = TRUE;
     
    99113  if(ordexports)
    100114        free(ordexports);
     115
     116  //SvL: Only happens for images that aren't really loaded (RSRC_LOAD)
     117  if(fImgMapping) CloseHandle(fImgMapping);
     118  fImgMapping = 0;
    101119}
    102120//******************************************************************************
     
    104122BOOL Win32PeLdrImage::init(ULONG reservedMem)
    105123{
    106  HANDLE fImgMapping = 0;
    107124 char   szErrorMsg[64];
    108125 LPVOID win32file     = NULL;
     
    172189  nSections = NR_SECTIONS(win32file);
    173190
    174   if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) {
     191  if(loadType == REAL_LOAD)
     192  {
     193   if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) {
    175194    fout << endl << "*************************PE SECTIONS START**************************" << endl;
    176195    for (i=0; i<nSections; i++) {
     
    281300        goto failure;
    282301     }
    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 size
    291   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) {
    292311        fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
    293312        imageSize = imageVirtEnd - oh.ImageBase;
    294   }
    295   if(allocSections(reservedMem) == FALSE) {
     313   }
     314   if(allocSections(reservedMem) == FALSE) {
    296315        fout << "Failed to allocate image memory, rc " << errorState << endl;
    297316        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) {
    301320        fout << "Failed to store sections, rc " << errorState << endl;
    302321        goto failure;
    303   }
    304   if(oh.AddressOfEntryPoint) {
     322   }
     323   if(oh.AddressOfEntryPoint) {
    305324        entryPoint = realBaseAddress + oh.AddressOfEntryPoint;
    306   }
    307   else {
    308         fout << "EntryPoint == NULL" << endl;
     325   }
     326   else {
     327        fout << "EntryPoint == NULL" << endl; 
    309328        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);
    314333
    315334        if(sect == NULL) {
     
    334353        }
    335354        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) {
    339358        if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) {
    340359                fout << "Failed to set fixups" << endl;
    341360                goto failure;
    342361        }
    343   }
    344   if(fh.Characteristics & IMAGE_FILE_DLL) {
     362   }
     363   if(fh.Characteristics & IMAGE_FILE_DLL) {
    345364        if(processExports((char *)win32file) == FALSE) {
    346365                fout << "Failed to process exported apis" << endl;
    347366                goto failure;
    348367        }
    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  }
    353373
    354374  //PH: get pResDir pointer correct first, since processImports may
     
    361381  }
    362382
    363   if(processImports((char *)win32file) == FALSE) {
     383  if (loadType == REAL_LOAD)
     384  {
     385   if(processImports((char *)win32file) == FALSE) {
    364386        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) {
    370392        fout << "Failed to set memory protection" << endl;
    371393        goto failure;
    372   }
    373 
    374   CloseHandle(fImgMapping);
     394   }
     395   CloseHandle(fImgMapping);
     396   fImgMapping = 0;
     397  }
    375398  return(TRUE);
    376399failure:
    377400  if(fImgMapping) CloseHandle(fImgMapping);
     401  fImgMapping = 0;
    378402  errorState = ERROR_INTERNAL;
    379403  return FALSE;
Note: See TracChangeset for help on using the changeset viewer.