From 05637a5e3d83d355962c434eeeb2e0333054a898 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Tue, 13 Sep 2022 20:46:51 +0200 Subject: [PATCH] [MSI] Abuse SE_DynamicShim until we have proper shims integration CORE-18362 --- dll/win32/msi/CMakeLists.txt | 2 +- dll/win32/msi/package.c | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/dll/win32/msi/CMakeLists.txt b/dll/win32/msi/CMakeLists.txt index 56fcc80cb25..82874b70b46 100644 --- a/dll/win32/msi/CMakeLists.txt +++ b/dll/win32/msi/CMakeLists.txt @@ -86,7 +86,7 @@ set_source_files_properties(msi.rc PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BI set_module_type(msi win32dll) target_link_libraries(msi uuid ${PSEH_LIB} wine_dll_register oldnames) add_dependencies(msi msi_idlheader) -add_delay_importlibs(msi odbccp32 crypt32 wintrust) +add_delay_importlibs(msi odbccp32 crypt32 wintrust apphelp) add_importlibs(msi advapi32 advapi32_vista cabinet comctl32 gdi32 ole32 oleaut32 shell32 shlwapi rpcrt4 urlmon user32 version wininet sxs #FIXME : imagehlp, mspatcha should be in delayed imports imagehlp diff --git a/dll/win32/msi/package.c b/dll/win32/msi/package.c index 3095026003e..b87132494bd 100644 --- a/dll/win32/msi/package.c +++ b/dll/win32/msi/package.c @@ -1330,6 +1330,58 @@ UINT msi_set_original_database_property( MSIDATABASE *db, const WCHAR *package ) return r; } +#ifdef __REACTOS__ +BOOL WINAPI ApphelpCheckRunAppEx(HANDLE FileHandle, PVOID Unk1, PVOID Unk2, PCWSTR ApplicationName, PVOID Environment, USHORT ExeType, PULONG Reason, PVOID *SdbQueryAppCompatData, PULONG SdbQueryAppCompatDataSize, + PVOID *SxsData, PULONG SxsDataSize, PULONG FusionFlags, PULONG64 SomeFlag1, PULONG SomeFlag2); +BOOL WINAPI SE_DynamicShim(LPCWSTR ProcessImage, PVOID hsdb, PVOID pQueryResult, LPCSTR Module, LPDWORD lpdwDynamicToken); +PVOID WINAPI SdbInitDatabase(DWORD flags, LPCWSTR path); +PVOID WINAPI SdbReleaseDatabase(PVOID hsdb); + +#define HID_DOS_PATHS 0x1 +#define SDB_DATABASE_MAIN_SHIM 0x80030000 + +#define APPHELP_VALID_RESULT 0x10000 +#define APPHELP_RESULT_FOUND 0x40000 + +static void +AppHelpCheckPackage(LPCWSTR szPackage) +{ + USHORT ExeType = 0; + ULONG Reason = 0; + + PVOID QueryResult = NULL; + ULONG QueryResultSize = 0; + + HANDLE Handle = NULL; + BOOL Continue = ApphelpCheckRunAppEx( + Handle, NULL, NULL, szPackage, NULL, ExeType, &Reason, &QueryResult, &QueryResultSize, NULL, + NULL, NULL, NULL, NULL); + + if (Continue) + { + if ((Reason & (APPHELP_VALID_RESULT | APPHELP_RESULT_FOUND)) == (APPHELP_VALID_RESULT | APPHELP_RESULT_FOUND)) + { + DWORD dwToken; + PVOID hsdb = SdbInitDatabase(HID_DOS_PATHS | SDB_DATABASE_MAIN_SHIM, NULL); + if (hsdb) + { + BOOL bShim = SE_DynamicShim(szPackage, hsdb, QueryResult, "msi.dll", &dwToken); + ERR("ReactOS HACK: Used SE_DynamicShim %d!\n", bShim); + + SdbReleaseDatabase(hsdb); + } + else + { + ERR("Unable to open SDB_DATABASE_MAIN_SHIM\n"); + } + } + } + + if (QueryResult) + RtlFreeHeap(RtlGetProcessHeap(), 0, QueryResult); +} +#endif + UINT MSI_OpenPackageW(LPCWSTR szPackage, DWORD dwOptions, MSIPACKAGE **pPackage) { MSIDATABASE *db; @@ -1368,6 +1420,10 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, DWORD dwOptions, MSIPACKAGE **pPackage) file = cachefile; } +#ifdef __REACTOS__ + AppHelpCheckPackage(file); +#endif + r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db ); if (r != ERROR_SUCCESS) {