1 // Capstone Java binding
2 /* M680X Backend by Wolfgang Schwotzer <wolfgang.schwotzer@gmx.net> 2017 */
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.M680x_const.*;
13 
14 public class M680x {
15 
16   public static class OpIndexed extends Structure {
17     public int base_reg;
18     public int offset_reg;
19     public short offset;
20     public short offset_addr;
21     public byte offset_bits;
22     public byte inc_dec;
23     public byte flags;
24 
25     @Override
getFieldOrder()26     public List getFieldOrder() {
27       return Arrays.asList("base_reg", "offset_reg", "offset", "offset_addr", "offset_bits", "inc_dec", "flags");
28     }
29   }
30 
31   public static class OpRelative extends Structure {
32     public short address;
33     public short offset;
34 
35     @Override
getFieldOrder()36     public List getFieldOrder() {
37       return Arrays.asList("address", "offset");
38     }
39   }
40 
41   public static class OpExtended extends Structure {
42     public short address;
43     public byte indirect;
44 
45     @Override
getFieldOrder()46     public List getFieldOrder() {
47       return Arrays.asList("address", "indirect");
48     }
49   }
50 
51   public static class OpValue extends Union {
52     public int imm;
53     public int reg;
54     public OpIndexed idx;
55     public OpRelative rel;
56     public OpExtended ext;
57     public byte direct_addr;
58     public byte const_val;
59 
60     @Override
getFieldOrder()61     public List getFieldOrder() {
62       return Arrays.asList("imm", "reg", "idx", "rel", "ext", "direct_addr", "const_val");
63     }
64   }
65 
66   public static class Operand extends Structure {
67     public int type;
68     public OpValue value;
69     public byte size;
70     public byte access;
71 
read()72     public void read() {
73       readField("type");
74       if (type == M680X_OP_IMMEDIATE)
75         value.setType(Integer.TYPE);
76       if (type == M680X_OP_REGISTER)
77         value.setType(Integer.TYPE);
78       if (type == M680X_OP_INDEXED)
79         value.setType(OpIndexed.class);
80       if (type == M680X_OP_RELATIVE)
81         value.setType(OpRelative.class);
82       if (type == M680X_OP_EXTENDED)
83         value.setType(OpExtended.class);
84       if (type == M680X_OP_DIRECT)
85         value.setType(Integer.TYPE);
86       if (type == M680X_OP_INVALID)
87         return;
88       readField("value");
89       readField("size");
90       readField("access");
91     }
92 
93     @Override
getFieldOrder()94     public List getFieldOrder() {
95       return Arrays.asList("type", "value", "size", "access");
96     }
97   }
98 
99   public static class UnionOpInfo extends Capstone.UnionOpInfo {
100     public byte flags;
101     public byte op_count;
102 
103     public Operand [] op;
104 
UnionOpInfo()105     public UnionOpInfo() {
106       op = new Operand[9];
107     }
108 
read()109     public void read() {
110       readField("flags");
111       readField("op_count");
112       op = new Operand[op_count];
113       if (op_count != 0)
114         readField("op");
115     }
116 
117     @Override
getFieldOrder()118     public List getFieldOrder() {
119       return Arrays.asList("flags", "op_count", "op");
120     }
121   }
122 
123   public static class OpInfo extends Capstone.OpInfo {
124     public byte flags;
125     public Operand [] op = null;
126 
OpInfo(UnionOpInfo op_info)127     public OpInfo(UnionOpInfo op_info) {
128       flags = op_info.flags;
129       op = op_info.op;
130     }
131   }
132 }
133