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

Go to the source code of this file.

Functions

RZ_API RzAsmCoderz_asm_code_new (void)
 
RZ_API void * rz_asm_code_free (RzAsmCode *acode)
 
RZ_API void rz_asm_equ_item_free (RzAsmEqu *equ)
 
static RzAsmEqu__asm_equ_new (const char *key, const char *value)
 
RZ_API bool rz_asm_code_set_equ (RzAsmCode *code, const char *key, const char *value)
 
RZ_API char * rz_asm_code_equ_replace (RzAsmCode *code, char *str)
 
RZ_API char * rz_asm_code_get_hex (RzAsmCode *acode)
 

Function Documentation

◆ __asm_equ_new()

static RzAsmEqu* __asm_equ_new ( const char *  key,
const char *  value 
)
static

Definition at line 29 of file acode.c.

29  {
30  RzAsmEqu *equ = RZ_NEW0(RzAsmEqu);
31  if (equ) {
32  equ->key = strdup(key);
33  equ->value = strdup(value);
34  }
35  return equ;
36 }
static int value
Definition: cmd_api.c:93
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 static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
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")
#define RZ_NEW0(x)
Definition: rz_types.h:284
char * key
Definition: rz_asm.h:93
char * value
Definition: rz_asm.h:94

References RzAsmEqu::key, key, RZ_NEW0, strdup(), value, and RzAsmEqu::value.

Referenced by rz_asm_code_set_equ().

◆ rz_asm_code_equ_replace()

RZ_API char* rz_asm_code_equ_replace ( RzAsmCode code,
char *  str 
)

Definition at line 58 of file acode.c.

58  {
60  RzAsmEqu *equ;
62  rz_list_foreach (code->equs, iter, equ) {
63  str = rz_str_replace(str, equ->key, equ->value, true);
64  }
65  return str;
66 }
#define NULL
Definition: cris-opc.c:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
Definition: inftree9.h:24

References RzAsmEqu::key, NULL, rz_return_val_if_fail, rz_str_replace(), cmd_descs_generate::str, and RzAsmEqu::value.

Referenced by rz_asm_massemble().

◆ rz_asm_code_free()

RZ_API void* rz_asm_code_free ( RzAsmCode acode)

Definition at line 11 of file acode.c.

11  {
12  if (acode) {
13  rz_list_free(acode->equs);
14  free(acode->bytes);
15  free(acode->assembly);
16  free(acode);
17  }
18  return NULL;
19 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
char * assembly
Definition: rz_asm.h:81
ut8 * bytes
Definition: rz_asm.h:80
RzList * equs
Definition: rz_asm.h:85

References rz_asm_code_t::assembly, rz_asm_code_t::bytes, rz_asm_code_t::equs, free(), NULL, and rz_list_free().

Referenced by rasm_asm(), rasm_disasm(), readline_callback(), rz_asm_from_string(), rz_asm_massemble(), rz_asm_mdisassemble(), rz_asm_to_string(), rz_cmd_debug(), rz_core_asm_bwdisassemble(), rz_core_asm_search(), rz_core_assembly_of_hex(), rz_core_esil_of_assembly(), rz_core_hex_of_assembly(), rz_core_visual_asm(), rz_core_write_assembly(), rz_core_write_assembly_fill(), and rz_egg_assemble_asm().

◆ rz_asm_code_get_hex()

RZ_API char* rz_asm_code_get_hex ( RzAsmCode acode)

Definition at line 68 of file acode.c.

68  {
70  char *str = calloc(acode->len + 1, 2);
71  if (str) {
72  rz_hex_bin2str(acode->bytes, acode->len, str);
73  }
74  return str;
75 }
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

References rz_asm_code_t::bytes, calloc(), rz_asm_code_t::len, NULL, rz_hex_bin2str(), rz_return_val_if_fail, and cmd_descs_generate::str.

Referenced by rasm_asm(), readline_callback(), and rz_core_asm_search().

◆ rz_asm_code_new()

RZ_API RzAsmCode* rz_asm_code_new ( void  )

Definition at line 7 of file acode.c.

7  {
8  return RZ_NEW0(RzAsmCode);
9 }

References RZ_NEW0.

Referenced by rz_asm_massemble(), and rz_asm_mdisassemble().

◆ rz_asm_code_set_equ()

RZ_API bool rz_asm_code_set_equ ( RzAsmCode code,
const char *  key,
const char *  value 
)

Definition at line 38 of file acode.c.

38  {
39  rz_return_val_if_fail(code && key && value, false);
40 
41  if (code->equs) {
42  RzAsmEqu *equ;
44  rz_list_foreach (code->equs, iter, equ) {
45  if (!strcmp(equ->key, key)) {
46  free(equ->value);
47  equ->value = strdup(value);
48  return true;
49  }
50  }
51  } else {
53  }
55  return true;
56 }
static RzAsmEqu * __asm_equ_new(const char *key, const char *value)
Definition: acode.c:29
RZ_API void rz_asm_equ_item_free(RzAsmEqu *equ)
Definition: acode.c:21
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11

References __asm_equ_new(), free(), RzAsmEqu::key, key, rz_asm_equ_item_free(), rz_list_append(), rz_list_newf(), rz_return_val_if_fail, strdup(), value, and RzAsmEqu::value.

Referenced by rz_asm_massemble().

◆ rz_asm_equ_item_free()

RZ_API void rz_asm_equ_item_free ( RzAsmEqu equ)

Definition at line 21 of file acode.c.

21  {
22  if (equ) {
23  free(equ->key);
24  free(equ->value);
25  free(equ);
26  }
27 }

References free(), RzAsmEqu::key, and RzAsmEqu::value.

Referenced by rz_asm_code_set_equ().