1 /* udis86 - libudis86/types.h 2 * 3 * Copyright (c) 2002-2013 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 27 module udis86.c.types; 28 29 import udis86.c.extern_; 30 import udis86.c.itab; 31 32 import core.stdc.stdio; 33 34 extern (C): 35 36 /// All possible "types" of objects in udis86. Order is Important! 37 enum ud_type 38 { 39 UD_NONE, 40 /* 8 bit GPRs */ 41 UD_R_AL, UD_R_CL, UD_R_DL, UD_R_BL, 42 UD_R_AH, UD_R_CH, UD_R_DH, UD_R_BH, 43 UD_R_SPL, UD_R_BPL, UD_R_SIL, UD_R_DIL, 44 UD_R_R8B, UD_R_R9B, UD_R_R10B, UD_R_R11B, 45 UD_R_R12B, UD_R_R13B, UD_R_R14B, UD_R_R15B, 46 /* 16 bit GPRs */ 47 UD_R_AX, UD_R_CX, UD_R_DX, UD_R_BX, 48 UD_R_SP, UD_R_BP, UD_R_SI, UD_R_DI, 49 UD_R_R8W, UD_R_R9W, UD_R_R10W, UD_R_R11W, 50 UD_R_R12W, UD_R_R13W, UD_R_R14W, UD_R_R15W, 51 /* 32 bit GPRs */ 52 UD_R_EAX, UD_R_ECX, UD_R_EDX, UD_R_EBX, 53 UD_R_ESP, UD_R_EBP, UD_R_ESI, UD_R_EDI, 54 UD_R_R8D, UD_R_R9D, UD_R_R10D, UD_R_R11D, 55 UD_R_R12D, UD_R_R13D, UD_R_R14D, UD_R_R15D, 56 /* 64 bit GPRs */ 57 UD_R_RAX, UD_R_RCX, UD_R_RDX, UD_R_RBX, 58 UD_R_RSP, UD_R_RBP, UD_R_RSI, UD_R_RDI, 59 UD_R_R8, UD_R_R9, UD_R_R10, UD_R_R11, 60 UD_R_R12, UD_R_R13, UD_R_R14, UD_R_R15, 61 /* segment registers */ 62 UD_R_ES, UD_R_CS, UD_R_SS, UD_R_DS, 63 UD_R_FS, UD_R_GS, 64 /* control registers*/ 65 UD_R_CR0, UD_R_CR1, UD_R_CR2, UD_R_CR3, 66 UD_R_CR4, UD_R_CR5, UD_R_CR6, UD_R_CR7, 67 UD_R_CR8, UD_R_CR9, UD_R_CR10, UD_R_CR11, 68 UD_R_CR12, UD_R_CR13, UD_R_CR14, UD_R_CR15, 69 /* debug registers */ 70 UD_R_DR0, UD_R_DR1, UD_R_DR2, UD_R_DR3, 71 UD_R_DR4, UD_R_DR5, UD_R_DR6, UD_R_DR7, 72 UD_R_DR8, UD_R_DR9, UD_R_DR10, UD_R_DR11, 73 UD_R_DR12, UD_R_DR13, UD_R_DR14, UD_R_DR15, 74 /* mmx registers */ 75 UD_R_MM0, UD_R_MM1, UD_R_MM2, UD_R_MM3, 76 UD_R_MM4, UD_R_MM5, UD_R_MM6, UD_R_MM7, 77 /* x87 registers */ 78 UD_R_ST0, UD_R_ST1, UD_R_ST2, UD_R_ST3, 79 UD_R_ST4, UD_R_ST5, UD_R_ST6, UD_R_ST7, 80 /* extended multimedia registers */ 81 UD_R_XMM0, UD_R_XMM1, UD_R_XMM2, UD_R_XMM3, 82 UD_R_XMM4, UD_R_XMM5, UD_R_XMM6, UD_R_XMM7, 83 UD_R_XMM8, UD_R_XMM9, UD_R_XMM10, UD_R_XMM11, 84 UD_R_XMM12, UD_R_XMM13, UD_R_XMM14, UD_R_XMM15, 85 /* 256B multimedia registers */ 86 UD_R_YMM0, UD_R_YMM1, UD_R_YMM2, UD_R_YMM3, 87 UD_R_YMM4, UD_R_YMM5, UD_R_YMM6, UD_R_YMM7, 88 UD_R_YMM8, UD_R_YMM9, UD_R_YMM10, UD_R_YMM11, 89 UD_R_YMM12, UD_R_YMM13, UD_R_YMM14, UD_R_YMM15, 90 UD_R_RIP, 91 /* Operand Types */ 92 UD_OP_REG, UD_OP_MEM, UD_OP_PTR, UD_OP_IMM, 93 UD_OP_JIMM, UD_OP_CONST 94 } 95 96 union ud_lval 97 { 98 byte sbyte; 99 ubyte ubyte_; 100 short sword; 101 ushort uword; 102 int sdword; 103 uint udword; 104 long sqword; 105 ulong uqword; 106 Ptr ptr; 107 108 struct Ptr 109 { 110 ushort seg; 111 uint off; 112 } 113 } 114 115 /// Disassembled instruction operand 116 struct ud_operand 117 { 118 ud_type type; 119 ubyte size; 120 ud_type base; 121 ud_type index; 122 ubyte scale; 123 ubyte offset; 124 ud_lval lval; 125 ulong _legacy; 126 ubyte _oprcode; 127 } 128 129 /// udis86 object 130 struct ud 131 { 132 int function (ud*) inp_hook; 133 FILE* inp_file; 134 const(ubyte)* inp_buf; 135 size_t inp_buf_size; 136 size_t inp_buf_index; 137 ubyte inp_curr; 138 size_t inp_ctr; 139 ubyte[64] inp_sess; 140 int inp_end; 141 void function (ud*) translator; 142 ulong insn_offset; 143 char[64] insn_hexcode; 144 145 /// Assembly output buffer 146 char* asm_buf; 147 size_t asm_buf_size; 148 size_t asm_buf_fill; 149 char[128] asm_buf_int; 150 151 /// Symbol resolver for use in the translation phase 152 const(char)* function (ud*, ulong, long*) sym_resolver; 153 154 ubyte dis_mode; 155 ulong pc; 156 ubyte vendor; 157 ud_mnemonic_code mnemonic; 158 ud_operand[3] operand; 159 ubyte error; 160 ubyte pfx_rex; 161 ubyte pfx_seg; 162 ubyte pfx_opr; 163 ubyte pfx_adr; 164 ubyte pfx_lock; 165 ubyte pfx_str; 166 ubyte pfx_rep; 167 ubyte pfx_repe; 168 ubyte pfx_repne; 169 ubyte opr_mode; 170 ubyte adr_mode; 171 ubyte br_far; 172 ubyte br_near; 173 ubyte have_modrm; 174 ubyte modrm; 175 ubyte primary_opcode; 176 void* user_opaque_data; 177 ud_itab_entry* itab_entry; 178 ud_lookup_table_list_entry* le; 179 } 180 181 struct ud_itab_entry; 182 struct ud_lookup_table_list_entry; 183 184 alias ud_type_t = ud_type; 185 alias ud_mnemonic_code_t = ud_mnemonic_code; 186 187 alias ud_t = ud; 188 alias ud_operand_t = ud_operand; 189 190 enum UD_SYN_INTEL = &ud_translate_intel; 191 enum UD_SYN_ATT = &ud_translate_att; 192 193 enum UD_EOI = -1; 194 enum UD_INP_CACHE_SZ = 32; 195 enum UD_VENDER_AMD = 0; 196 enum UD_VENDOR_INTEL = 1; 197 enum UD_VENDOR_ANY = 2;