some updates
[iv.d.git] / capstone / package.d
blobb9db1dc788fa5ee17efcc433dc2bfe309bcb59bb
1 // Capstone Disassembly Engine
2 // By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015
3 // k8: see licenses in original capstone package, i'm too lazy to copy 'em.
4 module iv.capstone /*is aliced*/;
5 pragma(lib, "capstone");
6 import iv.alice;
7 extern(C) nothrow:
9 // Capstone API version
10 enum CS_API_MAJOR = 4;
11 enum CS_API_MINOR = 0;
13 // Version for bleeding edge code of the Github's "next" branch.
14 // Use this if you want the absolutely latest developement code.
15 // This version number will be bumped up whenever we have a new major change.
16 enum CS_NEXT_VERSION = 3;
18 // Macro to create combined version which can be compared to
19 // result of cs_version() API.
20 uint CS_MAKE_VERSION (ubyte major, ubyte minor) { return ((major<<8)+minor); }
22 // Maximum size of an instruction mnemonic string.
23 enum CS_MNEMONIC_SIZE = 32;
25 // Handle using with all API
26 alias csh = usize;
28 // Architecture type
29 alias cs_arch = uint;
30 enum /*cs_arch*/ : uint {
31 CS_ARCH_ARM = 0, // ARM architecture (including Thumb, Thumb-2)
32 CS_ARCH_ARM64, // ARM-64, also called AArch64
33 CS_ARCH_MIPS, // Mips architecture
34 CS_ARCH_X86, // X86 architecture (including x86 & x86-64)
35 CS_ARCH_PPC, // PowerPC architecture
36 CS_ARCH_SPARC, // Sparc architecture
37 CS_ARCH_SYSZ, // SystemZ architecture
38 CS_ARCH_XCORE, // XCore architecture
39 CS_ARCH_M68K, // 68K architecture
40 CS_ARCH_MAX,
41 CS_ARCH_ALL = 0xFFFF, // All architectures - for cs_support()
44 // Support value to verify diet mode of the engine.
45 // If cs_support(CS_SUPPORT_DIET) return True, the engine was compiled
46 // in diet mode.
47 enum CS_SUPPORT_DIET = (CS_ARCH_ALL+1);
49 // Support value to verify X86 reduce mode of the engine.
50 // If cs_support(CS_SUPPORT_X86_REDUCE) return True, the engine was compiled
51 // in X86 reduce mode.
52 enum CS_SUPPORT_X86_REDUCE = (CS_ARCH_ALL+2);
54 // Mode type
55 alias cs_mode = uint;
56 enum /*cs_mode*/ : uint {
57 CS_MODE_LITTLE_ENDIAN = 0, // little-endian mode (default mode)
58 CS_MODE_ARM = 0, // 32-bit ARM
59 CS_MODE_16 = 1 << 1, // 16-bit mode (X86)
60 CS_MODE_32 = 1 << 2, // 32-bit mode (X86)
61 CS_MODE_64 = 1 << 3, // 64-bit mode (X86, PPC)
62 CS_MODE_THUMB = 1 << 4, // ARM's Thumb mode, including Thumb-2
63 CS_MODE_MCLASS = 1 << 5, // ARM's Cortex-M series
64 CS_MODE_V8 = 1 << 6, // ARMv8 A32 encodings for ARM
65 CS_MODE_MICRO = 1 << 4, // MicroMips mode (MIPS)
66 CS_MODE_MIPS3 = 1 << 5, // Mips III ISA
67 CS_MODE_MIPS32R6 = 1 << 6, // Mips32r6 ISA
68 CS_MODE_V9 = 1 << 4, // SparcV9 mode (Sparc)
69 CS_MODE_QPX = 1 << 4, // Quad Processing eXtensions mode (PPC)
70 CS_MODE_M68K_000 = 1 << 1, // M68K 68000 mode
71 CS_MODE_M68K_010 = 1 << 2, // M68K 68010 mode
72 CS_MODE_M68K_020 = 1 << 3, // M68K 68020 mode
73 CS_MODE_M68K_030 = 1 << 4, // M68K 68030 mode
74 CS_MODE_M68K_040 = 1 << 5, // M68K 68040 mode
75 CS_MODE_M68K_060 = 1 << 6, // M68K 68060 mode
76 CS_MODE_BIG_ENDIAN = 1 << 31, // big-endian mode
77 CS_MODE_MIPS32 = CS_MODE_32, // Mips32 ISA (Mips)
78 CS_MODE_MIPS64 = CS_MODE_64, // Mips64 ISA (Mips)
81 import core.stdc.stdarg : va_list;
83 alias void* function (usize size) cs_malloc_t;
84 alias void* function (usize nmemb, usize size) cs_calloc_t;
85 alias void* function (void *ptr, usize size) cs_realloc_t;
86 alias void function (void *ptr) cs_free_t;
87 alias int function (char *str, usize size, const char *format, va_list ap) cs_vsnprintf_t;
90 // User-defined dynamic memory related functions: malloc/calloc/realloc/free/vsnprintf()
91 // By default, Capstone uses system's malloc(), calloc(), realloc(), free() & vsnprintf().
92 struct cs_opt_mem {
93 cs_malloc_t malloc;
94 cs_calloc_t calloc;
95 cs_realloc_t realloc;
96 cs_free_t free;
97 cs_vsnprintf_t vsnprintf;
100 // Customize mnemonic for instructions with alternative name.
101 // To reset existing customized instruction to its default mnemonic,
102 // call cs_option(CS_OPT_MNEMONIC) again with the same @id and NULL value
103 // for @mnemonic.
104 struct cs_opt_mnem {
105 // ID of instruction to be customized.
106 uint id;
107 // Customized instruction mnemonic.
108 char* mnemonic;
111 // Runtime option for the disassembled engine
112 alias cs_opt_type = uint;
113 enum /*cs_opt_type*/ : uint {
114 CS_OPT_INVALID = 0, // No option specified
115 CS_OPT_SYNTAX, // Assembly output syntax
116 CS_OPT_DETAIL, // Break down instruction structure into details
117 CS_OPT_MODE, // Change engine's mode at run-time
118 CS_OPT_MEM, // User-defined dynamic memory related functions
119 CS_OPT_SKIPDATA, // Skip data when disassembling. Then engine is in SKIPDATA mode.
120 CS_OPT_SKIPDATA_SETUP, // Setup user-defined function for SKIPDATA option
121 CS_OPT_MNEMONIC, // Customize instruction mnemonic
122 CS_OPT_UNSIGNED, // print immediate operands in unsigned form
125 // Runtime option value (associated with option type above)
126 alias cs_opt_value = uint;
127 enum /*cs_opt_value*/ : uint {
128 CS_OPT_OFF = 0, // Turn OFF an option - default for CS_OPT_DETAIL, CS_OPT_SKIPDATA, CS_OPT_UNSIGNED.
129 CS_OPT_ON = 3, // Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
130 CS_OPT_SYNTAX_DEFAULT = 0, // Default asm syntax (CS_OPT_SYNTAX).
131 CS_OPT_SYNTAX_INTEL, // X86 Intel asm syntax - default on X86 (CS_OPT_SYNTAX).
132 CS_OPT_SYNTAX_ATT, // X86 ATT asm syntax (CS_OPT_SYNTAX).
133 CS_OPT_SYNTAX_NOREGNAME, // Prints register name with only number (CS_OPT_SYNTAX)
134 CS_OPT_SYNTAX_MASM, // X86 Intel Masm syntax (CS_OPT_SYNTAX).
137 // Common instruction operand types - to be consistent across all architectures.
138 alias cs_op_type = uint;
139 enum /*cs_op_type*/ : uint {
140 CS_OP_INVALID = 0, // uninitialized/invalid operand.
141 CS_OP_REG, // Register operand.
142 CS_OP_IMM, // Immediate operand.
143 CS_OP_MEM, // Memory operand.
144 CS_OP_FP, // Floating-Point operand.
147 // Common instruction operand access types - to be consistent across all architectures.
148 // It is possible to combine access types, for example: CS_AC_READ | CS_AC_WRITE
149 alias cs_ac_type = uint;
150 enum /*cs_ac_type*/ : uint {
151 CS_AC_INVALID = 0, // Uninitialized/invalid access type.
152 CS_AC_READ = 1 << 0, // Operand read from memory or register.
153 CS_AC_WRITE = 1 << 1, // Operand write to memory or register.
156 // Common instruction groups - to be consistent across all architectures.
157 alias cs_group_type = uint;
158 enum /*cs_group_type*/ : uint {
159 CS_GRP_INVALID = 0, // uninitialized/invalid group.
160 CS_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps)
161 CS_GRP_CALL, // all call instructions
162 CS_GRP_RET, // all return instructions
163 CS_GRP_INT, // all interrupt instructions (int+syscall)
164 CS_GRP_IRET, // all interrupt return instructions
165 CS_GRP_PRIVILEGE, // all privileged instructions
169 User-defined callback function for SKIPDATA option.
170 See tests/test_skipdata.c for sample code demonstrating this API.
172 @code: the input buffer containing code to be disassembled.
173 This is the same buffer passed to cs_disasm().
174 @code_size: size (in bytes) of the above @code buffer.
175 @offset: the position of the currently-examining byte in the input
176 buffer @code mentioned above.
177 @user_data: user-data passed to cs_option() via @user_data field in
178 cs_opt_skipdata struct below.
180 @return: return number of bytes to skip, or 0 to immediately stop disassembling.
182 alias usize function (const ubyte *code, usize code_size, usize offset, void *user_data) cs_skipdata_cb_t;
184 // User-customized setup for SKIPDATA option
185 struct cs_opt_skipdata {
186 // Capstone considers data to skip as special "instructions".
187 // User can specify the string for this instruction's "mnemonic" here.
188 // By default (if @mnemonic is NULL), Capstone use ".byte".
189 const(char)* mnemonic;
191 // User-defined callback function to be called when Capstone hits data.
192 // If the returned value from this callback is positive (>0), Capstone
193 // will skip exactly that number of bytes & continue. Otherwise, if
194 // the callback returns 0, Capstone stops disassembling and returns
195 // immediately from cs_disasm()
196 // NOTE: if this callback pointer is NULL, Capstone would skip a number
197 // of bytes depending on architectures, as following:
198 // Arm: 2 bytes (Thumb mode) or 4 bytes.
199 // Arm64: 4 bytes.
200 // Mips: 4 bytes.
201 // PowerPC: 4 bytes.
202 // Sparc: 4 bytes.
203 // SystemZ: 2 bytes.
204 // X86: 1 bytes.
205 // XCore: 2 bytes.
206 cs_skipdata_cb_t callback; // default value is NULL
208 // User-defined data to be passed to @callback function pointer.
209 void* user_data;
213 public import iv.capstone.x86;
216 // NOTE: All information in cs_detail is only available when CS_OPT_DETAIL = CS_OPT_ON
217 struct cs_detail {
218 ushort[12] regs_read; // list of implicit registers read by this insn
219 ubyte regs_read_count; // number of implicit registers read by this insn
221 ushort[20] regs_write; // list of implicit registers modified by this insn
222 ubyte regs_write_count; // number of implicit registers modified by this insn
224 ubyte[8] groups; // list of group this instruction belong to
225 ubyte groups_count; // number of groups this insn belongs to
227 // Architecture-specific instruction info
228 union {
229 cs_x86 x86; // X86 architecture, including 16-bit, 32-bit & 64-bit mode
231 cs_arm64 arm64; // ARM64 architecture (aka AArch64)
232 cs_arm arm; // ARM architecture (including Thumb/Thumb2)
233 cs_m68k m68k; // M68K architecture
234 cs_mips mips; // MIPS architecture
235 cs_ppc ppc; // PowerPC architecture
236 cs_sparc sparc; // Sparc architecture
237 cs_sysz sysz; // SystemZ architecture
238 cs_xcore xcore; // XCore architecture
243 // Detail information of disassembled instruction
244 struct cs_insn {
245 // Instruction ID (basically a numeric ID for the instruction mnemonic)
246 // Find the instruction id in the '[ARCH]_insn' enum in the header file
247 // of corresponding architecture, such as 'arm_insn' in arm.h for ARM,
248 // 'x86_insn' in x86.h for X86, etc...
249 // This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
250 // NOTE: in Skipdata mode, "data" instruction has 0 for this id field.
251 uint id;
253 // Address (EIP) of this instruction
254 // This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
255 ulong address;
257 // Size of this instruction
258 // This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
259 ushort size;
261 // Machine bytes of this instruction, with number of bytes indicated by @size above
262 // This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
263 ubyte[16] bytes;
265 // Ascii text of instruction mnemonic
266 // This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
267 char[CS_MNEMONIC_SIZE] mnemonic;
269 // Ascii text of instruction operands
270 // This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
271 char[160] op_str;
273 // Pointer to cs_detail.
274 // NOTE: detail pointer is only valid when both requirements below are met:
275 // (1) CS_OP_DETAIL = CS_OPT_ON
276 // (2) Engine is not in Skipdata mode (CS_OP_SKIPDATA option set to CS_OPT_ON)
278 // NOTE 2: when in Skipdata mode, or when detail mode is OFF, even if this pointer
279 // is not NULL, its content is still irrelevant.
280 cs_detail* detail;
284 // Calculate the offset of a disassembled instruction in its buffer, given its position
285 // in its array of disassembled insn
286 // NOTE: this macro works with position (>=1), not index
287 //uint CS_INSN_OFFSET(insns, post) (insns[post - 1].address - insns[0].address)
290 // All type of errors encountered by Capstone API.
291 // These are values returned by cs_errno()
292 alias cs_err = uint;
293 enum /*cs_err*/ : uint {
294 CS_ERR_OK = 0, // No error: everything was fine
295 CS_ERR_MEM, // Out-Of-Memory error: cs_open(), cs_disasm(), cs_disasm_iter()
296 CS_ERR_ARCH, // Unsupported architecture: cs_open()
297 CS_ERR_HANDLE, // Invalid handle: cs_op_count(), cs_op_index()
298 CS_ERR_CSH, // Invalid csh argument: cs_close(), cs_errno(), cs_option()
299 CS_ERR_MODE, // Invalid/unsupported mode: cs_open()
300 CS_ERR_OPTION, // Invalid/unsupported option: cs_option()
301 CS_ERR_DETAIL, // Information is unavailable because detail option is OFF
302 CS_ERR_MEMSETUP, // Dynamic memory management uninitialized (see CS_OPT_MEM)
303 CS_ERR_VERSION, // Unsupported version (bindings)
304 CS_ERR_DIET, // Access irrelevant data in "diet" engine
305 CS_ERR_SKIPDATA, // Access irrelevant data for "data" instruction in SKIPDATA mode
306 CS_ERR_X86_ATT, // X86 AT&T syntax is unsupported (opt-out at compile time)
307 CS_ERR_X86_INTEL, // X86 Intel syntax is unsupported (opt-out at compile time)
308 CS_ERR_X86_MASM, // X86 Intel syntax is unsupported (opt-out at compile time)
312 Return combined API version & major and minor version numbers.
314 @major: major number of API version
315 @minor: minor number of API version
317 @return hexical number as (major << 8 | minor), which encodes both
318 major & minor versions.
319 NOTE: This returned value can be compared with version number made
320 with macro CS_MAKE_VERSION
322 For example, second API version would return 1 in @major, and 1 in @minor
323 The return value would be 0x0101
325 NOTE: if you only care about returned value, but not major and minor values,
326 set both @major & @minor arguments to NULL.
328 public uint cs_version (int* major, int* minor);
332 This API can be used to either ask for archs supported by this library,
333 or check to see if the library was compile with 'diet' option (or called
334 in 'diet' mode).
336 To check if a particular arch is supported by this library, set @query to
337 arch mode (CS_ARCH_* value).
338 To verify if this library supports all the archs, use CS_ARCH_ALL.
340 To check if this library is in 'diet' mode, set @query to CS_SUPPORT_DIET.
342 @return True if this library supports the given arch, or in 'diet' mode.
344 public bool cs_support (int query);
347 Initialize CS handle: this must be done before any usage of CS.
349 @arch: architecture type (CS_ARCH_*)
350 @mode: hardware mode. This is combined of CS_MODE_*
351 @handle: pointer to handle, which will be updated at return time
353 @return CS_ERR_OK on success, or other value on failure (refer to cs_err enum
354 for detailed error).
356 public cs_err cs_open (cs_arch arch, cs_mode mode, csh* handle);
359 Close CS handle: MUST do to release the handle when it is not used anymore.
360 NOTE: this must be only called when there is no longer usage of Capstone,
361 not even access to cs_insn array. The reason is the this API releases some
362 cached memory, thus access to any Capstone API after cs_close() might crash
363 your application.
365 In fact,this API invalidate @handle by ZERO out its value (i.e *handle = 0).
367 @handle: pointer to a handle returned by cs_open()
369 @return CS_ERR_OK on success, or other value on failure (refer to cs_err enum
370 for detailed error).
372 public cs_err cs_close (csh* handle);
375 Set option for disassembling engine at runtime
377 @handle: handle returned by cs_open()
378 @type: type of option to be set
379 @value: option value corresponding with @type
381 @return: CS_ERR_OK on success, or other value on failure.
382 Refer to cs_err enum for detailed error.
384 NOTE: in the case of CS_OPT_MEM, handle's value can be anything,
385 so that cs_option(handle, CS_OPT_MEM, value) can (i.e must) be called
386 even before cs_open()
388 public cs_err cs_option (csh handle, cs_opt_type type, usize value);
391 Report the last error number when some API function fail.
392 Like glibc's errno, cs_errno might not retain its old value once accessed.
394 @handle: handle returned by cs_open()
396 @return: error code of cs_err enum type (CS_ERR_*, see above)
398 public cs_err cs_errno (csh handle);
402 Return a string describing given error code.
404 @code: error code (see CS_ERR_* above)
406 @return: returns a pointer to a string that describes the error code
407 passed in the argument @code
409 public const(char)* cs_strerror (cs_err code);
412 Disassemble binary code, given the code buffer, size, address and number
413 of instructions to be decoded.
414 This API dynamically allocate memory to contain disassembled instruction.
415 Resulted instructions will be put into @*insn
417 NOTE 1: this API will automatically determine memory needed to contain
418 output disassembled instructions in @insn.
420 NOTE 2: caller must free the allocated memory itself to avoid memory leaking.
422 NOTE 3: for system with scarce memory to be dynamically allocated such as
423 OS kernel or firmware, the API cs_disasm_iter() might be a better choice than
424 cs_disasm(). The reason is that with cs_disasm(), based on limited available
425 memory, we have to calculate in advance how many instructions to be disassembled,
426 which complicates things. This is especially troublesome for the case @count=0,
427 when cs_disasm() runs uncontrollably (until either end of input buffer, or
428 when it encounters an invalid instruction).
430 @handle: handle returned by cs_open()
431 @code: buffer containing raw binary code to be disassembled.
432 @code_size: size of the above code buffer.
433 @address: address of the first instruction in given raw code buffer.
434 @insn: array of instructions filled in by this API.
435 NOTE: @insn will be allocated by this function, and should be freed
436 with cs_free() API.
437 @count: number of instructions to be disassembled, or 0 to get all of them
439 @return: the number of successfully disassembled instructions,
440 or 0 if this function failed to disassemble the given code
442 On failure, call cs_errno() for error code.
444 public usize cs_disasm (csh handle, const(ubyte)* code, usize code_size, ulong address, usize count, cs_insn** insn);
447 Deprecated function - to be retired in the next version!
448 Use cs_disasm() instead of cs_disasm_ex()
450 deprecated("wow, deprecated Capstone API") public usize cs_disasm_ex(csh handle, const(ubyte)* code, usize code_size, ulong address, usize count, cs_insn** insn);
453 Free memory allocated by cs_malloc() or cs_disasm() (argument @insn)
455 @insn: pointer returned by @insn argument in cs_disasm() or cs_malloc()
456 @count: number of cs_insn structures returned by cs_disasm(), or 1
457 to free memory allocated by cs_malloc().
459 public void cs_free (cs_insn* insn, usize count);
463 Allocate memory for 1 instruction to be used by cs_disasm_iter().
465 @handle: handle returned by cs_open()
467 NOTE: when no longer in use, you can reclaim the memory allocated for
468 this instruction with cs_free(insn, 1)
470 public cs_insn* cs_malloc (csh handle);
473 Fast API to disassemble binary code, given the code buffer, size, address
474 and number of instructions to be decoded.
475 This API put the resulted instruction into a given cache in @insn.
476 See tests/test_iter.c for sample code demonstrating this API.
478 NOTE 1: this API will update @code, @size & @address to point to the next
479 instruction in the input buffer. Therefore, it is convenient to use
480 cs_disasm_iter() inside a loop to quickly iterate all the instructions.
481 While decoding one instruction at a time can also be achieved with
482 cs_disasm(count=1), some benchmarks shown that cs_disasm_iter() can be 30%
483 faster on random input.
485 NOTE 2: the cache in @insn can be created with cs_malloc() API.
487 NOTE 3: for system with scarce memory to be dynamically allocated such as
488 OS kernel or firmware, this API is recommended over cs_disasm(), which
489 allocates memory based on the number of instructions to be disassembled.
490 The reason is that with cs_disasm(), based on limited available memory,
491 we have to calculate in advance how many instructions to be disassembled,
492 which complicates things. This is especially troublesome for the case
493 @count=0, when cs_disasm() runs uncontrollably (until either end of input
494 buffer, or when it encounters an invalid instruction).
496 @handle: handle returned by cs_open()
497 @code: buffer containing raw binary code to be disassembled
498 @code_size: size of above code
499 @address: address of the first insn in given raw code buffer
500 @insn: pointer to instruction to be filled in by this API.
502 @return: true if this API successfully decode 1 instruction,
503 or false otherwise.
505 On failure, call cs_errno() for error code.
507 public bool cs_disasm_iter (csh handle, const(ubyte)** code, usize* size, ulong* address, cs_insn* insn);
510 Return friendly name of register in a string.
511 Find the instruction id from header file of corresponding architecture (arm.h for ARM,
512 x86.h for X86, ...)
514 WARN: when in 'diet' mode, this API is irrelevant because engine does not
515 store register name.
517 @handle: handle returned by cs_open()
518 @reg_id: register id
520 @return: string name of the register, or NULL if @reg_id is invalid.
522 public const(char)* cs_reg_name (csh handle, uint reg_id);
525 Return friendly name of an instruction in a string.
526 Find the instruction id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
528 WARN: when in 'diet' mode, this API is irrelevant because the engine does not
529 store instruction name.
531 @handle: handle returned by cs_open()
532 @insn_id: instruction id
534 @return: string name of the instruction, or NULL if @insn_id is invalid.
536 public const(char)* cs_insn_name (csh handle, uint insn_id);
539 Return friendly name of a group id (that an instruction can belong to)
540 Find the group id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
542 WARN: when in 'diet' mode, this API is irrelevant because the engine does not
543 store group name.
545 @handle: handle returned by cs_open()
546 @group_id: group id
548 @return: string name of the group, or NULL if @group_id is invalid.
550 public const(char)* cs_group_name (csh handle, uint group_id);
553 Check if a disassembled instruction belong to a particular group.
554 Find the group id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
555 Internally, this simply verifies if @group_id matches any member of insn->groups array.
557 NOTE: this API is only valid when detail option is ON (which is OFF by default).
559 WARN: when in 'diet' mode, this API is irrelevant because the engine does not
560 update @groups array.
562 @handle: handle returned by cs_open()
563 @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
564 @group_id: group that you want to check if this instruction belong to.
566 @return: true if this instruction indeed belongs to aboved group, or false otherwise.
568 public bool cs_insn_group (csh handle, const(cs_insn)* insn, uint group_id);
571 Check if a disassembled instruction IMPLICITLY used a particular register.
572 Find the register id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
573 Internally, this simply verifies if @reg_id matches any member of insn->regs_read array.
575 NOTE: this API is only valid when detail option is ON (which is OFF by default)
577 WARN: when in 'diet' mode, this API is irrelevant because the engine does not
578 update @regs_read array.
580 @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
581 @reg_id: register that you want to check if this instruction used it.
583 @return: true if this instruction indeed implicitly used aboved register, or false otherwise.
585 public bool cs_reg_read (csh handle, const(cs_insn)* insn, uint reg_id);
588 Check if a disassembled instruction IMPLICITLY modified a particular register.
589 Find the register id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
590 Internally, this simply verifies if @reg_id matches any member of insn->regs_write array.
592 NOTE: this API is only valid when detail option is ON (which is OFF by default)
594 WARN: when in 'diet' mode, this API is irrelevant because the engine does not
595 update @regs_write array.
597 @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
598 @reg_id: register that you want to check if this instruction modified it.
600 @return: true if this instruction indeed implicitly modified aboved register, or false otherwise.
602 public bool cs_reg_write (csh handle, const(cs_insn)* insn, uint reg_id);
605 Count the number of operands of a given type.
606 Find the operand type in header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
608 NOTE: this API is only valid when detail option is ON (which is OFF by default)
610 @handle: handle returned by cs_open()
611 @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
612 @op_type: Operand type to be found.
614 @return: number of operands of given type @op_type in instruction @insn,
615 or -1 on failure.
617 public int cs_op_count (csh handle, const(cs_insn)* insn, uint op_type);
620 Retrieve the position of operand of given type in <arch>.operands[] array.
621 Later, the operand can be accessed using the returned position.
622 Find the operand type in header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
624 NOTE: this API is only valid when detail option is ON (which is OFF by default)
626 @handle: handle returned by cs_open()
627 @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_iter()
628 @op_type: Operand type to be found.
629 @position: position of the operand to be found. This must be in the range
630 [1, cs_op_count(handle, insn, op_type)]
632 @return: index of operand of given type @op_type in <arch>.operands[] array
633 in instruction @insn, or -1 on failure.
635 public int cs_op_index (csh handle, const(cs_insn)* insn, uint op_type, uint position);
637 // Type of array to keep the list of registers
638 alias cs_regs = ushort[64];
641 Retrieve all the registers accessed by an instruction, either explicitly or
642 implicitly.
644 WARN: when in 'diet' mode, this API is irrelevant because engine does not
645 store registers.
647 @handle: handle returned by cs_open()
648 @insn: disassembled instruction structure returned from cs_disasm() or cs_disasm_iter()
649 @regs_read: on return, this array contains all registers read by instruction.
650 @regs_read_count: number of registers kept inside @regs_read array.
651 @regs_write: on return, this array contains all registers written by instruction.
652 @regs_write_count: number of registers kept inside @regs_write array.
654 @return CS_ERR_OK on success, or other value on failure (refer to cs_err enum
655 for detailed error).
657 public cs_err cs_regs_access (csh handle, const(cs_insn)* insn, cs_regs regs_read, ubyte* regs_read_count, cs_regs regs_write, ubyte* regs_write_count);