2012-08-04 23:48:06 +02:00
|
|
|
/* radare - LGPL - Copyright 2009-2012 nibble<.ds@gmail.com> */
|
2010-10-01 04:26:52 +02:00
|
|
|
|
|
|
|
#include <r_types.h>
|
|
|
|
#include <r_util.h>
|
|
|
|
#include <r_lib.h>
|
|
|
|
#include <r_bin.h>
|
|
|
|
#include "mach0/dyldcache.h"
|
|
|
|
|
|
|
|
static int check(RBin *bin) {
|
|
|
|
int size, ret = R_FALSE;
|
2010-11-18 11:41:17 +01:00
|
|
|
ut8 *filebuf = (ut8*)r_file_slurp_range (bin->file, 0, 4, &size);
|
2010-10-01 04:26:52 +02:00
|
|
|
if (filebuf && size == 4) {
|
|
|
|
if (!memcmp (filebuf, "\x64\x79\x6c\x64", 4))
|
|
|
|
ret = R_TRUE;
|
|
|
|
free (filebuf);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-18 11:41:17 +01:00
|
|
|
// TODO: destroy must be void?
|
2010-10-01 04:26:52 +02:00
|
|
|
static int destroy(RBin *bin) {
|
|
|
|
r_bin_dyldcache_free ((struct r_bin_dyldcache_obj_t*)bin->bin_obj);
|
|
|
|
return R_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-10-04 03:46:58 +02:00
|
|
|
static int load(RBin *bin) {
|
2010-11-18 11:41:17 +01:00
|
|
|
return ((bin->bin_obj = r_bin_dyldcache_new (bin->file)))? R_TRUE: R_FALSE;
|
2010-10-04 03:46:58 +02:00
|
|
|
}
|
2010-10-01 04:26:52 +02:00
|
|
|
|
2010-10-04 03:46:58 +02:00
|
|
|
static int extract(RBin *bin, int idx) {
|
2010-11-18 11:41:17 +01:00
|
|
|
int nlib = 0;
|
|
|
|
struct r_bin_dyldcache_lib_t *lib = r_bin_dyldcache_extract (
|
|
|
|
(struct r_bin_dyldcache_obj_t*)bin->bin_obj, idx, &nlib);
|
|
|
|
if (lib) {
|
2012-08-04 23:48:06 +02:00
|
|
|
bin->cur.file = strdup (lib->path);
|
2013-06-20 02:49:39 +02:00
|
|
|
bin->cur.offset = lib->offset;
|
2012-08-04 23:48:06 +02:00
|
|
|
bin->cur.buf = lib->b;
|
|
|
|
bin->cur.size = lib->size;
|
2010-11-18 11:41:17 +01:00
|
|
|
free (lib);
|
|
|
|
}
|
2010-10-04 03:46:58 +02:00
|
|
|
return nlib;
|
2010-10-01 04:26:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct r_bin_xtr_plugin_t r_bin_xtr_plugin_dyldcache = {
|
|
|
|
.name = "dyldcache",
|
|
|
|
.desc = "dyld cache bin extractor plugin",
|
2013-12-10 04:19:04 +01:00
|
|
|
.license = "LGPL3",
|
2010-10-01 04:26:52 +02:00
|
|
|
.init = NULL,
|
|
|
|
.fini = NULL,
|
|
|
|
.check = &check,
|
2010-10-04 03:46:58 +02:00
|
|
|
.load = &load,
|
2010-10-01 04:26:52 +02:00
|
|
|
.extract = &extract,
|
|
|
|
.destroy = &destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef CORELIB
|
|
|
|
struct r_lib_struct_t radare_plugin = {
|
|
|
|
.type = R_LIB_TYPE_BIN_XTR,
|
|
|
|
.data = &r_bin_xtr_plugin_dyldcache
|
|
|
|
};
|
|
|
|
#endif
|