fixed Mos65xx not included in MacOS; Add -D option to report; Add NOREGNAME while testing

This commit is contained in:
HarDToBelieve 2019-02-12 12:58:46 +07:00
parent bc7976f7b8
commit 55af82c52a
7 changed files with 109 additions and 73 deletions

View File

@ -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,0x18,0x80 = fitos %f0, %f4
0x89,0xa0,0x19,0x00 = fitod %f0, %f4 0x89,0xa0,0x19,0x00 = fitod %f0, %f4
0x89,0xa0,0x19,0x80 = fitoq %f0, %f4 0x89,0xa0,0x19,0x80 = fitoq %f0, %f4

View File

@ -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_x86(csh *handle, cs_mode mode, cs_insn *ins);
char *get_detail_xcore(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); 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); 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); char *get_detail_tms320c64x(csh *handle, cs_mode mode, cs_insn *ins);
#endif /* FACTORY_H */ #endif /* FACTORY_H */

View File

@ -136,7 +136,7 @@
!# issue 750 !# issue 750
!#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL !#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 !# issue 747
!#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL !#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL
@ -148,7 +148,7 @@
!# issue 746 !# issue 746
!#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL !#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 !# issue 744
!#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL !#CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL

View File

@ -12,14 +12,15 @@ def Usage(s):
print 'Usage: {} -t <cstest_path> [-f <file_name.cs>] [-d <directory>]'.format(s) print 'Usage: {} -t <cstest_path> [-f <file_name.cs>] [-d <directory>]'.format(s)
sys.exit(-1) sys.exit(-1)
def get_report_file(toolpath, filepath): def get_report_file(toolpath, filepath, getDetails):
cmd = [toolpath, '-f', filepath] cmd = [toolpath, '-f', filepath]
process = Popen(cmd, stdout=PIPE, stderr=PIPE) process = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate() stdout, stderr = process.communicate()
# stdout # stdout
failed_tests = [] 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) matches = re.finditer(r'\[\s+RUN\s+\]\s+(.*)\n\[\s+FAILED\s+\]', stdout)
for match in matches: for match in matches:
failed_tests.append(match.group(1)) failed_tests.append(match.group(1))
@ -31,57 +32,46 @@ def get_report_file(toolpath, filepath):
break break
elif 'LINE' in line: elif 'LINE' in line:
continue continue
elif 'ERROR' in line: elif 'ERROR' in line and ' --- ' in line:
try:
details.append((failed_tests[counter], line.split(' --- ')[1])) details.append((failed_tests[counter], line.split(' --- ')[1]))
except IndexError:
details.append(('Unknown test', line.split(' --- ')[1]))
counter += 1 counter += 1
else: else:
continue continue
# print stderr
print '\n[-] There are/is {} failed test(s)'.format(len(details)) 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) print '[-] Detailed report for {}:\n'.format(filepath)
for f, d in details: for f, d in details:
print '\t[+] {}:\n\t\t{}\n'.format(f, d) print '\t[+] {}:\n\t\t{}\n'.format(f, d)
print '\n' print '\n'
def get_report_folder(toolpath, folderpath): def get_report_folder(toolpath, folderpath, details):
cmd = [toolpath, '-d', folderpath] for root, dirs, files in os.walk(folderpath):
process = Popen(cmd, stdout=PIPE, stderr=PIPE) path = root.split(os.sep)
stdout, stderr = process.communicate() for f in files:
if f.split('.')[-1] == 'cs':
print '\n[-] Folder {}'.format(folderpath) print '[-] Target:', f,
print '[-] General information\n' get_report_file(toolpath, os.sep.join(x for x in path) + os.sep + f, details)
file_status = stdout.split('[+] TARGET: ')[1:]
for fs in file_status:
lines = fs.split('\n')
fname = lines[0]
failed_tests = []
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__': if __name__ == '__main__':
Done = False Done = False
details = False
toolpath = '' toolpath = ''
try: 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: for opt, arg in opts:
if opt == '-f': if opt == '-f':
get_report_file(toolpath, arg) get_report_file(toolpath, arg, details)
Done = True Done = True
elif opt == '-d': elif opt == '-d':
get_report_folder(toolpath, arg) get_report_folder(toolpath, arg, details)
Done = True Done = True
elif opt == '-t': elif opt == '-t':
toolpath = arg toolpath = arg
elif opt == '-D':
details = True
except getopt.GetoptError: except getopt.GetoptError:
Usage(sys.argv[0]) Usage(sys.argv[0])

View File

@ -84,15 +84,18 @@ double_dict options[] = {
char *(*function)(csh *, cs_mode, cs_insn*) = NULL; 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)) { if (strcmp(src1, des2) && strcmp(src2, des2) && strcmp(src1, des1) && strcmp(src1, des2)) {
fprintf(stderr,"[ ERROR ] --- \"%s\" != \"%s\"", src1, des); fprintf(stderr,"[ ERROR ] --- \"%s\" != \"%s\"", src1, des2);
if (strcmp(src1, src2)) 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"); fprintf(stderr, "\n");
return 0; return 0;
} }
return 1; return 1;
} }
@ -100,10 +103,11 @@ void test_single_MC(csh *handle, char *line)
{ {
char **list_part, **list_byte, **list_data; char **list_part, **list_byte, **list_data;
int size_part, size_byte, size_data, size_insn; int size_part, size_byte, size_data, size_insn;
int i, count; int i, count, count_noreg;
unsigned char *code; unsigned char *code;
cs_insn *insn; 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; char **offset_opcode;
int size_offset_opcode; int size_offset_opcode;
unsigned long offset; unsigned long offset;
@ -117,13 +121,7 @@ void test_single_MC(csh *handle, char *line)
offset = 0; offset = 0;
list_byte = split(offset_opcode[0], ",", &size_byte); list_byte = split(offset_opcode[0], ",", &size_byte);
} }
code = (unsigned char *)malloc(sizeof(char) * size_byte);
for (i=0; i<size_byte; ++i) {
code[i] = (unsigned char)strtol(list_byte[i], NULL, 16);
// printf("Byte: 0x%.2x\n", (int)code[i]);
}
count = cs_disasm(*handle, code, size_byte, offset, 0, &insn);
code = (unsigned char *)malloc(size_byte * sizeof(char)); code = (unsigned char *)malloc(size_byte * sizeof(char));
for (i=0; i<size_byte; ++i) { for (i=0; i<size_byte; ++i) {
code[i] = (unsigned char)strtol(list_byte[i], NULL, 16); code[i] = (unsigned char)strtol(list_byte[i], NULL, 16);
@ -138,25 +136,66 @@ void test_single_MC(csh *handle, char *line)
fprintf(stderr, "[ ERROR ] --- Failed to disassemble given code!\n"); fprintf(stderr, "[ ERROR ] --- Failed to disassemble given code!\n");
_fail(__FILE__, __LINE__); _fail(__FILE__, __LINE__);
} }
for (i=0; i<count; ++i) { if (count > 1) {
tmp = (char *)malloc(strlen(insn[i].mnemonic) + strlen(insn[i].op_str) + 100); fprintf(stderr, "[ ERROR ] --- Multiple instructions disassembling doesn't support!\n");
strcpy(tmp, insn[i].mnemonic);
if (strlen(insn[i].op_str) > 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__); _fail(__FILE__, __LINE__);
free(tmp);
free(tmptmp);
} }
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); cs_free(insn, count);
free(list_part); free(list_part);
free(list_byte); free(list_byte);
@ -220,9 +259,11 @@ int set_function(int arch)
case CS_ARCH_EVM: case CS_ARCH_EVM:
function = get_detail_evm; function = get_detail_evm;
break; break;
#ifndef __APPLE__
case CS_ARCH_MOS65XX: case CS_ARCH_MOS65XX:
function = get_detail_mos65xx; function = get_detail_mos65xx;
break; break;
#endif
case CS_ARCH_TMS320C64X: case CS_ARCH_TMS320C64X:
function = get_detail_tms320c64x; function = get_detail_tms320c64x;
break; break;

View File

@ -17,15 +17,17 @@ static int setup_MC(void **state)
int arch, mode; int arch, mode;
int i, index; int i, index;
if (failed_setup) if (failed_setup) {
fprintf(stderr, "[ ERROR ] --- Invalid file to setup\n");
return -1; return -1;
}
list_params = split(list_lines[0], ", ", &size_params); list_params = split(list_lines[0], ", ", &size_params);
arch = get_value(arches, NUMARCH, list_params[0]); arch = get_value(arches, NUMARCH, list_params[0]);
mode = get_value(modes, NUMMODE, list_params[1]); mode = get_value(modes, NUMMODE, list_params[1]);
if (arch == -1 || mode == -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; failed_setup = 1;
return -1; return -1;
} }
@ -37,7 +39,7 @@ static int setup_MC(void **state)
if (strcmp(list_params[i], "None")) { if (strcmp(list_params[i], "None")) {
index = get_index(options, NUMOPTION, list_params[i]); index = get_index(options, NUMOPTION, list_params[i]);
if (index == -1) { if (index == -1) {
printf("[-] Option is not supported!\n"); fprintf(stderr, "[ ERROR ] --- Option is not supported!\n");
failed_setup = 1; failed_setup = 1;
return -1; return -1;
} }
@ -84,7 +86,7 @@ static int setup_issue(void **state)
mode = get_value(modes, NUMMODE, list_params[1]); mode = get_value(modes, NUMMODE, list_params[1]);
if (arch == -1 || mode == -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; failed_setup = 1;
return -1; return -1;
} }
@ -96,14 +98,14 @@ static int setup_issue(void **state)
if (strcmp(list_params[i], "None")) { if (strcmp(list_params[i], "None")) {
index = get_index(options, NUMOPTION, list_params[i]); index = get_index(options, NUMOPTION, list_params[i]);
if (index == -1) { if (index == -1) {
printf("[-] Option is not supported!\n"); fprintf(stderr, "[ ERROR ] --- Option is not supported!\n");
failed_setup = 1; failed_setup = 1;
return -1; return -1;
} }
if (index == 0) { if (index == 0) {
result = set_function(arch); result = set_function(arch);
if (result == -1) { if (result == -1) {
printf("[-] Cannot get details\n"); fprintf(stderr, "[ ERROR ] --- Cannot get details\n");
failed_setup = 1; failed_setup = 1;
return -1; return -1;
} }

View File

@ -1,5 +1,6 @@
#include "factory.h" #include "factory.h"
#ifndef __APPLE__
static const char *get_am_name(mos65xx_address_mode mode) static const char *get_am_name(mos65xx_address_mode mode)
{ {
switch(mode) { switch(mode) {
@ -74,4 +75,4 @@ char *get_detail_mos65xx(csh *handle, cs_mode mode, cs_insn *ins)
} }
return result; return result;
} }
#endif