reduce abhorrent indenting

This commit is contained in:
zeffy
2017-10-06 13:56:29 -07:00
parent edc0e8d2a7
commit d771c7984b

View File

@@ -22,63 +22,67 @@ LSTATUS WINAPI RegQueryValueExW_Hook(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpR
if ( (lpData && lpcbData) if ( (lpData && lpcbData)
&& (lpValueName && !_wcsicmp(lpValueName, L"ServiceDll")) ) { && (lpValueName && !_wcsicmp(lpValueName, L"ServiceDll")) ) {
// store original lpData buffer size
DWORD cbData = *lpcbData; DWORD cbData = *lpcbData;
size_t MaxCount = cbData / sizeof(wchar_t);
// this way the dll path is guaranteed to be null-terminated // this way the dll path is guaranteed to be null-terminated
result = RegGetValueW(hKey, NULL, lpValueName, RRF_RT_REG_EXPAND_SZ | RRF_NOEXPAND, lpType, lpData, lpcbData); result = RegGetValueW(hKey, NULL, lpValueName, RRF_RT_REG_EXPAND_SZ | RRF_NOEXPAND, lpType, lpData, lpcbData);
if ( result != ERROR_SUCCESS )
goto L_ret;
NTSTATUS Status;
ULONG ResultLength; ULONG ResultLength;
NTSTATUS Status = NtQueryKey((HANDLE)hKey, KeyNameInformation, NULL, 0, &ResultLength); if ( result != ERROR_SUCCESS
if ( Status != STATUS_BUFFER_OVERFLOW && Status != STATUS_BUFFER_TOO_SMALL ) || (Status = NtQueryKey((HANDLE)hKey, KeyNameInformation, NULL, 0, &ResultLength),
Status != STATUS_BUFFER_OVERFLOW && Status != STATUS_BUFFER_TOO_SMALL) )
goto L_ret; goto L_ret;
PKEY_NAME_INFORMATION pkni = rtl_malloc(ResultLength); PKEY_NAME_INFORMATION pkni = rtl_malloc(ResultLength);
Status = NtQueryKey((HANDLE)hKey, KeyNameInformation, (PVOID)pkni, ResultLength, &ResultLength);
if ( Status == STATUS_SUCCESS ) {
size_t BufferCount = pkni->NameLength / sizeof(wchar_t);
// change key name to lower-case because there is no case-insensitive version of _snwscanf_s if ( NtQueryKey((HANDLE)hKey, KeyNameInformation, (PVOID)pkni, ResultLength, &ResultLength) != STATUS_SUCCESS )
for ( size_t i = 0; i < BufferCount; i++ ) goto L_free_pkni;
pkni->Name[i] = towlower(pkni->Name[i]);
int current, pos; size_t BufferCount = pkni->NameLength / sizeof(wchar_t);
if ( _snwscanf_s(pkni->Name, BufferCount, L"\\registry\\machine\\system\\controlset%03d\\services\\wuauserv\\parameters%n", &current, &pos) == 1
&& pos == BufferCount ) {
wchar_t drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; // change key name to lower-case because there is no case-insensitive version of _snwscanf_s
_wsplitpath_s((wchar_t *)lpData, for ( size_t i = 0; i < BufferCount; i++ )
drive, _countof(drive), pkni->Name[i] = towlower(pkni->Name[i]);
dir, _countof(dir),
fname, _countof(fname),
ext, _countof(ext));
if ( !_wcsicmp(ext, L".dll") int current, pos;
&& (!_wcsicmp(fname, L"wuaueng2") // UpdatePack7R2 if ( _snwscanf_s(pkni->Name, BufferCount,
|| !_wcsicmp(fname, L"WuaCpuFix64") // WuaCpuFix L"\\registry\\machine\\system\\controlset%03d\\services\\wuauserv\\parameters%n", &current, &pos) == 1
|| !_wcsicmp(fname, L"WuaCpuFix")) ) { && pos == BufferCount ) {
wchar_t *tmp = rtl_malloc(cbData); wchar_t drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
_wsplitpath_s((wchar_t *)lpData,
drive, _countof(drive),
dir, _countof(dir),
fname, _countof(fname),
ext, _countof(ext));
_wmakepath_s(tmp, MaxCount, drive, dir, L"wuaueng", ext); if ( !_wcsicmp(ext, L".dll")
DWORD nSize = ExpandEnvironmentStringsW(tmp, NULL, 0); && (!_wcsicmp(fname, L"wuaueng2") // UpdatePack7R2
|| !_wcsicmp(fname, L"WuaCpuFix64") // WuaCpuFix
|| !_wcsicmp(fname, L"WuaCpuFix")) ) {
wchar_t *lpDst = rtl_calloc(nSize, sizeof(wchar_t)); wchar_t *tmp = rtl_malloc(cbData);
ExpandEnvironmentStringsW(tmp, lpDst, nSize);
rtl_free(tmp); size_t MaxCount = cbData / sizeof(wchar_t);
_wmakepath_s(tmp, MaxCount, drive, dir, L"wuaueng", ext);
DWORD nSize = ExpandEnvironmentStringsW(tmp, NULL, 0);
if ( file_exists(lpDst) ) { wchar_t *lpDst = rtl_calloc(nSize, sizeof(wchar_t));
_wmakepath_s((wchar_t *)lpData, MaxCount, drive, dir, L"wuaueng", ext); ExpandEnvironmentStringsW(tmp, lpDst, nSize);
*lpcbData = (DWORD)((wcslen((wchar_t *)lpData) + 1) * sizeof(wchar_t));
trace(L"Fixed wuauserv %ls path: %ls", lpValueName, lpDst); rtl_free(tmp);
}
rtl_free(lpDst); if ( file_exists(lpDst) ) {
_wmakepath_s((wchar_t *)lpData, MaxCount, drive, dir, L"wuaueng", ext);
*lpcbData = (DWORD)((wcslen((wchar_t *)lpData) + 1) * sizeof(wchar_t));
trace(L"Fixed wuauserv %ls path: %ls", lpValueName, lpDst);
} }
rtl_free(lpDst);
} }
} }
L_free_pkni:
rtl_free(pkni); rtl_free(pkni);
} else { } else {
// handle normally // handle normally
@@ -98,50 +102,54 @@ HMODULE WINAPI LoadLibraryExW_Hook(LPCWSTR lpFileName, HANDLE hFile, DWORD dwFla
trace(L"Loaded library: %ls", lpFileName); trace(L"Loaded library: %ls", lpFileName);
DWORD dwLen = GetFileVersionInfoSizeW(lpFileName, NULL); DWORD dwLen = GetFileVersionInfoSizeW(lpFileName, NULL);
if ( !dwLen ) { if ( !dwLen )
trace(L"Failed to get file version info size for file %ls (error code=%08X)", lpFileName, GetLastError());
goto L_ret; goto L_ret;
}
LPVOID pBlock = rtl_malloc(dwLen); LPVOID pBlock = rtl_malloc(dwLen);
if ( GetFileVersionInfoW(lpFileName, 0, dwLen, pBlock) ) {
PLANGANDCODEPAGE ptl;
UINT cb;
if ( VerQueryValueW(pBlock, L"\\VarFileInfo\\Translation", (LPVOID *)&ptl, &cb) ) {
wchar_t lpSubBlock[38];
for ( size_t i = 0; i < (cb / sizeof(LANGANDCODEPAGE)); i++ ) {
swprintf_s(lpSubBlock, _countof(lpSubBlock), L"\\StringFileInfo\\%04x%04x\\InternalName", ptl[i].wLanguage, ptl[i].wCodePage);
wchar_t *lpszInternalName;
UINT uLen;
if ( VerQueryValueW(pBlock, lpSubBlock, (LPVOID *)&lpszInternalName, &uLen)
&& !_wcsicmp(lpszInternalName, L"wuaueng.dll") ) {
VS_FIXEDFILEINFO *pffi; PLANGANDCODEPAGE ptl;
VerQueryValueW(pBlock, L"\\", (LPVOID *)&pffi, &uLen); UINT cb;
WORD wMajor = HIWORD(pffi->dwProductVersionMS); if ( !GetFileVersionInfoW(lpFileName, 0, dwLen, pBlock)
WORD wMinor = LOWORD(pffi->dwProductVersionMS); || !VerQueryValueW(pBlock, L"\\VarFileInfo\\Translation", (LPVOID *)&ptl, &cb) )
WORD wBuild = HIWORD(pffi->dwProductVersionLS); goto L_free_pBlock;
WORD wRevision = LOWORD(pffi->dwProductVersionLS);
wchar_t path[MAX_PATH]; wchar_t lpSubBlock[38];
GetModuleFileNameW(result, path, _countof(path)); for ( size_t i = 0; i < (cb / sizeof(LANGANDCODEPAGE)); i++ ) {
wchar_t *fname = find_fname(path); swprintf_s(lpSubBlock, _countof(lpSubBlock),
L"\\StringFileInfo\\%04x%04x\\InternalName",
ptl[i].wLanguage,
ptl[i].wCodePage);
if ( (verify_win7() && compare_versions(wMajor, wMinor, wBuild, wRevision, 7, 6, 7601, 23714) != -1) wchar_t *lpszInternalName;
|| (verify_win81() && compare_versions(wMajor, wMinor, wBuild, wRevision, 7, 9, 9600, 18621) != -1) ) { UINT uLen;
if ( VerQueryValueW(pBlock, lpSubBlock, (LPVOID *)&lpszInternalName, &uLen)
&& !_wcsicmp(lpszInternalName, L"wuaueng.dll") ) {
trace(L"%ls version: %d.%d.%d.%d", fname, wMajor, wMinor, wBuild, wRevision); VS_FIXEDFILEINFO *pffi;
MODULEINFO modinfo; VerQueryValueW(pBlock, L"\\", (LPVOID *)&pffi, &uLen);
if ( GetModuleInformation(GetCurrentProcess(), result, &modinfo, sizeof(MODULEINFO)) ) { WORD wMajor = HIWORD(pffi->dwProductVersionMS);
if ( !patch_wua(modinfo.lpBaseOfDll, modinfo.SizeOfImage, fname) ) WORD wMinor = LOWORD(pffi->dwProductVersionMS);
trace(L"Failed to patch %ls!", fname); WORD wBuild = HIWORD(pffi->dwProductVersionLS);
} else trace(L"Failed to get module information for %ls (%p) (couldn't patch)", fname, result); WORD wRevision = LOWORD(pffi->dwProductVersionLS);
} else trace(L"Unsupported version of %ls: %d.%d.%d.%d (patching skipped)", fname, wMajor, wMinor, wBuild, wRevision);
break; wchar_t path[MAX_PATH];
} GetModuleFileNameW(result, path, _countof(path));
} wchar_t *fname = find_fname(path);
if ( (verify_win7() && compare_versions(wMajor, wMinor, wBuild, wRevision, 7, 6, 7601, 23714) != -1)
|| (verify_win81() && compare_versions(wMajor, wMinor, wBuild, wRevision, 7, 9, 9600, 18621) != -1) ) {
trace(L"%ls version: %d.%d.%d.%d", fname, wMajor, wMinor, wBuild, wRevision);
MODULEINFO modinfo;
if ( GetModuleInformation(GetCurrentProcess(), result, &modinfo, sizeof(MODULEINFO)) ) {
if ( !patch_wua(modinfo.lpBaseOfDll, modinfo.SizeOfImage, fname) )
trace(L"Failed to patch %ls!", fname);
} else trace(L"Failed to get module information for %ls (%p) (couldn't patch)", fname, result);
} else trace(L"Unsupported %ls version: %d.%d.%d.%d (patching skipped)", fname, wMajor, wMinor, wBuild, wRevision);
break;
} }
} }
L_free_pBlock:
rtl_free(pBlock); rtl_free(pBlock);
L_ret: L_ret:
return result; return result;