diff --git a/bindings/java/capstone/Arm.java b/bindings/java/capstone/Arm.java index 198a1f4a7e..a308a0b202 100644 --- a/bindings/java/capstone/Arm.java +++ b/bindings/java/capstone/Arm.java @@ -57,7 +57,7 @@ public static class MemType extends Structure { public int base; public int index; public int scale; - public long disp; + public int disp; @Override public List getFieldOrder() { @@ -67,7 +67,7 @@ public List getFieldOrder() { public static class OpValue extends Union { public int reg; - public long imm; + public int imm; public double fp; public MemType mem; @@ -99,7 +99,7 @@ public void read() { if (type == ARM_OP_FP) value.setType(Double.TYPE); if (type == ARM_OP_PIMM || type == ARM_OP_IMM || type == ARM_OP_CIMM) - value.setType(Long.TYPE); + value.setType(Integer.TYPE); if (type == ARM_OP_REG) value.setType(Integer.TYPE); if (type == ARM_OP_INVALID) @@ -122,12 +122,12 @@ public static class UnionOpInfo extends Capstone.UnionOpInfo { public Operand [] op; - public UnionOpInfo(){ - op = new Operand[32]; + public UnionOpInfo(){ + op = new Operand[20]; } public UnionOpInfo(Pointer p){ - op = new Operand[32]; + op = new Operand[20]; useMemory(p); read(); } @@ -142,6 +142,7 @@ public void read() { readField("_update_flags"); readField("_writeback"); readField("op_count"); + if (op_count == 0) return; op = new Operand[op_count]; readField("op"); } diff --git a/bindings/java/capstone/Arm64.java b/bindings/java/capstone/Arm64.java index 06cf9c9be3..e7936e19c6 100644 --- a/bindings/java/capstone/Arm64.java +++ b/bindings/java/capstone/Arm64.java @@ -62,7 +62,7 @@ public class Arm64 { public static class MemType extends Structure { public int base; public int index; - public long disp; + public int disp; @Override public List getFieldOrder() { @@ -72,7 +72,7 @@ public List getFieldOrder() { public static class OpValue extends Union { public int reg; - public long imm; + public int imm; public double fp; public MemType mem; @@ -104,9 +104,7 @@ public void read() { value.setType(MemType.class); if (type == ARM64_OP_FP) value.setType(Double.TYPE); - if (type == ARM64_OP_IMM || type == ARM64_OP_CIMM) - value.setType(Long.TYPE); - if (type == ARM64_OP_REG) + if (type == ARM64_OP_IMM || type == ARM64_OP_CIMM || type == ARM64_OP_REG) value.setType(Integer.TYPE); if (type == ARM64_OP_INVALID) return; @@ -130,11 +128,11 @@ public static class UnionOpInfo extends Capstone.UnionOpInfo { public Operand [] op; public UnionOpInfo() { - op = new Operand[32]; + op = new Operand[8]; } public UnionOpInfo(Pointer p) { - op = new Operand[32]; + op = new Operand[8]; useMemory(p); read(); } @@ -148,6 +146,7 @@ public void read() { readField("_update_flags"); readField("_writeback"); readField("op_count"); + if (op_count == 0) return; op = new Operand[op_count]; readField("op"); } diff --git a/bindings/java/capstone/Capstone.java b/bindings/java/capstone/Capstone.java index 4e71e39f72..38a7e97326 100644 --- a/bindings/java/capstone/Capstone.java +++ b/bindings/java/capstone/Capstone.java @@ -5,9 +5,10 @@ import com.sun.jna.Library; import com.sun.jna.Native; +import com.sun.jna.NativeLong; +import com.sun.jna.ptr.NativeLongByReference; import com.sun.jna.Structure; import com.sun.jna.Union; -import com.sun.jna.ptr.LongByReference; import com.sun.jna.Pointer; import com.sun.jna.ptr.PointerByReference; import com.sun.jna.ptr.IntByReference; @@ -26,12 +27,15 @@ protected static abstract class OpInfo {} protected static abstract class UnionOpInfo extends Structure {} protected static int max(int a, int b, int c, int d) { - return Math.max(Math.max(Math.max(a,b),c),d); + if (ai", s).encode('hex') + while x[0] == '0': x = x[1:] + return x + ### Test class cs def test_class(): def print_insn_detail(insn): @@ -40,7 +47,7 @@ def print_insn_detail(insn): if i.type == ARM_OP_REG: print("\t\toperands[%u].type: REG = %s" %(c, insn.reg_name(i.value.reg))) if i.type == ARM_OP_IMM: - print("\t\toperands[%u].type: IMM = 0x%s" %(c, to_x(i.value.imm))) + print("\t\toperands[%u].type: IMM = 0x%s" %(c, to_x_32(i.value.imm))) if i.type == ARM_OP_PIMM: print("\t\toperands[%u].type: P-IMM = %u" %(c, i.value.imm)) if i.type == ARM_OP_CIMM: @@ -60,7 +67,7 @@ def print_insn_detail(insn): %(c, i.value.mem.scale)) if i.value.mem.disp != 0: print("\t\t\toperands[%u].mem.disp: 0x%s" \ - %(c, to_x(i.value.mem.disp))) + %(c, to_x_32(i.value.mem.disp))) if i.shift.type != ARM_SFT_INVALID and i.shift.value: print("\t\t\tShift: type = %u, value = %u\n" \