Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor java binding, remove offset dependency #2

Merged
merged 1 commit into from
Nov 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 40 additions & 35 deletions bindings/java/Arm.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,22 @@ public List getFieldOrder() {
}
}

public static class OpValue extends Union implements Union.ByReference {
public static class OpValue extends Union {
public int reg;
public long imm;
public double fp;
public MemType mem;

public OpValue(Pointer p) {
super(p);
read();
}

@Override
public List getFieldOrder() {
return Arrays.asList("reg", "imm", "fp", "mem");
}
}

public static class OpShift extends Structure implements Structure.ByReference {
public static class OpShift extends Structure {
public int type;
public int value;

public OpShift(Pointer p) {
super(p);
read();
}

@Override
public List getFieldOrder() {
return Arrays.asList("type","value");
Expand All @@ -100,38 +90,53 @@ public static class Operand extends Structure {
public int type;
public OpValue value;

public void read() {
super.read();
if (type == ARM_OP_MEM)
value.setType(MemType.class);
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);
if (type == ARM_OP_REG)
value.setType(Integer.TYPE);
readField("value");
}

@Override
public List getFieldOrder() {
return Arrays.asList("shift", "type", "value");
}
}

public static class OpInfo extends Capstone.OpInfo {
public static class UnionOpInfo extends Structure {
public int cc;
public byte _update_flags;
public byte _writeback;
public byte op_count;

public Operand [] op;
public Operand [] op = new Operand[32];

public OpInfo(Pointer p) {
cc = p.getInt(0);
update_flags = (boolean) (p.getByte(4) > 0);
writeback = (boolean) (p.getByte(5) > 0);
int op_count = p.getShort(6);
if (op_count == 0) {
op = null;
return;
}
@Override
public List getFieldOrder() {
return Arrays.asList("cc", "_update_flags", "_writeback", "op_count", "op");
}
}

public static class OpInfo extends Capstone.OpInfo {
public int cc;
public boolean update_flags;
public boolean writeback;
public Operand [] op = null;

op = new Operand[op_count];
for (int i=0; i<op_count; i++) {
Pointer p1 = p.share(8 + i*40);
op[i] = new Operand();
op[i].shift = new OpShift(p1);
op[i].type = p1.getInt(8);
op[i].value = new OpValue(p1.share(16));
if (op[i].type == ARM_OP_MEM) {
op[i].value.setType(MemType.class);
op[i].value.read();
}
}
public OpInfo(UnionOpInfo op_info) {
cc = op_info.cc;
update_flags = (op_info._update_flags > 0);
writeback = (op_info._writeback > 0);
if (op_info.op_count == 0) return;
op = new Operand[op_info.op_count];
for (int i=0; i<op_info.op_count; i++)
op[i] = op_info.op[i];
}
}

Expand Down
85 changes: 49 additions & 36 deletions bindings/java/Arm64.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,22 @@ public List getFieldOrder() {
}
}

public static class OpValue extends Union implements Union.ByReference {
public static class OpValue extends Union {
public int reg;
public long imm;
public double fp;
public MemType mem;

public OpValue(Pointer p) {
super(p);
read();
}

@Override
public List getFieldOrder() {
return Arrays.asList("reg", "imm", "fp", "mem");
}
}

public static class OpShift extends Structure implements Structure.ByReference {
public static class OpShift extends Structure {
public int type;
public int value;

public OpShift(Pointer p) {
super(p);
read();
}

@Override
public List getFieldOrder() {
return Arrays.asList("type","value");
Expand All @@ -106,39 +96,62 @@ public static class Operand extends Structure {
public int type;
public OpValue value;

public void read() {
super.read();
if (type == ARM64_OP_MEM)
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)
value.setType(Integer.TYPE);
if (type == ARM64_OP_INVALID)
return;
readField("value");
}

@Override
public List getFieldOrder() {
return Arrays.asList("shift", "ext", "type", "value");
}
}

public static class OpInfo extends Capstone.OpInfo {
public static class UnionOpInfo extends Structure {
public int cc;
public byte _update_flags;
public byte _writeback;
public byte op_count;

public Operand [] op;

public OpInfo(Pointer p) {
cc = p.getInt(0);
update_flags = (boolean) (p.getByte(4) > 0);
writeback = (boolean) (p.getByte(5) > 0);
int op_count = p.getShort(6);
if (op_count == 0) {
op = null;
return;
}
public Operand [] op = new Operand[32];

public void read() {
readField("cc");
readField("_update_flags");
readField("_writeback");
readField("op_count");
op = new Operand[op_count];
for (int i=0; i<op_count; i++) {
Pointer p1 = p.share(8 + i*32);
op[i] = new Operand();
op[i].shift = new OpShift(p1);
op[i].ext = p1.getInt(8);
op[i].type = p1.getInt(12);
op[i].value = new OpValue(p1.share(16));
if (op[i].type == ARM64_OP_MEM) {
op[i].value.setType(MemType.class);
op[i].value.read();
}
}
readField("op");
}

@Override
public List getFieldOrder() {
return Arrays.asList("cc", "_update_flags", "_writeback", "op_count", "op");
}
}

public static class OpInfo extends Capstone.OpInfo {
public int cc;
public boolean update_flags;
public boolean writeback;
public Operand [] op = null;

public OpInfo(UnionOpInfo op_info) {
cc = op_info.cc;
update_flags = (op_info._update_flags > 0);
writeback = (op_info._writeback > 0);
if (op_info.op_count == 0) return;
op = op_info.op;
}
}

Expand Down
Loading