Rizin
unix-like reverse engineering framework and cli tools
bin_ningb.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>
#include <string.h>
#include "../format/nin/nin.h"

Go to the source code of this file.

Functions

static bool check_buffer (RzBuffer *b)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
 
static ut64 baddr (RzBinFile *bf)
 
static RzBinAddrbinsym (RzBinFile *bf, RzBinSpecialSymbol type)
 
static RzListentries (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzListsymbols (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
RzListmem (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_ningb
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 23 of file bin_ningb.c.

23  {
24  return 0LL;
25 }

◆ binsym()

static RzBinAddr* binsym ( RzBinFile bf,
RzBinSpecialSymbol  type 
)
static

Definition at line 27 of file bin_ningb.c.

27  {
28  if (type == RZ_BIN_SPECIAL_SYMBOL_MAIN && bf && bf->buf) {
29  ut8 init_jmp[4];
30  RzBinAddr *ret = RZ_NEW0(RzBinAddr);
31  if (!ret) {
32  return NULL;
33  }
34  rz_buf_read_at(bf->buf, 0x100, init_jmp, 4);
35  if (init_jmp[1] == 0xc3) {
36  ret->paddr = ret->vaddr = init_jmp[3] * 0x100 + init_jmp[2];
37  return ret;
38  }
39  free(ret);
40  }
41  return NULL;
42 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
int type
Definition: mipsasm.c:17
@ RZ_BIN_SPECIAL_SYMBOL_MAIN
Definition: rz_bin.h:139
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
#define RZ_NEW0(x)
Definition: rz_types.h:284
ut64 vaddr
Definition: rz_bin.h:186
ut64 paddr
Definition: rz_bin.h:187
RzBuffer * buf
Definition: rz_bin.h:303

References rz_bin_file_t::buf, free(), NULL, rz_bin_addr_t::paddr, RZ_BIN_SPECIAL_SYMBOL_MAIN, rz_buf_read_at(), RZ_NEW0, type, and rz_bin_addr_t::vaddr.

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 11 of file bin_ningb.c.

11  {
12  ut8 lict[sizeof(lic)];
13  if (rz_buf_read_at(b, 0x104, lict, sizeof(lict)) == sizeof(lict)) {
14  return !memcmp(lict, lic, sizeof(lict));
15  }
16  return false;
17 }
const ut8 lic[]
Definition: nin.h:62
#define b(i)
Definition: sha256.c:42

References b, lic, and rz_buf_read_at().

Referenced by load_buffer().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 44 of file bin_ningb.c.

44  {
45  RzList *ret = rz_list_new();
46  RzBinAddr *ptr = NULL;
47 
48  if (bf && bf->buf != NULL) {
49  if (!ret) {
50  return NULL;
51  }
52  ret->free = free;
53  if (!(ptr = RZ_NEW0(RzBinAddr))) {
54  return ret;
55  }
56  ptr->paddr = ptr->vaddr = ptr->hpaddr = 0x100;
57  rz_list_append(ret, ptr);
58  }
59  return ret;
60 }
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
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
ut64 hpaddr
Definition: rz_bin.h:189
RzListFree free
Definition: rz_list.h:21

References rz_bin_file_t::buf, rz_list_t::free, free(), rz_bin_addr_t::hpaddr, NULL, rz_bin_addr_t::paddr, rz_list_append(), rz_list_new(), RZ_NEW0, and rz_bin_addr_t::vaddr.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 158 of file bin_ningb.c.

158  {
159  ut8 rom_header[76];
160  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
161  if (!ret || !bf || !bf->buf) {
162  free(ret);
163  return NULL;
164  }
165  rz_buf_read_at(bf->buf, 0x104, rom_header, 76);
166  ret->file = rz_str_ndup((const char *)&rom_header[48], 16);
167  ret->type = malloc(128);
168  ret->type[0] = 0;
169  gb_get_gbtype(ret->type, rom_header[66], rom_header[63]);
170  gb_add_cardtype(ret->type, rom_header[67]); // XXX
171  ret->machine = strdup("Gameboy");
172  ret->os = strdup("any");
173  ret->arch = strdup("gb");
174  ret->has_va = true;
175  ret->bits = 16;
176  ret->big_endian = 0;
177  ret->dbg_info = 0;
178  return ret;
179 }
void * malloc(size_t size)
Definition: malloc.c:123
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")
void gb_get_gbtype(char *type, ut8 foo, ut8 bar)
Definition: nin.h:154
void gb_add_cardtype(char *type, ut8 cardcode)
Definition: nin.h:105
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
int has_va
Definition: rz_bin.h:228
char * type
Definition: rz_bin.h:211
char * os
Definition: rz_bin.h:219
char * machine
Definition: rz_bin.h:216
char * file
Definition: rz_bin.h:210
ut64 dbg_info
Definition: rz_bin.h:240
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::big_endian, rz_bin_info_t::bits, rz_bin_file_t::buf, rz_bin_info_t::dbg_info, rz_bin_info_t::file, free(), gb_add_cardtype(), gb_get_gbtype(), rz_bin_info_t::has_va, rz_bin_info_t::machine, malloc(), NULL, rz_bin_info_t::os, rz_buf_read_at(), RZ_NEW0, rz_str_ndup(), strdup(), and rz_bin_info_t::type.

◆ load_buffer()

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

Definition at line 19 of file bin_ningb.c.

19  {
20  return check_buffer(buf);
21 }
static bool check_buffer(RzBuffer *b)
Definition: bin_ningb.c:11
voidpf void * buf
Definition: ioapi.h:138

References check_buffer().

◆ mem()

RzList* mem ( RzBinFile bf)

Definition at line 181 of file bin_ningb.c.

181  {
182  RzList *ret;
183  RzBinMem *m, *n;
184  if (!(ret = rz_list_new())) {
185  return NULL;
186  }
187  ret->free = free;
188  if (!(m = RZ_NEW0(RzBinMem))) {
189  rz_list_free(ret);
190  return NULL;
191  }
192  m->name = strdup("fastram");
193  m->addr = 0xff80LL;
194  m->size = 0x80;
195  m->perms = rz_str_rwx("rwx");
196  rz_list_append(ret, m);
197 
198  if (!(m = RZ_NEW0(RzBinMem))) {
199  return ret;
200  }
201  m->name = strdup("ioports");
202  m->addr = 0xff00LL;
203  m->size = 0x4c;
204  m->perms = rz_str_rwx("rwx");
205  rz_list_append(ret, m);
206 
207  if (!(m = RZ_NEW0(RzBinMem))) {
208  return ret;
209  }
210  m->name = strdup("oam");
211  m->addr = 0xfe00LL;
212  m->size = 0xa0;
213  m->perms = rz_str_rwx("rwx");
214  rz_list_append(ret, m);
215 
216  if (!(m = RZ_NEW0(RzBinMem))) {
217  return ret;
218  }
219  m->name = strdup("videoram");
220  m->addr = 0x8000LL;
221  m->size = 0x2000;
222  m->perms = rz_str_rwx("rwx");
223  rz_list_append(ret, m);
224 
225  if (!(m = RZ_NEW0(RzBinMem))) {
226  return ret;
227  }
228  m->name = strdup("iram");
229  m->addr = 0xc000LL;
230  m->size = 0x2000;
231  m->perms = rz_str_rwx("rwx");
232  rz_list_append(ret, m);
233  if (!(m->mirrors = rz_list_new())) {
234  return ret;
235  }
236  if (!(n = RZ_NEW0(RzBinMem))) {
237  rz_list_free(m->mirrors);
238  m->mirrors = NULL;
239  return ret;
240  }
241  n->name = strdup("iram_echo");
242  n->addr = 0xe000LL;
243  n->size = 0x1e00;
244  n->perms = rz_str_rwx("rx");
245  rz_list_append(m->mirrors, n);
246 
247  return ret;
248 }
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
int n
Definition: mipsasm.c:19
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318

References rz_list_t::free, free(), regress::m, n, NULL, rz_list_append(), rz_list_free(), rz_list_new(), RZ_NEW0, rz_str_rwx(), and strdup().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 62 of file bin_ningb.c.

62  {
63  if (!bf || !bf->buf) {
64  return NULL;
65  }
67  if (!ret) {
68  return NULL;
69  }
70  ut8 bank_id;
71  rz_buf_read_at(bf->buf, 0x148, &bank_id, 1);
72  int banks_count = gb_get_rombanks(bank_id);
73  for (size_t i = 0; i < banks_count; i++) {
75  section->name = rz_str_newf("rombank%02x", (unsigned int)i);
76  section->paddr = i * 0x4000;
77  section->vaddr = i ? (i * 0x10000 - 0xc000) : 0;
78  section->size = section->vsize = 0x4000;
79  section->perm = rz_str_rwx("rx");
80  rz_list_append(ret, section);
81  }
82  return ret;
83 }
lzma_index ** i
Definition: index.h:629
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
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
int gb_get_rombanks(ut8 id)
Definition: nin.h:128
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
uint32_t size

References rz_bin_file_t::buf, gb_get_rombanks(), i, NULL, rz_bin_section_free(), rz_buf_read_at(), rz_list_append(), rz_list_newf(), RZ_NEW0, rz_str_newf(), rz_str_rwx(), and section::size.

◆ symbols()

static RzList* symbols ( RzBinFile bf)
static

Definition at line 85 of file bin_ningb.c.

85  {
86  RzList *ret = NULL;
87  RzBinSymbol *ptr[13];
88  int i;
90  return NULL;
91  }
92 
93  for (i = 0; i < 8; i++) {
94  if (!(ptr[i] = RZ_NEW0(RzBinSymbol))) {
95  ret->free(ret);
96  return NULL;
97  }
98  ptr[i]->name = rz_str_newf("rst_%i", i * 8);
99  ptr[i]->paddr = ptr[i]->vaddr = i * 8;
100  ptr[i]->size = 1;
101  ptr[i]->ordinal = i;
102  rz_list_append(ret, ptr[i]);
103  }
104 
105  if (!(ptr[8] = RZ_NEW0(RzBinSymbol))) {
106  return ret;
107  }
108 
109  ptr[8]->name = strdup("Interrupt_Vblank");
110  ptr[8]->paddr = ptr[8]->vaddr = 64;
111  ptr[8]->size = 1;
112  ptr[8]->ordinal = 8;
113  rz_list_append(ret, ptr[8]);
114 
115  if (!(ptr[9] = RZ_NEW0(RzBinSymbol))) {
116  return ret;
117  }
118 
119  ptr[9]->name = strdup("Interrupt_LCDC-Status");
120  ptr[9]->paddr = ptr[9]->vaddr = 72;
121  ptr[9]->size = 1;
122  ptr[9]->ordinal = 9;
123  rz_list_append(ret, ptr[9]);
124 
125  if (!(ptr[10] = RZ_NEW0(RzBinSymbol))) {
126  return ret;
127  }
128 
129  ptr[10]->name = strdup("Interrupt_Timer-Overflow");
130  ptr[10]->paddr = ptr[10]->vaddr = 80;
131  ptr[10]->size = 1;
132  ptr[10]->ordinal = 10;
133  rz_list_append(ret, ptr[10]);
134 
135  if (!(ptr[11] = RZ_NEW0(RzBinSymbol))) {
136  return ret;
137  }
138 
139  ptr[11]->name = strdup("Interrupt_Serial-Transfere");
140  ptr[11]->paddr = ptr[11]->vaddr = 88;
141  ptr[11]->size = 1;
142  ptr[11]->ordinal = 11;
143  rz_list_append(ret, ptr[11]);
144 
145  if (!(ptr[12] = RZ_NEW0(RzBinSymbol))) {
146  return ret;
147  }
148 
149  ptr[12]->name = strdup("Interrupt_Joypad");
150  ptr[12]->paddr = ptr[12]->vaddr = 96;
151  ptr[12]->size = 1;
152  ptr[12]->ordinal = 12;
153  rz_list_append(ret, ptr[12]);
154 
155  return ret;
156 }
RZ_API void rz_bin_symbol_free(RzBinSymbol *sym)
Definition: bin.c:175
char * name
Definition: rz_bin.h:675
ut32 ordinal
Definition: rz_bin.h:692

References rz_list_t::free, i, rz_bin_symbol_t::name, NULL, rz_bin_symbol_t::ordinal, rz_bin_symbol_t::paddr, rz_bin_symbol_free(), rz_list_append(), rz_list_newf(), RZ_NEW0, rz_str_newf(), rz_bin_symbol_t::size, strdup(), and rz_bin_symbol_t::vaddr.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_ningb
Definition: bin_ningb.c:250
@ 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 267 of file bin_ningb.c.

◆ rz_bin_plugin_ningb

RzBinPlugin rz_bin_plugin_ningb
Initial value:
= {
.name = "ningb",
.desc = "Gameboy format rz_bin plugin",
.license = "LGPL3",
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.baddr = &baddr,
.binsym = &binsym,
.entries = &entries,
.sections = &sections,
.symbols = &symbols,
.info = &info,
.mem = &mem,
}
RZ_API RZ_OWN RzList * rz_bin_maps_of_file_sections(RZ_NONNULL RzBinFile *binfile)
Create a list of RzBinMap from RzBinSections queried from the given file.
Definition: bin.c:1040
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: bin_ningb.c:19
static RzList * symbols(RzBinFile *bf)
Definition: bin_ningb.c:85
static RzBinAddr * binsym(RzBinFile *bf, RzBinSpecialSymbol type)
Definition: bin_ningb.c:27
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_ningb.c:158
static ut64 baddr(RzBinFile *bf)
Definition: bin_ningb.c:23
static RzList * entries(RzBinFile *bf)
Definition: bin_ningb.c:44
RzList * mem(RzBinFile *bf)
Definition: bin_ningb.c:181
static RzList * sections(RzBinFile *bf)
Definition: bin_ningb.c:62

Definition at line 250 of file bin_ningb.c.