Addressed compile/link errors when built on VS for drivers
diff --git a/cs.c b/cs.c
index b824b10..c426c10 100644
--- a/cs.c
+++ b/cs.c
@@ -110,7 +110,7 @@
#endif
CAPSTONE_EXPORT
-unsigned int cs_version(int *major, int *minor)
+unsigned int CAPSTONE_API cs_version(int *major, int *minor)
{
archs_enable();
@@ -123,7 +123,7 @@
}
CAPSTONE_EXPORT
-bool cs_support(int query)
+bool CAPSTONE_API cs_support(int query)
{
archs_enable();
@@ -157,7 +157,7 @@
}
CAPSTONE_EXPORT
-cs_err cs_errno(csh handle)
+cs_err CAPSTONE_API cs_errno(csh handle)
{
struct cs_struct *ud;
if (!handle)
@@ -169,7 +169,7 @@
}
CAPSTONE_EXPORT
-const char *cs_strerror(cs_err code)
+const char * CAPSTONE_API cs_strerror(cs_err code)
{
switch(code) {
default:
@@ -202,7 +202,7 @@
}
CAPSTONE_EXPORT
-cs_err cs_open(cs_arch arch, cs_mode mode, csh *handle)
+cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
{
cs_err err;
struct cs_struct *ud;
@@ -247,7 +247,7 @@
}
CAPSTONE_EXPORT
-cs_err cs_close(csh *handle)
+cs_err CAPSTONE_API cs_close(csh *handle)
{
struct cs_struct *ud;
@@ -358,7 +358,7 @@
}
CAPSTONE_EXPORT
-cs_err cs_option(csh ud, cs_opt_type type, size_t value)
+cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
{
struct cs_struct *handle;
archs_enable();
@@ -411,25 +411,34 @@
char *p = opstr;
int len;
size_t i;
+ size_t available = sizeof(((cs_insn*)NULL)->op_str);
if (!size) {
opstr[0] = '\0';
return;
}
- len = sprintf(p, "0x%02x", buffer[0]);
+ len = cs_snprintf(p, available, "0x%02x", buffer[0]);
p+= len;
+ available -= len;
for(i = 1; i < size; i++) {
- len = sprintf(p, ", 0x%02x", buffer[i]);
+ len = cs_snprintf(p, available, ", 0x%02x", buffer[i]);
+ if (len < 0) {
+ break;
+ }
+ if ((size_t)len > available - 1) {
+ break;
+ }
p+= len;
+ available -= len;
}
}
// dynamicly allocate memory to contain disasm insn
// NOTE: caller must free() the allocated memory itself to avoid memory leaking
CAPSTONE_EXPORT
-size_t cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
+size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
{
struct cs_struct *handle;
MCInst mci;
@@ -627,13 +636,13 @@
CAPSTONE_EXPORT
CAPSTONE_DEPRECATED
-size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
+size_t CAPSTONE_API cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
{
return cs_disasm(ud, buffer, size, offset, count, insn);
}
CAPSTONE_EXPORT
-void cs_free(cs_insn *insn, size_t count)
+void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
{
size_t i;
@@ -646,7 +655,7 @@
}
CAPSTONE_EXPORT
-cs_insn *cs_malloc(csh ud)
+cs_insn * CAPSTONE_API cs_malloc(csh ud)
{
cs_insn *insn;
struct cs_struct *handle = (struct cs_struct *)(uintptr_t)ud;
@@ -674,7 +683,7 @@
// iterator for instruction "single-stepping"
CAPSTONE_EXPORT
-bool cs_disasm_iter(csh ud, const uint8_t **code, size_t *size,
+bool CAPSTONE_API cs_disasm_iter(csh ud, const uint8_t **code, size_t *size,
uint64_t *address, cs_insn *insn)
{
struct cs_struct *handle;
@@ -761,7 +770,7 @@
// return friendly name of regiser in a string
CAPSTONE_EXPORT
-const char *cs_reg_name(csh ud, unsigned int reg)
+const char * CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
{
struct cs_struct *handle = (struct cs_struct *)(uintptr_t)ud;
@@ -773,7 +782,7 @@
}
CAPSTONE_EXPORT
-const char *cs_insn_name(csh ud, unsigned int insn)
+const char * CAPSTONE_API cs_insn_name(csh ud, unsigned int insn)
{
struct cs_struct *handle = (struct cs_struct *)(uintptr_t)ud;
@@ -785,7 +794,7 @@
}
CAPSTONE_EXPORT
-const char *cs_group_name(csh ud, unsigned int group)
+const char * CAPSTONE_API cs_group_name(csh ud, unsigned int group)
{
struct cs_struct *handle = (struct cs_struct *)(uintptr_t)ud;
@@ -809,7 +818,7 @@
}
CAPSTONE_EXPORT
-bool cs_insn_group(csh ud, const cs_insn *insn, unsigned int group_id)
+bool CAPSTONE_API cs_insn_group(csh ud, const cs_insn *insn, unsigned int group_id)
{
struct cs_struct *handle;
if (!ud)
@@ -836,7 +845,7 @@
}
CAPSTONE_EXPORT
-bool cs_reg_read(csh ud, const cs_insn *insn, unsigned int reg_id)
+bool CAPSTONE_API cs_reg_read(csh ud, const cs_insn *insn, unsigned int reg_id)
{
struct cs_struct *handle;
if (!ud)
@@ -863,7 +872,7 @@
}
CAPSTONE_EXPORT
-bool cs_reg_write(csh ud, const cs_insn *insn, unsigned int reg_id)
+bool CAPSTONE_API cs_reg_write(csh ud, const cs_insn *insn, unsigned int reg_id)
{
struct cs_struct *handle;
if (!ud)
@@ -890,7 +899,7 @@
}
CAPSTONE_EXPORT
-int cs_op_count(csh ud, const cs_insn *insn, unsigned int op_type)
+int CAPSTONE_API cs_op_count(csh ud, const cs_insn *insn, unsigned int op_type)
{
struct cs_struct *handle;
unsigned int count = 0, i;
@@ -966,7 +975,7 @@
}
CAPSTONE_EXPORT
-int cs_op_index(csh ud, const cs_insn *insn, unsigned int op_type,
+int CAPSTONE_API cs_op_index(csh ud, const cs_insn *insn, unsigned int op_type,
unsigned int post)
{
struct cs_struct *handle;