Merge remote-tracking branch 'upstream/master'
diff --git a/bindings/java/capstone/Arm.java b/bindings/java/capstone/Arm.java
index 198a1f4..a308a0b 100644
--- a/bindings/java/capstone/Arm.java
+++ b/bindings/java/capstone/Arm.java
@@ -57,7 +57,7 @@
public int base;
public int index;
public int scale;
- public long disp;
+ public int disp;
@Override
public List getFieldOrder() {
@@ -67,7 +67,7 @@
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 @@
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 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 @@
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 06cf9c9..e7936e1 100644
--- a/bindings/java/capstone/Arm64.java
+++ b/bindings/java/capstone/Arm64.java
@@ -62,7 +62,7 @@
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 static class OpValue extends Union {
public int reg;
- public long imm;
+ public int imm;
public double fp;
public MemType mem;
@@ -104,9 +104,7 @@
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 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 @@
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 4e71e39..983694c 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;
@@ -31,7 +32,7 @@
protected static class _cs_insn extends Structure {
public int id;
- public long address;
+ public NativeLong address;
public short size;
public byte[] mnemonic = new byte[32];
public byte[] operands = new byte[96];
@@ -40,13 +41,13 @@
public int[] groups = new int[8];
public _cs_insn(Pointer p) {
- mnemonic = new byte[32];
- operands = new byte[96];
- regs_read = new int[32];
- regs_write = new int[32];
- groups = new int[8];
- useMemory(p);
- read();
+ mnemonic = new byte[32];
+ operands = new byte[96];
+ regs_read = new int[32];
+ regs_write = new int[32];
+ groups = new int[8];
+ useMemory(p);
+ read();
}
@Override
@@ -58,7 +59,7 @@
public static class cs_insn {
public OpInfo op_info;
public Pointer ptr_origin;
- public long csh;
+ public NativeLong csh;
public int id;
public long address;
@@ -72,9 +73,9 @@
private CS cs;
private int _size;
- public cs_insn (_cs_insn struct, Pointer _ptr_origin, long _csh, CS _cs, OpInfo _op_info) {
+ public cs_insn (_cs_insn struct, Pointer _ptr_origin, NativeLong _csh, CS _cs, OpInfo _op_info) {
id = struct.id;
- address = struct.address;
+ address = struct.address.longValue();
size = struct.size;
mnemonic = new String(struct.mnemonic).replace("\u0000","");
operands = new String(struct.operands).replace("\u0000","");
@@ -169,21 +170,21 @@
}
private interface CS extends Library {
- public int cs_open(int arch, int mode, LongByReference handle);
- public long cs_disasm_dyn(long handle, byte[] code, long code_len,
- long addr, long count, PointerByReference insn);
+ public int cs_open(int arch, int mode, NativeLongByReference handle);
+ public NativeLong cs_disasm_dyn(NativeLong handle, byte[] code, NativeLong code_len,
+ NativeLong addr, NativeLong count, PointerByReference insn);
public void cs_free(Pointer p);
- public int cs_close(long handle);
- public String cs_reg_name(long csh, int id);
- public int cs_op_count(long csh, Pointer insn, int type);
- public int cs_op_index(long csh, Pointer insn, int type, int index);
+ public int cs_close(NativeLong handle);
+ public String cs_reg_name(NativeLong csh, int id);
+ public int cs_op_count(NativeLong csh, Pointer insn, int type);
+ public int cs_op_index(NativeLong csh, Pointer insn, int type, int index);
- public String cs_insn_name(long csh, int id);
- public byte cs_insn_group(long csh, Pointer insn, int id);
- public byte cs_reg_read(long csh, Pointer insn, int id);
- public byte cs_reg_write(long csh, Pointer insn, int id);
+ public String cs_insn_name(NativeLong csh, int id);
+ public byte cs_insn_group(NativeLong csh, Pointer insn, int id);
+ public byte cs_reg_read(NativeLong csh, Pointer insn, int id);
+ public byte cs_reg_write(NativeLong csh, Pointer insn, int id);
public void cs_version(IntByReference major, IntByReference minor);
- public int cs_errno(long csh);
+ public int cs_errno(NativeLong csh);
}
public static final int CS_ARCH_ARM = 0;
@@ -210,7 +211,7 @@
public static final int CS_ERR_MODE = 5; // Invalid/unsupported mode
- private long csh;
+ private NativeLong csh;
private PointerByReference insnRef;
private CS cs;
@@ -219,7 +220,7 @@
this.arch = arch;
this.mode = mode;
cs = (CS)Native.loadLibrary("capstone", CS.class);
- LongByReference handleref = new LongByReference();
+ NativeLongByReference handleref = new NativeLongByReference();
if (cs.cs_open(arch, mode, handleref) != CS_ERR_OK) {
throw new RuntimeException("ERROR: Wrong arch or mode");
}
@@ -241,10 +242,10 @@
public cs_insn[] disasm(byte[] code, long address, long count) {
insnRef = new PointerByReference();
- long c = cs.cs_disasm_dyn(csh, code, code.length, address, count, insnRef);
+ NativeLong c = cs.cs_disasm_dyn(csh, code, new NativeLong(code.length), new NativeLong(address), new NativeLong(count), insnRef);
Pointer p = insnRef.getValue();
- cs_insn[] all_insn = fromArrayPointer(p, (int)c);
+ cs_insn[] all_insn = fromArrayPointer(p, c.intValue());
return all_insn;
}
}
diff --git a/bindings/java/capstone/Mips.java b/bindings/java/capstone/Mips.java
index 37f6761..78b342d 100644
--- a/bindings/java/capstone/Mips.java
+++ b/bindings/java/capstone/Mips.java
@@ -63,7 +63,7 @@
}
public static class UnionOpInfo extends Capstone.UnionOpInfo {
- public short op_count;
+ public byte op_count;
public Operand [] op;
public UnionOpInfo() {
@@ -82,6 +82,7 @@
public void read() {
readField("op_count");
+ if (op_count ==0) return;
op = new Operand[op_count];
readField("op");
}
diff --git a/bindings/java/capstone/X86.java b/bindings/java/capstone/X86.java
index cf70f95..5682c3e 100644
--- a/bindings/java/capstone/X86.java
+++ b/bindings/java/capstone/X86.java
@@ -84,7 +84,7 @@
public byte sib_scale;
public int sib_base;
- public int op_count;
+ public char op_count;
public Operand [] op;
diff --git a/bindings/python/test_arm.py b/bindings/python/test_arm.py
index bf3c4d9..ea7b635 100755
--- a/bindings/python/test_arm.py
+++ b/bindings/python/test_arm.py
@@ -27,6 +27,13 @@
while x[0] == '0': x = x[1:]
return x
+def to_x_32(s):
+ from struct import pack
+ if not s: return '0'
+ x = pack(">i", 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 @@
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 @@
%(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" \