diff --git a/suite/MC/Sparc/sparc-fp-instructions.s.cs b/suite/MC/Sparc/sparc-fp-instructions.s.cs index 276357b2..ee30d428 100644 --- a/suite/MC/Sparc/sparc-fp-instructions.s.cs +++ b/suite/MC/Sparc/sparc-fp-instructions.s.cs @@ -1,4 +1,4 @@ -# CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN + CS_MODE_V9, None +# CS_ARCH_SPARC, CS_MODE_BIG_ENDIAN+CS_MODE_V9, None 0x89,0xa0,0x18,0x80 = fitos %f0, %f4 0x89,0xa0,0x19,0x00 = fitod %f0, %f4 0x89,0xa0,0x19,0x80 = fitoq %f0, %f4 diff --git a/suite/cstest/include/factory.h b/suite/cstest/include/factory.h index b950e754..cfc2c524 100644 --- a/suite/cstest/include/factory.h +++ b/suite/cstest/include/factory.h @@ -15,7 +15,9 @@ char *get_detail_sysz(csh *handle, cs_mode mode, cs_insn *ins); char *get_detail_x86(csh *handle, cs_mode mode, cs_insn *ins); char *get_detail_xcore(csh *handle, cs_mode mode, cs_insn *ins); char *get_detail_m68k(csh *handle, cs_mode mode, cs_insn *ins); +#ifndef __APPLE__ char *get_detail_mos65xx(csh *handle, cs_mode mode, cs_insn *ins); +#endif char *get_detail_tms320c64x(csh *handle, cs_mode mode, cs_insn *ins); #endif /* FACTORY_H */ diff --git a/suite/cstest/issues.cs b/suite/cstest/issues.cs index b0ab8773..bcaded11 100644 --- a/suite/cstest/issues.cs +++ b/suite/cstest/issues.cs @@ -136,7 +136,7 @@ !# issue 750 !#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL -0x0: 0x0e,0x00,0x20,0xe9 == stmdb r0!, {r1, r2, r3} ; op_count: 4 ; operands[0].type: REG = r0 ; operands[0].access: READ ; operands[1].type: REG = r1 ; operands[2].type: REG = r2 ; operands[3].type: REG = r3 ; Write-back: True ; Registers read: r0 ; Groups: arm +0x0: 0x0e,0x00,0x20,0xe9 == stmdb r0!, {r1, r2, r3} ; op_count: 4 ; operands[0].type: REG = r0 ; operands[0].access: READ | WRITE ; operands[1].type: REG = r1 ; operands[1].access: READ ; operands[2].type: REG = r2 ; operands[2].access: READ ; operands[3].type: REG = r3 ; operands[3].access: READ ; Write-back: True ; Registers read: r0 r1 r2 r3 ; Registers modified: r0 ; Groups: arm !# issue 747 !#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL @@ -148,7 +148,7 @@ !# issue 746 !#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL -0x0: 0x89,0x00,0x2d,0xe9 == push {r0, r3, r7} ; op_count: 3 ; operands[0].type: REG = r0 ; operands[0].access: READ ; operands[1].type: REG = r3 ; operands[1].access: READ ; operands[2].type: REG = r7 ; operands[2].access: READ ; Registers read: sp r0 r3 r7 ; Registers modified: sp ; Groups: arm +0x0: 0x89,0x00,0x2d,0xe9 == push {r0, r3, r7} ; op_count: 3 ; operands[0].type: REG = r0 ; operands[0].access: READ | WRITE ; operands[1].type: REG = r3 ; operands[1].access: READ | WRITE ; operands[2].type: REG = r7 ; operands[2].access: READ | WRITE ; Registers read: sp r0 r3 r7 ; Registers modified: sp r0 r3 r7 ; Groups: arm !# issue 744 !#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL diff --git a/suite/cstest/report.py b/suite/cstest/report.py index 20feebe7..8db56f28 100755 --- a/suite/cstest/report.py +++ b/suite/cstest/report.py @@ -12,14 +12,15 @@ def Usage(s): print 'Usage: {} -t [-f ] [-d ]'.format(s) sys.exit(-1) -def get_report_file(toolpath, filepath): +def get_report_file(toolpath, filepath, getDetails): cmd = [toolpath, '-f', filepath] process = Popen(cmd, stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() # stdout failed_tests = [] -# print stdout +# print '---> stdout\n', stdout +# print '---> stderr\n', stderr matches = re.finditer(r'\[\s+RUN\s+\]\s+(.*)\n\[\s+FAILED\s+\]', stdout) for match in matches: failed_tests.append(match.group(1)) @@ -31,57 +32,46 @@ def get_report_file(toolpath, filepath): break elif 'LINE' in line: continue - elif 'ERROR' in line: - details.append((failed_tests[counter], line.split(' --- ')[1])) + elif 'ERROR' in line and ' --- ' in line: + try: + details.append((failed_tests[counter], line.split(' --- ')[1])) + except IndexError: + details.append(('Unknown test', line.split(' --- ')[1])) counter += 1 else: continue -# print stderr print '\n[-] There are/is {} failed test(s)'.format(len(details)) - if len(details) > 0: + if len(details) > 0 and getDetails: print '[-] Detailed report for {}:\n'.format(filepath) for f, d in details: print '\t[+] {}:\n\t\t{}\n'.format(f, d) print '\n' -def get_report_folder(toolpath, folderpath): - cmd = [toolpath, '-d', folderpath] - process = Popen(cmd, stdout=PIPE, stderr=PIPE) - stdout, stderr = process.communicate() - - print '\n[-] Folder {}'.format(folderpath) - print '[-] General information\n' - file_status = stdout.split('[+] TARGET: ')[1:] - - for fs in file_status: - lines = fs.split('\n') - fname = lines[0] - failed_tests = [] +def get_report_folder(toolpath, folderpath, details): + for root, dirs, files in os.walk(folderpath): + path = root.split(os.sep) + for f in files: + if f.split('.')[-1] == 'cs': + print '[-] Target:', f, + get_report_file(toolpath, os.sep.join(x for x in path) + os.sep + f, details) - matches = re.finditer(r'\[\s+RUN\s+\] (.*)\n\[\s+FAILED\s+\]', '\n'.join(x for x in lines[1:])) - for match in matches: - failed_tests.append(match.group(1)) - - if len(failed_tests) > 0: - print '\tFile {}:\n'.format(os.path.basename(fname)) - for ft in failed_tests: - print '\t\tError in {} --- Path: {}'.format(ft.lower(), fname) - print '\n\n' - if __name__ == '__main__': Done = False + details = False toolpath = '' try: - opts, args = getopt.getopt(sys.argv[1:], "t:f:d:") + opts, args = getopt.getopt(sys.argv[1:], "t:f:d:D") for opt, arg in opts: if opt == '-f': - get_report_file(toolpath, arg) + get_report_file(toolpath, arg, details) Done = True elif opt == '-d': - get_report_folder(toolpath, arg) + get_report_folder(toolpath, arg, details) Done = True elif opt == '-t': toolpath = arg + elif opt == '-D': + details = True except getopt.GetoptError: Usage(sys.argv[0]) diff --git a/suite/cstest/src/capstone_test.c b/suite/cstest/src/capstone_test.c index 33bf1693..ddadbc1c 100644 --- a/suite/cstest/src/capstone_test.c +++ b/suite/cstest/src/capstone_test.c @@ -84,15 +84,18 @@ double_dict options[] = { char *(*function)(csh *, cs_mode, cs_insn*) = NULL; -static int triple_compare(const char *src1, const char *src2, const char *des) +static int quadruple_compare(const char *src1, const char *src2, const char *des1, const char *des2) { - if (strcmp(src1, des) && strcmp(src2, des)) { - fprintf(stderr,"[ ERROR ] --- \"%s\" != \"%s\"", src1, des); + if (strcmp(src1, des2) && strcmp(src2, des2) && strcmp(src1, des1) && strcmp(src1, des2)) { + fprintf(stderr,"[ ERROR ] --- \"%s\" != \"%s\"", src1, des2); if (strcmp(src1, src2)) - fprintf(stderr, " (\"%s\" != \"%s\")", src2, des); + fprintf(stderr, " (\"%s\" != \"%s\")", src2, des2); + else if (strcmp(des1, des2)) + fprintf(stderr, " (\"%s\" != \"%s\")", src1, des1); fprintf(stderr, "\n"); return 0; } + return 1; } @@ -100,10 +103,11 @@ void test_single_MC(csh *handle, char *line) { char **list_part, **list_byte, **list_data; int size_part, size_byte, size_data, size_insn; - int i, count; + int i, count, count_noreg; unsigned char *code; cs_insn *insn; - char *tmp, *tmptmp; + char *tmp, *cs_hex, *mc_hex, *mc_dec; + char *tmp_noreg, *cs_hex_noreg, *mc_hex_noreg, *mc_dec_noreg; char **offset_opcode; int size_offset_opcode; unsigned long offset; @@ -117,13 +121,7 @@ void test_single_MC(csh *handle, char *line) offset = 0; list_byte = split(offset_opcode[0], ",", &size_byte); } - code = (unsigned char *)malloc(sizeof(char) * size_byte); - for (i=0; i 0) { - tmp[strlen(insn[i].mnemonic)] = ' '; - strcpy(tmp + strlen(insn[i].mnemonic) + 1, insn[i].op_str); - } - // printf("--------\nCapstone: %s\nUser: %s\n", tmp, list_data[i]); - tmptmp = strdup(tmp); - replace_hex(&tmp); - // assert_string_equal(tmp, list_data[i]); - trim_str(&tmp); - trim_str(&tmptmp); - trim_str(&list_data[i]); - if (!triple_compare(tmp, tmptmp, list_data[i])) - _fail(__FILE__, __LINE__); - free(tmp); - free(tmptmp); + if (count > 1) { + fprintf(stderr, "[ ERROR ] --- Multiple instructions disassembling doesn't support!\n"); + _fail(__FILE__, __LINE__); } + + trim_str(&list_data[0]); + + tmp = (char *)malloc(strlen(insn[0].mnemonic) + strlen(insn[0].op_str) + 100); + strcpy(tmp, insn[0].mnemonic); + if (strlen(insn[0].op_str) > 0) { + tmp[strlen(insn[0].mnemonic)] = ' '; + strcpy(tmp + strlen(insn[0].mnemonic) + 1, insn[0].op_str); + } + trim_str(&tmp); +// printf("--------\nCapstone: %s\nUser: %s\n", tmp, list_data[0]); + cs_hex = strdup(tmp); + replace_hex(&tmp); + mc_hex = strdup(list_data[0]); + mc_dec = strdup(list_data[0]); + replace_hex(&mc_dec); + // assert_string_equal(tmp, list_data[i]); + + + if ( cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME) == CS_ERR_OK ) { + count_noreg = cs_disasm(*handle, code, size_byte, offset, 0, &insn); + tmp_noreg = (char *)malloc(strlen(insn[0].mnemonic) + strlen(insn[0].op_str) + 100); + strcpy(tmp_noreg, insn[0].mnemonic); + if (strlen(insn[i].op_str) > 0) { + tmp_noreg[strlen(insn[0].mnemonic)] = ' '; + strcpy(tmp_noreg + strlen(insn[0].mnemonic) + 1, insn[0].op_str); + } + + trim_str(&tmp_noreg); + cs_hex_noreg = strdup(tmp_noreg); + replace_hex(&tmp_noreg); + mc_hex_noreg = strdup(list_data[0]); + mc_dec_noreg = strdup(list_data[0]); + replace_hex(&mc_dec_noreg); + + if (strcmp(tmp, mc_hex) && strcmp(cs_hex, mc_hex) && strcmp(tmp, mc_dec) && strcmp(tmp, mc_hex) + && strcmp(tmp_noreg, mc_hex_noreg) && strcmp(cs_hex_noreg, mc_hex_noreg) && strcmp(tmp_noreg, mc_dec_noreg) && strcmp(tmp_noreg, mc_hex_noreg)) { + fprintf(stderr, "[ ERROR ] --- \"%s\" != \"%s\"\n", tmp, list_data[0]); + _fail(__FILE__, __LINE__); + } + + free(tmp_noreg); + free(cs_hex_noreg); + free(mc_hex_noreg); + free(mc_dec_noreg); + + cs_option(*handle, CS_OPT_SYNTAX, 0); + } + else if (!quadruple_compare(tmp, cs_hex, mc_dec, mc_hex)) + _fail(__FILE__, __LINE__); + + free(tmp); + free(cs_hex); + free(mc_hex); + free(mc_dec); + cs_free(insn, count); free(list_part); free(list_byte); @@ -220,9 +259,11 @@ int set_function(int arch) case CS_ARCH_EVM: function = get_detail_evm; break; +#ifndef __APPLE__ case CS_ARCH_MOS65XX: function = get_detail_mos65xx; break; +#endif case CS_ARCH_TMS320C64X: function = get_detail_tms320c64x; break; diff --git a/suite/cstest/src/main.c b/suite/cstest/src/main.c index fdbc8298..ca0a26e8 100644 --- a/suite/cstest/src/main.c +++ b/suite/cstest/src/main.c @@ -17,15 +17,17 @@ static int setup_MC(void **state) int arch, mode; int i, index; - if (failed_setup) + if (failed_setup) { + fprintf(stderr, "[ ERROR ] --- Invalid file to setup\n"); return -1; + } list_params = split(list_lines[0], ", ", &size_params); arch = get_value(arches, NUMARCH, list_params[0]); mode = get_value(modes, NUMMODE, list_params[1]); if (arch == -1 || mode == -1) { - printf("[-] Arch and/or Mode are not supported!\n"); + fprintf(stderr, "[ ERROR ] --- Arch and/or Mode are not supported!\n"); failed_setup = 1; return -1; } @@ -37,7 +39,7 @@ static int setup_MC(void **state) if (strcmp(list_params[i], "None")) { index = get_index(options, NUMOPTION, list_params[i]); if (index == -1) { - printf("[-] Option is not supported!\n"); + fprintf(stderr, "[ ERROR ] --- Option is not supported!\n"); failed_setup = 1; return -1; } @@ -84,7 +86,7 @@ static int setup_issue(void **state) mode = get_value(modes, NUMMODE, list_params[1]); if (arch == -1 || mode == -1) { - printf("[-] Arch and/or Mode are not supported!\n"); + fprintf(stderr, "[ ERROR ] --- Arch and/or Mode are not supported!\n"); failed_setup = 1; return -1; } @@ -96,18 +98,18 @@ static int setup_issue(void **state) if (strcmp(list_params[i], "None")) { index = get_index(options, NUMOPTION, list_params[i]); if (index == -1) { - printf("[-] Option is not supported!\n"); + fprintf(stderr, "[ ERROR ] --- Option is not supported!\n"); failed_setup = 1; return -1; } if (index == 0) { result = set_function(arch); if (result == -1) { - printf("[-] Cannot get details\n"); + fprintf(stderr, "[ ERROR ] --- Cannot get details\n"); failed_setup = 1; return -1; } - getDetail = 1; + getDetail = 1; } cs_option(*handle, options[index].first_value, options[index].second_value); } diff --git a/suite/cstest/src/mos65xx_detail.c b/suite/cstest/src/mos65xx_detail.c index 46f8d10d..6544f76d 100644 --- a/suite/cstest/src/mos65xx_detail.c +++ b/suite/cstest/src/mos65xx_detail.c @@ -1,5 +1,6 @@ #include "factory.h" +#ifndef __APPLE__ static const char *get_am_name(mos65xx_address_mode mode) { switch(mode) { @@ -74,4 +75,4 @@ char *get_detail_mos65xx(csh *handle, cs_mode mode, cs_insn *ins) } return result; } - +#endif