[SHIMENG] Filter shims based on the include/exclude node specified, as well as their...
[reactos.git] / reactos / dll / appcompat / apphelp / shimeng.h
1 /*
2 * Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #ifndef SHIMENG_H
20 #define SHIMENG_H
21
22 /* This header is ReactOS specific */
23
24 /* Structure that allows dynamic growing.
25 Be aware, the data may move! */
26 typedef struct _ARRAY
27 {
28 PVOID Data__;
29 DWORD Size__;
30 DWORD MaxSize__;
31 DWORD ItemSize__;
32 } ARRAY, *PARRAY;
33
34 typedef struct _SHIMINFO *PSHIMINFO;
35 typedef struct _SHIMMODULE *PSHIMMODULE;
36
37 /* Shims know this structure as HOOKAPI, with 2 reserved members (the last 2). */
38 typedef struct tagHOOKAPIEX
39 {
40 PCSTR LibraryName;
41 PCSTR FunctionName;
42 PVOID ReplacementFunction;
43 PVOID OriginalFunction;
44 PSHIMINFO pShimInfo;
45 PVOID Unused;
46 } HOOKAPIEX, *PHOOKAPIEX;
47
48 C_ASSERT(sizeof(HOOKAPIEX) == sizeof(HOOKAPI));
49 C_ASSERT(offsetof(HOOKAPIEX, pShimInfo) == offsetof(HOOKAPI, Reserved));
50
51 typedef struct _INEXCLUDE
52 {
53 UNICODE_STRING Module;
54 BOOL Include;
55 } INEXCLUDE, *PINEXCLUDE;
56
57 typedef struct _SHIMINFO
58 {
59 PCWSTR ShimName;
60 PHOOKAPIEX pHookApi;
61 DWORD dwHookCount;
62 PSHIMMODULE pShimModule;
63 ARRAY InExclude; /* INEXCLUDE */
64 } SHIMINFO, *PSHIMINFO;
65
66 typedef struct _SHIMMODULE
67 {
68 UNICODE_STRING Name;
69 PVOID BaseAddress;
70
71 PHOOKAPIEX (WINAPI* pGetHookAPIs)(LPCSTR szCommandLine, LPCWSTR wszShimName, PDWORD pdwHookCount);
72 BOOL (WINAPI* pNotifyShims)(DWORD fdwReason, PVOID ptr);
73
74 ARRAY EnabledShims; /* PSHIMINFO */
75 } SHIMMODULE, *PSHIMMODULE;
76
77 typedef struct _HOOKMODULEINFO
78 {
79 UNICODE_STRING Name;
80 PVOID BaseAddress;
81
82 ARRAY HookApis; /* PHOOKAPIEX */
83
84 } HOOKMODULEINFO, *PHOOKMODULEINFO;
85
86
87 #if SDBAPI_DEBUG_ALLOC
88
89 LPVOID SdbpAlloc(SIZE_T size, int line, const char* file);
90 LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, SIZE_T oldSize, int line, const char* file);
91 VOID SdbpFree(LPVOID mem, int line, const char* file);
92
93 #define SeiAlloc(size) SdbpAlloc(size, __LINE__, __FILE__)
94 #define SeiReAlloc(mem, size, oldSize) SdbpReAlloc(mem, size, oldSize, __LINE__, __FILE__)
95 #define SeiFree(mem) SdbpFree(mem, __LINE__, __FILE__)
96
97 #else
98
99 LPVOID SdbpAlloc(SIZE_T size);
100 LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, SIZE_T oldSize);
101 VOID SdbpFree(LPVOID mem);
102
103 #define SeiAlloc(size) SdbpAlloc(size)
104 #define SeiReAlloc(mem, size, oldSize) SdbpReAlloc(mem, size, oldSize)
105 #define SeiFree(mem) SdbpFree(mem)
106
107 #endif
108
109 #endif // SHIMENG_H