-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeystone.cs
More file actions
351 lines (308 loc) · 12.4 KB
/
keystone.cs
File metadata and controls
351 lines (308 loc) · 12.4 KB
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
// ----------------------------------------------------------------------------
// <auto-generated>
// This is autogenerated code by CppSharp.
// Do not edit this file or all your changes will be lost after re-generation.
// </auto-generated>
// ----------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Security;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr;
namespace keystone.NET
{
public enum KsArch
{
KS_ARCH_ARM = 1,
KS_ARCH_ARM64 = 2,
KS_ARCH_MIPS = 3,
KS_ARCH_X86 = 4,
KS_ARCH_PPC = 5,
KS_ARCH_SPARC = 6,
KS_ARCH_SYSTEMZ = 7,
KS_ARCH_HEXAGON = 8,
KS_ARCH_EVM = 9,
KS_ARCH_MAX = 10
}
[Flags]
public enum KsMode
{
KS_MODE_LITTLE_ENDIAN = 0,
KS_MODE_BIG_ENDIAN = 1073741824,
KS_MODE_ARM = 1,
KS_MODE_THUMB = 16,
KS_MODE_V8 = 64,
KS_MODE_MICRO = 16,
KS_MODE_MIPS3 = 32,
KS_MODE_MIPS32R6 = 64,
KS_MODE_MIPS32 = 4,
KS_MODE_MIPS64 = 8,
KS_MODE_16 = 2,
KS_MODE_32 = 4,
KS_MODE_64 = 8,
KS_MODE_PPC32 = 4,
KS_MODE_PPC64 = 8,
KS_MODE_QPX = 16,
KS_MODE_SPARC32 = 4,
KS_MODE_SPARC64 = 8,
KS_MODE_V9 = 16
}
public enum KsErr
{
KS_ERR_OK = 0,
KS_ERR_NOMEM = 1,
KS_ERR_ARCH = 2,
KS_ERR_HANDLE = 3,
KS_ERR_MODE = 4,
KS_ERR_VERSION = 5,
KS_ERR_OPT_INVALID = 6,
KS_ERR_ASM_EXPR_TOKEN = 128,
KS_ERR_ASM_DIRECTIVE_VALUE_RANGE = 129,
KS_ERR_ASM_DIRECTIVE_ID = 130,
KS_ERR_ASM_DIRECTIVE_TOKEN = 131,
KS_ERR_ASM_DIRECTIVE_STR = 132,
KS_ERR_ASM_DIRECTIVE_COMMA = 133,
KS_ERR_ASM_DIRECTIVE_RELOC_NAME = 134,
KS_ERR_ASM_DIRECTIVE_RELOC_TOKEN = 135,
KS_ERR_ASM_DIRECTIVE_FPOINT = 136,
KS_ERR_ASM_DIRECTIVE_UNKNOWN = 137,
KS_ERR_ASM_DIRECTIVE_EQU = 138,
KS_ERR_ASM_DIRECTIVE_INVALID = 139,
KS_ERR_ASM_VARIANT_INVALID = 140,
KS_ERR_ASM_EXPR_BRACKET = 141,
KS_ERR_ASM_SYMBOL_MODIFIER = 142,
KS_ERR_ASM_SYMBOL_REDEFINED = 143,
KS_ERR_ASM_SYMBOL_MISSING = 144,
KS_ERR_ASM_RPAREN = 145,
KS_ERR_ASM_STAT_TOKEN = 146,
KS_ERR_ASM_UNSUPPORTED = 147,
KS_ERR_ASM_MACRO_TOKEN = 148,
KS_ERR_ASM_MACRO_PAREN = 149,
KS_ERR_ASM_MACRO_EQU = 150,
KS_ERR_ASM_MACRO_ARGS = 151,
KS_ERR_ASM_MACRO_LEVELS_EXCEED = 152,
KS_ERR_ASM_MACRO_STR = 153,
KS_ERR_ASM_MACRO_INVALID = 154,
KS_ERR_ASM_ESC_BACKSLASH = 155,
KS_ERR_ASM_ESC_OCTAL = 156,
KS_ERR_ASM_ESC_SEQUENCE = 157,
KS_ERR_ASM_ESC_STR = 158,
KS_ERR_ASM_TOKEN_INVALID = 159,
KS_ERR_ASM_INSN_UNSUPPORTED = 160,
KS_ERR_ASM_FIXUP_INVALID = 161,
KS_ERR_ASM_LABEL_INVALID = 162,
KS_ERR_ASM_FRAGMENT_INVALID = 163,
KS_ERR_ASM_INVALIDOPERAND = 512,
KS_ERR_ASM_MISSINGFEATURE = 513,
KS_ERR_ASM_MNEMONICFAIL = 514
}
public enum KsOptType
{
KS_OPT_SYNTAX = 1,
KS_OPT_SYM_RESOLVER = 2
}
[Flags]
public enum KsOptValue
{
KS_OPT_SYNTAX_INTEL = 1,
KS_OPT_SYNTAX_ATT = 2,
KS_OPT_SYNTAX_NASM = 4,
KS_OPT_SYNTAX_MASM = 8,
KS_OPT_SYNTAX_GAS = 16,
KS_OPT_SYNTAX_RADIX16 = 32
}
[SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(__CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public unsafe delegate bool KsSymResolver([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CppSharp.Runtime.UTF8Marshaller))] string symbol, ulong* value);
public unsafe partial class KsStruct
{
public partial struct __Internal
{
}
public __IntPtr __Instance { get; protected set; }
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::keystone.NET.KsStruct> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::keystone.NET.KsStruct>();
protected bool __ownsNativeInstance;
internal static KsStruct __CreateInstance(__IntPtr native, bool skipVTables = false)
{
return new KsStruct(native.ToPointer(), skipVTables);
}
internal static KsStruct __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false)
{
if (native == __IntPtr.Zero)
return null;
if (NativeToManagedMap.TryGetValue(native, out var managed))
return (KsStruct)managed;
var result = __CreateInstance(native, skipVTables);
if (saveInstance)
NativeToManagedMap[native] = result;
return result;
}
internal static KsStruct __CreateInstance(__Internal native, bool skipVTables = false)
{
return new KsStruct(native, skipVTables);
}
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(sizeof(__Internal));
*(__Internal*) ret = native;
return ret.ToPointer();
}
private KsStruct(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
protected KsStruct(void* native, bool skipVTables = false)
{
if (native == null)
return;
__Instance = new __IntPtr(native);
}
}
public unsafe partial class keystone
{
public partial struct __Internal
{
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_version", CallingConvention = __CallingConvention.Cdecl)]
internal static extern uint KsVersion(uint* major, uint* minor);
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_arch_supported", CallingConvention = __CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
internal static extern bool KsArchSupported(global::keystone.NET.KsArch arch);
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_open", CallingConvention = __CallingConvention.Cdecl)]
internal static extern global::keystone.NET.KsErr KsOpen(global::keystone.NET.KsArch arch, int mode, IntPtr* ks);
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_close", CallingConvention = __CallingConvention.Cdecl)]
internal static extern global::keystone.NET.KsErr KsClose(__IntPtr ks);
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_errno", CallingConvention = __CallingConvention.Cdecl)]
internal static extern global::keystone.NET.KsErr KsErrno(__IntPtr ks);
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_strerror", CallingConvention = __CallingConvention.Cdecl)]
internal static extern __IntPtr KsStrerror(global::keystone.NET.KsErr code);
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_option", CallingConvention = __CallingConvention.Cdecl)]
internal static extern global::keystone.NET.KsErr KsOption(__IntPtr ks, global::keystone.NET.KsOptType type, ulong value);
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_asm", CallingConvention = __CallingConvention.Cdecl)]
internal static extern int KsAsm(__IntPtr ks, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CppSharp.Runtime.UTF8Marshaller))] string @string, ulong address, byte** encoding, ulong* encoding_size, ulong* stat_count);
[SuppressUnmanagedCodeSecurity, DllImport("keystone", EntryPoint = "ks_free", CallingConvention = __CallingConvention.Cdecl)]
internal static extern void KsFree(byte* p);
}
public static uint KsVersion(ref uint major, ref uint minor)
{
fixed (uint* __major0 = &major)
{
var __arg0 = __major0;
fixed (uint* __minor1 = &minor)
{
var __arg1 = __minor1;
var __ret = __Internal.KsVersion(__arg0, __arg1);
return __ret;
}
}
}
public static bool KsArchSupported(global::keystone.NET.KsArch arch)
{
var __ret = __Internal.KsArchSupported(arch);
return __ret;
}
public static global::keystone.NET.KsErr KsOpen(global::keystone.NET.KsArch arch, int mode,out global::keystone.NET.KsStruct ks)
{
IntPtr __arg2;
var __ret = __Internal.KsOpen(arch, mode, &__arg2);
ks = global::keystone.NET.KsStruct.__CreateInstance(__arg2);
return __ret;
}
public static global::keystone.NET.KsErr KsClose(global::keystone.NET.KsStruct ks)
{
var __arg0 = ks is null ? __IntPtr.Zero : ks.__Instance;
var __ret = __Internal.KsClose(__arg0);
return __ret;
}
public static global::keystone.NET.KsErr KsErrno(global::keystone.NET.KsStruct ks)
{
var __arg0 = ks is null ? __IntPtr.Zero : ks.__Instance;
var __ret = __Internal.KsErrno(__arg0);
return __ret;
}
public static string KsStrerror(global::keystone.NET.KsErr code)
{
var __ret = __Internal.KsStrerror(code);
return CppSharp.Runtime.MarshalUtil.GetString(global::System.Text.Encoding.UTF8, __ret);
}
public static global::keystone.NET.KsErr KsOption(global::keystone.NET.KsStruct ks, global::keystone.NET.KsOptType type, ulong value)
{
var __arg0 = ks is null ? __IntPtr.Zero : ks.__Instance;
var __ret = __Internal.KsOption(__arg0, type, value);
return __ret;
}
public static int KsAsm(global::keystone.NET.KsStruct ks, string @string, ulong address, byte** encoding, out ulong encoding_size, out ulong stat_count)
{
var __arg0 = ks is null ? __IntPtr.Zero : ks.__Instance;
fixed (ulong* __encoding_size4 = &encoding_size)
{
var __arg4 = __encoding_size4;
fixed (ulong* __stat_count5 = &stat_count)
{
var __arg5 = __stat_count5;
var __ret = __Internal.KsAsm(__arg0, @string, address, encoding, __arg4, __arg5);
return __ret;
}
}
}
public static void KsFree(byte* p)
{
__Internal.KsFree(p);
}
}
public enum KsErrAsmArm64
{
KS_ERR_ASM_ARM64INVALIDOPERAND = 512,
KS_ERR_ASM_ARM64MISSINGFEATURE = 513,
KS_ERR_ASM_ARM64MNEMONICFAIL = 514
}
public enum KsErrAsmArm
{
KS_ERR_ASM_ARM_INVALIDOPERAND = 512,
KS_ERR_ASM_ARM_MISSINGFEATURE = 513,
KS_ERR_ASM_ARM_MNEMONICFAIL = 514
}
public enum KsErrAsmEvm
{
KS_ERR_ASM_EVM_INVALIDOPERAND = 512,
KS_ERR_ASM_EVM_MISSINGFEATURE = 513,
KS_ERR_ASM_EVM_MNEMONICFAIL = 514
}
public enum KsErrAsmHexagon
{
KS_ERR_ASM_HEXAGON_INVALIDOPERAND = 512,
KS_ERR_ASM_HEXAGON_MISSINGFEATURE = 513,
KS_ERR_ASM_HEXAGON_MNEMONICFAIL = 514
}
public enum KsErrAsmMips
{
KS_ERR_ASM_MIPS_INVALIDOPERAND = 512,
KS_ERR_ASM_MIPS_MISSINGFEATURE = 513,
KS_ERR_ASM_MIPS_MNEMONICFAIL = 514
}
public enum KsErrAsmPpc
{
KS_ERR_ASM_PPC_INVALIDOPERAND = 512,
KS_ERR_ASM_PPC_MISSINGFEATURE = 513,
KS_ERR_ASM_PPC_MNEMONICFAIL = 514
}
public enum KsErrAsmSparc
{
KS_ERR_ASM_SPARC_INVALIDOPERAND = 512,
KS_ERR_ASM_SPARC_MISSINGFEATURE = 513,
KS_ERR_ASM_SPARC_MNEMONICFAIL = 514
}
public enum KsErrAsmSystemz
{
KS_ERR_ASM_SYSTEMZ_INVALIDOPERAND = 512,
KS_ERR_ASM_SYSTEMZ_MISSINGFEATURE = 513,
KS_ERR_ASM_SYSTEMZ_MNEMONICFAIL = 514
}
public enum KsErrAsmX86
{
KS_ERR_ASM_X86INVALIDOPERAND = 512,
KS_ERR_ASM_X86MISSINGFEATURE = 513,
KS_ERR_ASM_X86MNEMONICFAIL = 514
}
}