mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 12:12:06 +00:00
Add bin.menuet plugin
This commit is contained in:
parent
8fdd7af0b3
commit
adc8ee4fa3
164
libr/bin/p/bin_menuet.c
Normal file
164
libr/bin/p/bin_menuet.c
Normal file
@ -0,0 +1,164 @@
|
||||
/* radare2 - LGPL - Copyright 2016 - pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_bin.h>
|
||||
|
||||
static int check(RBinFile *arch);
|
||||
static int check_bytes(const ut8 *buf, ut64 length);
|
||||
|
||||
#if 0
|
||||
org 0x0
|
||||
db 'MENUET01' ; 8 byte id
|
||||
dd 1 ; header version
|
||||
dd START ; program start
|
||||
dd I_END ; program image size
|
||||
dd 0x1000 ; required amount of memory
|
||||
dd 0x1000 ; esp
|
||||
dd 0, 0 ; no parameters, no path
|
||||
#endif
|
||||
|
||||
static int check(RBinFile *arch) {
|
||||
const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL;
|
||||
ut64 sz = arch ? r_buf_size (arch->buf): 0;
|
||||
return check_bytes (bytes, sz);
|
||||
}
|
||||
|
||||
static int check_bytes(const ut8 *buf, ut64 length) {
|
||||
if (buf && length >= 8) {
|
||||
return (!memcmp (buf, "MENUET01", 8));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){
|
||||
return (void*)(size_t)check_bytes (buf, sz);
|
||||
}
|
||||
|
||||
static int load(RBinFile *arch) {
|
||||
return check(arch);
|
||||
}
|
||||
|
||||
static int destroy (RBinFile *arch) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static ut64 baddr(RBinFile *arch) {
|
||||
return 0; // 0x800000;
|
||||
}
|
||||
|
||||
static RList* entries(RBinFile *arch) {
|
||||
RList* ret;
|
||||
RBinAddr *ptr = NULL;
|
||||
if (!(ret = r_list_new ())) {
|
||||
return NULL;
|
||||
}
|
||||
ret->free = free;
|
||||
if ((ptr = R_NEW0 (RBinAddr))) {
|
||||
const ut8 *bytes = r_buf_buffer (arch->buf);
|
||||
ptr->paddr = r_read_ble32 (bytes + 12, false);
|
||||
ptr->vaddr = ptr->paddr + baddr (arch);
|
||||
r_list_append (ret, ptr);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static RList* sections(RBinFile *arch) {
|
||||
RList *ret = NULL;
|
||||
RBinSection *ptr = NULL;
|
||||
if (!arch->o->info) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(ret = r_list_newf (free))) {
|
||||
return NULL;
|
||||
}
|
||||
// add text segment
|
||||
if (!(ptr = R_NEW0 (RBinSection))) {
|
||||
return ret;
|
||||
}
|
||||
strncpy (ptr->name, "text", R_BIN_SIZEOF_STRINGS);
|
||||
ptr->size = r_read_ble32 (arch->buf->buf + 16, false);
|
||||
ptr->vsize = ptr->size + (ptr->size % 4096);
|
||||
ptr->paddr = r_read_ble32 (arch->buf->buf + 12, false);
|
||||
ptr->vaddr = ptr->paddr + baddr(arch);
|
||||
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE | R_BIN_SCN_MAP; // r-x
|
||||
ptr->add = true;
|
||||
r_list_append (ret, ptr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static RBinInfo* info(RBinFile *arch) {
|
||||
RBinInfo *ret = R_NEW0 (RBinInfo);
|
||||
if (ret) {
|
||||
ret->file = strdup (arch->file);
|
||||
ret->bclass = strdup ("program");
|
||||
ret->rclass = strdup ("menuet");
|
||||
ret->os = strdup ("MenuetOS");
|
||||
ret->arch = strdup ("x86");
|
||||
ret->machine = strdup (ret->arch);
|
||||
ret->subsystem = strdup ("kolibri");
|
||||
ret->type = strdup ("EXEC");
|
||||
ret->bits = 32;
|
||||
ret->has_va = true;
|
||||
ret->big_endian = 0;
|
||||
ret->dbg_info = 0;
|
||||
ret->dbg_info = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ut64 size(RBinFile *arch) {
|
||||
if (!arch->o->info) {
|
||||
arch->o->info = info (arch);
|
||||
}
|
||||
if (!arch->o->info) {
|
||||
return 0;
|
||||
}
|
||||
return (ut64)r_read_ble32 (arch->buf->buf + 16, false);
|
||||
}
|
||||
|
||||
#if !R_BIN_P9
|
||||
|
||||
/* inspired in http://www.phreedom.org/solar/code/tinype/tiny.97/tiny.asm */
|
||||
static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, int datalen) {
|
||||
RBuffer *buf = r_buf_new ();
|
||||
#define B(x,y) r_buf_append_bytes(buf,(const ut8*)x,y)
|
||||
#define D(x) r_buf_append_ut32(buf,x)
|
||||
B ("MENUET01", 8);
|
||||
D (1); // header version
|
||||
D (1); // program start
|
||||
D (0x1000); // program image size
|
||||
D (0x1000); // ESP
|
||||
D (0); // no parameters
|
||||
D (0); // no path
|
||||
B (code, codelen);
|
||||
return buf;
|
||||
}
|
||||
|
||||
RBinPlugin r_bin_plugin_menuet = {
|
||||
.name = "menuet",
|
||||
.desc = "Menuet/KolibriOS bin plugin",
|
||||
.license = "LGPL3",
|
||||
.load = &load,
|
||||
.load_bytes = &load_bytes,
|
||||
.size = &size,
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.check_bytes = &check_bytes,
|
||||
.baddr = &baddr,
|
||||
.entries = &entries,
|
||||
.sections = §ions,
|
||||
.info = &info,
|
||||
.create = &create,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_BIN,
|
||||
.data = &r_bin_plugin_menuet,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
||||
#endif
|
9
libr/bin/p/menuet.mk
Normal file
9
libr/bin/p/menuet.mk
Normal file
@ -0,0 +1,9 @@
|
||||
OBJ_MENUET=bin_menuet.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_MENUET}
|
||||
TARGET_MENUET=bin_menuet.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_MENUET}
|
||||
|
||||
${TARGET_MENUET}: ${OBJ_MENUET}
|
||||
-${CC} $(call libname,bin_menuet) ${CFLAGS} ${OBJ_MENUET}
|
@ -641,6 +641,7 @@ extern RBinPlugin r_bin_plugin_spc700;
|
||||
extern RBinPlugin r_bin_plugin_vsf;
|
||||
extern RBinPlugin r_bin_plugin_dyldcache;
|
||||
extern RBinPlugin r_bin_plugin_avr;
|
||||
extern RBinPlugin r_bin_plugin_menuet;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ bin.elf
|
||||
bin.elf64
|
||||
bin.fs
|
||||
bin.java
|
||||
bin.menuet
|
||||
bin.mach0
|
||||
bin.mach064
|
||||
bin.mbn
|
||||
|
Loading…
x
Reference in New Issue
Block a user