Rizin
unix-like reverse engineering framework and cli tools
TestArm Class Reference

Static Public Member Functions

static void print_ins_detail (Capstone.CsInsn ins)
 
static void main (String argv[])
 

Static Public Attributes

static Capstone cs
 

Static Package Functions

static byte[] hexString2Byte (String s)
 

Static Package Attributes

static final String ARM_CODE = "EDFFFFEB04e02de500000000e08322e5f102030e0000a0e30230c1e7000053e3000201f10540d0e8"
 
static final String ARM_CODE2 = "d1e800f0f02404071f3cf2c000004ff00001466c"
 
static final String THUMB_CODE2 = "4ff00001bde80088d1e800f018bfadbff3ff0b0c86f3008980f3008c4ffa99f6d0ffa201"
 
static final String THUMB_CODE = "7047eb4683b0c9681fb130bfaff32084"
 

Static Private Member Functions

static String hex (int i)
 
static String hex (long i)
 

Detailed Description

Definition at line 9 of file TestArm.java.

Member Function Documentation

◆ hex() [1/2]

static String TestArm.hex ( int  i)
inlinestaticprivate

Definition at line 29 of file TestArm.java.

29  {
30  return Integer.toString(i, 16);
31  }
lzma_index ** i
Definition: index.h:629

References i.

Referenced by print_ins_detail().

◆ hex() [2/2]

static String TestArm.hex ( long  i)
inlinestaticprivate

Definition at line 33 of file TestArm.java.

33  {
34  return Long.toString(i, 16);
35  }

References i.

◆ hexString2Byte()

static byte [] TestArm.hexString2Byte ( String  s)
inlinestaticpackage

Definition at line 11 of file TestArm.java.

11  {
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  }
size_t len
Definition: 6502dis.c:15
static RzSocket * s
Definition: rtr.c:28

References i, len, and s.

Referenced by main().

◆ main()

static void TestArm.main ( String  argv[])
inlinestatic

Definition at line 109 of file TestArm.java.

109  {
110 
111  final TestBasic.platform[] all_tests = {
112  new TestBasic.platform(Capstone.CS_ARCH_ARM, Capstone.CS_MODE_ARM, hexString2Byte(ARM_CODE), "ARM"),
113  new TestBasic.platform(Capstone.CS_ARCH_ARM, Capstone.CS_MODE_THUMB, hexString2Byte(THUMB_CODE), "Thumb"),
114  new TestBasic.platform(Capstone.CS_ARCH_ARM, Capstone.CS_MODE_THUMB, hexString2Byte(ARM_CODE2), "Thumb-mixed"),
115  new TestBasic.platform(Capstone.CS_ARCH_ARM, Capstone.CS_MODE_THUMB, Capstone.CS_OPT_SYNTAX_NOREGNAME, hexString2Byte(THUMB_CODE2), "Thumb-2 & register named with numbers"),
116  };
117 
118  for (int i=0; i<all_tests.length; i++) {
120  System.out.println(new String(new char[16]).replace("\0", "*"));
121  System.out.println("Platform: " + test.comment);
122  System.out.println("Code: " + TestBasic.stringToHex(test.code));
123  System.out.println("Disasm:");
124 
125  cs = new Capstone(test.arch, test.mode);
126  cs.setDetail(Capstone.CS_OPT_ON);
127  if (test.syntax != 0)
128  cs.setSyntax(test.syntax);
129  Capstone.CsInsn[] all_ins = cs.disasm(test.code, 0x1000);
130 
131  for (int j = 0; j < all_ins.length; j++) {
132  print_ins_detail(all_ins[j]);
133  System.out.println();
134  }
135  System.out.printf("0x%x:\n\n", (all_ins[all_ins.length-1].address + all_ins[all_ins.length-1].size));
136 
137  // Close when done
138  cs.close();
139  }
140  }
static final String ARM_CODE2
Definition: TestArm.java:23
static final String THUMB_CODE2
Definition: TestArm.java:24
static final String ARM_CODE
Definition: TestArm.java:22
static final String THUMB_CODE
Definition: TestArm.java:25
static void print_ins_detail(Capstone.CsInsn ins)
Definition: TestArm.java:37
static Capstone cs
Definition: TestArm.java:27
static byte[] hexString2Byte(String s)
Definition: TestArm.java:11
static String stringToHex(byte[] code)
Definition: TestBasic.java:30
tuple all_tests
Definition: test_arm.py:18
-lz4-versions
int replace(char *string, const char *token, const char *fmt,...)
Definition: tms320_dasm.c:325

References test_arm.all_tests, ARM_CODE, ARM_CODE2, cs, hexString2Byte(), i, print_ins_detail(), replace(), TestBasic.stringToHex(), THUMB_CODE, and THUMB_CODE2.

◆ print_ins_detail()

static void TestArm.print_ins_detail ( Capstone.CsInsn  ins)
inlinestatic

Definition at line 37 of file TestArm.java.

37  {
38  System.out.printf("0x%x:\t%s\t%s\n", ins.address, ins.mnemonic, ins.opStr);
39 
40  Arm.OpInfo operands = (Arm.OpInfo) ins.operands;
41 
42  if (operands.op.length != 0) {
43  System.out.printf("\top_count: %d\n", operands.op.length);
44  for (int c=0; c<operands.op.length; c++) {
45  Arm.Operand i = (Arm.Operand) operands.op[c];
46  String imm = hex(i.value.imm);
47  if (i.type == ARM_OP_SYSREG)
48  System.out.printf("\t\toperands[%d].type: SYSREG = %d\n", c, i.value.reg);
49  if (i.type == ARM_OP_REG)
50  System.out.printf("\t\toperands[%d].type: REG = %s\n", c, ins.regName(i.value.reg));
51  if (i.type == ARM_OP_IMM)
52  System.out.printf("\t\toperands[%d].type: IMM = 0x%x\n", c, i.value.imm);
53  if (i.type == ARM_OP_PIMM)
54  System.out.printf("\t\toperands[%d].type: P-IMM = %d\n", c, i.value.imm);
55  if (i.type == ARM_OP_CIMM)
56  System.out.printf("\t\toperands[%d].type: C-IMM = %d\n", c, i.value.imm);
57  if (i.type == ARM_OP_SETEND)
58  System.out.printf("\t\toperands[%d].type: SETEND = %s\n", c, i.value.setend == ARM_SETEND_BE? "be" : "le");
59  if (i.type == ARM_OP_FP)
60  System.out.printf("\t\toperands[%d].type: FP = %f\n", c, i.value.fp);
61  if (i.type == ARM_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.scale != 1)
70  System.out.printf("\t\t\toperands[%d].mem.scale: %d\n", c, (i.value.mem.scale));
71  if (i.value.mem.disp != 0)
72  System.out.printf("\t\t\toperands[%d].mem.disp: 0x%x\n", c, (i.value.mem.disp));
73  if (i.value.mem.lshift != 0)
74  System.out.printf("\t\t\toperands[%d].mem.lshift: 0x%x\n", c, (i.value.mem.lshift));
75  }
76  if (i.vector_index > 0)
77  System.out.printf("\t\t\toperands[%d].vector_index = %d\n", c, (i.vector_index));
78  if (i.shift.type != ARM_SFT_INVALID && i.shift.value > 0)
79  System.out.printf("\t\t\tShift: %d = %d\n", i.shift.type, i.shift.value);
80  if (i.subtracted)
81  System.out.printf("\t\t\toperands[%d].subtracted = True\n", c);
82  }
83  }
84  if (operands.writeback)
85  System.out.println("\tWrite-back: True");
86 
87  if (operands.updateFlags)
88  System.out.println("\tUpdate-flags: True");
89 
90  if (operands.cc != ARM_CC_AL && operands.cc != ARM_CC_INVALID)
91  System.out.printf("\tCode condition: %d\n", operands.cc);
92 
93  if (operands.cpsMode > 0)
94  System.out.printf("\tCPSI-mode: %d\n", operands.cpsMode);
95 
96  if (operands.cpsFlag > 0)
97  System.out.printf("\tCPSI-flag: %d\n", operands.cpsFlag);
98 
99  if (operands.vectorData > 0)
100  System.out.printf("\tVector-data: %d\n", operands.vectorData);
101 
102  if (operands.vectorSize > 0)
103  System.out.printf("\tVector-size: %d\n", operands.vectorSize);
104 
105  if (operands.usermode)
106  System.out.printf("\tUser-mode: True\n");
107  }
#define imm
@ ARM_SFT_INVALID
Definition: arm.h:19
@ ARM_SETEND_BE
BE operand.
Definition: arm.h:176
@ ARM_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: arm.h:164
@ ARM_OP_REG
= CS_OP_REG (Register operand).
Definition: arm.h:163
@ ARM_OP_CIMM
C-Immediate (coprocessor registers)
Definition: arm.h:167
@ ARM_OP_SETEND
operand for SETEND instruction
Definition: arm.h:169
@ ARM_OP_PIMM
P-Immediate (coprocessor registers)
Definition: arm.h:168
@ ARM_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: arm.h:165
@ ARM_OP_FP
= CS_OP_FP (Floating-Point operand).
Definition: arm.h:166
@ ARM_OP_SYSREG
MSR/MRS special register operand.
Definition: arm.h:170
@ ARM_CC_AL
Always (unconditional) Always (unconditional)
Definition: arm.h:49
@ ARM_CC_INVALID
Definition: arm.h:34
static String hex(int i)
Definition: TestArm.java:29
#define c(i)
Definition: sha256.c:43
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References ARM_CC_AL, ARM_CC_INVALID, ARM_OP_CIMM, ARM_OP_FP, ARM_OP_IMM, ARM_OP_MEM, ARM_OP_PIMM, ARM_OP_REG, ARM_OP_SETEND, ARM_OP_SYSREG, ARM_SETEND_BE, ARM_SFT_INVALID, c, hex(), i, if(), and imm.

Referenced by main().

Member Data Documentation

◆ ARM_CODE

final String TestArm.ARM_CODE = "EDFFFFEB04e02de500000000e08322e5f102030e0000a0e30230c1e7000053e3000201f10540d0e8"
staticpackage

Definition at line 22 of file TestArm.java.

Referenced by main().

◆ ARM_CODE2

final String TestArm.ARM_CODE2 = "d1e800f0f02404071f3cf2c000004ff00001466c"
staticpackage

Definition at line 23 of file TestArm.java.

Referenced by main().

◆ cs

Capstone TestArm.cs
static

Definition at line 27 of file TestArm.java.

Referenced by main().

◆ THUMB_CODE

final String TestArm.THUMB_CODE = "7047eb4683b0c9681fb130bfaff32084"
staticpackage

Definition at line 25 of file TestArm.java.

Referenced by main().

◆ THUMB_CODE2

final String TestArm.THUMB_CODE2 = "4ff00001bde80088d1e800f018bfadbff3ff0b0c86f3008980f3008c4ffa99f6d0ffa201"
staticpackage

Definition at line 24 of file TestArm.java.

Referenced by main().


The documentation for this class was generated from the following file: