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.Arm64_const.*;
13 
14 public class Arm64 {
15 
16   public static class MemType extends Structure {
17     public int base;
18     public int index;
19     public int disp;
20 
21     @Override
getFieldOrder()22     public List getFieldOrder() {
23       return Arrays.asList("base", "index", "disp");
24     }
25   }
26 
27   public static class OpValue extends Union {
28     public int reg;
29     public long imm;
30     public double fp;
31     public MemType mem;
32     public int pstate;
33     public int sys;
34     public int prefetch;
35     public int barrier;
36 
37     @Override
getFieldOrder()38     public List getFieldOrder() {
39       return Arrays.asList("reg", "imm", "fp", "mem", "pstate", "sys", "prefetch", "barrier");
40     }
41   }
42 
43   public static class OpShift extends Structure {
44     public int type;
45     public int value;
46 
47     @Override
getFieldOrder()48     public List getFieldOrder() {
49       return Arrays.asList("type","value");
50     }
51   }
52 
53   public static class Operand extends Structure {
54     public int vector_index;
55     public int vas;
56     public OpShift shift;
57     public int ext;
58     public int type;
59     public OpValue value;
60 
read()61     public void read() {
62       readField("type");
63       if (type == ARM64_OP_MEM)
64         value.setType(MemType.class);
65       if (type == ARM64_OP_FP)
66         value.setType(Double.TYPE);
67       if (type == ARM64_OP_IMM || type == ARM64_OP_CIMM || type == ARM64_OP_REG || type == ARM64_OP_REG_MRS || type == ARM64_OP_REG_MSR || type == ARM64_OP_PSTATE || type == ARM64_OP_SYS || type == ARM64_OP_PREFETCH || type == ARM64_OP_BARRIER)
68         value.setType(Integer.TYPE);
69       if (type == ARM64_OP_INVALID)
70         return;
71       readField("value");
72       readField("ext");
73       readField("shift");
74       readField("vas");
75       readField("vector_index");
76     }
77 
78     @Override
getFieldOrder()79     public List getFieldOrder() {
80       return Arrays.asList("vector_index", "vas", "shift", "ext", "type", "value");
81     }
82   }
83 
84   public static class UnionOpInfo extends Capstone.UnionOpInfo {
85     public int cc;
86     public byte _update_flags;
87     public byte _writeback;
88     public byte op_count;
89 
90     public Operand [] op;
91 
UnionOpInfo()92     public UnionOpInfo() {
93       op = new Operand[8];
94     }
95 
read()96     public void read() {
97       readField("cc");
98       readField("_update_flags");
99       readField("_writeback");
100       readField("op_count");
101       op = new Operand[op_count];
102       if (op_count != 0)
103         readField("op");
104     }
105 
106     @Override
getFieldOrder()107     public List getFieldOrder() {
108       return Arrays.asList("cc", "_update_flags", "_writeback", "op_count", "op");
109     }
110   }
111 
112   public static class OpInfo extends Capstone.OpInfo {
113     public int cc;
114     public boolean updateFlags;
115     public boolean writeback;
116     public Operand [] op = null;
117 
OpInfo(UnionOpInfo op_info)118     public OpInfo(UnionOpInfo op_info) {
119       cc = op_info.cc;
120       updateFlags = (op_info._update_flags > 0);
121       writeback = (op_info._writeback > 0);
122       op = op_info.op;
123     }
124   }
125 }
126