@ -12,6 +12,7 @@ single_dict arches[] = {
{ " CS_ARCH_M68K " , CS_ARCH_M68K }
} ;
/*
single_dict modes [ ] = {
{ " CS_MODE_16 " , CS_MODE_16 } ,
{ " CS_MODE_32 " , CS_MODE_32 } ,
@ -38,6 +39,43 @@ single_dict modes[] = {
{ " CS_MODE_MIPS64+CS_MODE_BIG_ENDIAN " , CS_MODE_MIPS64 + CS_MODE_BIG_ENDIAN } ,
{ " CS_MODE_THUMB | CS_MODE_BIG_ENDIAN " , CS_MODE_THUMB | CS_MODE_BIG_ENDIAN }
} ;
*/
single_dict modes [ ] = {
{ " CS_MODE_LITTLE_ENDIAN " , CS_MODE_LITTLE_ENDIAN } ,
{ " CS_MODE_ARM " , CS_MODE_ARM } ,
{ " CS_MODE_16 " , CS_MODE_16 } ,
{ " CS_MODE_32 " , CS_MODE_32 } ,
{ " CS_MODE_64 " , CS_MODE_64 } ,
{ " CS_MODE_THUMB " , CS_MODE_THUMB } ,
{ " CS_MODE_MCLASS " , CS_MODE_MCLASS } ,
{ " CS_MODE_V8 " , CS_MODE_V8 } ,
{ " CS_MODE_MICRO " , CS_MODE_MICRO } ,
{ " CS_MODE_MIPS3 " , CS_MODE_MIPS3 } ,
{ " CS_MODE_MIPS32R6 " , CS_MODE_MIPS32R6 } ,
{ " CS_MODE_MIPS2 " , CS_MODE_MIPS2 } ,
{ " CS_MODE_V9 " , CS_MODE_V9 } ,
{ " CS_MODE_QPX " , CS_MODE_QPX } ,
{ " CS_MODE_M68K_000 " , CS_MODE_M68K_000 } ,
{ " CS_MODE_M68K_010 " , CS_MODE_M68K_010 } ,
{ " CS_MODE_M68K_020 " , CS_MODE_M68K_020 } ,
{ " CS_MODE_M68K_030 " , CS_MODE_M68K_030 } ,
{ " CS_MODE_M68K_040 " , CS_MODE_M68K_040 } ,
{ " CS_MODE_M68K_060 " , CS_MODE_M68K_060 } ,
{ " CS_MODE_BIG_ENDIAN " , CS_MODE_BIG_ENDIAN } ,
{ " CS_MODE_MIPS32 " , CS_MODE_MIPS32 } ,
{ " CS_MODE_MIPS64 " , CS_MODE_MIPS64 } ,
{ " CS_MODE_M680X_6301 " , CS_MODE_M680X_6301 } ,
{ " CS_MODE_M680X_6309 " , CS_MODE_M680X_6309 } ,
{ " CS_MODE_M680X_6800 " , CS_MODE_M680X_6800 } ,
{ " CS_MODE_M680X_6801 " , CS_MODE_M680X_6801 } ,
{ " CS_MODE_M680X_6805 " , CS_MODE_M680X_6805 } ,
{ " CS_MODE_M680X_6808 " , CS_MODE_M680X_6808 } ,
{ " CS_MODE_M680X_6809 " , CS_MODE_M680X_6809 } ,
{ " CS_MODE_M680X_6811 " , CS_MODE_M680X_6811 } ,
{ " CS_MODE_M680X_CPU12 " , CS_MODE_M680X_CPU12 } ,
{ " CS_MODE_M680X_HCS08 " , CS_MODE_M680X_HCS08 }
} ;
double_dict options [ ] = {
{ " CS_OPT_DETAIL " , CS_OPT_DETAIL , CS_OPT_ON } ,
@ -79,7 +117,8 @@ double_dict options[] = {
{ " 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 ;
@ -106,7 +145,7 @@ void test_single_MC(csh *handle, int mc_mode, char *line)
int i , count , count_noreg ;
unsigned char * code ;
cs_insn * insn ;
char tmp [ MAXMEM ] , cs_hex [ MAXMEM ] , mc_hex [ MAXMEM ] , mc_dec [ MAXMEM ] ;
char tmp [ MAXMEM ] , cs_hex [ MAXMEM ] , mc_hex [ MAXMEM ] , mc_dec [ MAXMEM ] , tmp_mc [ MAXMEM ] ;
char tmp_noreg [ MAXMEM ] , cs_hex_noreg [ MAXMEM ] , mc_hex_noreg [ MAXMEM ] , mc_dec_noreg [ MAXMEM ] ;
char * * offset_opcode ;
int size_offset_opcode ;
@ -126,34 +165,34 @@ void test_single_MC(csh *handle, int mc_mode, char *line)
code = ( unsigned char * ) malloc ( size_byte * sizeof ( char ) ) ;
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]);
// 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 ) ;
if ( count = = 0 ) {
fprintf ( stderr , " [ ERROR ] --- %s --- Failed to disassemble given code! \n " , list_part [ 0 ] ) ;
free ( list_part ) ;
free ( offset_opcode ) ;
free ( list_byte ) ;
free_strs ( list_part , size _part ) ;
free_strs ( offset_opcode , size_ offset_opcode) ;
free_strs ( list_byte , size _byte ) ;
free ( code ) ;
// free(list_data);
// free(list_data);
_fail ( __FILE__ , __LINE__ ) ;
}
if ( count > 1 ) {
fprintf ( stderr , " [ ERROR ] --- %s --- Multiple instructions(%d) disassembling doesn't support! \n " , list_part [ 0 ] , count ) ;
free ( list_part ) ;
free ( offset_opcode ) ;
free ( list_byte ) ;
free_strs ( list_part , size _part ) ;
free_strs ( offset_opcode , size_ offset_opcode) ;
free_strs ( list_byte , size _byte ) ;
free ( code ) ;
// free(list_data);
// free(list_data);
_fail ( __FILE__ , __LINE__ ) ;
}
for ( p = list_part [ 1 ] ; * p ; + + p ) * p = tolower ( * p ) ;
trim_str ( list_part [ 1 ] ) ;
// replace_negative(list_part[1], mc_mode);
strcpy ( tmp_mc , list_part [ 1 ] ) ;
replace_negative ( tmp_mc , mc_mode ) ;
// tmp = (char *)malloc(strlen(insn[0].mnemonic) + strlen(insn[0].op_str) + 100);
strcpy ( tmp , insn [ 0 ] . mnemonic ) ;
@ -166,10 +205,11 @@ void test_single_MC(csh *handle, int mc_mode, char *line)
// cs_hex = strdup(tmp);
strcpy ( cs_hex , tmp ) ;
replace_hex ( tmp ) ;
// replace_negative(tmp, mc_mode);
// mc_hex = strdup(list_data[0]);
// mc_dec = strdup(list_data[0]);
strcpy ( mc_hex , list_part [ 1 ] ) ;
strcpy ( mc_dec , list_part [ 1 ] ) ;
strcpy ( mc_hex , tmp_mc ) ;
strcpy ( mc_dec , tmp_mc ) ;
replace_hex ( mc_dec ) ;
if ( cs_option ( * handle , CS_OPT_SYNTAX , CS_OPT_SYNTAX_NOREGNAME ) = = CS_ERR_OK ) {
@ -186,16 +226,17 @@ void test_single_MC(csh *handle, int mc_mode, char *line)
strcpy ( cs_hex_noreg , tmp_noreg ) ;
replace_hex ( tmp_noreg ) ;
// mc_dec_noreg = strdup(list_data[0]);
strcpy ( mc_hex_noreg , list_part [ 1 ] ) ;
strcpy ( mc_dec_noreg , list_part [ 1 ] ) ;
strcpy ( mc_hex_noreg , tmp_mc ) ;
strcpy ( mc_dec_noreg , tmp_mc ) ;
replace_hex ( mc_dec_noreg ) ;
// replace_negative(mc_dec_noreg, mc_mode);
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 \" != \" %s \" \n " , list_part [ 0 ] , cs_hex , list_part [ 1 ] ) ;
free ( list_part ) ;
free ( offset_opcode ) ;
free ( list_byte ) ;
free_strs ( list_part , size _part ) ;
free_strs ( offset_opcode , size_ offset_opcode) ;
free_strs ( list_byte , size _byte ) ;
free ( code ) ;
// free(list_data);
cs_free ( insn , count ) ;
@ -204,18 +245,18 @@ void test_single_MC(csh *handle, int mc_mode, char *line)
cs_option ( * handle , CS_OPT_SYNTAX , 0 ) ;
} else if ( ! quadruple_compare ( tmp , cs_hex , mc_dec , mc_hex , list_part [ 0 ] ) ) {
free ( list_part ) ;
free ( offset_opcode ) ;
free ( list_byte ) ;
free_strs ( list_part , size _part ) ;
free_strs ( offset_opcode , size_ offset_opcode) ;
free_strs ( list_byte , size _byte ) ;
free ( code ) ;
// free(list_data);
cs_free ( insn , count ) ;
_fail ( __FILE__ , __LINE__ ) ;
}
free ( list_part ) ;
free ( offset_opcode ) ;
free ( list_byte ) ;
free_strs ( list_part , size _part ) ;
free_strs ( offset_opcode , size_ offset_opcode) ;
free_strs ( list_byte , size _byte ) ;
free ( code ) ;
// free(list_data);
cs_free ( insn , count ) ;
@ -352,6 +393,12 @@ void test_single_issue(csh *handle, cs_mode mode, char *line, int detail)
if ( size_part_cs_result ! = size_part_issue_result ) {
fprintf ( stderr , " [ ERROR ] --- %s --- Number of details( Capstone: %d --- Issue: %d ) doesn't match \n " , list_part [ 0 ] , size_part_cs_result , size_part_issue_result ) ;
cs_free ( insn , count ) ;
free_strs ( list_part , size_part ) ;
free_strs ( list_byte , size_byte ) ;
free ( cs_result ) ;
free_strs ( list_part_cs_result , size_part_cs_result ) ;
free_strs ( list_part_issue_result , size_part_issue_result ) ;
_fail ( __FILE__ , __LINE__ ) ;
}
@ -362,20 +409,20 @@ void test_single_issue(csh *handle, cs_mode mode, char *line, int detail)
if ( strcmp ( list_part_cs_result [ i ] , list_part_issue_result [ i ] ) ) {
fprintf ( stderr , " [ ERROR ] --- %s --- \" %s \" != \" %s \" \n " , list_part [ 0 ] , list_part_cs_result [ i ] , list_part_issue_result [ i ] ) ;
cs_free ( insn , count ) ;
free ( list_part ) ;
free ( list_byte ) ;
free_strs ( list_part , size _part ) ;
free_strs ( list_byte , size _byte ) ;
free ( cs_result ) ;
free ( list_part_cs_result ) ;
free ( list_part_issue_result ) ;
free_strs ( list_part_cs_result , size _part_cs_result ) ;
free_strs ( list_part_issue_result , size _part_issue_result ) ;
_fail ( __FILE__ , __LINE__ ) ;
}
}
cs_free ( insn , count ) ;
free ( list_part ) ;
free ( list_byte ) ;
free_strs ( list_part , size _part ) ;
free_strs ( list_byte , size _byte ) ;
free ( cs_result ) ;
free ( list_part_cs_result ) ;
free ( list_part_issue_result ) ;
free_strs ( list_part_cs_result , size _part_cs_result ) ;
free_strs ( list_part_issue_result , size _part_issue_result ) ;
}