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