- Timestamp:
- Jun 10, 2020 10:43:44 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kWorker/kWorker.c
r3368 r3369 5723 5723 if (!kHlpIsFilenameOnly(pszFilename)) 5724 5724 pMod = kwLdrModuleTryLoadDll(pszFilename, KWLOCATION_UNKNOWN, g_Sandbox.pTool->u.Sandboxed.pExe, pszSearchPath); 5725 #if 1 /* HACK ALERT! We run into trouble with a 2nd mspdb140.dll instance (x64 + x86), so use the one already loaded. A call 5726 * to NdrClientCall2 at ConnectToServer+0x426 fails with E_INVALIDARG. Problems with multiple connections from same PID? */ 5727 else if ( strcmp(pszFilename, "mspdb140.dll") == 0 5728 && GetModuleHandleA(pszFilename) != NULL) 5729 { 5730 pMod = kwLdrModuleForLoadedNativeByHandle(GetModuleHandleA(pszFilename), K_FALSE, pszFilename); 5731 KWLDR_LOG(("LoadLibraryExA: mspdb140 hack: pMod=%p\n", pMod)); 5732 } 5733 #endif 5725 5734 else 5726 5735 { … … 5772 5781 * We may have to help resolved unqualified DLLs living in the executable directory. 5773 5782 */ 5774 if (kHlpIsFilenameOnly(pszFilename)) 5775 { 5776 KSIZE cchFilename = kHlpStrLen(pszFilename); 5777 KSIZE cchExePath = g_Sandbox.pTool->u.Sandboxed.pExe->offFilename; 5778 if (cchExePath + cchFilename + 1 <= sizeof(szPath)) 5779 { 5780 kHlpMemCopy(szPath, g_Sandbox.pTool->u.Sandboxed.pExe->pszPath, cchExePath); 5781 kHlpMemCopy(&szPath[cchExePath], pszFilename, cchFilename + 1); 5782 if (kwFsPathExists(szPath)) 5783 { 5784 KWLDR_LOG(("kwSandbox_Kernel32_Native_LoadLibraryExA: %s -> %s\n", pszFilename, szPath)); 5785 pszFilename = szPath; 5786 } 5787 } 5788 5789 if (pszFilename != szPath) 5790 { 5791 KSIZE cchSuffix = 0; 5792 KBOOL fNeedSuffix = K_FALSE; 5793 const char *pszCur = kwSandboxDoGetEnvA(&g_Sandbox, "PATH", 4); 5794 kHlpAssert(pszCur); 5795 if (pszCur) 5796 { 5797 while (*pszCur != '\0') 5783 if ( kHlpIsFilenameOnly(pszFilename) 5784 && g_Sandbox.pTool 5785 && g_Sandbox.pTool->u.Sandboxed.pExe) 5786 { 5787 KSIZE const cchFilename = kHlpStrLen(pszFilename); 5788 #define MY_IMATCH(a_szName) (cchFilename == sizeof(a_szName) - 1 && kHlpStrICompAscii(pszFilename, a_szName) == 0) 5789 if ( !kwLdrIsVirtualApiModule(pszFilename, cchFilename) 5790 && !MY_IMATCH("ntdll") 5791 && !MY_IMATCH("kernel32") 5792 && !MY_IMATCH("ntdll.dll") 5793 && !MY_IMATCH("kernelbase") 5794 && !MY_IMATCH("kernel32.dll") 5795 && !MY_IMATCH("kernelbase.dll") 5796 ) 5797 #undef MY_IMATCH 5798 { 5799 KSIZE cchExePath = g_Sandbox.pTool->u.Sandboxed.pExe->offFilename; 5800 if (cchExePath + cchFilename + 1 <= sizeof(szPath)) 5801 { 5802 kHlpMemCopy(szPath, g_Sandbox.pTool->u.Sandboxed.pExe->pszPath, cchExePath); 5803 kHlpMemCopy(&szPath[cchExePath], pszFilename, cchFilename + 1); 5804 if (kwFsPathExists(szPath)) 5798 5805 { 5799 /* Find the end of the component */ 5800 KSIZE cch = 0; 5801 while (pszCur[cch] != ';' && pszCur[cch] != '\0') 5802 cch++; 5803 5804 if ( cch > 0 /* wrong, but whatever */ 5805 && cch + 1 + cchFilename + cchSuffix < sizeof(szPath)) 5806 KWLDR_LOG(("kwSandbox_Kernel32_Native_LoadLibraryExA: %s -> %s\n", pszFilename, szPath)); 5807 pszFilename = szPath; 5808 } 5809 } 5810 5811 if (pszFilename != szPath) 5812 { 5813 KSIZE cchSuffix = 0; 5814 KBOOL fNeedSuffix = K_FALSE; 5815 const char *pszCur = kwSandboxDoGetEnvA(&g_Sandbox, "PATH", 4); 5816 kHlpAssert(pszCur); 5817 if (pszCur) 5818 { 5819 while (*pszCur != '\0') 5806 5820 { 5807 char *pszDst = kHlpMemPCopy(szPath, pszCur, cch); 5808 if ( szPath[cch - 1] != ':' 5809 && szPath[cch - 1] != '/' 5810 && szPath[cch - 1] != '\\') 5811 *pszDst++ = '\\'; 5812 pszDst = kHlpMemPCopy(pszDst, pszFilename, cchFilename); 5813 if (fNeedSuffix) 5814 pszDst = kHlpMemPCopy(pszDst, ".dll", 4); 5815 *pszDst = '\0'; 5816 5817 if (kwFsPathExists(szPath)) 5821 /* Find the end of the component */ 5822 KSIZE cch = 0; 5823 while (pszCur[cch] != ';' && pszCur[cch] != '\0') 5824 cch++; 5825 5826 if ( cch > 0 /* wrong, but whatever */ 5827 && cch + 1 + cchFilename + cchSuffix < sizeof(szPath)) 5818 5828 { 5819 KWLDR_LOG(("kwSandbox_Kernel32_Native_LoadLibraryExA: %s -> %s\n", pszFilename, szPath)); 5820 pszFilename = szPath; 5821 break; 5829 char *pszDst = kHlpMemPCopy(szPath, pszCur, cch); 5830 if ( szPath[cch - 1] != ':' 5831 && szPath[cch - 1] != '/' 5832 && szPath[cch - 1] != '\\') 5833 *pszDst++ = '\\'; 5834 pszDst = kHlpMemPCopy(pszDst, pszFilename, cchFilename); 5835 if (fNeedSuffix) 5836 pszDst = kHlpMemPCopy(pszDst, ".dll", 4); 5837 *pszDst = '\0'; 5838 5839 if (kwFsPathExists(szPath)) 5840 { 5841 KWLDR_LOG(("kwSandbox_Kernel32_Native_LoadLibraryExA: %s -> %s\n", pszFilename, szPath)); 5842 pszFilename = szPath; 5843 break; 5844 } 5822 5845 } 5846 5847 /* Advance */ 5848 pszCur += cch; 5849 while (*pszCur == ';') 5850 pszCur++; 5823 5851 } 5824 5825 /* Advance */5826 pszCur += cch;5827 while (*pszCur == ';')5828 pszCur++;5829 5852 } 5830 5853 } … … 5833 5856 5834 5857 return LoadLibraryExA(pszFilename, hFile, fFlags); 5858 } 5859 5860 5861 /** Kernel32 - LoadLibraryExW() for native overloads */ 5862 static HMODULE WINAPI kwSandbox_Kernel32_Native_LoadLibraryExW(LPCWSTR pwszFilename, HANDLE hFile, DWORD fFlags) 5863 { 5864 char szTmp[4096]; 5865 KSIZE cchTmp = kwUtf16ToStr(pwszFilename, szTmp, sizeof(szTmp)); 5866 if (cchTmp < sizeof(szTmp)) 5867 return kwSandbox_Kernel32_Native_LoadLibraryExA(szTmp, hFile, fFlags); 5868 5869 KWFS_TODO(); 5870 SetLastError(ERROR_FILENAME_EXCED_RANGE); 5871 return NULL; 5835 5872 } 5836 5873 … … 6285 6322 return GetProcAddress(hmod, pszProc); 6286 6323 } 6324 6325 6326 #ifndef NDEBUG 6327 /** Kernel32 - GetProcAddress() - native replacement for debugging only. */ 6328 static FARPROC WINAPI kwSandbox_Kernel32_Native_GetProcAddress(HMODULE hmod, LPCSTR pszProc) 6329 { 6330 FARPROC pfnRet = GetProcAddress(hmod, pszProc); 6331 KWLDR_LOG(("kwSandbox_Kernel32_Native_GetProcAddress(%p, %s) -> %p\n", hmod, pszProc, pfnRet)); 6332 return pfnRet; 6333 } 6334 #endif 6287 6335 6288 6336 … … 10780 10828 { TUPLE("TerminateProcess"), NULL, (KUPTR)kwSandbox_Kernel32_TerminateProcess }, 10781 10829 10830 { TUPLE("GetCommandLineA"), NULL, (KUPTR)kwSandbox_Kernel32_GetCommandLineA }, 10831 { TUPLE("GetCommandLineW"), NULL, (KUPTR)kwSandbox_Kernel32_GetCommandLineW }, 10832 10782 10833 #if 0 10783 10834 { TUPLE("CreateThread"), NULL, (KUPTR)kwSandbox_Kernel32_CreateThread }, … … 10814 10865 { TUPLE("SetConsoleCtrlHandler"), NULL, (KUPTR)kwSandbox_Kernel32_SetConsoleCtrlHandler }, 10815 10866 { TUPLE("LoadLibraryExA"), NULL, (KUPTR)kwSandbox_Kernel32_Native_LoadLibraryExA }, 10867 { TUPLE("LoadLibraryExW"), NULL, (KUPTR)kwSandbox_Kernel32_Native_LoadLibraryExW }, 10868 #ifndef NDEBUG 10869 { TUPLE("GetProcAddress"), NULL, (KUPTR)kwSandbox_Kernel32_Native_GetProcAddress }, 10870 #endif 10816 10871 10817 10872 #ifdef WITH_CONSOLE_OUTPUT_BUFFERING
Note:
See TracChangeset
for help on using the changeset viewer.