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.Sysz_const.*;
13 
14 public class Systemz {
15 
16   public static class MemType extends Structure {
17     public byte base;
18     public byte index;
19     public long length;
20     public long disp;
21 
22     @Override
getFieldOrder()23     public List getFieldOrder() {
24       return Arrays.asList("base", "index", "length", "disp");
25     }
26   }
27 
28   public static class OpValue extends Union {
29     public int reg;
30     public long 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 == SYSZ_OP_MEM)
41         value.setType(MemType.class);
42       if (type == SYSZ_OP_IMM)
43         value.setType(Long.TYPE);
44       if (type == SYSZ_OP_REG || type == SYSZ_OP_ACREG)
45         value.setType(Integer.TYPE);
46       if (type == SYSZ_OP_INVALID)
47         return;
48       readField("value");
49     }
50 
51     @Override
getFieldOrder()52     public List getFieldOrder() {
53       return Arrays.asList("type", "value");
54     }
55   }
56 
57   public static class UnionOpInfo extends Capstone.UnionOpInfo {
58     public int cc;
59     public byte op_count;
60 
61     public Operand [] op;
62 
UnionOpInfo()63     public UnionOpInfo() {
64       op = new Operand[6];
65     }
66 
read()67     public void read() {
68       readField("cc");
69       readField("op_count");
70       op = new Operand[op_count];
71       if (op_count != 0)
72         readField("op");
73     }
74 
75     @Override
getFieldOrder()76     public List getFieldOrder() {
77       return Arrays.asList("cc", "op_count", "op");
78     }
79   }
80 
81   public static class OpInfo extends Capstone.OpInfo {
82     public int cc;
83 
84     public Operand [] op;
85 
OpInfo(UnionOpInfo op_info)86     public OpInfo(UnionOpInfo op_info) {
87       cc = op_info.cc;
88       op = op_info.op;
89     }
90   }
91 }
92