Home | History | Annotate | Download | only in capstone
      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.Ppc_const.*;
     13 
     14 public class Ppc {
     15 
     16   public static class MemType extends Structure {
     17     public int base;
     18     public int disp;
     19 
     20     @Override
     21     public List getFieldOrder() {
     22       return Arrays.asList("base", "disp");
     23     }
     24   }
     25 
     26   public static class CrxType extends Structure {
     27     public int scale;
     28     public int reg;
     29     public int cond;
     30 
     31     @Override
     32     public List getFieldOrder() {
     33       return Arrays.asList("scale", "reg", "cond");
     34     }
     35   }
     36 
     37   public static class OpValue extends Union {
     38     public int reg;
     39     public int imm;
     40     public MemType mem;
     41     public CrxType crx;
     42   }
     43 
     44   public static class Operand extends Structure {
     45     public int type;
     46     public OpValue value;
     47 
     48     public void read() {
     49       readField("type");
     50       if (type == PPC_OP_MEM)
     51         value.setType(MemType.class);
     52       if (type == PPC_OP_CRX)
     53         value.setType(CrxType.class);
     54       if (type == PPC_OP_IMM || type == PPC_OP_REG)
     55         value.setType(Integer.TYPE);
     56       if (type == PPC_OP_INVALID)
     57         return;
     58       readField("value");
     59     }
     60 
     61     @Override
     62     public List getFieldOrder() {
     63       return Arrays.asList("type", "value");
     64     }
     65   }
     66 
     67   public static class UnionOpInfo extends Capstone.UnionOpInfo {
     68     public int bc;
     69     public int bh;
     70     public byte update_cr0;
     71     public byte op_count;
     72 
     73     public Operand [] op;
     74 
     75     public UnionOpInfo() {
     76       op = new Operand[8];
     77     }
     78 
     79     public void read() {
     80       readField("bc");
     81       readField("bh");
     82       readField("update_cr0");
     83       readField("op_count");
     84       op = new Operand[op_count];
     85       if (op_count != 0)
     86         readField("op");
     87     }
     88 
     89     @Override
     90     public List getFieldOrder() {
     91       return Arrays.asList("bc", "bh", "update_cr0", "op_count", "op");
     92     }
     93   }
     94 
     95   public static class OpInfo extends Capstone.OpInfo {
     96     public int bc;
     97     public int bh;
     98     public boolean updateCr0;
     99 
    100     public Operand [] op;
    101 
    102     public OpInfo(UnionOpInfo op_info) {
    103       bc = op_info.bc;
    104       bh = op_info.bh;
    105       updateCr0 = (op_info.update_cr0 > 0);
    106       op = op_info.op;
    107     }
    108   }
    109 }
    110