change cs_option() API to be more flexible with option value
diff --git a/cs.c b/cs.c
index b6adfb7..039d2b8 100644
--- a/cs.c
+++ b/cs.c
@@ -196,7 +196,7 @@
insn->mnemonic[sizeof(insn->mnemonic) - 1] = '\0';
}
-cs_err cs_option(csh ud, unsigned int option)
+cs_err cs_option(csh ud, cs_opt_type type, cs_opt_value value)
{
cs_struct *handle = (cs_struct *)(uintptr_t)ud;
if (!handle)
@@ -206,12 +206,18 @@
default:
break;
case CS_ARCH_X86:
- if (option & CS_OPT_X86_INTEL)
- handle->printer = X86_Intel_printInst;
-
- if (option & CS_OPT_X86_ATT)
- handle->printer = X86_ATT_printInst;
-
+ if (type & CS_OPT_SYNTAX) {
+ switch(value) {
+ default:
+ break;
+ case CS_OPT_V_INTEL:
+ handle->printer = X86_Intel_printInst;
+ break;
+ case CS_OPT_V_ATT:
+ handle->printer = X86_ATT_printInst;
+ break;
+ }
+ }
break;
}
diff --git a/include/capstone.h b/include/capstone.h
index 3609ae7..a4698dc 100644
--- a/include/capstone.h
+++ b/include/capstone.h
@@ -38,10 +38,15 @@
} cs_mode;
// Option type
-typedef enum cs_opt {
- CS_OPT_X86_INTEL = 1 << 0, // Intel X86 asm syntax (CS_ARCH_X86 arch)
- CS_OPT_X86_ATT = 1 << 1, // ATT asm syntax (CS_ARCH_X86 arch)
-} cs_opt;
+typedef enum cs_opt_type {
+ CS_OPT_SYNTAX = 1, // Asssembly syntax option
+} cs_opt_type;
+
+// Option value
+typedef enum cs_opt_value {
+ CS_OPT_V_INTEL = 1, // X86 Intel asm syntax (CS_OPT_SYNTAX)
+ CS_OPT_V_ATT, // X86 ATT asm syntax (CS_OPT_SYNTAX)
+} cs_opt_value;
#include "arm.h"
@@ -133,12 +138,13 @@
Set option for disassembling
@handle: handle returned by cs_open()
- @option: option to be set, which can be OR by several cs_opt enums
+ @type: type of option to be set
+ @value: option value for corresponding , which can be OR by several cs_opt enums
@return CS_ERR_OK on success, or other value on failure (refer to cs_err enum
for detailed error).
*/
-cs_err cs_option(csh handle, unsigned int option);
+cs_err cs_option(csh handle, cs_opt_type type, cs_opt_value value);
/*
Report the last error number when some API function fail.
diff --git a/tests/test.c b/tests/test.c
index 1f935a0..1953e30 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -13,7 +13,8 @@
unsigned char *code;
size_t size;
char *comment;
- cs_opt option;
+ cs_opt_type opt_type;
+ cs_opt_value opt_value;
};
static void print_string_hex(unsigned char *str, int len)
@@ -59,7 +60,8 @@
.code = (unsigned char*)X86_CODE32,
.size = sizeof(X86_CODE32) - 1,
.comment = "X86 32bit (ATT syntax)",
- .option = CS_OPT_X86_ATT,
+ .opt_type = CS_OPT_SYNTAX,
+ .opt_value = CS_OPT_V_ATT,
},
{
.arch = CS_ARCH_X86,
@@ -139,8 +141,8 @@
return;
}
- if (platforms[i].option)
- cs_option(handle, platforms[i].option);
+ if (platforms[i].opt_type)
+ cs_option(handle, platforms[i].opt_type, platforms[i].opt_value);
//size_t count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, insn);
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
diff --git a/tests/test_detail.c b/tests/test_detail.c
index 041f6d7..12b2f00 100644
--- a/tests/test_detail.c
+++ b/tests/test_detail.c
@@ -13,7 +13,8 @@
unsigned char *code;
size_t size;
char *comment;
- cs_opt option;
+ cs_opt_type opt_type;
+ cs_opt_value opt_value;
};
static void print_string_hex(unsigned char *str, int len)
@@ -64,7 +65,8 @@
.code = (unsigned char *)X86_CODE32,
.size = sizeof(X86_CODE32) - 1,
.comment = "X86 32bit (ATT syntax)",
- .option = CS_OPT_X86_ATT,
+ .opt_type = CS_OPT_SYNTAX,
+ .opt_value = CS_OPT_V_ATT,
},
{
.arch = CS_ARCH_X86,
@@ -141,8 +143,8 @@
if (cs_open(platforms[i].arch, platforms[i].mode, &handle))
return;
- if (platforms[i].option)
- cs_option(handle, platforms[i].option);
+ if (platforms[i].opt_type)
+ cs_option(handle, platforms[i].opt_type, platforms[i].opt_value);
//size_t count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, all_insn);
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &all_insn);
diff --git a/tests/test_x86.c b/tests/test_x86.c
index f1f4bb4..eb0e0b2 100644
--- a/tests/test_x86.c
+++ b/tests/test_x86.c
@@ -15,7 +15,8 @@
unsigned char *code;
size_t size;
char *comment;
- cs_opt option;
+ cs_opt_type opt_type;
+ cs_opt_value opt_value;
};
static void print_string_hex(char *comment, unsigned char *str, int len)
@@ -136,7 +137,8 @@
.code = (unsigned char *)X86_CODE32,
.size = sizeof(X86_CODE32) - 1,
.comment = "X86 32 (AT&T syntax)",
- .option = CS_OPT_X86_ATT,
+ .opt_type = CS_OPT_SYNTAX,
+ .opt_value = CS_OPT_V_ATT,
},
{
.arch = CS_ARCH_X86,
@@ -163,8 +165,8 @@
if (cs_open(platforms[i].arch, platforms[i].mode, &handle))
return;
- if (platforms[i].option)
- cs_option(handle, platforms[i].option);
+ if (platforms[i].opt_type)
+ cs_option(handle, platforms[i].opt_type, platforms[i].opt_value);
//size_t count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, insn);
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &insn);