static RBinInfo *info(RBinFile *bf) { RBinInfo *ret = R_NEW0 (RBinInfo); if (!ret) { return NULL; } const char *ft = fileType (r_buf_get_at (bf->buf, NRO_OFF (magic), NULL)); if (!ft) { ft = "nro"; } ret->file = strdup (bf->file); ret->rclass = strdup (ft); ret->os = strdup ("switch"); ret->arch = strdup ("arm"); ret->machine = strdup ("Nintendo Switch"); ret->subsystem = strdup (ft); if (!strncmp (ft, "nrr", 3)) { ret->bclass = strdup ("program"); ret->type = strdup ("EXEC (executable file)"); } else if (!strncmp (ft, "nro", 3)) { ret->bclass = strdup ("object"); ret->type = strdup ("OBJECT (executable code)"); } else { // mod ret->bclass = strdup ("library"); ret->type = strdup ("MOD (executable library)"); } ret->bits = 64; ret->has_va = true; ret->has_lit = true; ret->big_endian = false; ret->dbg_info = 0; ret->dbg_info = 0; return ret; }
R_API RIODesc *r_io_open_buffer(RIO *io, RBuffer *b, int flags, int mode) { const int bufSize = r_buf_size (b); char *uri = r_str_newf ("malloc://%d", bufSize); RIODesc *desc = r_io_open_nomap (io, uri, flags, mode); if (desc) { r_io_desc_write (desc, r_buf_get_at(b, 0, NULL), bufSize); } return desc; }
static void headers64(RBinFile *bf) { #define p bf->rbin->cb_printf const ut8 *buf = r_buf_get_at (bf->buf, 0, NULL); p ("0x00000000 ELF64 0x%08x\n", r_read_le32 (buf)); p ("0x00000010 Type 0x%04x\n", r_read_le16 (buf + 0x10)); p ("0x00000012 Machine 0x%04x\n", r_read_le16 (buf + 0x12)); p ("0x00000014 Version 0x%08x\n", r_read_le32 (buf + 0x14)); p ("0x00000018 Entrypoint 0x%08"PFMT64x"\n", r_read_le64 (buf + 0x18)); p ("0x00000020 PhOff 0x%08"PFMT64x"\n", r_read_le64 (buf + 0x20)); p ("0x00000028 ShOff 0x%08"PFMT64x"\n", r_read_le64 (buf + 0x28)); }
static ut64 readLE64(RBuffer *buf, int off) { int left = 0; const ut8 *data = r_buf_get_at (buf, off, &left); return left > 7? r_read_le64 (data): 0; }
static ut32 readLE32(RBuffer *buf, int off) { int left = 0; const ut8 *data = r_buf_get_at (buf, off, &left); return left > 3? r_read_le32 (data): 0; }
static const char *readString(RBuffer *buf, int off) { int left = 0; const char *data = (const char *)r_buf_get_at (buf, off, &left); return left > 0 ? data: NULL; }
R_API bool r_buf_dump(RBuffer *b, const char *file) { if (!b || !file) { return false; } return r_file_dump (file, r_buf_get_at (b, 0, NULL), r_buf_size (b), 0); }