number of bytes skipped by SKIPDATA option depends on arch
diff --git a/cs.c b/cs.c
index 2dd9374..ec74c50 100644
--- a/cs.c
+++ b/cs.c
@@ -294,6 +294,7 @@
}
// how many bytes will we skip when encountering data (CS_OPT_SKIPDATA)?
+// this very much depends on instruction alignment requirement of each arch.
static uint8_t skipdata_size(cs_struct *handle)
{
switch(handle->arch) {
@@ -301,12 +302,20 @@
// should never reach
return -1;
case CS_ARCH_ARM:
+ // skip 2 bytes on Thumb mode.
+ if (handle->mode & CS_MODE_THUMB)
+ return 2;
+ // otherwise, skip 4 bytes
+ return 4;
case CS_ARCH_ARM64:
case CS_ARCH_MIPS:
case CS_ARCH_PPC:
case CS_ARCH_SPARC:
+ // skip 4 bytes
+ return 4;
case CS_ARCH_SYSZ:
- // skip 2 bytes due to instruction alignment
+ // SystemZ instruction's length can be 2, 4 or 6 bytes,
+ // so we just skip 2 bytes
return 2;
case CS_ARCH_X86:
// X86 has no restriction on instruction alignment
diff --git a/include/capstone.h b/include/capstone.h
index c9be396..3c93646 100644
--- a/include/capstone.h
+++ b/include/capstone.h
@@ -118,13 +118,22 @@
// User can specify the string for this instruction's "mnemonic" here.
// By default (if @mnemonic is NULL), Capstone use ".db".
const char *mnemonic;
+
// User-defined callback function to be called when Capstone hits data.
- // 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()
- // NOTE: if this callback pointer is NULL, Capstone skip 1 byte on X86, and 2 bytes on
- // every other architectures.
+ // 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()
+ // 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.
+ // Arm64: 4 bytes.
+ // Mips: 4 bytes.
+ // Sparc: 4 bytes.
+ // SystemZ: 2 bytes.
+ // X86: 1 bytes.
cs_skipdata_cb_t callback; // default value is NULL
+
// User-defined data to be passed to @callback function pointer.
void *user_data;
} cs_opt_skipdata;