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.
26 #ifndef __UD_STANDALONE__
29 #endif /* __UD_STANDALONE__ */
34 /* =============================================================================
35 * ud_init() - Initializes ud_t object.
36 * =============================================================================
41 memset((void*)u, 0, sizeof(struct ud));
43 u->mnemonic = UD_Iinvalid;
45 #ifndef __UD_STANDALONE__
46 ud_set_input_file(u, stdin);
47 #endif /* __UD_STANDALONE__ */
50 /* =============================================================================
51 * ud_disassemble() - disassembles one instruction and returns the number of
52 * bytes disassembled. A zero means end of disassembly.
53 * =============================================================================
56 ud_disassemble(struct ud* u)
62 u->insn_buffer[0] = u->insn_hexcode[0] = 0;
65 if (ud_decode(u) == 0)
69 return ud_insn_len(u);
72 /* =============================================================================
73 * ud_set_mode() - Set Disassemly Mode.
74 * =============================================================================
77 ud_set_mode(struct ud* u, uint8_t m)
82 case 64: u->dis_mode = m ; return;
83 default: u->dis_mode = 16; return;
87 /* =============================================================================
88 * ud_set_vendor() - Set vendor.
89 * =============================================================================
92 ud_set_vendor(struct ud* u, unsigned v)
102 u->vendor = UD_VENDOR_AMD;
106 /* =============================================================================
107 * ud_set_pc() - Sets code origin.
108 * =============================================================================
111 ud_set_pc(struct ud* u, uint64_t o)
116 /* =============================================================================
117 * ud_set_syntax() - Sets the output syntax.
118 * =============================================================================
121 ud_set_syntax(struct ud* u, void (*t)(struct ud*))
126 /* =============================================================================
127 * ud_insn() - returns the disassembled instruction
128 * =============================================================================
131 ud_insn_asm(struct ud* u)
133 return u->insn_buffer;
136 /* =============================================================================
137 * ud_insn_offset() - Returns the offset.
138 * =============================================================================
141 ud_insn_off(struct ud* u)
143 return u->insn_offset;
147 /* =============================================================================
148 * ud_insn_hex() - Returns hex form of disassembled instruction.
149 * =============================================================================
152 ud_insn_hex(struct ud* u)
154 return u->insn_hexcode;
157 /* =============================================================================
158 * ud_insn_ptr() - Returns code disassembled.
159 * =============================================================================
162 ud_insn_ptr(struct ud* u)
167 /* =============================================================================
168 * ud_insn_len() - Returns the count of bytes disassembled.
169 * =============================================================================
172 ud_insn_len(struct ud* u)