Fix java binding test, output the same as core test

This commit is contained in:
danghvu 2013-11-27 21:41:17 -06:00
parent f86a7d5696
commit f3ef69673a
5 changed files with 40 additions and 33 deletions

View File

@ -22,7 +22,7 @@ public class Test {
}
};
static String stringToHex(byte[] code) {
static public String stringToHex(byte[] code) {
StringBuilder buf = new StringBuilder(200);
for (byte ch: code) {
if (buf.length() > 0)

View File

@ -6,7 +6,6 @@ import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import capstone.Capstone;
import capstone.Capstone.*;
import capstone.Arm;
public class TestArm {
@ -42,18 +41,6 @@ public class TestArm {
Arm.OpInfo op_info = (Arm.OpInfo) ins.op_info;
if (op_info.cc != Arm.ARM_CC_AL && op_info.cc != Arm.ARM_CC_INVALID){
System.out.printf("\tCode condition: %d\n", op_info.cc);
}
if (op_info.update_flags) {
System.out.println("\tUpdate-flags: True");
}
if (op_info.writeback) {
System.out.println("\tWriteback: True");
}
if (op_info.op != null) {
System.out.printf("\top_count: %d\n", op_info.op.length);
for (int c=0; c<op_info.op.length; c++) {
@ -85,6 +72,14 @@ public class TestArm {
if (i.shift.type != Arm.ARM_SFT_INVALID && i.shift.value > 0)
System.out.printf("\t\t\tShift: type = %d, value = %d\n", i.shift.type, i.shift.value);
}
if (op_info.writeback)
System.out.println("\tWrite-back: True");
if (op_info.update_flags)
System.out.println("\tUpdate-flags: True");
if (op_info.cc != Arm.ARM_CC_AL && op_info.cc != Arm.ARM_CC_INVALID)
System.out.printf("\tCode condition: %d\n", op_info.cc);
}
}
@ -99,8 +94,9 @@ public class TestArm {
for (int i=0; i<all_tests.length; i++) {
Test.platform test = all_tests[i];
System.out.println(new String(new char[30]).replace("\0", "*"));
System.out.println(new String(new char[16]).replace("\0", "*"));
System.out.println("Platform: " + test.comment);
System.out.println("Code: " + Test.stringToHex(test.code));
System.out.println("Disasm:");
cs = new Capstone(test.arch, test.mode);

View File

@ -38,18 +38,6 @@ public class TestArm64 {
Arm64.OpInfo op_info = (Arm64.OpInfo) ins.op_info;
if (op_info.cc != Arm64.ARM64_CC_AL && op_info.cc != Arm64.ARM64_CC_INVALID){
System.out.printf("\tCode condition: %d\n", op_info.cc);
}
if (op_info.update_flags) {
System.out.println("\tUpdate-flags: True");
}
if (op_info.writeback) {
System.out.println("\tWriteback: True");
}
if (op_info.op != null) {
System.out.printf("\top_count: %d\n", op_info.op.length);
for (int c=0; c<op_info.op.length; c++) {
@ -80,6 +68,16 @@ public class TestArm64 {
System.out.printf("\t\t\tExt: %d\n", i.ext);
}
}
if (op_info.writeback)
System.out.println("\tWrite-back: True");
if (op_info.update_flags)
System.out.println("\tUpdate-flags: True");
if (op_info.cc != Arm64.ARM64_CC_AL && op_info.cc != Arm64.ARM64_CC_INVALID)
System.out.printf("\tCode condition: %d\n", op_info.cc);
}
public static void main(String argv[]) {
@ -90,17 +88,20 @@ public class TestArm64 {
for (int i=0; i<all_tests.length; i++) {
Test.platform test = all_tests[i];
System.out.println(new String(new char[30]).replace("\0", "*"));
System.out.println(new String(new char[16]).replace("\0", "*"));
System.out.println("Platform: " + test.comment);
System.out.println("Code: " + Test.stringToHex(test.code));
System.out.println("Disasm:");
cs = new Capstone(test.arch, test.mode);
Capstone.cs_insn[] all_ins = cs.disasm(test.code, 0x1000);
Capstone.cs_insn[] all_ins = cs.disasm(test.code, 0x2c);
for (int j = 0; j < all_ins.length; j++) {
print_ins_detail(all_ins[j]);
System.out.println();
}
System.out.printf("0x%x: \n\n", all_ins[all_ins.length-1].address + all_ins[all_ins.length-1].size);
}
}

View File

@ -69,8 +69,9 @@ public class TestMips {
for (int i=0; i<all_tests.length; i++) {
Test.platform test = all_tests[i];
System.out.println(new String(new char[30]).replace("\0", "*"));
System.out.println(new String(new char[16]).replace("\0", "*"));
System.out.println("Platform: " + test.comment);
System.out.println("Code: " + Test.stringToHex(test.code));
System.out.println("Disasm:");
cs = new Capstone(test.arch, test.mode);
@ -80,6 +81,8 @@ public class TestMips {
print_ins_detail(all_ins[j]);
System.out.println();
}
System.out.printf("0x%x:\n\n", all_ins[all_ins.length-1].address + all_ins[all_ins.length-1].size);
}
}

View File

@ -66,9 +66,13 @@ public class TestX86 {
System.out.printf("\tdisp: 0x%x\n", op_info.disp);
// SIB is not available in 16-bit mode
if ( (cs.mode & Capstone.CS_MODE_16) == 0)
if ( (cs.mode & Capstone.CS_MODE_16) == 0) {
// print SIB byte
System.out.printf("\tsib: 0x%x\n", op_info.sib);
if (op_info.sib != 0)
System.out.printf("\tsib_index: %s, sib_scale: %d, sib_base: %s\n",
cs.reg_name(op_info.sib_index), op_info.sib_scale, cs.reg_name(op_info.sib_base));
}
int count = ins.op_count(X86.X86_OP_IMM);
if (count > 0) {
@ -111,15 +115,16 @@ public class TestX86 {
final Test.platform[] all_tests = {
new Test.platform(Capstone.CS_ARCH_X86, Capstone.CS_MODE_16, hexString2Byte(X86_CODE16), "X86 16bit (Intel syntax)"),
new Test.platform(Capstone.CS_ARCH_X86, Capstone.CS_MODE_32 + Capstone.CS_MODE_SYNTAX_ATT, hexString2Byte(X86_CODE32), "X86 32bit (ATT syntax)"),
new Test.platform(Capstone.CS_ARCH_X86, Capstone.CS_MODE_32 + Capstone.CS_MODE_SYNTAX_ATT, hexString2Byte(X86_CODE32), "X86 32 (AT&T syntax)"),
new Test.platform(Capstone.CS_ARCH_X86, Capstone.CS_MODE_32, hexString2Byte(X86_CODE32), "X86 32 (Intel syntax)"),
new Test.platform(Capstone.CS_ARCH_X86, Capstone.CS_MODE_64, hexString2Byte(X86_CODE64), "X86 64 (Intel syntax)"),
};
for (int i=0; i<all_tests.length; i++) {
Test.platform test = all_tests[i];
System.out.println(new String(new char[30]).replace("\0", "*"));
System.out.println(new String(new char[16]).replace("\0", "*"));
System.out.println("Platform: " + test.comment);
System.out.println("Code: " + Test.stringToHex(test.code));
System.out.println("Disasm:");
cs = new Capstone(test.arch, test.mode);
@ -129,6 +134,8 @@ public class TestX86 {
print_ins_detail(all_ins[j]);
System.out.println();
}
System.out.printf("0x%x:\n\n", all_ins[all_ins.length-1].address + all_ins[all_ins.length-1].size);
}
}