diff --git a/src/Shared/km.h b/src/Shared/km.h index 458af75..26b9620 100644 --- a/src/Shared/km.h +++ b/src/Shared/km.h @@ -10,7 +10,9 @@ #include #include -//#pragma comment(lib,"ntdll.lib") +#pragma warning(push) +// 忽略非标准的 0 数组警告。 +#pragma warning(disable:4200) #define FILE_SUPERSEDE 0x00000000 @@ -5202,7 +5204,7 @@ typedef struct _KUSER_SHARED_DATA #define KI_USER_SHARED_DATA 0x7ffe0000 const auto SharedUserData = reinterpret_cast(KI_USER_SHARED_DATA); - +#pragma warning(pop) #if defined __cplusplus && !defined _Disallow_YY_KM_Namespace } //namespace YY #endif diff --git a/src/Thunks/Iphlpapi.hpp b/src/Thunks/Iphlpapi.hpp index 80e0156..a024a65 100644 --- a/src/Thunks/Iphlpapi.hpp +++ b/src/Thunks/Iphlpapi.hpp @@ -262,7 +262,7 @@ namespace YY return ERROR_INVALID_PARAMETER; MIB_IFROW _IfRow; - _IfRow.dwIndex = _pRow->InterfaceLuid.Value ? _pRow->InterfaceLuid.Info.NetLuidIndex : _pRow->InterfaceIndex; + _IfRow.dwIndex = _pRow->InterfaceLuid.Value ? static_cast(_pRow->InterfaceLuid.Info.NetLuidIndex) : _pRow->InterfaceIndex; auto _lStatus = GetIfEntry(&_IfRow); if (NO_ERROR != _lStatus) diff --git a/src/Thunks/YY_Thunks.cpp b/src/Thunks/YY_Thunks.cpp index deb96e5..dcb4872 100644 --- a/src/Thunks/YY_Thunks.cpp +++ b/src/Thunks/YY_Thunks.cpp @@ -162,6 +162,37 @@ namespace YY { namespace internal { + inline UINT8 __fastcall BitsCount(ULONG32 _fBitMask) + { +#if defined(_M_IX86) || defined(_M_AMD64) + return static_cast(__popcnt(_fBitMask)); +#else + _fBitMask = (_fBitMask & 0x55555555) + ((_fBitMask >> 1) & 0x55555555); + _fBitMask = (_fBitMask & 0x33333333) + ((_fBitMask >> 2) & 0x33333333); + _fBitMask = (_fBitMask & 0x0f0f0f0f) + ((_fBitMask >> 4) & 0x0f0f0f0f); + _fBitMask = (_fBitMask & 0x00ff00ff) + ((_fBitMask >> 8) & 0x00ff00ff); + _fBitMask = (_fBitMask & 0x0000ffff) + ((_fBitMask >> 16) & 0x0000ffff); + return static_cast(_fBitMask); +#endif + } + + inline UINT8 __fastcall BitsCount(ULONG64 _fBitMask) + { +#if defined(_M_IX86) + return static_cast(__popcnt(static_cast(_fBitMask)) + __popcnt(static_cast(_fBitMask >> 32))); +#elif defined(_M_AMD64) + return static_cast(__popcnt64(_fBitMask)); +#else + _fBitMask = (_fBitMask & 0x55555555'55555555) + ((_fBitMask >> 1) & 0x55555555'55555555); + _fBitMask = (_fBitMask & 0x33333333'33333333) + ((_fBitMask >> 2) & 0x33333333'33333333); + _fBitMask = (_fBitMask & 0x0f0f0f0f'0f0f0f0f) + ((_fBitMask >> 4) & 0x0f0f0f0f'0f0f0f0f); + _fBitMask = (_fBitMask & 0x00ff00ff'00ff00ff) + ((_fBitMask >> 8) & 0x00ff00ff'00ff00ff); + _fBitMask = (_fBitMask & 0x0000ffff'0000ffff) + ((_fBitMask >> 16) & 0x0000ffff'0000ffff); + _fBitMask = (_fBitMask & 0x00000000'ffffffff) + ((_fBitMask >> 32) & 0x00000000'ffffffff); + return static_cast(_fBitMask); +#endif + } + __forceinline constexpr DWORD __fastcall MakeVersion(_In_ DWORD _uMajorVersion, _In_ DWORD _uMinorVersion) { return (_uMajorVersion << 16) | _uMinorVersion; @@ -234,13 +265,17 @@ namespace YY const UINT CodePage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; auto cchDst = MultiByteToWideChar(CodePage, MB_ERR_INVALID_CHARS, Src, -1, pDst->Buffer, pDst->MaximumLength / sizeof(wchar_t)); - if (cchDst == 0) + if (cchDst <= 0) { return GetLastError(); } + cchDst *= sizeof(wchar_t); + if (cchDst > MAXUINT16) + { + return ERROR_BAD_PATHNAME; + } - pDst->Length = cchDst * sizeof(wchar_t); - + pDst->Length = static_cast(cchDst); return ERROR_SUCCESS; } diff --git a/src/Thunks/api-ms-win-core-file.hpp b/src/Thunks/api-ms-win-core-file.hpp index e4fc6f8..64c8996 100644 --- a/src/Thunks/api-ms-win-core-file.hpp +++ b/src/Thunks/api-ms-win-core-file.hpp @@ -253,7 +253,7 @@ namespace YY return FALSE; } - auto dwNewBufferSize = sizeof(FILE_RENAME_INFO) + NtName.Length; + DWORD dwNewBufferSize = sizeof(FILE_RENAME_INFO) + NtName.Length; auto NewRenameInfo = (FILE_RENAME_INFO*)HeapAlloc(ProcessHeap, 0, dwNewBufferSize); if (!NewRenameInfo) @@ -533,8 +533,14 @@ namespace YY goto __Exit; } + const auto _uNewLength = pObjectName->Name.Length - pFileNameInfo->FileNameLength + sizeof(wchar_t); + if (_uNewLength > MAXUINT16) + { + lStatus = ERROR_BAD_PATHNAME; + goto __Exit; + } VolumeNtName.Buffer = pObjectName->Name.Buffer; - VolumeNtName.Length = VolumeNtName.MaximumLength = pObjectName->Name.Length - pFileNameInfo->FileNameLength + sizeof(wchar_t); + VolumeNtName.Length = VolumeNtName.MaximumLength = static_cast(_uNewLength); if (VOLUME_NAME_NT & dwFlags) @@ -568,8 +574,14 @@ namespace YY } } + const auto _uNewLength = (wcslen(szVolumeRoot) - 1) * sizeof(szVolumeRoot[0]); + if (_uNewLength > MAXUINT16) + { + lStatus = ERROR_BAD_PATHNAME; + goto __Exit; + } TargetVolumeName.Buffer = szVolumeRoot; - TargetVolumeName.Length = TargetVolumeName.MaximumLength = (wcslen(szVolumeRoot) - 1) * sizeof(szVolumeRoot[0]); + TargetVolumeName.Length = TargetVolumeName.MaximumLength = static_cast(_uNewLength); } //将路径进行规范化 @@ -597,7 +609,14 @@ namespace YY } } - cbszVolumeRoot = (wcslen(szVolumeRoot) - 1) * sizeof(szVolumeRoot[0]); + const auto _cbData = (wcslen(szVolumeRoot) - 1) * sizeof(szVolumeRoot[0]); + if (_cbData > MAXUINT16) + { + lStatus = ERROR_BAD_PATHNAME; + goto __Exit; + } + + cbszVolumeRoot = static_cast(_cbData); } @@ -611,7 +630,7 @@ namespace YY goto __Exit; } - auto cchLongPathNameBufferSize = cbLongPathNameBufferSize / sizeof(szLongPathNameBuffer[0]); + DWORD cchLongPathNameBufferSize = cbLongPathNameBufferSize / sizeof(szLongPathNameBuffer[0]); memcpy(szLongPathNameBuffer, szVolumeRoot, cbszVolumeRoot); memcpy((char*)szLongPathNameBuffer + cbszVolumeRoot, pFileNameInfo->FileName, pFileNameInfo->FileNameLength); @@ -643,18 +662,31 @@ namespace YY } else { + const auto _uNewLength = result * sizeof(wchar_t) - cbszVolumeRoot; + if (_uNewLength > MAXUINT16) + { + lStatus = ERROR_BAD_PATHNAME; + goto __Exit; + } + //转换成功 TargetFileName.Buffer = (wchar_t*)((char*)szLongPathNameBuffer + cbszVolumeRoot); - TargetFileName.Length = TargetFileName.MaximumLength = result * sizeof(wchar_t) - cbszVolumeRoot; + TargetFileName.Length = TargetFileName.MaximumLength = static_cast(_uNewLength); break; } } } else { + if (pFileNameInfo->FileNameLength > MAXUINT16) + { + lStatus = ERROR_BAD_PATHNAME; + goto __Exit; + } + //直接返回原始路径 TargetFileName.Buffer = pFileNameInfo->FileName; - TargetFileName.Length = TargetFileName.MaximumLength = pFileNameInfo->FileNameLength; + TargetFileName.Length = TargetFileName.MaximumLength = static_cast(pFileNameInfo->FileNameLength); } @@ -769,11 +801,11 @@ namespace YY auto cchReturnANSI = WideCharToMultiByte(CodePage, WC_NO_BEST_FIT_CHARS, szFilePathUnicode, cchReturn, nullptr, 0, nullptr, nullptr); - if (0 == cchReturnANSI) + if (cchReturnANSI <= 0) { goto __Error; } - else if (cchReturnANSI >= cchFilePath) + else if (static_cast(cchReturnANSI) >= cchFilePath) { //长度不足 ++cchReturnANSI; diff --git a/src/Thunks/api-ms-win-core-libraryloader.hpp b/src/Thunks/api-ms-win-core-libraryloader.hpp index 903a026..4a2e1b9 100644 --- a/src/Thunks/api-ms-win-core-libraryloader.hpp +++ b/src/Thunks/api-ms-win-core-libraryloader.hpp @@ -509,7 +509,7 @@ namespace YY if (dwLoadLibrarySearchFlags & LOAD_LIBRARY_SEARCH_APPLICATION_DIR) { - const auto nBufferMax = _countof(szFilePathBuffer) - nSize; + const DWORD nBufferMax = _countof(szFilePathBuffer) - nSize; auto nBuffer = GetModuleFileNameW(NULL, szFilePathBuffer + nSize, nBufferMax); @@ -544,7 +544,7 @@ namespace YY if (dwLoadLibrarySearchFlags & LOAD_LIBRARY_SEARCH_SYSTEM32) { - const auto nBufferMax = _countof(szFilePathBuffer) - nSize; + const DWORD nBufferMax = _countof(szFilePathBuffer) - nSize; auto nBuffer = GetSystemDirectoryW(szFilePathBuffer + nSize, nBufferMax); @@ -563,8 +563,14 @@ namespace YY ModuleFileName.Buffer = (PWSTR)lpLibFileName; for (; *lpLibFileName; ++lpLibFileName); + const auto _uNewLength = (lpLibFileName - ModuleFileName.Buffer) * sizeof(lpLibFileName[0]); + if (_uNewLength + sizeof(lpLibFileName[0]) > MAXUINT16) + { + SetLastError(ERROR_INVALID_PARAMETER); + return nullptr; + } - ModuleFileName.Length = (lpLibFileName - ModuleFileName.Buffer) * sizeof(lpLibFileName[0]); + ModuleFileName.Length = static_cast(_uNewLength); ModuleFileName.MaximumLength = ModuleFileName.Length + sizeof(lpLibFileName[0]); HMODULE hModule = NULL; @@ -772,7 +778,7 @@ namespace YY if (_cchSource == -1) { - _cchSource = wcslen(_pStringSource); + _cchSource = (int)wcslen(_pStringSource); } if (_cchSource == 0) @@ -782,7 +788,7 @@ namespace YY if (_cchValue == -1) { - _cchValue = wcslen(_pStringValue); + _cchValue = (int)wcslen(_pStringValue); } if (_cchValue == 0 || _cchValue > _cchSource) @@ -798,7 +804,7 @@ namespace YY { if (CompareStringOrdinal(_pStart, _cchValue, _pStringValue, _cchValue, _bIgnoreCase) == CSTR_EQUAL) { - return _pStart - _pStringSource; + return static_cast(_pStart - _pStringSource); } } return -1; @@ -808,7 +814,7 @@ namespace YY { if (CompareStringOrdinal(_pStart, _cchValue, _pStringValue, _cchValue, _bIgnoreCase) == CSTR_EQUAL) { - return _pStart - _pStringSource; + return static_cast(_pStart - _pStringSource); } } return -1; diff --git a/src/Thunks/api-ms-win-core-localization.hpp b/src/Thunks/api-ms-win-core-localization.hpp index cc6804f..85df584 100644 --- a/src/Thunks/api-ms-win-core-localization.hpp +++ b/src/Thunks/api-ms-win-core-localization.hpp @@ -2137,7 +2137,7 @@ namespace YY if (dwFlags & MUI_MERGE_SYSTEM_FALLBACK) { - for (; LangID = internal::DownlevelGetFallbackLocaleLCID(LangID);) + for (; LangID = (LANGID)internal::DownlevelGetFallbackLocaleLCID(LangID);) { internal::AddLangIDToBuffer(LanguageIds, _countof(LanguageIds), ulNumLanguages, LangID); } @@ -2151,7 +2151,7 @@ namespace YY internal::AddLangIDToBuffer(LanguageIds, _countof(LanguageIds), ulNumLanguages, LangID); - for (; LangID = internal::DownlevelGetFallbackLocaleLCID(LangID);) + for (; LangID = (LANGID)internal::DownlevelGetFallbackLocaleLCID(LangID);) { internal::AddLangIDToBuffer(LanguageIds, _countof(LanguageIds), ulNumLanguages, LangID); } @@ -2163,7 +2163,7 @@ namespace YY internal::AddLangIDToBuffer(LanguageIds, _countof(LanguageIds), ulNumLanguages, LangID); - for (; LangID = internal::DownlevelGetFallbackLocaleLCID(LangID);) + for (; LangID = (LANGID)internal::DownlevelGetFallbackLocaleLCID(LangID);) { internal::AddLangIDToBuffer(LanguageIds, _countof(LanguageIds), ulNumLanguages, LangID); } @@ -2238,7 +2238,7 @@ namespace YY *pTmp++ = L'\0'; - cchLanguagesBufferNeed = pTmp - pBuffer; + cchLanguagesBufferNeed = static_cast(pTmp - pBuffer); *pcchLanguagesBuffer = cchLanguagesBufferNeed; @@ -2267,7 +2267,7 @@ namespace YY if (result <= LOCALE_NAME_MAX_LENGTH) { - cchLanguagesBufferNeed += result; + cchLanguagesBufferNeed += static_cast(result); } } } @@ -2306,12 +2306,12 @@ namespace YY void ) { - if (auto const pGetThreadUILanguage = try_get_GetThreadUILanguage()) + if (auto const _pfnGetThreadUILanguage = try_get_GetThreadUILanguage()) { - return pGetThreadUILanguage(); + return _pfnGetThreadUILanguage(); } - return GetThreadLocale(); + return (LANGID)GetThreadLocale(); } #endif @@ -2678,7 +2678,7 @@ namespace YY } if (_cchStr < 0) - _cchStr = wcslen(_szString); + _cchStr = (int)wcslen(_szString); for (; _cchStr;--_cchStr, ++_szString) diff --git a/src/Thunks/api-ms-win-core-path.hpp b/src/Thunks/api-ms-win-core-path.hpp index a25a901..99cf430 100644 --- a/src/Thunks/api-ms-win-core-path.hpp +++ b/src/Thunks/api-ms-win-core-path.hpp @@ -1247,7 +1247,7 @@ namespace YY //处于长命名模式中,如果规范化后的路径有效部分小于 MAX_PATH,那么删除长命名前缀 if (ulReservedSize) { - if (pTempOut - pszPathOut <= ulReservedSize + MAX_PATH) + if (size_t(pTempOut - pszPathOut) <= ulReservedSize + MAX_PATH) { if (bUNC) { @@ -1759,4 +1759,4 @@ namespace YY #endif } -} \ No newline at end of file +} diff --git a/src/Thunks/api-ms-win-core-processthreads.hpp b/src/Thunks/api-ms-win-core-processthreads.hpp index 27e3a6a..ee7f231 100644 --- a/src/Thunks/api-ms-win-core-processthreads.hpp +++ b/src/Thunks/api-ms-win-core-processthreads.hpp @@ -121,7 +121,7 @@ namespace YY { //不支持GetCurrentProcessorNumberEx时假定用户只有一组CPU ProcNumber->Group = 0; - ProcNumber->Number = GetCurrentProcessorNumber(); + ProcNumber->Number = static_cast(GetCurrentProcessorNumber()); ProcNumber->Reserved = 0; } } @@ -800,7 +800,7 @@ namespace YY return FALSE; } - YY_ProcessPolicyInfo _Info = { _eMitigationPolicy }; + YY_ProcessPolicyInfo _Info = { static_cast(_eMitigationPolicy) }; NTSTATUS _Status = _pfnNtQueryInformationProcess(_hProcess, YY_ProcessPolicy, &_Info, sizeof(_Info), nullptr); if (_Status >= 0) { @@ -897,7 +897,7 @@ namespace YY return FALSE; } - YY_ProcessPolicyInfo _Info = { _eMitigationPolicy, *(DWORD*)_pBuffer }; + YY_ProcessPolicyInfo _Info = { static_cast(_eMitigationPolicy), *(DWORD*)_pBuffer }; _Status = _pfnNtSetInformationProcess(NtCurrentProcess(), YY_ProcessPolicy, &_Info, sizeof(_Info)); } @@ -1129,7 +1129,7 @@ namespace YY if (_pPreviousIdealProcessor) { _pPreviousIdealProcessor->Group = 0; - _pPreviousIdealProcessor->Number = _uPreviousIdealProcessor; + _pPreviousIdealProcessor->Number = static_cast(_uPreviousIdealProcessor); _pPreviousIdealProcessor->Reserved = 0; } return TRUE; @@ -1164,7 +1164,7 @@ namespace YY } _pIdealProcessor->Group = 0; - _pIdealProcessor->Number = _uPreviousIdealProcessor; + _pIdealProcessor->Number = static_cast(_uPreviousIdealProcessor); _pIdealProcessor->Reserved = 0; return TRUE; } diff --git a/src/Thunks/api-ms-win-core-string.hpp b/src/Thunks/api-ms-win-core-string.hpp index c9fbef8..c649ac5 100644 --- a/src/Thunks/api-ms-win-core-string.hpp +++ b/src/Thunks/api-ms-win-core-string.hpp @@ -153,11 +153,11 @@ namespace YY return 0; } - DWORD cchLength = min(__cchCount1, __cchCount2); + size_t cchLength = min(__cchCount1, __cchCount2); if (bIgnoreCase) { - for (DWORD Index = 0; Index != cchLength; ++Index) + for (size_t Index = 0; Index != cchLength; ++Index) { auto ch1 = lpString1[Index]; auto ch2 = lpString2[Index]; @@ -180,7 +180,7 @@ namespace YY } else { - for (DWORD Index = 0; Index != cchLength; ++Index) + for (size_t Index = 0; Index != cchLength; ++Index) { auto ch1 = lpString1[Index]; auto ch2 = lpString2[Index]; diff --git a/src/Thunks/api-ms-win-core-synch.hpp b/src/Thunks/api-ms-win-core-synch.hpp index df1744e..7c6225f 100644 --- a/src/Thunks/api-ms-win-core-synch.hpp +++ b/src/Thunks/api-ms-win-core-synch.hpp @@ -245,7 +245,7 @@ namespace YY } else { - auto NewStatus = InterlockedCompareExchange((volatile LONG *)SRWLock, Status & ~YY_SRWLOCK_Waking, Status); + auto NewStatus = InterlockedCompareExchange((volatile size_t*)SRWLock, Status & ~YY_SRWLOCK_Waking, Status); if (NewStatus == Status) return; @@ -2868,4 +2868,4 @@ namespace YY #endif }//namespace Thunks -} //namespace YY \ No newline at end of file +} //namespace YY diff --git a/src/Thunks/api-ms-win-core-sysinfo.hpp b/src/Thunks/api-ms-win-core-sysinfo.hpp index fb954a6..1b7da55 100644 --- a/src/Thunks/api-ms-win-core-sysinfo.hpp +++ b/src/Thunks/api-ms-win-core-sysinfo.hpp @@ -243,45 +243,9 @@ namespace YY GetSystemInfo(&SystemInfo); - - static constexpr const size_t BitCountTable[256] = - { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 - }; - pInfo->Group.GroupInfo->ActiveProcessorMask = SystemInfo.dwActiveProcessorMask; - - auto& ActiveProcessorMask = SystemInfo.dwActiveProcessorMask; - -#if defined(_M_IX86) || defined(_M_ARM) - size_t ActiveProcessorCount = BitCountTable[((byte*)&ActiveProcessorMask)[0]] + BitCountTable[((byte*)&ActiveProcessorMask)[1]] + BitCountTable[((byte*)&ActiveProcessorMask)[2]] + BitCountTable[((byte*)&ActiveProcessorMask)[3]]; -#elif defined(_M_AMD64) || defined(_M_IA64) || defined(_M_ARM64) - size_t ActiveProcessorCount = BitCountTable[((byte*)&ActiveProcessorMask)[0]] + BitCountTable[((byte*)&ActiveProcessorMask)[1]] + BitCountTable[((byte*)&ActiveProcessorMask)[2]] + BitCountTable[((byte*)&ActiveProcessorMask)[3]] - + BitCountTable[((byte*)&ActiveProcessorMask)[4]] + BitCountTable[((byte*)&ActiveProcessorMask)[5]] + BitCountTable[((byte*)&ActiveProcessorMask)[6]] + BitCountTable[((byte*)&ActiveProcessorMask)[7]]; -#else - size_t ActiveProcessorCount = 0; - for (int i = 0; i != sizeof(ActiveProcessorMask); ++i) - { - ActiveProcessorCount += BitCountTable[((byte*)&ActiveProcessorMask)[i]]; - } -#endif - pInfo->Group.GroupInfo->ActiveProcessorCount = ActiveProcessorCount; - pInfo->Group.GroupInfo->MaximumProcessorCount = SystemInfo.dwNumberOfProcessors; + pInfo->Group.GroupInfo->ActiveProcessorCount = internal::BitsCount(static_cast(SystemInfo.dwActiveProcessorMask)); + pInfo->Group.GroupInfo->MaximumProcessorCount = static_cast(SystemInfo.dwNumberOfProcessors); } } diff --git a/src/Thunks/api-ms-win-core-systemtopology.hpp b/src/Thunks/api-ms-win-core-systemtopology.hpp index 70732b0..9a74d21 100644 --- a/src/Thunks/api-ms-win-core-systemtopology.hpp +++ b/src/Thunks/api-ms-win-core-systemtopology.hpp @@ -63,12 +63,17 @@ namespace YY } else { - ULONGLONG ullProcessorMask; - auto bRet = GetNumaNodeProcessorMask(Node, &ullProcessorMask); + if (Node > MAXUINT8) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + ULONGLONG ullProcessorMask; + auto bRet = GetNumaNodeProcessorMask(static_cast(Node), &ullProcessorMask); if (bRet) { - ProcessorMask->Mask = ullProcessorMask; + ProcessorMask->Mask = static_cast(ullProcessorMask); //假定只有一组CPU ProcessorMask->Group = 0; ProcessorMask->Reserved[0] = 0; @@ -233,4 +238,4 @@ namespace YY }//namespace Thunks -} //namespace YY \ No newline at end of file +} //namespace YY diff --git a/src/Thunks/api-ms-win-core-threadpool.hpp b/src/Thunks/api-ms-win-core-threadpool.hpp index 2d4467c..cd8c32d 100644 --- a/src/Thunks/api-ms-win-core-threadpool.hpp +++ b/src/Thunks/api-ms-win-core-threadpool.hpp @@ -968,7 +968,7 @@ namespace YY if (lDueTime.QuadPart < 0) { //相对时间 - DueTime = lDueTime.QuadPart / -10'000; + DueTime = static_cast(lDueTime.QuadPart / -10'000); } else if (lDueTime.QuadPart > 0) { @@ -981,7 +981,7 @@ namespace YY if (lDueTime.QuadPart > lCurrentTime.QuadPart) { - DueTime = (lDueTime.QuadPart - lCurrentTime.QuadPart) / 10'000; + DueTime = static_cast((lDueTime.QuadPart - lCurrentTime.QuadPart) / 10'000); } } @@ -1534,7 +1534,7 @@ namespace YY if (Time.QuadPart < 0) { //这是一个相对时间 - dwMilliseconds = Time.QuadPart / -10'000; + dwMilliseconds = static_cast(Time.QuadPart / -10'000); } else if (Time.QuadPart == 0) { @@ -1551,7 +1551,7 @@ namespace YY if (Time.QuadPart > lCurrentTime.QuadPart) { - dwMilliseconds = (Time.QuadPart - lCurrentTime.QuadPart) / 10'000; + dwMilliseconds = static_cast((Time.QuadPart - lCurrentTime.QuadPart) / 10'000); } else { diff --git a/src/Thunks/api-ms-win-power-base.hpp b/src/Thunks/api-ms-win-power-base.hpp index cbe3cdc..445057e 100644 --- a/src/Thunks/api-ms-win-power-base.hpp +++ b/src/Thunks/api-ms-win-power-base.hpp @@ -1,4 +1,4 @@ -#if (YY_Thunks_Support_Version < NTDDI_WIN8) +#if (YY_Thunks_Support_Version < NTDDI_WIN8) #include #endif @@ -54,7 +54,7 @@ namespace YY if (WM_POWERBROADCAST == _uMsg) { - _pWork2->Parameters.Callback(_pWork2->Parameters.Context, _wParam, (PVOID)_lParam); + _pWork2->Parameters.Callback(_pWork2->Parameters.Context, static_cast(_wParam), (PVOID)_lParam); } return TRUE; @@ -93,8 +93,8 @@ namespace YY #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ|UWP Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ | UWP Ӧ] + // 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用] + // 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用] __DEFINE_THUNK( powrprof, 4, @@ -122,8 +122,8 @@ namespace YY #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ] + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012[仅限桌面应用] __DEFINE_THUNK( powrprof, 12, @@ -146,8 +146,8 @@ namespace YY #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ] + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012[仅限桌面应用] __DEFINE_THUNK( powrprof, 4, diff --git a/src/Thunks/dwmapi.hpp b/src/Thunks/dwmapi.hpp index 47d72f9..36b4855 100644 --- a/src/Thunks/dwmapi.hpp +++ b/src/Thunks/dwmapi.hpp @@ -1,5 +1,8 @@ #include +// 忽略deprecated,因为是Thunks项目肯定是需要调用老接口的。 +#pragma warning(disable:4995) + namespace YY { namespace Thunks diff --git a/src/Thunks/psapi.hpp b/src/Thunks/psapi.hpp index b99a92d..dd04a72 100644 --- a/src/Thunks/psapi.hpp +++ b/src/Thunks/psapi.hpp @@ -106,14 +106,19 @@ namespace YY //确定实际个数 const auto pWatchInfoMax = (PPSAPI_WS_WATCH_INFORMATION)((byte*)pWatchInfo + cbWatchInfo); auto pWatchInfoTerminated = pWatchInfo; - for (; pWatchInfoTerminated < pWatchInfoMax && pWatchInfoTerminated->FaultingPc != nullptr; pWatchInfoTerminated += sizeof(pWatchInfoTerminated[0])); + for (; pWatchInfoTerminated < pWatchInfoMax && pWatchInfoTerminated->FaultingPc != nullptr; ++pWatchInfoTerminated); auto ccWatchInfo = pWatchInfoTerminated - pWatchInfo; auto cbWatchInfoExRequest = (ccWatchInfo + 1) * sizeof(lpWatchInfoEx[0]); + if (cbWatchInfoExRequest > MAXUINT32) + { + lStatus = ERROR_FUNCTION_FAILED; + break; + } auto cbBuffer = *cb; - *cb = cbWatchInfoExRequest; + *cb = static_cast(cbWatchInfoExRequest); if (cbBuffer < cbWatchInfoExRequest) { @@ -183,4 +188,4 @@ namespace YY #endif }//namespace Thunks -} //namespace YY \ No newline at end of file +} //namespace YY diff --git a/src/YY-Thunks.UnitTest/api-ms-win-core-synch.UnitTest.cpp b/src/YY-Thunks.UnitTest/api-ms-win-core-synch.UnitTest.cpp index 5f71061..63c710d 100644 --- a/src/YY-Thunks.UnitTest/api-ms-win-core-synch.UnitTest.cpp +++ b/src/YY-Thunks.UnitTest/api-ms-win-core-synch.UnitTest.cpp @@ -222,10 +222,10 @@ namespace api_ms_win_core_synch auto _hThreadHandle = (HANDLE)_beginthreadex(nullptr, 0, [](void* pMyData) -> unsigned { - auto _uStart = GetTickCount64(); + const auto _uStart = GetTickCount64(); ::AcquireSRWLockExclusive((SRWLOCK*)pMyData); - return GetTickCount64() - _uStart; + return static_cast(GetTickCount64() - _uStart); }, &_SRWLock, 0, @@ -246,4 +246,4 @@ namespace api_ms_win_core_synch Assert::IsTrue(_uCode >= 400 && _uCode <= 800); } }; -} \ No newline at end of file +}