Changeset 13979


Ignore:
Timestamp:
Apr 16, 2000, 9:07:01 AM (25 years ago)
Author:
bird
Message:

Changed the return from isPEImage a bit. It'll now return 1 if DLL and 2 if
EXE.

File:
1 edited

Legend:

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

    r13977 r13979  
    1 /* $Id: wprocess.cpp,v 1.77 2000-04-16 06:49:07 bird Exp $ */
     1/* $Id: wprocess.cpp,v 1.78 2000-04-16 07:07:01 bird Exp $ */
    22
    33/*
     
    780780    /** @sketch
    781781     *  If PE image THEN
    782      *      Check again(!) if the module is allready loaded.
    783      *      IF Allready loaded THEN
    784      *          Inc dynamic ref count.
    785      *          Inc ref count.
    786      *          hDll <- instance handle.
    787      *      ELSE
    788      *          Try load the file using the Win32PeLdrDll class.
    789      *          <sketch continued further down>
    790      *      Endif
    791      *      Try load the file using the peldr.
     782     *      IF LOAD_LIBRARY_AS_DATAFILE or Executable THEN
     783     *
     784     *
     785     *      Try load the file using the Win32PeLdrDll class.
     786     *      <sketch continued further down>
    792787     *  Else
    793788     *      Set last error.
     
    796791     *  return hDll.
    797792     */
    798 
    799     if ((fPE = Win32ImageBase::isPEImage(szModname)))
     793    fPE = Win32ImageBase::isPEImage(szModname);
     794    if (fPE)
    800795    {
    801         pModule = Win32DllBase::findModule(szModname); /* This should _NEVER_ succeed! */
    802         if (pModule)
    803         {
    804             pModule->incDynamicLib();
    805             pModule->AddRef();
    806             hDll = pModule->getInstanceHandle();
    807             dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): returns 0x%x, Dll found (2) %s",
    808                      lpszLibFile, hFile, dwFlags, pModule->getInstanceHandle(), pModule->getFullPath()));
     796        Win32PeLdrDll * peldrDll;
     797        /* TODO!
     798         * We might use the fake loader class to do the LOAD_LIBRARY_AS_DATAFILE and
     799         * executable image loading. These are both loaded for accessing resource.
     800         * But this requires that they behaves like Dlls...
     801        if (dwFlags & LOAD_LIBRARY_AS_DATAFILE || fPE == 2)
     802        {
     803            peldrDll = new Win32PeLdrRsrcImg(szModname);
    809804        }
    810805        else
    811         {
    812             /* TODO EXE loading - will use the Win32PeLdrRsrcImg for that */
    813             Win32PeLdrDll * peldrDll;
    814 
    815             peldrDll = new Win32PeLdrDll(szModname);
    816             if (peldrDll == NULL)
    817             {
    818                 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Failed to created instance of Win32PeLdrDll. returns NULL.",
    819                          lpszLibFile, hFile, dwFlags));
    820                 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    821                 return NULL;
    822             }
    823 
    824             /** @sketch
    825              * Process dwFlags
    826              */
    827             if (dwFlags & (DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE))
    828             {
    829                 peldrDll->setNoEntryCalls();
    830                 //peldrDll->setDontProcessImports(); not implemented?
    831             }
    832             if (dwFlags & LOAD_WITH_ALTERED_SEARCH_PATH)
    833             {
    834                 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Warning dwFlags LOAD_WITH_ALTERED_SEARCH_PATH is not implemented.",
    835                           lpszLibFile, hFile, dwFlags));
    836                 //peldrDll->setLoadWithAlteredSearchPath();
    837             }
    838             if (dwFlags & LOAD_LIBRARY_AS_DATAFILE)
    839             {
    840                 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Warning dwFlags LOAD_LIBRARY_AS_DATAFILE is not implemented.",
    841                          lpszLibFile, hFile, dwFlags));
    842                 //peldrDll->setLoadAsDatafile();
    843             }
    844 
    845             /** @sketch
    846              *  Initiate the peldr DLL.
    847              *  IF successful init THEN
    848              *      Inc dynamic ref count.
    849              *      Inc ref count.
    850              *      Attach to process
    851              *      IF successful THEN
    852              *          hDLL <- instance handle.
    853              *      ELSE
    854              *          set last error
    855              *          delete Win32PeLdrDll instance.
    856              *      Endif
    857              *  ELSE
    858              *      set last error
    859              *      delete Win32PeLdrDll instance.
    860              *  Endif.
    861              */
    862             if (peldrDll->init(0))
    863             {
    864                 peldrDll->incDynamicLib();
    865                 peldrDll->AddRef();
    866                 if (peldrDll->attachProcess())
    867                     hDll = peldrDll->getInstanceHandle();
    868                 else
    869                 {
    870                     dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): attachProcess call to Win32PeLdrDll instance failed. returns NULL.",
    871                              lpszLibFile, hFile, dwFlags));
    872                     SetLastError(ERROR_DLL_INIT_FAILED);
    873                     delete peldrDll;
    874                 }
    875             }
     806        */
     807
     808        peldrDll = new Win32PeLdrDll(szModname);
     809        if (peldrDll == NULL)
     810        {
     811            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Failed to created instance of Win32PeLdrDll. returns NULL.",
     812                     lpszLibFile, hFile, dwFlags));
     813            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     814            return NULL;
     815        }
     816
     817        /** @sketch
     818         * Process dwFlags
     819         */
     820        if (dwFlags & (DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE))
     821        {
     822            peldrDll->setNoEntryCalls();
     823            //peldrDll->setDontProcessImports(); not implemented?
     824        }
     825        if (dwFlags & LOAD_WITH_ALTERED_SEARCH_PATH)
     826        {
     827            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Warning dwFlags LOAD_WITH_ALTERED_SEARCH_PATH is not implemented.",
     828                      lpszLibFile, hFile, dwFlags));
     829            //peldrDll->setLoadWithAlteredSearchPath();
     830        }
     831        if (dwFlags & LOAD_LIBRARY_AS_DATAFILE)
     832        {
     833            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Warning dwFlags LOAD_LIBRARY_AS_DATAFILE is not implemented.",
     834                     lpszLibFile, hFile, dwFlags));
     835            //peldrDll->setLoadAsDatafile();
     836        }
     837
     838        /** @sketch
     839         *  Initiate the peldr DLL.
     840         *  IF successful init THEN
     841         *      Inc dynamic ref count.
     842         *      Inc ref count.
     843         *      Attach to process
     844         *      IF successful THEN
     845         *          hDLL <- instance handle.
     846         *      ELSE
     847         *          set last error
     848         *          delete Win32PeLdrDll instance.
     849         *      Endif
     850         *  ELSE
     851         *      set last error
     852         *      delete Win32PeLdrDll instance.
     853         *  Endif.
     854         */
     855        if (peldrDll->init(0))
     856        {
     857            peldrDll->incDynamicLib();
     858            peldrDll->AddRef();
     859            if (peldrDll->attachProcess())
     860                hDll = peldrDll->getInstanceHandle();
    876861            else
    877862            {
    878                 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Failed to init Win32PeLdrDll instance. error=%d returns NULL.",
    879                          lpszLibFile, hFile, dwFlags, peldrDll->getError()));
    880                 SetLastError(ERROR_INVALID_EXE_SIGNATURE);
     863                dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): attachProcess call to Win32PeLdrDll instance failed. returns NULL.",
     864                         lpszLibFile, hFile, dwFlags));
     865                SetLastError(ERROR_DLL_INIT_FAILED);
    881866                delete peldrDll;
    882867            }
     868        }
     869        else
     870        {
     871            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Failed to init Win32PeLdrDll instance. error=%d returns NULL.",
     872                     lpszLibFile, hFile, dwFlags, peldrDll->getError()));
     873            SetLastError(ERROR_INVALID_EXE_SIGNATURE);
     874            delete peldrDll;
    883875        }
    884876    }
Note: See TracChangeset for help on using the changeset viewer.