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

Go to the source code of this file.

Classes

struct  N64Header
 

Macros

#define N64_ROM_START   0x1000
 

Functions

static ut64 baddr (RzBinFile *bf)
 
static bool check_buffer (RzBuffer *b)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *b, Sdb *sdb)
 
static RzListentries (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static ut64 boffset (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 

Variables

static N64Header n64_header
 
RzBinPlugin rz_bin_plugin_z64
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ N64_ROM_START

#define N64_ROM_START   0x1000

Definition at line 17 of file bin_z64.c.

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 69 of file bin_z64.c.

69  {
71 }
static N64Header n64_header
Definition: bin_z64.c:67
static ut32 rz_read_be32(const void *src)
Definition: rz_endian.h:87
ut32 BootAddress
Definition: bin_z64.c:51
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References N64Header::BootAddress, n64_header, rz_read_be32(), and ut64().

Referenced by entries(), and sections().

◆ boffset()

static ut64 boffset ( RzBinFile bf)
static

Definition at line 126 of file bin_z64.c.

126  {
127  return 0LL;
128 }

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 73 of file bin_z64.c.

73  {
74  ut8 magic[4];
75  if (rz_buf_size(b) < N64_ROM_START) {
76  return false;
77  }
78  (void)rz_buf_read_at(b, 0, magic, sizeof(magic));
79  return !memcmp(magic, "\x80\x37\x12\x40", 4);
80 }
#define N64_ROM_START
Definition: bin_z64.c:17
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
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define b(i)
Definition: sha256.c:42

References b, N64_ROM_START, rz_buf_read_at(), and rz_buf_size().

Referenced by load_buffer().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 92 of file bin_z64.c.

92  {
93  RzList /*<RzBinAddr>*/ *ret = rz_list_newf(free);
94  if (!ret) {
95  return NULL;
96  }
97  RzBinAddr *ptr = RZ_NEW0(RzBinAddr);
98  if (ptr) {
99  ptr->paddr = N64_ROM_START;
100  ptr->vaddr = baddr(bf);
101  rz_list_append(ret, ptr);
102  }
103  return ret;
104 }
static ut64 baddr(RzBinFile *bf)
Definition: bin_z64.c:69
#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 baddr(), free(), N64_ROM_START, 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 130 of file bin_z64.c.

130  {
131  char GameName[21] = { 0 };
132  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
133  if (!ret) {
134  return NULL;
135  }
136  memcpy(GameName, n64_header.Name, sizeof(n64_header.Name));
137  ret->file = rz_str_newf("%s (%c)", GameName, n64_header.CountryCode);
138  ret->os = strdup("n64");
139  ret->arch = strdup("mips");
140  ret->machine = strdup("Nintendo 64");
141  ret->type = strdup("ROM");
142  ret->bits = 64;
143  ret->has_va = true;
144  ret->big_endian = true;
145  return ret;
146 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
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_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
char Name[20]
Definition: bin_z64.c:56
char CountryCode
Definition: bin_z64.c:62
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
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, N64Header::CountryCode, rz_bin_info_t::file, rz_bin_info_t::has_va, rz_bin_info_t::machine, memcpy(), n64_header, N64Header::Name, NULL, rz_bin_info_t::os, RZ_NEW0, 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 82 of file bin_z64.c.

82  {
83  if (check_buffer(b)) {
84  ut8 buf[sizeof(N64Header)] = { 0 };
85  rz_buf_read_at(b, 0, buf, sizeof(buf));
86  obj->bin_obj = memcpy(&n64_header, buf, sizeof(N64Header));
87  return true;
88  }
89  return false;
90 }
static bool check_buffer(RzBuffer *b)
Definition: bin_z64.c:73
voidpf void * buf
Definition: ioapi.h:138
void * bin_obj
Definition: rz_bin.h:293

References b, rz_bin_object_t::bin_obj, check_buffer(), memcpy(), n64_header, and rz_buf_read_at().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 106 of file bin_z64.c.

106  {
107  RzList /*<RzBinSection>*/ *ret = rz_list_new();
108  if (!ret) {
109  return NULL;
110  }
112  if (!text) {
113  rz_list_free(ret);
114  return NULL;
115  }
116  text->name = strdup("text");
117  text->size = rz_buf_size(bf->buf) - N64_ROM_START;
118  text->vsize = text->size;
119  text->paddr = N64_ROM_START;
120  text->vaddr = baddr(bf);
121  text->perm = RZ_PERM_RX;
122  rz_list_append(ret, text);
123  return ret;
124 }
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 void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
#define RZ_PERM_RX
Definition: rz_types.h:97
RzBuffer * buf
Definition: rz_bin.h:303

References baddr(), rz_bin_file_t::buf, N64_ROM_START, NULL, rz_buf_size(), rz_list_append(), rz_list_free(), rz_list_new(), RZ_NEW0, RZ_PERM_RX, strdup(), and create_tags_rz::text.

Variable Documentation

◆ n64_header

N64Header n64_header
static

Definition at line 67 of file bin_z64.c.

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

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_z64
Definition: bin_z64.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 165 of file bin_z64.c.

◆ rz_bin_plugin_z64

RzBinPlugin rz_bin_plugin_z64
Initial value:
= {
.name = "z64",
.desc = "Nintendo 64 binaries big endian 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_z64.c:82
static ut64 boffset(RzBinFile *bf)
Definition: bin_z64.c:126
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_z64.c:130
static RzList * entries(RzBinFile *bf)
Definition: bin_z64.c:92
static RzList * sections(RzBinFile *bf)
Definition: bin_z64.c:106

Definition at line 150 of file bin_z64.c.