You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. #ifndef UD_TYPES_H
  27. #define UD_TYPES_H
  28. #ifdef __KERNEL__
  29. /* -D__KERNEL__ is automatically passed on the command line when
  30. building something as part of the Linux kernel */
  31. # include <linux/kernel.h>
  32. # include <linux/string.h>
  33. # ifndef __UD_STANDALONE__
  34. # define __UD_STANDALONE__ 1
  35. #endif
  36. #endif /* __KERNEL__ */
  37. #if defined(_MSC_VER) || defined(__BORLANDC__)
  38. # include <stdint.h>
  39. # include <stdio.h>
  40. # define inline __inline /* MS Visual Studio requires __inline
  41. instead of inline for C code */
  42. #elif !defined(__UD_STANDALONE__)
  43. # include <stdio.h>
  44. # include <inttypes.h>
  45. #endif /* !__UD_STANDALONE__ */
  46. /* gcc specific extensions */
  47. #ifdef __GNUC__
  48. # define UD_ATTR_PACKED __attribute__((packed))
  49. #else
  50. # define UD_ATTR_PACKED
  51. #endif /* UD_ATTR_PACKED */
  52. /* -----------------------------------------------------------------------------
  53. * All possible "types" of objects in udis86. Order is Important!
  54. * -----------------------------------------------------------------------------
  55. */
  56. enum ud_type
  57. {
  58. UD_NONE,
  59. /* 8 bit GPRs */
  60. UD_R_AL, UD_R_CL, UD_R_DL, UD_R_BL,
  61. UD_R_AH, UD_R_CH, UD_R_DH, UD_R_BH,
  62. UD_R_SPL, UD_R_BPL, UD_R_SIL, UD_R_DIL,
  63. UD_R_R8B, UD_R_R9B, UD_R_R10B, UD_R_R11B,
  64. UD_R_R12B, UD_R_R13B, UD_R_R14B, UD_R_R15B,
  65. /* 16 bit GPRs */
  66. UD_R_AX, UD_R_CX, UD_R_DX, UD_R_BX,
  67. UD_R_SP, UD_R_BP, UD_R_SI, UD_R_DI,
  68. UD_R_R8W, UD_R_R9W, UD_R_R10W, UD_R_R11W,
  69. UD_R_R12W, UD_R_R13W, UD_R_R14W, UD_R_R15W,
  70. /* 32 bit GPRs */
  71. UD_R_EAX, UD_R_ECX, UD_R_EDX, UD_R_EBX,
  72. UD_R_ESP, UD_R_EBP, UD_R_ESI, UD_R_EDI,
  73. UD_R_R8D, UD_R_R9D, UD_R_R10D, UD_R_R11D,
  74. UD_R_R12D, UD_R_R13D, UD_R_R14D, UD_R_R15D,
  75. /* 64 bit GPRs */
  76. UD_R_RAX, UD_R_RCX, UD_R_RDX, UD_R_RBX,
  77. UD_R_RSP, UD_R_RBP, UD_R_RSI, UD_R_RDI,
  78. UD_R_R8, UD_R_R9, UD_R_R10, UD_R_R11,
  79. UD_R_R12, UD_R_R13, UD_R_R14, UD_R_R15,
  80. /* segment registers */
  81. UD_R_ES, UD_R_CS, UD_R_SS, UD_R_DS,
  82. UD_R_FS, UD_R_GS,
  83. /* control registers*/
  84. UD_R_CR0, UD_R_CR1, UD_R_CR2, UD_R_CR3,
  85. UD_R_CR4, UD_R_CR5, UD_R_CR6, UD_R_CR7,
  86. UD_R_CR8, UD_R_CR9, UD_R_CR10, UD_R_CR11,
  87. UD_R_CR12, UD_R_CR13, UD_R_CR14, UD_R_CR15,
  88. /* debug registers */
  89. UD_R_DR0, UD_R_DR1, UD_R_DR2, UD_R_DR3,
  90. UD_R_DR4, UD_R_DR5, UD_R_DR6, UD_R_DR7,
  91. UD_R_DR8, UD_R_DR9, UD_R_DR10, UD_R_DR11,
  92. UD_R_DR12, UD_R_DR13, UD_R_DR14, UD_R_DR15,
  93. /* mmx registers */
  94. UD_R_MM0, UD_R_MM1, UD_R_MM2, UD_R_MM3,
  95. UD_R_MM4, UD_R_MM5, UD_R_MM6, UD_R_MM7,
  96. /* x87 registers */
  97. UD_R_ST0, UD_R_ST1, UD_R_ST2, UD_R_ST3,
  98. UD_R_ST4, UD_R_ST5, UD_R_ST6, UD_R_ST7,
  99. /* extended multimedia registers */
  100. UD_R_XMM0, UD_R_XMM1, UD_R_XMM2, UD_R_XMM3,
  101. UD_R_XMM4, UD_R_XMM5, UD_R_XMM6, UD_R_XMM7,
  102. UD_R_XMM8, UD_R_XMM9, UD_R_XMM10, UD_R_XMM11,
  103. UD_R_XMM12, UD_R_XMM13, UD_R_XMM14, UD_R_XMM15,
  104. UD_R_RIP,
  105. /* Operand Types */
  106. UD_OP_REG, UD_OP_MEM, UD_OP_PTR, UD_OP_IMM,
  107. UD_OP_JIMM, UD_OP_CONST
  108. };
  109. #include "itab.h"
  110. union ud_lval {
  111. int8_t sbyte;
  112. uint8_t ubyte;
  113. int16_t sword;
  114. uint16_t uword;
  115. int32_t sdword;
  116. uint32_t udword;
  117. int64_t sqword;
  118. uint64_t uqword;
  119. struct {
  120. uint16_t seg;
  121. uint32_t off;
  122. } ptr;
  123. };
  124. /* -----------------------------------------------------------------------------
  125. * struct ud_operand - Disassembled instruction Operand.
  126. * -----------------------------------------------------------------------------
  127. */
  128. struct ud_operand {
  129. enum ud_type type;
  130. uint8_t size;
  131. enum ud_type base;
  132. enum ud_type index;
  133. uint8_t scale;
  134. uint8_t offset;
  135. union ud_lval lval;
  136. /*
  137. * internal use only
  138. */
  139. uint64_t _legacy; /* this will be removed in 1.8 */
  140. uint8_t _oprcode;
  141. };
  142. /* -----------------------------------------------------------------------------
  143. * struct ud - The udis86 object.
  144. * -----------------------------------------------------------------------------
  145. */
  146. struct ud
  147. {
  148. /*
  149. * input buffering
  150. */
  151. int (*inp_hook) (struct ud*);
  152. #ifndef __UD_STANDALONE__
  153. FILE* inp_file;
  154. #endif
  155. const uint8_t* inp_buf;
  156. size_t inp_buf_size;
  157. size_t inp_buf_index;
  158. uint8_t inp_curr;
  159. size_t inp_ctr;
  160. uint8_t inp_sess[64];
  161. int inp_end;
  162. void (*translator)(struct ud*);
  163. uint64_t insn_offset;
  164. char insn_hexcode[64];
  165. /*
  166. * Assembly output buffer
  167. */
  168. char *asm_buf;
  169. size_t asm_buf_size;
  170. size_t asm_buf_fill;
  171. char asm_buf_int[128];
  172. /*
  173. * Symbol resolver for use in the translation phase.
  174. */
  175. const char* (*sym_resolver)(struct ud*, uint64_t addr, int64_t *offset);
  176. uint8_t dis_mode;
  177. uint64_t pc;
  178. uint8_t vendor;
  179. enum ud_mnemonic_code mnemonic;
  180. struct ud_operand operand[3];
  181. uint8_t error;
  182. uint8_t pfx_rex;
  183. uint8_t pfx_seg;
  184. uint8_t pfx_opr;
  185. uint8_t pfx_adr;
  186. uint8_t pfx_lock;
  187. uint8_t pfx_str;
  188. uint8_t pfx_rep;
  189. uint8_t pfx_repe;
  190. uint8_t pfx_repne;
  191. uint8_t opr_mode;
  192. uint8_t adr_mode;
  193. uint8_t br_far;
  194. uint8_t br_near;
  195. uint8_t have_modrm;
  196. uint8_t modrm;
  197. uint8_t primary_opcode;
  198. void * user_opaque_data;
  199. struct ud_itab_entry * itab_entry;
  200. struct ud_lookup_table_list_entry *le;
  201. };
  202. /* -----------------------------------------------------------------------------
  203. * Type-definitions
  204. * -----------------------------------------------------------------------------
  205. */
  206. typedef enum ud_type ud_type_t;
  207. typedef enum ud_mnemonic_code ud_mnemonic_code_t;
  208. typedef struct ud ud_t;
  209. typedef struct ud_operand ud_operand_t;
  210. #define UD_SYN_INTEL ud_translate_intel
  211. #define UD_SYN_ATT ud_translate_att
  212. #define UD_EOI (-1)
  213. #define UD_INP_CACHE_SZ 32
  214. #define UD_VENDOR_AMD 0
  215. #define UD_VENDOR_INTEL 1
  216. #define UD_VENDOR_ANY 2
  217. #endif
  218. /*
  219. vim: set ts=2 sw=2 expandtab
  220. */