diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index 3e9e7b2..fb579d2 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -629,6 +629,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) &hKey, &dwDisposition ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } RegQueryValueExW( hKey, name, @@ -651,6 +655,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) KEY_READ | (hDC ? 0 : KEY_WRITE), &hKey ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } value = hKey; } if (bInvert || bBool || bJustCheck) @@ -744,6 +752,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) &hKey, &dwDisposition ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } if (d[1] == '"') { wchar_t* p = wcschr(d + 2, L'"'); @@ -1173,6 +1185,10 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin &hKey, &dwDisposition ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } DWORD bAllocConsole = FALSE; RegQueryValueExW( hKey, diff --git a/ExplorerPatcher/SettingsMonitor.c b/ExplorerPatcher/SettingsMonitor.c index dca4b27..7ab42e9 100644 --- a/ExplorerPatcher/SettingsMonitor.c +++ b/ExplorerPatcher/SettingsMonitor.c @@ -55,11 +55,20 @@ DWORD MonitorSettingsChanges(SettingsChangeParameters* params) KEY_READ, &hKeyCU ); + if (hKeyCU == NULL || hKeyCU == INVALID_HANDLE_VALUE) + { + hKeyCU = NULL; + } if (lRes != ERROR_SUCCESS) { return 0; } HANDLE hEvHKCU = CreateEvent(NULL, FALSE, FALSE, NULL); + if (hEvHKCU == NULL || hEvHKCU == INVALID_HANDLE_VALUE) + { + hEvHKCU = NULL; + return 0; + } RegNotifyChangeKeyValue( hKeyCU, FALSE, @@ -75,11 +84,20 @@ DWORD MonitorSettingsChanges(SettingsChangeParameters* params) KEY_READ, &hKeyLM ); + if (hKeyLM == NULL || hKeyLM == INVALID_HANDLE_VALUE) + { + hKeyLM = NULL; + } if (lRes != ERROR_SUCCESS) { return 0; } HANDLE hEvHKLM = CreateEvent(NULL, FALSE, FALSE, NULL); + if (hEvHKLM == NULL || hEvHKLM == INVALID_HANDLE_VALUE) + { + hEvHKLM = NULL; + return 0; + } RegNotifyChangeKeyValue( hKeyLM, FALSE, @@ -309,10 +327,10 @@ DWORD MonitorSettingsChanges(SettingsChangeParameters* params) } } - CloseHandle(hEvHKCU); - CloseHandle(hEvHKLM); - RegCloseKey(hKeyCU); - RegCloseKey(hKeyLM); + if (hEvHKCU) CloseHandle(hEvHKCU); + if (hEvHKLM) CloseHandle(hEvHKLM); + if (hKeyCU) RegCloseKey(hKeyCU); + if (hKeyLM) RegCloseKey(hKeyLM); } } } \ No newline at end of file diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 5785836..60df375 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -1356,7 +1356,8 @@ __declspec(dllexport) DWORD WINAPI main( { funchook = funchook_create(); printf("funchook create %d\n", funchook != 0); - HKEY hKey; + + HKEY hKey = NULL; DWORD dwDisposition; DWORD dwSize = sizeof(DWORD); @@ -1373,6 +1374,10 @@ __declspec(dllexport) DWORD WINAPI main( &hKey, &dwDisposition ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } DWORD bAllocConsole = FALSE; RegQueryValueExW( hKey, @@ -1760,6 +1765,12 @@ __declspec(dllexport) DWORD WINAPI main( { printf("Failed to register taskbar update notification.\n"); } + + + if (hKey) + { + RegCloseKey(hKey); + } } else { diff --git a/ExplorerPatcher/symbols.c b/ExplorerPatcher/symbols.c index 96ae80e..a0dbc72 100644 --- a/ExplorerPatcher/symbols.c +++ b/ExplorerPatcher/symbols.c @@ -59,7 +59,7 @@ L"\r\n"; DWORD DownloadSymbols(DownloadSymbolsParams* params) { - HKEY hKey; + HKEY hKey = NULL; DWORD dwDisposition; HMODULE hModule = params->hModule; @@ -224,7 +224,7 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) &hKey, &dwDisposition ); - if (!hKey) + if (!hKey || hKey == INVALID_HANDLE_VALUE) { FreeLibraryAndExitThread( hModule, @@ -296,7 +296,7 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) &(symbols_PTRS.twinui_pcshell_PTRS[7]), sizeof(DWORD) ); - RegCloseKey(hKey); + if (hKey) RegCloseKey(hKey); @@ -364,7 +364,7 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) &hKey, &dwDisposition ); - if (!hKey) + if (!hKey || hKey == INVALID_HANDLE_VALUE) { FreeLibraryAndExitThread( hModule, @@ -412,7 +412,7 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) &(symbols_PTRS.startdocked_PTRS[4]), sizeof(DWORD) ); - RegCloseKey(hKey); + if (hKey) RegCloseKey(hKey); @@ -430,7 +430,7 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) &hKey, &dwDisposition ); - if (!hKey) + if (!hKey || hKey == INVALID_HANDLE_VALUE) { FreeLibraryAndExitThread( hModule, @@ -446,7 +446,7 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) szReportedVersion, wcslen(szReportedVersion) * sizeof(TCHAR) ); - RegCloseKey(hKey); + if (hKey) RegCloseKey(hKey); if (symbols_PTRS.twinui_pcshell_PTRS[0]) @@ -503,9 +503,9 @@ DWORD DownloadSymbols(DownloadSymbolsParams* params) exit(0); } -BOOL LoadSymbols(symbols_addr* symbols_PTRS) +BOOL LoadSymbols(symbols_addr* symbols_PTRS, HMODULE hModule) { - HKEY hKey; + HKEY hKey = NULL; DWORD dwDisposition; DWORD dwSize = sizeof(DWORD); @@ -520,6 +520,14 @@ BOOL LoadSymbols(symbols_addr* symbols_PTRS) &hKey, &dwDisposition ); + if (!hKey || hKey == INVALID_HANDLE_VALUE) + { + FreeLibraryAndExitThread( + hModule, + 1 + ); + return 1; + } RegQueryValueExW( hKey, TEXT(TWINUI_PCSHELL_SB_0), @@ -637,7 +645,7 @@ BOOL LoadSymbols(symbols_addr* symbols_PTRS) &(symbols_PTRS->startdocked_PTRS[4]), &dwSize ); - RegCloseKey(hKey); + if (hKey) RegCloseKey(hKey); BOOL bNeedToDownload = FALSE; for (UINT i = 0; i < sizeof(symbols_addr) / sizeof(DWORD); ++i)