@@ -5545,6 +5545,21 @@ namespace Detours {
55455545 return false;
55465546 };
55475547
5548+ // ----------------------------------------------------------------
5549+ // __is_range_in_range
5550+ // ----------------------------------------------------------------
5551+
5552+ static bool inline __is_range_in_range(void const* const pOuterRangeStart, const size_t unOuterRangeSize, void const* const pInnerRangeStart, const size_t unInnerRangeSize) {
5553+ if (!pOuterRangeStart || !pInnerRangeStart) {
5554+ return false;
5555+ }
5556+
5557+ const char* const pOuterRangeEnd = static_cast<const char* const>(pOuterRangeStart) + unOuterRangeSize;
5558+ const char* const pInnerRangeEnd = static_cast<const char* const>(pInnerRangeStart) + unInnerRangeSize;
5559+
5560+ return (pInnerRangeStart < pOuterRangeEnd) && (pOuterRangeStart < pInnerRangeEnd);
5561+ }
5562+
55485563 // ----------------------------------------------------------------
55495564 // Shared
55505565 // ----------------------------------------------------------------
@@ -84837,17 +84852,6 @@ namespace Detours {
8483784852 return false;
8483884853 }
8483984854
84840- for (auto& pRecord : g_MemoryHookRecords) {
84841- if (pRecord->m_bPendingDeletion) {
84842- continue;
84843- }
84844-
84845- if (pRecord->m_pCallBack == pCallBack) {
84846- g_Suspender.Resume();
84847- return false;
84848- }
84849- }
84850-
8485184855 auto vecPages = __get_pages_info(pAddress, unSize, true);
8485284856 if (vecPages.empty()) {
8485384857 g_Suspender.Resume();
@@ -84871,6 +84875,36 @@ namespace Detours {
8487184875 return false;
8487284876 }
8487384877
84878+ for (auto& pRecord : g_MemoryHookRecords) {
84879+ if (pRecord->m_bPendingDeletion) {
84880+ continue;
84881+ }
84882+
84883+ if (pRecord->m_pCallBack == pCallBack) {
84884+ g_Suspender.Resume();
84885+ return false;
84886+ }
84887+
84888+ if (__is_range_in_range(pRecord->m_pAddress, pRecord->m_unSize, pAddress, unSize)) {
84889+ g_Suspender.Resume();
84890+ return false;
84891+ }
84892+
84893+ auto vecRecordPages = __get_pages_info(pRecord->m_pAddress, pRecord->m_unSize, true);
84894+ if (vecRecordPages.empty()) {
84895+ continue;
84896+ }
84897+
84898+ for (const auto& pPage : vecPages) {
84899+ for (const auto& pRecordPage : vecRecordPages) {
84900+ if (__is_range_in_range(pRecordPage.m_pBaseAddress, pRecordPage.m_unSize, pPage.m_pBaseAddress, pPage.m_unSize)) {
84901+ g_Suspender.Resume();
84902+ return false;
84903+ }
84904+ }
84905+ }
84906+ }
84907+
8487484908 auto pRecord = std::make_unique<MEMORY_HOOK_RECORD>();
8487584909 if (!pRecord) {
8487684910 g_Suspender.Resume();
0 commit comments