Rizin
unix-like reverse engineering framework and cli tools
bin_nso.c File Reference
#include <rz_bin.h>
#include "nxo/nxo.h"
#include <lz4.h>

Go to the source code of this file.

Classes

struct  NSOHeader
 

Macros

#define NSO_OFF(x)   rz_offsetof(NSOHeader, x)
 
#define NSO_OFFSET_MODMEMOFF   rz_offsetof(NXOStart, mod_memoffset)
 
#define VFILE_NAME_DECOMPRESSED   "decompressed"
 

Functions

static ut64 baddr (RzBinFile *bf)
 
static bool check_buffer (RzBuffer *b)
 
static bool parse_header_aux (RzBuffer *buf, NSOHeader *r)
 
static NSOHeaderparse_header (RzBuffer *buf)
 
static RzBinNXOObjnso_new (RzBuffer *buf)
 
static void nso_free (RzBinNXOObj *bin)
 
static bool decompress (RzBuffer *source_buf, ut64 source_offset, ut64 source_size, ut8 *dst_buf, ut64 decompressed_size)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
 
static void destroy (RzBinFile *bf)
 
static RzBinAddrbinsym (RzBinFile *bf, RzBinSpecialSymbol type)
 
static RzListentries (RzBinFile *bf)
 
static Sdbget_sdb (RzBinFile *bf)
 
static RzListvirtual_files (RzBinFile *bf)
 
static RzListmaps (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_nso
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ NSO_OFF

#define NSO_OFF (   x)    rz_offsetof(NSOHeader, x)

Definition at line 9 of file bin_nso.c.

◆ NSO_OFFSET_MODMEMOFF

#define NSO_OFFSET_MODMEMOFF   rz_offsetof(NXOStart, mod_memoffset)

Definition at line 10 of file bin_nso.c.

◆ VFILE_NAME_DECOMPRESSED

#define VFILE_NAME_DECOMPRESSED   "decompressed"

Definition at line 12 of file bin_nso.c.

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 34 of file bin_nso.c.

34  {
35  return 0x8000000;
36 }

Referenced by entries(), load_buffer(), and maps().

◆ binsym()

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

Definition at line 190 of file bin_nso.c.

190  {
191  return NULL; // TODO
192 }
#define NULL
Definition: cris-opc.c:27

References NULL.

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 38 of file bin_nso.c.

38  {
39  if (rz_buf_size(b) >= 0x20) {
40  ut8 magic[4];
41  if (rz_buf_read_at(b, 0, magic, sizeof(magic)) != 4) {
42  return false;
43  }
44  return fileType(magic) != NULL;
45  }
46  return false;
47 }
uint8_t ut8
Definition: lh5801.h:11
const char * fileType(const ut8 *buf)
Definition: nxo.c:24
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, fileType(), NULL, rz_buf_read_at(), and rz_buf_size().

◆ decompress()

static bool decompress ( RzBuffer source_buf,
ut64  source_offset,
ut64  source_size,
ut8 dst_buf,
ut64  decompressed_size 
)
static

Definition at line 108 of file bin_nso.c.

108  {
109  if (!source_size || decompressed_size > (ut64)SIZE_MAX || source_size > (ut64)INT_MAX || decompressed_size > (ut64)INT_MAX) {
110  return false;
111  }
112  ut8 *tmp = RZ_NEWS0(ut8, source_size);
113  if (!tmp) {
114  return false;
115  }
116  if (rz_buf_read_at(source_buf, source_offset, tmp, source_size) != source_size) {
117  free(tmp);
118  return false;
119  }
120  int r = LZ4_decompress_safe((const char *)tmp, (char *)dst_buf, source_size, decompressed_size);
121  free(tmp);
122  return r == decompressed_size;
123 }
#define INT_MAX
Definition: cp-demangle.c:131
#define r
Definition: crypto_rc6.c:12
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
LZ4_FORCE_O2 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
Definition: lz4.c:2171
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
#define SIZE_MAX
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References free(), INT_MAX, LZ4_decompress_safe(), r, rz_buf_read_at(), RZ_NEWS0, SIZE_MAX, autogen_x86imm::tmp, and ut64().

Referenced by load_buffer(), and main().

◆ destroy()

static void destroy ( RzBinFile bf)
static

Definition at line 183 of file bin_nso.c.

183  {
184  if (!bf->o) {
185  return;
186  }
187  nso_free(bf->o->bin_obj);
188 }
static void nso_free(RzBinNXOObj *bin)
Definition: bin_nso.c:99
RzBinObject * o
Definition: rz_bin.h:305
void * bin_obj
Definition: rz_bin.h:293

References rz_bin_object_t::bin_obj, nso_free(), and rz_bin_file_t::o.

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 194 of file bin_nso.c.

194  {
195  RzList *ret;
196  RzBuffer *b = bf->buf;
197 
198  if (!(ret = rz_list_new())) {
199  return NULL;
200  }
201 
202  ret->free = free;
203 
204  RzBinAddr *ptr = RZ_NEW0(RzBinAddr);
205  if (!ptr) {
206  rz_list_free(ret);
207  return NULL;
208  }
209 
210  ut32 tmp;
211  if (!rz_buf_read_le32_at(b, NSO_OFF(text_memoffset), &tmp)) {
212  rz_list_free(ret);
213  free(ptr);
214  return NULL;
215  }
216  ptr->paddr = tmp;
217 
218  if (!rz_buf_read_le32_at(b, NSO_OFF(text_loc), &tmp)) {
219  rz_list_free(ret);
220  free(ptr);
221  return NULL;
222  }
223  ptr->vaddr = tmp;
224 
225  ptr->vaddr += baddr(bf);
226 
227  rz_list_append(ret, ptr);
228 
229  return ret;
230 }
#define NSO_OFF(x)
Definition: bin_nso.c:9
static ut64 baddr(RzBinFile *bf)
Definition: bin_nso.c:34
uint32_t ut32
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_buf_read_le32_at(b, addr, result)
Definition: rz_buf.h:271
#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
RzListFree free
Definition: rz_list.h:21

References b, baddr(), rz_bin_file_t::buf, rz_list_t::free, free(), NSO_OFF, NULL, rz_bin_addr_t::paddr, rz_buf_read_le32_at, rz_list_append(), rz_list_free(), rz_list_new(), RZ_NEW0, autogen_x86imm::tmp, and rz_bin_addr_t::vaddr.

◆ get_sdb()

static Sdb* get_sdb ( RzBinFile bf)
static

Definition at line 232 of file bin_nso.c.

232  {
233  Sdb *kv = sdb_new0();
234  sdb_num_set(kv, "nso_start.offset", 0, 0);
235  sdb_num_set(kv, "nso_start.size", 16, 0);
236  sdb_set(kv, "nso_start.format", "xxq unused mod_memoffset padding", 0);
237  sdb_num_set(kv, "nso_header.offset", 0, 0);
238  sdb_num_set(kv, "nso_header.size", 0x40, 0);
239  sdb_set(kv, "nso_header.format", "xxxxxxxxxxxx magic unk size unk2 text_offset text_size ro_offset ro_size data_offset data_size bss_size unk3", 0);
240  sdb_ns_set(bf->sdb, "info", kv);
241  return kv;
242 }
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_DEPRECATE Sdb * sdb
deprecated, put info in C structures instead of this
Definition: rz_bin.h:315
Definition: sdb.h:63

References rz_bin_file_t::sdb, sdb_new0(), sdb_ns_set(), sdb_num_set(), and sdb_set().

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 355 of file bin_nso.c.

355  {
356  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
357  if (!ret) {
358  return NULL;
359  }
360  ut8 magic[4];
361  if (rz_buf_read_at(bf->buf, NSO_OFF(magic), magic, sizeof(magic)) != sizeof(magic)) {
362  free(ret);
363  return NULL;
364  }
365 
366  const char *ft = fileType(magic);
367  if (!ft) {
368  ft = "nso";
369  }
370  ret->file = strdup(bf->file);
371  ret->rclass = strdup(ft);
372  ret->os = strdup("switch");
373  ret->arch = strdup("arm");
374  ret->machine = strdup("Nintendo Switch");
375  ret->subsystem = strdup(ft);
376  ret->bclass = strdup("program");
377  ret->type = strdup("EXEC (executable file)");
378  ret->bits = 64;
379  ret->has_va = true;
380  ret->big_endian = false;
381  ret->dbg_info = 0;
382  return ret;
383 }
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")
char * file
Definition: rz_bin.h:299
int has_va
Definition: rz_bin.h:228
char * type
Definition: rz_bin.h:211
char * os
Definition: rz_bin.h:219
char * subsystem
Definition: rz_bin.h:220
char * machine
Definition: rz_bin.h:216
char * bclass
Definition: rz_bin.h:212
char * file
Definition: rz_bin.h:210
ut64 dbg_info
Definition: rz_bin.h:240
char * rclass
Definition: rz_bin.h:213
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::bclass, 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, rz_bin_file_t::file, fileType(), free(), rz_bin_info_t::has_va, rz_bin_info_t::machine, NSO_OFF, NULL, rz_bin_info_t::os, rz_bin_info_t::rclass, rz_buf_read_at(), RZ_NEW0, strdup(), rz_bin_info_t::subsystem, and rz_bin_info_t::type.

◆ load_buffer()

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

Definition at line 125 of file bin_nso.c.

125  {
126  rz_return_val_if_fail(bf && buf, false);
128  if (!bin) {
129  return false;
130  }
131  ut8 *tmp = NULL;
132  NSOHeader *hdr = bin->header;
133  if (hdr->ro_memoffset >= rz_buf_size(buf)) {
134  RZ_LOG_ERROR("NSO file smaller than ro section offset\n");
135  goto another_castle;
136  }
137  ut64 total_size = hdr->text_size + hdr->ro_size + hdr->data_size;
138  if (total_size < hdr->text_size) {
139  // Prevent integer overflow
140  goto another_castle;
141  }
142  tmp = RZ_NEWS0(ut8, total_size);
143  if (!tmp) {
144  goto another_castle;
145  }
146  ut64 ba = baddr(bf);
147 
148  /* Decompress each section */
149  if (!decompress(buf, hdr->text_memoffset, hdr->ro_memoffset - hdr->text_memoffset, tmp, hdr->text_size)) {
150  RZ_LOG_ERROR("Failed to decompress NSO text section\n");
151  goto another_castle;
152  }
153  if (!decompress(buf, hdr->ro_memoffset, hdr->data_memoffset - hdr->ro_memoffset, tmp + hdr->text_size, hdr->ro_size)) {
154  RZ_LOG_ERROR("Failed to decompress NSO ro section\n");
155  goto another_castle;
156  }
157  if (!decompress(buf, hdr->data_memoffset, rz_buf_size(buf) - hdr->data_memoffset, tmp + hdr->text_size + hdr->ro_size, hdr->data_size)) {
158  RZ_LOG_ERROR("Failed to decompress NSO data section\n");
159  goto another_castle;
160  }
161  bin->decompressed = rz_buf_new_with_pointers(tmp, total_size, true);
162  if (!bin->decompressed) {
163  goto another_castle;
164  }
165 
166  /* Load unpacked binary */
167  ut32 modoff;
168  if (!rz_buf_read_le32_at(bin->decompressed, NSO_OFFSET_MODMEMOFF, &modoff)) {
169  goto another_castle;
170  }
171 
172  RZ_LOG_INFO("MOD Offset = 0x%" PFMT64x "\n", (ut64)modoff);
173  parseMod(bin->decompressed, bin, modoff, ba);
174  obj->bin_obj = bin;
175  return true;
176 another_castle:
177  nso_free(bin);
178  free(tmp);
179  obj->bin_obj = NULL;
180  return false;
181 }
static RzBinNXOObj * nso_new(RzBuffer *buf)
Definition: bin_nso.c:86
#define NSO_OFFSET_MODMEMOFF
Definition: bin_nso.c:10
static bool decompress(RzBuffer *source_buf, ut64 source_offset, ut64 source_size, ut8 *dst_buf, ut64 decompressed_size)
Definition: bin_nso.c:108
voidpf void * buf
Definition: ioapi.h:138
void parseMod(RzBuffer *buf, RzBinNXOObj *bin, ut32 mod0, ut64 baddr)
Definition: nxo.c:130
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal)
Creates a new buffer with a bytes array.
Definition: buf.c:552
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define PFMT64x
Definition: rz_types.h:393
ut32 text_memoffset
Definition: bin_nso.c:20
ut32 ro_memoffset
Definition: bin_nso.c:24
ut32 data_memoffset
Definition: bin_nso.c:28
ut32 data_size
Definition: bin_nso.c:30
ut32 ro_size
Definition: bin_nso.c:26
ut32 text_size
Definition: bin_nso.c:22
Definition: malloc.c:26

References baddr(), rz_bin_object_t::bin_obj, NSOHeader::data_memoffset, NSOHeader::data_size, decompress(), free(), nso_free(), nso_new(), NSO_OFFSET_MODMEMOFF, NULL, parseMod(), PFMT64x, NSOHeader::ro_memoffset, NSOHeader::ro_size, rz_buf_new_with_pointers(), rz_buf_read_le32_at, rz_buf_size(), RZ_LOG_ERROR, RZ_LOG_INFO, RZ_NEWS0, rz_return_val_if_fail, NSOHeader::text_memoffset, NSOHeader::text_size, autogen_x86imm::tmp, and ut64().

◆ maps()

static RzList* maps ( RzBinFile bf)
static

Definition at line 263 of file bin_nso.c.

263  {
265  if (!ret) {
266  return NULL;
267  }
268 
269  RzBinNXOObj *bin = bf->o->bin_obj;
270  NSOHeader *hdr = bin->header;
271  ut64 ba = baddr(bf);
272 
274  if (!map) {
275  return ret;
276  }
277  map->name = strdup("text");
278  map->paddr = bin->decompressed ? 0 : hdr->text_memoffset;
279  map->vsize = map->psize = hdr->text_size;
280  map->vaddr = hdr->text_loc + ba;
281  map->perm = RZ_PERM_RX;
282  map->vfile_name = bin->decompressed ? strdup(VFILE_NAME_DECOMPRESSED) : NULL;
283  rz_list_append(ret, map);
284 
285  // add ro segment
286  map = RZ_NEW0(RzBinMap);
287  if (!map) {
288  return ret;
289  }
290  map->name = strdup("ro");
291  map->paddr = bin->decompressed ? hdr->text_size : hdr->ro_memoffset;
292  map->vsize = map->psize = hdr->ro_size;
293  map->vaddr = hdr->ro_loc + ba;
294  map->perm = RZ_PERM_R;
295  map->vfile_name = bin->decompressed ? strdup(VFILE_NAME_DECOMPRESSED) : NULL;
296  rz_list_append(ret, map);
297 
298  // add data segment
299  map = RZ_NEW0(RzBinMap);
300  if (!map) {
301  return ret;
302  }
303  map->name = strdup("data");
304  map->paddr = bin->decompressed ? hdr->text_size + hdr->ro_size : hdr->data_memoffset;
305  map->vsize = map->psize = hdr->data_size;
306  map->vaddr = hdr->data_loc + ba;
307  map->perm = RZ_PERM_RW;
308  map->vfile_name = bin->decompressed ? strdup(VFILE_NAME_DECOMPRESSED) : NULL;
309  rz_list_append(ret, map);
310  return ret;
311 }
RZ_API void rz_bin_map_free(RzBinMap *map)
Definition: bin.c:1023
#define VFILE_NAME_DECOMPRESSED
Definition: bin_nso.c:12
size_t map(int syms, int left, int len)
Definition: enough.c:237
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
#define RZ_PERM_R
Definition: rz_types.h:93
#define RZ_PERM_RW
Definition: rz_types.h:96
#define RZ_PERM_RX
Definition: rz_types.h:97
ut32 text_loc
Definition: bin_nso.c:21
ut32 data_loc
Definition: bin_nso.c:29
ut32 ro_loc
Definition: bin_nso.c:25
Description of a single memory mapping into virtual memory from a binary.
Definition: rz_bin.h:602

References baddr(), rz_bin_object_t::bin_obj, NSOHeader::data_loc, NSOHeader::data_memoffset, NSOHeader::data_size, map(), NULL, rz_bin_file_t::o, NSOHeader::ro_loc, NSOHeader::ro_memoffset, NSOHeader::ro_size, rz_bin_map_free(), rz_list_append(), rz_list_newf(), RZ_NEW0, RZ_PERM_R, RZ_PERM_RW, RZ_PERM_RX, strdup(), NSOHeader::text_loc, NSOHeader::text_memoffset, NSOHeader::text_size, ut64(), and VFILE_NAME_DECOMPRESSED.

Referenced by sections().

◆ nso_free()

static void nso_free ( RzBinNXOObj bin)
static

Definition at line 99 of file bin_nso.c.

99  {
100  if (!bin) {
101  return;
102  }
103  rz_buf_free(bin->decompressed);
104  free(bin->header);
105  free(bin);
106 }
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253

References free(), and rz_buf_free().

Referenced by destroy(), and load_buffer().

◆ nso_new()

static RzBinNXOObj* nso_new ( RzBuffer buf)
static

Definition at line 86 of file bin_nso.c.

86  {
88  if (!bin) {
89  return NULL;
90  }
91  bin->header = parse_header(buf);
92  if (!bin->header) {
93  free(bin);
94  return NULL;
95  }
96  return bin;
97 }
static NSOHeader * parse_header(RzBuffer *buf)
Definition: bin_nso.c:68

References free(), NULL, parse_header(), and RZ_NEW0.

Referenced by load_buffer().

◆ parse_header()

static NSOHeader* parse_header ( RzBuffer buf)
static

Definition at line 68 of file bin_nso.c.

68  {
69  RZ_STATIC_ASSERT(sizeof(NSOHeader) == 64);
70  if (rz_buf_size(buf) < sizeof(NSOHeader)) {
71  return NULL;
72  }
74  if (!r) {
75  return NULL;
76  }
77 
78  if (!parse_header_aux(buf, r)) {
79  free(r);
80  return NULL;
81  }
82 
83  return r;
84 }
static bool parse_header_aux(RzBuffer *buf, NSOHeader *r)
Definition: bin_nso.c:49
#define RZ_STATIC_ASSERT(x)
Definition: rz_assert.h:10

References free(), NULL, parse_header_aux(), r, rz_buf_size(), RZ_NEW0, and RZ_STATIC_ASSERT.

Referenced by nso_new().

◆ parse_header_aux()

static bool parse_header_aux ( RzBuffer buf,
NSOHeader r 
)
static

Definition at line 49 of file bin_nso.c.

49  {
50  return rz_buf_read_le32_at(buf, NSO_OFF(magic), &r->magic) &&
51  rz_buf_read_le32_at(buf, NSO_OFF(pad0), &r->pad0) &&
52  rz_buf_read_le32_at(buf, NSO_OFF(pad1), &r->pad1) &&
53  rz_buf_read_le32_at(buf, NSO_OFF(pad2), &r->pad2) &&
54  rz_buf_read_le32_at(buf, NSO_OFF(text_memoffset), &r->text_memoffset) &&
55  rz_buf_read_le32_at(buf, NSO_OFF(text_loc), &r->text_loc) &&
56  rz_buf_read_le32_at(buf, NSO_OFF(text_size), &r->text_size) &&
57  rz_buf_read_le32_at(buf, NSO_OFF(pad3), &r->pad3) &&
58  rz_buf_read_le32_at(buf, NSO_OFF(ro_memoffset), &r->ro_memoffset) &&
59  rz_buf_read_le32_at(buf, NSO_OFF(ro_loc), &r->ro_loc) &&
60  rz_buf_read_le32_at(buf, NSO_OFF(ro_size), &r->ro_size) &&
61  rz_buf_read_le32_at(buf, NSO_OFF(pad4), &r->pad4) &&
62  rz_buf_read_le32_at(buf, NSO_OFF(data_memoffset), &r->data_memoffset) &&
63  rz_buf_read_le32_at(buf, NSO_OFF(data_loc), &r->data_loc) &&
64  rz_buf_read_le32_at(buf, NSO_OFF(data_size), &r->data_size) &&
65  rz_buf_read_le32_at(buf, NSO_OFF(bss_size), &r->bss_size);
66 }

References NSO_OFF, r, and rz_buf_read_le32_at.

Referenced by parse_header().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 313 of file bin_nso.c.

313  {
314  RzList *ret = NULL;
315  RzBinSection *ptr = NULL;
316  RzBuffer *b = bf->buf;
318  return NULL;
319  }
320 
321  if (!(ptr = RZ_NEW0(RzBinSection))) {
322  return ret;
323  }
324  ptr->name = strdup("header");
325  ut32 tmp;
326  if (!rz_buf_read_le32_at(b, NSO_OFF(text_memoffset), &tmp)) {
327  rz_list_free(ret);
328  return NULL;
329  }
330  ptr->size = tmp;
331 
332  if (!rz_buf_read_le32_at(b, NSO_OFF(text_memoffset), &tmp)) {
333  rz_list_free(ret);
334  return NULL;
335  }
336  ptr->vsize = tmp;
337 
338  ptr->paddr = 0;
339  ptr->vaddr = 0;
340  ptr->perm = RZ_PERM_R;
341  rz_list_append(ret, ptr);
342 
343  RzList *mappies = maps(bf);
344  if (mappies) {
345  RzList *msecs = rz_bin_sections_of_maps(mappies);
346  if (msecs) {
347  rz_list_join(ret, msecs);
348  rz_list_free(msecs);
349  }
350  rz_list_free(mappies);
351  }
352  return ret;
353 }
RZ_API RzList * rz_bin_sections_of_maps(RzList *maps)
Create a list of RzBinSection from RzBinMaps.
Definition: bin.c:1084
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
static RzList * maps(RzBinFile *bf)
Definition: bin_nso.c:263
RZ_API bool rz_list_join(RZ_NONNULL RzList *list1, RZ_NONNULL RzList *list2)
Joins 2 list into one (list2 pointer needs to be freed by the user)
Definition: list.c:209
char * name
Definition: rz_bin.h:619

References b, rz_bin_file_t::buf, maps(), rz_bin_section_t::name, NSO_OFF, NULL, rz_bin_section_t::paddr, rz_bin_section_t::perm, rz_bin_section_free(), rz_bin_sections_of_maps(), rz_buf_read_le32_at, rz_list_append(), rz_list_free(), rz_list_join(), rz_list_newf(), RZ_NEW0, RZ_PERM_R, rz_bin_section_t::size, strdup(), autogen_x86imm::tmp, rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

◆ virtual_files()

static RzList* virtual_files ( RzBinFile bf)
static

Definition at line 244 of file bin_nso.c.

244  {
246  if (!ret) {
247  return NULL;
248  }
249  RzBinNXOObj *bin = bf->o->bin_obj;
250  if (bin->decompressed) {
252  if (!vf) {
253  return ret;
254  }
255  vf->buf = bin->decompressed;
256  vf->buf_owned = false;
258  rz_list_push(ret, vf);
259  }
260  return ret;
261 }
RZ_API void rz_bin_virtual_file_free(RzBinVirtualFile *vfile)
Definition: bin.c:1012
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RZ_NONNULL RzBuffer * buf
Definition: rz_bin.h:597
bool buf_owned
whether buf is owned and freed by this RzBinVirtualFile
Definition: rz_bin.h:598
RZ_OWN RZ_NONNULL char * name
Definition: rz_bin.h:596

References rz_bin_object_t::bin_obj, rz_bin_virtual_file_t::buf, rz_bin_virtual_file_t::buf_owned, rz_bin_virtual_file_t::name, NULL, rz_bin_file_t::o, rz_bin_virtual_file_free(), rz_list_newf(), rz_list_push(), RZ_NEW0, strdup(), and VFILE_NAME_DECOMPRESSED.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_nso
Definition: bin_nso.c:387
@ 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 405 of file bin_nso.c.

◆ rz_bin_plugin_nso

RzBinPlugin rz_bin_plugin_nso
Initial value:
= {
.name = "nso",
.desc = "Nintendo Switch NSO0 binaries",
.license = "MIT",
.load_buffer = &load_buffer,
.destroy = &destroy,
.check_buffer = &check_buffer,
.baddr = &baddr,
.binsym = &binsym,
.entries = &entries,
.virtual_files = &virtual_files,
.maps = &maps,
.sections = &sections,
.get_sdb = &get_sdb,
.info = &info,
}
static Sdb * get_sdb(RzBinFile *bf)
Definition: bin_nso.c:232
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: bin_nso.c:125
static RzBinAddr * binsym(RzBinFile *bf, RzBinSpecialSymbol type)
Definition: bin_nso.c:190
static void destroy(RzBinFile *bf)
Definition: bin_nso.c:183
static bool check_buffer(RzBuffer *b)
Definition: bin_nso.c:38
static RzList * virtual_files(RzBinFile *bf)
Definition: bin_nso.c:244
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_nso.c:355
static RzList * entries(RzBinFile *bf)
Definition: bin_nso.c:194
static RzList * sections(RzBinFile *bf)
Definition: bin_nso.c:313

Definition at line 387 of file bin_nso.c.