TestArm64.java
Go to the documentation of this file.
1 // Capstone Java binding
2 // By Nguyen Anh Quynh & Dang Hoang Vu, 2013
3 
4 import capstone.Capstone;
5 import capstone.Arm64;
6 
7 import static capstone.Arm64_const.*;
8 
9 public class TestArm64 {
10 
11  static byte[] hexString2Byte(String s) {
12  // from http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java
13  int len = s.length();
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));
18  }
19  return data;
20  }
21 
22  static final String ARM64_CODE = "090038d5bf4000d50c0513d52050020e20e43d0f0018a05fa200ae9e9f3703d5bf3303d5df3f03d5217c029b217c00530040214be10b40b9200481da2008028b105be83c";
23 
24  public static Capstone cs;
25 
26  private static String hex(int i) {
27  return Integer.toString(i, 16);
28  }
29 
30  private static String hex(long i) {
31  return Long.toString(i, 16);
32  }
33 
34  public static void print_ins_detail(Capstone.CsInsn ins) {
35  System.out.printf("0x%x:\t%s\t%s\n", ins.address, ins.mnemonic, ins.opStr);
36 
37  Arm64.OpInfo operands = (Arm64.OpInfo) ins.operands;
38 
39  if (operands.op.length != 0) {
40  System.out.printf("\top_count: %d\n", operands.op.length);
41  for (int c=0; c<operands.op.length; c++) {
42  Arm64.Operand i = (Arm64.Operand) operands.op[c];
43  String imm = hex(i.value.imm);
44  if (i.type == ARM64_OP_REG)
45  System.out.printf("\t\toperands[%d].type: REG = %s\n", c, ins.regName(i.value.reg));
46  if (i.type == ARM64_OP_REG_MRS)
47  System.out.printf("\t\toperands[%d].type: REG_MRS = 0x%x\n", c, i.value.reg);
48  if (i.type == ARM64_OP_REG_MSR)
49  System.out.printf("\t\toperands[%d].type: REG_MSR = 0x%x\n", c, i.value.reg);
50  if (i.type == ARM64_OP_PSTATE)
51  System.out.printf("\t\toperands[%d].type: PSTATE = 0x%x\n", c, i.value.imm);
52  if (i.type == ARM64_OP_BARRIER)
53  System.out.printf("\t\toperands[%d].type: BARRIER = 0x%x\n", c, i.value.imm);
54 
55  if (i.type == ARM64_OP_IMM)
56  System.out.printf("\t\toperands[%d].type: IMM = 0x%x\n", c, i.value.imm);
57  if (i.type == ARM64_OP_CIMM)
58  System.out.printf("\t\toperands[%d].type: C-IMM = %d\n", c, i.value.imm);
59  if (i.type == ARM64_OP_FP)
60  System.out.printf("\t\toperands[%d].type: FP = %f\n", c, i.value.fp);
61  if (i.type == ARM64_OP_MEM) {
62  System.out.printf("\t\toperands[%d].type: MEM\n",c);
63  String base = ins.regName(i.value.mem.base);
64  String index = ins.regName(i.value.mem.index);
65  if (base != null)
66  System.out.printf("\t\t\toperands[%d].mem.base: REG = %s\n", c, base);
67  if (index != null)
68  System.out.printf("\t\t\toperands[%d].mem.index: REG = %s\n", c, index);
69  if (i.value.mem.disp != 0)
70  System.out.printf("\t\t\toperands[%d].mem.disp: 0x%x\n", c, i.value.mem.disp);
71  }
72  if (i.shift.type != ARM64_SFT_INVALID && i.shift.value > 0)
73  System.out.printf("\t\t\tShift: type = %d, value = %d\n", i.shift.type, i.shift.value);
74  if (i.ext != ARM64_EXT_INVALID)
75  System.out.printf("\t\t\tExt: %d\n", i.ext);
76  if (i.vas != ARM64_VAS_INVALID)
77  System.out.printf("\t\t\tVector Arrangement Specifier: 0x%x\n", i.vas);
78  if (i.vess != ARM64_VESS_INVALID)
79  System.out.printf("\t\t\tVector Element Size Specifier: %d\n", i.vess);
80  if (i.vector_index != -1)
81  System.out.printf("\t\t\tVector Index: %d\n", i.vector_index);
82 
83  }
84  }
85 
86  if (operands.writeback)
87  System.out.println("\tWrite-back: True");
88 
89  if (operands.updateFlags)
90  System.out.println("\tUpdate-flags: True");
91 
92  if (operands.cc != ARM64_CC_AL && operands.cc != ARM64_CC_INVALID)
93  System.out.printf("\tCode-condition: %d\n", operands.cc);
94 
95  }
96 
97  public static void main(String argv[]) {
98 
99  final TestBasic.platform[] all_tests = {
100  new TestBasic.platform(Capstone.CS_ARCH_ARM64, Capstone.CS_MODE_ARM, hexString2Byte(ARM64_CODE), "ARM-64"),
101  };
102 
103  for (int i=0; i<all_tests.length; i++) {
105  System.out.println(new String(new char[16]).replace("\0", "*"));
106  System.out.println("Platform: " + test.comment);
107  System.out.println("Code: " + TestBasic.stringToHex(test.code));
108  System.out.println("Disasm:");
109 
110  cs = new Capstone(test.arch, test.mode);
111  cs.setDetail(Capstone.CS_OPT_ON);
112  Capstone.CsInsn[] all_ins = cs.disasm(test.code, 0x2c);
113 
114  for (int j = 0; j < all_ins.length; j++) {
115  print_ins_detail(all_ins[j]);
116  System.out.println();
117  }
118 
119  System.out.printf("0x%x: \n\n", all_ins[all_ins.length-1].address + all_ins[all_ins.length-1].size);
120 
121  // Close when done
122  cs.close();
123  }
124  }
125 
126 }
ARM64_OP_FP
@ ARM64_OP_FP
= CS_OP_FP (Floating-Point operand).
Definition: arm64.h:238
capstone.Arm64.OpInfo
Definition: Arm64.java:114
TestArm64.main
static void main(String argv[])
Definition: TestArm64.java:97
ARM64_OP_REG_MRS
@ ARM64_OP_REG_MRS
MRS register operand.
Definition: arm64.h:240
TestBasic
Definition: TestBasic.java:6
TestArm64.hex
static String hex(long i)
Definition: TestArm64.java:30
TestArm64
Definition: TestArm64.java:9
ARM64_OP_REG
@ ARM64_OP_REG
= CS_OP_REG (Register operand).
Definition: arm64.h:235
ARM64_VESS_INVALID
@ ARM64_VESS_INVALID
Definition: arm64.h:208
ARM64_VAS_INVALID
@ ARM64_VAS_INVALID
Definition: arm64.h:194
TestArm64.hex
static String hex(int i)
Definition: TestArm64.java:26
ARM64_OP_REG_MSR
@ ARM64_OP_REG_MSR
MSR register operand.
Definition: arm64.h:241
ARM64_OP_PSTATE
@ ARM64_OP_PSTATE
PState operand.
Definition: arm64.h:242
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
ARM64_CC_INVALID
@ ARM64_CC_INVALID
Definition: arm64.h:42
ARM64_CC_AL
@ ARM64_CC_AL
Always (unconditional): Always (unconditional)
Definition: arm64.h:57
capstone.Arm64_const
Definition: Arm64_const.java:4
test_arm.all_tests
all_tests
Definition: test_arm.py:18
gen_synthetic_protos.base
base
Definition: gen_synthetic_protos.py:31
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
capstone
Definition: Arm.java:4
ARM64_CODE
#define ARM64_CODE
TestBasic.stringToHex
static String stringToHex(byte[] code)
Definition: TestBasic.java:30
ARM64_OP_CIMM
@ ARM64_OP_CIMM
C-Immediate.
Definition: arm64.h:239
ares::byte
unsigned char byte
Definition: ares-test.h:33
update_failure_list.test
test
Definition: bloaty/third_party/protobuf/conformance/update_failure_list.py:69
ARM64_SFT_INVALID
@ ARM64_SFT_INVALID
Definition: arm64.h:19
ARM64_OP_BARRIER
@ ARM64_OP_BARRIER
Memory barrier operand (ISB/DMB/DSB instructions).
Definition: arm64.h:245
capstone.Arm64.Operand
Definition: Arm64.java:53
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
ARM64_EXT_INVALID
@ ARM64_EXT_INVALID
Definition: arm64.h:29
capstone.Arm64
Definition: Arm64.java:14
ARM64_OP_IMM
@ ARM64_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: arm64.h:236
TestBasic.platform
Definition: TestBasic.java:7
ARM64_OP_MEM
@ ARM64_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: arm64.h:237
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
TestArm64.cs
static Capstone cs
Definition: TestArm64.java:24
if
if(p->owned &&p->wrapped !=NULL)
Definition: call.c:42
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
TestArm64.print_ins_detail
static void print_ins_detail(Capstone.CsInsn ins)
Definition: TestArm64.java:34


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:34