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