forked from xiaobfly/DisPg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Except.h
243 lines (208 loc) · 5.72 KB
/
Except.h
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
/*
*
* Copyright (c) 2015-2018 by blindtiger ( blindtiger@foxmail.com )
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. SEe the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original e is blindtiger.
*
*/
#ifndef _EXCEPT_H_
#define _EXCEPT_H_
#ifdef __cplusplus
/* Assume C declarations for C++ */
extern "C" {
#endif /* __cplusplus */
#define DivideErrorFault 0
#define DebugTrapOrFault 1
#define NmiInterrupt 2
#define BreakpointTrap 3
#define OverflowTrap 4
#define BoundFault 5
#define InvalidOpcodeFault 6
#define NpxNotAvailableFault 7
#define DoubleFaultAbort 8
#define NpxSegmentOverrunAbort 9
#define InvalidTssFault 10
#define SegmentNotPresentFault 11
#define StackFault 12
#define GeneralProtectionFault 13
#define PageFault 14
#define FloatingErrorFault 16
#define AlignmentFault 17
#define McheckAbort 18
#define XmmException 19
#define ApcInterrupt 31
#define RaiseAssertion 44
#define DebugServiceTrap 45
#define DpcInterrupt 47
#define IpiInterrupt 225
#ifndef _WIN64
typedef struct _DISPATCHER_CONTEXT {
PEXCEPTION_REGISTRATION_RECORD RegistrationPointer;
} DISPATCHER_CONTEXT;
#endif // !_WIN64
#define MAXIMUM_USER_FUNCTION_TABLE_SIZE 512
#define MAXIMUM_KERNEL_FUNCTION_TABLE_SIZE 256
typedef struct _FUNCTION_TABLE_ENTRY32 {
ULONG FunctionTable;
ULONG ImageBase;
ULONG SizeOfImage;
ULONG SizeOfTable;
} FUNCTION_TABLE_ENTRY32, *PFUNCTION_TABLE_ENTRY32;
C_ASSERT(sizeof(FUNCTION_TABLE_ENTRY32) == 0x10);
typedef struct _FUNCTION_TABLE_ENTRY64 {
ULONG64 FunctionTable;
ULONG64 ImageBase;
ULONG SizeOfImage;
ULONG SizeOfTable;
} FUNCTION_TABLE_ENTRY64, *PFUNCTION_TABLE_ENTRY64;
C_ASSERT(sizeof(FUNCTION_TABLE_ENTRY64) == 0x18);
typedef struct _FUNCTION_TABLE {
ULONG CurrentSize;
ULONG MaximumSize;
ULONG Epoch;
BOOLEAN Overflow;
ULONG TableEntry[1];
} FUNCTION_TABLE, *PFUNCTION_TABLE;
C_ASSERT(FIELD_OFFSET(FUNCTION_TABLE, TableEntry) == 0x10);
typedef struct _FUNCTION_TABLE_SPECIAL {
ULONG CurrentSize;
ULONG MaximumSize;
BOOLEAN Overflow;
ULONG TableEntry[1];
} FUNCTION_TABLE_SPECIAL, *PFUNCTION_TABLE_SPECIAL;
C_ASSERT(FIELD_OFFSET(FUNCTION_TABLE_SPECIAL, TableEntry) == 0xc);
typedef
VOID
(*PKI_INTERRUPT_HANDLER) (
VOID
);
ULONG
NTAPI
EncodeSystemPointer(
__in ULONG Pointer
);
ULONG
NTAPI
DecodeSystemPointer(
__in ULONG Pointer
);
VOID
NTAPI
CaptureImageExceptionValues(
__in PVOID Base,
__out PVOID * FunctionTable,
__out PULONG TableSize
);
VOID
NTAPI
InitializeExcept(
VOID
);
VOID
NTAPI
InsertUserInvertedFunctionTable(
__in PVOID ImageBase,
__in ULONG SizeOfImage
);
VOID
NTAPI
RemoveUserInvertedFunctionTable(
__in PVOID ImageBase
);
#ifndef _WIN64
PVOID
NTAPI
DetourRtlLookupFunctionTable(
__in PVOID ControlPc,
__out PVOID * ImageBase,
__out PULONG SizeOfTable
);
BOOLEAN
NTAPI
IsValidHandler(
__in PEXCEPTION_ROUTINE Handler
);
VOID
NTAPI
InsertUserSpecialInvertedFunctionTable(
__in PVOID ImageBase,
__in ULONG SizeOfImage
);
VOID
NTAPI
RemoveUserSpecialInvertedFunctionTable(
__in PVOID ImageBase
);
#else
PRUNTIME_FUNCTION
NTAPI
DetourRtlLookupFunctionTable(
__in PVOID ControlPc,
__out PVOID * ImageBase,
__out PULONG SizeOfTable
);
PRUNTIME_FUNCTION
NTAPI
DetourRtlLookupFunctionEntry(
__in ULONG64 ControlPc,
__out PULONG64 ImageBase,
__inout_opt PUNWIND_HISTORY_TABLE HistoryTable
);
VOID
NTAPI
SaveProcessorControlState(
__out PKPROCESSOR_STATE ProcessorState
);
VOID
NTAPI
RestoreProcessorControlState(
__out PKPROCESSOR_STATE ProcessorState
);
VOID
NTAPI
InsertInvertedFunctionTable(
__in PVOID ImageBase,
__in ULONG SizeOfImage
);
VOID
NTAPI
RemoveInvertedFunctionTable(
__in PVOID ImageBase
);
VOID
NTAPI
InsertWx86UserInvertedFunctionTable(
__in PVOID ImageBase,
__in ULONG SizeOfImage
);
VOID
NTAPI
RemoveWx86UserInvertedFunctionTable(
__in PVOID ImageBase
);
VOID
NTAPI
InsertWx86UserSpecialInvertedFunctionTable(
__in PVOID ImageBase,
__in ULONG SizeOfImage
);
VOID
NTAPI
RemoveWx86UserSpecialInvertedFunctionTable(
__in PVOID ImageBase
);
#endif // !_WIN64
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // !_EXCEPT_H_