Skip to content

Commit 37808b2

Browse files
committed
Fixes
1 parent 15597cb commit 37808b2

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

Detours.cpp

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6576,27 +6576,32 @@ namespace Detours {
65766576
static inline bool __ranges_overlap(const void* a, size_t asz,
65776577
const void* b, size_t bsz) {
65786578
if (asz == 0 || bsz == 0) return false;
6579-
const uintptr_t a0 = (uintptr_t)a, a1 = a0 + asz;
6580-
const uintptr_t b0 = (uintptr_t)b, b1 = b0 + bsz;
6581-
// ������������ ��������� [a0,a1) � [b0,b1)
6579+
const uintptr_t a0 = reinterpret_cast<uintptr_t>(a), a1 = a0 + asz;
6580+
const uintptr_t b0 = reinterpret_cast<uintptr_t>(b), b1 = b0 + bsz;
65826581
return (a0 < b1) && (b0 < a1);
65836582
}
65846583

6585-
static inline bool __addr_in_range(const void* base, size_t size, const void* addr) {
6586-
const uintptr_t b = (uintptr_t)base;
6587-
const uintptr_t a = (uintptr_t)addr;
6588-
return (a - b) < size; // ��������� ���� ��� a<b
6584+
static inline bool __address_in_range(const void* base, size_t size, const void* addr) {
6585+
const uintptr_t b = reinterpret_cast<uintptr_t>(base);
6586+
const uintptr_t a = reinterpret_cast<uintptr_t>(addr);
6587+
return (a - b) < size;
65896588
}
65906589

6591-
static inline bool __range_intersection(const void* a, size_t asz,
6592-
const void* b, size_t bsz,
6593-
void** outStart, size_t* outSize) {
6594-
const uintptr_t a0 = (uintptr_t)a, a1 = a0 + asz;
6595-
const uintptr_t b0 = (uintptr_t)b, b1 = b0 + bsz;
6590+
static inline bool __range_intersection(const void* a, size_t asz, const void* b, size_t bsz, void** outStart, size_t* outSize) {
6591+
const uintptr_t a0 = reinterpret_cast<uintptr_t>(a), a1 = a0 + asz;
6592+
const uintptr_t b0 = reinterpret_cast<uintptr_t>(b), b1 = b0 + bsz;
65966593
const uintptr_t s = (a0 > b0 ? a0 : b0);
65976594
const uintptr_t e = (a1 < b1 ? a1 : b1);
6598-
if (e > s) { *outStart = (void*)s; *outSize = (size_t)(e - s); return true; }
6599-
*outStart = nullptr; *outSize = 0; return false;
6595+
6596+
if (e > s) {
6597+
*outStart = reinterpret_cast<void*>(s);
6598+
*outSize = static_cast<size_t>(e - s);
6599+
return true;
6600+
}
6601+
6602+
*outStart = nullptr;
6603+
*outSize = 0;
6604+
return false;
66006605
}
66016606

66026607
// ----------------------------------------------------------------
@@ -8433,7 +8438,7 @@ namespace Detours {
84338438
}
84348439

84358440
if (pRecord->m_pPostCallBack) {
8436-
if (PostCTX.m_pFaultAddress && __addr_in_range(pRecord->m_pUserAddress, pRecord->m_unUserSize, PostCTX.m_pFaultAddress)) {
8441+
if (PostCTX.m_pFaultAddress && __address_in_range(pRecord->m_pUserAddress, pRecord->m_unUserSize, PostCTX.m_pFaultAddress)) {
84378442
pRecord->m_pPostCallBack(pCTX, PostCTX.m_pExceptionAddress ? PostCTX.m_pExceptionAddress : reinterpret_cast<void*>(Exception.ExceptionAddress), PostCTX.m_unOperation, pRecord->m_pUserAddress, PostCTX.m_pFaultAddress);
84388443
}
84398444
}
@@ -8538,11 +8543,11 @@ namespace Detours {
85388543
continue;
85398544
}
85408545

8541-
if (!pRecord->m_bIsVirtual && __addr_in_range(pRecord->m_pAddress, pRecord->m_unSize, pFaultAddress)) {
8546+
if (!pRecord->m_bIsVirtual && __address_in_range(pRecord->m_pAddress, pRecord->m_unSize, pFaultAddress)) {
85428547
vecCommitOpenStack.push_back(pRecord);
85438548
}
85448549

8545-
if (__addr_in_range(pRecord->m_pUserAddress, pRecord->m_unUserSize, pFaultAddress)) {
8550+
if (__address_in_range(pRecord->m_pUserAddress, pRecord->m_unUserSize, pFaultAddress)) {
85468551
vecCallBacks.push_back(pRecord);
85478552
}
85488553
}
@@ -86112,11 +86117,12 @@ namespace Detours {
8611286117
auto pRecord = std::make_unique<MEMORY_HOOK_RECORD>();
8611386118
if (!pRecord) {
8611486119
ReleaseSRWLockExclusive(&g_MemoryHookRecordsLock);
86115-
for (const auto& pPage : vecInstalled) {
86116-
__reg_uninstall_page(pPage);
86117-
g_Suspender.Resume();
86118-
return false;
86120+
for (const auto& pPageAddress : vecInstalled) {
86121+
__reg_uninstall_page(pPageAddress);
8611986122
}
86123+
86124+
g_Suspender.Resume();
86125+
return false;
8612086126
}
8612186127

8612286128
pRecord->m_bIsVirtual = false;
@@ -86136,8 +86142,8 @@ namespace Detours {
8613686142
auto pPage = std::make_unique<Page>(pPageAddress, false, false);
8613786143
if (!pPage) {
8613886144
ReleaseSRWLockExclusive(&g_MemoryHookRecordsLock);
86139-
for (void* b : vecInstalled) {
86140-
__reg_uninstall_page(b);
86145+
for (const auto& pInstalledPageAddress : vecInstalled) {
86146+
__reg_uninstall_page(pInstalledPageAddress);
8614186147
}
8614286148

8614386149
g_Suspender.Resume();
@@ -86146,8 +86152,8 @@ namespace Detours {
8614686152

8614786153
if (!__reg_install_page(pPageAddress)) {
8614886154
ReleaseSRWLockExclusive(&g_MemoryHookRecordsLock);
86149-
for (void* b : vecInstalled) {
86150-
__reg_uninstall_page(b);
86155+
for (const auto& pInstalledPageAddress : vecInstalled) {
86156+
__reg_uninstall_page(pInstalledPageAddress);
8615186157
}
8615286158

8615386159
g_Suspender.Resume();
@@ -86165,8 +86171,8 @@ namespace Detours {
8616586171
auto pRecord = std::make_unique<MEMORY_HOOK_RECORD>();
8616686172
if (!pRecord) {
8616786173
ReleaseSRWLockExclusive(&g_MemoryHookRecordsLock);
86168-
for (void* b : vecInstalled) {
86169-
__reg_uninstall_page(b);
86174+
for (const auto& pInstalledPageAddress : vecInstalled) {
86175+
__reg_uninstall_page(pInstalledPageAddress);
8617086176
}
8617186177

8617286178
g_Suspender.Resume();
@@ -86182,14 +86188,15 @@ namespace Detours {
8618286188
void* pUserAddress = nullptr;
8618386189
size_t unUserSize = 0;
8618486190
__range_intersection(pAddress, unSize, seg.m_pBaseAddress, seg.m_unSize, &pUserAddress, &unUserSize);
86191+
8618586192
pRecord->m_pUserAddress = pUserAddress;
8618686193
pRecord->m_unUserSize = unUserSize;
8618786194

8618886195
vecNewRecords.emplace_back(std::move(pRecord));
8618986196
}
8619086197

86191-
for (auto& rec : vecNewRecords) {
86192-
g_MemoryHookRecords.emplace_back(std::move(rec));
86198+
for (auto& pNewRecord : vecNewRecords) {
86199+
g_MemoryHookRecords.emplace_back(std::move(pNewRecord));
8619386200
}
8619486201
}
8619586202
ReleaseSRWLockExclusive(&g_MemoryHookRecordsLock);
@@ -86229,15 +86236,14 @@ namespace Detours {
8622986236
continue;
8623086237
}
8623186238

86232-
if ((pRecord->m_pCallBack == pCallBack) && __addr_in_range(pRecord->m_pUserAddress, pRecord->m_unUserSize, pAddress))
86233-
{
86239+
if ((pRecord->m_pCallBack == pCallBack) && __address_in_range(pRecord->m_pUserAddress, pRecord->m_unUserSize, pAddress)) {
8623486240
AcquireSRWLockExclusive(&pRecord->m_Lock);
8623586241

8623686242
if (!pRecord->m_bPendingDeletion) {
8623786243
if (!pRecord->m_bIsVirtual) {
86238-
for (auto& p : pRecord->m_Pages) {
86239-
if (p) {
86240-
__reg_uninstall_page(p->GetPageAddress());
86244+
for (auto& pRecordPage : pRecord->m_Pages) {
86245+
if (pRecordPage) {
86246+
__reg_uninstall_page(pRecordPage->GetPageAddress());
8624186247
}
8624286248
}
8624386249
}

0 commit comments

Comments
 (0)