Rizin
unix-like reverse engineering framework and cli tools
test_group_name.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 from capstone import *
4 from capstone.arm import *
5 from capstone.arm64 import *
6 from capstone.mips import *
7 from capstone.ppc import *
8 from capstone.sparc import *
9 from capstone.systemz import *
10 from capstone.x86 import *
11 from capstone.xcore import *
12 import sys
13 
14 class GroupTest:
15  def __init__(self, name, arch, mode, data):
16  self.namename = name
17  self.archarch = arch
18  self.modemode = mode
19  self.datadata = data
20 
21  def run(self):
22  print('Testing %s' %self.namename)
23  cap = Cs(self.archarch, self.modemode)
24  for group_id in xrange(0,255):
25  name = self.datadata.get(group_id)
26  res = cap.group_name(group_id)
27  if res != name:
28  print("ERROR: id = %u expected '%s', but got '%s'" %(group_id, name, res))
29  print("")
30 
31 arm_dict = {
32  ARM_GRP_JUMP: "jump",
33  ARM_GRP_CALL: "call",
34  ARM_GRP_INT: "int",
35  ARM_GRP_PRIVILEGE: "privilege",
36 
37  ARM_GRP_CRYPTO: "crypto",
38  ARM_GRP_DATABARRIER: "databarrier",
39  ARM_GRP_DIVIDE: "divide",
40  ARM_GRP_FPARMV8: "fparmv8",
41  ARM_GRP_MULTPRO: "multpro",
42  ARM_GRP_NEON: "neon",
43  ARM_GRP_T2EXTRACTPACK: "T2EXTRACTPACK",
44  ARM_GRP_THUMB2DSP: "THUMB2DSP",
45  ARM_GRP_TRUSTZONE: "TRUSTZONE",
46  ARM_GRP_V4T: "v4t",
47  ARM_GRP_V5T: "v5t",
48  ARM_GRP_V5TE: "v5te",
49  ARM_GRP_V6: "v6",
50  ARM_GRP_V6T2: "v6t2",
51  ARM_GRP_V7: "v7",
52  ARM_GRP_V8: "v8",
53  ARM_GRP_VFP2: "vfp2",
54  ARM_GRP_VFP3: "vfp3",
55  ARM_GRP_VFP4: "vfp4",
56  ARM_GRP_ARM: "arm",
57  ARM_GRP_MCLASS: "mclass",
58  ARM_GRP_NOTMCLASS: "notmclass",
59  ARM_GRP_THUMB: "thumb",
60  ARM_GRP_THUMB1ONLY: "thumb1only",
61  ARM_GRP_THUMB2: "thumb2",
62  ARM_GRP_PREV8: "prev8",
63  ARM_GRP_FPVMLX: "fpvmlx",
64  ARM_GRP_MULOPS: "mulops",
65  ARM_GRP_CRC: "crc",
66  ARM_GRP_DPVFP: "dpvfp",
67  ARM_GRP_V6M: "v6m",
68  ARM_GRP_VIRTUALIZATION: "virtualization",
69 }
70 
71 arm64_dict = {
72  ARM64_GRP_JUMP: "jump",
73  ARM64_GRP_CALL: "call",
74  ARM64_GRP_RET: "return",
75  ARM64_GRP_INT: "int",
76  ARM64_GRP_PRIVILEGE: "privilege",
77 
78  ARM64_GRP_CRYPTO: "crypto",
79  ARM64_GRP_FPARMV8: "fparmv8",
80  ARM64_GRP_NEON: "neon",
81  ARM64_GRP_CRC: "crc"
82 }
83 
84 mips_dict = {
85  MIPS_GRP_JUMP: "jump",
86  MIPS_GRP_CALL: "call",
87  MIPS_GRP_RET: "ret",
88  MIPS_GRP_INT: "int",
89  MIPS_GRP_IRET: "iret",
90  MIPS_GRP_PRIVILEGE: "privilege",
91  MIPS_GRP_BITCOUNT: "bitcount",
92  MIPS_GRP_DSP: "dsp",
93  MIPS_GRP_DSPR2: "dspr2",
94  MIPS_GRP_FPIDX: "fpidx",
95  MIPS_GRP_MSA: "msa",
96  MIPS_GRP_MIPS32R2: "mips32r2",
97  MIPS_GRP_MIPS64: "mips64",
98  MIPS_GRP_MIPS64R2: "mips64r2",
99  MIPS_GRP_SEINREG: "seinreg",
100  MIPS_GRP_STDENC: "stdenc",
101  MIPS_GRP_SWAP: "swap",
102  MIPS_GRP_MICROMIPS: "micromips",
103  MIPS_GRP_MIPS16MODE: "mips16mode",
104  MIPS_GRP_FP64BIT: "fp64bit",
105  MIPS_GRP_NONANSFPMATH: "nonansfpmath",
106  MIPS_GRP_NOTFP64BIT: "notfp64bit",
107  MIPS_GRP_NOTINMICROMIPS: "notinmicromips",
108  MIPS_GRP_NOTNACL: "notnacl",
109 
110  MIPS_GRP_NOTMIPS32R6: "notmips32r6",
111  MIPS_GRP_NOTMIPS64R6: "notmips64r6",
112  MIPS_GRP_CNMIPS: "cnmips",
113 
114  MIPS_GRP_MIPS32: "mips32",
115  MIPS_GRP_MIPS32R6: "mips32r6",
116  MIPS_GRP_MIPS64R6: "mips64r6",
117 
118  MIPS_GRP_MIPS2: "mips2",
119  MIPS_GRP_MIPS3: "mips3",
120  MIPS_GRP_MIPS3_32: "mips3_32",
121  MIPS_GRP_MIPS3_32R2: "mips3_32r2",
122 
123  MIPS_GRP_MIPS4_32: "mips4_32",
124  MIPS_GRP_MIPS4_32R2: "mips4_32r2",
125  MIPS_GRP_MIPS5_32R2: "mips5_32r2",
126 
127  MIPS_GRP_GP32BIT: "gp32bit",
128  MIPS_GRP_GP64BIT: "gp64bit",
129 }
130 
131 ppc_dict = {
132  PPC_GRP_JUMP: "jump",
133 
134  PPC_GRP_ALTIVEC: "altivec",
135  PPC_GRP_MODE32: "mode32",
136  PPC_GRP_MODE64: "mode64",
137  PPC_GRP_BOOKE: "booke",
138  PPC_GRP_NOTBOOKE: "notbooke",
139  PPC_GRP_SPE: "spe",
140  PPC_GRP_VSX: "vsx",
141  PPC_GRP_E500: "e500",
142  PPC_GRP_PPC4XX: "ppc4xx",
143  PPC_GRP_PPC6XX: "ppc6xx",
144  PPC_GRP_ICBT: "icbt",
145  PPC_GRP_P8ALTIVEC: "p8altivec",
146  PPC_GRP_P8VECTOR: "p8vector",
147  PPC_GRP_QPX: "qpx",
148 }
149 
150 sparc_dict = {
151  SPARC_GRP_JUMP: "jump",
152 
153  SPARC_GRP_HARDQUAD: "hardquad",
154  SPARC_GRP_V9: "v9",
155  SPARC_GRP_VIS: "vis",
156  SPARC_GRP_VIS2: "vis2",
157  SPARC_GRP_VIS3: "vis3",
158  SPARC_GRP_32BIT: "32bit",
159  SPARC_GRP_64BIT: "64bit",
160 }
161 
162 sysz_dict = {
163  SYSZ_GRP_JUMP: "jump",
164 
165  SYSZ_GRP_DISTINCTOPS: "distinctops",
166  SYSZ_GRP_FPEXTENSION: "fpextension",
167  SYSZ_GRP_HIGHWORD: "highword",
168  SYSZ_GRP_INTERLOCKEDACCESS1: "interlockedaccess1",
169  SYSZ_GRP_LOADSTOREONCOND: "loadstoreoncond",
170 }
171 
172 x86_dict = {
173  X86_GRP_JUMP: "jump",
174  X86_GRP_CALL: "call",
175  X86_GRP_RET: "ret",
176  X86_GRP_INT: "int",
177  X86_GRP_IRET: "iret",
178  X86_GRP_PRIVILEGE: "privilege",
179 
180  X86_GRP_VM: "vm",
181  X86_GRP_3DNOW: "3dnow",
182  X86_GRP_AES: "aes",
183  X86_GRP_ADX: "adx",
184  X86_GRP_AVX: "avx",
185  X86_GRP_AVX2: "avx2",
186  X86_GRP_AVX512: "avx512",
187  X86_GRP_BMI: "bmi",
188  X86_GRP_BMI2: "bmi2",
189  X86_GRP_CMOV: "cmov",
190  X86_GRP_F16C: "fc16",
191  X86_GRP_FMA: "fma",
192  X86_GRP_FMA4: "fma4",
193  X86_GRP_FSGSBASE: "fsgsbase",
194  X86_GRP_HLE: "hle",
195  X86_GRP_MMX: "mmx",
196  X86_GRP_MODE32: "mode32",
197  X86_GRP_MODE64: "mode64",
198  X86_GRP_RTM: "rtm",
199  X86_GRP_SHA: "sha",
200  X86_GRP_SSE1: "sse1",
201  X86_GRP_SSE2: "sse2",
202  X86_GRP_SSE3: "sse3",
203  X86_GRP_SSE41: "sse41",
204  X86_GRP_SSE42: "sse42",
205  X86_GRP_SSE4A: "sse4a",
206  X86_GRP_SSSE3: "ssse3",
207  X86_GRP_PCLMUL: "pclmul",
208  X86_GRP_XOP: "xop",
209  X86_GRP_CDI: "cdi",
210  X86_GRP_ERI: "eri",
211  X86_GRP_TBM: "tbm",
212  X86_GRP_16BITMODE: "16bitmode",
213  X86_GRP_NOT64BITMODE: "not64bitmode",
214  X86_GRP_SGX: "sgx",
215  X86_GRP_DQI: "dqi",
216  X86_GRP_BWI: "bwi",
217  X86_GRP_PFI: "pfi",
218  X86_GRP_VLX: "vlx",
219  X86_GRP_SMAP: "smap",
220  X86_GRP_NOVLX: "novlx",
221 }
222 
223 xcore_dict = {
224  XCORE_GRP_JUMP: "jump",
225 }
226 
227 tests = [
228  GroupTest('arm', CS_ARCH_ARM, CS_MODE_THUMB, arm_dict),
229  GroupTest('arm64', CS_ARCH_ARM64, CS_MODE_ARM, arm64_dict),
230  GroupTest('mips', CS_ARCH_MIPS, CS_MODE_MIPS32 | CS_MODE_BIG_ENDIAN, mips_dict),
231  GroupTest('ppc', CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, ppc_dict),
232  GroupTest('sparc', CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN, sparc_dict),
233  GroupTest('sysz', CS_ARCH_SYSZ, CS_MODE_BIG_ENDIAN, sysz_dict),
234  GroupTest('x86', CS_ARCH_X86, CS_MODE_32, x86_dict),
235  GroupTest('xcore', CS_ARCH_XCORE, CS_MODE_BIG_ENDIAN, xcore_dict),
236  GroupTest('m68k', CS_ARCH_M68K, CS_MODE_BIG_ENDIAN, xcore_dict),
237 ]
238 
239 if __name__ == '__main__':
240  args = sys.argv[1:]
241  all = len(args) == 0 or 'all' in args
242  for t in tests:
243  if all or t.name in args:
244  t.run()
245  else:
246  print('Skipping %s' %t.name)
247 
size_t len
Definition: 6502dis.c:15
def __init__(self, name, arch, mode, data)