radare2/libr/bin/p/bin_bios.c

128 lines
2.8 KiB
C
Raw Normal View History

2013-06-09 02:11:17 +02:00
/* radare - LGPL - Copyright 2013 - pancake */
#include <r_types.h>
#include <r_util.h>
#include <r_lib.h>
#include <r_bin.h>
static int check(RBinFile *arch);
2013-06-09 02:11:17 +02:00
static int load(RBinFile *arch) {
2013-06-09 02:11:17 +02:00
if (check (arch))
return R_TRUE;
return R_FALSE;
}
static int destroy(RBinFile *arch) {
//r_bin_bios_free ((struct r_bin_bios_obj_t*)arch->o->bin_obj);
2013-06-09 02:11:17 +02:00
return R_TRUE;
}
static ut64 baddr(RBinFile *arch) {
2013-06-09 02:11:17 +02:00
return 0;
}
/* accelerate binary load */
static RList *strings(RBinFile *arch) {
2013-06-09 02:11:17 +02:00
return NULL;
}
static RBinInfo* info(RBinFile *arch) {
2013-06-09 02:11:17 +02:00
RBinInfo *ret = NULL;
if (!(ret = R_NEW (RBinInfo)))
return NULL;
memset (ret, '\0', sizeof (RBinInfo));
ret->lang = NULL;
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS-1);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS-1);
strncpy (ret->type, "bios", sizeof (ret->type)-1); // asm.arch
strncpy (ret->bclass, "1.0", sizeof (ret->bclass)-1);
strncpy (ret->rclass, "bios", sizeof (ret->rclass)-1); // file.type
strncpy (ret->os, "any", sizeof (ret->os)-1);
strncpy (ret->subsystem, "unknown", sizeof (ret->subsystem)-1);
strncpy (ret->machine, "pc", sizeof (ret->machine)-1);
strcpy (ret->arch, "x86");
ret->has_va = 1;
ret->bits = 16;
ret->big_endian = 0;
ret->dbg_info = 0;
return ret;
}
static int check(RBinFile *arch) {
if ((arch->buf) && (arch->buf->length > 0xffff)) {
const ut32 ep = arch->buf->length - 0x10000 + 0xfff0; /* F000:FFF0 address */
/* Check if this a 'jmp' opcode */
if ((arch->buf->buf[ep] == 0xea) || (arch->buf->buf[ep] == 0xe9))
return 1;
2013-06-09 02:11:17 +02:00
}
return 0;
}
static RList* sections(RBinFile *arch) {
2013-06-09 02:11:17 +02:00
RList *ret = NULL;
RBinSection *ptr = NULL;
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
// program headers is another section
if (!(ptr = R_NEW0 (RBinSection)))
return ret;
strcpy (ptr->name, "bootblk");
ptr->vsize = ptr->size = 0x10000;
ptr->offset = arch->buf->length - ptr->size;
ptr->rva = 0xf0000;
ptr->srwx = 7;
r_list_append (ret, ptr);
return ret;
}
static RList* entries(RBinFile *arch) {
2013-06-09 02:11:17 +02:00
RList *ret;
RBinAddr *ptr = NULL;
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(ptr = R_NEW (RBinAddr)))
return ret;
memset (ptr, '\0', sizeof (RBinAddr));
ptr->offset = ptr->rva = 0xffff0;
r_list_append (ret, ptr);
return ret;
}
struct r_bin_plugin_t r_bin_plugin_bios = {
.name = "bios",
.desc = "filesystem bin plugin",
.license = "LGPL",
2013-06-09 02:11:17 +02:00
.init = NULL,
.fini = NULL,
.load = &load,
.destroy = &destroy,
.check = &check,
.baddr = &baddr,
.boffset = NULL,
2013-06-09 02:11:17 +02:00
.binsym = NULL,
.entries = entries,
.sections = sections,
.symbols = NULL,
.imports = NULL,
.strings = &strings,
.info = &info,
.fields = NULL,
.libs = NULL,
.relocs = NULL,
2014-03-10 02:27:32 +01:00
.dbginfo = NULL,
2013-06-09 02:11:17 +02:00
.write = NULL,
.demangle_type = NULL
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_bios
};
#endif