Change the prototype of the callback in SKIPDATA option. Suggested by Ben Nagy.
Original prototype:
typedef size_t (*cs_skipdata_cb_t)(const uint8_t *code, uint64_t offset, void* user_data);
Now we add @code_size argument to reflect the size of the input buffer @code.
Also, we change the data type of @offset to size_t because this argument indicates the
distance from currently examining bytes to @code, but not the address of the byte.
typedef size_t (*cs_skipdata_cb_t)(const uint8_t *code, size_t code_size, size_t offset, void* user_data);
diff --git a/cs.c b/cs.c
index 9e40a17..dcabf20 100644
--- a/cs.c
+++ b/cs.c
@@ -422,7 +422,10 @@
bool r;
void *tmp;
size_t skipdata_bytes;
+ // save all the original info of the buffer
uint64_t offset_org;
+ size_t size_org;
+ const uint8_t *buffer_org;
if (!handle) {
// FIXME: how to handle this case:
@@ -433,7 +436,9 @@
handle->errnum = CS_ERR_OK;
// save the original offset for SKIPDATA
+ buffer_org = buffer;
offset_org = offset;
+ size_org = size;
total_size = (sizeof(cs_insn) * INSN_CACHE_SIZE);
total = cs_mem_malloc(total_size);
insn_cache = total;
@@ -512,8 +517,8 @@
break;
if (handle->skipdata_setup.callback) {
- skipdata_bytes = handle->skipdata_setup.callback(buffer, offset - offset_org,
- handle->skipdata_setup.user_data);
+ skipdata_bytes = handle->skipdata_setup.callback(buffer_org, size_org,
+ offset - offset_org, handle->skipdata_setup.user_data);
if (skipdata_bytes > size)
// remaining data is not enough
break;