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 int vess;
57     public OpShift shift;
58     public int ext;
59     public int type;
60     public OpValue value;
61 
read()62     public void read() {
63       readField("type");
64       if (type == ARM64_OP_MEM)
65         value.setType(MemType.class);
66       if (type == ARM64_OP_FP)
67         value.setType(Double.TYPE);
68       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)
69         value.setType(Integer.TYPE);
70       if (type == ARM64_OP_INVALID)
71         return;
72       readField("value");
73       readField("ext");
74       readField("shift");
75       readField("vess");
76       readField("vas");
77       readField("vector_index");
78     }
79 
80     @Override
getFieldOrder()81     public List getFieldOrder() {
82       return Arrays.asList("vector_index", "vas", "vess", "shift", "ext", "type", "value");
83     }
84   }
85 
86   public static class UnionOpInfo extends Capstone.UnionOpInfo {
87     public int cc;
88     public byte _update_flags;
89     public byte _writeback;
90     public byte op_count;
91 
92     public Operand [] op;
93 
UnionOpInfo()94     public UnionOpInfo() {
95       op = new Operand[8];
96     }
97 
read()98     public void read() {
99       readField("cc");
100       readField("_update_flags");
101       readField("_writeback");
102       readField("op_count");
103       op = new Operand[op_count];
104       if (op_count != 0)
105         readField("op");
106     }
107 
108     @Override
getFieldOrder()109     public List getFieldOrder() {
110       return Arrays.asList("cc", "_update_flags", "_writeback", "op_count", "op");
111     }
112   }
113 
114   public static class OpInfo extends Capstone.OpInfo {
115     public int cc;
116     public boolean updateFlags;
117     public boolean writeback;
118     public Operand [] op = null;
119 
OpInfo(UnionOpInfo op_info)120     public OpInfo(UnionOpInfo op_info) {
121       cc = op_info.cc;
122       updateFlags = (op_info._update_flags > 0);
123       writeback = (op_info._writeback > 0);
124       op = op_info.op;
125     }
126   }
127 }
128