Changeset 4523 for trunk/src/kernel32/wprocess.cpp
- Timestamp:
- Oct 23, 2000, 3:42:47 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/wprocess.cpp
r4496 r4523 1 /* $Id: wprocess.cpp,v 1.10 5 2000-10-18 17:09:34sandervl Exp $ */1 /* $Id: wprocess.cpp,v 1.106 2000-10-23 13:42:47 sandervl Exp $ */ 2 2 3 3 /* … … 679 679 ULONG fPE; /* isPEImage return value. */ 680 680 DWORD Characteristics; //file header's Characteristics 681 BOOL fDllModule; //file type681 char *dot; 682 682 683 683 /** @sketch … … 709 709 /** @sketch 710 710 * First we'll see if the module is allready loaded - either as the EXE or as DLL. 711 * IF NOT dll ANDExecutable present AND libfile matches the modname of the executable THEN711 * IF Executable present AND libfile matches the modname of the executable THEN 712 712 * RETURN instance handle of executable. 713 713 * Endif … … 721 721 * Endif 722 722 */ 723 if(strstr(lpszLibFile, ".DLL")) { 724 fDllModule = TRUE; 723 strcpy(szModname, lpszLibFile); 724 strupr(szModname); 725 dot = strchr(szModname, '.'); 726 if(dot == NULL) { 727 //if there's no extension or trainling dot, we 728 //assume it's a dll (see Win32 SDK docs) 729 strcat(szModname, DLL_EXTENSION); 725 730 } 726 731 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)) 732 if(dot[1] == 0) { 733 //a trailing dot means the module has no extension (SDK docs) 734 *dot = 0; 735 } 736 } 737 if (WinExe != NULL && WinExe->matchModName(szModname)) 737 738 return WinExe->getInstanceHandle(); 738 739 739 pModule = Win32DllBase::findModule((LPSTR) lpszLibFile);740 pModule = Win32DllBase::findModule((LPSTR)szModname); 740 741 if (pModule) 741 742 { … … 743 744 pModule->AddRef(); 744 745 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): returns 0x%x. Dll found %s", 745 lpszLibFile, hFile, dwFlags, pModule->getInstanceHandle(), pModule->getFullPath()));746 szModname, hFile, dwFlags, pModule->getInstanceHandle(), pModule->getFullPath())); 746 747 return pModule->getInstanceHandle(); 747 748 } … … 758 759 * Endif 759 760 */ 760 fPath = strchr(lpszLibFile, '\\') || strchr(lpszLibFile, '/'); 761 strcpy(szModname, lpszLibFile); 761 fPath = strchr(szModname, '\\') || strchr(szModname, '/'); 762 762 Win32DllBase::renameDll(szModname); 763 strupr(szModname);764 763 765 764 if (!fPath) 766 765 { 767 char 766 char szModName2[CCHMAXPATH]; 768 767 strcpy(szModName2, szModname); 769 768 if (!Win32ImageBase::findDll(szModName2, szModname, sizeof(szModname))) … … 1125 1124 return ERROR_NOT_ENOUGH_MEMORY; 1126 1125 } 1127 strcpy((char *)pszCmdLineA, pszPeExe);1126 strcpy((char *)pszCmdLineA, pszPeExe); 1128 1127 1129 1128 rc = NO_ERROR; … … 1464 1463 //NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e. 1465 1464 // very.weird.exe) 1465 // 1466 // hinst = LoadLibrary("WINSPOOL.DRV"); -> succeeds 1467 // hinst2 = GetModuleHandle("WINSPOOL.DRV"); -> succeeds 1468 // hinst3 = GetModuleHandle("WINSPOOL."); -> fails 1469 // hinst4 = GetModuleHandle("WINSPOOL"); -> fails 1470 // hinst = LoadLibrary("KERNEL32.DLL"); -> succeeds 1471 // hinst2 = GetModuleHandle("KERNEL32.DLL"); -> succeeds 1472 // hinst3 = GetModuleHandle("KERNEL32."); -> fails 1473 // hinst4 = GetModuleHandle("KERNEL32"); -> succeeds 1474 // Same behaviour as observed in NT4, SP6 1466 1475 //****************************************************************************** 1467 1476 HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule) … … 1470 1479 Win32DllBase *windll; 1471 1480 char szModule[CCHMAXPATH]; 1472 BOOL fDllModule = FALSE; 1473 1474 if(lpszModule == NULL) { 1475 if(WinExe) 1481 char *dot; 1482 1483 if(lpszModule == NULL) 1484 { 1485 if(WinExe) 1486 hMod = WinExe->getInstanceHandle(); 1487 else hMod = -1; 1488 } 1489 else 1490 { 1491 strcpy(szModule, OSLibStripPath((char *)lpszModule)); 1492 strupr(szModule); 1493 dot = strchr(szModule, '.'); 1494 if(dot == NULL) { 1495 //if no extension -> add .DLL (see SDK docs) 1496 strcat(szModule, DLL_EXTENSION); 1497 } 1498 else { 1499 if(dot[1] == 0) { 1500 //a trailing dot means the module has no extension (SDK docs) 1501 *dot = 0; 1502 } 1503 } 1504 if(WinExe && WinExe->matchModName(szModule)) { 1476 1505 hMod = WinExe->getInstanceHandle(); 1477 else hMod = -1; 1478 } 1479 else 1480 { 1481 strcpy(szModule, OSLibStripPath((char *)lpszModule)); 1482 strupr(szModule); 1483 if(strstr(szModule, ".DLL")) { 1484 fDllModule = TRUE; 1485 } 1486 else { 1487 if(!strstr(szModule, ".")) { 1488 //if there's no extension or trainling dot, we 1489 //assume it's a dll (see Win32 SDK docs) 1490 fDllModule = TRUE; 1491 } 1492 } 1493 char *dot = strstr(szModule, "."); 1494 if(dot) 1495 *dot = 0; 1496 1497 if(!fDllModule && WinExe && WinExe->matchModName(szModule)) { 1498 hMod = WinExe->getInstanceHandle(); 1499 } 1500 else { 1501 windll = Win32DllBase::findModule(szModule); 1502 if(windll) { 1503 hMod = windll->getInstanceHandle(); 1504 } 1505 } 1506 } 1507 1508 dprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod)); 1509 return(hMod); 1506 } 1507 else { 1508 windll = Win32DllBase::findModule(szModule); 1509 if(windll) { 1510 hMod = windll->getInstanceHandle(); 1511 } 1512 } 1513 } 1514 dprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod)); 1515 return(hMod); 1510 1516 } 1511 1517 //****************************************************************************** … … 1605 1611 } 1606 1612 if(szAppName[0] == '"') { 1607 exename = &szAppName[1];1613 exename = &szAppName[1]; 1608 1614 } 1609 1615 else exename = szAppName; 1610 1616 1611 1617 if(GetFileAttributesA(exename) == -1) { 1612 dprintf(("CreateProcess: can't find executable!"));1613 SetLastError(ERROR_FILE_NOT_FOUND);1614 return FALSE;1618 dprintf(("CreateProcess: can't find executable!")); 1619 SetLastError(ERROR_FILE_NOT_FOUND); 1620 return FALSE; 1615 1621 } 1616 1622 dprintf(("KERNEL32: CreateProcess %s\n", cmdline)); … … 1619 1625 // lpCurrentDirectory ourselves. (Open32 ignores it!) 1620 1626 if(lpCurrentDirectory) { 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;1627 char *newcmdline; 1628 1629 newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(cmdline) + 32); 1630 sprintf(newcmdline, "PE.EXE /OPT:[CURDIR=%s] %s", lpCurrentDirectory, cmdline); 1631 free(cmdline); 1632 cmdline = newcmdline; 1627 1633 } 1628 1634 else { 1629 char *newcmdline;1630 1631 newcmdline = (char *)malloc(strlen(cmdline) + 16);1632 sprintf(newcmdline, "PE.EXE %s", cmdline);1633 free(cmdline);1634 cmdline = newcmdline;1635 char *newcmdline; 1636 1637 newcmdline = (char *)malloc(strlen(cmdline) + 16); 1638 sprintf(newcmdline, "PE.EXE %s", cmdline); 1639 free(cmdline); 1640 cmdline = newcmdline; 1635 1641 } 1636 1642 rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline,lpProcessAttributes, … … 1828 1834 Win32ImageBase *winimage; 1829 1835 HINSTANCE hDll; 1830 1831 dprintf(("GetVersionStruct of module %s %x %d", lpszModName, verstruct, bufLength)); 1832 if(verstruct == NULL) { 1833 SetLastError(ERROR_INVALID_PARAMETER); 1834 return FALSE; 1835 } 1836 if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) 1837 { 1838 winimage = (Win32ImageBase *)WinExe; 1839 } 1840 else 1841 { 1842 winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName); 1843 if(winimage == NULL) 1844 { 1845 char modname[CCHMAXPATH]; 1846 1847 strcpy(modname, lpszModName); 1848 //rename dll if necessary (i.e. OLE32 -> OLE32OS2) 1849 Win32DllBase::renameDll(modname); 1850 1851 if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS) 1852 { 1853 HINSTANCE hInstance; 1854 1855 //must be an LX dll, just load it (app will probably load it anyway) 1856 hInstance = LoadLibraryA(modname); 1857 if(hInstance == 0) 1858 return 0; 1859 1860 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance); 1861 if(winimage) { 1862 return winimage->getVersionStruct(verstruct, bufLength); 1863 } 1864 dprintf(("GetVersionStruct; just loaded dll %s, but can't find it now!", modname)); 1865 return 0; 1866 } 1867 BOOL rc = FALSE; 1868 1869 hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE); 1870 if(hDll == 0) 1871 return 0; 1872 1873 winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName); 1874 if(winimage != NULL) { 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); 1879 return rc; 1880 } 1881 } 1882 return winimage->getVersionStruct(verstruct, bufLength); 1836 BOOL rc = FALSE; 1837 1838 dprintf(("GetVersionStruct of module %s %x %d", lpszModName, verstruct, bufLength)); 1839 if(verstruct == NULL) { 1840 SetLastError(ERROR_INVALID_PARAMETER); 1841 return FALSE; 1842 } 1843 if (WinExe != NULL && WinExe->matchModName(lpszModName)) { 1844 return WinExe->getVersionStruct(verstruct, bufLength); 1845 } 1846 hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE); 1847 if(hDll == 0) { 1848 dprintf(("ERROR: GetVersionStruct: Unable to load module!!")); 1849 return 0; 1850 } 1851 winimage = (Win32ImageBase *)Win32DllBase::findModule(hDll); 1852 if(winimage != NULL) { 1853 rc = winimage->getVersionStruct(verstruct, bufLength); 1854 } 1855 else { 1856 dprintf(("GetVersionStruct; just loaded dll %s, but can't find it now!", lpszModName)); 1857 DebugInt3(); 1858 } 1859 FreeLibrary(hDll); 1860 return rc; 1883 1861 } 1884 1862 //****************************************************************************** … … 1888 1866 Win32ImageBase *winimage; 1889 1867 HINSTANCE hDll; 1890 1891 dprintf(("GetVersionSize of %s\n", lpszModName)); 1892 1893 if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) { 1894 winimage = (Win32ImageBase *)WinExe; 1895 } 1896 else { 1897 winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName); 1898 if(winimage == NULL) 1899 { 1900 char modname[CCHMAXPATH]; 1901 1902 strcpy(modname, lpszModName); 1903 //rename dll if necessary (i.e. OLE32 -> OLE32OS2) 1904 Win32DllBase::renameDll(modname); 1905 1906 if(Win32ImageBase::isPEImage(modname) != ERROR_SUCCESS) 1907 { 1908 HINSTANCE hInstance; 1909 1910 //must be an LX dll, just load it (app will probably load it anyway) 1911 hInstance = LoadLibraryA(modname); 1912 if(hInstance == 0) 1913 return 0; 1914 1915 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance); 1916 if(winimage) { 1917 return winimage->getVersionSize(); 1918 } 1919 dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", modname)); 1920 return 0; 1921 } 1922 int size = 0; 1923 1924 hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE); 1925 if(hDll == 0) 1926 return 0; 1927 1928 winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName); 1929 if(winimage != NULL) { 1930 size = winimage->getVersionSize(); 1931 } 1932 else dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName)); 1868 ULONG size = 0; 1869 1870 dprintf(("GetVersionSize of %s", lpszModName)); 1871 if (WinExe != NULL && WinExe->matchModName(lpszModName)) { 1872 return WinExe->getVersionSize(); 1873 } 1874 1875 hDll = LoadLibraryExA(lpszModName, 0, LOAD_LIBRARY_AS_DATAFILE); 1876 if(hDll == 0) { 1877 dprintf(("ERROR: GetVersionStruct: Unable to load module!!")); 1878 return 0; 1879 } 1880 winimage = (Win32ImageBase *)Win32DllBase::findModule(hDll); 1881 if(winimage != NULL) { 1882 size = winimage->getVersionSize(); 1883 } 1884 else { 1885 dprintf(("GetVersionSize; just loaded dll %s, but can't find it now!", lpszModName)); 1886 DebugInt3(); 1887 } 1933 1888 FreeLibrary(hDll); 1934 return size; 1935 } 1936 } 1937 return winimage->getVersionSize(); 1889 return size; 1938 1890 } 1939 1891 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.