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.Xcore_const.*;
13 
14 public class Xcore {
15 
16   public static class MemType extends Structure {
17     public byte base;
18     public byte index;
19     public int disp;
20     public int direct;
21 
22     @Override
getFieldOrder()23     public List getFieldOrder() {
24       return Arrays.asList("base", "index", "disp", "direct");
25     }
26   }
27 
28   public static class OpValue extends Union {
29     public int reg;
30     public int imm;
31     public MemType mem;
32   }
33 
34   public static class Operand extends Structure {
35     public int type;
36     public OpValue value;
37 
read()38     public void read() {
39       readField("type");
40       if (type == XCORE_OP_MEM)
41         value.setType(MemType.class);
42       if (type == XCORE_OP_IMM || type == XCORE_OP_REG)
43         value.setType(Integer.TYPE);
44       if (type == XCORE_OP_INVALID)
45         return;
46       readField("value");
47     }
48 
49     @Override
getFieldOrder()50     public List getFieldOrder() {
51       return Arrays.asList("type", "value");
52     }
53   }
54 
55   public static class UnionOpInfo extends Capstone.UnionOpInfo {
56     public byte op_count;
57     public Operand [] op;
58 
UnionOpInfo()59     public UnionOpInfo() {
60       op = new Operand[8];
61     }
62 
read()63     public void read() {
64       readField("op_count");
65       op = new Operand[op_count];
66       if (op_count != 0)
67         readField("op");
68     }
69 
70     @Override
getFieldOrder()71     public List getFieldOrder() {
72       return Arrays.asList("op_count", "op");
73     }
74   }
75 
76   public static class OpInfo extends Capstone.OpInfo {
77     public Operand [] op;
78 
OpInfo(UnionOpInfo op_info)79     public OpInfo(UnionOpInfo op_info) {
80       op = op_info.op;
81     }
82   }
83 }
84