[SDBINST] Update according to review

Replace macroses with unicode functions
Minor fixes
Replace dynamic allocations
Add GUID string validation

Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Mark Jansen <mark.jansen@reactos.org>
This commit is contained in:
Max Korostil 2020-10-26 23:58:52 +03:00 committed by Mark Jansen
parent d4a9879583
commit dd34a8a731
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
2 changed files with 106 additions and 177 deletions

View file

@ -1,6 +1,7 @@
project(appcompat)
include_directories(${REACTOS_SOURCE_DIR}/dll/appcompat/apphelp) include_directories(${REACTOS_SOURCE_DIR}/dll/appcompat/apphelp)
add_executable(sdbinst sdbinst.c) add_executable(sdbinst sdbinst.c)
set_module_type(sdbinst win32cui UNICODE) set_module_type(sdbinst win32cui UNICODE)
add_importlibs(sdbinst msvcrt kernel32 ntdll advapi32 apphelp ole32) add_importlibs(sdbinst advapi32 apphelp ole32 msvcrt kernel32 ntdll)
add_cd_file(TARGET sdbinst DESTINATION reactos/system32 FOR all) add_cd_file(TARGET sdbinst DESTINATION reactos/system32 FOR all)

View file

@ -5,22 +5,22 @@
* COPYRIGHT: Copyright 2020 Max Korostil (mrmks04@yandex.ru) * COPYRIGHT: Copyright 2020 Max Korostil (mrmks04@yandex.ru)
*/ */
#include <tchar.h>
#include <windef.h> #include <windef.h>
#include <winbase.h> #include <winbase.h>
#include <tchar.h>
#include <winreg.h> #include <winreg.h>
#include <strsafe.h> #include <strsafe.h>
#include <objbase.h> #include <objbase.h>
#include <apphelp.h> #include <apphelp.h>
#define APPCOMPAT_CUSTOM_REG_PATH L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Custom" #define APPCOMPAT_CUSTOM_REG_PATH L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Custom"
#define APPCOMPAT_LAYERS_REG_PATH L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers" #define APPCOMPAT_LAYERS_REG_PATH L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"
#define APPCOMPAT_INSTALLEDSDB_REG_PATH L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\InstalledSDB" #define APPCOMPAT_INSTALLEDSDB_REG_PATH L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\InstalledSDB"
#define UNINSTALL_REG_PATH L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall" #define UNINSTALL_REG_PATH L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
#define DBPATH_KEY_NAME L"DatabasePath" #define DBPATH_KEY_NAME L"DatabasePath"
#define SDB_EXT L".sdb"
#define GUID_STR_LENGTH 38
HRESULT HRESULT
RegisterSdbEntry( RegisterSdbEntry(
@ -30,21 +30,14 @@ RegisterSdbEntry(
_In_ BOOL isInstall, _In_ BOOL isInstall,
_In_ BOOL isExe) _In_ BOOL isExe)
{ {
PWCHAR regName; WCHAR regName[MAX_PATH];
HKEY hKey = NULL; HKEY hKey = NULL;
LSTATUS status; LSTATUS status;
HRESULT hres; HRESULT hres;
regName = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR)); hres = StringCchPrintfW(regName, MAX_PATH, L"%ls\\%ls",
if (!regName) isExe ? APPCOMPAT_CUSTOM_REG_PATH : APPCOMPAT_LAYERS_REG_PATH,
{ sdbEntryName);
hres = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
goto end;
}
ZeroMemory(regName, MAX_PATH * sizeof(WCHAR));
hres = StringCchPrintf(regName, MAX_PATH, L"%ls\\%ls",
isExe ? APPCOMPAT_CUSTOM_REG_PATH : APPCOMPAT_LAYERS_REG_PATH, sdbEntryName);
if (FAILED(hres)) if (FAILED(hres))
{ {
wprintf(L"StringCchPrintfW error: 0x%08X\n", hres); wprintf(L"StringCchPrintfW error: 0x%08X\n", hres);
@ -54,12 +47,12 @@ RegisterSdbEntry(
// Remove key // Remove key
if (!isInstall) if (!isInstall)
{ {
status = RegDeleteKey(HKEY_LOCAL_MACHINE, regName); status = RegDeleteKeyW(HKEY_LOCAL_MACHINE, regName);
return HRESULT_FROM_WIN32(status); return HRESULT_FROM_WIN32(status);
} }
// Create main key // Create main key
status = RegCreateKeyEx(HKEY_LOCAL_MACHINE, status = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
regName, regName,
0, 0,
NULL, NULL,
@ -68,7 +61,6 @@ RegisterSdbEntry(
NULL, NULL,
&hKey, &hKey,
NULL); NULL);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
wprintf(L"RegKeyCreateEx error: 0x%08X", status); wprintf(L"RegKeyCreateEx error: 0x%08X", status);
@ -76,8 +68,8 @@ RegisterSdbEntry(
goto end; goto end;
} }
// Set instlled time // Set installed time
status = RegSetValueEx(hKey, status = RegSetValueExW(hKey,
dbGuid, dbGuid,
0, 0,
REG_QWORD, REG_QWORD,
@ -85,7 +77,7 @@ RegisterSdbEntry(
sizeof(time)); sizeof(time));
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
wprintf(L"RegSetValueEx error: 0x%08X", status); wprintf(L"RegSetValueExW error: 0x%08X", status);
hres = HRESULT_FROM_WIN32(status); hres = HRESULT_FROM_WIN32(status);
goto end; goto end;
} }
@ -96,11 +88,6 @@ end:
RegCloseKey(hKey); RegCloseKey(hKey);
} }
if (regName)
{
HeapFree(GetProcessHeap(), 0, regName);
}
return hres; return hres;
} }
@ -110,52 +97,41 @@ AddUninstallKey(
_In_ LPCWSTR sdbInstalledPath, _In_ LPCWSTR sdbInstalledPath,
_In_ LPCWSTR guidDbStr) _In_ LPCWSTR guidDbStr)
{ {
PWCHAR sdbinstPath; WCHAR sdbinstPath[MAX_PATH];
PWCHAR regName; WCHAR regName[MAX_PATH];
PWCHAR uninstString; WCHAR uninstString[MAX_PATH];
HKEY hKey = NULL; HKEY hKey = NULL;
HRESULT hres; HRESULT hres;
sdbinstPath = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
regName = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
uninstString = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
if (!sdbinstPath || !regName || !uninstString)
{
hres = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
goto end;
}
ZeroMemory(sdbinstPath, MAX_PATH * sizeof(WCHAR));
ZeroMemory(regName, MAX_PATH * sizeof(WCHAR));
ZeroMemory(uninstString, MAX_PATH * sizeof(WCHAR));
UINT count = GetSystemWindowsDirectory(sdbinstPath, MAX_PATH); UINT count = GetSystemWindowsDirectory(sdbinstPath, MAX_PATH);
if (sdbinstPath[count - 1] != L'\\') if (sdbinstPath[count - 1] != L'\\')
{ {
sdbinstPath[count] = L'\\'; hres = StringCchCatW(sdbinstPath, MAX_PATH, L"\\");
if (FAILED(hres))
{
wprintf(L"StringCchCatW error: 0x%08X", hres);
goto end;
}
} }
// Full path to sdbinst.exe // Full path to sdbinst.exe
hres = StringCchCat(sdbinstPath, MAX_PATH, L"System32\\sdbinst.exe"); hres = StringCchCatW(sdbinstPath, MAX_PATH, L"System32\\sdbinst.exe");
if (FAILED(hres)) if (FAILED(hres))
{ {
wprintf(L"StringCchCat error: 0x%08X", hres); wprintf(L"StringCchCatW error: 0x%08X", hres);
goto end;
} }
// Sdb guid reg key // Sdb guid reg key
hres = StringCchPrintf(regName, MAX_PATH, L"%ls\\%ls", UNINSTALL_REG_PATH, guidDbStr); hres = StringCchPrintfW(regName, MAX_PATH, L"%ls\\%ls", UNINSTALL_REG_PATH, guidDbStr);
if (FAILED(hres)) if (FAILED(hres))
{ {
wprintf(L"StringCchPrintfW error: 0x%08X", hres); wprintf(L"StringCchPrintfW error: 0x%08X", hres);
goto end; goto end;
} }
wprintf(L"%ls\n", sdbinstPath);
wprintf(L"%ls\n", regName);
// Create main key // Create main key
LSTATUS status = RegCreateKeyEx(HKEY_LOCAL_MACHINE, LSTATUS status = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
regName, regName,
0, 0,
NULL, NULL,
@ -174,7 +150,7 @@ AddUninstallKey(
// Set Display name // Set Display name
DWORD length = wcslen(dbName) * sizeof(WCHAR); DWORD length = wcslen(dbName) * sizeof(WCHAR);
status = RegSetValueEx(hKey, status = RegSetValueExW(hKey,
L"DisplayName", L"DisplayName",
0, 0,
REG_SZ, REG_SZ,
@ -182,13 +158,13 @@ AddUninstallKey(
length + sizeof(WCHAR)); length + sizeof(WCHAR));
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
wprintf(L"RegSetValueEx error: 0x%08X", status); wprintf(L"RegSetValueExW error: 0x%08X", status);
hres = HRESULT_FROM_WIN32(status); hres = HRESULT_FROM_WIN32(status);
goto end; goto end;
} }
// Uninstall full string // Uninstall full string
hres = StringCchPrintf(uninstString, MAX_PATH, L"%ls -u \"%ls\"", sdbinstPath, sdbInstalledPath); hres = StringCchPrintfW(uninstString, MAX_PATH, L"%ls -u \"%ls\"", sdbinstPath, sdbInstalledPath);
if (FAILED(hres)) if (FAILED(hres))
{ {
wprintf(L"StringCchPrintfW error: 0x%08X", hres); wprintf(L"StringCchPrintfW error: 0x%08X", hres);
@ -197,7 +173,7 @@ AddUninstallKey(
// Set uninstall string // Set uninstall string
length = wcslen(uninstString) * sizeof(WCHAR); length = wcslen(uninstString) * sizeof(WCHAR);
status = RegSetValueEx(hKey, status = RegSetValueExW(hKey,
L"UninstallString", L"UninstallString",
0, 0,
REG_SZ, REG_SZ,
@ -205,7 +181,7 @@ AddUninstallKey(
length + sizeof(WCHAR)); length + sizeof(WCHAR));
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
wprintf(L"RegSetValueEx error: 0x%08X", status); wprintf(L"RegSetValueExW error: 0x%08X", status);
hres = HRESULT_FROM_WIN32(status); hres = HRESULT_FROM_WIN32(status);
goto end; goto end;
} }
@ -216,21 +192,6 @@ end:
RegCloseKey(hKey); RegCloseKey(hKey);
} }
if (sdbinstPath)
{
HeapFree(GetProcessHeap(), 0, sdbinstPath);
}
if (regName)
{
HeapFree(GetProcessHeap(), 0, regName);
}
if (uninstString)
{
HeapFree(GetProcessHeap(), 0, uninstString);
}
return hres; return hres;
} }
@ -246,7 +207,6 @@ GetSdbGuid(
TAGID tagDbId; TAGID tagDbId;
tagDbId = SdbFindFirstTag(pdb, tagDb, TAG_DATABASE_ID); tagDbId = SdbFindFirstTag(pdb, tagDb, TAG_DATABASE_ID);
if (!tagDbId) if (!tagDbId)
{ {
wprintf(L"Can't find database id tag"); wprintf(L"Can't find database id tag");
@ -276,7 +236,7 @@ ProcessLayers(
TAGID tagLayer = SdbFindFirstTag(pdb, tagDb, TAG_LAYER); TAGID tagLayer = SdbFindFirstTag(pdb, tagDb, TAG_LAYER);
// Add all exe to registry (AppCompatFlags) // Add all layers to registry (AppCompatFlags)
while (tagLayer && (tagLayer != prevTagLayer)) while (tagLayer && (tagLayer != prevTagLayer))
{ {
tagLayerName = SdbFindFirstTag(pdb, tagLayer, TAG_NAME); tagLayerName = SdbFindFirstTag(pdb, tagLayer, TAG_NAME);
@ -287,7 +247,6 @@ ProcessLayers(
} }
LPWSTR name = SdbGetStringTagPtr(pdb, tagLayerName); LPWSTR name = SdbGetStringTagPtr(pdb, tagLayerName);
wprintf(L"Layer name %ls", name);
res = RegisterSdbEntry(name, guidDbStr, time, isInstall, FALSE); res = RegisterSdbEntry(name, guidDbStr, time, isInstall, FALSE);
if (FAILED(res)) if (FAILED(res))
@ -329,7 +288,6 @@ ProcessExe(
} }
LPWSTR name = SdbGetStringTagPtr(pdb, tagExeName); LPWSTR name = SdbGetStringTagPtr(pdb, tagExeName);
wprintf(L"Exe name %ls\n", name);
res = RegisterSdbEntry(name, guidDbStr, time, isInstall, TRUE); res = RegisterSdbEntry(name, guidDbStr, time, isInstall, TRUE);
if (FAILED(res)) if (FAILED(res))
@ -365,13 +323,17 @@ CopySdbToAppPatch(
CopyMemory(sysdirPath, destSdbPath, destLen * sizeof(WCHAR)); CopyMemory(sysdirPath, destSdbPath, destLen * sizeof(WCHAR));
pTmpSysdir = sysdirPath + destLen; pTmpSysdir = sysdirPath + destLen;
while (*pTmpSysdir != L'\\') while (pTmpSysdir > sysdirPath && *pTmpSysdir != L'\\')
{ {
*pTmpSysdir = L'\0'; *pTmpSysdir = L'\0';
--pTmpSysdir; --pTmpSysdir;
} }
wprintf(L"%ls\n", sysdirPath); if (pTmpSysdir == sysdirPath)
{
wprintf(L"Can't find directory separator\n");
goto end;
}
// Create directory if need // Create directory if need
if (!CreateDirectory(sysdirPath, NULL)) if (!CreateDirectory(sysdirPath, NULL))
@ -379,7 +341,7 @@ CopySdbToAppPatch(
error = GetLastError(); error = GetLastError();
if (error != ERROR_ALREADY_EXISTS) if (error != ERROR_ALREADY_EXISTS)
{ {
wprintf(L"Can't create folder %ls\n Error: 0x%08\n", sysdirPath, error); wprintf(L"Can't create folder %ls\n Error: 0x%08X\n", sysdirPath, error);
goto end; goto end;
} }
error = ERROR_SUCCESS; error = ERROR_SUCCESS;
@ -392,34 +354,37 @@ CopySdbToAppPatch(
wprintf(L"Can't copy sdb file"); wprintf(L"Can't copy sdb file");
} }
HeapFree(GetProcessHeap(), 0, sysdirPath);
end: end:
if (sysdirPath)
{
HeapFree(GetProcessHeap(), 0, sysdirPath);
}
return HRESULT_FROM_WIN32(error); return HRESULT_FROM_WIN32(error);
} }
HRESULT HRESULT
BuildPathToSdb( BuildPathToSdb(
_In_ PWCHAR* buffer, _In_ PWCHAR buffer,
_In_ SIZE_T bufLen, _In_ SIZE_T bufLen,
_In_ LPCWSTR guidDbStr) _In_ LPCWSTR guidDbStr)
{ {
PWCHAR pBuffer = *buffer; ZeroMemory(buffer, bufLen * sizeof(WCHAR));
ZeroMemory(pBuffer, bufLen * sizeof(WCHAR));
UINT count = GetSystemWindowsDirectory(pBuffer, bufLen); // Can't use here SdbGetAppPatchDir, because Windows XP haven't this function
if (pBuffer[count - 1] != L'\\') UINT count = GetSystemWindowsDirectory(buffer, bufLen);
if (buffer[count - 1] != L'\\')
{ {
pBuffer[count] = L'\\'; buffer[count] = L'\\';
} }
HRESULT res = StringCchCatW(pBuffer, bufLen, L"AppPatch\\Custom\\"); HRESULT res = StringCchCatW(buffer, bufLen, L"AppPatch\\Custom\\");
if (FAILED(res)) if (FAILED(res))
{ {
goto end; goto end;
} }
res = StringCchCatW(pBuffer, bufLen, guidDbStr); res = StringCchCatW(buffer, bufLen, guidDbStr);
end: end:
return res; return res;
@ -436,15 +401,8 @@ SdbInstall(
GUID dbGuid = {0}; GUID dbGuid = {0};
FILETIME systemTime = {0}; FILETIME systemTime = {0};
ULARGE_INTEGER currentTime = {0}; ULARGE_INTEGER currentTime = {0};
PWCHAR sysdirPatchPath = NULL; WCHAR sysdirPatchPath[MAX_PATH];
PWCHAR guidDbStr; WCHAR guidDbStr[GUID_STR_LENGTH + ARRAYSIZE(SDB_EXT) + 1];
guidDbStr = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
if (!guidDbStr)
{
goto end;
}
ZeroMemory(guidDbStr, MAX_PATH * sizeof(WCHAR));
GetSystemTimeAsFileTime(&systemTime); GetSystemTimeAsFileTime(&systemTime);
currentTime.LowPart = systemTime.dwLowDateTime; currentTime.LowPart = systemTime.dwLowDateTime;
@ -473,7 +431,7 @@ SdbInstall(
} }
StringFromGUID2(&dbGuid, guidDbStr, MAX_PATH); StringFromGUID2(&dbGuid, guidDbStr, MAX_PATH);
HRESULT hres = StringCchCatW(guidDbStr, MAX_PATH, L".sdb"); HRESULT hres = StringCchCatW(guidDbStr, MAX_PATH, SDB_EXT);
if (FAILED(hres)) if (FAILED(hres))
{ {
wprintf(L"StringCchCatW error 0x%08X\n", hres); wprintf(L"StringCchCatW error 0x%08X\n", hres);
@ -508,11 +466,8 @@ SdbInstall(
goto end; goto end;
} }
SIZE_T bufLen = MAX_PATH * 2; // Create full path to sdb in system folder
sysdirPatchPath = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, bufLen * sizeof(WCHAR)); hres = BuildPathToSdb(sysdirPatchPath, ARRAYSIZE(sysdirPatchPath), guidDbStr);
// Create full path tos db in system folder
hres = BuildPathToSdb(&sysdirPatchPath, bufLen, guidDbStr);
if (FAILED(hres)) if (FAILED(hres))
{ {
wprintf(L"Build path error\n"); wprintf(L"Build path error\n");
@ -533,7 +488,7 @@ SdbInstall(
// Registration // Registration
if (!SdbRegisterDatabaseEx(sysdirPatchPath, SDB_DATABASE_SHIM, &currentTime.QuadPart)) if (!SdbRegisterDatabaseEx(sysdirPatchPath, SDB_DATABASE_SHIM, &currentTime.QuadPart))
{ {
wprintf(L"SdbRegisterDatabaseEx UNSUCCESS"); wprintf(L"SdbRegisterDatabaseEx failed");
goto end; goto end;
} }
@ -545,16 +500,6 @@ end:
SdbCloseDatabase(pdb); SdbCloseDatabase(pdb);
} }
if (sysdirPatchPath)
{
HeapFree(GetProcessHeap(), 0, sysdirPatchPath);
}
if (guidDbStr)
{
HeapFree(GetProcessHeap(), 0, guidDbStr);
}
return res; return res;
} }
@ -565,7 +510,7 @@ DeleteUninstallKey(
HKEY hKey = NULL; HKEY hKey = NULL;
HRESULT hres = HRESULT_FROM_WIN32(ERROR_SUCCESS); HRESULT hres = HRESULT_FROM_WIN32(ERROR_SUCCESS);
LSTATUS status = RegCreateKeyEx(HKEY_LOCAL_MACHINE, LSTATUS status = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
UNINSTALL_REG_PATH, UNINSTALL_REG_PATH,
0, 0,
NULL, NULL,
@ -581,7 +526,7 @@ DeleteUninstallKey(
goto end; goto end;
} }
status = RegDeleteKey(hKey, keyName); status = RegDeleteKeyW(hKey, keyName);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
hres = HRESULT_FROM_WIN32(status); hres = HRESULT_FROM_WIN32(status);
@ -676,8 +621,25 @@ end:
return res; return res;
} }
#define BUFFER_SIZE (MAX_PATH * sizeof(WCHAR) + sizeof(WCHAR)) BOOL
#define STRING_LEN (MAX_PATH + 1) ValidateGuidString(
_In_ PWCHAR guidStr)
{
ULONG length = wcslen(guidStr);
if (length == GUID_STR_LENGTH &&
guidStr[0] == L'{' &&
guidStr[GUID_STR_LENGTH - 1] == L'}' &&
guidStr[9] == L'-' &&
guidStr[14] == L'-' &&
guidStr[19] == L'-' &&
guidStr[24] == L'-')
{
return TRUE;
}
return FALSE;
}
BOOL BOOL
SdbUninstallByGuid( SdbUninstallByGuid(
@ -687,24 +649,24 @@ SdbUninstallByGuid(
HKEY hKey = NULL; HKEY hKey = NULL;
HKEY guidKey = NULL; HKEY guidKey = NULL;
LSTATUS status; LSTATUS status;
DWORD keyValSize = BUFFER_SIZE; WCHAR dbPath[MAX_PATH];
PWCHAR dbPath = NULL; DWORD keyValSize = sizeof(dbPath);
dbPath = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE); if (!ValidateGuidString(guidSdbStr))
if (!dbPath)
{ {
goto end; wprintf(L"Invalid GUID: %ls\n", guidSdbStr);
return res;
} }
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, APPCOMPAT_INSTALLEDSDB_REG_PATH, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, APPCOMPAT_INSTALLEDSDB_REG_PATH, 0, KEY_READ | KEY_QUERY_VALUE, &hKey);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
wprintf(L"RegOpenKey error: 0x%08X", status); wprintf(L"RegOpenKeyW error: 0x%08X", status);
goto end; goto end;
} }
status = RegOpenKeyEx(hKey, guidSdbStr, 0, KEY_READ | KEY_QUERY_VALUE, &guidKey); status = RegOpenKeyExW(hKey, guidSdbStr, 0, KEY_READ | KEY_QUERY_VALUE, &guidKey);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
@ -712,21 +674,16 @@ SdbUninstallByGuid(
goto end; goto end;
} }
status = RegQueryValueEx(guidKey, DBPATH_KEY_NAME, NULL, NULL, (LPBYTE)dbPath, &keyValSize); status = RegQueryValueExW(guidKey, DBPATH_KEY_NAME, NULL, NULL, (LPBYTE)dbPath, &keyValSize);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
wprintf(L"RegQueryValueEx: 0x%08X\n", status); wprintf(L"RegQueryValueExW: 0x%08X\n", status);
goto end; goto end;
} }
res = SdbUninstall(dbPath); res = SdbUninstall(dbPath);
end: end:
if (dbPath)
{
HeapFree(GetProcessHeap(), 0, dbPath);
}
if (hKey) if (hKey)
{ {
RegCloseKey(hKey); RegCloseKey(hKey);
@ -748,31 +705,18 @@ SdbUninstallByName(
LSTATUS status; LSTATUS status;
HKEY hKey = NULL; HKEY hKey = NULL;
HKEY subKey = NULL; HKEY subKey = NULL;
DWORD index = 0; DWORD index = 0;
DWORD keyNameLen = STRING_LEN; WCHAR keyName[MAX_PATH];
PWCHAR keyName = NULL; DWORD keyNameLen = ARRAYSIZE(keyName);
DWORD keyValSize; DWORD keyValSize;
PWCHAR dbDescript = NULL; WCHAR dbDescript[MAX_PATH];
PWCHAR dbPath = NULL; WCHAR dbPath[MAX_PATH];
keyName = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE); status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, APPCOMPAT_INSTALLEDSDB_REG_PATH, 0, KEY_READ | KEY_QUERY_VALUE, &hKey);
dbDescript = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE);
dbPath = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, BUFFER_SIZE);
if (!keyName || !dbDescript || !dbPath)
{
goto end;
}
ZeroMemory(keyName, BUFFER_SIZE);
ZeroMemory(dbDescript, BUFFER_SIZE);
ZeroMemory(dbPath, BUFFER_SIZE);
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, APPCOMPAT_INSTALLEDSDB_REG_PATH, 0, KEY_READ | KEY_QUERY_VALUE, &hKey);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
wprintf(L"RegOpenKey error: 0x%08X", status); wprintf(L"RegOpenKeyW error: 0x%08X", status);
goto end; goto end;
} }
@ -782,14 +726,14 @@ SdbUninstallByName(
// Search db guid by name // Search db guid by name
while (status == ERROR_SUCCESS) while (status == ERROR_SUCCESS)
{ {
status = RegOpenKeyEx(hKey, keyName, 0, KEY_READ | KEY_QUERY_VALUE, &subKey); status = RegOpenKeyExW(hKey, keyName, 0, KEY_READ | KEY_QUERY_VALUE, &subKey);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
break; break;
} }
keyValSize = BUFFER_SIZE; keyValSize = sizeof(dbDescript);
status = RegQueryValueEx(subKey, L"DatabaseDescription", NULL, NULL, (LPBYTE)dbDescript, &keyValSize); status = RegQueryValueExW(subKey, L"DatabaseDescription", NULL, NULL, (LPBYTE)dbDescript, &keyValSize);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
break; break;
@ -800,8 +744,8 @@ SdbUninstallByName(
if (_wcsnicmp(dbDescript, nameSdbStr, keyNameLen) == 0) if (_wcsnicmp(dbDescript, nameSdbStr, keyNameLen) == 0)
{ {
// Take db full path // Take db full path
keyValSize = BUFFER_SIZE; keyValSize = sizeof(dbPath);
status = RegQueryValueEx(subKey, DBPATH_KEY_NAME, NULL, NULL, (LPBYTE)dbPath, &keyValSize); status = RegQueryValueExW(subKey, DBPATH_KEY_NAME, NULL, NULL, (LPBYTE)dbPath, &keyValSize);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
dbPath[0] = UNICODE_NULL; dbPath[0] = UNICODE_NULL;
@ -818,8 +762,8 @@ SdbUninstallByName(
keyName[0] = UNICODE_NULL; keyName[0] = UNICODE_NULL;
++index; ++index;
keyNameLen = STRING_LEN; keyNameLen = ARRAYSIZE(keyName);
status = RegEnumKeyEx(hKey, index, keyName, &keyNameLen, NULL, NULL, NULL, NULL); status = RegEnumKeyExW(hKey, index, keyName, &keyNameLen, NULL, NULL, NULL, NULL);
} }
RegCloseKey(hKey); RegCloseKey(hKey);
@ -830,21 +774,6 @@ SdbUninstallByName(
} }
end: end:
if (dbPath)
{
HeapFree(GetProcessHeap(), 0, dbPath);
}
if (dbDescript)
{
HeapFree(GetProcessHeap(), 0, dbDescript);
}
if (keyName)
{
HeapFree(GetProcessHeap(), 0, keyName);
}
return res; return res;
} }
@ -854,7 +783,6 @@ ShowHelp()
{ {
wprintf(L"Using: sdbinst [-?][-q][-u][-g][-n] foo.sdb | {guid} | \"name\" \n" wprintf(L"Using: sdbinst [-?][-q][-u][-g][-n] foo.sdb | {guid} | \"name\" \n"
L"-? - show help\n" L"-? - show help\n"
//L"-q - silence mode\n"
L"-u - uninstall\n" L"-u - uninstall\n"
L"-g - {guid} file guid (only uninstall)\n" L"-g - {guid} file guid (only uninstall)\n"
L"-n - \"name\" - file name (only uninstall)\n"); L"-n - \"name\" - file name (only uninstall)\n");