Rizin
unix-like reverse engineering framework and cli tools
acode.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2019 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <stdio.h>
5 #include <rz_asm.h>
6 
8  return RZ_NEW0(RzAsmCode);
9 }
10 
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 }
20 
22  if (equ) {
23  free(equ->key);
24  free(equ->value);
25  free(equ);
26  }
27 }
28 
29 static RzAsmEqu *__asm_equ_new(const char *key, const char *value) {
30  RzAsmEqu *equ = RZ_NEW0(RzAsmEqu);
31  if (equ) {
32  equ->key = strdup(key);
33  equ->value = strdup(value);
34  }
35  return equ;
36 }
37 
38 RZ_API bool rz_asm_code_set_equ(RzAsmCode *code, const char *key, const char *value) {
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 }
57 
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 }
67 
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 }
static RzAsmEqu * __asm_equ_new(const char *key, const char *value)
Definition: acode.c:29
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
Definition: acode.c:11
RZ_API bool rz_asm_code_set_equ(RzAsmCode *code, const char *key, const char *value)
Definition: acode.c:38
RZ_API void rz_asm_equ_item_free(RzAsmEqu *equ)
Definition: acode.c:21
RZ_API RzAsmCode * rz_asm_code_new(void)
Definition: acode.c:7
RZ_API char * rz_asm_code_get_hex(RzAsmCode *acode)
Definition: acode.c:68
RZ_API char * rz_asm_code_equ_replace(RzAsmCode *code, char *str)
Definition: acode.c:58
static int value
Definition: cmd_api.c:93
#define RZ_API
#define NULL
Definition: cris-opc.c:27
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
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
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")
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
#define RZ_NEW0(x)
Definition: rz_types.h:284
char * key
Definition: rz_asm.h:93
char * value
Definition: rz_asm.h:94
Definition: inftree9.h:24
char * assembly
Definition: rz_asm.h:81
ut8 * bytes
Definition: rz_asm.h:80
RzList * equs
Definition: rz_asm.h:85