Rizin
unix-like reverse engineering framework and cli tools
bin_ningba.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/gba.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 RzListentries (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_ningba
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 11 of file bin_ningba.c.

11  {
12  ut8 lict[156];
13  rz_return_val_if_fail(b, false);
14  rz_buf_read_at(b, 4, (ut8 *)lict, sizeof(lict));
15  return !memcmp(lict, lic_gba, 156);
16 }
const ut8 lic_gba[]
Definition: gba.h:6
uint8_t ut8
Definition: lh5801.h:11
#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
#define b(i)
Definition: sha256.c:42

References b, lic_gba, rz_buf_read_at(), and rz_return_val_if_fail.

Referenced by load_buffer().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 22 of file bin_ningba.c.

22  {
23  RzList *ret = rz_list_newf(free);
24  RzBinAddr *ptr = NULL;
25 
26  if (bf && bf->buf) {
27  if (!ret) {
28  return NULL;
29  }
30  if (!(ptr = RZ_NEW0(RzBinAddr))) {
31  return ret;
32  }
33  ptr->paddr = ptr->vaddr = 0x8000000;
34  rz_list_append(ret, ptr);
35  }
36  return ret;
37 }
#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
RzBuffer * buf
Definition: rz_bin.h:303

References rz_bin_file_t::buf, 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 39 of file bin_ningba.c.

39  {
40  ut8 rom_info[16];
41  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
42 
43  if (!ret) {
44  return NULL;
45  }
46 
47  if (!bf || !bf->buf) {
48  free(ret);
49  return NULL;
50  }
51 
52  ret->lang = NULL;
53  rz_buf_read_at(bf->buf, 0xa0, rom_info, 16);
54  ret->file = rz_str_ndup((const char *)rom_info, 12);
55  ret->type = rz_str_ndup((char *)&rom_info[12], 4);
56  ret->machine = strdup("GameBoy Advance");
57  ret->os = strdup("any");
58  ret->arch = strdup("arm");
59  ret->has_va = 1;
60  ret->bits = 32;
61  ret->big_endian = 0;
62  ret->dbg_info = 0;
63  return ret;
64 }
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")
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
const char * lang
Definition: rz_bin.h:224
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(), rz_bin_info_t::has_va, rz_bin_info_t::lang, rz_bin_info_t::machine, 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 18 of file bin_ningba.c.

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

References check_buffer().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 66 of file bin_ningba.c.

66  {
67  RzList *ret = NULL;
69  if (!s) {
70  return NULL;
71  }
72  ut64 sz = rz_buf_size(bf->buf);
74  free(s);
75  return NULL;
76  }
77  s->name = strdup("ROM");
78  s->paddr = 0;
79  s->vaddr = 0x8000000;
80  s->size = sz;
81  s->vsize = 0x2000000;
82  s->perm = RZ_PERM_RX;
83 
84  rz_list_append(ret, s);
85  return ret;
86 }
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
static RzSocket * s
Definition: rtr.c:28
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_PERM_RX
Definition: rz_types.h:97
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_bin_file_t::buf, free(), NULL, rz_bin_section_free(), rz_buf_size(), rz_list_append(), rz_list_newf(), RZ_NEW0, RZ_PERM_RX, s, strdup(), and ut64().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_ningba
Definition: bin_ningba.c:88
@ 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 101 of file bin_ningba.c.

◆ rz_bin_plugin_ningba

RzBinPlugin rz_bin_plugin_ningba
Initial value:
= {
.name = "ningba",
.desc = "Game Boy Advance format rz_bin plugin",
.license = "LGPL3",
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.entries = &entries,
.info = &info,
.sections = &sections,
}
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_ningba.c:18
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_ningba.c:39
static RzList * entries(RzBinFile *bf)
Definition: bin_ningba.c:22
static RzList * sections(RzBinFile *bf)
Definition: bin_ningba.c:66

Definition at line 88 of file bin_ningba.c.