api: get back the old API cs_disasm() & mark cs_disasm_ex() deprecated. cs_disasm_ex() will be removed in the future
diff --git a/bindings/java/capstone/Capstone.java b/bindings/java/capstone/Capstone.java
index 2911bb5..2a2b1ce 100644
--- a/bindings/java/capstone/Capstone.java
+++ b/bindings/java/capstone/Capstone.java
@@ -242,7 +242,7 @@
private interface CS extends Library {
public int cs_open(int arch, int mode, NativeLongByReference handle);
- public NativeLong cs_disasm_ex(NativeLong handle, byte[] code, NativeLong code_len,
+ public NativeLong cs_disasm(NativeLong handle, byte[] code, NativeLong code_len,
long addr, NativeLong count, PointerByReference insn);
public void cs_free(Pointer p, NativeLong count);
public int cs_close(NativeLongByReference handle);
@@ -402,7 +402,7 @@
public CsInsn[] disasm(byte[] code, long address, long count) {
PointerByReference insnRef = new PointerByReference();
- NativeLong c = cs.cs_disasm_ex(ns.csh, code, new NativeLong(code.length), address, new NativeLong(count), insnRef);
+ NativeLong c = cs.cs_disasm(ns.csh, code, new NativeLong(code.length), address, new NativeLong(count), insnRef);
Pointer p = insnRef.getValue();
_cs_insn byref = new _cs_insn(p);
diff --git a/bindings/ocaml/ocaml.c b/bindings/ocaml/ocaml.c
index 72fa7a6..ca8627e 100644
--- a/bindings/ocaml/ocaml.c
+++ b/bindings/ocaml/ocaml.c
@@ -34,7 +34,7 @@
list = Val_emptylist;
- size_t c = cs_disasm_ex(handle, code, code_len, addr, count, &insn);
+ size_t c = cs_disasm(handle, code, code_len, addr, count, &insn);
if (c) {
//printf("Found %lu insn, addr: %lx\n", c, addr);
diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py
index e5c3ebf..e58f9cd 100644
--- a/bindings/python/capstone/__init__.py
+++ b/bindings/python/capstone/__init__.py
@@ -131,7 +131,7 @@
# Capstone error type
CS_ERR_OK = 0 # No error: everything was fine
-CS_ERR_MEM = 1 # Out-Of-Memory error: cs_open(), cs_disasm_ex()
+CS_ERR_MEM = 1 # Out-Of-Memory error: cs_open(), cs_disasm()
CS_ERR_ARCH = 2 # Unsupported architecture: cs_open()
CS_ERR_HANDLE = 3 # Invalid handle: cs_op_count(), cs_op_index()
CS_ERR_CSH = 4 # Invalid csh argument: cs_close(), cs_errno(), cs_option()
@@ -250,7 +250,7 @@
getattr(lib, fname).argtypes = argtypes
_setup_prototype(_cs, "cs_open", ctypes.c_int, ctypes.c_uint, ctypes.c_uint, ctypes.POINTER(ctypes.c_size_t))
-_setup_prototype(_cs, "cs_disasm_ex", ctypes.c_size_t, ctypes.c_size_t, ctypes.POINTER(ctypes.c_char), ctypes.c_size_t, \
+_setup_prototype(_cs, "cs_disasm", ctypes.c_size_t, ctypes.c_size_t, ctypes.POINTER(ctypes.c_char), ctypes.c_size_t, \
ctypes.c_uint64, ctypes.c_size_t, ctypes.POINTER(ctypes.POINTER(_cs_insn)))
_setup_prototype(_cs, "cs_free", None, ctypes.c_void_p, ctypes.c_size_t)
_setup_prototype(_cs, "cs_close", ctypes.c_int, ctypes.POINTER(ctypes.c_size_t))
@@ -316,7 +316,7 @@
raise CsError(status)
all_insn = ctypes.POINTER(_cs_insn)()
- res = _cs.cs_disasm_ex(csh, code, len(code), offset, count, ctypes.byref(all_insn))
+ res = _cs.cs_disasm(csh, code, len(code), offset, count, ctypes.byref(all_insn))
if res > 0:
for i in range(res):
yield CsInsn(_dummy_cs(csh, arch), all_insn[i])
@@ -356,7 +356,7 @@
raise CsError(status)
all_insn = ctypes.POINTER(_cs_insn)()
- res = _cs.cs_disasm_ex(csh, code, len(code), offset, count, ctypes.byref(all_insn))
+ res = _cs.cs_disasm(csh, code, len(code), offset, count, ctypes.byref(all_insn))
if res > 0:
for i in range(res):
insn = all_insn[i]
@@ -776,7 +776,7 @@
print(code)
code = code.encode()
print(code)'''
- res = _cs.cs_disasm_ex(self.csh, code, len(code), offset, count, ctypes.byref(all_insn))
+ res = _cs.cs_disasm(self.csh, code, len(code), offset, count, ctypes.byref(all_insn))
if res > 0:
for i in range(res):
yield CsInsn(self, all_insn[i])
@@ -798,7 +798,7 @@
raise CsError(CS_ERR_DIET)
all_insn = ctypes.POINTER(_cs_insn)()
- res = _cs.cs_disasm_ex(self.csh, code, len(code), offset, count, ctypes.byref(all_insn))
+ res = _cs.cs_disasm(self.csh, code, len(code), offset, count, ctypes.byref(all_insn))
if res > 0:
for i in range(res):
insn = all_insn[i]
diff --git a/bindings/python/pyx/ccapstone.pxd b/bindings/python/pyx/ccapstone.pxd
index f575985..ba5071c 100644
--- a/bindings/python/pyx/ccapstone.pxd
+++ b/bindings/python/pyx/ccapstone.pxd
@@ -41,7 +41,7 @@
cs_err cs_errno(csh handle)
- size_t cs_disasm_ex(csh handle,
+ size_t cs_disasm(csh handle,
const uint8_t *code, size_t code_size,
uint64_t address,
size_t count,
diff --git a/bindings/python/pyx/ccapstone.pyx b/bindings/python/pyx/ccapstone.pyx
index 26548d2..91b7623 100644
--- a/bindings/python/pyx/ccapstone.pyx
+++ b/bindings/python/pyx/ccapstone.pyx
@@ -256,7 +256,7 @@
def disasm(self, code, addr, count=0):
cdef cc.cs_insn *allinsn
- cdef res = cc.cs_disasm_ex(self.csh, code, len(code), addr, count, &allinsn)
+ cdef res = cc.cs_disasm(self.csh, code, len(code), addr, count, &allinsn)
detail = self._cs.detail
arch = self._cs.arch
@@ -284,7 +284,7 @@
# Diet engine cannot provide @mnemonic & @op_str
raise CsError(capstone.CS_ERR_DIET)
- cdef res = cc.cs_disasm_ex(self.csh, code, len(code), addr, count, &allinsn)
+ cdef res = cc.cs_disasm(self.csh, code, len(code), addr, count, &allinsn)
for i from 0 <= i < res:
insn = allinsn[i]
diff --git a/cs.c b/cs.c
index a78fb9a..a66af43 100644
--- a/cs.c
+++ b/cs.c
@@ -409,7 +409,7 @@
// 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_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
+size_t cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
{
struct cs_struct *handle = (struct cs_struct *)(uintptr_t)ud;
MCInst mci;
@@ -607,6 +607,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)
+{
+ return cs_disasm(ud, buffer, size, offset, count, insn);
+}
+
+CAPSTONE_EXPORT
void cs_free(cs_insn *insn, size_t count)
{
size_t i;
diff --git a/include/capstone.h b/include/capstone.h
index 8d8f22a..e767995 100644
--- a/include/capstone.h
+++ b/include/capstone.h
@@ -27,6 +27,15 @@
#define CAPSTONE_EXPORT
#endif
+#ifdef __GNUC__
+#define CAPSTONE_DEPRECATED __attribute__((deprecated))
+#elif defined(_MSC_VER)
+#define CAPSTONE_DEPRECATED __declspec(deprecated)
+#else
+#pragma message("WARNING: You need to implement CAPSTONE_DEPRECATED for this compiler")
+#define CAPSTONE_DEPRECATED
+#endif
+
// Capstone API version
#define CS_API_MAJOR 3
#define CS_API_MINOR 0
@@ -119,7 +128,7 @@
// User-defined callback function for SKIPDATA option
// @code: the input buffer containing code to be disassembled. This is the
-// same buffer passed to cs_disasm_ex().
+// same buffer passed to cs_disasm().
// @code_size: size (in bytes) of the above @code buffer.
// @offset: the position of the currently-examining byte in the input
// buffer @code mentioned above.
@@ -139,7 +148,7 @@
// If the returned value from this callback is positive (>0), Capstone
// will skip exactly that number of bytes & continue. Otherwise, if
// the callback returns 0, Capstone stops disassembling and returns
- // immediately from cs_disasm_ex()
+ // immediately from cs_disasm()
// NOTE: if this callback pointer is NULL, Capstone would skip a number
// of bytes depending on architectures, as following:
// Arm: 2 bytes (Thumb mode) or 4 bytes.
@@ -236,7 +245,7 @@
// These are values returned by cs_errno()
typedef enum cs_err {
CS_ERR_OK = 0, // No error: everything was fine
- CS_ERR_MEM, // Out-Of-Memory error: cs_open(), cs_disasm_ex()
+ CS_ERR_MEM, // Out-Of-Memory error: cs_open(), cs_disasm()
CS_ERR_ARCH, // Unsupported architecture: cs_open()
CS_ERR_HANDLE, // Invalid handle: cs_op_count(), cs_op_index()
CS_ERR_CSH, // Invalid csh argument: cs_close(), cs_errno(), cs_option()
@@ -380,17 +389,27 @@
On failure, call cs_errno() for error code.
*/
CAPSTONE_EXPORT
-size_t cs_disasm_ex(csh handle,
+size_t cs_disasm(csh handle,
const uint8_t *code, size_t code_size,
uint64_t address,
size_t count,
cs_insn **insn);
+/* Deprecated function - to be retired in the next version!
+ Use cs_disasm() instead of cs_disasm_ex()
+*/
+CAPSTONE_EXPORT
+CAPSTONE_DEPRECATED
+size_t cs_disasm_ex(csh handle,
+ const uint8_t *code, size_t code_size,
+ uint64_t address,
+ size_t count,
+ cs_insn **insn);
/*
- Free memory allocated in @insn by cs_disasm_ex()
+ Free memory allocated in @insn by cs_disasm()
- @insn: pointer returned by @insn argument in cs_disasm_ex()
- @count: number of cs_insn structures returned by cs_disasm_ex()
+ @insn: pointer returned by @insn argument in cs_disasm()
+ @count: number of cs_insn structures returned by cs_disasm()
*/
CAPSTONE_EXPORT
void cs_free(cs_insn *insn, size_t count);
@@ -451,7 +470,7 @@
update @groups array.
@handle: handle returned by cs_open()
- @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
+ @insn: disassembled instruction structure received from cs_disasm() or cs_disasm()
@group_id: group that you want to check if this instruction belong to.
@return: true if this instruction indeed belongs to aboved group, or false otherwise.
@@ -469,7 +488,7 @@
WARN: when in 'diet' mode, this API is irrelevant because the engine does not
update @regs_read array.
- @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
+ @insn: disassembled instruction structure received from cs_disasm() or cs_disasm()
@reg_id: register that you want to check if this instruction used it.
@return: true if this instruction indeed implicitly used aboved register, or false otherwise.
@@ -487,7 +506,7 @@
WARN: when in 'diet' mode, this API is irrelevant because the engine does not
update @regs_write array.
- @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
+ @insn: disassembled instruction structure received from cs_disasm() or cs_disasm()
@reg_id: register that you want to check if this instruction modified it.
@return: true if this instruction indeed implicitly modified aboved register, or false otherwise.
@@ -502,7 +521,7 @@
NOTE: this API is only valid when detail option is ON (which is OFF by default)
@handle: handle returned by cs_open()
- @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
+ @insn: disassembled instruction structure received from cs_disasm() or cs_disasm()
@op_type: Operand type to be found.
@return: number of operands of given type @op_type in instruction @insn,
@@ -519,7 +538,7 @@
NOTE: this API is only valid when detail option is ON (which is OFF by default)
@handle: handle returned by cs_open()
- @insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
+ @insn: disassembled instruction structure received from cs_disasm() or cs_disasm()
@op_type: Operand type to be found.
@position: position of the operand to be found. This must be in the range
[1, cs_op_count(handle, insn, op_type)]
diff --git a/tests/test.c b/tests/test.c
index 652c4b7..1502e93 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -205,7 +205,7 @@
if (platforms[i].opt_type)
cs_option(handle, platforms[i].opt_type, platforms[i].opt_value);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -220,7 +220,7 @@
// print out the next offset, after the last insn
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_arm.c b/tests/test_arm.c
index a265860..879f360 100644
--- a/tests/test_arm.c
+++ b/tests/test_arm.c
@@ -213,7 +213,7 @@
if (platforms[i].syntax)
cs_option(handle, CS_OPT_SYNTAX, platforms[i].syntax);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
printf("****************\n");
@@ -227,7 +227,7 @@
}
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_arm64.c b/tests/test_arm64.c
index f721ce8..cfc539d 100644
--- a/tests/test_arm64.c
+++ b/tests/test_arm64.c
@@ -201,7 +201,7 @@
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -216,7 +216,7 @@
}
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_detail.c b/tests/test_detail.c
index 2893642..5509357 100644
--- a/tests/test_detail.c
+++ b/tests/test_detail.c
@@ -199,7 +199,7 @@
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &all_insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &all_insn);
if (count) {
size_t j;
int n;
@@ -249,7 +249,7 @@
// print out the next offset, after the last insn
printf("0x%"PRIx64":\n", all_insn[j-1].address + all_insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(all_insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_mips.c b/tests/test_mips.c
index 19eb7ee..c28a228 100644
--- a/tests/test_mips.c
+++ b/tests/test_mips.c
@@ -112,7 +112,7 @@
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -127,7 +127,7 @@
}
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_ppc.c b/tests/test_ppc.c
index 8748438..f4575bb 100644
--- a/tests/test_ppc.c
+++ b/tests/test_ppc.c
@@ -104,7 +104,7 @@
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -119,7 +119,7 @@
}
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_skipdata.c b/tests/test_skipdata.c
index 6f46276..9610815 100644
--- a/tests/test_skipdata.c
+++ b/tests/test_skipdata.c
@@ -111,7 +111,7 @@
cs_option(handle, CS_OPT_SKIPDATA, CS_OPT_ON);
cs_option(handle, platforms[i].opt_skipdata, platforms[i].skipdata);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -126,7 +126,7 @@
// print out the next offset, after the last insn
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_sparc.c b/tests/test_sparc.c
index 5840b72..29cc57a 100644
--- a/tests/test_sparc.c
+++ b/tests/test_sparc.c
@@ -113,7 +113,7 @@
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -128,7 +128,7 @@
}
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_systemz.c b/tests/test_systemz.c
index 9906360..a844679 100644
--- a/tests/test_systemz.c
+++ b/tests/test_systemz.c
@@ -106,7 +106,7 @@
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -121,7 +121,7 @@
}
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_x86.c b/tests/test_x86.c
index a56cbe7..99c7e23 100644
--- a/tests/test_x86.c
+++ b/tests/test_x86.c
@@ -216,7 +216,7 @@
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -231,7 +231,7 @@
}
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");
diff --git a/tests/test_xcore.c b/tests/test_xcore.c
index 2b681d7..39a575e 100644
--- a/tests/test_xcore.c
+++ b/tests/test_xcore.c
@@ -101,7 +101,7 @@
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
- count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
+ count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
size_t j;
@@ -116,7 +116,7 @@
}
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
- // free memory allocated by cs_disasm_ex()
+ // free memory allocated by cs_disasm()
cs_free(insn, count);
} else {
printf("****************\n");