-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetours_api.cpp
More file actions
821 lines (624 loc) · 17.5 KB
/
detours_api.cpp
File metadata and controls
821 lines (624 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
#pragma warning(disable : 26812)
#include "detours_api.h"
#include <tlhelp32.h>
#define FOR_EACH_DETOUR(iter) for (unsigned int iter = 0; iter < m_detours.size(); iter++)
//-----------------------------------------------------------------------------
// CDetourFunction
//-----------------------------------------------------------------------------
class CDetourFunction
{
friend class CDetourContext;
public:
CDetourFunction(DetourHandle_t handle, CDetourContext *pContext, void *pDetour, void **ppTrampoline);
bool IsPaused() const;
void *GetDetour() const;
CDetourContext *GetContext() const;
void SetTrampoline(void *pTrampoline);
public:
bool operator==(DetourHandle_t handle) const;
private:
DetourHandle_t m_handle;
CDetourContext *m_pContext;
void *m_pDetour;
void **m_ppTrampoline;
bool m_bPaused;
};
//-----------------------------------------------------------------------------
// CDetourContext
//-----------------------------------------------------------------------------
class CDetourContext
{
public:
CDetourContext(DETOUR_TYPE type, void *pDetourTarget);
~CDetourContext();
bool Init(int iDisasmMinBytes);
// Pause all detours
bool Pause();
bool Unpause();
void InstallDetours();
void RemoveDetours();
public:
DETOUR_TYPE GetType() const;
bool HasDetours() const;
void *GetDetourTarget() const;
public:
CDetourFunction *FindDetourByFunction(void *pDetourFunction);
CDetourFunction *AddDetour(DetourHandle_t hDetour, void *pDetourFunction, void **ppTrampoline, bool bPaused);
bool RemoveDetour(DetourHandle_t hDetour);
bool PauseDetour(DetourHandle_t hDetour);
bool UnpauseDetour(DetourHandle_t hDetour);
private:
DETOUR_TYPE m_type;
std::vector<CDetourFunction *> m_detours;
bool m_bDetoursAttached;
void *m_pFunction;
void *m_pGateway;
int m_nStolenBytes;
unsigned char *m_pOriginalBytes;
unsigned char *m_pPatchedBytes;
};
//-----------------------------------------------------------------------------
// CDetoursAPI implementation
//-----------------------------------------------------------------------------
CDetoursAPI::CDetoursAPI() : m_DetoursTable(48), m_ContextsTable(48)
{
m_iDetourHandles = 0;
m_dwCurrentThreadID = 0;
m_dwCurrentProcessID = 0;
}
CDetoursAPI::~CDetoursAPI()
{
for (int i = 0; i < m_ContextsTable.Count(); i++)
{
HashTableIterator_t it = m_ContextsTable.First(i);
while ( m_ContextsTable.IsValidIterator(it) )
{
delete m_ContextsTable.ValueAt(i, it);
it = m_ContextsTable.Next(i, it);
}
}
m_DetoursTable.Purge();
m_ContextsTable.Purge();
}
void CDetoursAPI::Init()
{
m_dwCurrentThreadID = GetCurrentThreadId();
m_dwCurrentProcessID = GetCurrentProcessId();
}
DetourHandle_t CDetoursAPI::DetourFunction(void *pFunction, void *pDetourFunction, void **ppOriginalFunction, bool bPause /* = false */, int iDisasmMinBytes /* = 5 */)
{
return CreateDetour(DETOUR_FUNCTION, pFunction, pDetourFunction, ppOriginalFunction, bPause, iDisasmMinBytes);
}
DetourHandle_t CDetoursAPI::DetourFunctionByName(HMODULE hModule, const char *pszFunctionName, void *pDetourFunction, void **ppOriginalFunction, bool bPause /* = false */, int iDisasmMinBytes /* = 5 */)
{
void *pFunction = MemoryUtils()->ResolveSymbol(hModule, pszFunctionName);
if ( !pFunction )
return DETOUR_INVALID_HANDLE;
return CreateDetour(DETOUR_FUNCTION, pFunction, pDetourFunction, ppOriginalFunction, bPause, iDisasmMinBytes);
}
DetourHandle_t CDetoursAPI::DetourVirtualFunction(void *pClassInstance, int nFunctionIndex, void *pDetourFunction, void **ppOriginalFunction, bool bPause /* = false */)
{
void *pVTable = *static_cast<void **>(pClassInstance);
if ( !pVTable )
return DETOUR_INVALID_HANDLE;
void *pFunction = (void *)((unsigned long *)pVTable + nFunctionIndex);
return CreateDetour(DETOUR_VTABLE_FUNCTION, pFunction, pDetourFunction, ppOriginalFunction, bPause, 5);
}
bool CDetoursAPI::PauseDetour(DetourHandle_t hDetour)
{
CDetourFunction **ppDetour = m_DetoursTable.Find(hDetour);
if (ppDetour)
{
return (*ppDetour)->GetContext()->PauseDetour(hDetour);
}
return false;
}
bool CDetoursAPI::UnpauseDetour(DetourHandle_t hDetour)
{
CDetourFunction **ppDetour = m_DetoursTable.Find(hDetour);
if (ppDetour)
{
return (*ppDetour)->GetContext()->UnpauseDetour(hDetour);
}
return false;
}
bool CDetoursAPI::RemoveDetour(DetourHandle_t hDetour)
{
CDetourFunction **ppDetour = m_DetoursTable.Find(hDetour);
if (ppDetour)
{
CDetourContext *pContext = (*ppDetour)->GetContext();
bool bRemoved = pContext->RemoveDetour(hDetour);
if (bRemoved)
{
m_DetoursTable.Remove(hDetour);
if ( !pContext->HasDetours() )
{
m_ContextsTable.Remove( pContext->GetDetourTarget() );
delete pContext;
}
return true;
}
}
return false;
}
bool CDetoursAPI::PauseAllDetours()
{
bool bPaused = false;
for (int i = 0; i < m_ContextsTable.Count(); i++)
{
HashTableIterator_t it = m_ContextsTable.First(i);
while ( m_ContextsTable.IsValidIterator(it) )
{
bPaused = m_ContextsTable.ValueAt(i, it)->Pause() || bPaused;
it = m_ContextsTable.Next(i, it);
}
}
return bPaused;
}
bool CDetoursAPI::UnpauseAllDetours()
{
bool bUnpaused = false;
for (int i = 0; i < m_ContextsTable.Count(); i++)
{
HashTableIterator_t it = m_ContextsTable.First(i);
while ( m_ContextsTable.IsValidIterator(it) )
{
bUnpaused = m_ContextsTable.ValueAt(i, it)->Unpause() || bUnpaused;
it = m_ContextsTable.Next(i, it);
}
}
return bUnpaused;
}
DetourHandle_t CDetoursAPI::CreateDetour(DETOUR_TYPE type, void *pFunction, void *pDetourFunction, void **ppOriginalFunction, bool bPause, int iDisasmMinBytes)
{
if ( iDisasmMinBytes < 5 )
{
iDisasmMinBytes = 5;
}
CDetourContext *pContext = NULL;
CDetourContext **pContextEntry = m_ContextsTable.Find(pFunction);
if ( pContextEntry )
{
pContext = *pContextEntry;
if ( !pContext->FindDetourByFunction(pDetourFunction) )
{
CDetourFunction *pDetour = NULL;
DetourHandle_t hDetour = AllocateDetourHandle();
if ( pDetour = pContext->AddDetour( hDetour, pDetourFunction, ppOriginalFunction, bPause ) )
{
m_DetoursTable.Insert( hDetour, pDetour );
return hDetour;
}
}
}
else
{
pContext = new CDetourContext(type, pFunction);
if ( !pContext->Init( iDisasmMinBytes ) )
{
delete pContext;
}
else
{
CDetourFunction *pDetour = NULL;
DetourHandle_t hDetour = AllocateDetourHandle();
m_ContextsTable.Insert( pFunction, pContext );
pDetour = pContext->AddDetour( hDetour, pDetourFunction, ppOriginalFunction, bPause );
if (pDetour)
{
m_DetoursTable.Insert( hDetour, pDetour );
return hDetour;
}
}
}
return DETOUR_INVALID_HANDLE;
}
DetourHandle_t CDetoursAPI::AllocateDetourHandle()
{
return m_iDetourHandles++;
}
void CDetoursAPI::SuspendThreads()
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
THREADENTRY32 te;
te.dwSize = sizeof(te);
if (Thread32First(hSnapshot, &te))
{
do
{
if (te.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) + sizeof(te.th32OwnerProcessID))
{
if (te.th32OwnerProcessID == m_dwCurrentProcessID && te.th32ThreadID != m_dwCurrentThreadID)
{
HANDLE hThread = ::OpenThread(THREAD_ALL_ACCESS, FALSE, te.th32ThreadID);
if (hThread != NULL)
{
m_SuspendedThreads.push_back(te.th32ThreadID);
SuspendThread(hThread);
CloseHandle(hThread);
}
}
}
te.dwSize = sizeof(te);
} while (Thread32Next(hSnapshot, &te));
}
CloseHandle(hSnapshot);
}
}
void CDetoursAPI::ResumeThreads()
{
for (int i = m_SuspendedThreads.size() - 1; i >= 0; --i)
{
HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, m_SuspendedThreads[i]);
if (hThread != NULL)
{
ResumeThread(hThread);
CloseHandle(hThread);
}
}
m_SuspendedThreads.clear();
}
//-----------------------------------------------------------------------------
// Export Detours API
//-----------------------------------------------------------------------------
CDetoursAPI g_DetoursAPI;
CDetoursAPI *DetoursAPI()
{
return &g_DetoursAPI;
}
//-----------------------------------------------------------------------------
// CDetourFunction implementation
//-----------------------------------------------------------------------------
CDetourFunction::CDetourFunction(DetourHandle_t handle, CDetourContext *pContext, void *pDetour, void **ppTrampoline)
{
m_handle = handle;
m_pContext = pContext;
m_pDetour = pDetour;
m_ppTrampoline = ppTrampoline;
m_bPaused = false;
}
inline CDetourContext *CDetourFunction::GetContext() const
{
return m_pContext;
}
inline void *CDetourFunction::GetDetour() const
{
return m_pDetour;
}
inline void CDetourFunction::SetTrampoline(void *pTrampoline)
{
*m_ppTrampoline = pTrampoline;
}
inline bool CDetourFunction::IsPaused() const
{
return m_bPaused;
}
bool CDetourFunction::operator==(DetourHandle_t handle) const
{
return m_handle == handle;
}
//-----------------------------------------------------------------------------
// CDetourContext implementation
//-----------------------------------------------------------------------------
CDetourContext::CDetourContext(DETOUR_TYPE type, void *pDetourTarget)
{
m_type = type;
m_bDetoursAttached = false;
m_pFunction = pDetourTarget;
m_pGateway = NULL;
// DETOUR_FUNCTION
m_nStolenBytes = 0;
m_pOriginalBytes = NULL;
m_pPatchedBytes = NULL;
}
CDetourContext::~CDetourContext()
{
RemoveDetours();
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
if ( m_type == DETOUR_VTABLE_FUNCTION )
pDetour->SetTrampoline( m_pGateway );
else
pDetour->SetTrampoline( m_pFunction );
delete pDetour;
}
if (m_type == DETOUR_FUNCTION)
{
if (m_pOriginalBytes)
{
free((void *)m_pOriginalBytes);
m_pOriginalBytes = m_pPatchedBytes = NULL;
}
if (m_pGateway)
{
MemoryUtils()->VirtualFree(m_pGateway, 0, MEM_RELEASE);
m_pGateway = NULL;
}
}
m_detours.clear();
}
bool CDetourContext::Init(int iDisasmMinBytes)
{
if (m_type == DETOUR_FUNCTION)
{
std::vector<void *> vCalleeFunctions;
m_nStolenBytes = 0;
ud_t instruction;
unsigned char *buffer = (unsigned char *)m_pFunction;
ud_init(&instruction);
ud_set_mode(&instruction, 32);
ud_set_input_buffer(&instruction, (const uint8_t *)buffer, iDisasmMinBytes <= 15 ? 15 : iDisasmMinBytes); // 15 - longest x86 instruction
// Disassemble for JMP opcode
do
{
int disassembledBytes = ud_disassemble(&instruction);
// Save callee functions, then we can calc their relative addresses in gateway
if (instruction.mnemonic == UD_Icall || instruction.mnemonic == UD_Ijmp)
{
unsigned long luRelativeAddress = *(unsigned long *)(buffer + 1);
void *pAbsoluteAddress = (void *)(luRelativeAddress + (unsigned long)buffer + sizeof(void *) + 1);
vCalleeFunctions.push_back( pAbsoluteAddress );
}
buffer += disassembledBytes;
m_nStolenBytes += disassembledBytes;
} while (m_nStolenBytes < iDisasmMinBytes);
int nNOPs = m_nStolenBytes - 5;
// Allocate needed bytes once
m_pOriginalBytes = (unsigned char *)malloc(m_nStolenBytes * 2);
if ( !m_pOriginalBytes )
{
vCalleeFunctions.clear();
return false;
}
m_pPatchedBytes = m_pOriginalBytes + m_nStolenBytes;
memcpy(m_pOriginalBytes, m_pFunction, m_nStolenBytes);
*m_pPatchedBytes = 0xE9; // JMP opcode; relative address will be calculated later
// NOP the rest opcodes, just for safe
if ( nNOPs )
memset(m_pPatchedBytes + 5, 0x90, nNOPs);
// Initializaing the gateway
// Alloc size: m_nStolenBytes + 5 ( JMP [relative offset] )
unsigned char callBytes[5] = { 0xE9 };
m_pGateway = MemoryUtils()->VirtualAlloc(NULL, m_nStolenBytes + sizeof(callBytes), MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if ( !m_pGateway )
{
vCalleeFunctions.clear();
return false;
}
memcpy(m_pGateway, m_pOriginalBytes, m_nStolenBytes);
// Write relative addresses to CALL opcodes
if ( vCalleeFunctions.size() > 0 )
{
int iter = 0;
int disassembledBytes = 0;
buffer = (unsigned char *)m_pGateway;
ud_init(&instruction);
ud_set_mode(&instruction, 32);
ud_set_input_buffer(&instruction, (const uint8_t *)buffer, m_nStolenBytes);
while ( disassembledBytes = ud_disassemble(&instruction) )
{
if (instruction.mnemonic == UD_Icall || instruction.mnemonic == UD_Ijmp)
{
*(unsigned long *)(buffer + 1) = ((unsigned long)vCalleeFunctions[iter] - ((unsigned long)buffer + sizeof(void *) + 1));
++iter;
}
buffer += disassembledBytes;
}
}
// Calc relative address to jump back to original function
*(unsigned long *)(callBytes + 1) = ((unsigned long)m_pFunction + m_nStolenBytes) - (((unsigned long)m_pGateway + m_nStolenBytes) + sizeof(void *) + 1);
// And copy it
memcpy((unsigned char *)m_pGateway + m_nStolenBytes, callBytes, sizeof(callBytes));
vCalleeFunctions.clear();
return true;
}
else if (m_type == DETOUR_VTABLE_FUNCTION)
{
m_pGateway = *static_cast<void **>(m_pFunction);
return true;
}
return false;
}
bool CDetourContext::Pause()
{
bool bPaused = false;
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
if ( !pDetour->IsPaused() )
{
bPaused = true;
pDetour->m_bPaused = true;
}
}
if ( bPaused )
{
InstallDetours();
}
return bPaused;
}
bool CDetourContext::Unpause()
{
bool bUnpaused = false;
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
if ( pDetour->IsPaused() )
{
bUnpaused = true;
pDetour->m_bPaused = false;
}
}
if ( bUnpaused )
{
InstallDetours();
}
return bUnpaused;
}
void CDetourContext::InstallDetours()
{
CDetourFunction *pFirstDetour = NULL;
CDetourFunction *pLastDetour = NULL;
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
if ( !pDetour->IsPaused() )
{
if ( !pFirstDetour )
pFirstDetour = pDetour;
if ( pLastDetour )
{
pLastDetour->SetTrampoline( pDetour->GetDetour() );
}
pLastDetour = pDetour;
}
}
if ( !pFirstDetour )
{
RemoveDetours();
return;
}
int dwProtection;
if (m_type == DETOUR_FUNCTION)
{
g_DetoursAPI.SuspendThreads();
// Relative address
*(unsigned long *)(m_pPatchedBytes + 1) = (unsigned long)pFirstDetour->GetDetour() - ((unsigned long)m_pFunction + sizeof(void *) + 1);
MemoryUtils()->VirtualProtect(m_pFunction, m_nStolenBytes, PAGE_EXECUTE_READWRITE, &dwProtection);
memcpy(m_pFunction, m_pPatchedBytes, m_nStolenBytes);
MemoryUtils()->VirtualProtect(m_pFunction, m_nStolenBytes, dwProtection, NULL);
g_DetoursAPI.ResumeThreads();
}
else if (m_type == DETOUR_VTABLE_FUNCTION)
{
MemoryUtils()->VirtualProtect(m_pFunction, sizeof(void *), PAGE_EXECUTE_READWRITE, &dwProtection);
*(void **)(m_pFunction) = pFirstDetour->GetDetour();
MemoryUtils()->VirtualProtect(m_pFunction, sizeof(void *), dwProtection, NULL);
}
pLastDetour->SetTrampoline( m_pGateway );
m_bDetoursAttached = true;
}
void CDetourContext::RemoveDetours()
{
if ( !m_bDetoursAttached )
return;
int dwProtection;
if (m_type == DETOUR_FUNCTION)
{
g_DetoursAPI.SuspendThreads();
MemoryUtils()->VirtualProtect(m_pFunction, m_nStolenBytes, PAGE_EXECUTE_READWRITE, &dwProtection);
memcpy(m_pFunction, m_pOriginalBytes, m_nStolenBytes);
MemoryUtils()->VirtualProtect(m_pFunction, m_nStolenBytes, dwProtection, NULL);
g_DetoursAPI.ResumeThreads();
}
else if (m_type == DETOUR_VTABLE_FUNCTION)
{
MemoryUtils()->VirtualProtect(m_pFunction, sizeof(void *), PAGE_EXECUTE_READWRITE, &dwProtection);
*(void **)(m_pFunction) = m_pGateway;
MemoryUtils()->VirtualProtect(m_pFunction, sizeof(void *), dwProtection, NULL);
}
if (m_type == DETOUR_VTABLE_FUNCTION)
{
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
pDetour->SetTrampoline(m_pGateway);
}
}
else
{
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
pDetour->SetTrampoline(m_pFunction);
}
}
m_bDetoursAttached = false;
}
inline bool CDetourContext::HasDetours() const
{
return m_detours.size() > 0;
}
inline void *CDetourContext::GetDetourTarget() const
{
return m_pFunction;
}
inline DETOUR_TYPE CDetourContext::GetType() const
{
return m_type;
}
CDetourFunction *CDetourContext::FindDetourByFunction(void *pDetourFunction)
{
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
if ( pDetour->GetDetour() == pDetourFunction )
return pDetour;
}
return NULL;
}
CDetourFunction *CDetourContext::AddDetour(DetourHandle_t hDetour, void *pDetourFunction, void **ppTrampoline, bool bPaused)
{
CDetourFunction *pDetour = new CDetourFunction(hDetour, this, pDetourFunction, ppTrampoline);
if ( !pDetour )
return NULL;
m_detours.push_back(pDetour);
if (bPaused)
pDetour->m_bPaused = true;
else
InstallDetours();
return pDetour;
}
bool CDetourContext::RemoveDetour(DetourHandle_t hDetour)
{
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
if ( *pDetour == hDetour )
{
bool bPaused = pDetour->IsPaused();
delete pDetour;
m_detours.erase(m_detours.begin() + i);
if ( !bPaused )
InstallDetours();
return true;
}
}
return false;
}
bool CDetourContext::PauseDetour(DetourHandle_t hDetour)
{
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
if ( *pDetour == hDetour )
{
if ( pDetour->IsPaused() )
return false;
pDetour->m_bPaused = true;
InstallDetours();
return true;
}
}
return false;
}
bool CDetourContext::UnpauseDetour(DetourHandle_t hDetour)
{
FOR_EACH_DETOUR(i)
{
CDetourFunction *pDetour = m_detours[i];
if ( *pDetour == hDetour )
{
if ( !pDetour->IsPaused() )
return false;
pDetour->m_bPaused = false;
InstallDetours();
return true;
}
}
return false;
}