Rizin
unix-like reverse engineering framework and cli tools
bin_spc700.c File Reference
#include <rz_bin.h>
#include <rz_lib.h>
#include "../format/spc700/spc_specs.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 RzBinInfoinfo (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzListentries (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_spc700
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 8 of file bin_spc700.c.

8  {
9  ut8 buf[27];
10  if (rz_buf_read_at(b, 0, buf, sizeof(buf)) == 27) {
11  return !memcmp(buf, SPC_MAGIC, 27);
12  }
13  return false;
14 }
voidpf void * buf
Definition: ioapi.h:138
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
#define SPC_MAGIC
Definition: spc_specs.h:7

References b, rz_buf_read_at(), and SPC_MAGIC.

Referenced by load_buffer().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 69 of file bin_spc700.c.

69  {
70  RzList *ret = rz_list_newf(free);
71  if (ret) {
72  RzBinAddr *ptr = RZ_NEW0(RzBinAddr);
73  if (ptr) {
74  ptr->paddr = RAM_START_ADDRESS;
75  ptr->vaddr = 0;
76  rz_list_append(ret, ptr);
77  }
78  }
79  return ret;
80 }
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 RAM_START_ADDRESS
Definition: nes_specs.h:15
#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(), rz_bin_addr_t::paddr, RAM_START_ADDRESS, rz_list_append(), rz_list_newf(), RZ_NEW0, and rz_bin_addr_t::vaddr.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 20 of file bin_spc700.c.

20  {
21  RzBinInfo *ret = NULL;
22  spc_hdr spchdr;
23  memset(&spchdr, 0, SPC_HDR_SIZE);
24  int reat = rz_buf_read_at(bf->buf, 0, (ut8 *)&spchdr, SPC_HDR_SIZE);
25  if (reat != SPC_HDR_SIZE) {
26  eprintf("Truncated Header\n");
27  return NULL;
28  }
29  if (!(ret = RZ_NEW0(RzBinInfo))) {
30  return NULL;
31  }
32  ret->file = strdup(bf->file);
33  ret->type = strdup("Sound File Data");
34  ret->machine = strdup("SPC700");
35  ret->os = strdup("spc700");
36  ret->arch = strdup("spc700");
37  ret->bits = 16;
38  ret->has_va = 1;
39  return ret;
40 }
#define NULL
Definition: cris-opc.c:27
return memset(p, 0, total)
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 eprintf(x, y...)
Definition: rlcc.c:7
#define SPC_HDR_SIZE
Definition: spc_specs.h:8
char * file
Definition: rz_bin.h:299
RzBuffer * buf
Definition: rz_bin.h:303
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, eprintf, rz_bin_info_t::file, rz_bin_file_t::file, rz_bin_info_t::has_va, rz_bin_info_t::machine, memset(), NULL, rz_bin_info_t::os, rz_buf_read_at(), RZ_NEW0, SPC_HDR_SIZE, 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 16 of file bin_spc700.c.

16  {
17  return check_buffer(b);
18 }
static bool check_buffer(RzBuffer *b)
Definition: bin_spc700.c:8

References b, and check_buffer().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 42 of file bin_spc700.c.

42  {
43  RzList *ret = NULL;
44  RzBinSection *ptr = NULL;
45  spc_hdr spchdr;
46  memset(&spchdr, 0, SPC_HDR_SIZE);
47  int reat = rz_buf_read_at(bf->buf, 0, (ut8 *)&spchdr, SPC_HDR_SIZE);
48  if (reat != SPC_HDR_SIZE) {
49  eprintf("Truncated Header\n");
50  return NULL;
51  }
52  if (!(ret = rz_list_new())) {
53  return NULL;
54  }
55  if (!(ptr = RZ_NEW0(RzBinSection))) {
56  rz_list_free(ret);
57  return NULL;
58  }
59  ptr->name = strdup("RAM");
60  ptr->paddr = RAM_START_ADDRESS;
61  ptr->size = RAM_SIZE;
62  ptr->vaddr = 0x0;
63  ptr->vsize = RAM_SIZE;
64  ptr->perm = RZ_PERM_R;
65  rz_list_append(ret, ptr);
66  return ret;
67 }
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 RAM_SIZE
Definition: nes_specs.h:16
#define RZ_PERM_R
Definition: rz_types.h:93
char * name
Definition: rz_bin.h:619

References rz_bin_file_t::buf, eprintf, memset(), rz_bin_section_t::name, NULL, rz_bin_section_t::paddr, rz_bin_section_t::perm, RAM_SIZE, RAM_START_ADDRESS, rz_buf_read_at(), rz_list_append(), rz_list_free(), rz_list_new(), RZ_NEW0, RZ_PERM_R, rz_bin_section_t::size, SPC_HDR_SIZE, strdup(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_spc700
Definition: bin_spc700.c:82
@ 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 95 of file bin_spc700.c.

◆ rz_bin_plugin_spc700

RzBinPlugin rz_bin_plugin_spc700
Initial value:
= {
.name = "spc700",
.desc = "SNES-SPC700 Sound File Data",
.license = "LGPL3",
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.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_spc700.c:16
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_spc700.c:20
static RzList * entries(RzBinFile *bf)
Definition: bin_spc700.c:69
static RzList * sections(RzBinFile *bf)
Definition: bin_spc700.c:42

Definition at line 82 of file bin_spc700.c.