Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/kernelbase/kernelbase.spec | 12 +- dlls/kernelbase/path.c | 403 ++++++++++++++++++++++++++++++++ 2 files changed, 409 insertions(+), 6 deletions(-)
diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index 193af89b43..7f48169745 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -771,7 +771,7 @@ @ stdcall GlobalMemoryStatusEx(ptr) kernel32.GlobalMemoryStatusEx # @ stub GuardCheckLongJumpTarget # @ stub HasPolicyForegroundProcessingCompletedInternal -@ stdcall HashData(ptr long ptr long) shlwapi.HashData +@ stdcall HashData(ptr long ptr long) @ stdcall HeapAlloc(long long long) kernel32.HeapAlloc @ stdcall HeapCompact(long long) kernel32.HeapCompact @ stdcall HeapCreate(long long long) kernel32.HeapCreate @@ -861,7 +861,7 @@ # @ stub IsDeveloperModePolicyApplied # @ stub IsEnclaveTypeSupported # @ stub IsGlobalizationUserSettingsKeyRedirected -@ stdcall IsInternetESCEnabled() shlwapi.IsInternetESCEnabled +@ stdcall IsInternetESCEnabled() @ stub IsNLSDefinedString @ stdcall IsNormalizedString(long wstr long) kernel32.IsNormalizedString # @ stub IsProcessCritical @@ -1632,8 +1632,8 @@ @ stdcall UrlApplySchemeW(wstr ptr ptr long) @ stdcall UrlCanonicalizeA(str ptr ptr long) @ stdcall UrlCanonicalizeW(wstr ptr ptr long) -@ stdcall UrlCombineA(str str ptr ptr long) shlwapi.UrlCombineA -@ stdcall UrlCombineW(wstr wstr ptr ptr long) shlwapi.UrlCombineW +@ stdcall UrlCombineA(str str ptr ptr long) +@ stdcall UrlCombineW(wstr wstr ptr ptr long) @ stdcall UrlCompareA(str str long) @ stdcall UrlCompareW(wstr wstr long) @ stdcall UrlCreateFromPathA(str ptr ptr long) @@ -1645,8 +1645,8 @@ @ stdcall UrlGetLocationW(wstr) @ stdcall UrlGetPartA(str ptr ptr long long) @ stdcall UrlGetPartW(wstr ptr ptr long long) -@ stdcall UrlHashA(str ptr long) shlwapi.UrlHashA -@ stdcall UrlHashW(wstr ptr long) shlwapi.UrlHashW +@ stdcall UrlHashA(str ptr long) +@ stdcall UrlHashW(wstr ptr long) @ stdcall UrlIsA(str long) @ stdcall UrlIsNoHistoryA(str) @ stdcall UrlIsNoHistoryW(wstr) diff --git a/dlls/kernelbase/path.c b/dlls/kernelbase/path.c index 76f8610956..767ae43d5a 100644 --- a/dlls/kernelbase/path.c +++ b/dlls/kernelbase/path.c @@ -36,6 +36,26 @@ WINE_DEFAULT_DEBUG_CHANNEL(path);
static const char hexDigits[] = "0123456789ABCDEF";
+static const unsigned char hashdata_lookup[256] = +{ + 0x01, 0x0e, 0x6e, 0x19, 0x61, 0xae, 0x84, 0x77, 0x8a, 0xaa, 0x7d, 0x76, 0x1b, 0xe9, 0x8c, 0x33, + 0x57, 0xc5, 0xb1, 0x6b, 0xea, 0xa9, 0x38, 0x44, 0x1e, 0x07, 0xad, 0x49, 0xbc, 0x28, 0x24, 0x41, + 0x31, 0xd5, 0x68, 0xbe, 0x39, 0xd3, 0x94, 0xdf, 0x30, 0x73, 0x0f, 0x02, 0x43, 0xba, 0xd2, 0x1c, + 0x0c, 0xb5, 0x67, 0x46, 0x16, 0x3a, 0x4b, 0x4e, 0xb7, 0xa7, 0xee, 0x9d, 0x7c, 0x93, 0xac, 0x90, + 0xb0, 0xa1, 0x8d, 0x56, 0x3c, 0x42, 0x80, 0x53, 0x9c, 0xf1, 0x4f, 0x2e, 0xa8, 0xc6, 0x29, 0xfe, + 0xb2, 0x55, 0xfd, 0xed, 0xfa, 0x9a, 0x85, 0x58, 0x23, 0xce, 0x5f, 0x74, 0xfc, 0xc0, 0x36, 0xdd, + 0x66, 0xda, 0xff, 0xf0, 0x52, 0x6a, 0x9e, 0xc9, 0x3d, 0x03, 0x59, 0x09, 0x2a, 0x9b, 0x9f, 0x5d, + 0xa6, 0x50, 0x32, 0x22, 0xaf, 0xc3, 0x64, 0x63, 0x1a, 0x96, 0x10, 0x91, 0x04, 0x21, 0x08, 0xbd, + 0x79, 0x40, 0x4d, 0x48, 0xd0, 0xf5, 0x82, 0x7a, 0x8f, 0x37, 0x69, 0x86, 0x1d, 0xa4, 0xb9, 0xc2, + 0xc1, 0xef, 0x65, 0xf2, 0x05, 0xab, 0x7e, 0x0b, 0x4a, 0x3b, 0x89, 0xe4, 0x6c, 0xbf, 0xe8, 0x8b, + 0x06, 0x18, 0x51, 0x14, 0x7f, 0x11, 0x5b, 0x5c, 0xfb, 0x97, 0xe1, 0xcf, 0x15, 0x62, 0x71, 0x70, + 0x54, 0xe2, 0x12, 0xd6, 0xc7, 0xbb, 0x0d, 0x20, 0x5e, 0xdc, 0xe0, 0xd4, 0xf7, 0xcc, 0xc4, 0x2b, + 0xf9, 0xec, 0x2d, 0xf4, 0x6f, 0xb6, 0x99, 0x88, 0x81, 0x5a, 0xd9, 0xca, 0x13, 0xa5, 0xe7, 0x47, + 0xe6, 0x8e, 0x60, 0xe3, 0x3e, 0xb3, 0xf6, 0x72, 0xa2, 0x35, 0xa0, 0xd7, 0xcd, 0xb4, 0x2f, 0x6d, + 0x2c, 0x26, 0x1f, 0x95, 0x87, 0x00, 0xd8, 0x34, 0x3f, 0x17, 0x25, 0x45, 0x27, 0x75, 0x92, 0xb8, + 0xa3, 0xc8, 0xde, 0xeb, 0xf8, 0xf3, 0xdb, 0x0a, 0x98, 0x83, 0x7b, 0xe5, 0xcb, 0x4c, 0x78, 0xd1, +}; + struct parsed_url { const WCHAR *scheme; /* [out] start of scheme */ @@ -4699,3 +4719,386 @@ HRESULT WINAPI UrlCreateFromPathW(const WCHAR *path, WCHAR *url, DWORD *url_len,
return hr; } + +HRESULT WINAPI UrlCombineA(const char *base, const char *relative, char *combined, DWORD *combined_len, DWORD flags) +{ + WCHAR *baseW, *relativeW, *combinedW; + DWORD len, len2; + HRESULT hr; + + TRACE("%s, %s, %d, %#x\n", debugstr_a(base), debugstr_a(relative), combined_len ? *combined_len : 0, flags); + + if (!base || !relative || !combined_len) + return E_INVALIDARG; + + baseW = heap_alloc(3 * INTERNET_MAX_URL_LENGTH * sizeof(WCHAR)); + relativeW = baseW + INTERNET_MAX_URL_LENGTH; + combinedW = relativeW + INTERNET_MAX_URL_LENGTH; + + MultiByteToWideChar(CP_ACP, 0, base, -1, baseW, INTERNET_MAX_URL_LENGTH); + MultiByteToWideChar(CP_ACP, 0, relative, -1, relativeW, INTERNET_MAX_URL_LENGTH); + len = *combined_len; + + hr = UrlCombineW(baseW, relativeW, combined ? combinedW : NULL, &len, flags); + if (hr != S_OK) + { + *combined_len = len; + heap_free(baseW); + return hr; + } + + len2 = WideCharToMultiByte(CP_ACP, 0, combinedW, len, NULL, 0, NULL, NULL); + if (len2 > *combined_len) + { + *combined_len = len2; + heap_free(baseW); + return E_POINTER; + } + WideCharToMultiByte(CP_ACP, 0, combinedW, len+1, combined, *combined_len + 1, NULL, NULL); + *combined_len = len2; + heap_free(baseW); + return S_OK; +} + +HRESULT WINAPI UrlCombineW(const WCHAR *baseW, const WCHAR *relativeW, WCHAR *combined, DWORD *combined_len, DWORD flags) +{ + static const WCHAR myfilestr[] = {'f','i','l','e',':','/','/','/','\0'}; + static const WCHAR fragquerystr[] = {'#','?',0}; + DWORD i, len, process_case = 0, myflags, sizeloc = 0; + LPWSTR work, preliminary, mbase, mrelative; + PARSEDURLW base, relative; + HRESULT hr; + + TRACE("%s, %s, %d, %#x\n", debugstr_w(baseW), debugstr_w(relativeW), combined_len ? *combined_len : 0, flags); + + if (!baseW || !relativeW || !combined_len) + return E_INVALIDARG; + + base.cbSize = sizeof(base); + relative.cbSize = sizeof(relative); + + /* Get space for duplicates of the input and the output */ + preliminary = heap_alloc(3 * INTERNET_MAX_URL_LENGTH * sizeof(WCHAR)); + mbase = preliminary + INTERNET_MAX_URL_LENGTH; + mrelative = mbase + INTERNET_MAX_URL_LENGTH; + *preliminary = '\0'; + + /* Canonicalize the base input prior to looking for the scheme */ + myflags = flags & (URL_DONT_SIMPLIFY | URL_UNESCAPE); + len = INTERNET_MAX_URL_LENGTH; + UrlCanonicalizeW(baseW, mbase, &len, myflags); + + /* Canonicalize the relative input prior to looking for the scheme */ + len = INTERNET_MAX_URL_LENGTH; + UrlCanonicalizeW(relativeW, mrelative, &len, myflags); + + /* See if the base has a scheme */ + if (ParseURLW(mbase, &base) != S_OK) + { + /* If base has no scheme return relative. */ + TRACE("no scheme detected in Base\n"); + process_case = 1; + } + else do + { + BOOL manual_search = FALSE; + + work = (LPWSTR)base.pszProtocol; + for (i = 0; i < base.cchProtocol; ++i) + work[i] = tolowerW(work[i]); + + /* mk is a special case */ + if (base.nScheme == URL_SCHEME_MK) + { + static const WCHAR wsz[] = {':',':',0}; + WCHAR *ptr = strstrW(base.pszSuffix, wsz); + if (ptr) + { + int delta; + + ptr += 2; + delta = ptr-base.pszSuffix; + base.cchProtocol += delta; + base.pszSuffix += delta; + base.cchSuffix -= delta; + } + } + else + { + /* get size of location field (if it exists) */ + work = (LPWSTR)base.pszSuffix; + sizeloc = 0; + if (*work++ == '/') + { + if (*work++ == '/') + { + /* At this point have start of location and + * it ends at next '/' or end of string. + */ + while (*work && (*work != '/')) work++; + sizeloc = (DWORD)(work - base.pszSuffix); + } + } + } + + /* If there is a '?', then the remaining part can only contain a + * query string or fragment, so start looking for the last leaf + * from the '?'. Otherwise, if there is a '#' and the characters + * immediately preceding it are ".htm[l]", then begin looking for + * the last leaf starting from the '#'. Otherwise the '#' is not + * meaningful and just start looking from the end. */ + if ((work = strpbrkW(base.pszSuffix + sizeloc, fragquerystr))) + { + static const WCHAR htmlW[] = {'.','h','t','m','l'}; + static const WCHAR htmW[] = {'.','h','t','m'}; + + if (*work == '?' || base.nScheme == URL_SCHEME_HTTP || base.nScheme == URL_SCHEME_HTTPS) + manual_search = TRUE; + else if (work - base.pszSuffix > ARRAY_SIZE(htmW)) + { + work -= ARRAY_SIZE(htmW); + if (!strncmpiW(work, htmW, ARRAY_SIZE(htmW))) + manual_search = TRUE; + work += ARRAY_SIZE(htmW); + } + + if (!manual_search && work - base.pszSuffix > ARRAY_SIZE(htmlW)) + { + work -= ARRAY_SIZE(htmlW); + if (!strncmpiW(work, htmlW, ARRAY_SIZE(htmlW))) + manual_search = TRUE; + work += ARRAY_SIZE(htmlW); + } + } + + if (manual_search) + { + /* search backwards starting from the current position */ + while (*work != '/' && work > base.pszSuffix + sizeloc) + --work; + base.cchSuffix = work - base.pszSuffix + 1; + } + else + { + /* search backwards starting from the end of the string */ + work = strrchrW((base.pszSuffix+sizeloc), '/'); + if (work) + { + len = (DWORD)(work - base.pszSuffix + 1); + base.cchSuffix = len; + } + else + base.cchSuffix = sizeloc; + } + + /* + * At this point: + * .pszSuffix points to location (starting with '//') + * .cchSuffix length of location (above) and rest less the last + * leaf (if any) + * sizeloc length of location (above) up to but not including + * the last '/' + */ + + if (ParseURLW(mrelative, &relative) != S_OK) + { + /* No scheme in relative */ + TRACE("no scheme detected in Relative\n"); + relative.pszSuffix = mrelative; /* case 3,4,5 depends on this */ + relative.cchSuffix = strlenW(mrelative); + if (*relativeW == ':') + { + /* Case that is either left alone or uses base. */ + if (flags & URL_PLUGGABLE_PROTOCOL) + { + process_case = 5; + break; + } + process_case = 1; + break; + } + if (isalnumW(*mrelative) && *(mrelative + 1) == ':') + { + /* case that becomes "file:///" */ + strcpyW(preliminary, myfilestr); + process_case = 1; + break; + } + if (*mrelative == '/' && *(mrelative+1) == '/') + { + /* Relative has location and the rest. */ + process_case = 3; + break; + } + if (*mrelative == '/') + { + /* Relative is root to location. */ + process_case = 4; + break; + } + if (*mrelative == '#') + { + if (!(work = strchrW(base.pszSuffix+base.cchSuffix, '#'))) + work = (LPWSTR)base.pszSuffix + strlenW(base.pszSuffix); + + memcpy(preliminary, base.pszProtocol, (work-base.pszProtocol)*sizeof(WCHAR)); + preliminary[work-base.pszProtocol] = '\0'; + process_case = 1; + break; + } + process_case = (*base.pszSuffix == '/' || base.nScheme == URL_SCHEME_MK) ? 5 : 3; + break; + } + else + { + work = (LPWSTR)relative.pszProtocol; + for (i = 0; i < relative.cchProtocol; ++i) + work[i] = tolowerW(work[i]); + } + + /* Handle cases where relative has scheme. */ + if ((base.cchProtocol == relative.cchProtocol) && !strncmpW(base.pszProtocol, relative.pszProtocol, base.cchProtocol)) + { + /* since the schemes are the same */ + if (*relative.pszSuffix == '/' && *(relative.pszSuffix+1) == '/') + { + /* Relative replaces location and what follows. */ + process_case = 3; + break; + } + if (*relative.pszSuffix == '/') + { + /* Relative is root to location */ + process_case = 4; + break; + } + /* replace either just location if base's location starts with a + * slash or otherwise everything */ + process_case = (*base.pszSuffix == '/') ? 5 : 1; + break; + } + + if (*relative.pszSuffix == '/' && *(relative.pszSuffix+1) == '/') + { + /* Relative replaces scheme, location, and following and handles PLUGGABLE */ + process_case = 2; + break; + } + process_case = 1; + break; + } while (FALSE); /* a little trick to allow easy exit from nested if's */ + + hr = S_OK; + switch (process_case) + { + case 1: + /* Return relative appended to whatever is in combined (which may the string "file:///" */ + strcatW(preliminary, mrelative); + break; + + case 2: + /* Relative replaces scheme and location */ + strcpyW(preliminary, mrelative); + break; + + case 3: + /* Return the base scheme with relative. Basically keeps the scheme and replaces the domain and following. */ + memcpy(preliminary, base.pszProtocol, (base.cchProtocol + 1)*sizeof(WCHAR)); + work = preliminary + base.cchProtocol + 1; + strcpyW(work, relative.pszSuffix); + break; + + case 4: + /* Return the base scheme and location but everything after the location is relative. (Replace document from root on.) */ + memcpy(preliminary, base.pszProtocol, (base.cchProtocol+1+sizeloc)*sizeof(WCHAR)); + work = preliminary + base.cchProtocol + 1 + sizeloc; + if (flags & URL_PLUGGABLE_PROTOCOL) + *(work++) = '/'; + strcpyW(work, relative.pszSuffix); + break; + + case 5: + /* Return the base without its document (if any) and append relative after its scheme. */ + memcpy(preliminary, base.pszProtocol, (base.cchProtocol + 1 + base.cchSuffix)*sizeof(WCHAR)); + work = preliminary + base.cchProtocol + 1 + base.cchSuffix - 1; + if (*work++ != '/') + *(work++) = '/'; + strcpyW(work, relative.pszSuffix); + break; + + default: + FIXME("Unexpected case %d.\n", process_case); + hr = E_INVALIDARG; + } + + if (hr == S_OK) + { + /* Reuse mrelative as temp storage as it's already allocated and not needed anymore */ + if (*combined_len == 0) + *combined_len = 1; + hr = UrlCanonicalizeW(preliminary, mrelative, combined_len, flags & ~URL_FILE_USE_PATHURL); + if (SUCCEEDED(hr) && combined) + lstrcpyW(combined, mrelative); + + TRACE("return-%d len=%d, %s\n", process_case, *combined_len, debugstr_w(combined)); + } + + heap_free(preliminary); + return hr; +} + +HRESULT WINAPI HashData(const unsigned char *src, DWORD src_len, unsigned char *dest, DWORD dest_len) +{ + INT src_count = src_len - 1, dest_count = dest_len - 1; + + if (!src || !dest) + return E_INVALIDARG; + + while (dest_count >= 0) + { + dest[dest_count] = (dest_count & 0xff); + dest_count--; + } + + while (src_count >= 0) + { + dest_count = dest_len - 1; + while (dest_count >= 0) + { + dest[dest_count] = hashdata_lookup[src[src_count] ^ dest[dest_count]]; + dest_count--; + } + src_count--; + } + + return S_OK; +} + +HRESULT WINAPI UrlHashA(const char *url, unsigned char *dest, DWORD dest_len) +{ + if (IsBadStringPtrA(url, -1) || IsBadWritePtr(dest, dest_len)) + return E_INVALIDARG; + + HashData((const BYTE *)url, (int)strlen(url), dest, dest_len); + return S_OK; +} + +HRESULT WINAPI UrlHashW(const WCHAR *url, unsigned char *dest, DWORD dest_len) +{ + char urlA[MAX_PATH]; + + TRACE("%s, %p, %d\n", debugstr_w(url), dest, dest_len); + + if (IsBadStringPtrW(url, -1) || IsBadWritePtr(dest, dest_len)) + return E_INVALIDARG; + + WideCharToMultiByte(CP_ACP, 0, url, -1, urlA, MAX_PATH, NULL, NULL); + HashData((const BYTE *)urlA, (int)strlen(urlA), dest, dest_len); + return S_OK; +} + +BOOL WINAPI IsInternetESCEnabled(void) +{ + FIXME(": stub\n"); + return FALSE; +}
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/kernelbase/kernelbase.spec | 2 +- dlls/kernelbase/string.c | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index 7f48169745..b721d8f8c6 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -1354,7 +1354,7 @@ # @ stub SHCoCreateInstance @ stdcall SHExpandEnvironmentStringsA(str ptr long) kernel32.ExpandEnvironmentStringsA @ stdcall SHExpandEnvironmentStringsW(wstr ptr long) kernel32.ExpandEnvironmentStringsW -@ stdcall SHLoadIndirectString(wstr ptr long ptr) shlwapi.SHLoadIndirectString +@ stdcall SHLoadIndirectString(wstr ptr long ptr) # @ stub SHLoadIndirectStringInternal @ stdcall SHRegCloseUSKey(ptr) shlwapi.SHRegCloseUSKey @ stdcall SHRegCreateUSKeyA(str long long ptr long) shlwapi.SHRegCreateUSKeyA diff --git a/dlls/kernelbase/string.c b/dlls/kernelbase/string.c index 4c18acffe5..bd495bd18b 100644 --- a/dlls/kernelbase/string.c +++ b/dlls/kernelbase/string.c @@ -1426,3 +1426,51 @@ DWORD WINAPI SHTruncateString(char *str, DWORD size)
return size; } + +HRESULT WINAPI SHLoadIndirectString(const WCHAR *src, WCHAR *dst, UINT dst_len, void **reserved) +{ + WCHAR *dllname = NULL; + HMODULE hmod = NULL; + HRESULT hr = E_FAIL; + + TRACE("%s, %p, %#x, %p\n", debugstr_w(src), dst, dst_len, reserved); + + if (src[0] == '@') + { + WCHAR *index_str; + int index; + + dst[0] = 0; + dllname = StrDupW(src + 1); + index_str = strchrW(dllname, ','); + + if(!index_str) goto end; + + *index_str = 0; + index_str++; + index = atoiW(index_str); + + hmod = LoadLibraryW(dllname); + if (!hmod) goto end; + + if (index < 0) + { + if (LoadStringW(hmod, -index, dst, dst_len)) + hr = S_OK; + } + else + FIXME("can't handle non-negative indices (%d)\n", index); + } + else + { + if (dst != src) + lstrcpynW(dst, src, dst_len); + hr = S_OK; + } + + TRACE("returning %s\n", debugstr_w(dst)); +end: + if (hmod) FreeLibrary(hmod); + LocalFree(dllname); + return hr; +}
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/kernelbase/Makefile.in | 1 + dlls/kernelbase/kernelbase.spec | 38 +-- dlls/kernelbase/registry.c | 477 ++++++++++++++++++++++++++++++++ 3 files changed, 497 insertions(+), 19 deletions(-) create mode 100644 dlls/kernelbase/registry.c
diff --git a/dlls/kernelbase/Makefile.in b/dlls/kernelbase/Makefile.in index 373f79d293..229b50bc51 100644 --- a/dlls/kernelbase/Makefile.in +++ b/dlls/kernelbase/Makefile.in @@ -4,4 +4,5 @@ IMPORTS = uuid advapi32 C_SRCS = \ main.c \ path.c \ + registry.c \ string.c diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index b721d8f8c6..24d7b1772b 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -1356,31 +1356,31 @@ @ stdcall SHExpandEnvironmentStringsW(wstr ptr long) kernel32.ExpandEnvironmentStringsW @ stdcall SHLoadIndirectString(wstr ptr long ptr) # @ stub SHLoadIndirectStringInternal -@ stdcall SHRegCloseUSKey(ptr) shlwapi.SHRegCloseUSKey -@ stdcall SHRegCreateUSKeyA(str long long ptr long) shlwapi.SHRegCreateUSKeyA -@ stdcall SHRegCreateUSKeyW(wstr long long ptr long) shlwapi.SHRegCreateUSKeyW -@ stdcall SHRegDeleteEmptyUSKeyA(long str long) shlwapi.SHRegDeleteEmptyUSKeyA -@ stdcall SHRegDeleteEmptyUSKeyW(long wstr long) shlwapi.SHRegDeleteEmptyUSKeyW -@ stdcall SHRegDeleteUSValueA(long str long) shlwapi.SHRegDeleteUSValueA -@ stdcall SHRegDeleteUSValueW(long wstr long) shlwapi.SHRegDeleteUSValueW -@ stdcall SHRegEnumUSKeyA(long long str ptr long) shlwapi.SHRegEnumUSKeyA -@ stdcall SHRegEnumUSKeyW(long long wstr ptr long) shlwapi.SHRegEnumUSKeyW -@ stdcall SHRegEnumUSValueA(long long ptr ptr ptr ptr ptr long) shlwapi.SHRegEnumUSValueA -@ stdcall SHRegEnumUSValueW(long long ptr ptr ptr ptr ptr long) shlwapi.SHRegEnumUSValueW +@ stdcall SHRegCloseUSKey(ptr) +@ stdcall SHRegCreateUSKeyA(str long long ptr long) +@ stdcall SHRegCreateUSKeyW(wstr long long ptr long) +@ stdcall SHRegDeleteEmptyUSKeyA(long str long) +@ stdcall SHRegDeleteEmptyUSKeyW(long wstr long) +@ stdcall SHRegDeleteUSValueA(long str long) +@ stdcall SHRegDeleteUSValueW(long wstr long) +@ stdcall SHRegEnumUSKeyA(long long str ptr long) +@ stdcall SHRegEnumUSKeyW(long long wstr ptr long) +@ stdcall SHRegEnumUSValueA(long long ptr ptr ptr ptr ptr long) +@ stdcall SHRegEnumUSValueW(long long ptr ptr ptr ptr ptr long) @ stdcall SHRegGetBoolUSValueA(str str long long) shlwapi.SHRegGetBoolUSValueA @ stdcall SHRegGetBoolUSValueW(wstr wstr long long) shlwapi.SHRegGetBoolUSValueW @ stdcall SHRegGetUSValueA( str str ptr ptr ptr long ptr long ) shlwapi.SHRegGetUSValueA @ stdcall SHRegGetUSValueW( wstr wstr ptr ptr ptr long ptr long ) shlwapi.SHRegGetUSValueW -@ stdcall SHRegOpenUSKeyA( str long long long long ) shlwapi.SHRegOpenUSKeyA -@ stdcall SHRegOpenUSKeyW( wstr long long long long ) shlwapi.SHRegOpenUSKeyW -@ stdcall SHRegQueryInfoUSKeyA( long ptr ptr ptr ptr long ) shlwapi.SHRegQueryInfoUSKeyA -@ stdcall SHRegQueryInfoUSKeyW( long ptr ptr ptr ptr long ) shlwapi.SHRegQueryInfoUSKeyW +@ stdcall SHRegOpenUSKeyA(str long long long long) +@ stdcall SHRegOpenUSKeyW(wstr long long long long) +@ stdcall SHRegQueryInfoUSKeyA(long ptr ptr ptr ptr long) +@ stdcall SHRegQueryInfoUSKeyW(long ptr ptr ptr ptr long) @ stdcall SHRegQueryUSValueA( long str ptr ptr ptr long ptr long ) shlwapi.SHRegQueryUSValueA @ stdcall SHRegQueryUSValueW( long wstr ptr ptr ptr long ptr long ) shlwapi.SHRegQueryUSValueW -@ stdcall SHRegSetUSValueA( str str long ptr long long) shlwapi.SHRegSetUSValueA -@ stdcall SHRegSetUSValueW( wstr wstr long ptr long long) shlwapi.SHRegSetUSValueW -@ stdcall SHRegWriteUSValueA(long str long ptr long long) shlwapi.SHRegWriteUSValueA -@ stdcall SHRegWriteUSValueW(long wstr long ptr long long) shlwapi.SHRegWriteUSValueW +@ stdcall SHRegSetUSValueA(str str long ptr long long) +@ stdcall SHRegSetUSValueW(wstr wstr long ptr long long) +@ stdcall SHRegWriteUSValueA(long str long ptr long long) +@ stdcall SHRegWriteUSValueW(long wstr long ptr long long) @ stdcall SHTruncateString(str long) # @ stub SaveAlternatePackageRootPath # @ stub SaveStateRootFolderPath diff --git a/dlls/kernelbase/registry.c b/dlls/kernelbase/registry.c new file mode 100644 index 0000000000..bfc7f10942 --- /dev/null +++ b/dlls/kernelbase/registry.c @@ -0,0 +1,477 @@ +/* + * Copyright 2019 Nikolay Sivov for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "shlwapi.h" + +#include "wine/debug.h" +#include "wine/heap.h" + +WINE_DEFAULT_DEBUG_CHANNEL(reg); + +struct USKEY +{ + HKEY HKCUstart; /* Start key in CU hive */ + HKEY HKCUkey; /* Opened key in CU hive */ + HKEY HKLMstart; /* Start key in LM hive */ + HKEY HKLMkey; /* Opened key in LM hive */ + WCHAR path[MAX_PATH]; +}; + +LONG WINAPI SHRegCreateUSKeyA(LPCSTR path, REGSAM samDesired, HUSKEY relative_key, PHUSKEY new_uskey, DWORD flags) +{ + WCHAR *pathW; + LONG ret; + + TRACE("%s, %#x, %p, %p, %#x\n", debugstr_a(path), samDesired, relative_key, new_uskey, flags); + + if (path) + { + INT len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0); + pathW = heap_alloc(len * sizeof(WCHAR)); + if (!pathW) + return ERROR_NOT_ENOUGH_MEMORY; + MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, len); + } + else + pathW = NULL; + + ret = SHRegCreateUSKeyW(pathW, samDesired, relative_key, new_uskey, flags); + HeapFree(GetProcessHeap(), 0, pathW); + return ret; +} + +static HKEY reg_duplicate_hkey(HKEY hKey) +{ + HKEY newKey = 0; + + RegOpenKeyExW(hKey, 0, 0, MAXIMUM_ALLOWED, &newKey); + return newKey; +} + +static HKEY reg_get_hkey_from_huskey(HUSKEY hUSKey, BOOL is_hkcu) +{ + struct USKEY *mihk = hUSKey; + HKEY test = hUSKey; + + if (test == HKEY_CLASSES_ROOT + || test == HKEY_CURRENT_CONFIG + || test == HKEY_CURRENT_USER + || test == HKEY_DYN_DATA + || test == HKEY_LOCAL_MACHINE + || test == HKEY_PERFORMANCE_DATA + || test == HKEY_USERS) +/* FIXME: need to define for Win2k, ME, XP + * (test == HKEY_PERFORMANCE_TEXT) || + * (test == HKEY_PERFORMANCE_NLSTEXT) || + */ + { + return test; + } + + return is_hkcu ? mihk->HKCUkey : mihk->HKLMkey; +} + +LONG WINAPI SHRegCreateUSKeyW(const WCHAR *path, REGSAM samDesired, HUSKEY relative_key, PHUSKEY new_uskey, DWORD flags) +{ + LONG ret = ERROR_CALL_NOT_IMPLEMENTED; + struct USKEY *ret_key; + + TRACE("%s, %#x, %p, %p, %#x\n", debugstr_w(path), samDesired, relative_key, new_uskey, flags); + + if (!new_uskey) + return ERROR_INVALID_PARAMETER; + + *new_uskey = NULL; + + if (flags & ~SHREGSET_FORCE_HKCU) + { + FIXME("unsupported flags 0x%08x\n", flags); + return ERROR_SUCCESS; + } + + ret_key = heap_alloc_zero(sizeof(*ret_key)); + lstrcpynW(ret_key->path, path, ARRAY_SIZE(ret_key->path)); + + if (relative_key) + { + ret_key->HKCUstart = reg_duplicate_hkey(reg_get_hkey_from_huskey(relative_key, TRUE)); + ret_key->HKLMstart = reg_duplicate_hkey(reg_get_hkey_from_huskey(relative_key, FALSE)); + } + else + { + ret_key->HKCUstart = HKEY_CURRENT_USER; + ret_key->HKLMstart = HKEY_LOCAL_MACHINE; + } + + if (flags & SHREGSET_FORCE_HKCU) + { + ret = RegCreateKeyExW(ret_key->HKCUstart, path, 0, NULL, 0, samDesired, NULL, &ret_key->HKCUkey, NULL); + if (ret == ERROR_SUCCESS) + *new_uskey = ret_key; + else + heap_free(ret_key); + } + + return ret; +} + +LONG WINAPI SHRegCloseUSKey(HUSKEY hUSKey) +{ + struct USKEY *key = hUSKey; + LONG ret = ERROR_SUCCESS; + + if (!key) + return ERROR_INVALID_PARAMETER; + + if (key->HKCUkey) + ret = RegCloseKey(key->HKCUkey); + if (key->HKCUstart && key->HKCUstart != HKEY_CURRENT_USER) + ret = RegCloseKey(key->HKCUstart); + if (key->HKLMkey) + ret = RegCloseKey(key->HKLMkey); + if (key->HKLMstart && key->HKLMstart != HKEY_LOCAL_MACHINE) + ret = RegCloseKey(key->HKLMstart); + + heap_free(key); + return ret; +} + +LONG WINAPI SHRegDeleteEmptyUSKeyA(HUSKEY hUSKey, const char *value, SHREGDEL_FLAGS flags) +{ + FIXME("%p, %s, %#x\n", hUSKey, debugstr_a(value), flags); + return ERROR_SUCCESS; +} + +LONG WINAPI SHRegDeleteEmptyUSKeyW(HUSKEY hUSKey, const WCHAR *value, SHREGDEL_FLAGS flags) +{ + FIXME("%p, %s, %#x\n", hUSKey, debugstr_w(value), flags); + return ERROR_SUCCESS; +} + +LONG WINAPI SHRegDeleteUSValueA(HUSKEY hUSKey, const char *value, SHREGDEL_FLAGS flags) +{ + FIXME("%p, %s, %#x\n", hUSKey, debugstr_a(value), flags); + return ERROR_SUCCESS; +} + +LONG WINAPI SHRegDeleteUSValueW(HUSKEY hUSKey, const WCHAR *value, SHREGDEL_FLAGS flags) +{ + FIXME("%p, %s, %#x\n", hUSKey, debugstr_w(value), flags); + return ERROR_SUCCESS; +} + +LONG WINAPI SHRegEnumUSValueA(HUSKEY hUSKey, DWORD index, char *value_name, DWORD *value_name_len, DWORD *type, + void *data, DWORD *data_len, SHREGENUM_FLAGS flags) +{ + HKEY dokey; + + TRACE("%p, %#x, %p, %p, %p, %p, %p, %#x\n", hUSKey, index, value_name, value_name_len, type, data, data_len, flags); + + if ((flags == SHREGENUM_HKCU || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, TRUE))) + return RegEnumValueA(dokey, index, value_name, value_name_len, NULL, type, data, data_len); + + if ((flags == SHREGENUM_HKLM || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, FALSE))) + return RegEnumValueA(dokey, index, value_name, value_name_len, NULL, type, data, data_len); + + FIXME("no support for SHREGENUM_BOTH\n"); + return ERROR_INVALID_FUNCTION; +} + +LONG WINAPI SHRegEnumUSValueW(HUSKEY hUSKey, DWORD index, WCHAR *value_name, DWORD *value_name_len, DWORD *type, + void *data, DWORD *data_len, SHREGENUM_FLAGS flags) +{ + HKEY dokey; + + TRACE("%p, %#x, %p, %p, %p, %p, %p, %#x\n", hUSKey, index, value_name, value_name_len, type, data, data_len, flags); + + if ((flags == SHREGENUM_HKCU || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, TRUE))) + return RegEnumValueW(dokey, index, value_name, value_name_len, NULL, type, data, data_len); + + if ((flags == SHREGENUM_HKLM || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, FALSE))) + return RegEnumValueW(dokey, index, value_name, value_name_len, NULL, type, data, data_len); + + FIXME("no support for SHREGENUM_BOTH\n"); + return ERROR_INVALID_FUNCTION; +} + +LONG WINAPI SHRegEnumUSKeyA(HUSKEY hUSKey, DWORD index, char *name, DWORD *name_len, SHREGENUM_FLAGS flags) +{ + HKEY dokey; + + TRACE("%p, %d, %p, %p(%d), %d\n", hUSKey, index, name, name_len, *name_len, flags); + + if ((flags == SHREGENUM_HKCU || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, TRUE))) + return RegEnumKeyExA(dokey, index, name, name_len, 0, 0, 0, 0); + + if ((flags == SHREGENUM_HKLM || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, FALSE))) + return RegEnumKeyExA(dokey, index, name, name_len, 0, 0, 0, 0); + + FIXME("no support for SHREGENUM_BOTH\n"); + return ERROR_INVALID_FUNCTION; +} + +LONG WINAPI SHRegEnumUSKeyW(HUSKEY hUSKey, DWORD index, WCHAR *name, DWORD *name_len, SHREGENUM_FLAGS flags) +{ + HKEY dokey; + + TRACE("%p, %d, %p, %p(%d), %d\n", hUSKey, index, name, name_len, *name_len, flags); + + if ((flags == SHREGENUM_HKCU || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, TRUE))) + return RegEnumKeyExW(dokey, index, name, name_len, 0, 0, 0, 0); + + if ((flags == SHREGENUM_HKLM || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, FALSE))) + return RegEnumKeyExW(dokey, index, name, name_len, 0, 0, 0, 0); + + FIXME("no support for SHREGENUM_BOTH\n"); + return ERROR_INVALID_FUNCTION; +} + +LONG WINAPI SHRegOpenUSKeyA(const char *path, REGSAM access_mask, HUSKEY relative_key, HUSKEY *uskey, BOOL ignore_hkcu) +{ + WCHAR pathW[MAX_PATH]; + + if (path) + MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, ARRAY_SIZE(pathW)); + + return SHRegOpenUSKeyW(path ? pathW : NULL, access_mask, relative_key, uskey, ignore_hkcu); +} + +LONG WINAPI SHRegOpenUSKeyW(const WCHAR *path, REGSAM access_mask, HUSKEY relative_key, HUSKEY *uskey, BOOL ignore_hkcu) +{ + LONG ret2, ret1 = ~ERROR_SUCCESS; + struct USKEY *key; + + TRACE("%s, %#x, %p, %p, %d\n", debugstr_w(path), access_mask, relative_key, uskey, ignore_hkcu); + + if (uskey) + *uskey = NULL; + + /* Create internal HUSKEY */ + key = heap_alloc_zero(sizeof(*key)); + lstrcpynW(key->path, path, ARRAY_SIZE(key->path)); + + if (relative_key) + { + key->HKCUstart = reg_duplicate_hkey(reg_get_hkey_from_huskey(relative_key, TRUE)); + key->HKLMstart = reg_duplicate_hkey(reg_get_hkey_from_huskey(relative_key, FALSE)); + + /* FIXME: if either of these keys is NULL, create the start key from + * the relative keys start+path + */ + } + else + { + key->HKCUstart = HKEY_CURRENT_USER; + key->HKLMstart = HKEY_LOCAL_MACHINE; + } + + if (!ignore_hkcu) + { + ret1 = RegOpenKeyExW(key->HKCUstart, key->path, 0, access_mask, &key->HKCUkey); + if (ret1) + key->HKCUkey = 0; + } + + ret2 = RegOpenKeyExW(key->HKLMstart, key->path, 0, access_mask, &key->HKLMkey); + if (ret2) + key->HKLMkey = 0; + + if (ret1 || ret2) + TRACE("one or more opens failed: HKCU=%d HKLM=%d\n", ret1, ret2); + + if (ret1 && ret2) + { + /* Neither open succeeded: fail */ + SHRegCloseUSKey(key); + return ret2; + } + + TRACE("HUSKEY=%p\n", key); + if (uskey) + *uskey = key; + + return ERROR_SUCCESS; +} + +LONG WINAPI SHRegWriteUSValueA(HUSKEY hUSKey, const char *value, DWORD type, void *data, DWORD data_len, DWORD flags) +{ + WCHAR valueW[MAX_PATH]; + + if (value) + MultiByteToWideChar(CP_ACP, 0, value, -1, valueW, ARRAY_SIZE(valueW)); + + return SHRegWriteUSValueW(hUSKey, value ? valueW : NULL, type, data, data_len, flags); +} + +LONG WINAPI SHRegWriteUSValueW(HUSKEY hUSKey, const WCHAR *value, DWORD type, void *data, DWORD data_len, DWORD flags) +{ + struct USKEY *hKey = hUSKey; + LONG ret = ERROR_SUCCESS; + DWORD dummy; + + TRACE("%p, %s, %d, %p, %d, %#x\n", hUSKey, debugstr_w(value), type, data, data_len, flags); + + if (!hUSKey || IsBadWritePtr(hUSKey, sizeof(struct USKEY)) || !(flags & (SHREGSET_FORCE_HKCU|SHREGSET_FORCE_HKLM))) + return ERROR_INVALID_PARAMETER; + + if (flags & (SHREGSET_FORCE_HKCU | SHREGSET_HKCU)) + { + if (!hKey->HKCUkey) + { + /* Create the key */ + ret = RegCreateKeyW(hKey->HKCUstart, hKey->path, &hKey->HKCUkey); + TRACE("Creating HKCU key, ret = %d\n", ret); + if (ret && (flags & SHREGSET_FORCE_HKCU)) + { + hKey->HKCUkey = 0; + return ret; + } + } + + if (!ret) + { + if ((flags & SHREGSET_FORCE_HKCU) || RegQueryValueExW(hKey->HKCUkey, value, NULL, NULL, NULL, &dummy)) + { + /* Doesn't exist or we are forcing: Write value */ + ret = RegSetValueExW(hKey->HKCUkey, value, 0, type, data, data_len); + TRACE("Writing HKCU value, ret = %d\n", ret); + } + } + } + + if (flags & (SHREGSET_FORCE_HKLM | SHREGSET_HKLM)) + { + if (!hKey->HKLMkey) + { + /* Create the key */ + ret = RegCreateKeyW(hKey->HKLMstart, hKey->path, &hKey->HKLMkey); + TRACE("Creating HKLM key, ret = %d\n", ret); + if (ret && (flags & (SHREGSET_FORCE_HKLM))) + { + hKey->HKLMkey = 0; + return ret; + } + } + + if (!ret) + { + if ((flags & SHREGSET_FORCE_HKLM) || RegQueryValueExW(hKey->HKLMkey, value, NULL, NULL, NULL, &dummy)) + { + /* Doesn't exist or we are forcing: Write value */ + ret = RegSetValueExW(hKey->HKLMkey, value, 0, type, data, data_len); + TRACE("Writing HKLM value, ret = %d\n", ret); + } + } + } + + return ret; +} + +LONG WINAPI SHRegSetUSValueA(const char *subkey, const char *value, DWORD type, void *data, DWORD data_len, + DWORD flags) +{ + BOOL ignore_hkcu; + HUSKEY hkey; + LONG ret; + + TRACE("%s, %s, %d, %p, %d, %#x\n", debugstr_a(subkey), debugstr_a(value), type, data, data_len, flags); + + if (!data) + return ERROR_INVALID_FUNCTION; + + ignore_hkcu = !(flags & SHREGSET_HKCU || flags & SHREGSET_FORCE_HKCU); + + ret = SHRegOpenUSKeyA(subkey, KEY_ALL_ACCESS, 0, &hkey, ignore_hkcu); + if (ret == ERROR_SUCCESS) + { + ret = SHRegWriteUSValueA(hkey, value, type, data, data_len, flags); + SHRegCloseUSKey(hkey); + } + + return ret; +} + +LONG WINAPI SHRegSetUSValueW(const WCHAR *subkey, const WCHAR *value, DWORD type, void *data, DWORD data_len, + DWORD flags) +{ + BOOL ignore_hkcu; + HUSKEY hkey; + LONG ret; + + TRACE("%s, %s, %d, %p, %d, %#x\n", debugstr_w(subkey), debugstr_w(value), type, data, data_len, flags); + + if (!data) + return ERROR_INVALID_FUNCTION; + + ignore_hkcu = !(flags & SHREGSET_HKCU || flags & SHREGSET_FORCE_HKCU); + + ret = SHRegOpenUSKeyW(subkey, KEY_ALL_ACCESS, 0, &hkey, ignore_hkcu); + if (ret == ERROR_SUCCESS) + { + ret = SHRegWriteUSValueW(hkey, value, type, data, data_len, flags); + SHRegCloseUSKey(hkey); + } + + return ret; +} + +LONG WINAPI SHRegQueryInfoUSKeyA(HUSKEY hUSKey, DWORD *subkeys, DWORD *max_subkey_len, DWORD *values, DWORD *max_value_name_len, + SHREGENUM_FLAGS flags) +{ + HKEY dokey; + LONG ret; + + TRACE("%p, %p, %p, %p, %p, %#x\n", hUSKey, subkeys, max_subkey_len, values, max_value_name_len, flags); + + if ((flags == SHREGENUM_HKCU || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, TRUE))) + { + ret = RegQueryInfoKeyA(dokey, 0, 0, 0, subkeys, max_subkey_len, 0, values, max_value_name_len, 0, 0, 0); + if (ret == ERROR_SUCCESS || flags == SHREGENUM_HKCU) + return ret; + } + + if ((flags == SHREGENUM_HKLM || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, FALSE))) + { + return RegQueryInfoKeyA(dokey, 0, 0, 0, subkeys, max_subkey_len, 0, values, max_value_name_len, 0, 0, 0); + } + + return ERROR_INVALID_FUNCTION; +} + +LONG WINAPI SHRegQueryInfoUSKeyW(HUSKEY hUSKey, DWORD *subkeys, DWORD *max_subkey_len, DWORD *values, DWORD *max_value_name_len, + SHREGENUM_FLAGS flags) +{ + HKEY dokey; + LONG ret; + + TRACE("%p, %p, %p, %p, %p, %#x\n", hUSKey, subkeys, max_subkey_len, values, max_value_name_len, flags); + + if ((flags == SHREGENUM_HKCU || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, TRUE))) + { + ret = RegQueryInfoKeyW(dokey, 0, 0, 0, subkeys, max_subkey_len, 0, values, max_value_name_len, 0, 0, 0); + if (ret == ERROR_SUCCESS || flags == SHREGENUM_HKCU) + return ret; + } + + if ((flags == SHREGENUM_HKLM || flags == SHREGENUM_DEFAULT) && (dokey = reg_get_hkey_from_huskey(hUSKey, FALSE))) + { + return RegQueryInfoKeyW(dokey, 0, 0, 0, subkeys, max_subkey_len, 0, values, max_value_name_len, 0, 0, 0); + } + + return ERROR_INVALID_FUNCTION; +}