libudis86_sys/api.rs
1use libc;
2use types::{ud, ud_operand};
3use itab::ud_mnemonic_code;
4
5extern "C" {
6 /// Initializes an instance.
7 pub fn ud_init(ud: *mut ud);
8
9 /// Sets the mode of disassembly. Possible values are 16, 32, and 64. By
10 /// default, the library works in 32bit mode.
11 pub fn ud_set_mode(ud: *mut ud, mode: u8);
12
13 /// Sets the program counter (IP/EIP/RIP). This changes the offset of the
14 /// assembly output generated, with direct effect on branch instructions.
15 pub fn ud_set_pc(ud: *mut ud, program_counter: u64);
16
17 /// Sets a pointer to a function, to callback for input. The callback is
18 /// invoked each time libudis86 needs the next byte in the input stream. To
19 /// single end-of-input, this callback must return the constant UD_EOI.
20 pub fn ud_set_input_hook(ud: *mut ud, callback: ::std::option::Option<unsafe extern "C" fn(ud: *mut ud) -> libc::c_int>);
21
22 /// Sets the input source for the library to a buffer of size bytes.
23 pub fn ud_set_input_buffer(ud: *mut ud, data: *const u8, len: usize);
24
25 /// Sets the input source to a file pointed to by a given standard library
26 /// FILE pointer. Note that libudis86 does not perform any checks, and
27 /// assumes that the file pointer is properly initialized and open for
28 /// reading.
29 pub fn ud_set_input_file(ud: *mut ud, file: *mut libc::FILE);
30
31 /// Sets the vendor of whose instruction to choose from. This is only useful
32 /// for selecting the VMX or SVM instruction sets at which point INTEL and
33 /// AMD have diverged significantly. At a later stage, support for a more
34 /// granular selection of instruction sets maybe added.
35 ///
36 /// - UD_VENDOR_INTEL - for INTEL instruction set.
37 /// - UD_VENDOR_ATT - for AMD instruction set.
38 /// - UD_VENDOR_ANY - for any valid instruction in either INTEL or AMD.
39 pub fn ud_set_vendor(ud: *mut ud, vendor: libc::c_uint);
40
41 /// Sets the function that translates the intermediate decode information to
42 /// a human readable form. There are two inbuilt translators,
43 ///
44 /// - `ud_translate_intel` for INTEL (NASM-like) syntax.
45 /// - `ud_translate_att` for AT&T (GAS-like) syntax.
46 ///
47 /// If you do not want libudis86 to translate, you can pass NULL to the
48 /// function, with no more translations thereafter. This is useful when you
49 /// only want to identify chunks of code and then create the assembly output
50 /// if needed, or when you are only interested in examining the instructions
51 /// and do not want to waste cycles generating the assembly language output.
52 ///
53 /// If you want to create your own translator, you can specify a pointer to
54 /// your own function. This function must accept a single parameter, the
55 /// udis86 object ud_t, and it will be invoked everytime an instruction is
56 /// decoded.
57 pub fn ud_set_syntax(ud: *mut ud, translator: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ud)>);
58
59 /// Skips ahead n number of bytes in the input stream.
60 pub fn ud_input_skip(ud: *mut ud, skipn: usize);
61
62 /// Test for end of input. You can use this function to test if udis86 has
63 /// exhausted the input.
64 pub fn ud_input_end(ud: *const ud) -> libc::c_int;
65
66 /// Returns the number of bytes decoded.
67 pub fn ud_decode(ud: *mut ud) -> libc::c_uint;
68
69 /// Disassembles the next instruction in the input stream.
70 /// Returns the number of bytes disassembled. A 0 indicates end of input.
71 /// Note, to restart disassembly after the end of input, you must call one
72 /// of the input setting functions with a new source of input.
73 ///
74 /// A common use-case pattern for this function is in a loop:
75 ///
76 /// ```norun
77 /// while ud_disassemble(&mut object) > 0 {
78 /// // Use or print decode info.
79 /// }
80 /// ```
81 pub fn ud_disassemble(ud: *mut ud) -> libc::c_uint;
82
83 /// Translator for the Intel syntax.
84 pub fn ud_translate_intel(ud: *mut ud);
85
86 /// Translator for the AT&T syntax.
87 pub fn ud_translate_att(ud: *mut ud);
88
89 /// If the syntax is specified, returns pointer to the character string
90 /// holding assembly language representation of the disassembled
91 /// instruction.
92 pub fn ud_insn_asm(ud: *const ud) -> *const libc::c_char;
93
94 /// Returns pointer to the buffer holding the instruction bytes. Use
95 /// `ud_insn_len` to determine the size of this buffer.
96 pub fn ud_insn_ptr(ud: *const ud) -> *const u8;
97
98 /// Returns the offset of the disassembled instruction in terms of the
99 /// program counter value specified initially.
100 pub fn ud_insn_off(ud: *const ud) -> u64;
101
102 /// Returns pointer to a character string holding the hexadecimal
103 /// representation of the disassembled bytes.
104 pub fn ud_insn_hex(ud: *mut ud) -> *const libc::c_char;
105
106 /// Returns the number of bytes disassembled.
107 pub fn ud_insn_len(ud: *const ud) -> libc::c_uint;
108
109 /// Returns a reference (`ud_operand`) to the nth (starting with 0) operand
110 /// of the instruction. If the instruction does not have such an operand,
111 /// the function returns `null`.
112 pub fn ud_insn_opr(ud: *const ud, n: libc::c_uint) -> *const ud_operand;
113
114 /// Returns true if the operand uses a segment register.
115 pub fn ud_opr_is_sreg(opr: *const ud_operand) -> libc::c_int;
116
117 /// Returns true if the operand uses a general purpose register.
118 pub fn ud_opr_is_gpr(opr: *const ud_operand) -> libc::c_int;
119
120 /// Returns the instruction mnemonic in the form of an enumerated constant
121 /// (`ud_mnemonic_code`). As a convention all mnemonic constants are
122 /// composed by prefixing standard instruction mnemonics with `UD_I`. For
123 /// example, the enumerations for mov, xor and jmp are `UD_Imov`, `UD_Ixor`,
124 /// and `UD_Ijmp`, respectively.
125 pub fn ud_insn_mnemonic(ud: *const ud) -> ud_mnemonic_code;
126
127 /// Returns a pointer to a character string corresponding to the given
128 /// mnemonic code. Returns a `null` if the code is invalid.
129 pub fn ud_lookup_mnemonic(code: ud_mnemonic_code) -> *const libc::c_char;
130
131 /// Associates a pointer with the udis86 object to be retrieved and used in
132 /// client functions, such as the input hook callback function.
133 pub fn ud_set_user_opaque_data(ud: *mut ud, data: *mut libc::c_void);
134
135 /// Returns any pointer associated with the udis86 object, using the
136 /// `ud_set_user_opaque_data` function.
137 pub fn ud_get_user_opaque_data(ud: *const ud) -> *mut libc::c_void;
138
139 /// Sets a custom assembler output buffer.
140 pub fn ud_set_asm_buffer(ud: *mut ud, data: *mut libc::c_char, len: usize);
141
142 /// Sets a symbol resolver for relative targets used in the translation
143 /// phase.
144 ///
145 /// The resolver is a function that takes a `u64` address and returns a
146 /// symbolic name for the that address. The function also takes a second
147 /// argument pointing to an integer that the client can optionally set to a
148 /// non-zero value for offsetted targets. (symbol + offset) The function may
149 /// also return `null`, in which case the translator only prints the target
150 /// address.
151 ///
152 /// The function pointer maybe `null` which resets symbol resolution.
153 pub fn ud_set_sym_resolver(ud: *mut ud, resolver: ::std::option::Option<unsafe extern "C" fn(ud: *mut ud, addr: u64, offset: *mut i64) -> *const libc::c_char>);
154}