]>
Commit | Line | Data |
---|---|---|
bbe45369 | 1 | /* udis86 - libudis86/types.h |
2 | * | |
3 | * Copyright (c) 2002-2009 Vivek Thampi | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without modification, | |
7 | * are permitted provided that the following conditions are met: | |
8 | * | |
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. | |
14 | * | |
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. | |
25 | */ | |
26 | #ifndef UD_TYPES_H | |
27 | #define UD_TYPES_H | |
28 | ||
29 | #ifdef __KERNEL__ | |
30 | /* -D__KERNEL__ is automatically passed on the command line when | |
31 | building something as part of the Linux kernel */ | |
32 | # include <linux/kernel.h> | |
33 | # include <linux/string.h> | |
34 | # define __UD_STANDALONE__ 1 | |
35 | #endif /* __KERNEL__ */ | |
36 | ||
37 | #include "itab.h" | |
38 | ||
39 | #ifndef __UD_STANDALONE__ | |
40 | # include <stdio.h> | |
41 | #endif /* __UD_STANDALONE__ */ | |
42 | ||
43 | #ifdef _MSC_VER | |
44 | # define FMT64 "%I64" | |
45 | typedef unsigned __int8 uint8_t; | |
46 | typedef unsigned __int16 uint16_t; | |
47 | typedef unsigned __int32 uint32_t; | |
48 | typedef unsigned __int64 uint64_t; | |
49 | typedef __int8 int8_t; | |
50 | typedef __int16 int16_t; | |
51 | typedef __int32 int32_t; | |
52 | typedef __int64 int64_t; | |
53 | #else | |
54 | # define FMT64 "%ll" | |
55 | # ifndef __UD_STANDALONE__ | |
56 | # include <inttypes.h> | |
57 | # endif /* __UD_STANDALONE__ */ | |
58 | #endif | |
59 | ||
60 | /* ----------------------------------------------------------------------------- | |
61 | * All possible "types" of objects in udis86. Order is Important! | |
62 | * ----------------------------------------------------------------------------- | |
63 | */ | |
64 | enum ud_type | |
65 | { | |
66 | UD_NONE, | |
67 | ||
68 | /* 8 bit GPRs */ | |
69 | UD_R_AL, UD_R_CL, UD_R_DL, UD_R_BL, | |
70 | UD_R_AH, UD_R_CH, UD_R_DH, UD_R_BH, | |
71 | UD_R_SPL, UD_R_BPL, UD_R_SIL, UD_R_DIL, | |
72 | UD_R_R8B, UD_R_R9B, UD_R_R10B, UD_R_R11B, | |
73 | UD_R_R12B, UD_R_R13B, UD_R_R14B, UD_R_R15B, | |
74 | ||
75 | /* 16 bit GPRs */ | |
76 | UD_R_AX, UD_R_CX, UD_R_DX, UD_R_BX, | |
77 | UD_R_SP, UD_R_BP, UD_R_SI, UD_R_DI, | |
78 | UD_R_R8W, UD_R_R9W, UD_R_R10W, UD_R_R11W, | |
79 | UD_R_R12W, UD_R_R13W, UD_R_R14W, UD_R_R15W, | |
80 | ||
81 | /* 32 bit GPRs */ | |
82 | UD_R_EAX, UD_R_ECX, UD_R_EDX, UD_R_EBX, | |
83 | UD_R_ESP, UD_R_EBP, UD_R_ESI, UD_R_EDI, | |
84 | UD_R_R8D, UD_R_R9D, UD_R_R10D, UD_R_R11D, | |
85 | UD_R_R12D, UD_R_R13D, UD_R_R14D, UD_R_R15D, | |
86 | ||
87 | /* 64 bit GPRs */ | |
88 | UD_R_RAX, UD_R_RCX, UD_R_RDX, UD_R_RBX, | |
89 | UD_R_RSP, UD_R_RBP, UD_R_RSI, UD_R_RDI, | |
90 | UD_R_R8, UD_R_R9, UD_R_R10, UD_R_R11, | |
91 | UD_R_R12, UD_R_R13, UD_R_R14, UD_R_R15, | |
92 | ||
93 | /* segment registers */ | |
94 | UD_R_ES, UD_R_CS, UD_R_SS, UD_R_DS, | |
95 | UD_R_FS, UD_R_GS, | |
96 | ||
97 | /* control registers*/ | |
98 | UD_R_CR0, UD_R_CR1, UD_R_CR2, UD_R_CR3, | |
99 | UD_R_CR4, UD_R_CR5, UD_R_CR6, UD_R_CR7, | |
100 | UD_R_CR8, UD_R_CR9, UD_R_CR10, UD_R_CR11, | |
101 | UD_R_CR12, UD_R_CR13, UD_R_CR14, UD_R_CR15, | |
102 | ||
103 | /* debug registers */ | |
104 | UD_R_DR0, UD_R_DR1, UD_R_DR2, UD_R_DR3, | |
105 | UD_R_DR4, UD_R_DR5, UD_R_DR6, UD_R_DR7, | |
106 | UD_R_DR8, UD_R_DR9, UD_R_DR10, UD_R_DR11, | |
107 | UD_R_DR12, UD_R_DR13, UD_R_DR14, UD_R_DR15, | |
108 | ||
109 | /* mmx registers */ | |
110 | UD_R_MM0, UD_R_MM1, UD_R_MM2, UD_R_MM3, | |
111 | UD_R_MM4, UD_R_MM5, UD_R_MM6, UD_R_MM7, | |
112 | ||
113 | /* x87 registers */ | |
114 | UD_R_ST0, UD_R_ST1, UD_R_ST2, UD_R_ST3, | |
115 | UD_R_ST4, UD_R_ST5, UD_R_ST6, UD_R_ST7, | |
116 | ||
117 | /* extended multimedia registers */ | |
118 | UD_R_XMM0, UD_R_XMM1, UD_R_XMM2, UD_R_XMM3, | |
119 | UD_R_XMM4, UD_R_XMM5, UD_R_XMM6, UD_R_XMM7, | |
120 | UD_R_XMM8, UD_R_XMM9, UD_R_XMM10, UD_R_XMM11, | |
121 | UD_R_XMM12, UD_R_XMM13, UD_R_XMM14, UD_R_XMM15, | |
122 | ||
123 | UD_R_RIP, | |
124 | ||
125 | /* Operand Types */ | |
126 | UD_OP_REG, UD_OP_MEM, UD_OP_PTR, UD_OP_IMM, | |
127 | UD_OP_JIMM, UD_OP_CONST | |
128 | }; | |
129 | ||
130 | /* ----------------------------------------------------------------------------- | |
131 | * struct ud_operand - Disassembled instruction Operand. | |
132 | * ----------------------------------------------------------------------------- | |
133 | */ | |
134 | struct ud_operand | |
135 | { | |
136 | enum ud_type type; | |
137 | uint8_t size; | |
138 | union { | |
139 | int8_t sbyte; | |
140 | uint8_t ubyte; | |
141 | int16_t sword; | |
142 | uint16_t uword; | |
143 | int32_t sdword; | |
144 | uint32_t udword; | |
145 | int64_t sqword; | |
146 | uint64_t uqword; | |
147 | ||
148 | struct { | |
149 | uint16_t seg; | |
150 | uint32_t off; | |
151 | } ptr; | |
152 | } lval; | |
153 | ||
154 | enum ud_type base; | |
155 | enum ud_type index; | |
156 | uint8_t offset; | |
157 | uint8_t scale; | |
158 | }; | |
159 | ||
160 | /* ----------------------------------------------------------------------------- | |
161 | * struct ud - The udis86 object. | |
162 | * ----------------------------------------------------------------------------- | |
163 | */ | |
164 | struct ud | |
165 | { | |
166 | int (*inp_hook) (struct ud*); | |
167 | uint8_t inp_curr; | |
168 | uint8_t inp_fill; | |
169 | #ifndef __UD_STANDALONE__ | |
170 | FILE* inp_file; | |
171 | #endif | |
172 | uint8_t inp_ctr; | |
173 | uint8_t* inp_buff; | |
174 | uint8_t* inp_buff_end; | |
175 | uint8_t inp_end; | |
176 | void (*translator)(struct ud*); | |
177 | uint64_t insn_offset; | |
178 | char insn_hexcode[32]; | |
179 | char insn_buffer[64]; | |
180 | unsigned int insn_fill; | |
181 | uint8_t dis_mode; | |
182 | uint64_t pc; | |
183 | uint8_t vendor; | |
184 | struct map_entry* mapen; | |
185 | enum ud_mnemonic_code mnemonic; | |
186 | struct ud_operand operand[3]; | |
187 | uint8_t error; | |
188 | uint8_t pfx_rex; | |
189 | uint8_t pfx_seg; | |
190 | uint8_t pfx_opr; | |
191 | uint8_t pfx_adr; | |
192 | uint8_t pfx_lock; | |
193 | uint8_t pfx_rep; | |
194 | uint8_t pfx_repe; | |
195 | uint8_t pfx_repne; | |
196 | uint8_t pfx_insn; | |
197 | uint8_t default64; | |
198 | uint8_t opr_mode; | |
199 | uint8_t adr_mode; | |
200 | uint8_t br_far; | |
201 | uint8_t br_near; | |
202 | uint8_t implicit_addr; | |
203 | uint8_t c1; | |
204 | uint8_t c2; | |
205 | uint8_t c3; | |
206 | uint8_t inp_cache[256]; | |
207 | uint8_t inp_sess[64]; | |
208 | void * user_opaque_data; | |
209 | struct ud_itab_entry * itab_entry; | |
210 | }; | |
211 | ||
212 | /* ----------------------------------------------------------------------------- | |
213 | * Type-definitions | |
214 | * ----------------------------------------------------------------------------- | |
215 | */ | |
216 | typedef enum ud_type ud_type_t; | |
217 | typedef enum ud_mnemonic_code ud_mnemonic_code_t; | |
218 | ||
219 | typedef struct ud ud_t; | |
220 | typedef struct ud_operand ud_operand_t; | |
221 | ||
222 | #define UD_SYN_INTEL ud_translate_intel | |
223 | #define UD_SYN_ATT ud_translate_att | |
224 | #define UD_EOI -1 | |
225 | #define UD_INP_CACHE_SZ 32 | |
226 | #define UD_VENDOR_AMD 0 | |
227 | #define UD_VENDOR_INTEL 1 | |
228 | #define UD_VENDOR_ANY 2 | |
229 | ||
230 | #define bail_out(ud,error_code) longjmp( (ud)->bailout, error_code ) | |
231 | #define try_decode(ud) if ( setjmp( (ud)->bailout ) == 0 ) | |
232 | #define catch_error() else | |
233 | ||
234 | #endif |