Rizin
unix-like reverse engineering framework and cli tools
bin_bf.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>

Go to the source code of this file.

Functions

static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
 
static void destroy (RzBinFile *bf)
 
static ut64 baddr (RzBinFile *bf)
 
static RzListstrings (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static bool check_buffer (RzBuffer *buf)
 
static bool check_filename (const char *filename)
 
static RzListentries (RzBinFile *bf)
 
static RzListmaps (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_bf
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 17 of file bin_bf.c.

17  {
18  return 0;
19 }

◆ check_buffer()

static bool check_buffer ( RzBuffer buf)
static

Definition at line 65 of file bin_bf.c.

65  {
66  rz_return_val_if_fail(buf, false);
67 
68  ut8 tmp[16];
69  int read_length = rz_buf_read_at(buf, 0, tmp, sizeof(tmp));
70  if (read_length <= 0) {
71  return false;
72  }
73 
74  const ut8 *p = (const ut8 *)tmp;
75  int i;
76  for (i = 0; i < read_length; i++) {
77  switch (p[i]) {
78  case '+':
79  case '-':
80  case '>':
81  case '<':
82  case '[':
83  case ']':
84  case ',':
85  case '.':
86  case ' ':
87  case '\n':
88  case '\r':
89  break;
90  default:
91  return false;
92  }
93  }
94  return true;
95 }
lzma_index ** i
Definition: index.h:629
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136

References i, p, rz_buf_read_at(), rz_return_val_if_fail, and autogen_x86imm::tmp.

◆ check_filename()

static bool check_filename ( const char *  filename)
static

Definition at line 97 of file bin_bf.c.

97  {
98  return rz_str_endswith_icase(filename, ".bf");
99 }
const char * filename
Definition: ioapi.h:137
RZ_API bool rz_str_endswith_icase(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case insensitive)
Definition: str.c:3340

References rz_str_endswith_icase().

◆ destroy()

static void destroy ( RzBinFile bf)
static

Definition at line 13 of file bin_bf.c.

13  {
14  rz_buf_free(bf->o->bin_obj);
15 }
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RzBinObject * o
Definition: rz_bin.h:305
void * bin_obj
Definition: rz_bin.h:293

References rz_bin_object_t::bin_obj, rz_bin_file_t::o, and rz_buf_free().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 101 of file bin_bf.c.

101  {
102  RzList *ret;
103  RzBinAddr *ptr = NULL;
104 
105  if (!(ret = rz_list_newf(free))) {
106  return NULL;
107  }
108  if (!(ptr = RZ_NEW0(RzBinAddr))) {
109  return ret;
110  }
111  ptr->paddr = ptr->vaddr = 0;
112  rz_list_append(ret, ptr);
113  return ret;
114 }
#define NULL
Definition: cris-opc.c:27
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
#define RZ_NEW0(x)
Definition: rz_types.h:284
ut64 vaddr
Definition: rz_bin.h:186
ut64 paddr
Definition: rz_bin.h:187

References free(), NULL, rz_bin_addr_t::paddr, rz_list_append(), rz_list_newf(), RZ_NEW0, and rz_bin_addr_t::vaddr.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 25 of file bin_bf.c.

25  {
26  RzBinInfo *ret = NULL;
27  if (!(ret = RZ_NEW0(RzBinInfo))) {
28  return NULL;
29  }
30  ret->lang = NULL;
31  ret->file = bf->file ? strdup(bf->file) : NULL;
32  ret->type = strdup("brainfuck");
33  ret->bclass = strdup("1.0");
34  ret->rclass = strdup("program");
35  ret->os = strdup("any");
36  ret->subsystem = strdup("unknown");
37  ret->machine = strdup("brainfuck");
38  ret->arch = strdup("bf");
39  ret->has_va = 1;
40  ret->bits = 64; // RzIL emulation of bf uses 64bit values
41  ret->big_endian = 0;
42  ret->dbg_info = 0;
43 
44  RZ_LOG_INFO("Brainfuck debugger setup:\n"
45  "f input 128 @ 0x3000\n"
46  "o malloc://128 0x3000\n"
47  "f screen 80*25 @ 0x4000\n"
48  "o malloc://80*25 0x4000\n"
49  "f stack 0x200 @ 0x5000\n"
50  "o malloc://0x200 0x5000\n"
51  "f data 0x1000 @ 0x6000\n"
52  "o malloc://0x1000 0x6000\n"
53  "ar\n" // hack to init
54  "ar brk=stack\n"
55  "ar scr=screen\n"
56  "ar kbd=input\n"
57  "ar ptr=data\n"
58  "e cmd.vprompt=\"pxa 32@stack;pxa 32@screen;pxa 32@data\"\n"
59  "s 0\n"
60  "e asm.bits=32\n"
61  "dL bf\n");
62  return ret;
63 }
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_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
char * file
Definition: rz_bin.h:299
int has_va
Definition: rz_bin.h:228
char * type
Definition: rz_bin.h:211
char * os
Definition: rz_bin.h:219
char * subsystem
Definition: rz_bin.h:220
char * machine
Definition: rz_bin.h:216
const char * lang
Definition: rz_bin.h:224
char * bclass
Definition: rz_bin.h:212
char * file
Definition: rz_bin.h:210
ut64 dbg_info
Definition: rz_bin.h:240
char * rclass
Definition: rz_bin.h:213
char * arch
Definition: rz_bin.h:214
int big_endian
Definition: rz_bin.h:235

References rz_bin_info_t::arch, rz_bin_info_t::bclass, rz_bin_info_t::big_endian, rz_bin_info_t::bits, rz_bin_info_t::dbg_info, rz_bin_info_t::file, rz_bin_file_t::file, rz_bin_info_t::has_va, rz_bin_info_t::lang, rz_bin_info_t::machine, NULL, rz_bin_info_t::os, rz_bin_info_t::rclass, RZ_LOG_INFO, RZ_NEW0, strdup(), rz_bin_info_t::subsystem, and rz_bin_info_t::type.

◆ load_buffer()

static bool load_buffer ( RzBinFile bf,
RzBinObject obj,
RzBuffer buf,
Sdb sdb 
)
static

Definition at line 9 of file bin_bf.c.

9  {
10  return true;
11 }

◆ maps()

static RzList* maps ( RzBinFile bf)
static

Definition at line 116 of file bin_bf.c.

116  {
118  if (!ret) {
119  return NULL;
120  }
121 
123  if (!map) {
124  rz_list_free(ret);
125  return NULL;
126  }
127  map->paddr = 0;
128  map->vaddr = 0;
129  map->psize = bf->size;
130  map->vsize = bf->size;
131  map->perm = RZ_PERM_RWX;
132  map->name = strdup("code");
133  rz_list_append(ret, map);
134 
135  map = RZ_NEW0(RzBinMap);
136  if (!map) {
137  rz_list_free(ret);
138  return NULL;
139  }
140  map->paddr = 0;
141  map->vaddr = 0x10000;
142  map->psize = 0;
143  map->vsize = 30000;
144  map->perm = RZ_PERM_RW;
145  map->name = strdup("mem");
146  rz_list_append(ret, map);
147  return ret;
148 }
RZ_API void rz_bin_map_free(RzBinMap *map)
Definition: bin.c:1023
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_PERM_RW
Definition: rz_types.h:96
#define RZ_PERM_RWX
Definition: rz_types.h:98
Description of a single memory mapping into virtual memory from a binary.
Definition: rz_bin.h:602

References map(), NULL, rz_bin_map_free(), rz_list_append(), rz_list_free(), rz_list_newf(), RZ_NEW0, RZ_PERM_RW, RZ_PERM_RWX, rz_bin_file_t::size, and strdup().

Referenced by __core_visual_gogo(), apply_maps_as_flags(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), findMinMax(), get_brks(), map_cpu_memory(), open_maps_list(), populate_cache_maps(), print_debug_maps_ascii_art(), read_cache_accel(), reloc_targets_map_base(), rz_bin_object_p2v_all(), rz_bin_relocs_patch_find_targets_map_base(), rz_bin_relocs_patch_maps(), rz_bin_sections_of_maps(), rz_core_analysis_address(), rz_core_analysis_code_count(), rz_core_analysis_coverage_count(), rz_core_bin_apply_maps(), rz_core_bin_sections_mapping_print(), rz_core_cmd_foreach3(), rz_core_debug_map_print(), rz_core_debug_map_update_flags(), rz_core_get_boundaries_prot(), rz_core_io_file_reopen(), rz_core_raw_file_print(), rz_core_visual_cmd(), rz_debug_dmp_maps(), rz_debug_map_list_visual(), rz_debug_winkd_maps(), rz_heap_resolve_main_arena(), rz_io_map_remap_fd(), rz_io_resize(), rz_main_rizin(), rz_open_maps_flags_global_handler(), rz_open_maps_list_ascii_handler(), RZ_PACKED(), va2pa(), and winkd_list_maps().

◆ strings()

static RzList* strings ( RzBinFile bf)
static

Definition at line 21 of file bin_bf.c.

21  {
22  return NULL;
23 }

References NULL.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
.data = &rz_bin_plugin_bf,
}
RzBinPlugin rz_bin_plugin_bf
Definition: bin_bf.c:150
@ RZ_LIB_TYPE_BIN
Definition: rz_lib.h:75
#define RZ_VERSION
Definition: rz_version.h:8
char * version
Definition: rz_bin.h:512

Definition at line 166 of file bin_bf.c.

◆ rz_bin_plugin_bf

RzBinPlugin rz_bin_plugin_bf
Initial value:
= {
.name = "bf",
.desc = "brainfuck",
.license = "LGPL3",
.load_buffer = &load_buffer,
.destroy = &destroy,
.check_buffer = &check_buffer,
.check_filename = &check_filename,
.baddr = &baddr,
.entries = entries,
.strings = &strings,
.maps = &maps,
.info = &info,
}
static bool check_buffer(RzBuffer *buf)
Definition: bin_bf.c:65
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: bin_bf.c:9
static RzList * strings(RzBinFile *bf)
Definition: bin_bf.c:21
static void destroy(RzBinFile *bf)
Definition: bin_bf.c:13
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_bf.c:25
static ut64 baddr(RzBinFile *bf)
Definition: bin_bf.c:17
static RzList * entries(RzBinFile *bf)
Definition: bin_bf.c:101
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116
static bool check_filename(const char *filename)
Definition: bin_bf.c:97

Definition at line 150 of file bin_bf.c.