cmp x1, x2
Registers read: x2
Registers modified: nzcv x1
which is wrong, as x1 is read, not modified.
#include <stdio.h>
#include "include/capstone/capstone.h"
#define CODE "\x3F\x00\x02\xEB" // cmp x1, x2
int main(void)
{
csh handle;
cs_insn *insn;
size_t count, j;
cs_regs regs_read, regs_write;
uint8_t read_count, write_count, i;
if (cs_open(CS_ARCH_ARM64, CS_MODE_ARM, &handle) != CS_ERR_OK)
return -1;
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
count = cs_disasm(handle, CODE, sizeof(CODE)-1, 0x1000, 0, &insn);
if (count > 0) {
for (j = 0; j < count; j++) {
// Print assembly
printf("%s\t%s\n", insn[j].mnemonic, insn[j].op_str);
// Print all registers accessed by this instruction.
if (cs_regs_access(handle, &insn[j],
regs_read, &read_count,
regs_write, &write_count) == 0) {
if (read_count > 0) {
printf("\n\tRegisters read:");
for (i = 0; i < read_count; i++) {
printf(" %s", cs_reg_name(handle, regs_read[i]));
}
printf("\n");
}
if (write_count > 0) {
printf("\n\tRegisters modified:");
for (i = 0; i < write_count; i++) {
printf(" %s", cs_reg_name(handle, regs_write[i]));
}
printf("\n");
}
}
}
cs_free(insn, count);
} else
printf("ERROR: Failed to disassemble given code!\n");
cs_close(&handle);
return 0;
}
First of all, thank you for your work, this is an amazing library.
Unfortunately, I found a bug when I used the code from the doc page to test register read/write flags here: https://www.capstone-engine.org/op_access.html
The code outputs:
which is wrong, as x1 is read, not modified.
I'll paste here the exact code I used for easier reproduction:
Thank you!