-
Notifications
You must be signed in to change notification settings - Fork 44
/
Types.ts
289 lines (251 loc) · 5.26 KB
/
Types.ts
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
/**
* The aim of this interface is to describe CPU-specific data required
* to retrieve and parse sys call from CPU context.
*
* @interface
* @export
*/
import {IStringIndex} from "../utilities/IStringIndex.js";
export interface SyscallCallingConvention extends IStringIndex {
/**
* The mmemonic of the opcode performing the interruption
* Example : 'swi' for armv7
* @type string
* @field
*/
OP: string;
/**
* The name of the register holding the syscall number
* Example : 'r7' for armv7
* @type string
* @field
*/
NR: string;
/**
* The name of the register holding the error code / return value after the syscall
* Example : 'r7' for armv7
* @type string
* @field
*/
RET: string;
/**
* The name of the register holding the 1st arg
* Example : 'r0' for armv7
* @type string
* @field
*/
ARG0: string;
/**
* The name of the register holding the 2nd arg
* Example : 'r1' for armv7
* @type string
* @field
*/
ARG1: string;
/**
* The name of the register holding the 3rd arg
* Example : 'r2' for armv7
* @type string
* @field
*/
ARG2: string;
/**
* The name of the register holding the 4th arg
* Example : 'r3' for armv7
* @type string
* @field
*/
ARG3: string;
/**
* The name of the register holding the 5th arg
* Example : 'r4' for armv7
* @type string
* @field
*/
ARG4: string;
/**
* The name of the register holding the 6th arg
* Example : 'r5' for armv7
* @type string
* @field
*/
ARG5: string;
/**
* The name of the register holding the program counter / current instruction
* Example : 'pc' for armv7 , 'EIP', ...
* @type string
* @field
*/
PC: string;
}
export type SyscallNumber = number;
export type SyscallName = string;
export type ErrorCodeName = string;
export type ErrorCodeConst = number;
/**
* To hold extra data for the hook context
* @interface
*/
interface ExtraContext {
orig?:any; //NativePointer;
FD?:any;
WD?:any;
SOCKFD?:any;
DFD?:any;
[name:string] :any;
}
export type RegisterName = string;
export interface CallConvention {
OP: RegisterName,
NR: RegisterName,
RET: RegisterName,
ARG0: RegisterName,
ARG1: RegisterName,
ARG2: RegisterName,
ARG3: RegisterName,
ARG4: RegisterName,
ARG5: RegisterName,
}
export interface RichCpuContext extends IStringIndex {
dxc?:ExtraContext;
log?:string;
dxcOpts?:any;
dxcRet?:any;
}
/**
* Basic interface to define an error code
* @interface
*/
export interface ErrorCode {
0: ErrorCodeConst;
1: string;
2?: ErrorCodeName;
}
export interface ErrorCodeList extends IStringIndex {
[name:string] :ErrorCode;
}
export interface ErrorCodeMapping extends IStringIndex {
[name:string] :number;
}
export interface SyscallInOutInfo extends IStringIndex{
t:T;
n?:SyscallName;
l?:L;
f?:any;
r?:string|number|(string|number)[];
c?:boolean;
e?:ErrorCode[]
}
export interface SyscallInInfo extends SyscallInOutInfo{
t:T;
n:SyscallName;
}
export interface SyscallOutInfo extends SyscallInOutInfo{
t:T;
e:ErrorCode[]
}
export interface SyscallOutMap extends IStringIndex {
[shortcut:string] :SyscallOutInfo;
}
export type SyscallParamSignature = SyscallInInfo | string;
export interface SyscallHook {
onEnter?: ((ctx:RichCpuContext)=>void);
onLeave?: ((ctx:RichCpuContext)=>void);
}
export interface SyscallHookMap {
[syscallName:string] : SyscallHook;
}
export enum SyscallInfo {
NUM,
NAME,
HEX,
ARGS,
RET
}
export interface SyscallSignature {
0: SyscallNumber;
1: SyscallName;
2: SyscallNumber;
3: SyscallParamSignature[];
4?: SyscallOutInfo;
}
export interface SyscallMapping {
[name:string] :SyscallSignature;
}
export type InterruptSignature = SyscallSignature;
export interface InterruptSignatureMap {
syscalls: SyscallSignature[] | null,
[type:string] :InterruptSignature[] | null
}
export enum F {
EXCLUDE_ANY,
INCLUDE_ANY,
FILTER
}
/**
* The aim of this enumeration is to provide a list of meaning to help
* to analyse syscall's arguments and provide useful information
*
* @enum
* @export
*/
export enum L {
PATH,
SIZE,
FD, // File Descriptor
DFD, // Directory File Descriptor
FLAG,
ATTRMODE,
O_FLAGS,
VADDR,
MPROT,
OUTPUT_BUFFER,
PID,
ERR,
SIG,
XATTR_LIST,
F_,
MFD, // Mapped FD
UID,
GID,
UTSNAME,
FCNTL_ARGS, // fnctl() args
FCNTL_RET, // fnctl() ret
TIME, // Timestamp
INODE, // Inode
DEV, // Device
DSTRUCT,
EPFD, // EPoll File Descriptor
WD,// Watch Descriptor,
PIPEFD, // fd[2] read FD, write FD
SOCKFD,
BUFFER,
PKEY,
IDSTRUCT,
FUTEX,
TIMER,
MQDES,// struct always parsed,
PTRACE
}
/**
* An enumeration of most basic type, most of them are primitive type.
*
* @enum
* @export
*/
export enum T {
INT32,
UINT32,
LONG,
ULONG,
SHORT,
USHORT,
FLOAT,
DOUBLE,
CHAR,
STRING,
CHAR_BUFFER,
POINTER32,
POINTER64,
STRUCT
}