Ignore:
Timestamp:
Oct 16, 2000, 1:05:15 PM (25 years ago)
Author:
sandervl
Message:

LoadLibraryExA fix (for dlls with the same name as the exe)

File:
1 edited

Legend:

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

    r4474 r4486  
    1 /* $Id: wprocess.cpp,v 1.103 2000-10-10 17:14:09 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.104 2000-10-16 11:05:15 sandervl Exp $ */
    22
    33/*
     
    679679    ULONG           fPE;                /* isPEImage return value. */
    680680    DWORD           Characteristics;    //file header's Characteristics
     681    BOOL            fDllModule;         //file type
    681682
    682683    /** @sketch
     
    708709    /** @sketch
    709710     *  First we'll see if the module is allready loaded - either as the EXE or as DLL.
    710      *  IF Executable present AND libfile matches the modname of the executable THEN
     711     *  IF NOT dll AND Executable present AND libfile matches the modname of the executable THEN
    711712     *      RETURN instance handle of executable.
    712713     *  Endif
     
    720721     *  Endif
    721722     */
    722     if (WinExe != NULL && WinExe->matchModName(lpszLibFile))
     723    if(strstr(lpszLibFile, ".DLL")) {
     724        fDllModule = TRUE;
     725    }
     726    else {
     727        if(!strstr(lpszLibFile, ".")) {
     728            //if there's no extension or trainling dot, we
     729            //assume it's a dll (see Win32 SDK docs)
     730            fDllModule = TRUE;
     731        }
     732    }
     733
     734    //todo: the entire exe name probably needs to be identical (path + extension)
     735    //      -> check in NT
     736    if (!fDllModule && WinExe != NULL && WinExe->matchModName(lpszLibFile))
    723737        return WinExe->getInstanceHandle();
    724738
     
    790804                if(pModule->isLxDll())
    791805                {
    792                         ((Win32LxDll *)pModule)->setDllHandleOS2(hDll);
    793                         if(fPeLoader)
    794                         {
    795                                 if(pModule->AddRef() == -1) {//-1 -> load failed (attachProcess)
    796                                         dprintf(("Dll %s refused to be loaded; aborting", szModname));
    797                                         delete pModule;
    798                                         return 0;
    799                                 }
    800                         }
     806                        ((Win32LxDll *)pModule)->setDllHandleOS2(hDll);
     807                        if(fPeLoader)
     808            {
     809                            if(pModule->AddRef() == -1) {//-1 -> load failed (attachProcess)
     810                    dprintf(("Dll %s refused to be loaded; aborting", szModname));
     811                    delete pModule;
     812                    return 0;
     813                }
     814                        }
    801815                }
    802816                pModule->incDynamicLib();
     
    851865         * Process dwFlags
    852866         */
    853         if (dwFlags & LOAD_LIBRARY_AS_DATAFILE) 
     867        if (dwFlags & LOAD_LIBRARY_AS_DATAFILE)
    854868        {
    855869            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): LOAD_LIBRARY_AS_DATAFILE",
    856870                      lpszLibFile, hFile, dwFlags));
    857871            peldrDll->setLoadAsDataFile();
    858             peldrDll->disableLibraryCalls();
     872            peldrDll->disableLibraryCalls();
    859873        }
    860874        if (dwFlags & DONT_RESOLVE_DLL_REFERENCES)
     
    862876            dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): DONT_RESOLVE_DLL_REFERENCES",
    863877                      lpszLibFile, hFile, dwFlags));
    864             peldrDll->disableLibraryCalls();
     878            peldrDll->disableLibraryCalls();
    865879            peldrDll->disableImportHandling();
    866880        }
     
    910924                SetLastError(ERROR_DLL_INIT_FAILED);
    911925                delete peldrDll;
    912                 return NULL;
     926        return NULL;
    913927            }
    914928        }
     
    919933            SetLastError(ERROR_INVALID_EXE_SIGNATURE);
    920934            delete peldrDll;
    921             return NULL;
     935        return NULL;
    922936        }
    923937    }
     
    927941                 lpszLibFile, hFile, dwFlags, szModname, fPE));
    928942        SetLastError(fPE);
    929         return NULL;
     943    return NULL;
    930944    }
    931945
     
    11111125            return ERROR_NOT_ENOUGH_MEMORY;
    11121126        }
    1113         strcpy((char *)pszCmdLineA, pszPeExe);
    1114        
     1127    strcpy((char *)pszCmdLineA, pszPeExe);
     1128
    11151129        rc = NO_ERROR;
    11161130    }
     
    14731487        if(!strstr(szModule, ".")) {
    14741488            //if there's no extension or trainling dot, we
    1475                         //assume it's a dll (see Win32 SDK docs)
     1489            //assume it's a dll (see Win32 SDK docs)
    14761490            fDllModule = TRUE;
    14771491        }
     
    14811495        *dot = 0;
    14821496
    1483     if(!fDllModule && WinExe && !strcmpi(szModule, WinExe->getModuleName())) {
     1497    if(!fDllModule && WinExe && WinExe->matchModName(szModule)) {
    14841498        hMod = WinExe->getInstanceHandle();
    14851499    }
     
    15911605    }
    15921606    if(szAppName[0] == '"') {
    1593         exename = &szAppName[1];
     1607    exename = &szAppName[1];
    15941608    }
    15951609    else exename = szAppName;
    15961610
    1597     if(GetFileAttributesA(exename) == -1) { 
    1598         dprintf(("CreateProcess: can't find executable!"));
    1599         SetLastError(ERROR_FILE_NOT_FOUND);
    1600         return FALSE;
    1601     }   
     1611    if(GetFileAttributesA(exename) == -1) {
     1612    dprintf(("CreateProcess: can't find executable!"));
     1613    SetLastError(ERROR_FILE_NOT_FOUND);
     1614    return FALSE;
     1615    }
    16021616    dprintf(("KERNEL32:  CreateProcess %s\n", cmdline));
    16031617
    1604     //SvL: Allright. Before we call O32_CreateProcess, we must take care of 
     1618    //SvL: Allright. Before we call O32_CreateProcess, we must take care of
    16051619    //     lpCurrentDirectory ourselves. (Open32 ignores it!)
    16061620    if(lpCurrentDirectory) {
    1607         char *newcmdline;
    1608 
    1609         newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(cmdline) + 32);
    1610         sprintf(newcmdline, "PE.EXE /OPT:[CURDIR=%s] %s", lpCurrentDirectory, cmdline);
    1611         free(cmdline);
    1612         cmdline = newcmdline;
     1621    char *newcmdline;
     1622
     1623    newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(cmdline) + 32);
     1624    sprintf(newcmdline, "PE.EXE /OPT:[CURDIR=%s] %s", lpCurrentDirectory, cmdline);
     1625    free(cmdline);
     1626    cmdline = newcmdline;
    16131627    }
    16141628    else {
    1615         char *newcmdline;
    1616 
    1617         newcmdline = (char *)malloc(strlen(cmdline) + 16);
    1618         sprintf(newcmdline, "PE.EXE %s", cmdline);
    1619         free(cmdline);
    1620         cmdline = newcmdline;
     1629    char *newcmdline;
     1630
     1631    newcmdline = (char *)malloc(strlen(cmdline) + 16);
     1632    sprintf(newcmdline, "PE.EXE %s", cmdline);
     1633    free(cmdline);
     1634    cmdline = newcmdline;
    16211635    }
    16221636    rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline,lpProcessAttributes,
     
    16241638                         lpEnvironment, lpCurrentDirectory, lpStartupInfo,
    16251639                         lpProcessInfo);
    1626     if(rc == TRUE) 
     1640    if(rc == TRUE)
    16271641    {
    16281642      if (dwCreationFlags & DEBUG_PROCESS && pThreadDB != NULL)
     
    17011715    rc = O32_WaitForInputIdle(procinfo.hProcess, 15000);
    17021716    if(rc != 0) {
    1703         dprintf(("WinExec: WaitForInputIdle %x returned %x", procinfo.hProcess, rc));
     1717        dprintf(("WinExec: WaitForInputIdle %x returned %x", procinfo.hProcess, rc));
    17041718    }
    17051719    return procinfo.hProcess; //correct?
     
    17121726 * Copyright 1995 Alexandre Julliard
    17131727 */
    1714 HINSTANCE WINAPI LoadModule( LPCSTR name, LPVOID paramBlock ) 
     1728HINSTANCE WINAPI LoadModule( LPCSTR name, LPVOID paramBlock )
    17151729{
    17161730    LOADPARAMS *params = (LOADPARAMS *)paramBlock;
     
    17471761        startup.wShowWindow = params->lpCmdShow[1];
    17481762    }
    1749    
     1763
    17501764    if (CreateProcessA( filename, cmdline, NULL, NULL, FALSE, 0,
    17511765                        params->lpEnvAddress, NULL, &startup, &info ))
    17521766    {
    17531767        /* Give 15 seconds to the app to come up */
    1754         if ( O32_WaitForInputIdle ( info.hProcess, 15000 ) ==  0xFFFFFFFF ) 
     1768        if ( O32_WaitForInputIdle ( info.hProcess, 15000 ) ==  0xFFFFFFFF )
    17551769            dprintf(("ERROR: WaitForInputIdle failed: Error %ld\n", GetLastError() ));
    17561770        hInstance = 33;
     
    18171831  dprintf(("GetVersionStruct of module %s %x %d", lpszModName, verstruct, bufLength));
    18181832  if(verstruct == NULL) {
    1819         SetLastError(ERROR_INVALID_PARAMETER);
    1820         return FALSE;
     1833    SetLastError(ERROR_INVALID_PARAMETER);
     1834    return FALSE;
    18211835  }
    1822   if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) 
     1836  if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName))
    18231837  {
    18241838        winimage = (Win32ImageBase *)WinExe;
    18251839  }
    1826   else 
     1840  else
    18271841  {
    18281842        winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
     
    18481862                   return winimage->getVersionStruct(verstruct, bufLength);
    18491863              }
    1850               dprintf(("GetVersionStruct; just loaded dll %s, but can't find it now!", modname));
     1864          dprintf(("GetVersionStruct; just loaded dll %s, but can't find it now!", modname));
    18511865              return 0;
    18521866          }
     
    18591873          winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
    18601874          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);
     1875            rc = winimage->getVersionStruct(verstruct, bufLength);
     1876      }
     1877          else  dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
     1878      FreeLibrary(hDll);
    18651879          return rc;
    18661880        }
     
    19031917                return winimage->getVersionSize();
    19041918            }
    1905             dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", modname));
     1919        dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", modname));
    19061920            return 0;
    19071921        }
     
    19141928        winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
    19151929        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);
     1930            size = winimage->getVersionSize();
     1931    }
     1932        else    dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName));
     1933    FreeLibrary(hDll);
    19201934        return size;
    19211935      }
Note: See TracChangeset for help on using the changeset viewer.