Rizin
unix-like reverse engineering framework and cli tools
TestMips 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 MIPS_CODE = "0C100097000000002402000c8fa2000034213456"
 
static final String MIPS_CODE2 = "56342134c2170100"
 

Static Private Member Functions

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

Detailed Description

Definition at line 9 of file TestMips.java.

Member Function Documentation

◆ hex() [1/2]

static String TestMips.hex ( int  i)
inlinestaticprivate

Definition at line 27 of file TestMips.java.

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

References i.

Referenced by print_ins_detail().

◆ hex() [2/2]

static String TestMips.hex ( long  i)
inlinestaticprivate

Definition at line 31 of file TestMips.java.

31  {
32  return Long.toString(i, 16);
33  }

References i.

◆ hexString2Byte()

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

Definition at line 11 of file TestMips.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 TestMips.main ( String  argv[])
inlinestatic

Definition at line 61 of file TestMips.java.

61  {
62 
63  final TestBasic.platform[] all_tests = {
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)"),
66  };
67 
68  for (int i=0; i<all_tests.length; i++) {
70  System.out.println(new String(new char[16]).replace("\0", "*"));
71  System.out.println("Platform: " + test.comment);
72  System.out.println("Code: " + TestBasic.stringToHex(test.code));
73  System.out.println("Disasm:");
74 
75  cs = new Capstone(test.arch, test.mode);
76  cs.setDetail(Capstone.CS_OPT_ON);
77  Capstone.CsInsn[] all_ins = cs.disasm(test.code, 0x1000);
78 
79  for (int j = 0; j < all_ins.length; j++) {
80  print_ins_detail(all_ins[j]);
81  System.out.println();
82  }
83 
84  System.out.printf("0x%x:\n\n", all_ins[all_ins.length-1].address + all_ins[all_ins.length-1].size);
85 
86  // Close when done
87  cs.close();
88  }
89  }
static String stringToHex(byte[] code)
Definition: TestBasic.java:30
static Capstone cs
Definition: TestMips.java:25
static final String MIPS_CODE2
Definition: TestMips.java:23
static byte[] hexString2Byte(String s)
Definition: TestMips.java:11
static final String MIPS_CODE
Definition: TestMips.java:22
static void print_ins_detail(Capstone.CsInsn ins)
Definition: TestMips.java:35
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, cs, hexString2Byte(), i, MIPS_CODE, MIPS_CODE2, print_ins_detail(), replace(), and TestBasic.stringToHex().

◆ print_ins_detail()

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

Definition at line 35 of file TestMips.java.

35  {
36  System.out.printf("0x%x:\t%s\t%s\n", ins.address, ins.mnemonic, ins.opStr);
37 
38  Mips.OpInfo operands = (Mips.OpInfo) ins.operands;
39 
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);
45  if (i.type == MIPS_OP_REG)
46  System.out.printf("\t\toperands[%d].type: REG = %s\n", c, ins.regName(i.value.reg));
47  if (i.type == MIPS_OP_IMM)
48  System.out.printf("\t\toperands[%d].type: IMM = 0x%x\n", c, i.value.imm);
49  if (i.type == MIPS_OP_MEM) {
50  System.out.printf("\t\toperands[%d].type: MEM\n",c);
51  String base = ins.regName(i.value.mem.base);
52  if (base != null)
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));
56  }
57  }
58  }
59  }
#define imm
static String hex(int i)
Definition: TestMips.java:27
#define c(i)
Definition: sha256.c:43
@ MIPS_OP_REG
= CS_OP_REG (Register operand).
Definition: mips.h:24
@ MIPS_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: mips.h:25
@ MIPS_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: mips.h:26
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References c, hex(), i, if(), imm, MIPS_OP_IMM, MIPS_OP_MEM, and MIPS_OP_REG.

Referenced by main().

Member Data Documentation

◆ cs

Capstone TestMips.cs
static

Definition at line 25 of file TestMips.java.

Referenced by main().

◆ MIPS_CODE

final String TestMips.MIPS_CODE = "0C100097000000002402000c8fa2000034213456"
staticpackage

Definition at line 22 of file TestMips.java.

Referenced by main().

◆ MIPS_CODE2

final String TestMips.MIPS_CODE2 = "56342134c2170100"
staticpackage

Definition at line 23 of file TestMips.java.

Referenced by main().


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