Rizin
unix-like reverse engineering framework and cli tools
bin_ninds.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/nds.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 *b, Sdb *sdb)
 
static ut64 baddr (RzBinFile *bf)
 
static ut64 boffset (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzListentries (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 

Variables

static struct nds_hdr loaded_header
 
RzBinPlugin rz_bin_plugin_ninds
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 35 of file bin_ninds.c.

35  {
36  return (ut64)loaded_header.arm9_ram_address;
37 }
static struct nds_hdr loaded_header
Definition: bin_ninds.c:12
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References loaded_header, and ut64().

◆ boffset()

static ut64 boffset ( RzBinFile bf)
static

Definition at line 39 of file bin_ninds.c.

39  {
40  return 0LL;
41 }

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 14 of file bin_ninds.c.

14  {
15  ut8 ninlogohead[6];
16  if (rz_buf_read_at(b, 0xc0, ninlogohead, sizeof(ninlogohead)) == 6) {
17  /* begin of nintendo logo = \x24\xff\xae\x51\x69\x9a */
18  if (!memcmp(ninlogohead, "\x24\xff\xae\x51\x69\x9a", 6)) {
19  return true;
20  }
21  /* begin of Homebrew magic */
22  if (!memcmp(ninlogohead, "\xC8\x60\x4F\xE2\x01\x70", 6)) {
23  return true;
24  }
25  }
26  return false;
27 }
uint8_t ut8
Definition: lh5801.h:11
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, and rz_buf_read_at().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 79 of file bin_ninds.c.

79  {
80  RzList *ret = rz_list_new();
81  RzBinAddr *ptr9 = NULL, *ptr7 = NULL;
82 
83  if (bf && bf->buf) {
84  if (!ret) {
85  return NULL;
86  }
87  ret->free = free;
88  if (!(ptr9 = RZ_NEW0(RzBinAddr))) {
89  rz_list_free(ret);
90  return NULL;
91  }
92  if (!(ptr7 = RZ_NEW0(RzBinAddr))) {
93  rz_list_free(ret);
94  free(ptr9);
95  return NULL;
96  }
97 
98  /* ARM9 entry point */
99  ptr9->vaddr = loaded_header.arm9_entry_address;
100  // ptr9->paddr = loaded_header.arm9_entry_address;
101  rz_list_append(ret, ptr9);
102 
103  /* ARM7 entry point */
104  ptr7->vaddr = loaded_header.arm7_entry_address;
105  // ptr7->paddr = loaded_header.arm7_entry_address;
106  rz_list_append(ret, ptr7);
107  }
108  return ret;
109 }
#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_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
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
#define RZ_NEW0(x)
Definition: rz_types.h:284
ut64 vaddr
Definition: rz_bin.h:186
RzBuffer * buf
Definition: rz_bin.h:303
RzListFree free
Definition: rz_list.h:21

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

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 111 of file bin_ninds.c.

111  {
112  rz_return_val_if_fail(bf && bf->buf, NULL);
113  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
114  if (ret) {
115  char *filepath = rz_str_newf("%.12s - %.4s",
116  loaded_header.title, loaded_header.gamecode);
117  ret->file = filepath;
118  ret->type = strdup("ROM");
119  ret->machine = strdup("Nintendo DS");
120  ret->os = strdup("nds");
121  ret->arch = strdup("arm");
122  ret->has_va = true;
123  ret->bits = 32;
124  }
125  return ret;
126 }
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 char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
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
char * arch
Definition: rz_bin.h:214

References rz_bin_info_t::arch, rz_bin_info_t::bits, rz_bin_file_t::buf, rz_bin_info_t::file, rz_bin_info_t::has_va, loaded_header, rz_bin_info_t::machine, NULL, rz_bin_info_t::os, RZ_NEW0, rz_return_val_if_fail, rz_str_newf(), strdup(), and rz_bin_info_t::type.

◆ load_buffer()

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

Definition at line 29 of file bin_ninds.c.

29  {
31  obj->bin_obj = &loaded_header;
32  return obj->bin_obj;
33 }
void * bin_obj
Definition: rz_bin.h:293

References b, rz_bin_object_t::bin_obj, loaded_header, and rz_buf_read_at().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 43 of file bin_ninds.c.

43  {
44  RzList *ret = NULL;
45  RzBinSection *ptr9 = NULL, *ptr7 = NULL;
46 
48  return NULL;
49  }
50  if (!(ptr9 = RZ_NEW0(RzBinSection))) {
51  rz_list_free(ret);
52  return NULL;
53  }
54  if (!(ptr7 = RZ_NEW0(RzBinSection))) {
55  rz_list_free(ret);
56  free(ptr9);
57  return NULL;
58  }
59 
60  ptr9->name = strdup("arm9");
61  ptr9->size = loaded_header.arm9_size;
62  ptr9->vsize = loaded_header.arm9_size;
63  ptr9->paddr = loaded_header.arm9_rom_offset;
64  ptr9->vaddr = loaded_header.arm9_ram_address;
65  ptr9->perm = rz_str_rwx("rwx");
66  rz_list_append(ret, ptr9);
67 
68  ptr7->name = strdup("arm7");
69  ptr7->size = loaded_header.arm7_size;
70  ptr7->vsize = loaded_header.arm7_size;
71  ptr7->paddr = loaded_header.arm7_rom_offset;
72  ptr7->vaddr = loaded_header.arm7_ram_address;
73  ptr7->perm = rz_str_rwx("rwx");
74  rz_list_append(ret, ptr7);
75 
76  return ret;
77 }
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
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318
char * name
Definition: rz_bin.h:619

References free(), loaded_header, rz_bin_section_t::name, NULL, rz_bin_section_t::paddr, rz_bin_section_t::perm, rz_bin_section_free(), rz_list_append(), rz_list_free(), rz_list_newf(), RZ_NEW0, rz_str_rwx(), rz_bin_section_t::size, strdup(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

Variable Documentation

◆ loaded_header

struct nds_hdr loaded_header
static

Definition at line 1 of file bin_ninds.c.

Referenced by baddr(), entries(), info(), load_buffer(), and sections().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_ninds
Definition: bin_ninds.c:128
@ 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 143 of file bin_ninds.c.

◆ rz_bin_plugin_ninds

RzBinPlugin rz_bin_plugin_ninds
Initial value:
= {
.name = "ninds",
.desc = "Nintendo DS format rz_bin plugin",
.license = "LGPL3",
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.baddr = &baddr,
.boffset = &boffset,
.entries = &entries,
.sections = &sections,
.info = &info,
}
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 *b, Sdb *sdb)
Definition: bin_ninds.c:29
static ut64 boffset(RzBinFile *bf)
Definition: bin_ninds.c:39
static bool check_buffer(RzBuffer *b)
Definition: bin_ninds.c:14
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_ninds.c:111
static ut64 baddr(RzBinFile *bf)
Definition: bin_ninds.c:35
static RzList * entries(RzBinFile *bf)
Definition: bin_ninds.c:79
static RzList * sections(RzBinFile *bf)
Definition: bin_ninds.c:43

Definition at line 128 of file bin_ninds.c.