/
VFTHook.cpp
69 lines (51 loc) · 1.3 KB
/
VFTHook.cpp
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
#include "VFTHook.hpp"
std::unique_ptr<VFTHook> g_pPanelHook;
VFTHook::VFTHook ( void*** class_ )
{
if ( !class_ )
Dispose ( );
m_class = class_;
if ( !*m_class )
Dispose ( );
m_originalTable = *m_class;
m_functionNumber = GetFunctionNumber ( );
if ( m_functionNumber <= 0 )
Dispose ( );
m_replaceTable = new void* [ m_functionNumber ];
if ( !m_replaceTable )
Dispose ( );
memcpy_s ( m_replaceTable, sizeof ( void* ) * m_functionNumber, m_originalTable, sizeof ( void* ) * m_functionNumber );
printf_s ( "m_class = %p\n", m_class );
printf_s ( "m_originalTable = %p\n", m_originalTable );
printf_s ( "m_functionNumber = %d\n", m_functionNumber );
printf_s ( "m_replaceTable: %p\n", m_replaceTable );
*m_class = m_replaceTable;
}
VFTHook::~VFTHook ( )
{
if ( *m_class == m_replaceTable )
*m_class = m_originalTable;
if ( m_replaceTable )
{
delete m_replaceTable;
m_replaceTable = nullptr;
}
}
size_t VFTHook::GetFunctionNumber ( ) const
{
size_t counter = 0;
while ( m_originalTable [ counter ] )
counter++;
return counter;
}
void VFTHook::Dispose ( ) const
{
if ( *m_class == m_replaceTable )
*m_class = m_originalTable;
if ( m_replaceTable )
{
delete m_replaceTable;
m_replaceTable;
}
delete this;
}