TestPpc.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.Ppc;
6 
7 import static capstone.Ppc_const.*;
8 
9 public class TestPpc {
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 PPC_CODE = "80200000803f00001043230ed04400804c4322022d0300807c4320147c4320934f2000214cc8002140820014";
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  Ppc.OpInfo operands = (Ppc.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  Ppc.Operand i = (Ppc.Operand) operands.op[c];
43  if (i.type == PPC_OP_REG)
44  System.out.printf("\t\toperands[%d].type: REG = %s\n", c, ins.regName(i.value.reg));
45  if (i.type == PPC_OP_IMM)
46  System.out.printf("\t\toperands[%d].type: IMM = 0x%x\n", c, i.value.imm);
47  if (i.type == PPC_OP_MEM) {
48  System.out.printf("\t\toperands[%d].type: MEM\n", c);
49  if (i.value.mem.base != PPC_REG_INVALID)
50  System.out.printf("\t\t\toperands[%d].mem.base: REG = %s\n", c, ins.regName(i.value.mem.base));
51  if (i.value.mem.disp != 0)
52  System.out.printf("\t\t\toperands[%d].mem.disp: 0x%x\n", c, i.value.mem.disp);
53  }
54  }
55  }
56 
57  if (operands.bc != 0)
58  System.out.printf("\tBranch code: %d\n", operands.bc);
59 
60  if (operands.bh != 0)
61  System.out.printf("\tBranch hint: %d\n", operands.bh);
62 
63  if (operands.updateCr0)
64  System.out.printf("\tUpdate-CR0: True\n");
65 
66  }
67 
68  public static void main(String argv[]) {
69 
70  final TestBasic.platform[] all_tests = {
71  new TestBasic.platform(Capstone.CS_ARCH_PPC, Capstone.CS_MODE_BIG_ENDIAN, hexString2Byte(PPC_CODE), "PPC-64"),
72  };
73 
74  for (int i=0; i<all_tests.length; i++) {
76  System.out.println(new String(new char[16]).replace("\0", "*"));
77  System.out.println("Platform: " + test.comment);
78  System.out.println("Code: " + TestBasic.stringToHex(test.code));
79  System.out.println("Disasm:");
80 
81  cs = new Capstone(test.arch, test.mode);
82  cs.setDetail(Capstone.CS_OPT_ON);
83  Capstone.CsInsn[] all_ins = cs.disasm(test.code, 0x1000);
84 
85  for (int j = 0; j < all_ins.length; j++) {
86  print_ins_detail(all_ins[j]);
87  System.out.println();
88  }
89  System.out.printf("0x%x:\n\n", (all_ins[all_ins.length-1].address + all_ins[all_ins.length-1].size));
90 
91  // Close when done
92  cs.close();
93  }
94  }
95 
96 }
PPC_REG_INVALID
@ PPC_REG_INVALID
Definition: ppc.h:52
TestBasic
Definition: TestBasic.java:6
TestPpc.hex
static String hex(long i)
Definition: TestPpc.java:30
capstone.Ppc
Definition: Ppc.java:14
PPC_OP_MEM
@ PPC_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: ppc.h:46
capstone.Ppc.Operand
Definition: Ppc.java:44
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
capstone.Ppc.OpInfo
Definition: Ppc.java:95
test_arm.all_tests
all_tests
Definition: test_arm.py:18
TestPpc.hex
static String hex(int i)
Definition: TestPpc.java:26
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
capstone
Definition: Arm.java:4
TestBasic.stringToHex
static String stringToHex(byte[] code)
Definition: TestBasic.java:30
TestPpc.cs
static Capstone cs
Definition: TestPpc.java:24
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
PPC_OP_REG
@ PPC_OP_REG
= CS_OP_REG (Register operand).
Definition: ppc.h:44
TestPpc.print_ins_detail
static void print_ins_detail(Capstone.CsInsn ins)
Definition: TestPpc.java:34
PPC_CODE
#define PPC_CODE
capstone.Ppc_const
Definition: Ppc_const.java:4
TestBasic.platform
Definition: TestBasic.java:7
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
PPC_OP_IMM
@ PPC_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: ppc.h:45
TestPpc
Definition: TestPpc.java:9
if
if(p->owned &&p->wrapped !=NULL)
Definition: call.c:42
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
TestPpc.main
static void main(String argv[])
Definition: TestPpc.java:68


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