Revert "load/unload registry keys on demand"

This reverts commit d41f0b868b.
This commit is contained in:
freedom
2023-08-16 02:03:08 -06:00
parent d41f0b868b
commit 8fb871de34

View File

@@ -46,14 +46,15 @@ PWSTR pszSettingsMask = L"SettingsMask";
/* * * *\ /* * * *\
InitializeRegistryKeys - InitializeRegistryKeys -
Creates the necessary registry keys if necessary. Takes the relevant registry keys and turns them
into valid and usable handles.
RETURNS - RETURNS -
TRUE if successful, FALSE if unsuccessful. TRUE if successful, FALSE if unsuccessful.
\* * * */ \* * * */
BOOL InitializeRegistryKeys() BOOL InitializeRegistryKeys()
{ {
if (RegCreateKeyEx(HKEY_CURRENT_USER, PROGMGR_KEY, 0, szProgMgr, 0, if (!RegCreateKeyEx(HKEY_CURRENT_USER, PROGMGR_KEY, 0, szProgMgr, 0,
KEY_READ | KEY_WRITE, NULL, &hKeyProgramManager, NULL) == ERROR_SUCCESS) KEY_READ | KEY_WRITE, NULL, &hKeyProgramManager, NULL))
{ {
// Create Program Groups and Settings keys // Create Program Groups and Settings keys
RegCreateKeyEx(hKeyProgramManager, pszProgramGroups, 0, szProgMgr, 0, RegCreateKeyEx(hKeyProgramManager, pszProgramGroups, 0, szProgMgr, 0,
@@ -61,11 +62,6 @@ BOOL InitializeRegistryKeys()
RegCreateKeyEx(hKeyProgramManager, pszSettings, 0, szProgMgr, 0, RegCreateKeyEx(hKeyProgramManager, pszSettings, 0, szProgMgr, 0,
KEY_READ | KEY_WRITE, NULL, &hKeySettings, NULL); KEY_READ | KEY_WRITE, NULL, &hKeySettings, NULL);
// Close the key. We'll open/close the registry as we need to.
RegCloseKey(hKeyProgramGroups);
RegCloseKey(hKeySettings);
RegCloseKey(hKeyProgramManager);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@@ -91,14 +87,18 @@ BOOL IsProgMgrDefaultShell()
if (RegQueryValueEx(hKeyWinlogon, L"Shell", 0, &dwType, if (RegQueryValueEx(hKeyWinlogon, L"Shell", 0, &dwType,
(LPBYTE)szShell, &dwBufferSize) == ERROR_SUCCESS) (LPBYTE)szShell, &dwBufferSize) == ERROR_SUCCESS)
{ {
RegCloseKey(hKeyWinlogon);
if (StrStr(szShell, szProgMgr)) if (StrStr(szShell, szProgMgr))
{
// ProgMgr detected >:) // ProgMgr detected >:)
RegCloseKey(hKeyWinlogon);
return TRUE; return TRUE;
}
else else
{
// Inferior shell detected. // Inferior shell detected.
RegCloseKey(hKeyWinlogon);
return FALSE; return FALSE;
}
} }
} }
else else
@@ -121,12 +121,6 @@ DWORD SaveGroupToRegistry(_In_ PGROUP pg)
{ {
DWORD dwConfigStatus = RCE_SUCCESS; DWORD dwConfigStatus = RCE_SUCCESS;
// Open the Program Groups key
RegOpenKeyEx(HKEY_LOCAL_MACHINE, PROGMGR_KEY,
0, KEY_READ | KEY_WRITE, &hKeyProgramManager);
RegOpenKeyEx(hKeyProgramManager, pszProgramGroups, 0,
KEY_READ | KEY_WRITE, &hKeyProgramGroups);
// If the pointer is invalid then fail out // If the pointer is invalid then fail out
if (pg == NULL) if (pg == NULL)
return RCE_FAILURE; return RCE_FAILURE;
@@ -136,10 +130,6 @@ DWORD SaveGroupToRegistry(_In_ PGROUP pg)
(const BYTE*)pg, (sizeof(*pg) + sizeof(ITEM) * pg->cItems)) == ERROR_SUCCESS) (const BYTE*)pg, (sizeof(*pg) + sizeof(ITEM) * pg->cItems)) == ERROR_SUCCESS)
dwConfigStatus = dwConfigStatus && RCE_GROUPS; dwConfigStatus = dwConfigStatus && RCE_GROUPS;
// Close the keys
RegCloseKey(hKeyProgramGroups);
RegCloseKey(hKeyProgramManager);
return dwConfigStatus; return dwConfigStatus;
} }
@@ -154,12 +144,6 @@ DWORD LoadGroupFromRegistry(_Inout_ PGROUP pg, _Out_ DWORD dwBufferSize)
DWORD dwConfigStatus = RCE_SUCCESS; DWORD dwConfigStatus = RCE_SUCCESS;
DWORD dwType = REG_BINARY; DWORD dwType = REG_BINARY;
// Open the Program Groups key
RegOpenKeyEx(HKEY_LOCAL_MACHINE, PROGMGR_KEY,
0, KEY_READ | KEY_WRITE, &hKeyProgramManager);
RegOpenKeyEx(hKeyProgramManager, pszProgramGroups, 0,
KEY_READ | KEY_WRITE, &hKeyProgramGroups);
// If the pointer is invalid then fail out // If the pointer is invalid then fail out
if (pg == NULL) if (pg == NULL)
return RCE_FAILURE; return RCE_FAILURE;
@@ -169,10 +153,6 @@ DWORD LoadGroupFromRegistry(_Inout_ PGROUP pg, _Out_ DWORD dwBufferSize)
(LPBYTE)pg, &dwBufferSize) == ERROR_SUCCESS) (LPBYTE)pg, &dwBufferSize) == ERROR_SUCCESS)
dwConfigStatus = dwConfigStatus && RCE_POSITION; dwConfigStatus = dwConfigStatus && RCE_POSITION;
// Close the keys
RegCloseKey(hKeyProgramGroups);
RegCloseKey(hKeyProgramManager);
return dwConfigStatus; return dwConfigStatus;
} }
@@ -187,14 +167,6 @@ DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
{ {
DWORD dwConfigStatus = RCE_SUCCESS; DWORD dwConfigStatus = RCE_SUCCESS;
// Open the Program Groups and Settings keys
RegOpenKeyEx(HKEY_LOCAL_MACHINE, PROGMGR_KEY,
0, KEY_READ | KEY_WRITE, &hKeyProgramManager);
RegOpenKeyEx(hKeyProgramManager, pszProgramGroups, 0,
KEY_READ | KEY_WRITE, &hKeyProgramGroups);
RegOpenKeyEx(hKeyProgramManager, pszSettings, 0,
KEY_READ | KEY_WRITE, &hKeySettings);
if (bSettings) if (bSettings)
{ {
// Shrink the settings into the bitmask and save it // Shrink the settings into the bitmask and save it
@@ -235,11 +207,6 @@ DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
dwConfigStatus = dwConfigStatus && RCE_GROUPS; dwConfigStatus = dwConfigStatus && RCE_GROUPS;
} }
// Close the keys
RegCloseKey(hKeyProgramGroups);
RegCloseKey(hKeySettings);
RegCloseKey(hKeyProgramManager);
return dwConfigStatus; return dwConfigStatus;
} }
@@ -254,14 +221,6 @@ DWORD LoadConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
{ {
DWORD dwConfigStatus = RCE_SUCCESS; DWORD dwConfigStatus = RCE_SUCCESS;
// Open the Program Groups and Settings keys
RegOpenKeyEx(HKEY_LOCAL_MACHINE, PROGMGR_KEY,
0, KEY_READ | KEY_WRITE, &hKeyProgramManager);
RegOpenKeyEx(hKeyProgramManager, pszProgramGroups, 0,
KEY_READ | KEY_WRITE, &hKeyProgramGroups);
RegOpenKeyEx(hKeyProgramManager, pszSettings, 0,
KEY_READ | KEY_WRITE, &hKeySettings);
if (bSettings) if (bSettings)
{ {
DWORD dwBufferSize = sizeof(dwSettingsMask); DWORD dwBufferSize = sizeof(dwSettingsMask);
@@ -297,10 +256,5 @@ DWORD LoadConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
dwConfigStatus = dwConfigStatus && RCE_GROUPS; dwConfigStatus = dwConfigStatus && RCE_GROUPS;
} }
// Close the keys
RegCloseKey(hKeyProgramGroups);
RegCloseKey(hKeySettings);
RegCloseKey(hKeyProgramManager);
return dwConfigStatus; return dwConfigStatus;
} }