]>
git.saurik.com Git - apple/javascriptcore.git/blob - disassembler/udis86/udis86.c
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.
31 #include "udis86_input.h"
32 #include "udis86_extern.h"
34 #ifndef __UD_STANDALONE__
37 #endif /* __UD_STANDALONE__ */
39 /* =============================================================================
40 * ud_init() - Initializes ud_t object.
41 * =============================================================================
46 memset((void*)u
, 0, sizeof(struct ud
));
48 u
->mnemonic
= UD_Iinvalid
;
50 #ifndef __UD_STANDALONE__
51 ud_set_input_file(u
, stdin
);
52 #endif /* __UD_STANDALONE__ */
55 /* =============================================================================
56 * ud_disassemble() - disassembles one instruction and returns the number of
57 * bytes disassembled. A zero means end of disassembly.
58 * =============================================================================
61 ud_disassemble(struct ud
* u
)
67 u
->insn_buffer
[0] = u
->insn_hexcode
[0] = 0;
70 if (ud_decode(u
) == 0)
74 return ud_insn_len(u
);
77 /* =============================================================================
78 * ud_set_mode() - Set Disassemly Mode.
79 * =============================================================================
82 ud_set_mode(struct ud
* u
, uint8_t m
)
87 case 64: u
->dis_mode
= m
; return;
88 default: u
->dis_mode
= 16; return;
92 /* =============================================================================
93 * ud_set_vendor() - Set vendor.
94 * =============================================================================
97 ud_set_vendor(struct ud
* u
, unsigned v
)
100 case UD_VENDOR_INTEL
:
107 u
->vendor
= UD_VENDOR_AMD
;
111 /* =============================================================================
112 * ud_set_pc() - Sets code origin.
113 * =============================================================================
116 ud_set_pc(struct ud
* u
, uint64_t o
)
121 /* =============================================================================
122 * ud_set_syntax() - Sets the output syntax.
123 * =============================================================================
126 ud_set_syntax(struct ud
* u
, void (*t
)(struct ud
*))
131 /* =============================================================================
132 * ud_insn() - returns the disassembled instruction
133 * =============================================================================
136 ud_insn_asm(struct ud
* u
)
138 return u
->insn_buffer
;
141 /* =============================================================================
142 * ud_insn_offset() - Returns the offset.
143 * =============================================================================
146 ud_insn_off(struct ud
* u
)
148 return u
->insn_offset
;
152 /* =============================================================================
153 * ud_insn_hex() - Returns hex form of disassembled instruction.
154 * =============================================================================
157 ud_insn_hex(struct ud
* u
)
159 return u
->insn_hexcode
;
162 /* =============================================================================
163 * ud_insn_ptr() - Returns code disassembled.
164 * =============================================================================
167 ud_insn_ptr(struct ud
* u
)
172 /* =============================================================================
173 * ud_insn_len() - Returns the count of bytes disassembled.
174 * =============================================================================
177 ud_insn_len(struct ud
* u
)
182 #endif // USE(UDIS86)