5 #if defined(_MSC_VER) && _MSC_VER < 1900
6 #define _CRT_SECURE_NO_WARNINGS
7 #define snprintf _snprintf
13 #include <capstone/platform.h>
14 #include <capstone/capstone.h>
35 if (!hex_out) {
goto Exit; }
37 for (
i = 0;
i <
len; ++
i) {
51 #define _this_printf(...) \
54 used = snprintf(buf + *cur, *left, __VA_ARGS__); \
63 if (ins->detail ==
NULL)
66 arm = &(ins->detail->arm);
71 for (
i = 0;
i <
arm->op_count;
i++) {
73 switch((
int)
op->type) {
93 if (
op->mem.scale != 1)
95 if (
op->mem.disp != 0)
123 if (
arm->update_flags) {
127 if (
arm->writeback) {
137 size_t cur=0, left=2048;
148 #define MAX_INVALID_CODES 16
166 (
unsigned char *)
"\xbd\xe8\x1e\xff",
168 "invalid thumb2 pop because sp used and because both pc and lr are "
169 "present at the same time"
181 printf(
"\nShould be invalid\n"
182 "-----------------\n");
184 for (
i = 0;
i <
sizeof(invalids)/
sizeof(invalids[0]);
i++) {
187 invalid = invalids +
i;
191 printf(
"Failed on cs_open() with error returned: %u\n",
err);
220 insn[
k].address, insn[
k].
mnemonic, insn[
k].op_str);
226 printf(
" SUCCESS: invalid\n");
242 #define MAX_VALID_CODES 16
258 {{ (
unsigned char *)
"\x00\xf0\x26\xe8", 4, 0x352,
259 "0x352:\tblx\t#0x3a0\n"
261 "\t\toperands[0].type: IMM = 0x3a0\n",
263 "thumb2 blx with misaligned immediate"
264 }, { (
unsigned char *)
"\x05\xdd", 2, 0x1f0,
265 "0x1f0:\tble\t#0x1fe\n"
267 "\t\toperands[0].type: IMM = 0x1fe\n"
268 "\tCode condition: 14\n",
270 "thumb b cc with thumb-aligned target"
271 }, { (
unsigned char *)
"\xbd\xe8\xf0\x8f", 4, 0,
272 "0x0:\tpop.w\t{r4, r5, r6, r7, r8, r9, r10, r11, pc}\n"
274 "\t\toperands[0].type: REG = r4\n"
275 "\t\toperands[1].type: REG = r5\n"
276 "\t\toperands[2].type: REG = r6\n"
277 "\t\toperands[3].type: REG = r7\n"
278 "\t\toperands[4].type: REG = r8\n"
279 "\t\toperands[5].type: REG = r9\n"
280 "\t\toperands[6].type: REG = r10\n"
281 "\t\toperands[7].type: REG = r11\n"
282 "\t\toperands[8].type: REG = pc\n",
284 "thumb2 pop that should be valid"
298 for (
i = 0;
i <
sizeof(valids)/
sizeof(valids[0]);
i++) {
305 printf(
"Failed on cs_open() with error returned: %u\n",
err);
312 #define _this_printf(...) \
315 used = snprintf(tmp_buf + cur, left, __VA_ARGS__); \
319 printf(
"\nShould be valid\n"
320 "---------------\n");
322 for (j = 0; j <
valid->num_valid_codes; ++j) {
335 printf(
"%s %s @ 0x%04x: %s\n %s",
359 max_len = strlen(tmp_buf);
361 if (tmp_len > max_len) {
367 " ERROR: '''\n%s''' does not match"
368 " expected '''\n%s'''\n",
372 printf(
" SUCCESS: valid\n");
378 printf(
"ERROR: invalid\n");
@ ARM_SFT_ASR_REG
shift with register
@ ARM_OP_IMM
= CS_OP_IMM (Immediate operand).
@ ARM_OP_REG
= CS_OP_REG (Register operand).
@ ARM_OP_CIMM
C-Immediate (coprocessor registers)
@ ARM_OP_PIMM
P-Immediate (coprocessor registers)
@ ARM_OP_MEM
= CS_OP_MEM (Memory operand).
@ ARM_OP_FP
= CS_OP_FP (Floating-Point operand).
@ ARM_CC_AL
Always (unconditional) Always (unconditional)
cs_arch
Architecture type.
@ CS_ARCH_ARM
ARM architecture (including Thumb, Thumb-2)
@ CS_MODE_THUMB
ARM's Thumb mode, including Thumb-2.
@ CS_OPT_DETAIL
Break down instruction structure into details.
@ CS_OPT_SYNTAX
Assembly output syntax.
@ CS_OPT_SYNTAX_NOREGNAME
Prints register name with only number (CS_OPT_SYNTAX)
@ CS_OPT_ON
Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
CAPSTONE_EXPORT size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * malloc(size_t size)
struct invalid_code invalid_codes[MAX_INVALID_CODES]
struct valid_code valid_codes[MAX_VALID_CODES]
static void test_invalids()
static void test_valids()
static void print_insn_detail(cs_insn *ins)
#define _this_printf(...)
#define MAX_INVALID_CODES
static char * hex_string(unsigned char *str, size_t len)
static void snprint_insn_detail(char *buf, size_t *cur, size_t *left, cs_insn *ins)