forked from adtools/clib2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hook_boopsi_functions.c
384 lines (304 loc) · 7.12 KB
/
test_hook_boopsi_functions.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
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
// Checks the hook and boopsi support functions: CallHookA, CallHook, DoMethodA, DoMethod, DoSuperMethodA, DoSuperMethod, CoerceMethodA, CoerceMethod, HookEntry, SetSuperAttrs
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <clib/alib_protos.h>
#include <string.h>
extern struct ExecBase *SysBase;
extern struct IntuitionBase *IntuitionBase;
extern struct DosLibrary *DOSBase;
extern struct UtilityBase *UtilityBase;
#define ALPHA_TAG (TAG_USER + 1)
#define BETA_TAG (TAG_USER + 2)
#define GAMMA_TAG (TAG_USER + 3)
#define DELTA_TAG (TAG_USER + 4)
#define OBJECT_VALUE_1 256
#define OBJECT_VALUE_2 1000
#define OBJECT_VALUE_3 64
#define OBJECT_VALUE_4 128
#define OBJECT_VALUE_5 2000
#define OBJECT_VALUE_6 3000
struct Class1Data {
ULONG alpha;
ULONG beta;
};
struct Class2Data {
ULONG gamma;
ULONG delta;
};
static ULONG dispatcherClass1(Class *cl,Object *o,Msg msg)
{
struct Class1Data *data;
struct TagItem *tstate,*ti;
APTR retval = NULL;
switch(msg->MethodID)
{
case OM_NEW:
if(retval = (APTR)DoSuperMethodA(cl,o,msg))
{
data = INST_DATA(cl,retval);
data->alpha = GetTagData(ALPHA_TAG,0L,((struct opSet *)msg)->ops_AttrList);
data->beta = GetTagData(BETA_TAG,0L,((struct opSet *)msg)->ops_AttrList);
}
break;
case OM_SET:
case OM_UPDATE:
data = INST_DATA(cl,o);
DoSuperMethodA(cl,o,msg);
ti = ((struct opSet *)msg)->ops_AttrList;
tstate = ti;
while(ti = NextTagItem(&tstate))
{
switch (ti->ti_Tag)
{
case ALPHA_TAG:
data->alpha = ti->ti_Data;
break;
case BETA_TAG:
data->beta = ti->ti_Data;
break;
}
}
break;
case OM_GET:
data = INST_DATA(cl,o);
switch(((struct opGet *)msg)->opg_AttrID)
{
case ALPHA_TAG:
*(((struct opGet *)msg)->opg_Storage) = data->alpha;
retval = (Object *)TRUE;
break;
case BETA_TAG:
*(((struct opGet *)msg)->opg_Storage) = data->beta;
retval = (Object *)TRUE;
break;
default:
retval = (APTR)DoSuperMethodA(cl,o,msg);
break;
}
break;
default: // includes OM_DISPOSE
retval = (APTR)DoSuperMethodA(cl,o,msg);
break;
}
return((ULONG)retval);
}
static ULONG dispatcherClass2(Class *cl,Object *o,Msg msg)
{
struct Class2Data *data;
struct TagItem *tstate,*ti;
APTR retval = NULL;
switch (msg->MethodID)
{
case OM_NEW:
if(retval = (APTR)DoSuperMethodA(cl,o,msg))
{
data = INST_DATA(cl,retval);
data->gamma = GetTagData(GAMMA_TAG,0L,((struct opSet *)msg)->ops_AttrList);
data->delta = GetTagData(DELTA_TAG,0L,((struct opSet *)msg)->ops_AttrList);
}
break;
case OM_SET:
case OM_UPDATE:
data = INST_DATA(cl,o);
DoSuperMethodA(cl,o,msg);
ti = ((struct opSet *)msg)->ops_AttrList;
tstate = ti;
while(ti = NextTagItem(&tstate))
{
switch (ti->ti_Tag)
{
case GAMMA_TAG:
data->gamma = ti->ti_Data;
break;
case DELTA_TAG:
data->delta = ti->ti_Data;
break;
}
}
break;
case OM_GET:
data = INST_DATA(cl,o);
switch(((struct opGet *)msg)->opg_AttrID)
{
case GAMMA_TAG:
*(((struct opGet *)msg)->opg_Storage) = data->gamma;
retval = (Object *)TRUE;
break;
case DELTA_TAG:
*(((struct opGet *)msg)->opg_Storage) = data->delta;
retval = (Object *)TRUE;
break;
default:
retval = (APTR)DoSuperMethodA(cl,o,msg);
break;
}
break;
default: // includes OM_DISPOSE
retval = (APTR)DoSuperMethodA(cl,o,msg);
break;
}
return((ULONG)retval);
}
WORD testHookBoopsiFunctions(void)
{
Class *cl1 = NULL,*cl2 = NULL;
Object *obj = NULL;
ULONG val;
WORD errCnt = 0;
struct opGet getVal;
cl1 = MakeClass(NULL,"rootclass",NULL,sizeof(struct Class1Data),0L);
if(cl1 == NULL)
{
errCnt++;
goto end;
}
cl1->cl_Dispatcher.h_Entry = HookEntry;
cl1->cl_Dispatcher.h_SubEntry = dispatcherClass1;
cl2 = MakeClass(NULL,NULL,cl1,sizeof(struct Class2Data),0L);
if(cl2 == NULL)
{
errCnt++;
goto end;
}
cl2->cl_Dispatcher.h_Entry = HookEntry;
cl2->cl_Dispatcher.h_SubEntry = dispatcherClass2;
// Create the object
obj = NewObject(cl2,NULL,ALPHA_TAG,OBJECT_VALUE_1,BETA_TAG,OBJECT_VALUE_2,GAMMA_TAG,OBJECT_VALUE_3,DELTA_TAG,OBJECT_VALUE_4,TAG_END);
if(obj == NULL)
{
errCnt++;
goto end;
}
// Get a value from the super class
DoMethod(obj,OM_GET,ALPHA_TAG,&val);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_1)
{
errCnt++;
}
// Get a value from the class
DoMethod(obj,OM_GET,GAMMA_TAG,&val);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_3)
{
errCnt++;
}
// Get the other value from the super class
getVal.MethodID = OM_GET;
getVal.opg_AttrID = BETA_TAG;
getVal.opg_Storage = &val;
DoMethodA(obj,(Msg)&getVal);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_2)
{
errCnt++;
}
// Get the other value from the class
getVal.MethodID = OM_GET;
getVal.opg_AttrID = DELTA_TAG;
getVal.opg_Storage = &val;
DoMethodA(obj,(Msg)&getVal);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_4)
{
errCnt++;
}
// Get a value directly from the super class
DoSuperMethod(cl2,obj,OM_GET,ALPHA_TAG,&val);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_1)
{
errCnt++;
}
// Get the other value directly from the super class
getVal.MethodID = OM_GET;
getVal.opg_AttrID = BETA_TAG;
getVal.opg_Storage = &val;
DoSuperMethodA(cl2,obj,(Msg)&getVal);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_2)
{
errCnt++;
}
// Get a value directly from the super class
CoerceMethod(cl1,obj,OM_GET,ALPHA_TAG,&val);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_1)
{
errCnt++;
}
// Get the other value directly from the super class
getVal.MethodID = OM_GET;
getVal.opg_AttrID = BETA_TAG;
getVal.opg_Storage = &val;
CoerceMethodA(cl1,obj,(Msg)&getVal);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_2)
{
errCnt++;
}
// Set the values directly in the super class
SetSuperAttrs(cl2,obj,ALPHA_TAG,OBJECT_VALUE_5,BETA_TAG,OBJECT_VALUE_6,TAG_END);
CoerceMethod(cl1,obj,OM_GET,ALPHA_TAG,&val); // we read the value back directly from the super class
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_5)
{
errCnt++;
}
CoerceMethod(cl1,obj,OM_GET,BETA_TAG,&val);
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_6)
{
errCnt++;
}
CallHook(&cl1->cl_Dispatcher,obj,OM_GET,ALPHA_TAG,&val); // CoerceMethod
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_5)
{
errCnt++;
}
getVal.MethodID = OM_GET;
getVal.opg_AttrID = BETA_TAG;
getVal.opg_Storage = &val;
CallHookA(&cl1->cl_Dispatcher,obj,&getVal); // CoerceMethod
#if OPTION_TRACE
Printf("val = %lu\n",val);
#endif
if(val != OBJECT_VALUE_6)
{
errCnt++;
}
end:
if(obj != NULL)
DisposeObject(obj);
if(cl2 != NULL)
FreeClass(cl2);
if(cl1 != NULL)
FreeClass(cl1);
return(errCnt);
}