From eb18696e725c78261ae6504e5fac9aaf8e56d15a Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sat, 2 Aug 2025 23:26:27 +0200 Subject: [PATCH] [APPHELP] Add basic support for wildcard matching CORE-20159 --- dll/appcompat/apphelp/hsdb.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/dll/appcompat/apphelp/hsdb.c b/dll/appcompat/apphelp/hsdb.c index 9e2726d905e..a491ef3637e 100644 --- a/dll/appcompat/apphelp/hsdb.c +++ b/dll/appcompat/apphelp/hsdb.c @@ -4,7 +4,7 @@ * PURPOSE: Shim matching / data (un)packing * COPYRIGHT: Copyright 2011 André Hentschel * Copyright 2013 Mislav Blaževic - * Copyright 2015-2019 Mark Jansen (mark.jansen@reactos.org) + * Copyright 2015-2025 Mark Jansen */ #define WIN32_NO_STATUS @@ -508,18 +508,28 @@ BOOL WINAPI SdbGetMatchingExe(HSDB hsdb, LPCWSTR path, LPCWSTR module_name, goto Cleanup; } - /* EXE is list TAG which contains data required to match executable */ - iter = SdbFindFirstTag(pdb, database, TAG_EXE); + /* + * Instead of brute-force searching the 'entire' DB, we should: + * 1. Iterate over the Index TAG_EXE.TAG_WILDCARD_NAME + * 2. Search the index TAG_EXE.TAG_NAME (fallback to SdbFindFirstNamedTag) + * 3. Search the index TAG_EXE.TAG_16BIT_MODULE_NAME (fallback to SdbFindFirstNamedTag) + */ - /* Search for entry in database, we should look into indexing tags! */ - while (iter != TAGID_NULL) + + /* EXE is list TAG which contains data required to match executable */ + for (iter = SdbFindFirstTag(pdb, database, TAG_EXE); iter != TAGID_NULL; iter = SdbFindNextTag(pdb, database, iter)) { - LPWSTR foundName; - /* Check if exe name matches */ name = SdbFindFirstTag(pdb, iter, TAG_NAME); + LPWSTR foundName = SdbGetStringTagPtr(pdb, name); /* If this is a malformed DB, (no TAG_NAME), we should not crash. */ - foundName = SdbGetStringTagPtr(pdb, name); - if (foundName && !_wcsicmp(foundName, file_name)) + if (!foundName) + continue; + + /* We only support full wildcard names for now */ + BOOL isWildcard = foundName[0] == '*' && foundName[1] == UNICODE_NULL; + + /* Check if exe name matches */ + if (isWildcard || !_wcsicmp(foundName, file_name)) { /* Get information about executable required to match it with database entry */ if (!attribs) @@ -536,9 +546,6 @@ BOOL WINAPI SdbGetMatchingExe(HSDB hsdb, LPCWSTR path, LPCWSTR module_name, SdbpAddExeMatch(hsdb, pdb, iter, result); } } - - /* Continue iterating */ - iter = SdbFindNextTag(pdb, database, iter); } /* Restore the full path. */