Initial import of the RBin.io plugin ##bin

This commit is contained in:
pancake 2024-02-29 17:55:52 +01:00 committed by GitHub
parent 5f5eb2d4be
commit 6673e8a42d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 183 additions and 3 deletions

View File

@ -98,6 +98,7 @@ bin.dis
bin.dmp64
bin.dol
bin.dyldcache
bin.io
bin.elf
bin.elf64
bin.fs

View File

@ -11,6 +11,7 @@ r_bin_sources = [
'bfile.c',
'bobj.c',
# plugins
'p/bin_io.c',
'p/bin_any.c',
'p/bin_art.c',
'p/bin_avr.c',

162
libr/bin/p/bin_io.c Normal file
View File

@ -0,0 +1,162 @@
/* radare - MIT - 2024 - pancake */
// the info loaded here is never updated maybe we should have a way to refresh it
#include <r_bin.h>
#include <r_io.h>
static ut64 baddr(RBinFile *bf) {
return 0;
}
static bool check(RBinFile *bf, RBuffer *b) {
return false;
}
static bool load(RBinFile *bf, RBuffer *b, ut64 loadaddr) {
return true;
}
static char *iocmd(RBinFile *bf, const char *s) {
RIO *io = R_UNWRAP3 (bf, rbin, iob.io);
if (!io) {
R_LOG_ERROR ("NO IO");
return NULL;
}
char *res = r_io_system (io, s);
if (!res) {
const char *buffer = r_cons_get_buffer ();
if (buffer != NULL) {
res = strdup (buffer);
}
}
return res;
}
static RBinInfo *info(RBinFile *bf) {
char *res = iocmd (bf, "i");
eprintf ("-->(i) %s\n", res);
free (res);
RBinInfo *ret = NULL;
if (!(ret = R_NEW0 (RBinInfo))) {
return NULL;
}
ret->file = strdup (bf->file);
ret->type = strdup ("IO");
ret->machine = strdup ("IO");
ut8 tmp[32];
r_buf_read_at (bf->buf, 0x100, tmp, sizeof (tmp));
ret->bclass = r_str_ndup ((char *)tmp, 32);
ret->os = strdup ("io");
ret->arch = strdup ("arm");
ret->bits = 64;
ret->has_va = 1;
ret->big_endian = 1;
return ret;
}
#if 0
static void addsym(RList *ret, const char *name, ut64 addr) {
RBinSymbol *ptr = R_NEW0 (RBinSymbol);
if (R_LIKELY (ptr)) {
ptr->name = r_bin_name_new (r_str_get (name));
ptr->paddr = ptr->vaddr = addr;
ptr->size = 0;
ptr->ordinal = 0;
r_list_append (ret, ptr);
}
}
#endif
static RList *symbols(RBinFile *bf) {
char *res = iocmd (bf, "is");
eprintf ("-->(is) %s\n", res);
free (res);
RList *ret = r_list_newf (free);
#if 0
addsym (ret, "rom_start", r_read_be32 (&hdr.RomStart));
#endif
return ret;
}
static RList *sections(RBinFile *bf) {
char *res = iocmd (bf, "iS");
eprintf ("-->(iS) %s\n", res);
free (res);
RList *ret = r_list_new ();
#if 0
RBinSection *ptr;
if (!(ptr = R_NEW0 (RBinSection))) {
return ret;
}
ptr->name = strdup ("vtable");
ptr->paddr = ptr->vaddr = 0;
ptr->size = ptr->vsize = 0x100;
ptr->perm = R_PERM_R;
ptr->add = true;
r_list_append (ret, ptr);
if (!(ptr = R_NEW0 (RBinSection))) {
return ret;
}
ptr->name = strdup ("header");
ptr->paddr = ptr->vaddr = 0x100;
ptr->size = ptr->vsize = sizeof (SMD_Header);
ptr->perm = R_PERM_R;
ptr->add = true;
r_list_append (ret, ptr);
if (!(ptr = R_NEW0 (RBinSection))) {
return ret;
}
ptr->name = strdup ("text");
ptr->paddr = ptr->vaddr = 0x100 + sizeof (SMD_Header);
{
SMD_Header hdr = {{0}};
r_buf_read_at (bf->buf, 0x100, (ut8*)&hdr, sizeof (hdr));
ut64 baddr = r_read_be32 (&hdr.RomStart);
ptr->vaddr += baddr;
}
ptr->size = ptr->vsize = r_buf_size (bf->buf) - ptr->paddr;
ptr->perm = R_PERM_RX;
ptr->add = true;
r_list_append (ret, ptr);
#endif
return ret;
}
static RList *entries(RBinFile *bf) {
RList *ret = r_list_newf (free);
char *res = iocmd (bf, "ie");
ut64 entry0 = r_num_get (NULL, res);
free (res);
RBinAddr *ptr = R_NEW0 (RBinAddr);
ptr->paddr = ptr->vaddr = entry0;
r_list_append (ret, ptr);
return ret;
}
RBinPlugin r_bin_plugin_io = {
.meta = {
.name = "io",
.desc = "bin plugin using the io interface",
.license = "MIT",
},
.load = &load,
.check = &check,
.baddr = &baddr,
.entries = &entries,
.sections = &sections,
.symbols = &symbols,
.info = &info,
.minstrlen = 10,
.strfilter = 'U'
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_io,
.version = R2_VERSION
};
#endif

10
libr/bin/p/io.mk Normal file
View File

@ -0,0 +1,10 @@
OBJ_IO=bin_io.o
STATIC_OBJ+=${OBJ_IO}
TARGET_IO=bin_io.${EXT_SO}
ALL_TARGETS+=${TARGET_IO}
${TARGET_IO}: ${OBJ_IO}
${CC} $(call libname,bin_io) -shared ${CFLAGS} \
-o ${TARGET_IO} ${OBJ_IO} $(LINK) $(LDFLAGS)

View File

@ -351,7 +351,12 @@ static void cmd_open_bin(RCore *core, const char *input) {
}
break;
case 'i': // "obi"
r_core_cmdf (core, "i%s", input + 2);
if (input[2] == 'o') { // "obio"
r_bin_force_plugin (core->bin, "io");
r_core_bin_load (core, NULL, 0);
} else {
r_core_cmdf (core, "i%s", input + 2);
}
break;
case 'm': // "obm"
{

View File

@ -979,6 +979,7 @@ extern RBinPlugin r_bin_plugin_lua;
extern RBinPlugin r_bin_plugin_xtac;
extern RBinPlugin r_bin_plugin_pdp11;
extern RBinPlugin r_bin_plugin_pcap;
extern RBinPlugin r_bin_plugin_io;
#ifdef __cplusplus
}

View File

@ -1,4 +1,4 @@
/* radare2 - LGPL - Copyright 2017-2023 - condret, pancake */
/* radare2 - LGPL - Copyright 2017-2024 - condret, pancake */
#ifndef R2_IO_H
#define R2_IO_H

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2023 - pancake */
/* radare - LGPL - Copyright 2009-2024 - pancake */
#define USE_THREADS 1
#define ALLOW_THREADED 1