-
Notifications
You must be signed in to change notification settings - Fork 29
/
reactos.c
473 lines (346 loc) · 9.29 KB
/
reactos.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
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
/*
Copyright (C) 2011 Jay Satiro <[email protected]>
All rights reserved.
This file is part of GetHooks.
GetHooks is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GetHooks is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GetHooks. If not, see <https://www.gnu.org/licenses/>.
*/
/**
This file contains functions for printing the structs I'm using from the ReactOS project.
Each function is documented in the comment block above its definition.
-
w_handlenames[], w_handlenames_count
An array of user-readable wide names of HANDLEENTRY types.
-
-
print_HANDLEENTRY_type()
Print user-readable name of a HANDLEENTRY's type. No newline.
-
-
print_HANDLEENTRY_flags()
Print user-readable names of a HANDLEENTRY's flags. No newline.
-
-
print_HANDLEENTRY()
Print a HANDLEENTRY struct.
-
-
w_hooknames[], w_hooknames_count
An array of user-readable wide names of HOOK ids. Add 1 to an id to get its position in the index.
-
-
print_HOOK_id()
Print user-readable name of a HOOK's id. No newline.
-
-
print_HOOK_flags()
Print user-readable names of a HOOK's flags. No newline.
-
-
print_HOOK_anomalies()
Print any anomalies found in a HOOK struct.
-
-
print_HOOK()
Print a HOOK struct.
-
-
get_HOOK_name_from_id()
Get the HOOK name from its id.
-
-
get_HOOK_id_from_name()
Get the HOOK id from its name.
-
*/
#include <stdio.h>
#include "util.h"
#include "reactos.h"
/* w_handlenames[]
An array of user-readable wide names of HANDLEENTRY types.
*/
const WCHAR *const w_handlenames[ 23 ] =
{
L"TYPE_FREE",
L"TYPE_WINDOW",
L"TYPE_MENU",
L"TYPE_CURSOR",
L"TYPE_SETWINDOWPOS",
L"TYPE_HOOK",
L"TYPE_CLIPDATA",
L"TYPE_CALLPROC",
L"TYPE_ACCELTABLE",
L"TYPE_DDEACCESS",
L"TYPE_DDECONV",
L"TYPE_DDEXACT",
L"TYPE_MONITOR",
L"TYPE_KBDLAYOUT",
L"TYPE_KBDFILE",
L"TYPE_WINEVENTHOOK",
L"TYPE_TIMER",
L"TYPE_INPUTCONTEXT",
L"TYPE_HIDDATA",
L"TYPE_DEVICEINFO",
L"TYPE_TOUCHINPUT",
L"TYPE_GESTUREINFO",
L"TYPE_CTYPES"
};
/* initialize to number of elements in w_handlenames[]: */
const unsigned w_handlenames_count = sizeof( w_handlenames ) / sizeof( w_handlenames[ 0 ] );
/* print_HANDLEENTRY_type()
Print user-readable name of a HANDLEENTRY's type. No newline.
*/
void print_HANDLEENTRY_type(
const BYTE bType // in
)
{
if( ( bType >= 0 ) && ( bType < w_handlenames_count ) )
printf( "%ls ", w_handlenames[ bType ] );
else
printf( "<%u> ", (unsigned)bType );
return;
}
/* print_HANDLEENTRY_flags()
Print user-readable names of a HANDLEENTRY's flags. No newline.
if 'bFlags' is 0 this function returns without having printed anything.
*/
void print_HANDLEENTRY_flags(
const BYTE bFlags // in
)
{
if( !bFlags )
return;
if( bFlags & HANDLEF_DESTROY )
printf( "HANDLEF_DESTROY " );
if( bFlags & HANDLEF_INDESTROY )
printf( "HANDLEF_INDESTROY " );
if( bFlags & HANDLEF_INWAITFORDEATH )
printf( "HANDLEF_INWAITFORDEATH " );
if( bFlags & HANDLEF_FINALDESTROY )
printf( "HANDLEF_FINALDESTROY " );
if( bFlags & HANDLEF_MARKED_OK )
printf( "HANDLEF_MARKED_OK " );
if( bFlags & HANDLEF_GRANTED )
printf( "HANDLEF_GRANTED " );
if( bFlags & ~(unsigned)HANDLEF_VALID )
printf( "<0x%02X> ", (unsigned)( bFlags & ~(unsigned)HANDLEF_VALID ) );
return;
}
/* print_HANDLEENTRY()
Print a HANDLEENTRY struct.
if 'entry' is NULL this function returns without having printed anything.
*/
void print_HANDLEENTRY(
const HANDLEENTRY *const entry // in
)
{
const char *const objname = "HANDLEENTRY struct";
if( !entry )
return;
PRINT_SEP_BEGIN( objname );
PRINT_HEX( entry->pHead );
PRINT_HEX( entry->pOwner );
printf( "entry->bType: %u ( ", (unsigned)entry->bType );
print_HANDLEENTRY_type( entry->bType );
printf( ")\n" );
printf( "entry->bFlags: 0x%02X", (unsigned)entry->bFlags );
if( entry->bFlags )
{
printf( " ( " );
print_HANDLEENTRY_flags( entry->bFlags );
printf( ")" );
}
printf( "\n" );
printf( "entry->wUniq: %u\n", (unsigned)entry->wUniq );
PRINT_SEP_END( objname );
return;
}
/* w_hooknames[]
An array of user-readable wide names of HOOK ids. Add 1 to an id to get its position in the index.
*/
const WCHAR *const w_hooknames[ 16 ] =
{
L"WH_MSGFILTER", // id -1
L"WH_JOURNALRECORD", // id 0
L"WH_JOURNALPLAYBACK", // id 1
L"WH_KEYBOARD", // id 2
L"WH_GETMESSAGE", // id 3
L"WH_CALLWNDPROC", // id 4
L"WH_CBT", // id 5
L"WH_SYSMSGFILTER", // id 6
L"WH_MOUSE", // id 7
L"WH_HARDWARE", // id 8
L"WH_DEBUG", // id 9
L"WH_SHELL", // id 10
L"WH_FOREGROUNDIDLE", // id 11
L"WH_CALLWNDPROCRET", // id 12
L"WH_KEYBOARD_LL", // id 13
L"WH_MOUSE_LL" // id 14
};
/* initialize to number of elements in w_hooknames[]: */
const unsigned w_hooknames_count = sizeof( w_hooknames ) / sizeof( w_hooknames[ 0 ] );
/* print_HOOK_id()
Print user-readable name of a HOOK's id. No newline.
*/
void print_HOOK_id(
const INT iHook // in
)
{
const unsigned index = (unsigned)( iHook + 1 ); /* the array index is the same as id + 1 */
if( index < w_hooknames_count )
printf( "%ls ", w_hooknames[ index ] );
else
printf( "<%d> ", iHook );
return;
}
/* print_HOOK_flags()
Print user-readable names of a HOOK's flags. No newline.
if 'flags' is NULL this function returns without having printed anything.
*/
void print_HOOK_flags(
const DWORD flags // in
)
{
if( !flags )
return;
if( flags & HF_GLOBAL )
printf( "HF_GLOBAL " );
if( flags & HF_ANSI )
printf( "HF_ANSI " );
if( flags & HF_NEEDHC_SKIP )
printf( "HF_NEEDHC_SKIP " );
if( flags & HF_HUNG )
printf( "HF_HUNG " );
if( flags & HF_HOOKFAULTED )
printf( "HF_HOOKFAULTED " );
if( flags & HF_NOPLAYBACKDELAY )
printf( "HF_NOPLAYBACKDELAY " );
if( flags & HF_WX86KNOWINDOWLL )
printf( "HF_WX86KNOWINDOWLL " );
if( flags & HF_DESTROYED )
printf( "HF_DESTROYED " );
if( flags & ~(DWORD)HF_VALID )
printf( "<0x%08lX> ", (DWORD)( flags & ~(DWORD)HF_VALID ) );
return;
}
/* print_HOOK_anomalies()
Print any anomalies found in a HOOK struct.
if 'object' is NULL this function returns without having printed anything.
*/
void print_HOOK_anomalies(
const HOOK *const object // in
)
{
if( !object )
return;
if( !( object->flags & HF_GLOBAL )
&& ( ( object->iHook == WH_JOURNALPLAYBACK )
|| ( object->iHook == WH_JOURNALRECORD )
|| ( object->iHook == WH_KEYBOARD_LL )
|| ( object->iHook == WH_MOUSE_LL )
|| ( object->iHook == WH_SYSMSGFILTER )
)
)
{
printf( "ERROR: The HOOK @ " );
PRINT_HEX_BARE( object->pSelf );
printf( " is supposed to be global-only but is missing the HF_GLOBAL flag!\n" );
}
if( ( object->flags & HF_GLOBAL ) && object->ptiHooked )
{
printf( "ERROR: The global HOOK @ " );
PRINT_HEX_BARE( object->pSelf );
printf( " has a target address even though global HOOKs aren't supposed to have them.\n" );
}
return;
}
/* print_HOOK()
Print a HOOK struct.
if 'object' is NULL this function returns without having printed anything.
*/
void print_HOOK(
const HOOK *const object // in
)
{
const char *const objname = "HOOK struct";
if( !object )
return;
PRINT_SEP_BEGIN( objname );
PRINT_HEX( object->head.h );
printf( "object->head.cLockObj: %u\n", object->head.cLockObj );
PRINT_HEX( object->pti );
PRINT_HEX( object->rpdesk1 );
PRINT_HEX( object->pSelf );
PRINT_HEX( object->phkNext );
printf( "object->iHook: %d ( ", object->iHook );
print_HOOK_id( object->iHook );
printf( ")\n" );
PRINT_HEX( object->offPfn );
printf( "object->flags: 0x%08X", object->flags );
if( object->flags )
{
printf( " ( " );
print_HOOK_flags( object->flags );
printf( ")" );
}
printf( "\n" );
printf( "object->ihmod: %d\n", object->ihmod );
PRINT_HEX( object->ptiHooked );
PRINT_HEX( object->rpdesk2 );
PRINT_SEP_END( objname );
return;
}
/* get_HOOK_name_from_id()
Get the HOOK name from its id.
'id' is the HOOK id you want the name of.
returns nonzero on success.
if success then '*name' has received a pointer to the HOOK name. free() when done.
if fail then '*name' has received NULL.
*/
int get_HOOK_name_from_id(
const WCHAR **const name, // out deref
const int id // in
)
{
const unsigned index = (unsigned)( id + 1 ); /* the array index is the same as id + 1 */
FAIL_IF( !name );
*name = NULL;
if( index < w_hooknames_count )
*name = must_wcsdup( w_hooknames[ index ] );
return !!*name;
}
/* get_HOOK_id_from_name()
Get the HOOK id from its name.
'name' is the HOOK name you want the id of.
returns nonzero on success.
if success then '*id' has received the HOOK id.
if fail then '*id' has received INT_MAX.
*/
int get_HOOK_id_from_name(
int *const id, // out
const WCHAR *const name // in
)
{
unsigned index = 0;
FAIL_IF( !id );
FAIL_IF( !name );
*id = INT_MAX;
for( index = 0; index < w_hooknames_count; ++index )
{
if( !_wcsicmp( name, w_hooknames[ index ] ) ) // match
{
/* the id is the same as the index in the array - 1 */
*id = index - 1;
break;
}
}
return ( *id != INT_MAX );
}