Remove defunct Dyldcache Xtr Plugin
This commit is contained in:
parent
4579651550
commit
bf5b9c41be
6 changed files with 1 additions and 568 deletions
|
|
@ -1,295 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2010-2018 nibble <nibble.ds@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2010-2018 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <stdio.h>
|
||||
#include <rz_types.h>
|
||||
#include <rz_util.h>
|
||||
#include "dyldcache.h"
|
||||
|
||||
static int rz_bin_dyldcache_init(struct rz_bin_dyldcache_obj_t *bin) {
|
||||
int len = rz_buf_fread_at(bin->b, 0, (ut8 *)&bin->hdr, "16c4i7l", 1);
|
||||
if (len == -1) {
|
||||
perror("read (cache_header)");
|
||||
return false;
|
||||
}
|
||||
bin->nlibs = bin->hdr.numlibs;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int rz_bin_dyldcache_apply_patch(RzBuffer *buf, ut32 data, ut64 offset) {
|
||||
return rz_buf_write_at(buf, offset, (ut8 *)&data, sizeof(data));
|
||||
}
|
||||
|
||||
#define NZ_OFFSET(x, y, z) \
|
||||
if ((x) > 0) \
|
||||
rz_bin_dyldcache_apply_patch(dbuf, (x)-linkedit_offset, addend + rz_offsetof(y, z))
|
||||
|
||||
// make it public in util/buf.c ?
|
||||
static ut64 rz_buf_read64le(RzBuffer *buf, ut64 off) {
|
||||
ut8 data[8] = { 0 };
|
||||
rz_buf_read_at(buf, off, data, 8);
|
||||
return rz_read_le64(data);
|
||||
}
|
||||
|
||||
static char *rz_buf_read_string(RzBuffer *buf, ut64 addr, int len) {
|
||||
ut8 *data = malloc(len);
|
||||
if (data) {
|
||||
rz_buf_read_at(buf, addr, data, len);
|
||||
data[len - 1] = 0;
|
||||
return (char *)data;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO: Needs more testing and ERROR HANDLING */
|
||||
struct rz_bin_dyldcache_lib_t *rz_bin_dyldcache_extract(struct rz_bin_dyldcache_obj_t *bin, int idx, int *nlib) {
|
||||
ut64 liboff, linkedit_offset;
|
||||
ut64 dyld_vmbase;
|
||||
ut32 addend = 0;
|
||||
struct rz_bin_dyldcache_lib_t *ret = NULL;
|
||||
struct dyld_cache_image_info *image_infos = NULL;
|
||||
struct mach_header mh;
|
||||
ut64 cmdptr;
|
||||
int cmd, libsz = 0;
|
||||
RzBuffer *dbuf = NULL;
|
||||
char *libname;
|
||||
|
||||
if (!bin) {
|
||||
return NULL;
|
||||
}
|
||||
if (bin->size < 1) {
|
||||
eprintf("Empty file? (%s)\n", rz_str_get_null(bin->file));
|
||||
return NULL;
|
||||
}
|
||||
if (bin->nlibs < 0 || idx < 0 || idx >= bin->nlibs) {
|
||||
return NULL;
|
||||
}
|
||||
*nlib = bin->nlibs;
|
||||
ret = RZ_NEW0(struct rz_bin_dyldcache_lib_t);
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
if (bin->hdr.startaddr > bin->size) {
|
||||
eprintf("corrupted dyldcache");
|
||||
goto ret_err;
|
||||
}
|
||||
|
||||
if (bin->hdr.startaddr > bin->size || bin->hdr.baseaddroff > bin->size) {
|
||||
eprintf("corrupted dyldcache");
|
||||
goto ret_err;
|
||||
}
|
||||
int sz = bin->nlibs * sizeof(struct dyld_cache_image_info);
|
||||
image_infos = malloc(sz);
|
||||
if (!image_infos) {
|
||||
goto ret_err;
|
||||
}
|
||||
rz_buf_read_at(bin->b, bin->hdr.startaddr, (ut8 *)image_infos, sz);
|
||||
dyld_vmbase = rz_buf_read64le(bin->b, bin->hdr.baseaddroff);
|
||||
liboff = image_infos[idx].address - dyld_vmbase;
|
||||
if (liboff > bin->size) {
|
||||
eprintf("Corrupted file\n");
|
||||
goto ret_err;
|
||||
}
|
||||
ret->offset = liboff;
|
||||
int pfo = image_infos[idx].pathFileOffset;
|
||||
if (pfo < 0 || pfo > bin->size) {
|
||||
eprintf("corrupted file: pathFileOffset > bin->size (%d)\n", pfo);
|
||||
goto ret_err;
|
||||
}
|
||||
libname = rz_buf_read_string(bin->b, pfo, 64);
|
||||
/* Locate lib hdr in cache */
|
||||
int r = rz_buf_read_at(bin->b, liboff, (ut8 *)&mh, sizeof(mh));
|
||||
if (r != sizeof(mh)) {
|
||||
goto ret_err;
|
||||
}
|
||||
/* Check it is mach-o */
|
||||
if (mh.magic != MH_MAGIC && mh.magic != MH_MAGIC_64) {
|
||||
if (mh.magic == 0xbebafeca) { //FAT binary
|
||||
eprintf("FAT Binary\n");
|
||||
}
|
||||
eprintf("Not mach-o\n");
|
||||
goto ret_err;
|
||||
}
|
||||
addend = mh.magic == MH_MAGIC ? sizeof(struct mach_header) : sizeof(struct mach_header_64);
|
||||
/* Write mach-o hdr */
|
||||
if (!(dbuf = rz_buf_new_with_bytes(NULL, 0))) {
|
||||
eprintf("new (dbuf)\n");
|
||||
goto ret_err;
|
||||
}
|
||||
if (!rz_buf_append_buf_slice(dbuf, bin->b, liboff, addend)) {
|
||||
goto dbuf_err;
|
||||
}
|
||||
cmdptr = liboff + addend;
|
||||
/* Write load commands */
|
||||
for (cmd = 0; cmd < mh.ncmds; cmd++) {
|
||||
struct load_command lc;
|
||||
int r = rz_buf_read_at(bin->b, cmdptr, (ut8 *)&lc, sizeof(lc));
|
||||
if (r != sizeof(lc)) {
|
||||
goto dbuf_err;
|
||||
}
|
||||
rz_buf_append_bytes(dbuf, (ut8 *)&lc, lc.cmdsize);
|
||||
cmdptr += lc.cmdsize;
|
||||
}
|
||||
cmdptr = liboff + addend;
|
||||
/* Write segments */
|
||||
for (cmd = linkedit_offset = 0; cmd < mh.ncmds; cmd++) {
|
||||
struct load_command lc;
|
||||
int r = rz_buf_read_at(bin->b, cmdptr, (ut8 *)&lc, sizeof(lc));
|
||||
if (r != sizeof(lc)) {
|
||||
goto dbuf_err;
|
||||
}
|
||||
switch (lc.cmd) {
|
||||
case LC_SEGMENT: {
|
||||
/* Write segment and patch offset */
|
||||
struct segment_command seg;
|
||||
r = rz_buf_read_at(bin->b, cmdptr, (ut8 *)&seg, sizeof(seg));
|
||||
if (r != sizeof(seg)) {
|
||||
goto dbuf_err;
|
||||
}
|
||||
int t = seg.filesize;
|
||||
if (seg.fileoff + seg.filesize > bin->size || seg.fileoff > bin->size) {
|
||||
eprintf("malformed dyldcache\n");
|
||||
goto dbuf_err;
|
||||
}
|
||||
rz_buf_append_buf_slice(dbuf, bin->b, seg.fileoff, t);
|
||||
rz_bin_dyldcache_apply_patch(dbuf, rz_buf_size(dbuf),
|
||||
addend + rz_offsetof(struct segment_command, fileoff));
|
||||
/* Patch section offsets */
|
||||
int sect_offset = seg.fileoff - libsz;
|
||||
libsz = rz_buf_size(dbuf);
|
||||
if (!strcmp(seg.segname, "__LINKEDIT")) {
|
||||
linkedit_offset = sect_offset;
|
||||
}
|
||||
if (seg.nsects > 0) {
|
||||
int nsect;
|
||||
for (nsect = 0; nsect < seg.nsects; nsect++) {
|
||||
struct section sect;
|
||||
r = rz_buf_read_at(bin->b, cmdptr + nsect * sizeof(struct segment_command), (ut8 *)§, sizeof(sect));
|
||||
if (r != sizeof(sect)) {
|
||||
break;
|
||||
}
|
||||
if (sect.offset > libsz) {
|
||||
rz_bin_dyldcache_apply_patch(dbuf, sect.offset - sect_offset,
|
||||
addend + rz_offsetof(struct section, offset));
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case LC_SYMTAB: {
|
||||
struct symtab_command st;
|
||||
r = rz_buf_read_at(bin->b, cmdptr, (ut8 *)&st, sizeof(st));
|
||||
if (r != sizeof(st)) {
|
||||
goto dbuf_err;
|
||||
}
|
||||
NZ_OFFSET(st.symoff, struct symtab_command, symoff);
|
||||
NZ_OFFSET(st.stroff, struct symtab_command, stroff);
|
||||
} break;
|
||||
case LC_DYSYMTAB: {
|
||||
struct dysymtab_command st;
|
||||
r = rz_buf_read_at(bin->b, cmdptr, (ut8 *)&st, sizeof(st));
|
||||
if (r != sizeof(st)) {
|
||||
goto dbuf_err;
|
||||
}
|
||||
NZ_OFFSET(st.tocoff, struct dysymtab_command, tocoff);
|
||||
NZ_OFFSET(st.modtaboff, struct dysymtab_command, modtaboff);
|
||||
NZ_OFFSET(st.extrefsymoff, struct dysymtab_command, extrefsymoff);
|
||||
NZ_OFFSET(st.indirectsymoff, struct dysymtab_command, indirectsymoff);
|
||||
NZ_OFFSET(st.extreloff, struct dysymtab_command, extreloff);
|
||||
NZ_OFFSET(st.locreloff, struct dysymtab_command, locreloff);
|
||||
} break;
|
||||
case LC_DYLD_INFO:
|
||||
case LC_DYLD_INFO_ONLY: {
|
||||
struct dyld_info_command st;
|
||||
r = rz_buf_read_at(bin->b, cmdptr, (ut8 *)&st, sizeof(st));
|
||||
if (r != sizeof(st)) {
|
||||
goto dbuf_err;
|
||||
}
|
||||
NZ_OFFSET(st.rebase_off, struct dyld_info_command, rebase_off);
|
||||
NZ_OFFSET(st.bind_off, struct dyld_info_command, bind_off);
|
||||
NZ_OFFSET(st.weak_bind_off, struct dyld_info_command, weak_bind_off);
|
||||
NZ_OFFSET(st.lazy_bind_off, struct dyld_info_command, lazy_bind_off);
|
||||
NZ_OFFSET(st.export_off, struct dyld_info_command, export_off);
|
||||
} break;
|
||||
}
|
||||
cmdptr += lc.cmdsize;
|
||||
}
|
||||
/* Fill rz_bin_dyldcache_lib_t ret */
|
||||
ret->b = dbuf;
|
||||
strncpy(ret->path, libname, sizeof(ret->path) - 1);
|
||||
ret->size = libsz;
|
||||
return ret;
|
||||
|
||||
dbuf_err:
|
||||
rz_buf_free(dbuf);
|
||||
ret_err:
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *rz_bin_dyldcache_free(struct rz_bin_dyldcache_obj_t *bin) {
|
||||
if (!bin) {
|
||||
return NULL;
|
||||
}
|
||||
rz_buf_free(bin->b);
|
||||
free(bin);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rz_bin_dydlcache_get_libname(struct rz_bin_dyldcache_lib_t *lib, char **libname) {
|
||||
char *cur = lib->path;
|
||||
char *res = lib->path;
|
||||
int path_length = strlen(lib->path);
|
||||
while (cur < cur + path_length - 1) {
|
||||
cur = strchr(cur, '/');
|
||||
if (!cur) {
|
||||
break;
|
||||
}
|
||||
cur++;
|
||||
res = cur;
|
||||
}
|
||||
*libname = res;
|
||||
}
|
||||
|
||||
struct rz_bin_dyldcache_obj_t *rz_bin_dyldcache_new(const char *file) {
|
||||
struct rz_bin_dyldcache_obj_t *bin;
|
||||
if (!(bin = RZ_NEW0(struct rz_bin_dyldcache_obj_t))) {
|
||||
return NULL;
|
||||
}
|
||||
bin->file = file;
|
||||
size_t binsz;
|
||||
ut8 *buf = (ut8 *)rz_file_slurp(file, &binsz);
|
||||
bin->size = binsz;
|
||||
if (!buf) {
|
||||
return rz_bin_dyldcache_free(bin);
|
||||
}
|
||||
bin->b = rz_buf_new_with_bytes(NULL, 0);
|
||||
if (!rz_buf_set_bytes(bin->b, buf, bin->size)) {
|
||||
free(buf);
|
||||
return rz_bin_dyldcache_free(bin);
|
||||
}
|
||||
free(buf);
|
||||
if (!rz_bin_dyldcache_init(bin)) {
|
||||
return rz_bin_dyldcache_free(bin);
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
|
||||
struct rz_bin_dyldcache_obj_t *rz_bin_dyldcache_from_bytes_new(const ut8 *buf, ut64 size) {
|
||||
struct rz_bin_dyldcache_obj_t *bin = RZ_NEW0(struct rz_bin_dyldcache_obj_t);
|
||||
if (!bin) {
|
||||
return NULL;
|
||||
}
|
||||
if (!buf) {
|
||||
return rz_bin_dyldcache_free(bin);
|
||||
}
|
||||
bin->b = rz_buf_new_with_bytes(NULL, 0);
|
||||
if (!bin->b || !rz_buf_set_bytes(bin->b, buf, size)) {
|
||||
return rz_bin_dyldcache_free(bin);
|
||||
}
|
||||
if (!rz_bin_dyldcache_init(bin)) {
|
||||
return rz_bin_dyldcache_free(bin);
|
||||
}
|
||||
bin->size = size;
|
||||
return bin;
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2009-2010 nibble <nibble.ds@gmail.com>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_types.h>
|
||||
#include "mach0_specs.h"
|
||||
|
||||
#ifndef _INCLUDE_R_BIN_DYLDCACHE_H_
|
||||
#define _INCLUDE_R_BIN_DYLDCACHE_H_
|
||||
|
||||
struct rz_bin_dyldcache_obj_t {
|
||||
const char *file;
|
||||
int size;
|
||||
int nlibs;
|
||||
struct cache_header hdr;
|
||||
RzBuffer *b;
|
||||
};
|
||||
|
||||
struct rz_bin_dyldcache_lib_t {
|
||||
char path[1024];
|
||||
int size;
|
||||
ut64 offset;
|
||||
RzBuffer *b;
|
||||
int last;
|
||||
};
|
||||
|
||||
struct dyld_cache_mapping_info {
|
||||
ut64 address;
|
||||
ut64 size;
|
||||
ut64 fileOffset;
|
||||
ut32 maxProt;
|
||||
ut32 initProt;
|
||||
};
|
||||
|
||||
struct dyld_cache_image_info {
|
||||
ut64 address;
|
||||
ut64 modTime;
|
||||
ut64 inode;
|
||||
ut32 pathFileOffset;
|
||||
ut32 pad;
|
||||
};
|
||||
|
||||
struct dyld_cache_slide_info {
|
||||
ut32 version;
|
||||
ut32 toc_offset;
|
||||
ut32 toc_count;
|
||||
ut32 entries_offset;
|
||||
ut32 entries_count;
|
||||
ut32 entries_size;
|
||||
};
|
||||
|
||||
typedef struct _dyld_cache_local_symbols_info {
|
||||
ut32 nlistOffset;
|
||||
ut32 nlistCount;
|
||||
ut32 stringsOffset;
|
||||
ut32 stringsSize;
|
||||
ut32 entriesOffset;
|
||||
ut32 entriesCount;
|
||||
} dyld_cache_local_symbols_info;
|
||||
|
||||
typedef struct _dyld_cache_local_symbols_entry {
|
||||
ut32 dylibOffset;
|
||||
ut32 nlistStartIndex;
|
||||
ut32 nlistCount;
|
||||
} dyld_cache_local_symbols_entry;
|
||||
|
||||
struct rz_bin_dyldcache_lib_t *rz_bin_dyldcache_extract(struct rz_bin_dyldcache_obj_t *bin, int idx, int *nlib);
|
||||
void *rz_bin_dyldcache_free(struct rz_bin_dyldcache_obj_t *bin);
|
||||
struct rz_bin_dyldcache_obj_t *rz_bin_dyldcache_new(const char *file);
|
||||
struct rz_bin_dyldcache_obj_t *rz_bin_dyldcache_from_bytes_new(const ut8 *bytes, ut64 size);
|
||||
void rz_bin_dydlcache_get_libname(struct rz_bin_dyldcache_lib_t *lib, char **libname);
|
||||
|
||||
#endif
|
||||
|
|
@ -66,7 +66,6 @@ rz_bin_sources = [
|
|||
'p/bin_write_pe64.c',
|
||||
'p/bin_xbe.c',
|
||||
'p/bin_xnu_kernelcache.c',
|
||||
'p/bin_xtr_dyldcache.c',
|
||||
'p/bin_xtr_fatmach0.c',
|
||||
'p/bin_xtr_pemixed.c',
|
||||
'p/bin_xtr_sep64.c',
|
||||
|
|
@ -89,7 +88,6 @@ rz_bin_sources = [
|
|||
'format/java/class_field.c',
|
||||
'format/java/class_method.c',
|
||||
'format/mach0/coresymbolication.c',
|
||||
'format/mach0/dyldcache.c',
|
||||
'format/mach0/fatmach0.c',
|
||||
'format/mach0/mach0.c',
|
||||
'format/mach0/mach0_rebase.c',
|
||||
|
|
|
|||
|
|
@ -1,195 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2009-2019 nibble <nibble.ds@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2009-2019 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_types.h>
|
||||
#include <rz_util.h>
|
||||
#include <rz_lib.h>
|
||||
#include <rz_bin.h>
|
||||
#include "mach0/dyldcache.h"
|
||||
#include "mach0/mach0.h"
|
||||
|
||||
static RzBinXtrData *extract(RzBin *bin, int idx);
|
||||
static RzList *extractall(RzBin *bin);
|
||||
static RzBinXtrData *oneshot(RzBin *bin, const ut8 *buf, ut64 size, int idx);
|
||||
static RzList *oneshotall(RzBin *bin, const ut8 *buf, ut64 size);
|
||||
|
||||
static bool check_buffer(RzBuffer *buf) {
|
||||
ut8 b[4] = { 0 };
|
||||
rz_buf_read_at(buf, 0, b, sizeof(b));
|
||||
return !memcmp(buf, "dyld", 4);
|
||||
}
|
||||
|
||||
static void free_xtr(void *xtr_obj) {
|
||||
rz_bin_dyldcache_free((struct rz_bin_dyldcache_obj_t *)xtr_obj);
|
||||
}
|
||||
|
||||
static void destroy(RzBin *bin) {
|
||||
free_xtr(bin->cur->xtr_obj);
|
||||
}
|
||||
|
||||
static bool load(RzBin *bin) {
|
||||
if (!bin || !bin->cur) {
|
||||
return false;
|
||||
}
|
||||
if (!bin->cur->xtr_obj) {
|
||||
bin->cur->xtr_obj = rz_bin_dyldcache_new(bin->cur->file);
|
||||
}
|
||||
if (!bin->file) {
|
||||
bin->file = bin->cur->file;
|
||||
}
|
||||
return bin->cur->xtr_obj ? true : false;
|
||||
}
|
||||
|
||||
static RzList *extractall(RzBin *bin) {
|
||||
RzList *result = NULL;
|
||||
int nlib, i = 0;
|
||||
RzBinXtrData *data = extract(bin, i);
|
||||
if (!data) {
|
||||
return result;
|
||||
}
|
||||
// XXX - how do we validate a valid nlib?
|
||||
nlib = data->file_count;
|
||||
result = rz_list_newf(rz_bin_xtrdata_free);
|
||||
if (!result) {
|
||||
rz_bin_xtrdata_free(data);
|
||||
return NULL;
|
||||
}
|
||||
rz_list_append(result, data);
|
||||
for (i = 1; data && i < nlib; i++) {
|
||||
data = extract(bin, i);
|
||||
rz_list_append(result, data);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void fill_metadata_info_from_hdr(RzBinXtrMetadata *meta, struct MACH0_(mach_header) * hdr) {
|
||||
meta->arch = strdup(MACH0_(get_cputype_from_hdr)(hdr));
|
||||
meta->bits = MACH0_(get_bits_from_hdr)(hdr);
|
||||
meta->machine = MACH0_(get_cpusubtype_from_hdr)(hdr);
|
||||
meta->type = MACH0_(get_filetype_from_hdr)(hdr);
|
||||
}
|
||||
|
||||
static RzBinXtrData *extract(RzBin *bin, int idx) {
|
||||
int nlib = 0;
|
||||
RzBinXtrData *res = NULL;
|
||||
char *libname;
|
||||
struct MACH0_(mach_header) * hdr;
|
||||
struct rz_bin_dyldcache_lib_t *lib = rz_bin_dyldcache_extract(
|
||||
(struct rz_bin_dyldcache_obj_t *)bin->cur->xtr_obj, idx, &nlib);
|
||||
|
||||
if (lib) {
|
||||
RzBinXtrMetadata *metadata = RZ_NEW0(RzBinXtrMetadata);
|
||||
if (!metadata) {
|
||||
free(lib);
|
||||
return NULL;
|
||||
}
|
||||
hdr = MACH0_(get_hdr)(lib->b);
|
||||
if (!hdr) {
|
||||
free(lib);
|
||||
RZ_FREE(metadata);
|
||||
free(hdr);
|
||||
return NULL;
|
||||
}
|
||||
fill_metadata_info_from_hdr(metadata, hdr);
|
||||
rz_bin_dydlcache_get_libname(lib, &libname);
|
||||
metadata->libname = strdup(libname);
|
||||
|
||||
res = rz_bin_xtrdata_new(lib->b, lib->offset, lib->size, nlib, metadata);
|
||||
rz_buf_free(lib->b);
|
||||
free(lib);
|
||||
free(hdr);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static RzBinXtrData *oneshot(RzBin *bin, const ut8 *buf, ut64 size, int idx) {
|
||||
RzBinXtrData *res = NULL;
|
||||
struct rz_bin_dyldcache_obj_t *xtr_obj;
|
||||
struct rz_bin_dyldcache_lib_t *lib;
|
||||
int nlib = 0;
|
||||
char *libname;
|
||||
struct MACH0_(mach_header) * hdr;
|
||||
|
||||
if (!load(bin)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xtr_obj = bin->cur->xtr_obj;
|
||||
lib = rz_bin_dyldcache_extract(xtr_obj, idx, &nlib);
|
||||
if (!lib) {
|
||||
free_xtr(xtr_obj);
|
||||
bin->cur->xtr_obj = NULL;
|
||||
return NULL;
|
||||
}
|
||||
RzBinXtrMetadata *metadata = RZ_NEW0(RzBinXtrMetadata);
|
||||
if (!metadata) {
|
||||
free(lib);
|
||||
return NULL;
|
||||
}
|
||||
hdr = MACH0_(get_hdr)(lib->b);
|
||||
if (!hdr) {
|
||||
free(lib);
|
||||
free(metadata);
|
||||
return NULL;
|
||||
}
|
||||
fill_metadata_info_from_hdr(metadata, hdr);
|
||||
rz_bin_dydlcache_get_libname(lib, &libname);
|
||||
metadata->libname = strdup(libname);
|
||||
|
||||
res = rz_bin_xtrdata_new(lib->b, lib->offset, rz_buf_size(lib->b), nlib, metadata);
|
||||
rz_buf_free(lib->b);
|
||||
free(hdr);
|
||||
free(lib);
|
||||
return res;
|
||||
}
|
||||
|
||||
static RzList *oneshotall(RzBin *bin, const ut8 *buf, ut64 size) {
|
||||
RzBinXtrData *data = NULL;
|
||||
RzList *res = NULL;
|
||||
int nlib, i = 0;
|
||||
if (!bin->file) {
|
||||
if (!load(bin)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
data = oneshot(bin, buf, size, i);
|
||||
if (!data) {
|
||||
return res;
|
||||
}
|
||||
// XXX - how do we validate a valid nlib?
|
||||
nlib = data->file_count;
|
||||
res = rz_list_newf(rz_bin_xtrdata_free);
|
||||
if (!res) {
|
||||
rz_bin_xtrdata_free(data);
|
||||
return NULL;
|
||||
}
|
||||
rz_list_append(res, data);
|
||||
for (i = 1; data && i < nlib; i++) {
|
||||
data = oneshot(bin, buf, size, i);
|
||||
rz_list_append(res, data);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
RzBinXtrPlugin rz_bin_xtr_plugin_xtr_dyldcache = {
|
||||
.name = "xtr.dyldcache",
|
||||
.desc = "dyld cache bin extractor plugin",
|
||||
.license = "LGPL3",
|
||||
.load = &load,
|
||||
.extract = &extract,
|
||||
.extractall = &extractall,
|
||||
.destroy = &destroy,
|
||||
.extract_from_bytes = &oneshot,
|
||||
.extractall_from_bytes = &oneshotall,
|
||||
.free_xtr = &free_xtr,
|
||||
.check_buffer = &check_buffer,
|
||||
};
|
||||
|
||||
#ifndef RZ_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct rizin_plugin = {
|
||||
.type = RZ_LIB_TYPE_BIN_XTR,
|
||||
.data = &rz_bin_xtr_plugin_dyldcache,
|
||||
.version = RZ_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -187,7 +187,6 @@ bin_ldr_plugins = [
|
|||
]
|
||||
|
||||
bin_xtr_plugins = [
|
||||
'xtr_dyldcache',
|
||||
'xtr_fatmach0',
|
||||
'xtr_sep64',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -147,7 +147,6 @@ bin xbe Microsoft Xbox xbe format rz_bin plugin (LGPL3)
|
|||
bin kernelcache kernelcache bin plugin (LGPL3)
|
||||
bin z64 Nintendo 64 binaries big endian rz_bin plugin (LGPL3)
|
||||
bin zimg zimg format bin plugin (LGPL3)
|
||||
xtr .dyldcache dyld cache bin extractor plugin (LGPL3)
|
||||
xtr .fatmach0 fat mach0 bin extractor plugin (LGPL3)
|
||||
xtr .sep64 64-bit SEP bin extractor plugin (LGPL3)
|
||||
ldr .linux Linux loader plugin for RzBin (MIT)
|
||||
|
|
@ -211,7 +210,6 @@ xbe
|
|||
kernelcache
|
||||
z64
|
||||
zimg
|
||||
xtr.dyldcache
|
||||
xtr.fatmach0
|
||||
xtr.sep64
|
||||
ldr.linux
|
||||
|
|
@ -222,7 +220,7 @@ NAME=Print the bin plugins in JSON
|
|||
FILE==
|
||||
CMDS=Lij
|
||||
EXPECT=<<EOF
|
||||
[{"name":"any","description":"Dummy format rz_bin plugin","license":"LGPL3"},{"name":"art","description":"Android Runtime","license":"LGPL3"},{"name":"avr","description":"ATmel AVR MCUs","license":"LGPL3"},{"name":"bf","description":"brainfuck","license":"LGPL3"},{"name":"bflt","description":"bFLT format rz_bin plugin","license":"LGPL3"},{"name":"bios","description":"BIOS bin plugin","license":"LGPL"},{"name":"bootimg","description":"Android Boot Image","license":"LGPL3"},{"name":"cgc","description":"CGC format rz_bin plugin","license":"LGPL3"},{"name":"coff","description":"COFF format rz_bin plugin","license":"LGPL3"},{"name":"dex","description":"dex format bin plugin","license":"LGPL3"},{"name":"dmp64","description":"Windows Crash Dump x64 rz_bin plugin","license":"LGPL3"},{"name":"dol","description":"Nintendo Dolphin binary format","license":"BSD"},{"name":"dyldcache","description":"dyldcache bin plugin","license":"LGPL3"},{"name":"elf","description":"ELF format plugin","license":"LGPL3"},{"name":"elf64","description":"elf64 bin plugin","license":"LGPL3"},{"name":"java","description":"java bin plugin","license":"LGPL3"},{"name":"le","description":"LE/LX format plugin","license":"LGPL3"},{"name":"luac","description":"LUA Compiled File","license":"LGPL3"},{"name":"mach0","description":"mach0 bin plugin","license":"LGPL3"},{"name":"mach064","description":"mach064 bin plugin","license":"LGPL3"},{"name":"mbn","description":"MBN/SBL bootloader things","license":"LGPL3"},{"name":"mdmp","description":"Minidump format rz_bin plugin","license":"LGPL3"},{"name":"menuet","description":"Menuet/KolibriOS bin plugin","license":"LGPL3"},{"name":"mz","description":"MZ bin plugin","license":"MIT"},{"name":"ne","description":"NE format plugin","license":"LGPL3"},{"name":"nes","description":"NES","license":"MIT"},{"name":"nin3ds","description":"Nintendo 3DS FIRM format rz_bin plugin","license":"LGPL3"},{"name":"ninds","description":"Nintendo DS format rz_bin plugin","license":"LGPL3"},{"name":"ningb","description":"Gameboy format rz_bin plugin","license":"LGPL3"},{"name":"ningba","description":"Game Boy Advance format rz_bin plugin","license":"LGPL3"},{"name":"nro","description":"Nintendo Switch NRO0 binaries","license":"MIT"},{"name":"nso","description":"Nintendo Switch NSO0 binaries","license":"MIT"},{"name":"omf","description":"omf bin plugin","license":"LGPL3"},{"name":"qnx","description":"QNX executable file support","license":"LGPL3"},{"name":"p9","description":"Plan9 bin plugin","license":"LGPL3"},{"name":"pe","description":"PE bin plugin","license":"LGPL3"},{"name":"pe64","description":"PE64 (PE32+) bin plugin","license":"LGPL3"},{"name":"pebble","description":"Pebble Watch App","license":"LGPL"},{"name":"prg","description":"C64 PRG","license":"LGPL3"},{"name":"psxexe","description":"Sony PlayStation 1 Executable","license":"LGPL3"},{"name":"pyc","description":"Python byte-compiled file plugin","license":"LGPL3"},{"name":"sfc","description":"Super NES / Super Famicom ROM file","license":"LGPL3"},{"name":"smd","description":"SEGA Genesis/Megadrive","license":"LGPL3"},{"name":"sms","description":"SEGA MasterSystem/GameGear","license":"LGPL3"},{"name":"spc700","description":"SNES-SPC700 Sound File Data","license":"LGPL3"},{"name":"symbols","description":"Apple Symbols file","license":"MIT"},{"name":"te","description":"TE bin plugin","license":"LGPL3"},{"name":"vsf","description":"VICE Snapshot File","license":"LGPL3"},{"name":"wasm","description":"WebAssembly bin plugin","license":"MIT"},{"name":"xbe","description":"Microsoft Xbox xbe format rz_bin plugin","license":"LGPL3"},{"name":"kernelcache","description":"kernelcache bin plugin","license":"LGPL3"},{"name":"z64","description":"Nintendo 64 binaries big endian rz_bin plugin","license":"LGPL3"},{"name":"zimg","description":"zimg format bin plugin","license":"LGPL3"},{"name":"xtr.dyldcache","description":"dyld cache bin extractor plugin","license":"LGPL3"},{"name":"xtr.fatmach0","description":"fat mach0 bin extractor plugin","license":"LGPL3"},{"name":"xtr.sep64","description":"64-bit SEP bin extractor plugin","license":"LGPL3"},{"name":"ldr.linux","description":"Linux loader plugin for RzBin","license":"MIT"}]
|
||||
[{"name":"any","description":"Dummy format rz_bin plugin","license":"LGPL3"},{"name":"art","description":"Android Runtime","license":"LGPL3"},{"name":"avr","description":"ATmel AVR MCUs","license":"LGPL3"},{"name":"bf","description":"brainfuck","license":"LGPL3"},{"name":"bflt","description":"bFLT format rz_bin plugin","license":"LGPL3"},{"name":"bios","description":"BIOS bin plugin","license":"LGPL"},{"name":"bootimg","description":"Android Boot Image","license":"LGPL3"},{"name":"cgc","description":"CGC format rz_bin plugin","license":"LGPL3"},{"name":"coff","description":"COFF format rz_bin plugin","license":"LGPL3"},{"name":"dex","description":"dex format bin plugin","license":"LGPL3"},{"name":"dmp64","description":"Windows Crash Dump x64 rz_bin plugin","license":"LGPL3"},{"name":"dol","description":"Nintendo Dolphin binary format","license":"BSD"},{"name":"dyldcache","description":"dyldcache bin plugin","license":"LGPL3"},{"name":"elf","description":"ELF format plugin","license":"LGPL3"},{"name":"elf64","description":"elf64 bin plugin","license":"LGPL3"},{"name":"java","description":"java bin plugin","license":"LGPL3"},{"name":"le","description":"LE/LX format plugin","license":"LGPL3"},{"name":"luac","description":"LUA Compiled File","license":"LGPL3"},{"name":"mach0","description":"mach0 bin plugin","license":"LGPL3"},{"name":"mach064","description":"mach064 bin plugin","license":"LGPL3"},{"name":"mbn","description":"MBN/SBL bootloader things","license":"LGPL3"},{"name":"mdmp","description":"Minidump format rz_bin plugin","license":"LGPL3"},{"name":"menuet","description":"Menuet/KolibriOS bin plugin","license":"LGPL3"},{"name":"mz","description":"MZ bin plugin","license":"MIT"},{"name":"ne","description":"NE format plugin","license":"LGPL3"},{"name":"nes","description":"NES","license":"MIT"},{"name":"nin3ds","description":"Nintendo 3DS FIRM format rz_bin plugin","license":"LGPL3"},{"name":"ninds","description":"Nintendo DS format rz_bin plugin","license":"LGPL3"},{"name":"ningb","description":"Gameboy format rz_bin plugin","license":"LGPL3"},{"name":"ningba","description":"Game Boy Advance format rz_bin plugin","license":"LGPL3"},{"name":"nro","description":"Nintendo Switch NRO0 binaries","license":"MIT"},{"name":"nso","description":"Nintendo Switch NSO0 binaries","license":"MIT"},{"name":"omf","description":"omf bin plugin","license":"LGPL3"},{"name":"qnx","description":"QNX executable file support","license":"LGPL3"},{"name":"p9","description":"Plan9 bin plugin","license":"LGPL3"},{"name":"pe","description":"PE bin plugin","license":"LGPL3"},{"name":"pe64","description":"PE64 (PE32+) bin plugin","license":"LGPL3"},{"name":"pebble","description":"Pebble Watch App","license":"LGPL"},{"name":"prg","description":"C64 PRG","license":"LGPL3"},{"name":"psxexe","description":"Sony PlayStation 1 Executable","license":"LGPL3"},{"name":"pyc","description":"Python byte-compiled file plugin","license":"LGPL3"},{"name":"sfc","description":"Super NES / Super Famicom ROM file","license":"LGPL3"},{"name":"smd","description":"SEGA Genesis/Megadrive","license":"LGPL3"},{"name":"sms","description":"SEGA MasterSystem/GameGear","license":"LGPL3"},{"name":"spc700","description":"SNES-SPC700 Sound File Data","license":"LGPL3"},{"name":"symbols","description":"Apple Symbols file","license":"MIT"},{"name":"te","description":"TE bin plugin","license":"LGPL3"},{"name":"vsf","description":"VICE Snapshot File","license":"LGPL3"},{"name":"wasm","description":"WebAssembly bin plugin","license":"MIT"},{"name":"xbe","description":"Microsoft Xbox xbe format rz_bin plugin","license":"LGPL3"},{"name":"kernelcache","description":"kernelcache bin plugin","license":"LGPL3"},{"name":"z64","description":"Nintendo 64 binaries big endian rz_bin plugin","license":"LGPL3"},{"name":"zimg","description":"zimg format bin plugin","license":"LGPL3"},{"name":"xtr.fatmach0","description":"fat mach0 bin extractor plugin","license":"LGPL3"},{"name":"xtr.sep64","description":"64-bit SEP bin extractor plugin","license":"LGPL3"},{"name":"ldr.linux","description":"Linux loader plugin for RzBin","license":"MIT"}]
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue