1 /*
2  * Hacker Disassembler Engine 64
3  * Copyright (c) 2008-2009, Vyacheslav Patkov.
4  * All rights reserved.
5  *
6  * hde64.h: C/C++ header file
7  *
8  */
9 
10 #ifndef _HDE64_H_
11 #define _HDE64_H_
12 
13 /* stdint.h - C99 standard header
14  * http://en.wikipedia.org/wiki/stdint.h
15  *
16  * if your compiler doesn't contain "stdint.h" header (for
17  * example, Microsoft Visual C++), you can download file:
18  *   http://www.azillionmonkeys.com/qed/pstdint.h
19  * and change next line to:
20  *   #include "pstdint.h"
21  */
22 #include "pstdint.h"
23 
24 #define F_MODRM         0x00000001
25 #define F_SIB           0x00000002
26 #define F_IMM8          0x00000004
27 #define F_IMM16         0x00000008
28 #define F_IMM32         0x00000010
29 #define F_IMM64         0x00000020
30 #define F_DISP8         0x00000040
31 #define F_DISP16        0x00000080
32 #define F_DISP32        0x00000100
33 #define F_RELATIVE      0x00000200
34 #define F_ERROR         0x00001000
35 #define F_ERROR_OPCODE  0x00002000
36 #define F_ERROR_LENGTH  0x00004000
37 #define F_ERROR_LOCK    0x00008000
38 #define F_ERROR_OPERAND 0x00010000
39 #define F_PREFIX_REPNZ  0x01000000
40 #define F_PREFIX_REPX   0x02000000
41 #define F_PREFIX_REP    0x03000000
42 #define F_PREFIX_66     0x04000000
43 #define F_PREFIX_67     0x08000000
44 #define F_PREFIX_LOCK   0x10000000
45 #define F_PREFIX_SEG    0x20000000
46 #define F_PREFIX_REX    0x40000000
47 #define F_PREFIX_ANY    0x7f000000
48 
49 #define PREFIX_SEGMENT_CS   0x2e
50 #define PREFIX_SEGMENT_SS   0x36
51 #define PREFIX_SEGMENT_DS   0x3e
52 #define PREFIX_SEGMENT_ES   0x26
53 #define PREFIX_SEGMENT_FS   0x64
54 #define PREFIX_SEGMENT_GS   0x65
55 #define PREFIX_LOCK         0xf0
56 #define PREFIX_REPNZ        0xf2
57 #define PREFIX_REPX         0xf3
58 #define PREFIX_OPERAND_SIZE 0x66
59 #define PREFIX_ADDRESS_SIZE 0x67
60 
61 #pragma pack(push,1)
62 
63 typedef struct {
64     uint8_t len;
65     uint8_t p_rep;
66     uint8_t p_lock;
67     uint8_t p_seg;
68     uint8_t p_66;
69     uint8_t p_67;
70     uint8_t rex;
71     uint8_t rex_w;
72     uint8_t rex_r;
73     uint8_t rex_x;
74     uint8_t rex_b;
75     uint8_t opcode;
76     uint8_t opcode2;
77     uint8_t modrm;
78     uint8_t modrm_mod;
79     uint8_t modrm_reg;
80     uint8_t modrm_rm;
81     uint8_t sib;
82     uint8_t sib_scale;
83     uint8_t sib_index;
84     uint8_t sib_base;
85     union {
86         uint8_t imm8;
87         uint16_t imm16;
88         uint32_t imm32;
89         uint64_t imm64;
90     } imm;
91     union {
92         uint8_t disp8;
93         uint16_t disp16;
94         uint32_t disp32;
95     } disp;
96     uint32_t flags;
97 } hde64s;
98 
99 #pragma pack(pop)
100 
101 #ifdef __cplusplus
102 extern "C" {
103 #endif
104 
105 /* __cdecl */
106 unsigned int hde64_disasm(const void *code, hde64s *hs);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* _HDE64_H_ */
113