Done
diff --git a/suite/cstest/issues.cs b/suite/cstest/issues.cs
index d549a4a..25a1900 100644
--- a/suite/cstest/issues.cs
+++ b/suite/cstest/issues.cs
@@ -1,10 +1,10 @@
-//!# issue 0
-//!#CS_ARCH_X86, CS_MODE_64, CS_OPT_UNSIGNED
-//0x66,0x83,0xc0,0x80 == add ax, 0xff80
+// !# issue 0
+// !#CS_ARCH_X86, CS_MODE_64, CS_OPT_UNSIGNED
+// 0x66,0x83,0xc0,0x80 == add ax, 0xff80
-//!# issue 0
-//!#CS_ARCH_X86, CS_MODE_64, CS_OPT_SYNTAX_ATT | CS_OPT_UNSIGNED
-//0x66,0x83,0xc0,0x80 == addw $0xff80, %ax
+// !# issue 0
+// !#CS_ARCH_X86, CS_MODE_64, CS_OPT_SYNTAX_ATT | CS_OPT_UNSIGNED
+// 0x66,0x83,0xc0,0x80 == addw $0xff80, %ax
!# issue 1323
!#CS_ARCH_ARM, CS_MODE_THUMB, CS_OPT_DETAIL
diff --git a/suite/cstest/report.py b/suite/cstest/report.py
index c2c6504..a7cd285 100755
--- a/suite/cstest/report.py
+++ b/suite/cstest/report.py
@@ -49,18 +49,23 @@
if len(f) > 0 and cmt_out is True:
tmp_cmd = ['sed', '-E', '-i.bak', 's/({})(.*)/\/\/ \\1\\2/g'.format(c), filepath]
sed_proc = Popen(tmp_cmd, stdout=PIPE, stderr=PIPE)
- sed_out, sed_err = sed_proc.communicate()
- print sed_out
- print sed_err
+ sed_proc.communicate()
print '\n'
+ return 0
+ elif len(details) > 0:
+ return 0;
+ return 1
def get_report_folder(toolpath, folderpath, details, cmt_out):
+ result = 1
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, cmt_out)
+ result *= get_report_file(toolpath, os.sep.join(x for x in path) + os.sep + f, details, cmt_out)
+
+ sys.exit(result ^ 1)
if __name__ == '__main__':
Done = False
@@ -68,7 +73,7 @@
toolpath = ''
cmt_out = False
try:
- opts, args = getopt.getopt(sys.argv[1:], "c:t:f:d:D")
+ opts, args = getopt.getopt(sys.argv[1:], "ct:f:d:D")
for opt, arg in opts:
if opt == '-f':
get_report_file(toolpath, arg, details, cmt_out)
@@ -80,7 +85,7 @@
toolpath = arg
elif opt == '-D':
details = True
- elif opt == 'c':
+ elif opt == '-c':
cmt_out = True
except getopt.GetoptError:
diff --git a/suite/cstest/src/capstone_test.c b/suite/cstest/src/capstone_test.c
index caa94ad..e6110d5 100644
--- a/suite/cstest/src/capstone_test.c
+++ b/suite/cstest/src/capstone_test.c
@@ -117,7 +117,8 @@
{"CS_MODE_M680X_6809", CS_OPT_MODE, CS_MODE_M680X_6809},
{"CS_MODE_M680X_6811", CS_OPT_MODE, CS_MODE_M680X_6811},
{"CS_MODE_M680X_CPU12", CS_OPT_MODE, CS_MODE_M680X_CPU12},
- {"CS_MODE_M680X_HCS08", CS_OPT_MODE, CS_MODE_M680X_HCS08}
+ {"CS_MODE_M680X_HCS08", CS_OPT_MODE, CS_MODE_M680X_HCS08},
+ {"CS_OPT_UNSIGNED", CS_OPT_ON, CS_OPT_UNSIGNED}
};
char *(*function)(csh *, cs_mode, cs_insn*) = NULL;
@@ -166,7 +167,6 @@
code[i] = (unsigned char)strtol(list_byte[i], NULL, 16);
// printf("Byte: 0x%.2x\n", (int)code[i]);
}
- cs_option(*handle, CS_OPT_UNSIGNED, CS_OPT_ON);
// list_data = split(list_part[1], ";", &size_data);
count = cs_disasm(*handle, code, size_byte, offset, 0, &insn);
diff --git a/suite/cstest/src/main.c b/suite/cstest/src/main.c
index a02a3e0..e13ca63 100644
--- a/suite/cstest/src/main.c
+++ b/suite/cstest/src/main.c
@@ -9,7 +9,7 @@
static cs_mode issue_mode;
static int getDetail;
static int mc_mode;
-static char delim;
+static int e_flag;
static int setup_MC(void **state)
{
@@ -25,9 +25,14 @@
}
tmp_counter = 0;
- while (tmp_counter < size_lines && list_lines[tmp_counter][0] != '#') tmp_counter++; // get issue line
+ while (tmp_counter < size_lines && list_lines[tmp_counter][0] != '#') tmp_counter++;
list_params = split(list_lines[tmp_counter] + 2, ", ", &size_params);
+ if (size_params != 3) {
+ fprintf(stderr, "[ ERROR ] --- Invalid options ( arch, mode, option )\n");
+ failed_setup = 1;
+ return -1;
+ }
arch = get_value(arches, NUMARCH, list_params[0]);
if (!strcmp(list_params[0], "CS_ARCH_ARM64")) mc_mode = 2;
else mc_mode = 1;
@@ -52,28 +57,37 @@
}
}
- if (arch == -1 || mode == -1) {
- fprintf(stderr, "[ ERROR ] --- Arch and/or Mode are not supported!\n");
+ if (arch == -1) {
+ fprintf(stderr, "[ ERROR ] --- Arch is not supported!\n");
failed_setup = 1;
return -1;
}
handle = (csh *)malloc(sizeof(csh));
- cs_open(arch, mode, handle);
- for (i=2; i < size_params; ++i)
- if (strcmp(list_params[i], "None")) {
- index = get_index(options, NUMOPTION, list_params[i]);
- if (index == -1) {
- fprintf(stderr, "[ ERROR ] --- Option is not supported!\n");
+ if(cs_open(arch, mode, handle) != CS_ERR_OK) {
+ fprintf(stderr, "[ ERROR ] --- Cannot initialize capstone\n");
+ failed_setup = 1;
+ return -1;
+ }
+
+ for (i=0; i<NUMOPTION; ++i) {
+ if (strstr(list_params[2], options[i].str)) {
+ if (cs_option(*handle, options[i].first_value, options[i].second_value) != CS_ERR_OK) {
+ fprintf(stderr, "[ ERROR ] --- Option is not supported for this arch/mode\n");
failed_setup = 1;
return -1;
}
- cs_option(*handle, options[index].first_value, options[index].second_value);
}
+ }
+
*state = (void *)handle;
counter++;
- while (counter < size_lines && list_lines[counter][0] != delim) counter++;
+ if (e_flag == 0)
+ while (counter < size_lines && strncmp(list_lines[counter], "0x", 2)) counter++;
+ else
+ while (counter < size_lines && strncmp(list_lines[counter], "// 0x", 5)) counter++;
+
free_strs(list_params, size_params);
return 0;
@@ -81,7 +95,10 @@
static void test_MC(void **state)
{
- test_single_MC((csh *)*state, mc_mode, list_lines[counter]);
+ if (e_flag == 1)
+ test_single_MC((csh *)*state, mc_mode, list_lines[counter] + 3);
+ else
+ test_single_MC((csh *)*state, mc_mode, list_lines[counter]);
}
static int teardown_MC(void **state)
@@ -103,10 +120,24 @@
getDetail = 0;
failed_setup = 0;
- while (counter < size_lines && list_lines[counter][0] != '!') counter++; // get issue line
+ if (e_flag == 0)
+ while (counter < size_lines && strncmp(list_lines[counter], "!# ", 3)) counter++; // get issue line
+ else
+ while (counter < size_lines && strncmp(list_lines[counter], "// !#", 5)) counter++;
+
counter++;
- while (counter < size_lines && list_lines[counter][0] != '!') counter++; // get arch/mode line
- list_params = split(list_lines[counter] + 2, ", ", &size_params);
+
+
+ if (e_flag == 0)
+ while (counter < size_lines && strncmp(list_lines[counter], "!#", 2)) counter++; // get arch line
+ else
+ while (counter < size_lines && strncmp(list_lines[counter], "// !#", 5)) counter++;
+
+ if (e_flag == 0)
+ list_params = split(list_lines[counter] + 2, ", ", &size_params);
+ else
+ list_params = split(list_lines[counter] + 5, ", ", &size_params);
+
// print_strs(list_params, size_params);
arch = get_value(arches, NUMARCH, list_params[0]);
@@ -133,24 +164,28 @@
}
}
- if (arch == -1 || mode == -1) {
- fprintf(stderr, "[ ERROR ] --- Arch and/or Mode are not supported!\n");
+ if (arch == -1) {
+ fprintf(stderr, "[ ERROR ] --- Arch is not supported!\n");
failed_setup = 1;
return -1;
}
handle = (csh *)calloc(1, sizeof(csh));
- cs_open(arch, mode, handle);
- for (i=2; i < size_params; ++i) {
- if (strcmp(list_params[i], "None")) {
- index = get_index(options, NUMOPTION, list_params[i]);
- if (index == -1) {
- fprintf(stderr, "[ ERROR ] --- Option is not supported!\n");
+ if(cs_open(arch, mode, handle) != CS_ERR_OK) {
+ fprintf(stderr, "[ ERROR ] --- Cannot initialize capstone\n");
+ failed_setup = 1;
+ return -1;
+ }
+
+ for (i=0; i<NUMOPTION; ++i) {
+ if (strstr(list_params[2], options[i].str)) {
+ if (cs_option(*handle, options[i].first_value, options[i].second_value) != CS_ERR_OK) {
+ fprintf(stderr, "[ ERROR ] --- Option is not supported for this arch/mode\n");
failed_setup = 1;
return -1;
}
- if (index == 0) {
+ if (i == 0) {
result = set_function(arch);
if (result == -1) {
fprintf(stderr, "[ ERROR ] --- Cannot get details\n");
@@ -159,14 +194,17 @@
}
getDetail = 1;
}
- cs_option(*handle, options[index].first_value, options[index].second_value);
}
}
*state = (void *)handle;
issue_mode = mode;
- while (counter < size_lines && list_lines[counter][0] != '0') counter ++;
+ if (e_flag == 0)
+ while (counter < size_lines && strncmp(list_lines[counter], "0x", 2)) counter++;
+ else
+ while (counter < size_lines && strncmp(list_lines[counter], "// 0x", 5)) counter++;
+
free_strs(list_params, size_params);
return 0;
@@ -174,14 +212,20 @@
static void test_issue(void **state)
{
- test_single_issue((csh *)*state, issue_mode, list_lines[counter], getDetail);
+ if (e_flag == 0)
+ test_single_issue((csh *)*state, issue_mode, list_lines[counter], getDetail);
+ else
+ test_single_issue((csh *)*state, issue_mode, list_lines[counter] + 3, getDetail);
// counter ++;
return;
}
static int teardown_issue(void **state)
{
- while (counter < size_lines && list_lines[counter][0] != '!') counter++; // get next issue
+ if (e_flag == 0)
+ while (counter < size_lines && strncmp(list_lines[counter], "!# ", 3)) counter++;
+ else
+ while (counter < size_lines && strncmp(list_lines[counter], "// !#", 5)) counter++;
cs_close(*state);
free(*state);
function = NULL;
@@ -208,14 +252,15 @@
// tests = (struct CMUnitTest *)malloc(sizeof(struct CMUnitTest) * size_lines / 3);
tests = NULL;
for (i=0; i < size_lines; ++i) {
- if (strstr(list_lines[i], "!# issue")) {
+ if ((!strncmp(list_lines[i], "// !# issue", 11) && e_flag == 1) ||
+ (!strncmp(list_lines[i], "!# issue", 8) && e_flag == 0)) {
// tmp = (char *)malloc(sizeof(char) * 100);
// sscanf(list_lines[i], "!# issue %d\n", &issue_num);
// sprintf(tmp, "Issue #%d", issue_num);
tests = (struct CMUnitTest *)realloc(tests, sizeof(struct CMUnitTest) * (number_of_tests + 1));
tests[number_of_tests] = (struct CMUnitTest)cmocka_unit_test_setup_teardown(test_issue, setup_issue, teardown_issue);
// tests[number_of_tests].name = tmp;
- tests[number_of_tests].name, strdup(list_lines[i]);
+ tests[number_of_tests].name = strdup(list_lines[i]);
number_of_tests ++;
}
}
@@ -228,7 +273,7 @@
tests = NULL;
// tests = (struct CMUnitTest *)malloc(sizeof(struct CMUnitTest) * (size_lines - 1));
for (i = 1; i < size_lines; ++i) {
- if (list_lines[i][0] == delim) {
+ if ((!strncmp(list_lines[i], "// 0x", 5) && e_flag == 1) || (!strncmp(list_lines[i], "0x", 2) && e_flag == 0)) {
tmp = (char *)malloc(sizeof(char) * 100);
sprintf(tmp, "Line %d", i+1);
tests = (struct CMUnitTest *)realloc(tests, sizeof(struct CMUnitTest) * (number_of_tests + 1));
@@ -266,7 +311,7 @@
int opt, flag;
flag = 0;
- delim = '0';
+ e_flag = 0;
while ((opt = getopt(argc, argv, "ef:d:")) > 0) {
switch (opt) {
@@ -279,8 +324,7 @@
flag = 1;
break;
case 'e':
- puts("HAHAHAHA");
- delim = '/';
+ e_flag = 1;
break;
default:
printf("Usage: %s [-f <file_name.cs>] [-d <directory>]\n", argv[0]);