Rizin
unix-like reverse engineering framework and cli tools
aop.c File Reference
#include <rz_asm.h>

Go to the source code of this file.

Functions

RZ_API RzAsmOprz_asm_op_new (void)
 
RZ_API void rz_asm_op_free (RzAsmOp *op)
 
RZ_API void rz_asm_op_init (RzAsmOp *op)
 
RZ_API void rz_asm_op_fini (RzAsmOp *op)
 
RZ_API char * rz_asm_op_get_hex (RzAsmOp *op)
 
RZ_API char * rz_asm_op_get_asm (RzAsmOp *op)
 
RZ_API ut8rz_asm_op_get_buf (RzAsmOp *op)
 
RZ_API int rz_asm_op_get_size (RzAsmOp *op)
 
RZ_API void rz_asm_op_set_asm (RzAsmOp *op, const char *str)
 
RZ_API int rz_asm_op_set_hex (RzAsmOp *op, const char *str)
 
RZ_API int rz_asm_op_set_hexbuf (RzAsmOp *op, const ut8 *buf, int len)
 
RZ_API void rz_asm_op_set_buf (RzAsmOp *op, const ut8 *buf, int len)
 

Function Documentation

◆ rz_asm_op_fini()

RZ_API void rz_asm_op_fini ( RzAsmOp op)

Definition at line 21 of file aop.c.

21  {
22  rz_strbuf_fini(&op->buf);
23  rz_strbuf_fini(&op->buf_asm);
24  rz_buf_fini(op->buf_inc);
25 }
RZ_API bool rz_buf_fini(RzBuffer *b)
Free all internal data hold by the buffer.
Definition: buf.c:822
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
Definition: dis.c:32

References rz_buf_fini(), and rz_strbuf_fini().

Referenced by construct_rop_gadget(), ds_disassemble(), ds_free(), rz_asm_massemble(), rz_asm_mdisassemble(), rz_asm_op_free(), rz_core_analysis_op(), rz_core_asm_strsearch(), rz_core_op_str(), and setprintmode().

◆ rz_asm_op_free()

RZ_API void rz_asm_op_free ( RzAsmOp op)

Definition at line 10 of file aop.c.

10  {
12  free(op);
13 }
RZ_API void rz_asm_op_fini(RzAsmOp *op)
Definition: aop.c:21
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free(), and rz_asm_op_fini().

◆ rz_asm_op_get_asm()

◆ rz_asm_op_get_buf()

RZ_API ut8* rz_asm_op_get_buf ( RzAsmOp op)

Definition at line 42 of file aop.c.

42  {
44  return (ut8 *)rz_strbuf_get(&op->buf);
45 }
uint8_t ut8
Definition: lh5801.h:11

References NULL, rz_return_val_if_fail, and rz_strbuf_get().

◆ rz_asm_op_get_hex()

RZ_API char* rz_asm_op_get_hex ( RzAsmOp op)

Definition at line 28 of file aop.c.

28  {
30  int size = rz_strbuf_length(&op->buf);
31  char *str = calloc(size + 1, 2);
33  rz_hex_bin2str((const ut8 *)rz_strbuf_get(&op->buf), size, str);
34  return str;
35 }
voidpf void uLong size
Definition: ioapi.h:138
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
RZ_API int rz_strbuf_length(RzStrBuf *sb)
Definition: strbuf.c:28

References calloc(), NULL, rz_hex_bin2str(), rz_return_val_if_fail, rz_strbuf_get(), rz_strbuf_length(), and cmd_descs_generate::str.

Referenced by ds_disassemble(), ds_print_show_bytes(), print_rop(), rasm_disasm(), rz_core_analysis_bytes(), rz_core_disasm_pdi_with_buf(), rz_core_print_disasm_all(), rz_core_visual_bit_editor(), and rz_core_visual_esil().

◆ rz_asm_op_get_size()

RZ_API int rz_asm_op_get_size ( RzAsmOp op)

Definition at line 47 of file aop.c.

47  {
49  const int len = op->size - op->payload;
50  return RZ_MAX(1, len);
51 }
size_t len
Definition: 6502dis.c:15
#define RZ_MAX(x, y)

References len, RZ_MAX, and rz_return_val_if_fail.

Referenced by ds_disassemble(), and rz_core_analysis_bytes().

◆ rz_asm_op_init()

RZ_API void rz_asm_op_init ( RzAsmOp op)

Definition at line 15 of file aop.c.

15  {
16  if (op) {
17  memset(op, 0, sizeof(*op));
18  }
19 }
return memset(p, 0, total)

References memset().

Referenced by rz_asm_disassemble(), rz_asm_massemble(), rz_asm_mdisassemble(), rz_core_analysis_op(), and setprintmode().

◆ rz_asm_op_new()

RZ_API RzAsmOp* rz_asm_op_new ( void  )

Definition at line 6 of file aop.c.

6  {
7  return RZ_NEW0(RzAsmOp);
8 }
#define RZ_NEW0(x)
Definition: rz_types.h:284

References RZ_NEW0.

◆ rz_asm_op_set_asm()

RZ_API void rz_asm_op_set_asm ( RzAsmOp op,
const char *  str 
)

◆ rz_asm_op_set_buf()

RZ_API void rz_asm_op_set_buf ( RzAsmOp op,
const ut8 buf,
int  len 
)

Definition at line 83 of file aop.c.

83  {
84  rz_return_if_fail(op && buf && len >= 0);
85  rz_strbuf_setbin(&op->buf, buf, len);
87 }
RZ_API int rz_asm_op_set_hexbuf(RzAsmOp *op, const ut8 *buf, int len)
Definition: aop.c:71
voidpf void * buf
Definition: ioapi.h:138
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
Definition: strbuf.c:85

References len, rz_asm_op_set_hexbuf(), rz_return_if_fail, and rz_strbuf_setbin().

Referenced by assemble(), rz_asm_assemble(), rz_asm_disassemble(), rz_asm_pseudo_byte(), and rz_asm_pseudo_fill().

◆ rz_asm_op_set_hex()

RZ_API int rz_asm_op_set_hex ( RzAsmOp op,
const char *  str 
)

Definition at line 58 of file aop.c.

58  {
59  ut8 *bin = (ut8 *)strdup(str);
60  if (bin) {
61  int len = rz_hex_str2bin(str, bin);
62  if (len > 0) {
63  rz_strbuf_setbin(&op->buf, bin, len);
64  }
65  free(bin);
66  return len;
67  }
68  return 0;
69 }
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 int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
Definition: malloc.c:26

References free(), len, rz_hex_str2bin(), rz_strbuf_setbin(), cmd_descs_generate::str, and strdup().

Referenced by rz_asm_massemble(), and rz_asm_op_set_hexbuf().

◆ rz_asm_op_set_hexbuf()

RZ_API int rz_asm_op_set_hexbuf ( RzAsmOp op,
const ut8 buf,
int  len 
)

Definition at line 71 of file aop.c.

71  {
72  rz_return_val_if_fail(op && buf && len >= 0, 0);
73  char *hex = malloc(len * 4 + 1);
74  if (hex) {
75  (void)rz_hex_bin2str(buf, len, hex);
76  int olen = rz_asm_op_set_hex(op, hex);
77  free(hex);
78  return olen;
79  }
80  return 0;
81 }
RZ_API int rz_asm_op_set_hex(RzAsmOp *op, const char *str)
Definition: aop.c:58
void * malloc(size_t size)
Definition: malloc.c:123
static const char hex[16]
Definition: print.c:21

References free(), hex, len, malloc(), rz_asm_op_set_hex(), rz_hex_bin2str(), and rz_return_val_if_fail.

Referenced by ds_disassemble(), and rz_asm_op_set_buf().