1 /* udis86 - libudis86/udis86.c
3 * Copyright (c) 2002-2009 Vivek Thampi
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __UD_STANDALONE__
33 #endif /* __UD_STANDALONE__ */
35 /* =============================================================================
36 * ud_init() - Initializes ud_t object.
37 * =============================================================================
42 memset((void*)u, 0, sizeof(struct ud));
44 u->mnemonic = UD_Iinvalid;
46 #ifndef __UD_STANDALONE__
47 ud_set_input_file(u, stdin);
48 #endif /* __UD_STANDALONE__ */
51 /* =============================================================================
52 * ud_disassemble() - disassembles one instruction and returns the number of
53 * bytes disassembled. A zero means end of disassembly.
54 * =============================================================================
57 ud_disassemble(struct ud* u)
63 u->insn_buffer[0] = u->insn_hexcode[0] = 0;
66 if (ud_decode(u) == 0)
70 return ud_insn_len(u);
73 /* =============================================================================
74 * ud_set_mode() - Set Disassemly Mode.
75 * =============================================================================
78 ud_set_mode(struct ud* u, uint8_t m)
83 case 64: u->dis_mode = m ; return;
84 default: u->dis_mode = 16; return;
88 /* =============================================================================
89 * ud_set_vendor() - Set vendor.
90 * =============================================================================
93 ud_set_vendor(struct ud* u, unsigned v)
103 u->vendor = UD_VENDOR_AMD;
107 /* =============================================================================
108 * ud_set_pc() - Sets code origin.
109 * =============================================================================
112 ud_set_pc(struct ud* u, uint64_t o)
117 /* =============================================================================
118 * ud_set_syntax() - Sets the output syntax.
119 * =============================================================================
122 ud_set_syntax(struct ud* u, void (*t)(struct ud*))
127 /* =============================================================================
128 * ud_insn() - returns the disassembled instruction
129 * =============================================================================
132 ud_insn_asm(struct ud* u)
134 return u->insn_buffer;
137 /* =============================================================================
138 * ud_insn_offset() - Returns the offset.
139 * =============================================================================
142 ud_insn_off(struct ud* u)
144 return u->insn_offset;
148 /* =============================================================================
149 * ud_insn_hex() - Returns hex form of disassembled instruction.
150 * =============================================================================
153 ud_insn_hex(struct ud* u)
155 return u->insn_hexcode;
158 /* =============================================================================
159 * ud_insn_ptr() - Returns code disassembled.
160 * =============================================================================
163 ud_insn_ptr(struct ud* u)
168 /* =============================================================================
169 * ud_insn_len() - Returns the count of bytes disassembled.
170 * =============================================================================
173 ud_insn_len(struct ud* u)