Ignore:
Timestamp:
Oct 10, 2000, 7:14:09 PM (25 years ago)
Author:
sandervl
Message:

pe loader fixes, add system32\drivers dir during installation, add build date + time during kernel32 load

File:
1 edited

Legend:

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

    r4445 r4474  
    1 /* $Id: wprocess.cpp,v 1.102 2000-10-06 15:16:07 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.103 2000-10-10 17:14:09 sandervl Exp $ */
    22
    33/*
     
    99 * NOTE: Even though Odin32 OS/2 apps don't switch FS selectors,
    1010 *       we still allocate a TEB to store misc information.
     11 *
     12 * TODO: What happens when a dll is first loaded as LOAD_LIBRARY_AS_DATAFILE
     13 *       and then for real? (first one not freed of course)
    1114 *
    1215 * Project Odin Software License can be found in LICENSE.TXT
     
    2528#include "windllpeldr.h"
    2629#include "winexepeldr.h"
    27 #include "winfakepeldr.h"
    2830#include "windlllx.h"
    2931#include <vmutex.h>
     
    443445 BOOL rc;
    444446
     447    SetLastError(ERROR_SUCCESS);
    445448    //SvL: Ignore FreeLibary for executable
    446449    if(WinExe && hinstance == WinExe->getInstanceHandle()) {
     
    633636 *                      by the module).
    634637 *
    635  *                  partially implemented yet - imports are resolved it seems.
    636638 *
    637639 *                  LOAD_LIBRARY_AS_DATAFILE
     
    648650 *                      LoadCursor, LoadIcon, LoadImage, LoadMenu.)
    649651 *
    650  *                  not implemented yet.
    651652 *
    652653 *                  LOAD_WITH_ALTERED_SEARCH_PATH
     
    677678                                        /* lpszLibFile contains a path. */
    678679    ULONG           fPE;                /* isPEImage return value. */
     680    DWORD           Characteristics;    //file header's Characteristics
    679681
    680682    /** @sketch
     
    720722    if (WinExe != NULL && WinExe->matchModName(lpszLibFile))
    721723        return WinExe->getInstanceHandle();
     724
    722725    pModule = Win32DllBase::findModule((LPSTR)lpszLibFile);
    723726    if (pModule)
     
    760763
    761764    //test if dll is in PE or LX format
    762     fPE = Win32ImageBase::isPEImage(szModname);
     765    fPE = Win32ImageBase::isPEImage(szModname, &Characteristics);
    763766
    764767    /** @sketch
     
    785788            if(pModule)
    786789            {
    787 
    788790                if(pModule->isLxDll())
    789791                {
     
    829831    if(fPE == ERROR_SUCCESS)
    830832    {
    831         Win32PeLdrDll * peldrDll;
    832         /* TODO!
    833          * We might use the fake loader class to do the LOAD_LIBRARY_AS_DATAFILE and
    834          * executable image loading. These are both loaded for accessing resource.
    835          * But this requires that they behaves like Dlls...
    836         if (dwFlags & LOAD_LIBRARY_AS_DATAFILE || fPE == 2)
    837         {
    838             peldrDll = new Win32PeLdrRsrcImg(szModname);
    839         }
    840         else
    841         */
     833        Win32PeLdrDll *peldrDll;
     834
     835        //SvL: If executable -> load as data file (only resources)
     836        if(!(Characteristics & IMAGE_FILE_DLL))
     837        {
     838            dwFlags |= (LOAD_LIBRARY_AS_DATAFILE | DONT_RESOLVE_DLL_REFERENCES);
     839        }
    842840
    843841        peldrDll = new Win32PeLdrDll(szModname);
     
    853851         * Process dwFlags
    854852         */
    855         if (dwFlags & (DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE))
    856         {
    857             peldrDll->disableThreadLibraryCalls();
    858             //peldrDll->setDontProcessImports(); not implemented?
     853        if (dwFlags & LOAD_LIBRARY_AS_DATAFILE)
     854        {
     855            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): LOAD_LIBRARY_AS_DATAFILE",
     856                      lpszLibFile, hFile, dwFlags));
     857            peldrDll->setLoadAsDataFile();
     858            peldrDll->disableLibraryCalls();
     859        }
     860        if (dwFlags & DONT_RESOLVE_DLL_REFERENCES)
     861        {
     862            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): DONT_RESOLVE_DLL_REFERENCES",
     863                      lpszLibFile, hFile, dwFlags));
     864            peldrDll->disableLibraryCalls();
     865            peldrDll->disableImportHandling();
    859866        }
    860867        if (dwFlags & LOAD_WITH_ALTERED_SEARCH_PATH)
     
    863870                      lpszLibFile, hFile, dwFlags));
    864871            //peldrDll->setLoadWithAlteredSearchPath();
    865         }
    866         if (dwFlags & LOAD_LIBRARY_AS_DATAFILE)
    867         {
    868             dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Warning dwFlags LOAD_LIBRARY_AS_DATAFILE is not implemented.",
    869                      lpszLibFile, hFile, dwFlags));
    870             //peldrDll->setLoadAsDatafile();
    871872        }
    872873
     
    918919            SetLastError(ERROR_INVALID_EXE_SIGNATURE);
    919920            delete peldrDll;
    920                 return NULL;
     921            return NULL;
    921922        }
    922923    }
     
    18121813{
    18131814 Win32ImageBase *winimage;
    1814  Win32PeLdrRsrcImg *rsrcimg;
    1815 
    1816   dprintf(("GetVersionStruct of module %s", lpszModName));
     1815 HINSTANCE hDll;
     1816
     1817  dprintf(("GetVersionStruct of module %s %x %d", lpszModName, verstruct, bufLength));
     1818  if(verstruct == NULL) {
     1819        SetLastError(ERROR_INVALID_PARAMETER);
     1820        return FALSE;
     1821  }
     1822  if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName))
     1823  {
     1824        winimage = (Win32ImageBase *)WinExe;
     1825  }
     1826  else
     1827  {
     1828        winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
     1829        if(winimage == NULL)
     1830        {
     1831          char modname[CCHMAXPATH];
     1832
     1833          strcpy(modname, lpszModName);
     1834          //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
     1835          Win32DllBase::renameDll(modname);
     1836
     1837          if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
     1838          {
     1839            HINSTANCE hInstance;
     1840
     1841              //must be an LX dll, just load it (app will probably load it anyway)
     1842              hInstance = LoadLibraryA(modname);
     1843              if(hInstance == 0)
     1844                  return 0;
     1845
     1846              winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
     1847              if(winimage) {
     1848                   return winimage->getVersionStruct(verstruct, bufLength);
     1849              }
     1850              dprintf(("GetVersionStruct; just loaded dll %s, but can't find it now!", modname));
     1851              return 0;
     1852          }
     1853          BOOL rc = FALSE;
     1854
     1855          hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE);
     1856          if(hDll == 0)
     1857              return 0;
     1858
     1859          winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
     1860          if(winimage != NULL) {
     1861                rc = winimage->getVersionStruct(verstruct, bufLength);
     1862          }
     1863          else  dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
     1864          FreeLibrary(hDll);
     1865          return rc;
     1866        }
     1867  }
     1868  return winimage->getVersionStruct(verstruct, bufLength);
     1869}
     1870//******************************************************************************
     1871//******************************************************************************
     1872ULONG SYSTEM GetVersionSize(char *lpszModName)
     1873{
     1874 Win32ImageBase *winimage;
     1875 HINSTANCE hDll;
     1876
     1877  dprintf(("GetVersionSize of %s\n", lpszModName));
     1878
    18171879  if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
    18181880        winimage = (Win32ImageBase *)WinExe;
     
    18221884        if(winimage == NULL)
    18231885        {
    1824         char modname[CCHMAXPATH];
    1825 
    1826         strcpy(modname, lpszModName);
    1827         //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
    1828         Win32DllBase::renameDll(modname);
    1829 
    1830         if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
    1831         {
    1832          HINSTANCE hInstance;
     1886          char modname[CCHMAXPATH];
     1887
     1888          strcpy(modname, lpszModName);
     1889          //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
     1890          Win32DllBase::renameDll(modname);
     1891
     1892          if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
     1893          {
     1894            HINSTANCE hInstance;
    18331895
    18341896            //must be an LX dll, just load it (app will probably load it anyway)
     
    18361898            if(hInstance == 0)
    18371899                return 0;
    1838                 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
    1839                 if(winimage) {
    1840                 return winimage->getVersionStruct(verstruct, bufLength);
    1841             }
    1842             return 0;
    1843         }
    1844         //SvL: Try to load it
    1845         rsrcimg = new Win32PeLdrRsrcImg(modname);
    1846         if(rsrcimg == NULL)
    1847             return 0;
    1848 
    1849             rsrcimg->init(0);
    1850         if(rsrcimg->getError() != NO_ERROR)
    1851         {
    1852                 dprintf(("GetVersionStruct can't load %s\n", modname));
    1853             delete rsrcimg;
    1854                 return(FALSE);
    1855         }
    1856         BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength);
    1857         delete rsrcimg;
    1858         return rc;
    1859         }
    1860   }
    1861   return winimage->getVersionStruct(verstruct, bufLength);
    1862 }
    1863 //******************************************************************************
    1864 //******************************************************************************
    1865 ULONG SYSTEM GetVersionSize(char *lpszModName)
    1866 {
    1867  Win32ImageBase *winimage;
    1868  Win32PeLdrRsrcImg *rsrcimg;
    1869 
    1870   dprintf(("GetVersionSize of %s\n", lpszModName));
    1871 
    1872   if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
    1873         winimage = (Win32ImageBase *)WinExe;
    1874   }
    1875   else {
    1876         winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
    1877         if(winimage == NULL)
    1878         {
    1879      char modname[CCHMAXPATH];
    1880 
    1881         strcpy(modname, lpszModName);
    1882         //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
    1883         Win32DllBase::renameDll(modname);
    1884 
    1885         if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS)
    1886         {
    1887          HINSTANCE hInstance;
    1888 
    1889             //must be an LX dll, just load it (app will probably load it anyway)
    1890             hInstance = LoadLibraryA(modname);
    1891             if(hInstance == 0)
    1892                 return 0;
    1893                 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
    1894                 if(winimage) {
     1900
     1901            winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
     1902            if(winimage) {
    18951903                return winimage->getVersionSize();
    18961904            }
     1905            dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", modname));
    18971906            return 0;
    18981907        }
    1899 
    1900         //SvL: Try to load it
    1901         rsrcimg = new Win32PeLdrRsrcImg(modname);
    1902         if(rsrcimg == NULL)
     1908        int size = 0;
     1909
     1910        hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE);
     1911        if(hDll == 0)
    19031912            return 0;
    19041913
    1905             rsrcimg->init(0);
    1906         if(rsrcimg->getError() != NO_ERROR)
    1907         {
    1908                 dprintf(("GetVersionSize can't load %s\n", modname));
    1909             delete rsrcimg;
    1910                 return(FALSE);
    1911         }
    1912         int size = rsrcimg->getVersionSize();
    1913         delete rsrcimg;
     1914        winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
     1915        if(winimage != NULL) {
     1916                size = winimage->getVersionSize();
     1917        }
     1918        else    dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
     1919        FreeLibrary(hDll);
    19141920        return size;
    1915         }
     1921      }
    19161922  }
    19171923  return winimage->getVersionSize();
    19181924}
    19191925//******************************************************************************
    1920 //TODO:What does this do exactly??
    19211926//******************************************************************************
    19221927ODINFUNCTION1(BOOL,DisableThreadLibraryCalls,HMODULE,hModule)
Note: See TracChangeset for help on using the changeset viewer.