Rizin
unix-like reverse engineering framework and cli tools
aop.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2018-2020 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_asm.h>
5 
7  return RZ_NEW0(RzAsmOp);
8 }
9 
12  free(op);
13 }
14 
16  if (op) {
17  memset(op, 0, sizeof(*op));
18  }
19 }
20 
22  rz_strbuf_fini(&op->buf);
23  rz_strbuf_fini(&op->buf_asm);
24  rz_buf_fini(op->buf_inc);
25 }
26 
27 // accessors
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 }
36 
39  return rz_strbuf_get(&op->buf_asm);
40 }
41 
44  return (ut8 *)rz_strbuf_get(&op->buf);
45 }
46 
49  const int len = op->size - op->payload;
50  return RZ_MAX(1, len);
51 }
52 
53 RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str) {
55  rz_strbuf_set(&op->buf_asm, str);
56 }
57 
58 RZ_API int rz_asm_op_set_hex(RzAsmOp *op, const char *str) {
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 }
70 
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 }
82 
83 RZ_API void rz_asm_op_set_buf(RzAsmOp *op, const ut8 *buf, int len) {
84  rz_return_if_fail(op && buf && len >= 0);
85  rz_strbuf_setbin(&op->buf, buf, len);
87 }
size_t len
Definition: 6502dis.c:15
RZ_API int rz_asm_op_get_size(RzAsmOp *op)
Definition: aop.c:47
RZ_API void rz_asm_op_fini(RzAsmOp *op)
Definition: aop.c:21
RZ_API void rz_asm_op_set_buf(RzAsmOp *op, const ut8 *buf, int len)
Definition: aop.c:83
RZ_API void rz_asm_op_init(RzAsmOp *op)
Definition: aop.c:15
RZ_API int rz_asm_op_set_hexbuf(RzAsmOp *op, const ut8 *buf, int len)
Definition: aop.c:71
RZ_API RzAsmOp * rz_asm_op_new(void)
Definition: aop.c:6
RZ_API ut8 * rz_asm_op_get_buf(RzAsmOp *op)
Definition: aop.c:42
RZ_API char * rz_asm_op_get_hex(RzAsmOp *op)
Definition: aop.c:28
RZ_API void rz_asm_op_free(RzAsmOp *op)
Definition: aop.c:10
RZ_API int rz_asm_op_set_hex(RzAsmOp *op, const char *str)
Definition: aop.c:58
RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str)
Definition: aop.c:53
RZ_API char * rz_asm_op_get_asm(RzAsmOp *op)
Definition: aop.c:37
#define RZ_API
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
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")
static const char hex[16]
Definition: print.c:21
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_buf_fini(RzBuffer *b)
Free all internal data hold by the buffer.
Definition: buf.c:822
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
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
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
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
Definition: strbuf.c:85
RZ_API int rz_strbuf_length(RzStrBuf *sb)
Definition: strbuf.c:28
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_MAX(x, y)
Definition: malloc.c:26
Definition: dis.c:32