Rizin
unix-like reverse engineering framework and cli tools
asm_arm_cs.c File Reference
#include <rz_asm.h>
#include <rz_lib.h>
#include <ht_uu.h>
#include <capstone/capstone.h>
#include "../arch/arm/asm-arm.h"
#include "../arch/arm/arm_it.h"
#include "./asm_arm_hacks.inc"

Go to the source code of this file.

Classes

struct  arm_cs_context_t
 

Typedefs

typedef struct arm_cs_context_t ArmCSContext
 

Functions

bool arm64ass (const char *str, ut64 addr, ut32 *op)
 
static bool check_features (RzAsm *a, cs_insn *insn)
 
static const char * cc_name (arm_cc cc)
 
static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
 
static int assemble (RzAsm *a, RzAsmOp *op, const char *buf)
 
static bool arm_init (void **user)
 
static bool arm_fini (void *user)
 
static char * mnemonics (RzAsm *a, int id, bool json)
 

Variables

RzAsmPlugin rz_asm_plugin_arm_cs
 
RZ_API RzLibStruct rizin_plugin
 

Typedef Documentation

◆ ArmCSContext

Function Documentation

◆ arm64ass()

bool arm64ass ( const char *  str,
ut64  addr,
ut32 op 
)

Definition at line 1348 of file armass64.c.

1348  {
1349  *op = UT32_MAX;
1350  ArmOp ops = { 0 };
1351  if (!parseOpcode(str, &ops)) {
1352  free(ops.mnemonic);
1353  return false;
1354  }
1355  /* TODO: write tests for this and move out the regsize logic into the mov */
1356  if (!strncmp(str, "mov", 3)) {
1357  *op = mov(&ops);
1358  } else if (!strncmp(str, "cb", 2)) {
1359  *op = cb(&ops);
1360  } else if (!strncmp(str, "cmp", 3)) {
1361  *op = cmp(&ops);
1362  } else if (!strncmp(str, "ldrb", 4)) {
1363  *op = lsop(&ops, 0x00004038, -1);
1364  } else if (!strncmp(str, "ldrh", 4)) {
1365  *op = lsop(&ops, 0x00004078, -1);
1366  } else if (!strncmp(str, "ldrsh", 5)) {
1367  *op = lsop(&ops, 0x00008078, -1);
1368  } else if (!strncmp(str, "ldrsw", 5)) {
1369  *op = lsop(&ops, 0x00000098, addr);
1370  } else if (!strncmp(str, "ldrsb", 5)) {
1371  *op = lsop(&ops, 0x00008038, -1);
1372  } else if (!strncmp(str, "strb", 4)) {
1373  *op = lsop(&ops, 0x00000038, -1);
1374  } else if (!strncmp(str, "strh", 4)) {
1375  *op = lsop(&ops, 0x00000078, -1);
1376  } else if (!strncmp(str, "ldr", 3)) {
1377  *op = reglsop(&ops, 0x000040f8);
1378  } else if (!strncmp(str, "stur", 4)) {
1379  *op = regsluop(&ops, 0x000000f8);
1380  } else if (!strncmp(str, "ldur", 4)) {
1381  *op = regsluop(&ops, 0x000040f8);
1382  } else if (!strncmp(str, "str", 3)) {
1383  *op = reglsop(&ops, 0x000000f8);
1384  } else if (!strncmp(str, "stp", 3)) {
1385  *op = stp(&ops, 0x000000a9);
1386  } else if (!strncmp(str, "ldp", 3)) {
1387  *op = stp(&ops, 0x000040a9);
1388  } else if (!strncmp(str, "sub", 3)) { // w
1389  *op = arithmetic(&ops, 0xd1);
1390  } else if (!strncmp(str, "add x", 5)) {
1391  *op = arithmetic(&ops, 0x91);
1392  } else if (!strncmp(str, "add w", 5)) {
1393  *op = arithmetic(&ops, 0x11);
1394  } else if (!strncmp(str, "adr x", 5)) { // w
1395  *op = adr(&ops, addr);
1396  } else if (!strncmp(str, "adrp x", 6)) {
1397  *op = adrp(&ops, addr, 0x00000090);
1398  } else if (!strncmp(str, "neg", 3)) {
1399  *op = neg(&ops);
1400  } else if (!strcmp(str, "isb")) {
1401  *op = 0xdf3f03d5;
1402  } else if (handlePAC(op, str)) { // PAC
1403  free(ops.mnemonic);
1404  return true;
1405  } else if (!strcmp(str, "nop")) {
1406  *op = 0x1f2003d5;
1407  } else if (!strcmp(str, "ret")) {
1408  *op = 0xc0035fd6;
1409  } else if (!strncmp(str, "msr ", 4)) {
1410  *op = msr(&ops, 0);
1411  } else if (!strncmp(str, "mrs ", 4)) {
1412  *op = msr(&ops, 1);
1413  } else if (!strncmp(str, "ands ", 5)) {
1414  *op = logical(&ops, false, ARM_ANDS);
1415  } else if (!strncmp(str, "and ", 4)) {
1416  *op = logical(&ops, false, ARM_AND);
1417  } else if (!strncmp(str, "bics ", 5)) {
1418  *op = logical(&ops, true, ARM_ANDS);
1419  } else if (!strncmp(str, "bic ", 4)) {
1420  *op = logical(&ops, true, ARM_AND);
1421  } else if (!strncmp(str, "eon ", 4)) {
1422  *op = logical(&ops, true, ARM_EOR);
1423  } else if (!strncmp(str, "eor ", 4)) {
1424  *op = logical(&ops, false, ARM_EOR);
1425  } else if (!strncmp(str, "orn ", 4)) {
1426  *op = logical(&ops, true, ARM_ORR);
1427  } else if (!strncmp(str, "orr ", 4)) {
1428  *op = logical(&ops, false, ARM_ORR);
1429  } else if (!strncmp(str, "svc ", 4)) { // system level exception
1430  *op = exception(&ops, 0x010000d4);
1431  } else if (!strncmp(str, "hvc ", 4)) { // hypervisor level exception
1432  *op = exception(&ops, 0x020000d4);
1433  } else if (!strncmp(str, "smc ", 4)) { // secure monitor exception
1434  *op = exception(&ops, 0x030000d4);
1435  } else if (!strncmp(str, "brk ", 4)) { // breakpoint
1436  *op = exception(&ops, 0x000020d4);
1437  } else if (!strncmp(str, "hlt ", 4)) { // halt
1438  *op = exception(&ops, 0x000040d4);
1439  } else if (!strncmp(str, "b ", 2)) {
1440  *op = branch(&ops, addr, 0x14);
1441  } else if (!strncmp(str, "b.", 2)) {
1442  *op = parse_bdot(str + 2, &ops, addr);
1443  } else if (!strncmp(str, "bl ", 3)) {
1444  *op = branch(&ops, addr, 0x94);
1445  } else if (!strncmp(str, "br x", 4)) {
1446  *op = branch(&ops, addr, 0x1fd6);
1447  } else if (!strncmp(str, "blr x", 5)) {
1448  *op = branch(&ops, addr, 0x3fd6);
1449  } else if (!strncmp(str, "dmb ", 4)) {
1450  *op = mem_barrier(&ops, addr, 0xbf3003d5);
1451  } else if (!strncmp(str, "dsb ", 4)) {
1452  *op = mem_barrier(&ops, addr, 0x9f3003d5);
1453  } else if (!strncmp(str, "isb", 3)) {
1454  *op = mem_barrier(&ops, addr, 0xdf3f03d5);
1455  } else if (!strncmp(str, "sbfiz ", 6) || !strncmp(str, "sbfm ", 5) || !strncmp(str, "sbfx ", 5)) {
1456  *op = bitfield(&ops, 0x00000013);
1457  } else if (!strncmp(str, "ubfiz ", 6) || !strncmp(str, "ubfm ", 5) || !strncmp(str, "ubfx ", 5)) {
1458  *op = bitfield(&ops, 0x00000053);
1459  }
1460  free(ops.mnemonic);
1461  return *op != UT32_MAX;
1462 }
static struct @29 ops[]
static ut32 parse_bdot(const char *str, ArmOp *op, ut64 addr)
Definition: armass64.c:673
static ut32 branch(ArmOp *op, ut64 addr, int k)
Definition: armass64.c:571
static ut32 bitfield(ArmOp *op, int k)
Definition: armass64.c:992
static ut32 logical(ArmOp *op, bool invert, LogicalOp opc)
Definition: armass64.c:786
static ut32 neg(ArmOp *op)
Definition: armass64.c:981
static ut32 cb(ArmOp *op)
Definition: armass64.c:310
static ut32 exception(ArmOp *op, ut32 k)
Definition: armass64.c:921
static ut32 adrp(ArmOp *op, ut64 addr, ut32 k)
Definition: armass64.c:853
static ut32 mov(ArmOp *op)
Definition: armass64.c:223
static ut32 arithmetic(ArmOp *op, int k)
Definition: armass64.c:933
static ut32 reglsop(ArmOp *op, int k)
Definition: armass64.c:405
static bool handlePAC(ut32 *op, const char *str)
Definition: armass64.c:1308
static bool parseOpcode(const char *str, ArmOp *op)
Definition: armass64.c:1293
static ut32 mem_barrier(ArmOp *op, ut64 addr, int k)
Definition: armass64.c:686
static ut32 lsop(ArmOp *op, int k, ut64 addr)
Definition: armass64.c:462
static ut32 cmp(ArmOp *op)
Definition: armass64.c:340
static ut32 regsluop(ArmOp *op, int k)
Definition: armass64.c:362
@ ARM_AND
Definition: armass64.c:45
@ ARM_EOR
Definition: armass64.c:47
@ ARM_ANDS
Definition: armass64.c:48
@ ARM_ORR
Definition: armass64.c:46
static ut32 adr(ArmOp *op, int addr)
Definition: armass64.c:884
static ut32 msr(ArmOp *op, int w)
Definition: armass64.c:706
static ut32 stp(ArmOp *op, int k)
Definition: armass64.c:904
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define UT32_MAX
Definition: rz_types_base.h:99
Definition: armass.c:21
Definition: dis.c:32
static int addr
Definition: z80asm.c:58

References addr, adr(), adrp(), arithmetic(), ARM_AND, ARM_ANDS, ARM_EOR, ARM_ORR, bitfield(), branch(), cb(), cmp(), exception(), free(), handlePAC(), logical(), lsop(), mem_barrier(), mov(), msr(), neg(), ops, parse_bdot(), parseOpcode(), reglsop(), regsluop(), stp(), cmd_descs_generate::str, and UT32_MAX.

Referenced by assemble().

◆ arm_fini()

static bool arm_fini ( void *  user)
static

Definition at line 252 of file asm_arm_cs.c.

252  {
253  rz_return_val_if_fail(user, false);
254  ArmCSContext *ctx = (ArmCSContext *)user;
255  cs_close(&ctx->cd);
257  free(ctx);
258  return true;
259 }
RZ_API void rz_arm_it_context_fini(RzArmITContext *ctx)
Definition: arm_it.c:25
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
Definition: cs.c:501
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

References cs_close(), free(), rz_arm_it_context_fini(), and rz_return_val_if_fail.

◆ arm_init()

static bool arm_init ( void **  user)
static

Definition at line 239 of file asm_arm_cs.c.

239  {
241  if (!ctx) {
242  return false;
243  }
245  ctx->cd = 0;
246  ctx->omode = -1;
247  ctx->obits = 32;
248  *user = ctx;
249  return true;
250 }
RZ_API void rz_arm_it_context_init(RzArmITContext *ctx)
Definition: arm_it.c:20
#define RZ_NEW0(x)
Definition: rz_types.h:284

References rz_arm_it_context_init(), and RZ_NEW0.

◆ assemble()

static int assemble ( RzAsm a,
RzAsmOp op,
const char *  buf 
)
static

Definition at line 190 of file asm_arm_cs.c.

190  {
191  const bool is_thumb = (a->bits == 16);
192  int opsize;
193  ut32 opcode;
194  if (a->bits == 64) {
195  if (!arm64ass(buf, a->pc, &opcode)) {
196  return -1;
197  }
198  } else {
199  opcode = armass_assemble(buf, a->pc, is_thumb);
200  if (a->bits != 32 && a->bits != 16) {
201  RZ_LOG_ERROR("assembler: arm: cannot assemble instruction due invalid 'asm.bits' value (accepted only 16 or 32 bits).\n");
202  return -1;
203  }
204  }
205  if (opcode == UT32_MAX) {
206  return -1;
207  }
208  ut8 opbuf[4];
209  if (is_thumb) {
210  const int o = opcode >> 16;
211  opsize = o > 0 ? 4 : 2;
212  if (opsize == 4) {
213  if (a->big_endian) {
214  rz_write_le16(opbuf, opcode >> 16);
215  rz_write_le16(opbuf + 2, opcode & UT16_MAX);
216  } else {
217  rz_write_be32(opbuf, opcode);
218  }
219  } else if (opsize == 2) {
220  if (a->big_endian) {
221  rz_write_le16(opbuf, opcode & UT16_MAX);
222  } else {
223  rz_write_be16(opbuf, opcode & UT16_MAX);
224  }
225  }
226  } else {
227  opsize = 4;
228  if (a->big_endian) {
229  rz_write_le32(opbuf, opcode);
230  } else {
231  rz_write_be32(opbuf, opcode);
232  }
233  }
234  rz_strbuf_setbin(&op->buf, opbuf, opsize);
235  // XXX. thumb endian assembler needs no swap
236  return opsize;
237 }
ut32 armass_assemble(const char *str, ut64 off, int thumb)
Definition: armass.c:6209
bool arm64ass(const char *str, ut64 addr, ut32 *op)
Definition: armass64.c:1348
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static bool is_thumb(RzBinFile *bf)
static void rz_write_le32(void *dest, ut32 val)
Definition: rz_endian.h:256
static void rz_write_le16(void *dest, ut16 val)
Definition: rz_endian.h:222
static void rz_write_be16(void *dest, ut16 val)
Definition: rz_endian.h:60
static void rz_write_be32(void *dest, ut32 val)
Definition: rz_endian.h:98
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
Definition: strbuf.c:85
#define UT16_MAX
#define a(i)
Definition: sha256.c:41

References a, arm64ass(), armass_assemble(), is_thumb(), RZ_LOG_ERROR, rz_strbuf_setbin(), rz_write_be16(), rz_write_be32(), rz_write_le16(), rz_write_le32(), UT16_MAX, and UT32_MAX.

◆ cc_name()

static const char* cc_name ( arm_cc  cc)
static

Definition at line 51 of file asm_arm_cs.c.

51  {
52  switch (cc) {
53  case ARM_CC_EQ: // Equal Equal
54  return "eq";
55  case ARM_CC_NE: // Not equal Not equal, or unordered
56  return "ne";
57  case ARM_CC_HS: // Carry set >, ==, or unordered
58  return "hs";
59  case ARM_CC_LO: // Carry clear Less than
60  return "lo";
61  case ARM_CC_MI: // Minus, negative Less than
62  return "mi";
63  case ARM_CC_PL: // Plus, positive or zero >, ==, or unordered
64  return "pl";
65  case ARM_CC_VS: // Overflow Unordered
66  return "vs";
67  case ARM_CC_VC: // No overflow Not unordered
68  return "vc";
69  case ARM_CC_HI: // Unsigned higher Greater than, or unordered
70  return "hi";
71  case ARM_CC_LS: // Unsigned lower or same Less than or equal
72  return "ls";
73  case ARM_CC_GE: // Greater than or equal Greater than or equal
74  return "ge";
75  case ARM_CC_LT: // Less than Less than, or unordered
76  return "lt";
77  case ARM_CC_GT: // Greater than Greater than
78  return "gt";
79  case ARM_CC_LE: // Less than or equal <, ==, or unordered
80  return "le";
81  default:
82  return "";
83  }
84 }
@ ARM_CC_GT
Greater than Greater than.
Definition: arm.h:47
@ ARM_CC_LE
Less than or equal <, ==, or unordered.
Definition: arm.h:48
@ ARM_CC_HI
Unsigned higher Greater than, or unordered.
Definition: arm.h:43
@ ARM_CC_VC
No overflow Not unordered.
Definition: arm.h:42
@ ARM_CC_LS
Unsigned lower or same Less than or equal.
Definition: arm.h:44
@ ARM_CC_GE
Greater than or equal Greater than or equal.
Definition: arm.h:45
@ ARM_CC_VS
Overflow Unordered.
Definition: arm.h:41
@ ARM_CC_PL
Plus, positive or zero >, ==, or unordered.
Definition: arm.h:40
@ ARM_CC_NE
Not equal Not equal, or unordered.
Definition: arm.h:36
@ ARM_CC_LO
Carry clear Less than.
Definition: arm.h:38
@ ARM_CC_EQ
Equal Equal.
Definition: arm.h:35
@ ARM_CC_LT
Less than Less than, or unordered.
Definition: arm.h:46
@ ARM_CC_HS
Carry set >, ==, or unordered.
Definition: arm.h:37
@ ARM_CC_MI
Minus, negative Less than.
Definition: arm.h:39

References ARM_CC_EQ, ARM_CC_GE, ARM_CC_GT, ARM_CC_HI, ARM_CC_HS, ARM_CC_LE, ARM_CC_LO, ARM_CC_LS, ARM_CC_LT, ARM_CC_MI, ARM_CC_NE, ARM_CC_PL, ARM_CC_VC, and ARM_CC_VS.

Referenced by disassemble().

◆ check_features()

static bool check_features ( RzAsm a,
cs_insn *  insn 
)
static

Definition at line 21 of file asm_arm_cs.c.

21  {
22  ArmCSContext *ctx = (ArmCSContext *)a->plugin_data;
23  int i;
24  if (!insn || !insn->detail) {
25  return true;
26  }
27  for (i = 0; i < insn->detail->groups_count; i++) {
28  int id = insn->detail->groups[i];
29  switch (id) {
30  case ARM_GRP_ARM:
31  case ARM_GRP_THUMB:
32  case ARM_GRP_THUMB1ONLY:
33  case ARM_GRP_THUMB2:
34  continue;
35  default:
36  if (id < 128) {
37  continue;
38  }
39  }
40  const char *name = cs_group_name(ctx->cd, id);
41  if (!name) {
42  return true;
43  }
44  if (!strstr(a->features, name)) {
45  return false;
46  }
47  }
48  return true;
49 }
lzma_index ** i
Definition: index.h:629
@ ARM_GRP_THUMB2
Definition: arm.h:921
@ ARM_GRP_ARM
Definition: arm.h:916
@ ARM_GRP_THUMB
Definition: arm.h:919
@ ARM_GRP_THUMB1ONLY
Definition: arm.h:920
CAPSTONE_EXPORT const char *CAPSTONE_API cs_group_name(csh ud, unsigned int group)
Definition: cs.c:1178
Definition: z80asm.h:102
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References a, ARM_GRP_ARM, ARM_GRP_THUMB, ARM_GRP_THUMB1ONLY, ARM_GRP_THUMB2, cs_group_name(), i, and if().

Referenced by disassemble().

◆ disassemble()

static int disassemble ( RzAsm a,
RzAsmOp op,
const ut8 buf,
int  len 
)
static

Definition at line 86 of file asm_arm_cs.c.

86  {
87  ArmCSContext *ctx = (ArmCSContext *)a->plugin_data;
88 
89  bool disp_hash = a->immdisp;
90  cs_insn *insn = NULL;
91  cs_mode mode = 0;
92  int ret, n = 0;
93 
94  bool thumb = a->bits == 16;
95  mode |= thumb ? CS_MODE_THUMB : CS_MODE_ARM;
96  mode |= (a->big_endian) ? CS_MODE_BIG_ENDIAN : CS_MODE_LITTLE_ENDIAN;
97  if (mode != ctx->omode || a->bits != ctx->obits) {
98  cs_close(&ctx->cd);
99  ctx->cd = 0; // unnecessary
100  ctx->omode = mode;
101  ctx->obits = a->bits;
102  }
103 
104  if (a->cpu) {
105  if (strstr(a->cpu, "cortex")) {
106  mode |= CS_MODE_MCLASS;
107  }
108  if (a->bits != 64) {
109  if (strstr(a->cpu, "v8")) {
110  mode |= CS_MODE_V8;
111  }
112  }
113  }
114  if (a->features && a->bits != 64) {
115  if (strstr(a->features, "v8")) {
116  mode |= CS_MODE_V8;
117  }
118  }
119  if (op) {
120  op->size = 4;
121  rz_strbuf_set(&op->buf_asm, "");
122  }
123  if (!ctx->cd || mode != ctx->omode) {
124  ret = (a->bits == 64) ? cs_open(CS_ARCH_ARM64, mode, &ctx->cd) : cs_open(CS_ARCH_ARM, mode, &ctx->cd);
125  if (ret) {
126  ret = -1;
127  goto beach;
128  }
129  }
131  cs_option(ctx->cd, CS_OPT_DETAIL, (a->features && *a->features) ? CS_OPT_ON : CS_OPT_OFF);
133  if (!buf) {
134  goto beach;
135  }
136  int haa = hackyArmAsm(a, op, buf, len);
137  if (haa > 0) {
138  return haa;
139  }
140 
141  n = cs_disasm(ctx->cd, buf, RZ_MIN(4, len), a->pc, 1, &insn);
142  if (n < 1 || insn->size < 1) {
143  ret = -1;
144  goto beach;
145  }
146  if (op) {
147  op->size = 0;
148  }
149  if (a->features && *a->features) {
150  if (!check_features(a, insn) && op) {
151  op->size = insn->size;
152  rz_strbuf_set(&op->buf_asm, "illegal");
153  }
154  }
155  if (op && !op->size) {
156  op->size = insn->size;
157  if (insn->id == ARM_INS_IT) {
158  rz_arm_it_update_block(&ctx->it, insn);
159  } else {
160  rz_arm_it_update_nonblock(&ctx->it, insn);
161  }
162  if (thumb && rz_arm_it_apply_cond(&ctx->it, insn)) {
163  char *tmpstr = rz_str_newf("%s%s",
164  cs_insn_name(ctx->cd, insn->id),
165  cc_name(insn->detail->arm.cc));
166  rz_str_cpy(insn->mnemonic, tmpstr);
167  free(tmpstr);
168  }
169  char *buf_asm = sdb_fmt("%s%s%s",
170  insn->mnemonic,
171  insn->op_str[0] ? " " : "",
172  insn->op_str);
173  if (!disp_hash) {
174  rz_str_replace_char(buf_asm, '#', 0);
175  }
176  rz_strbuf_set(&op->buf_asm, buf_asm);
177  }
178  cs_free(insn, n);
179 beach:
180  cs_close(&ctx->cd);
181  if (op) {
182  if (!*rz_strbuf_get(&op->buf_asm)) {
183  rz_strbuf_set(&op->buf_asm, "invalid");
184  }
185  return op->size;
186  }
187  return ret;
188 }
size_t len
Definition: 6502dis.c:15
RZ_API void rz_arm_it_update_nonblock(RzArmITContext *ctx, cs_insn *insn)
Definition: arm_it.c:70
RZ_API bool rz_arm_it_apply_cond(RzArmITContext *ctx, cs_insn *insn)
Definition: arm_it.c:87
RZ_API void rz_arm_it_update_block(RzArmITContext *ctx, cs_insn *insn)
Definition: arm_it.c:34
static const char * cc_name(arm_cc cc)
Definition: asm_arm_cs.c:51
static bool check_features(RzAsm *a, cs_insn *insn)
Definition: asm_arm_cs.c:21
@ ARM_INS_IT
Definition: arm.h:857
@ CS_ARCH_ARM64
ARM-64, also called AArch64.
Definition: capstone.h:76
@ CS_ARCH_ARM
ARM architecture (including Thumb, Thumb-2)
Definition: capstone.h:75
cs_mode
Mode type.
Definition: capstone.h:102
@ CS_MODE_MCLASS
ARM's Cortex-M series.
Definition: capstone.h:109
@ CS_MODE_ARM
32-bit ARM
Definition: capstone.h:104
@ CS_MODE_V8
ARMv8 A32 encodings for ARM.
Definition: capstone.h:110
@ CS_MODE_BIG_ENDIAN
big-endian mode
Definition: capstone.h:123
@ CS_MODE_THUMB
ARM's Thumb mode, including Thumb-2.
Definition: capstone.h:108
@ CS_MODE_LITTLE_ENDIAN
little-endian mode (default mode)
Definition: capstone.h:103
@ CS_OPT_DETAIL
Break down instruction structure into details.
Definition: capstone.h:171
@ CS_OPT_SYNTAX
Assembly output syntax.
Definition: capstone.h:170
@ CS_OPT_SYNTAX_NOREGNAME
Prints register name with only number (CS_OPT_SYNTAX)
Definition: capstone.h:187
@ CS_OPT_ON
Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
Definition: capstone.h:183
@ CS_OPT_OFF
Turn OFF an option - default for CS_OPT_DETAIL, CS_OPT_SKIPDATA, CS_OPT_UNSIGNED.
Definition: capstone.h:182
@ CS_OPT_SYNTAX_DEFAULT
Default asm syntax (CS_OPT_SYNTAX).
Definition: capstone.h:184
#define NULL
Definition: cris-opc.c:27
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)
Definition: cs.c:798
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: cs.c:453
CAPSTONE_EXPORT const char *CAPSTONE_API cs_insn_name(csh ud, unsigned int insn)
Definition: cs.c:1166
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
Definition: cs.c:1017
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
Definition: cs.c:646
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
voidpf void uLong size
Definition: ioapi.h:138
const char int mode
Definition: ioapi.h:137
int n
Definition: mipsasm.c:19
@ RZ_ASM_SYNTAX_REGNUM
Definition: rz_asm.h:53
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define rz_str_cpy(x, y)
Definition: rz_str.h:109
RZ_API int rz_str_replace_char(char *s, int a, int b)
Definition: str.c:169
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
#define RZ_MIN(x, y)

References a, ARM_INS_IT, cc_name(), check_features(), CS_ARCH_ARM, CS_ARCH_ARM64, cs_close(), cs_disasm(), cs_free(), cs_insn_name(), CS_MODE_ARM, CS_MODE_BIG_ENDIAN, CS_MODE_LITTLE_ENDIAN, CS_MODE_MCLASS, CS_MODE_THUMB, CS_MODE_V8, cs_open(), CS_OPT_DETAIL, CS_OPT_OFF, CS_OPT_ON, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT, CS_OPT_SYNTAX_NOREGNAME, cs_option(), free(), len, n, NULL, rz_arm_it_apply_cond(), rz_arm_it_update_block(), rz_arm_it_update_nonblock(), RZ_ASM_SYNTAX_REGNUM, RZ_MIN, rz_str_cpy, rz_str_newf(), rz_str_replace_char(), rz_strbuf_get(), rz_strbuf_set(), and sdb_fmt().

◆ mnemonics()

static char* mnemonics ( RzAsm a,
int  id,
bool  json 
)
static

Definition at line 261 of file asm_arm_cs.c.

261  {
262  ArmCSContext *ctx = (ArmCSContext *)a->plugin_data;
263  int i;
264  a->cur->disassemble(a, NULL, NULL, -1);
265  if (id != -1) {
266  const char *name = cs_insn_name(ctx->cd, id);
267  if (json) {
268  return name ? rz_str_newf("[\"%s\"]\n", name) : NULL;
269  }
270  return name ? strdup(name) : NULL;
271  }
272  RzStrBuf *buf = rz_strbuf_new("");
273  if (json) {
274  rz_strbuf_append(buf, "[");
275  }
276  for (i = 1;; i++) {
277  const char *op = cs_insn_name(ctx->cd, i);
278  if (!op) {
279  break;
280  }
281  if (json) {
282  rz_strbuf_append(buf, "\"");
283  }
285  if (json) {
286  if (cs_insn_name(ctx->cd, i + 1)) {
287  rz_strbuf_append(buf, "\",");
288  } else {
289  rz_strbuf_append(buf, "\"]\n");
290  }
291  } else {
292  rz_strbuf_append(buf, "\n");
293  }
294  }
295  return rz_strbuf_drain(buf);
296 }
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8

References a, cs_insn_name(), i, NULL, rz_str_newf(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), and strdup().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_arm_cs
Definition: asm_arm_cs.c:298
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_asm.h:133

Definition at line 323 of file asm_arm_cs.c.

◆ rz_asm_plugin_arm_cs

RzAsmPlugin rz_asm_plugin_arm_cs
Initial value:
= {
.name = "arm",
.desc = "Capstone ARM disassembler",
.cpus = "v8,cortex,arm1176,cortexA72,cortexA8",
.platforms = "bcm2835,omap3430",
.features = "v8",
.license = "BSD",
.arch = "arm",
.bits = 16 | 32 | 64,
.disassemble = &disassemble,
.mnemonics = mnemonics,
.assemble = &assemble,
.init = &arm_init,
.fini = &arm_fini,
}
static bool arm_init(void **user)
Definition: asm_arm_cs.c:239
static char * mnemonics(RzAsm *a, int id, bool json)
Definition: asm_arm_cs.c:261
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_arm_cs.c:86
static bool arm_fini(void *user)
Definition: asm_arm_cs.c:252
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf)
Definition: asm_arm_cs.c:190
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526

Definition at line 298 of file asm_arm_cs.c.