68 print(
"Test %s" %fname);
73 if not lines[0].startswith(
'# '):
74 print(
"ERROR: decoding information is missing")
81 (arch, mode, option) = lines[0][2:].split(
', ')
82 mode = mode.replace(
' ',
'')
83 option = option.strip()
86 "CS_ARCH_ARM": CS_ARCH_ARM,
87 "CS_ARCH_ARM64": CS_ARCH_ARM64,
88 "CS_ARCH_MIPS": CS_ARCH_MIPS,
89 "CS_ARCH_PPC": CS_ARCH_PPC,
90 "CS_ARCH_SPARC": CS_ARCH_SPARC,
91 "CS_ARCH_SYSZ": CS_ARCH_SYSZ,
92 "CS_ARCH_X86": CS_ARCH_X86,
93 "CS_ARCH_XCORE": CS_ARCH_XCORE,
94 "CS_ARCH_M68K": CS_ARCH_M68K,
98 "CS_MODE_16": CS_MODE_16,
99 "CS_MODE_32": CS_MODE_32,
100 "CS_MODE_64": CS_MODE_64,
101 "CS_MODE_MIPS32": CS_MODE_MIPS32,
102 "CS_MODE_MIPS64": CS_MODE_MIPS64,
104 "CS_MODE_ARM": CS_MODE_ARM,
105 "CS_MODE_THUMB": CS_MODE_THUMB,
106 "CS_MODE_ARM+CS_MODE_V8": CS_MODE_ARM+CS_MODE_V8,
107 "CS_MODE_THUMB+CS_MODE_V8": CS_MODE_THUMB+CS_MODE_V8,
108 "CS_MODE_THUMB+CS_MODE_MCLASS": CS_MODE_THUMB+CS_MODE_MCLASS,
109 "CS_MODE_LITTLE_ENDIAN": CS_MODE_LITTLE_ENDIAN,
110 "CS_MODE_BIG_ENDIAN": CS_MODE_BIG_ENDIAN,
111 "CS_MODE_64+CS_MODE_LITTLE_ENDIAN": CS_MODE_64+CS_MODE_LITTLE_ENDIAN,
112 "CS_MODE_64+CS_MODE_BIG_ENDIAN": CS_MODE_64+CS_MODE_BIG_ENDIAN,
113 "CS_MODE_MIPS32+CS_MODE_MICRO": CS_MODE_MIPS32+CS_MODE_MICRO,
114 "CS_MODE_MIPS32+CS_MODE_MICRO+CS_MODE_BIG_ENDIAN": CS_MODE_MIPS32+CS_MODE_MICRO+CS_MODE_BIG_ENDIAN,
115 "CS_MODE_MIPS32+CS_MODE_BIG_ENDIAN+CS_MODE_MICRO": CS_MODE_MIPS32+CS_MODE_MICRO+CS_MODE_BIG_ENDIAN,
116 "CS_MODE_BIG_ENDIAN+CS_MODE_V9": CS_MODE_BIG_ENDIAN + CS_MODE_V9,
117 "CS_MODE_MIPS32+CS_MODE_BIG_ENDIAN": CS_MODE_MIPS32+CS_MODE_BIG_ENDIAN,
118 "CS_MODE_MIPS32+CS_MODE_LITTLE_ENDIAN": CS_MODE_MIPS32+CS_MODE_LITTLE_ENDIAN,
119 "CS_MODE_MIPS64+CS_MODE_LITTLE_ENDIAN": CS_MODE_MIPS64+CS_MODE_LITTLE_ENDIAN,
120 "CS_MODE_MIPS64+CS_MODE_BIG_ENDIAN": CS_MODE_MIPS64+CS_MODE_BIG_ENDIAN,
124 "CS_OPT_SYNTAX_ATT": CS_OPT_SYNTAX_ATT,
125 "CS_OPT_SYNTAX_NOREGNAME": CS_OPT_SYNTAX_NOREGNAME,
129 (
"CS_ARCH_X86",
"CS_MODE_32"): [
'-triple=i386'],
130 (
"CS_ARCH_X86",
"CS_MODE_64"): [
'-triple=x86_64'],
131 (
"CS_ARCH_ARM",
"CS_MODE_ARM"): [
'-triple=armv7'],
132 (
"CS_ARCH_ARM",
"CS_MODE_THUMB"): [
'-triple=thumbv7'],
133 (
"CS_ARCH_ARM",
"CS_MODE_ARM+CS_MODE_V8"): [
'-triple=armv8'],
134 (
"CS_ARCH_ARM",
"CS_MODE_THUMB+CS_MODE_V8"): [
'-triple=thumbv8'],
135 (
"CS_ARCH_ARM",
"CS_MODE_THUMB+CS_MODE_MCLASS"): [
'-triple=thumbv7m'],
136 (
"CS_ARCH_ARM64",
"0"): [
'-triple=aarch64'],
137 (
"CS_ARCH_MIPS",
"CS_MODE_MIPS32+CS_MODE_BIG_ENDIAN"): [
'-triple=mips'],
138 (
"CS_ARCH_MIPS",
"CS_MODE_MIPS32+CS_MODE_MICRO"): [
'-triple=mipsel',
'-mattr=+micromips'],
139 (
"CS_ARCH_MIPS",
"CS_MODE_MIPS64"): [
'-triple=mips64el'],
140 (
"CS_ARCH_MIPS",
"CS_MODE_MIPS32"): [
'-triple=mipsel'],
141 (
"CS_ARCH_MIPS",
"CS_MODE_MIPS64+CS_MODE_BIG_ENDIAN"): [
'-triple=mips64'],
142 (
"CS_ARCH_MIPS",
"CS_MODE_MIPS32+CS_MODE_MICRO+CS_MODE_BIG_ENDIAN"): [
'-triple=mips',
'-mattr=+micromips'],
143 (
"CS_ARCH_MIPS",
"CS_MODE_MIPS32+CS_MODE_BIG_ENDIAN+CS_MODE_MICRO"): [
'-triple=mips',
'-mattr=+micromips'],
144 (
"CS_ARCH_PPC",
"CS_MODE_BIG_ENDIAN"): [
'-triple=powerpc64'],
145 (
'CS_ARCH_SPARC',
'CS_MODE_BIG_ENDIAN'): [
'-triple=sparc'],
146 (
'CS_ARCH_SPARC',
'CS_MODE_BIG_ENDIAN+CS_MODE_V9'): [
'-triple=sparcv9'],
147 (
'CS_ARCH_SYSZ',
'0'): [
'-triple=s390x',
'-mcpu=z196'],
154 md = Cs(archs[arch], modes[mode])
157 if arch ==
'CS_ARCH_X86':
159 mc_option =
'-output-asm-variant=1'
161 if arch ==
'CS_ARCH_ARM' or arch ==
'CS_ARCH_PPC' :
162 md.syntax = CS_OPT_SYNTAX_NOREGNAME
164 if fname.endswith(
'3DNow.s.cs'):
165 md.syntax = CS_OPT_SYNTAX_ATT
167 for line
in lines[1:]:
169 if line.startswith(
'#'):
172 code = line.split(
' = ')[0]
173 asm =
''.join(line.split(
' = ')[1:])
174 hex_code = code.replace(
'0x',
'')
175 hex_code = hex_code.replace(
',',
'')
176 hex_data = hex_code.decode(
'hex')
179 x =
list(md.disasm(hex_data, 0))
181 if x[0].op_str !=
'':
182 cs_output =
"%s %s" %(x[0].mnemonic, x[0].op_str)
184 cs_output = x[0].mnemonic
186 cs_output =
'FAILED to disassemble'
189 cs_output2 = cs_output2.replace(
' ',
'')
191 if arch ==
'CS_ARCH_MIPS':
193 cs_output2 = cs_output2.replace(
'$at',
'$1')
194 cs_output2 = cs_output2.replace(
'$v0',
'$2')
195 cs_output2 = cs_output2.replace(
'$v1',
'$3')
197 cs_output2 = cs_output2.replace(
'$a0',
'$4')
198 cs_output2 = cs_output2.replace(
'$a1',
'$5')
199 cs_output2 = cs_output2.replace(
'$a2',
'$6')
200 cs_output2 = cs_output2.replace(
'$a3',
'$7')
202 cs_output2 = cs_output2.replace(
'$t0',
'$8')
203 cs_output2 = cs_output2.replace(
'$t1',
'$9')
204 cs_output2 = cs_output2.replace(
'$t2',
'$10')
205 cs_output2 = cs_output2.replace(
'$t3',
'$11')
206 cs_output2 = cs_output2.replace(
'$t4',
'$12')
207 cs_output2 = cs_output2.replace(
'$t5',
'$13')
208 cs_output2 = cs_output2.replace(
'$t6',
'$14')
209 cs_output2 = cs_output2.replace(
'$t7',
'$15')
210 cs_output2 = cs_output2.replace(
'$t8',
'$24')
211 cs_output2 = cs_output2.replace(
'$t9',
'$25')
213 cs_output2 = cs_output2.replace(
'$s0',
'$16')
214 cs_output2 = cs_output2.replace(
'$s1',
'$17')
215 cs_output2 = cs_output2.replace(
'$s2',
'$18')
216 cs_output2 = cs_output2.replace(
'$s3',
'$19')
217 cs_output2 = cs_output2.replace(
'$s4',
'$20')
218 cs_output2 = cs_output2.replace(
'$s5',
'$21')
219 cs_output2 = cs_output2.replace(
'$s6',
'$22')
220 cs_output2 = cs_output2.replace(
'$s7',
'$23')
222 cs_output2 = cs_output2.replace(
'$k0',
'$26')
223 cs_output2 = cs_output2.replace(
'$k1',
'$27')
226 if fname.endswith(
'thumb-fp-armv8.s.cs'):
227 mc_output =
run_mc(archs[arch], code, [
'-triple=thumbv8'], mc_option)
228 elif fname.endswith(
'mips64-alu-instructions.s.cs'):
229 mc_output =
run_mc(archs[arch], code, [
'-triple=mips64el',
'-mcpu=mips64r2'], mc_option)
231 mc_output =
run_mc(archs[arch], code, mc_modes[(arch, mode)], mc_option)
234 if arch ==
'CS_ARCH_MIPS':
235 mc_output2 = mc_output2.replace(
' 0(',
'(')
237 if arch ==
'CS_ARCH_PPC':
238 mc_output2 = mc_output2.replace(
'.+',
'')
239 mc_output2 = mc_output2.replace(
'.',
'')
240 mc_output2 = mc_output2.replace(
' 0(',
'(')
242 mc_output2 = mc_output2.replace(
' ',
'')
243 mc_output2 = mc_output2.replace(
'opaque',
'')
246 if (cs_output2 != mc_output2):
247 asm = asm.replace(
' ',
'').
strip().lower()
248 if asm != cs_output2:
249 print(
"Mismatch: %s" %line.strip())
250 print(
"\tMC = %s" %mc_output)
251 print(
"\tCS = %s" %cs_output)
static void list(RzEgg *egg)
static int test_file(zip_t *za, zip_uint64_t idx, const char *zipname, const char *filename, zip_uint64_t size, zip_uint32_t crc)