11 static byte[] hexString2Byte(String s) {
14 byte[]
data =
new byte[
len / 2];
15 for (
int i = 0;
i <
len;
i += 2) {
16 data[
i / 2] = (
byte) ((Character.digit(s.charAt(
i), 16) << 4)
17 + Character.digit(s.charAt(
i+1), 16));
22 static final String MIPS_CODE =
"0C100097000000002402000c8fa2000034213456";
23 static final String MIPS_CODE2 =
"56342134c2170100";
25 public static Capstone
cs;
27 private static String
hex(
int i) {
28 return Integer.toString(
i, 16);
31 private static String
hex(
long i) {
32 return Long.toString(
i, 16);
36 System.out.printf(
"0x%x:\t%s\t%s\n", ins.address, ins.mnemonic, ins.opStr);
40 if (operands.op.length != 0) {
41 System.out.printf(
"\top_count: %d\n", operands.op.length);
42 for (
int c=0;
c<operands.op.length;
c++) {
44 String imm =
hex(
i.value.imm);
46 System.out.printf(
"\t\toperands[%d].type: REG = %s\n",
c, ins.regName(
i.value.reg));
48 System.out.printf(
"\t\toperands[%d].type: IMM = 0x%x\n",
c,
i.value.imm);
50 System.out.printf(
"\t\toperands[%d].type: MEM\n",
c);
51 String
base = ins.regName(
i.value.mem.base);
53 System.out.printf(
"\t\t\toperands[%d].mem.base: REG = %s\n",
c,
base);
54 if (
i.value.mem.disp != 0)
55 System.out.printf(
"\t\t\toperands[%d].mem.disp: %s\n",
c,
hex(
i.value.mem.disp));
61 public static void main(String argv[]) {
64 new TestBasic.
platform(Capstone.CS_ARCH_MIPS, Capstone.CS_MODE_MIPS32 + Capstone.CS_MODE_BIG_ENDIAN, hexString2Byte(
MIPS_CODE),
"MIPS-32 (Big-endian)"),
65 new TestBasic.
platform(Capstone.CS_ARCH_MIPS, Capstone.CS_MODE_MIPS64 + Capstone.CS_MODE_LITTLE_ENDIAN, hexString2Byte(
MIPS_CODE2),
"MIPS-64-EL (Little-endian)"),
70 System.out.println(
new String(
new char[16]).replace(
"\0",
"*"));
71 System.out.println(
"Platform: " +
test.comment);
73 System.out.println(
"Disasm:");
76 cs.setDetail(Capstone.CS_OPT_ON);
77 Capstone.CsInsn[] all_ins =
cs.disasm(
test.code, 0x1000);
79 for (
int j = 0; j < all_ins.length; j++) {
84 System.out.printf(
"0x%x:\n\n", all_ins[all_ins.length-1].address + all_ins[all_ins.length-1].size);