Rizin
unix-like reverse engineering framework and cli tools
X86.java
Go to the documentation of this file.
1 // Capstone Java binding
2 // By Nguyen Anh Quynh & Dang Hoang Vu, 2013
3 
4 package capstone;
5 
6 import com.sun.jna.Structure;
7 import com.sun.jna.Union;
8 
9 import java.util.List;
10 import java.util.Arrays;
11 
12 import static capstone.X86_const.*;
13 
14 public class X86 {
15 
16  public static class MemType extends Structure {
17  public int segment;
18  public int base;
19  public int index;
20  public int scale;
21  public long disp;
22 
23  @Override
24  public List getFieldOrder() {
25  return Arrays.asList("segment", "base", "index", "scale", "disp");
26  }
27  }
28 
29  public static class Encoding extends Structure {
30  public byte modrmOffset;
31  public byte dispOffset;
32  public byte dispSize;
33  public byte immOffset;
34  public byte immSize;
35 
36  @Override
37  public List getFieldOrder() {
38  return Arrays.asList("modrmOffset", "dispOffset", "dispSize", "immOffset", "immSize");
39  }
40  }
41 
42  public static class OpValue extends Union {
43  public int reg;
44  public long imm;
45  public MemType mem;
46 
47  @Override
48  public List getFieldOrder() {
49  return Arrays.asList("reg", "imm", "mem");
50  }
51  }
52 
53  public static class Operand extends Structure {
54  public int type;
55  public OpValue value;
56  public byte size;
57  public byte access;
58  public int avx_bcast;
59  public boolean avx_zero_opmask;
60 
61  public void read() {
62  super.read();
63  if (type == X86_OP_MEM)
64  value.setType(MemType.class);
65  if (type == X86_OP_IMM)
66  value.setType(Long.TYPE);
67  if (type == X86_OP_REG)
68  value.setType(Integer.TYPE);
69  if (type == X86_OP_INVALID)
70  return;
71  readField("value");
72  }
73 
74  @Override
75  public List getFieldOrder() {
76  return Arrays.asList("type", "value", "size", "access", "avx_bcast", "avx_zero_opmask");
77  }
78  }
79 
80  public static class UnionOpInfo extends Capstone.UnionOpInfo {
81  public byte [] prefix;
82  public byte [] opcode;
83  public byte rex;
84  public byte addr_size;
85  public byte modrm;
86  public byte sib;
87  public long disp;
88  public int sib_index;
89  public byte sib_scale;
90  public int sib_base;
91  public int xop_cc;
92  public int sse_cc;
93  public int avx_cc;
94  public byte avx_sae;
95  public int avx_rm;
96  public long eflags;
97 
98  public byte op_count;
99 
100  public Operand [] op;
101 
103 
104  public UnionOpInfo() {
105  op = new Operand[8];
106  opcode = new byte[4];
107  prefix = new byte[4];
108  }
109 
110  @Override
111  public List getFieldOrder() {
112  return Arrays.asList("prefix", "opcode", "rex", "addr_size",
113  "modrm", "sib", "disp", "sib_index", "sib_scale", "sib_base", "xop_cc", "sse_cc", "avx_cc", "avx_sae", "avx_rm", "eflags", "op_count", "op", "encoding");
114  }
115  }
116 
117  public static class OpInfo extends Capstone.OpInfo {
118  public byte [] prefix;
119  public byte [] opcode;
120  public byte opSize;
121  public byte rex;
122  public byte addrSize;
123  public byte dispSize;
124  public byte immSize;
125  public byte modrm;
126  public byte sib;
127  public long disp;
128  public int sibIndex;
129  public byte sibScale;
130  public int sibBase;
131  public int xopCC;
132  public int sseCC;
133  public int avxCC;
134  public boolean avxSae;
135  public int avxRm;
136  public long eflags;
137 
138  public Operand[] op;
139 
141 
142  public OpInfo(UnionOpInfo e) {
143  prefix = e.prefix;
144  opcode = e.opcode;
145  rex = e.rex;
146  addrSize = e.addr_size;
147  modrm = e.modrm;
148  sib = e.sib;
149  disp = e.disp;
150  sibIndex = e.sib_index;
151  sibScale = e.sib_scale;
152  sibBase = e.sib_base;
153  xopCC = e.xop_cc;
154  sseCC = e.sse_cc;
155  avxCC = e.avx_cc;
156  avxSae = e.avx_sae > 0;
157  avxRm = e.avx_rm;
158  eflags = e.eflags;
159  op = new Operand[e.op_count];
160  for (int i=0; i<e.op_count; i++)
161  op[i] = e.op[i];
162  encoding = e.encoding;
163  }
164  }
165 }
#define e(frag)
lzma_index ** i
Definition: index.h:629
@ X86_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: x86.h:161
@ X86_OP_INVALID
= CS_OP_INVALID (Uninitialized).
Definition: x86.h:159
@ X86_OP_REG
= CS_OP_REG (Register operand).
Definition: x86.h:160
@ X86_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: x86.h:162
List getFieldOrder()
Definition: X86.java:37
List getFieldOrder()
Definition: X86.java:24
boolean avxSae
Definition: X86.java:134
OpInfo(UnionOpInfo e)
Definition: X86.java:142
Encoding encoding
Definition: X86.java:140
Operand[] op
Definition: X86.java:138
List getFieldOrder()
Definition: X86.java:48
OpValue value
Definition: X86.java:55
List getFieldOrder()
Definition: X86.java:75
boolean avx_zero_opmask
Definition: X86.java:59
Definition: Arm.java:4
Definition: dis.c:32