Added initial zimg support
This commit is contained in:
parent
061a2af999
commit
d1351cf836
|
@ -55,6 +55,9 @@ EXTRA +=
|
|||
<library>../../shlr/java
|
||||
;
|
||||
|
||||
# Linux Kernel zImage File
|
||||
OBJS += p/bin_zimg.c ;
|
||||
|
||||
lib r_bin : $(OBJS) :
|
||||
<include>../include
|
||||
<include>mangling
|
||||
|
|
|
@ -14,7 +14,7 @@ char* r_bin_dex_get_version(struct r_bin_dex_obj_t* bin) {
|
|||
|
||||
#define FAIL(x) { eprintf(x); goto fail; }
|
||||
struct r_bin_dex_obj_t* r_bin_dex_new_buf(RBuffer *buf) {
|
||||
struct r_bin_dex_obj_t *bin = R_NEW0 (struct r_bin_dex_obj_t);;
|
||||
struct r_bin_dex_obj_t *bin = R_NEW0 (struct r_bin_dex_obj_t);
|
||||
if (!bin) {
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/* radare - LGPL - Copyright 2009-2015 - ninjahacker */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include "zimg.h"
|
||||
|
||||
|
||||
struct r_bin_zimg_obj_t* r_bin_zimg_new_buf(RBuffer *buf) {
|
||||
struct r_bin_zimg_obj_t *bin = R_NEW0 (struct r_bin_zimg_obj_t);
|
||||
if (!bin) {
|
||||
goto fail;
|
||||
}
|
||||
bin->size = buf->length;
|
||||
bin->b = r_buf_new ();
|
||||
if (!r_buf_set_bytes (bin->b, buf->buf, bin->size)){
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bin->header = (*(struct zimg_header_t*)bin->b->buf);
|
||||
|
||||
return bin;
|
||||
|
||||
fail:
|
||||
if (bin) {
|
||||
r_buf_free (bin->b);
|
||||
free (bin);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_bin.h>
|
||||
|
||||
#define R_BIN_ZIMG_MAXSTR 256
|
||||
|
||||
struct zimg_header_t {
|
||||
ut8 magic[8];
|
||||
ut32 filler[6];
|
||||
ut8 arm_magic[4];
|
||||
ut32 kernel_start;
|
||||
ut32 kernel_end;
|
||||
};
|
||||
|
||||
typedef struct r_bin_zimg_obj_t {
|
||||
int size;
|
||||
const char *file;
|
||||
struct r_buf_t *b;
|
||||
struct zimg_header_t header;
|
||||
ut32 *strings;
|
||||
RList *methods_list;
|
||||
RList *imports_list;
|
||||
ut64 code_from;
|
||||
ut64 code_to;
|
||||
Sdb *kv;
|
||||
} RBinZimgObj;
|
||||
|
||||
struct r_bin_zimg_str_t {
|
||||
char str[R_BIN_ZIMG_MAXSTR];
|
||||
ut64 offset;
|
||||
ut64 ordinal;
|
||||
int size;
|
||||
int last;
|
||||
};
|
||||
|
||||
struct r_bin_zimg_obj_t *r_bin_zimg_new_buf(struct r_buf_t *buf);
|
||||
struct r_bin_zimg_str_t *r_bin_zimg_get_strings (struct r_bin_zimg_obj_t* bin);
|
|
@ -10,7 +10,7 @@ foo: all
|
|||
ALL_TARGETS=
|
||||
FORMATS=any.mk elf.mk elf64.mk pe.mk pe64.mk te.mk mach0.mk
|
||||
FORMATS+=bios.mk mach064.mk fatmach0.mk dyldcache.mk java.mk
|
||||
FORMATS+=dex.mk fs.mk ningb.mk coff.mk ningba.mk xbe.mk
|
||||
FORMATS+=dex.mk fs.mk ningb.mk coff.mk ningba.mk xbe.mk zimg.mk
|
||||
include $(FORMATS)
|
||||
|
||||
all: ${ALL_TARGETS}
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
/* radare - LGPL - Copyright 2011-2015 - ninjahacker */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_bin.h>
|
||||
#include "zimg/zimg.h"
|
||||
|
||||
#define DEBUG_PRINTF 0
|
||||
|
||||
#if DEBUG_PRINTF
|
||||
#define dprintf eprintf
|
||||
#else
|
||||
#define dprintf if (0)eprintf
|
||||
#endif
|
||||
|
||||
static int check(RBinFile *arch);
|
||||
static int check_bytes(const ut8 *buf, ut64 length);
|
||||
|
||||
static Sdb* get_sdb (RBinObject *o) {
|
||||
if (!o) return NULL;
|
||||
struct r_bin_zimg_obj_t *bin = (struct r_bin_zimg_obj_t *) o->bin_obj;
|
||||
if (bin->kv) return bin->kv;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void * load_bytes(const ut8 *buf, ut64 size, ut64 loadaddr, Sdb *sdb){
|
||||
void *res = NULL;
|
||||
RBuffer *tbuf = NULL;
|
||||
if (!buf || size == 0 || size == UT64_MAX) return NULL;
|
||||
tbuf = r_buf_new ();
|
||||
r_buf_set_bytes (tbuf, buf, size);
|
||||
res = r_bin_zimg_new_buf (tbuf);
|
||||
r_buf_free (tbuf);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int load(RBinFile *arch) {
|
||||
const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL;
|
||||
ut64 size = arch ? r_buf_size (arch->buf): 0;
|
||||
|
||||
if (!arch || !arch->o) return R_FALSE;
|
||||
arch->o->bin_obj = load_bytes (bytes, size, arch->o->loadaddr, arch->sdb);
|
||||
return arch->o->bin_obj ? R_TRUE: R_FALSE;
|
||||
}
|
||||
|
||||
static ut64 baddr(RBinFile *arch) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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 R_FALSE;
|
||||
|
||||
// Checking ARM zImage kernel
|
||||
if (!memcmp (buf, "\x00\x00\xa0\xe1\x00\x00\xa0\xe1", 8)) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
// TODO: Add other architectures
|
||||
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
static RBinInfo *info(RBinFile *arch) {
|
||||
|
||||
RBinInfo *ret = R_NEW0 (RBinInfo);
|
||||
if (!ret) return NULL;
|
||||
ret->file = arch->file? strdup (arch->file): NULL;
|
||||
ret->type = strdup ("Linux zImage Kernel");
|
||||
ret->has_va = R_FALSE;
|
||||
ret->bclass = strdup ("Compressed Linux Kernel");
|
||||
ret->rclass = strdup ("zimg");
|
||||
ret->os = strdup ("linux");
|
||||
ret->subsystem = strdup ("linux");
|
||||
ret->machine = strdup ("ARM"); // TODO: can be other cpus
|
||||
ret->arch = strdup ("arm");
|
||||
ret->lang = "C";
|
||||
ret->bits = 32;
|
||||
ret->big_endian = 0;
|
||||
ret->dbg_info = 0; //1 | 4 | 8; /* Stripped | LineNums | Syms */
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
struct r_bin_plugin_t r_bin_plugin_zimg = {
|
||||
.name = "zimg",
|
||||
.desc = "zimg format bin plugin",
|
||||
.license = "LGPL3",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.get_sdb = &get_sdb,
|
||||
.load = &load,
|
||||
.load_bytes = &load_bytes,
|
||||
.destroy = NULL,
|
||||
.check = &check,
|
||||
.check_bytes = &check_bytes,
|
||||
.baddr = &baddr,
|
||||
.boffset = NULL,
|
||||
.binsym = NULL,
|
||||
.entries = NULL,
|
||||
.classes = NULL,
|
||||
.sections = NULL,
|
||||
.symbols = NULL,
|
||||
.imports = NULL,
|
||||
.strings = NULL,
|
||||
.info = &info,
|
||||
.fields = NULL,
|
||||
.libs = NULL,
|
||||
.relocs = NULL,
|
||||
.dbginfo = NULL,
|
||||
.size = NULL,//&size,
|
||||
.write = NULL,
|
||||
.get_offset = NULL//&getoffset
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_BIN,
|
||||
.data = &r_bin_plugin_zimg
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,10 @@
|
|||
OBJ_ZIMG=bin_zimg.o ../format/zimg/zimg.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_ZIMG}
|
||||
TARGET_ZIMG=bin_zimg.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_ZIMG}
|
||||
|
||||
${TARGET_ZIMG}: ${OBJ_ZIMG}
|
||||
${CC} $(call libname,bin_zimg) -shared ${CFLAGS} \
|
||||
-o ${TARGET_ZIMG} ${OBJ_ZIMG} $(LINK) $(LDFLAGS)
|
|
@ -512,6 +512,7 @@ extern RBinPlugin r_bin_plugin_ninds;
|
|||
extern RBinPlugin r_bin_plugin_xbe;
|
||||
extern RBinXtrPlugin r_bin_xtr_plugin_fatmach0;
|
||||
extern RBinXtrPlugin r_bin_xtr_plugin_dyldcache;
|
||||
extern RBinPlugin r_bin_plugin_zimg;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ bin.te
|
|||
bin.xbe
|
||||
bin_xtr.dyldcache
|
||||
bin_xtr.fatmach0
|
||||
bin.zimg
|
||||
bp.arm
|
||||
bp.bf
|
||||
bp.mips
|
||||
|
|
Loading…
Reference in New Issue