-
Notifications
You must be signed in to change notification settings - Fork 3
/
vtable.c
212 lines (160 loc) · 5.61 KB
/
vtable.c
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
#include "all.h"
static int vidx_CBaseEntity_GetBaseEntity = -1;
static int vidx_CBaseEntity_IsAlive = -1;
static int vidx_CBaseEntity_IsPlayer = -1;
static int vidx_CBasePlayer_CommitSuicide = -1;
static int vidx_CBasePlayer_IsBot = -1;
static int vidx_CBaseMultiplayerPlayer_SpeakConceptIfAllowed = -1;
static int vidx_CTFWeaponBase_GetWeaponID = -1;
static int vidx_CBaseCombatWeapon_SetWeaponVisible = -1;
static int vidx_INextBotComponent_GetBot = -1;
static int vidx_CTFBotMainAction_GetName = -1;
static int vtable_find_index_mem(void **vtable, size_t size, void *pfunc)
{
vtable += 2;
size -= 2 * sizeof(*vtable);
pr_info("%s\n", __func__);
pr_debug(
" vtable @ %08x\n"
" size: %04x\n"
" (%d entries)\n",
(uintptr_t)vtable,
size,
size / 4);
int count = size / 4;
for (int i = 0; i < count; ++i) {
if (vtable[i] == pfunc) {
return i;
}
}
return -1;
}
static int vtable_find_index_sym(const char *sym_name, void *pfunc)
{
void **vtable;
size_t size;
symtab_obj_absolute(sym_name, (void **)&vtable, &size);
return vtable_find_index_mem(vtable, size, pfunc);
}
int vtable_find_offset(const char *sym_name, void *pfunc)
{
int idx = vtable_find_index_sym(sym_name, pfunc);
if (idx != -1) {
return 4 * idx;
} else {
return idx;
}
}
void vtable_init(void)
{
assert((vidx_CBaseEntity_GetBaseEntity =
vtable_find_index_sym("_ZTV11CBaseEntity",
CBaseEntity_GetBaseEntity)) != -1);
assert((vidx_CBaseEntity_IsAlive =
vtable_find_index_sym("_ZTV11CBaseEntity",
CBaseEntity_IsAlive)) != -1);
assert((vidx_CBaseEntity_IsPlayer =
vtable_find_index_sym("_ZTV11CBaseEntity",
CBaseEntity_IsPlayer)) != -1);
assert((vidx_CBasePlayer_CommitSuicide =
vtable_find_index_sym("_ZTV11CBasePlayer",
CBasePlayer_CommitSuicide)) != -1);
assert((vidx_CBasePlayer_IsBot =
vtable_find_index_sym("_ZTV11CBasePlayer",
CBasePlayer_IsBot)) != -1);
assert((vidx_CBaseMultiplayerPlayer_SpeakConceptIfAllowed =
vtable_find_index_sym("_ZTV22CBaseMultiplayerPlayer",
CBaseMultiplayerPlayer_SpeakConceptIfAllowed)) != -1);
assert((vidx_CTFWeaponBase_GetWeaponID =
vtable_find_index_sym("_ZTV13CTFWeaponBase",
CTFWeaponBase_GetWeaponID)) != -1);
assert((vidx_CBaseCombatWeapon_SetWeaponVisible =
vtable_find_index_sym("_ZTV17CBaseCombatWeapon",
CBaseCombatWeapon_SetWeaponVisible)) != -1);
assert((vidx_INextBotComponent_GetBot =
vtable_find_index_sym("_ZTV17INextBotComponent",
INextBotComponent_GetBot)) != -1);
assert((vidx_CTFBotMainAction_GetName =
vtable_find_index_sym("_ZTV16CTFBotMainAction",
CTFBotMainAction_GetName)) != -1);
}
CBaseEntity* vcall_IServerUnknown_GetBaseEntity(IServerUnknown* this)
{
void **vtable = *((void ***)this);
int vidx = vidx_CBaseEntity_GetBaseEntity;
assert(vidx != -1);
CBaseEntity* (*vfunc)(IServerUnknown*) = vtable[vidx];
return vfunc(this);
}
bool vcall_CBaseEntity_IsAlive(CBaseEntity* this)
{
void **vtable = *((void ***)this);
int vidx = vidx_CBaseEntity_IsAlive;
assert(vidx != -1);
bool (*vfunc)(CBaseEntity*) = vtable[vidx];
return vfunc(this);
}
bool vcall_CBaseEntity_IsPlayer(CBaseEntity* this)
{
void **vtable = *((void ***)this);
int vidx = vidx_CBaseEntity_IsPlayer;
assert(vidx != -1);
bool (*vfunc)(CBaseEntity*) = vtable[vidx];
return vfunc(this);
}
void vcall_CBasePlayer_CommitSuicide(CBasePlayer* this, bool bExplode, bool bForce)
{
void **vtable = *((void ***)this);
int vidx = vidx_CBasePlayer_CommitSuicide;
assert(vidx != -1);
void (*vfunc)(CBasePlayer*, bool, bool) = vtable[vidx];
return vfunc(this, bExplode, bForce);
}
bool vcall_CBasePlayer_IsBot(CBasePlayer* this)
{
void **vtable = *((void ***)this);
int vidx = vidx_CBasePlayer_IsBot;
assert(vidx != -1);
bool (*vfunc)(CBasePlayer*) = vtable[vidx];
return vfunc(this);
}
bool vcall_CBaseMultiplayerPlayer_SpeakConceptIfAllowed(CBaseMultiplayerPlayer* this, int iConcept, const char *modifiers, char *pszOutResponseChosen, size_t bufsize, IRecipientFilter* filter)
{
void **vtable = *((void ***)this);
int vidx = vidx_CBaseMultiplayerPlayer_SpeakConceptIfAllowed;
assert(vidx != -1);
bool (*vfunc)(CBaseMultiplayerPlayer*, int, char const*, char*, size_t, IRecipientFilter*) = vtable[vidx];
return vfunc(this, iConcept, modifiers, pszOutResponseChosen, bufsize, filter);
}
int vcall_CTFWeaponBase_GetWeaponID(CTFWeaponBase* this)
{
void **vtable = *((void ***)this);
int vidx = vidx_CTFWeaponBase_GetWeaponID;
assert(vidx != -1);
int (*vfunc)(CTFWeaponBase*) = vtable[vidx];
return vfunc(this);
}
void vcall_CBaseCombatWeapon_SetWeaponVisible(CBaseCombatWeapon* this, bool visible)
{
void **vtable = *((void ***)this);
int vidx = vidx_CBaseCombatWeapon_SetWeaponVisible;
assert(vidx != -1);
void (*vfunc)(CBaseCombatWeapon*, bool) = vtable[vidx];
vfunc(this, visible);
}
INextBot* vcall_INextBotComponent_GetBot(INextBotComponent* this)
{
void **vtable = *((void ***)this);
int vidx = vidx_INextBotComponent_GetBot;
assert(vidx != -1);
INextBot* (*vfunc)(INextBotComponent*) = vtable[vidx];
return vfunc(this);
}
char const* vcall_Action_CTFBot_GetName(Action_CTFBot* this)
{
void **vtable = *((void ***)this);
int vidx = vidx_CTFBotMainAction_GetName;
assert(vidx != -1);
char const* (*vfunc)(Action_CTFBot*) = vtable[vidx];
return vfunc(this);
}