Ignore:
Timestamp:
Nov 11, 1999, 8:10:09 PM (26 years ago)
Author:
sandervl
Message:

version loading fixes + heap corruption fix

File:
1 edited

Legend:

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

    r1663 r1708  
    1 /* $Id: winimagepeldr.cpp,v 1.11 1999-11-09 14:19:47 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.12 1999-11-11 19:10:09 sandervl Exp $ */
    22
    33/*
     
    7373    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    7474    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    75     pResSection(NULL), fImgMapping(0)
     75    fImgMapping(0)
    7676{
    7777 HFILE  dllfile;
     
    140140 ULONG  filesize, ulRead;
    141141 PIMAGE_SECTION_HEADER psh;
     142 IMAGE_SECTION_HEADER sh;
    142143 IMAGE_TLS_DIRECTORY *tlsDir = NULL;
    143144 int    nSections, i;
     
    315316     }
    316317   }
    317    fout << "*************************PE SECTIONS END **************************" << endl;
    318    imageSize += imageVirtBase - oh.ImageBase;
    319    fout << "Total size of Image " << imageSize << endl;
    320    fout << "imageVirtBase       " << imageVirtBase << endl;
    321    fout << "imageVirtEnd        " << imageVirtEnd << endl;
    322 
    323    //In case there are any gaps between sections, adjust size
    324    if(imageSize != imageVirtEnd - oh.ImageBase) {
     318  }
     319  else {
     320        if(GetSectionHdrByName (win32file, &sh, ".rsrc"))
     321        {
     322            addSection(SECTION_RESOURCE, (char *)win32file+sh.PointerToRawData,
     323                       sh.SizeOfRawData, sh.VirtualAddress + oh.ImageBase,
     324                       sh.Misc.VirtualSize);
     325        }
     326  }
     327  fout << "*************************PE SECTIONS END **************************" << endl;
     328  imageSize += imageVirtBase - oh.ImageBase;
     329  fout << "Total size of Image " << imageSize << endl;
     330  fout << "imageVirtBase       " << imageVirtBase << endl;
     331  fout << "imageVirtEnd        " << imageVirtEnd << endl;
     332
     333  //In case there are any gaps between sections, adjust size
     334  if(imageSize != imageVirtEnd - oh.ImageBase) {
    325335        fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
    326336        imageSize = imageVirtEnd - oh.ImageBase;
    327    }
    328    if(allocSections(reservedMem) == FALSE) {
     337  }
     338  if(allocSections(reservedMem) == FALSE) {
    329339        fout << "Failed to allocate image memory, rc " << errorState << endl;
    330340        goto failure;
    331    }
    332    fout << "OS/2 base address " << realBaseAddress << endl;
    333    if(storeSections((char *)win32file) == FALSE) {
     341  }
     342  fout << "OS/2 base address " << realBaseAddress << endl;
     343  if(storeSections((char *)win32file) == FALSE) {
    334344        fout << "Failed to store sections, rc " << errorState << endl;
    335345        goto failure;
    336    }
    337    if(oh.AddressOfEntryPoint) {
     346  }
     347  if(oh.AddressOfEntryPoint) {
    338348        entryPoint = realBaseAddress + oh.AddressOfEntryPoint;
    339    }
    340    else {
     349  }
     350  else {
    341351        fout << "EntryPoint == NULL" << endl;
    342352        entryPoint = NULL;
    343    }
    344 
     353  }
     354
     355  if(loadType == REAL_LOAD)
     356  {
    345357   if(tlsDir != NULL) {
    346358    Section *sect = findSection(SECTION_TLS);
     
    381393        }
    382394   }
    383 
    384    //SvL: Use pointer to image header as module handle now. Some apps needs this
    385    hinstance = (HINSTANCE)realBaseAddress;
    386   }
     395  }
     396
     397  //SvL: Use pointer to image header as module handle now. Some apps needs this
     398  hinstance = (HINSTANCE)realBaseAddress;
    387399
    388400  //PH: get pResDir pointer correct first, since processImports may
    389401  //    implicitly call functions depending on it.
    390   IMAGE_SECTION_HEADER sh;
    391402  if(GetSectionHdrByName (win32file, &sh, ".rsrc")) {
    392403        //get offset in resource object of directory entry
    393404        pResDir = (PIMAGE_RESOURCE_DIRECTORY)(sh.VirtualAddress + realBaseAddress);
    394         pResourceSectionStart = (ULONG)pResSection->virtaddr - oh.ImageBase;
     405        pResourceSectionStart = sh.VirtualAddress;
    395406  }
    396407
     
    401412        goto failure;
    402413   }
    403 
    404    //set final memory protection flags (storeSections sets them to read/write)
    405    if(setMemFlags() == FALSE) {
     414  }
     415 
     416  //set final memory protection flags (storeSections sets them to read/write)
     417  if(setMemFlags() == FALSE) {
    406418        fout << "Failed to set memory protection" << endl;
    407419        goto failure;
    408    }
    409    CloseHandle(fImgMapping);
    410    fImgMapping = 0;
    411   }
     420  }
     421  CloseHandle(fImgMapping);
     422  fImgMapping = 0;
     423
    412424  return(TRUE);
    413425failure:
     
    428440  section[nrsections].virtaddr       = virtaddress;
    429441
    430   if(type == SECTION_RESOURCE) {
    431         pResSection = &section[nrsections];
    432   }
    433442  virtsize   = ((virtsize - 1) & ~0xFFF) + PAGE_SIZE;
    434443  imageSize += virtsize;
Note: See TracChangeset for help on using the changeset viewer.