* Massive refactoring of r_bin

- Add support for fatbins (currently only fatmach0)
  - Minimize creation of r_buffers
* rabin2
  - Add flag -A for listing archs
  - Add flags -a and -B for selecting arch
  - In the next commit -A and -B will be removed and -a will work
    with the following format:
    [-a arch bits] for selecting arch
	[-a] for listing them

--HG--
rename : libr/bin/p/bin_fatmach0.c => libr/bin/p/bin_xtr_fatmach0.c
This commit is contained in:
Nibble 2010-09-24 21:23:13 +02:00
parent d71fcd2708
commit 793dae395d
31 changed files with 597 additions and 466 deletions

1
TODO
View File

@ -26,6 +26,7 @@ Questions
TODO nibble
-----------
* implement rabin2 -x
* Cx/CX are not displayed in disasm as they should.. (C! must die)
* Better way to fix got_offset issue?
* use r_anal_value everywhere in r_anal

View File

@ -30,6 +30,7 @@
#define ACTION_MAIN 0x0800
#define ACTION_EXTRACT 0x1000
#define ACTION_RELOCS 0x2000
#define ACTION_LISTARCHS 0x4000
static struct r_lib_t *l;
static struct r_bin_t *bin = NULL;
@ -44,6 +45,8 @@ static char *name = NULL;
static int rabin_show_help() {
printf ("rabin2 [options] [file]\n"
" -a [arch] Set arch\n"
" -B [bits] Set bits\n"
" -b [addr] Override baddr\n"
" -e Entrypoint\n"
" -M Main\n"
@ -57,7 +60,6 @@ static int rabin_show_help() {
" -R Relocations\n"
" -O [str] Write/Extract operations (str=help for help)\n"
" -o [file] Output file for write operations (a.out by default)\n"
" -f [format] Override file format autodetection\n"
" -r radare output\n"
" -v Use vaddr in radare output\n"
" -m [addr] Show source line at addr\n"
@ -67,7 +69,7 @@ static int rabin_show_help() {
" -x Extract bins contained in file\n"
" -V Show version information\n"
" -h This help\n");
return R_TRUE;
return 1;
}
static int rabin_show_entrypoints() {
@ -82,7 +84,7 @@ static int rabin_show_entrypoints() {
return R_FALSE;
if (rad) printf ("fs symbols\n");
else printf ("[Entrypoints]\n");
else eprintf ("[Entrypoints]\n");
r_list_foreach (entries, iter, entry) {
if (rad) {
@ -93,7 +95,7 @@ static int rabin_show_entrypoints() {
i++;
}
if (!rad) printf ("\n%i entrypoints\n", i);
if (!rad) eprintf ("\n%i entrypoints\n", i);
return R_TRUE;
}
@ -106,7 +108,7 @@ static int rabin_show_main() {
return R_FALSE;
if (rad) printf ("fs symbols\n");
else printf ("[Main]\n");
else eprintf ("[Main]\n");
if (rad) {
printf ("f main @ 0x%08"PFMT64x"\n", va?baddr+binmain->rva:binmain->offset);
@ -117,12 +119,8 @@ static int rabin_show_main() {
}
static int rabin_extract() {
int n = r_bin_extract (bin);
if (n != 0) {
if (!rad) printf ("%i bins extracted\n", n);
return R_TRUE;
}
return R_FALSE;
/* TODO */
return R_TRUE;
}
static int rabin_show_libs() {
@ -134,14 +132,14 @@ static int rabin_show_libs() {
if ((libs = r_bin_get_libs (bin)) == NULL)
return R_FALSE;
printf ("[Linked libraries]\n");
eprintf ("[Linked libraries]\n");
r_list_foreach (libs, iter, lib) {
printf ("%s\n", lib);
i++;
}
if (!rad) printf ("\n%i libraries\n", i);
if (!rad) eprintf ("\n%i libraries\n", i);
return R_TRUE;
}
@ -158,7 +156,7 @@ static int rabin_show_relocs() {
return R_FALSE;
if (rad) printf ("fs relocs\n");
else printf ("[Relocations]\n");
else eprintf ("[Relocations]\n");
r_list_foreach (relocs, iter, reloc) {
if (rad) {
@ -168,7 +166,7 @@ static int rabin_show_relocs() {
i++;
}
if (!rad) printf ("\n%i relocations\n", i);
if (!rad) eprintf ("\n%i relocations\n", i);
return R_TRUE;
}
@ -186,7 +184,7 @@ static int rabin_show_imports() {
return R_FALSE;
if (!at && !rad)
printf ("[Imports]\n");
eprintf ("[Imports]\n");
r_list_foreach (imports, iter, import) {
if (name && strcmp (import->name, name))
@ -215,7 +213,7 @@ static int rabin_show_imports() {
i++;
}
if (!at && !rad) printf ("\n%i imports\n", i);
if (!at && !rad) eprintf ("\n%i imports\n", i);
return R_TRUE;
}
@ -234,7 +232,7 @@ static int rabin_show_symbols() {
if (!at) {
if (rad) printf ("fs symbols\n");
else printf ("[Symbols]\n");
else eprintf ("[Symbols]\n");
}
r_list_foreach (symbols, iter, symbol) {
@ -274,7 +272,7 @@ static int rabin_show_symbols() {
i++;
}
if (!at && !rad) printf ("\n%i symbols\n", i);
if (!at && !rad) eprintf ("\n%i symbols\n", i);
return R_TRUE;
}
@ -291,7 +289,7 @@ static int rabin_show_strings() {
return R_FALSE;
if (rad) printf ("fs strings\n");
else printf ("[strings]\n");
else eprintf ("[strings]\n");
r_list_foreach (strings, iter, string) {
section = r_bin_get_section_at (bin, string->offset, 0);
@ -309,7 +307,7 @@ static int rabin_show_strings() {
i++;
}
if (!rad) printf ("\n%i strings\n", i);
if (!rad) eprintf ("\n%i strings\n", i);
return R_TRUE;
}
@ -328,7 +326,7 @@ static int rabin_show_sections() {
if (!at) {
if (rad) printf ("fs sections\n");
else printf ("[Sections]\n");
else eprintf ("[Sections]\n");
}
r_list_foreach (sections, iter, section) {
@ -368,7 +366,7 @@ static int rabin_show_sections() {
i++;
}
if (!at && !rad) printf ("\n%i sections\n", i);
if (!at && !rad) eprintf ("\n%i sections\n", i);
return R_TRUE;
}
@ -388,34 +386,43 @@ static int rabin_show_info() {
"e asm.dwarf=%s\n",
info->rclass, info->big_endian?"true":"false", info->os, info->arch,
info->bits, R_BIN_DBG_STRIPPED (info->dbg_info)?"false":"true");
} else printf ("[File info]\n"
"File=%s\n"
"Type=%s\n"
"Class=%s\n"
"Arch=%s %i\n"
"Machine=%s\n"
"OS=%s\n"
"Subsystem=%s\n"
"Big endian=%s\n"
"Stripped=%s\n"
"Static=%s\n"
"Line_nums=%s\n"
"Local_syms=%s\n"
"Relocs=%s\n"
"RPath=%s\n",
info->file, info->type, info->bclass,
info->arch, info->bits, info->machine, info->os,
info->subsystem, info->big_endian?"True":"False",
R_BIN_DBG_STRIPPED (info->dbg_info)?"True":"False",
R_BIN_DBG_STATIC (info->dbg_info)?"True":"False",
R_BIN_DBG_LINENUMS (info->dbg_info)?"True":"False",
R_BIN_DBG_SYMS (info->dbg_info)?"True":"False",
R_BIN_DBG_RELOCS (info->dbg_info)?"True":"False",
info->rpath);
} else {
eprintf ("[File info]\n");
printf ("File=%s\n"
"Type=%s\n"
"Class=%s\n"
"Arch=%s %i\n"
"Machine=%s\n"
"OS=%s\n"
"Subsystem=%s\n"
"Big endian=%s\n"
"Stripped=%s\n"
"Static=%s\n"
"Line_nums=%s\n"
"Local_syms=%s\n"
"Relocs=%s\n"
"RPath=%s\n",
info->file, info->type, info->bclass,
info->arch, info->bits, info->machine, info->os,
info->subsystem, info->big_endian?"True":"False",
R_BIN_DBG_STRIPPED (info->dbg_info)?"True":"False",
R_BIN_DBG_STATIC (info->dbg_info)?"True":"False",
R_BIN_DBG_LINENUMS (info->dbg_info)?"True":"False",
R_BIN_DBG_SYMS (info->dbg_info)?"True":"False",
R_BIN_DBG_RELOCS (info->dbg_info)?"True":"False",
info->rpath);
}
return R_TRUE;
}
static void rabin_list_archs() {
int i;
for (i=0; i<bin->narch; i++)
printf ("%-5s %i\n", bin->arch[i].info->arch, bin->arch[i].info->bits);
}
static int rabin_show_fields() {
RList *fields;
RListIter *iter;
@ -429,7 +436,7 @@ static int rabin_show_fields() {
return R_FALSE;
if (rad) printf ("fs header\n");
else printf ("[Header fields]\n");
else eprintf ("[Header fields]\n");
r_list_foreach (fields, iter, field) {
if (rad) {
@ -443,7 +450,7 @@ static int rabin_show_fields() {
i++;
}
if (!rad) printf ("\n%i fields\n", i);
if (!rad) eprintf ("\n%i fields\n", i);
return R_TRUE;
}
@ -468,7 +475,7 @@ static int rabin_dump_symbols(int len) {
if (!(buf = malloc (len)) || !(ret = malloc(len*2+1)))
return R_FALSE;
r_buf_read_at (bin->buf, symbol->offset, buf, len);
r_buf_read_at (bin->curarch->buf, symbol->offset, buf, len);
r_hex_bin2str (buf, len, ret);
printf ("%s %s\n", symbol->name, ret);
free (buf);
@ -493,7 +500,7 @@ static int rabin_dump_sections(char *scnname) {
if (!(buf = malloc (section->size)) ||
!(ret = malloc (section->size*2+1)))
return R_FALSE;
r_buf_read_at (bin->buf, section->offset, buf, section->size);
r_buf_read_at (bin->curarch->buf, section->offset, buf, section->size);
r_hex_bin2str (buf, section->size, ret);
printf ("%s\n", ret);
free (buf);
@ -552,7 +559,7 @@ static int rabin_do_operation(const char *op) {
break;
default:
_rabin_do_operation_error:
printf ("Unknown operation. use -O help\n");
eprintf ("Unknown operation. use -O help\n");
return R_FALSE;
}
@ -583,17 +590,30 @@ static int __lib_bin_dt(struct r_lib_plugin_t *pl, void *p, void *u) {
return R_TRUE;
}
/* binxtr callback */
static int __lib_bin_xtr_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
struct r_bin_xtr_plugin_t *hand = (struct r_bin_xtr_plugin_t *)data;
//printf(" * Added (dis)assembly plugin\n");
r_bin_xtr_add (bin, hand);
return R_TRUE;
}
static int __lib_bin_xtr_dt(struct r_lib_plugin_t *pl, void *p, void *u) {
return R_TRUE;
}
int main(int argc, char **argv)
{
int c;
int c, bits = 32;
int action = ACTION_UNK;
const char *format = NULL, *op = NULL;
const char *plugin_name = NULL;
const char *op = NULL, *arch = NULL;
bin = r_bin_new ();
l = r_lib_new ("radare_plugin");
r_lib_add_handler (l, R_LIB_TYPE_BIN, "bin plugins",
&__lib_bin_cb, &__lib_bin_dt, NULL);
r_lib_add_handler (l, R_LIB_TYPE_BIN_XTR, "bin xtr plugins",
&__lib_bin_xtr_cb, &__lib_bin_xtr_dt, NULL);
{ /* load plugins everywhere */
char *homeplugindir = r_str_home (".radare/plugins");
@ -602,11 +622,21 @@ int main(int argc, char **argv)
r_lib_opendir (l, LIBDIR"/radare2/");
}
while ((c = getopt (argc, argv, "b:Mm:n:@:VisSzIHelRwO:o:f:rvLhx")) != -1) {
while ((c = getopt (argc, argv, "Aa:B:b:Mm:n:@:VisSzIHelRwO:o:rvLhx")) != -1) {
switch(c) {
case 'A':
action |= ACTION_LISTARCHS;
break;
case 'a':
arch = optarg;
break;
case 'B':
bits = r_num_math (NULL, optarg);
break;
case 'm':
at = r_num_math (NULL, optarg);
action |= ACTION_SRCLINE;
break;
case 'i':
action |= ACTION_IMPORTS;
break;
@ -650,9 +680,6 @@ int main(int argc, char **argv)
case 'o':
output = optarg;
break;
case 'f':
format = optarg;
break;
case 'r':
rad = R_TRUE;
break;
@ -661,7 +688,7 @@ int main(int argc, char **argv)
break;
case 'L':
r_bin_list (bin);
exit(1);
return 1;
case 'b':
gbaddr = r_num_math (NULL, optarg);
break;
@ -684,13 +711,15 @@ int main(int argc, char **argv)
if (action == ACTION_HELP || action == ACTION_UNK || file == NULL)
return rabin_show_help ();
if (format)
plugin_name = format;
if (!r_bin_load (bin, file, plugin_name) &&
!r_bin_load (bin, file, "dummy")) {
if (!r_bin_load (bin, file, R_FALSE) &&
!r_bin_load (bin, file, R_TRUE)) {
eprintf ("r_bin: Cannot open '%s'\n", file);
return R_FALSE;
return 1;
}
if (action&ACTION_LISTARCHS || (arch && !r_bin_set_arch (bin, arch, bits))) {
rabin_list_archs ();
r_bin_free (bin);
return 1;
}
if (action&ACTION_SECTIONS)
@ -722,5 +751,5 @@ int main(int argc, char **argv)
r_bin_free (bin);
return R_FALSE;
return 0;
}

View File

@ -10,6 +10,7 @@ CFLAGS+=-DCORELIB -Iformat
include ../config.mk
include ${STATIC_BIN_PLUGINS}
include ${STATIC_BIN_XTR_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst bin_,p/bin_,$(STATIC_OBJ)))
OBJ=bin.o bin_meta.o bin_write.o ${STATIC_OBJS}

View File

@ -13,15 +13,16 @@
#include "../config.h"
static RBinPlugin *bin_static_plugins[] = { R_BIN_STATIC_PLUGINS };
static RBinXtrPlugin *bin_xtr_static_plugins[] = { R_BIN_XTR_STATIC_PLUGINS };
static void get_strings_range(RBin *bin, RList *list, int min, ut64 from, ut64 to) {
static void get_strings_range(RBinArch *arch, RList *list, int min, ut64 from, ut64 to) {
char str[R_BIN_SIZEOF_STRINGS];
int i, matches = 0, ctr = 0;
RBinString *ptr = NULL;
for(i = from; i < to; i++) {
if ((IS_PRINTABLE (bin->buf->buf[i])) && matches < R_BIN_SIZEOF_STRINGS-1) {
str[matches] = bin->buf->buf[i];
if ((IS_PRINTABLE (arch->buf->buf[i])) && matches < R_BIN_SIZEOF_STRINGS-1) {
str[matches] = arch->buf->buf[i];
matches++;
} else {
/* check if the length fits in our request */
@ -46,7 +47,7 @@ static void get_strings_range(RBin *bin, RList *list, int min, ut64 from, ut64 t
}
// TODO: check only in data section. filter chars only in -r mode
static RList* get_strings(RBin *bin, int min) {
static RList* get_strings(RBinArch *arch, int min) {
RList *ret;
int count = 0;
@ -56,72 +57,102 @@ static RList* get_strings(RBin *bin, int min) {
}
ret->free = free;
if (bin->sections) {
if (arch->sections) {
RBinSection *section;
RListIter *iter;
r_list_foreach (bin->sections, iter, section) {
r_list_foreach (arch->sections, iter, section) {
// XXX: DIRTY HACK! should we check sections srwx to be READ ONLY and NONEXEC?
if ((strstr (bin->info->bclass, "MACH0") && strstr (section->name, "_cstring")) || // OSX
(strstr (bin->info->bclass, "ELF") && strstr (section->name, "data"))) { // LINUX
if ((strstr (arch->info->bclass, "MACH0") && strstr (section->name, "_cstring")) || // OSX
(strstr (arch->info->bclass, "ELF") && strstr (section->name, "data"))) { // LINUX
count ++;
get_strings_range (bin, ret, min,
get_strings_range (arch, ret, min,
section->offset, section->offset+section->size);
}
}
}
if (count == 0)
get_strings_range (bin, ret, min, 0, bin->size);
get_strings_range (arch, ret, min, 0, arch->size);
return ret;
}
static void r_bin_init_items(RBin *bin) {
if (!bin->cur)
static void r_bin_init_items(RBinArch *arch) {
if (!arch->curplugin)
return;
if (bin->cur->baddr)
bin->baddr = bin->cur->baddr (bin);
if (bin->cur->main)
bin->main = bin->cur->main (bin);
if (bin->cur->entries)
bin->entries = bin->cur->entries (bin);
if (bin->cur->fields)
bin->fields = bin->cur->fields (bin);
if (bin->cur->imports)
bin->imports = bin->cur->imports (bin);
if (bin->cur->info)
bin->info = bin->cur->info (bin);
if (bin->cur->libs)
bin->libs = bin->cur->libs (bin);
if (bin->cur->relocs)
bin->relocs = bin->cur->relocs (bin);
if (bin->cur->sections)
bin->sections = bin->cur->sections (bin);
if (bin->cur->strings)
bin->strings = bin->cur->strings (bin);
else bin->strings = get_strings (bin, 4);
if (bin->cur->symbols)
bin->symbols = bin->cur->symbols (bin);
if (arch->curplugin->baddr)
arch->baddr = arch->curplugin->baddr (arch);
if (arch->curplugin->main)
arch->main = arch->curplugin->main (arch);
if (arch->curplugin->entries)
arch->entries = arch->curplugin->entries (arch);
if (arch->curplugin->fields)
arch->fields = arch->curplugin->fields (arch);
if (arch->curplugin->imports)
arch->imports = arch->curplugin->imports (arch);
if (arch->curplugin->info)
arch->info = arch->curplugin->info (arch);
if (arch->curplugin->libs)
arch->libs = arch->curplugin->libs (arch);
if (arch->curplugin->relocs)
arch->relocs = arch->curplugin->relocs (arch);
if (arch->curplugin->sections)
arch->sections = arch->curplugin->sections (arch);
if (arch->curplugin->strings)
arch->strings = arch->curplugin->strings (arch);
else arch->strings = get_strings (arch, 4);
if (arch->curplugin->symbols)
arch->symbols = arch->curplugin->symbols (arch);
}
/* TODO: Free plugins */
static void r_bin_free_items(RBin *bin) {
if (bin->entries)
r_list_free (bin->entries);
if (bin->fields)
r_list_free (bin->fields);
if (bin->imports)
r_list_free (bin->imports);
if (bin->info)
free (bin->info);
if (bin->libs)
r_list_free (bin->libs);
if (bin->relocs)
r_list_free (bin->relocs);
if (bin->sections)
r_list_free (bin->sections);
if (bin->strings)
r_list_free (bin->strings);
if (bin->symbols)
r_list_free (bin->symbols);
static void r_bin_free_items(RBinArch *arch) {
if (arch->entries)
r_list_free (arch->entries);
if (arch->fields)
r_list_free (arch->fields);
if (arch->imports)
r_list_free (arch->imports);
if (arch->info)
free (arch->info);
if (arch->libs)
r_list_free (arch->libs);
if (arch->relocs)
r_list_free (arch->relocs);
if (arch->sections)
r_list_free (arch->sections);
if (arch->strings)
r_list_free (arch->strings);
if (arch->symbols)
r_list_free (arch->symbols);
if (arch->main)
free (arch->main);
}
static int r_bin_extract(RBin *bin, const char* file) {
struct list_head *pos;
ut8 *buf;
int n = 1;
bin->curxtr = NULL;
bin->file = r_file_abspath (file);
list_for_each (pos, &bin->binxtrs) {
RBinXtrPlugin *h = list_entry (pos, RBinXtrPlugin, list);
if (h->check && h->check (bin)) {
bin->curxtr = h;
}
}
if (bin->curxtr && bin->curxtr->extract)
n = bin->curxtr->extract (bin);
else {
bin->arch[0].file = bin->file;
if (!(buf = (ut8*)r_file_slurp (bin->file, &bin->arch[0].size)))
return 0;
bin->arch[0].buf = r_buf_new ();
if (!r_buf_set_bytes (bin->arch[0].buf, buf, bin->arch[0].size)) {
free (buf);
return 0;
}
free (buf);
}
return n;
}
R_API int r_bin_add(RBin *bin, RBinPlugin *foo) {
@ -137,19 +168,29 @@ R_API int r_bin_add(RBin *bin, RBinPlugin *foo) {
return R_TRUE;
}
R_API int r_bin_extract(RBin *bin) {
if (bin->cur && bin->cur->extract)
return bin->cur->extract (bin);
return 0;
R_API int r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo) {
struct list_head *pos;
if (foo->init)
foo->init (bin->user);
list_for_each_prev (pos, &bin->binxtrs) {
RBinXtrPlugin *h = list_entry (pos, RBinXtrPlugin, list);
if (!strcmp (h->name, foo->name))
return R_FALSE;
}
list_add_tail (&(foo->list), &(bin->binxtrs));
return R_TRUE;
}
R_API void* r_bin_free(RBin *bin) {
int i;
if (!bin)
return NULL;
r_bin_free_items (bin);
if (bin->cur && bin->cur->destroy)
bin->cur->destroy (bin);
for (i = 0; i < bin->narch; i++) {
r_bin_free_items (&bin->arch[i]);
if (bin->arch[i].curplugin && bin->arch[i].curplugin->destroy)
bin->arch[i].curplugin->destroy (&bin->arch[i]);
}
free (bin);
return NULL;
}
@ -161,62 +202,75 @@ R_API int r_bin_list(RBin *bin) {
RBinPlugin *h = list_entry (pos, RBinPlugin, list);
printf ("bin %-10s %s\n", h->name, h->desc);
}
list_for_each_prev(pos, &bin->binxtrs) {
RBinXtrPlugin *h = list_entry (pos, RBinXtrPlugin, list);
printf ("bin-xtr %-10s %s\n", h->name, h->desc);
}
return R_FALSE;
}
R_API int r_bin_load(RBin *bin, const char *file, const char *plugin_name) {
R_API int r_bin_load(RBin *bin, const char *file, int dummy) {
struct list_head *pos;
int i;
if (!bin || !file)
return R_FALSE;
bin->file = r_file_abspath (file);
bin->cur = NULL;
list_for_each (pos, &bin->bins) {
RBinPlugin *h = list_entry (pos, RBinPlugin, list);
if ((plugin_name && !strcmp (h->name, plugin_name)) ||
(h->check && h->check (bin)))
bin->cur = h;
bin->narch = r_bin_extract (bin, file);
if (bin->narch == 0)
return R_FALSE;
bin->curarch = &bin->arch[0];
for (i = 0; i < bin->narch; i++) {
bin->arch[i].curplugin = NULL;
list_for_each (pos, &bin->bins) {
RBinPlugin *h = list_entry (pos, RBinPlugin, list);
if ((dummy && !strncmp (h->name, "dummy", 5)) ||
(!dummy && (h->check && h->check (&bin->arch[i])))) {
bin->arch[i].curplugin = h;
break;
}
}
if (bin->arch[i].curplugin && bin->arch[i].curplugin->load &&
bin->arch[i].curplugin->load (&bin->arch[i]))
r_bin_init_items (&bin->arch[i]);
else return R_FALSE;
}
if (bin->cur && bin->cur->load && bin->cur->load (bin))
r_bin_init_items (bin);
else return R_FALSE;
return R_TRUE;
}
// remove this getters.. we have no threads or mutexes to protect here
R_API ut64 r_bin_get_baddr(RBin *bin) {
return bin->baddr;
return bin->curarch->baddr;
}
R_API RBinAddr* r_bin_get_main(RBin *bin) {
return bin->main;
return bin->curarch->main;
}
R_API RList* r_bin_get_entries(RBin *bin) {
return bin->entries;
return bin->curarch->entries;
}
R_API RList* r_bin_get_fields(RBin *bin) {
return bin->fields;
return bin->curarch->fields;
}
R_API RList* r_bin_get_imports(RBin *bin) {
return bin->imports;
return bin->curarch->imports;
}
R_API RBinInfo* r_bin_get_info(RBin *bin) {
return bin->info;
return bin->curarch->info;
}
R_API RList* r_bin_get_libs(RBin *bin) {
return bin->libs;
return bin->curarch->libs;
}
R_API RList* r_bin_get_relocs(RBin *bin) {
return bin->relocs;
return bin->curarch->relocs;
}
R_API RList* r_bin_get_sections(RBin *bin) {
return bin->sections;
return bin->curarch->sections;
}
R_API RBinSection* r_bin_get_section_at(RBin *bin, ut64 off, int va) {
@ -224,10 +278,10 @@ R_API RBinSection* r_bin_get_section_at(RBin *bin, ut64 off, int va) {
RListIter *iter;
ut64 from, to;
if (bin->sections)
r_list_foreach (bin->sections, iter, section) {
from = va ? bin->baddr+section->rva : section->offset;
to = va ? bin->baddr+section->rva+section->vsize :
if (bin->curarch->sections)
r_list_foreach (bin->curarch->sections, iter, section) {
from = va ? bin->curarch->baddr+section->rva : section->offset;
to = va ? bin->curarch->baddr+section->rva+section->vsize :
section->offset + section->size;
if (off >= from && off < to)
return section;
@ -236,41 +290,42 @@ R_API RBinSection* r_bin_get_section_at(RBin *bin, ut64 off, int va) {
}
R_API RList* r_bin_get_strings(RBin *bin) {
return bin->strings;
return bin->curarch->strings;
}
R_API RList* r_bin_get_symbols(RBin *bin) {
return bin->symbols;
return bin->curarch->symbols;
}
R_API int r_bin_is_big_endian (RBin *bin) {
return bin->info->big_endian;
return bin->curarch->info->big_endian;
}
R_API int r_bin_is_stripped (RBin *bin) {
return R_BIN_DBG_STRIPPED (bin->info->dbg_info);
return R_BIN_DBG_STRIPPED (bin->curarch->info->dbg_info);
}
R_API int r_bin_is_static (RBin *bin) {
return R_BIN_DBG_STATIC (bin->info->dbg_info);
return R_BIN_DBG_STATIC (bin->curarch->info->dbg_info);
}
/* XXX Implement in r_bin_meta and deprecate? */
R_API int r_bin_has_dbg_linenums (RBin *bin) {
return R_BIN_DBG_LINENUMS (bin->info->dbg_info);
return R_BIN_DBG_LINENUMS (bin->curarch->info->dbg_info);
}
R_API int r_bin_has_dbg_syms (RBin *bin) {
return R_BIN_DBG_SYMS (bin->info->dbg_info);
return R_BIN_DBG_SYMS (bin->curarch->info->dbg_info);
}
R_API int r_bin_has_dbg_relocs (RBin *bin) {
return R_BIN_DBG_RELOCS (bin->info->dbg_info);
return R_BIN_DBG_RELOCS (bin->curarch->info->dbg_info);
}
R_API RBin* r_bin_new() {
RBin *bin;
RBinPlugin *static_plugin;
RBinXtrPlugin *static_xtr_plugin;
int i;
bin = R_NEW (RBin);
@ -282,10 +337,27 @@ R_API RBin* r_bin_new() {
memcpy (static_plugin, bin_static_plugins[i], sizeof (RBinPlugin));
r_bin_add (bin, static_plugin);
}
INIT_LIST_HEAD (&bin->binxtrs);
for (i=0; bin_xtr_static_plugins[i]; i++) {
static_xtr_plugin = R_NEW (RBinXtrPlugin);
memcpy (static_xtr_plugin, bin_xtr_static_plugins[i], sizeof (RBinXtrPlugin));
r_bin_xtr_add (bin, static_xtr_plugin);
}
}
return bin;
}
R_API int r_bin_set_arch(RBin *bin, const char *arch, int bits) {
int i;
for (i = 0; i < bin->narch; i++)
if (!strcmp (arch, bin->arch[i].info->arch) && bits == bin->arch[i].info->bits) {
bin->curarch = &bin->arch[i];
return R_TRUE;
}
return R_FALSE;
}
R_API void r_bin_set_user_ptr(RBin *bin, void *user) {
bin->user = user;
}

View File

@ -4,11 +4,12 @@
#include <r_bin.h>
R_API int r_bin_meta_get_line(RBin *bin, ut64 addr, char *file, int len, int *line) {
if (bin && bin->cur && bin->cur->meta) {
if (bin->curarch && bin->curarch->curplugin && bin->curarch->curplugin->meta) {
// XXX quick hack to not show lines out of opened bin
if (addr >= bin->baddr && addr < (bin->baddr+bin->size))
if (bin->cur->meta->get_line)
return bin->cur->meta->get_line (bin, addr, file, len, line);
if (addr >= bin->curarch->baddr && addr < (bin->curarch->baddr+bin->curarch->size))
if (bin->curarch->curplugin->meta->get_line)
return bin->curarch->curplugin->meta->get_line (bin->arch, addr,
file, len, line);
}
return R_FALSE;
}

View File

@ -6,17 +6,23 @@
/* XXX Implement r__bin_wr_scn_{set, del} instead */
R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size) {
if (bin && bin->cur && bin->cur->write && bin->cur->write->scn_resize)
return bin->cur->write->scn_resize (bin, name, size);
if (bin->curarch && bin->curarch->curplugin &&
bin->curarch->curplugin->write &&
bin->curarch->curplugin->write->scn_resize)
return bin->curarch->curplugin->write->scn_resize (bin->curarch,
name, size);
return R_FALSE;
}
R_API int r_bin_wr_rpath_del(RBin *bin) {
if (bin && bin->cur && bin->cur->write && bin->cur->write->rpath_del)
return bin->cur->write->rpath_del (bin);
if (bin->curarch && bin->curarch->curplugin &&
bin->curarch->curplugin->write &&
bin->curarch->curplugin->write->rpath_del)
return bin->curarch->curplugin->write->rpath_del (bin->curarch);
return R_FALSE;
}
R_API int r_bin_wr_output(RBin *bin, const char *filename) {
return r_file_dump (filename, bin->buf->buf, bin->buf->length);
return r_file_dump (filename, bin->curarch->buf->buf,
bin->curarch->buf->length);
}

View File

@ -818,3 +818,16 @@ struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new)(const char* file) {
return Elf_(r_bin_elf_free) (bin);
return bin;
}
struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new_buf)(struct r_buf_t *buf) {
struct Elf_(r_bin_elf_obj_t) *bin;
if (!(bin = malloc (sizeof (struct Elf_(r_bin_elf_obj_t)))))
return NULL;
memset (bin, 0, sizeof (struct Elf_(r_bin_elf_obj_t)));
bin->b = buf;
bin->size = buf->length;
if (!Elf_(r_bin_elf_init) (bin))
return Elf_(r_bin_elf_free) (bin);
return bin;
}

View File

@ -95,6 +95,7 @@ struct r_bin_elf_field_t* Elf_(r_bin_elf_get_fields)(struct Elf_(r_bin_elf_obj_t
char *Elf_(r_bin_elf_get_rpath)(struct Elf_(r_bin_elf_obj_t) *bin);
void* Elf_(r_bin_elf_free)(struct Elf_(r_bin_elf_obj_t)* bin);
struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new)(const char* file);
struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new_buf)(struct r_buf_t *buf);
ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const char *name, ut64 size);
int Elf_(r_bin_elf_del_rpath)(struct Elf_(r_bin_elf_obj_t) *bin);

View File

@ -433,3 +433,16 @@ struct r_bin_java_obj_t* r_bin_java_new(const char* file) {
return r_bin_java_free(bin);
return bin;
}
struct r_bin_java_obj_t* r_bin_java_new_buf(struct r_buf_t *buf) {
struct r_bin_java_obj_t *bin;
if (!(bin = malloc(sizeof(struct r_bin_java_obj_t))))
return NULL;
memset (bin, 0, sizeof (struct r_bin_java_obj_t));
bin->b = buf;
bin->size = buf->length;
if (!javasm_init(bin))
return r_bin_java_free(bin);
return bin;
}

View File

@ -111,3 +111,4 @@ struct r_bin_java_sym_t* r_bin_java_get_symbols(struct r_bin_java_obj_t* bin);
struct r_bin_java_str_t* r_bin_java_get_strings(struct r_bin_java_obj_t* bin);
void* r_bin_java_free(struct r_bin_java_obj_t* bin);
struct r_bin_java_obj_t* r_bin_java_new(const char* file);
struct r_bin_java_obj_t* r_bin_java_new_buf(struct r_buf_t *buf);

View File

@ -28,37 +28,43 @@ static int r_bin_fatmach0_init(struct r_bin_fatmach0_obj_t* bin) {
return R_TRUE;
}
int r_bin_fatmach0_extract(struct r_bin_fatmach0_obj_t* bin) {
struct r_bin_fatmach0_arch_t *r_bin_fatmach0_extract(struct r_bin_fatmach0_obj_t* bin) {
ut8 *buf = NULL;
char output[256];
struct r_bin_fatmach0_arch_t *ret;
int i;
eprintf ("Extracting files...\n");
if (bin->hdr.nfat_arch < 0)
return R_FALSE;
ret = malloc ((bin->hdr.nfat_arch+1) * sizeof(struct r_bin_fatmach0_arch_t));
for (i = 0; i < bin->hdr.nfat_arch; i++) {
snprintf (output, 255, "%s.%i", bin->file, i);
eprintf (" %s... ", output);
if (bin->archs[i].size == 0 || bin->archs[i].size > bin->size) {
eprintf ("Corrupted file\n");
return R_FALSE;
return NULL;
}
eprintf ("%u\n", bin->archs[i].size);
if (!(buf = malloc (bin->archs[i].size))) {
perror ("malloc (buf)");
return R_FALSE;
return NULL;
}
if (r_buf_read_at (bin->b, bin->archs[i].offset, buf, bin->archs[i].size) == -1) {
perror ("read (buf)");
free (buf);
return R_FALSE;
return NULL;
}
if (!r_file_dump (output, buf, bin->archs[i].size)) {
perror ("write (file)");
if (!(ret[i].b = r_buf_new ())) {
free (buf);
return R_FALSE;
return NULL;
}
if (!r_buf_set_bytes (ret[i].b, buf, bin->archs[i].size)) {
free (buf);
r_buf_free (ret[i].b);
return NULL;
}
free (buf);
ret[i].size = bin->archs[i].size;
ret[i].last = 0;
}
return bin->nfat_arch;
ret[i].last = 1;
return ret;
}
void* r_bin_fatmach0_free(struct r_bin_fatmach0_obj_t* bin) {

View File

@ -15,7 +15,13 @@ struct r_bin_fatmach0_obj_t {
struct r_buf_t* b;
};
int r_bin_fatmach0_extract(struct r_bin_fatmach0_obj_t* bin);
struct r_bin_fatmach0_arch_t {
int size;
struct r_buf_t *b;
int last;
};
struct r_bin_fatmach0_arch_t *r_bin_fatmach0_extract(struct r_bin_fatmach0_obj_t* bin);
void* r_bin_fatmach0_free(struct r_bin_fatmach0_obj_t* bin);
struct r_bin_fatmach0_obj_t* r_bin_fatmach0_new(const char* file);

View File

@ -367,6 +367,20 @@ struct MACH0_(r_bin_mach0_obj_t)* MACH0_(r_bin_mach0_new)(const char* file)
return bin;
}
struct MACH0_(r_bin_mach0_obj_t)* MACH0_(r_bin_mach0_new_buf)(struct r_buf_t *buf)
{
struct MACH0_(r_bin_mach0_obj_t) *bin;
if (!(bin = malloc(sizeof(struct MACH0_(r_bin_mach0_obj_t)))))
return NULL;
memset (bin, 0, sizeof (struct MACH0_(r_bin_mach0_obj_t)));
bin->b = buf;
bin->size = buf->length;
if (!MACH0_(r_bin_mach0_init)(bin))
return MACH0_(r_bin_mach0_free)(bin);
return bin;
}
struct r_bin_mach0_section_t* MACH0_(r_bin_mach0_get_sections)(struct MACH0_(r_bin_mach0_obj_t)* bin)
{
struct r_bin_mach0_section_t *sections;

View File

@ -90,6 +90,7 @@ struct MACH0_(r_bin_mach0_obj_t) {
};
struct MACH0_(r_bin_mach0_obj_t)* MACH0_(r_bin_mach0_new)(const char* file);
struct MACH0_(r_bin_mach0_obj_t)* MACH0_(r_bin_mach0_new_buf)(struct r_buf_t *buf);
void* MACH0_(r_bin_mach0_free)(struct MACH0_(r_bin_mach0_obj_t)* bin);
struct r_bin_mach0_section_t* MACH0_(r_bin_mach0_get_sections)(struct MACH0_(r_bin_mach0_obj_t)* bin);
struct r_bin_mach0_symbol_t* MACH0_(r_bin_mach0_get_symbols)(struct MACH0_(r_bin_mach0_obj_t)* bin);

View File

@ -757,3 +757,17 @@ struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new)(const char* file)
return PE_(r_bin_pe_free)(bin);
return bin;
}
struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new_buf)(struct r_buf_t *buf)
{
struct PE_(r_bin_pe_obj_t) *bin;
if (!(bin = malloc(sizeof(struct PE_(r_bin_pe_obj_t)))))
return NULL;
memset (bin, 0, sizeof (struct PE_(r_bin_pe_obj_t)));
bin->b = buf;
bin->size = buf->length;
if (!PE_(r_bin_pe_init)(bin))
return PE_(r_bin_pe_free)(bin);
return bin;
}

View File

@ -97,3 +97,4 @@ int PE_(r_bin_pe_is_stripped_local_syms)(struct PE_(r_bin_pe_obj_t)* bin);
int PE_(r_bin_pe_is_stripped_debug)(struct PE_(r_bin_pe_obj_t)* bin);
void* PE_(r_bin_pe_free)(struct PE_(r_bin_pe_obj_t)* bin);
struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new)(const char* file);
struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new_buf)(struct r_buf_t *buf);

View File

@ -6,24 +6,16 @@
#include <r_bin.h>
#include "java/java.h"
static int load(RBin *bin) {
int ret = R_FALSE;
ut8* buf;
if ((buf = (ut8*)r_file_slurp (bin->file, &bin->size))) {
bin->buf = r_buf_new ();
if (r_buf_set_bytes (bin->buf, buf, bin->size))
ret = R_TRUE;
free (buf);
}
return ret;
}
static int destroy(RBin *bin) {
r_buf_free(bin->buf);
static int load(RBinArch *arch) {
return R_TRUE;
}
static ut64 baddr(RBin *bin) {
static int destroy(RBinArch *arch) {
r_buf_free (arch->buf);
return R_TRUE;
}
static ut64 baddr(RBinArch *arch) {
return 0LL;
}
@ -33,7 +25,6 @@ struct r_bin_plugin_t r_bin_plugin_dummy = {
.init = NULL,
.fini = NULL,
.load = &load,
.extract = NULL,
.destroy = &destroy,
.check = NULL,
.baddr = &baddr,

View File

@ -6,34 +6,32 @@
#include <r_bin.h>
#include "elf/elf.h"
static int load(RBin *bin) {
if(!(bin->bin_obj = Elf_(r_bin_elf_new) (bin->file)))
static int load(RBinArch *arch) {
if(!(arch->bin_obj = Elf_(r_bin_elf_new_buf) (arch->buf)))
return R_FALSE;
bin->size = ((struct Elf_(r_bin_elf_obj_t)*) (bin->bin_obj))->size;
bin->buf = ((struct Elf_(r_bin_elf_obj_t)*) (bin->bin_obj))->b;
return R_TRUE;
}
static int destroy(RBin *bin) {
Elf_(r_bin_elf_free) ((struct Elf_(r_bin_elf_obj_t)*)bin->bin_obj);
static int destroy(RBinArch *arch) {
Elf_(r_bin_elf_free) ((struct Elf_(r_bin_elf_obj_t)*)arch->bin_obj);
return R_TRUE;
}
static ut64 baddr(RBin *bin) {
return Elf_(r_bin_elf_get_baddr) (bin->bin_obj);
static ut64 baddr(RBinArch *arch) {
return Elf_(r_bin_elf_get_baddr) (arch->bin_obj);
}
static RBinAddr* binmain(RBin *bin) {
static RBinAddr* binmain(RBinArch *arch) {
RBinAddr *ret = NULL;
if (!(ret = R_NEW (RBinAddr)))
return NULL;
memset (ret, '\0', sizeof (RBinAddr));
ret->offset = ret->rva = Elf_(r_bin_elf_get_main_offset) (bin->bin_obj);
ret->offset = ret->rva = Elf_(r_bin_elf_get_main_offset) (arch->bin_obj);
return ret;
}
static RList* entries(RBin *bin) {
static RList* entries(RBinArch *arch) {
RList *ret;
RBinAddr *ptr = NULL;
@ -43,12 +41,12 @@ static RList* entries(RBin *bin) {
if (!(ptr = R_NEW (RBinAddr)))
return ret;
memset (ptr, '\0', sizeof (RBinAddr));
ptr->offset = ptr->rva = Elf_(r_bin_elf_get_entry_offset) (bin->bin_obj);
ptr->offset = ptr->rva = Elf_(r_bin_elf_get_entry_offset) (arch->bin_obj);
r_list_append (ret, ptr);
return ret;
}
static RList* sections(RBin *bin) {
static RList* sections(RBinArch *arch) {
RList *ret = NULL;
RBinSection *ptr = NULL;
struct r_bin_elf_section_t *section = NULL;
@ -57,7 +55,7 @@ static RList* sections(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(section = Elf_(r_bin_elf_get_sections) (bin->bin_obj)))
if (!(section = Elf_(r_bin_elf_get_sections) (arch->bin_obj)))
return ret;
for (i = 0; !section[i].last; i++) {
if (!(ptr = R_NEW (RBinSection)))
@ -80,7 +78,7 @@ static RList* sections(RBin *bin) {
return ret;
}
static RList* symbols(RBin *bin) {
static RList* symbols(RBinArch *arch) {
RList *ret = NULL;
RBinSymbol *ptr = NULL;
struct r_bin_elf_symbol_t *symbol = NULL;
@ -89,7 +87,7 @@ static RList* symbols(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(symbol = Elf_(r_bin_elf_get_symbols) (bin->bin_obj, R_BIN_ELF_SYMBOLS)))
if (!(symbol = Elf_(r_bin_elf_get_symbols) (arch->bin_obj, R_BIN_ELF_SYMBOLS)))
return ret;
for (i = 0; !symbol[i].last; i++) {
if (!(ptr = R_NEW (RBinSymbol)))
@ -108,7 +106,7 @@ static RList* symbols(RBin *bin) {
return ret;
}
static RList* imports(RBin *bin) {
static RList* imports(RBinArch *arch) {
RList *ret = NULL;
RBinImport *ptr = NULL;
struct r_bin_elf_symbol_t *import = NULL;
@ -117,7 +115,7 @@ static RList* imports(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(import = Elf_(r_bin_elf_get_symbols) (bin->bin_obj, R_BIN_ELF_IMPORTS)))
if (!(import = Elf_(r_bin_elf_get_symbols) (arch->bin_obj, R_BIN_ELF_IMPORTS)))
return ret;
for (i = 0; !import[i].last; i++) {
if (!(ptr = R_NEW (RBinImport)))
@ -136,7 +134,7 @@ static RList* imports(RBin *bin) {
return ret;
}
static RList* libs(RBin *bin) {
static RList* libs(RBinArch *arch) {
RList *ret = NULL;
char *ptr = NULL;
struct r_bin_elf_lib_t *libs = NULL;
@ -145,7 +143,7 @@ static RList* libs(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(libs = Elf_(r_bin_elf_get_libs) (bin->bin_obj)))
if (!(libs = Elf_(r_bin_elf_get_libs) (arch->bin_obj)))
return ret;
for (i = 0; !libs[i].last; i++) {
ptr = strdup (libs[i].name);
@ -155,7 +153,7 @@ static RList* libs(RBin *bin) {
return ret;
}
static RList* relocs(RBin *bin) {
static RList* relocs(RBinArch *arch) {
RList *ret = NULL;
RBinReloc *ptr = NULL;
struct r_bin_elf_reloc_t *relocs = NULL;
@ -164,7 +162,7 @@ static RList* relocs(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(relocs = Elf_(r_bin_elf_get_relocs) (bin->bin_obj)))
if (!(relocs = Elf_(r_bin_elf_get_relocs) (arch->bin_obj)))
return ret;
for (i = 0; !relocs[i].last; i++) {
if (!(ptr = R_NEW (RBinReloc)))
@ -180,57 +178,57 @@ static RList* relocs(RBin *bin) {
return ret;
}
static RBinInfo* info(RBin *bin) {
static RBinInfo* info(RBinArch *arch) {
RBinInfo *ret = NULL;
char *str;
if(!(ret = R_NEW (RBinInfo)))
return NULL;
memset (ret, '\0', sizeof (RBinInfo));
strncpy (ret->file, bin->file, R_BIN_SIZEOF_STRINGS);
if ((str = Elf_(r_bin_elf_get_rpath)(bin->bin_obj))) {
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
if ((str = Elf_(r_bin_elf_get_rpath)(arch->bin_obj))) {
strncpy (ret->rpath, str, R_BIN_SIZEOF_STRINGS);
free (str);
} else strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
if ((str = Elf_(r_bin_elf_get_file_type) (bin->bin_obj)) == NULL)
if ((str = Elf_(r_bin_elf_get_file_type) (arch->bin_obj)) == NULL)
return NULL;
strncpy (ret->type, str, R_BIN_SIZEOF_STRINGS);
free (str);
if ((str = Elf_(r_bin_elf_get_elf_class) (bin->bin_obj)) == NULL)
if ((str = Elf_(r_bin_elf_get_elf_class) (arch->bin_obj)) == NULL)
return NULL;
strncpy (ret->bclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
if ((str = Elf_(r_bin_elf_get_osabi_name) (bin->bin_obj)) == NULL)
if ((str = Elf_(r_bin_elf_get_osabi_name) (arch->bin_obj)) == NULL)
return NULL;
strncpy (ret->os, str, R_BIN_SIZEOF_STRINGS);
free (str);
if ((str = Elf_(r_bin_elf_get_osabi_name) (bin->bin_obj)) == NULL)
if ((str = Elf_(r_bin_elf_get_osabi_name) (arch->bin_obj)) == NULL)
return NULL;
strncpy (ret->subsystem, str, R_BIN_SIZEOF_STRINGS);
free (str);
if ((str = Elf_(r_bin_elf_get_machine_name) (bin->bin_obj)) == NULL)
if ((str = Elf_(r_bin_elf_get_machine_name) (arch->bin_obj)) == NULL)
return NULL;
strncpy (ret->machine, str, R_BIN_SIZEOF_STRINGS);
free (str);
if ((str = Elf_(r_bin_elf_get_arch) (bin->bin_obj)) == NULL)
if ((str = Elf_(r_bin_elf_get_arch) (arch->bin_obj)) == NULL)
return NULL;
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
strncpy (ret->rclass, "elf", R_BIN_SIZEOF_STRINGS);
ret->bits = Elf_(r_bin_elf_get_bits) (bin->bin_obj);
ret->big_endian=Elf_(r_bin_elf_is_big_endian) (bin->bin_obj);
ret->bits = Elf_(r_bin_elf_get_bits) (arch->bin_obj);
ret->big_endian=Elf_(r_bin_elf_is_big_endian) (arch->bin_obj);
ret->dbg_info = 0;
if (!Elf_(r_bin_elf_get_stripped) (bin->bin_obj)) {
if (!Elf_(r_bin_elf_get_stripped) (arch->bin_obj)) {
ret->dbg_info |= 0x04;
ret->dbg_info |= 0x08;
ret->dbg_info |= 0x10;
} else ret->dbg_info |= 0x01;
if (Elf_(r_bin_elf_get_static) (bin->bin_obj))
if (Elf_(r_bin_elf_get_static) (arch->bin_obj))
ret->dbg_info |= 0x02;
return ret;
}
static RList* fields(RBin *bin) {
static RList* fields(RBinArch *arch) {
RList *ret = NULL;
RBinField *ptr = NULL;
struct r_bin_elf_field_t *field = NULL;
@ -239,7 +237,7 @@ static RList* fields(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(field = Elf_(r_bin_elf_get_fields) (bin->bin_obj)))
if (!(field = Elf_(r_bin_elf_get_fields) (arch->bin_obj)))
return ret;
for (i = 0; !field[i].last; i++) {
if (!(ptr = R_NEW (RBinField)))
@ -254,18 +252,10 @@ static RList* fields(RBin *bin) {
}
#if !R_BIN_ELF64
static int check(RBin *bin) {
ut8 *buf;
int n, ret = R_FALSE;
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 5, &n))) {
/* buf[EI_CLASS] == ELFCLASS32 */
if (n == 5)
if (!memcmp (buf, "\x7F\x45\x4c\x46\x01", 5))
ret = R_TRUE;
free (buf);
}
return ret;
static int check(RBinArch *arch) {
if (!memcmp (arch->buf->buf, "\x7F\x45\x4c\x46\x01", 5))
return R_TRUE;
return R_FALSE;
}
extern struct r_bin_meta_t r_bin_meta_elf;
@ -277,7 +267,6 @@ struct r_bin_plugin_t r_bin_plugin_elf = {
.init = NULL,
.fini = NULL,
.load = &load,
.extract = NULL,
.destroy = &destroy,
.check = &check,
.baddr = &baddr,

View File

@ -3,17 +3,10 @@
#define R_BIN_ELF64 1
#include "bin_elf.c"
static int check(RBin *bin) {
ut8 *buf;
int n, ret = R_FALSE;
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 5, &n))) {
/* buf[EI_CLASS] == ELFCLASS64 */
if (n==5 && !memcmp (buf, "\x7F\x45\x4c\x46\x02", 5))
ret = R_TRUE;
free (buf);
}
return ret;
static int check(RBinArch *arch) {
if (!memcmp (arch->buf->buf, "\x7F\x45\x4c\x46\x02", 5))
return R_TRUE;
return R_FALSE;
}
extern struct r_bin_meta_t r_bin_meta_elf64;
@ -25,7 +18,6 @@ struct r_bin_plugin_t r_bin_plugin_elf64 = {
.init = NULL,
.fini = NULL,
.load = &load,
.extract = NULL,
.destroy = &destroy,
.check = &check,
.baddr = &baddr,

View File

@ -6,20 +6,18 @@
#include <r_bin.h>
#include "java/java.h"
static int load(RBin *bin) {
if(!(bin->bin_obj = r_bin_java_new(bin->file)))
static int load(RBinArch *arch) {
if(!(arch->bin_obj = r_bin_java_new_buf(arch->buf)))
return R_FALSE;
bin->size = ((struct r_bin_java_obj_t*)(bin->bin_obj))->size;
bin->buf = ((struct r_bin_java_obj_t*)(bin->bin_obj))->b;
return R_TRUE;
}
static int destroy(RBin *bin) {
r_bin_java_free ((struct r_bin_java_obj_t*)bin->bin_obj);
static int destroy(RBinArch *arch) {
r_bin_java_free ((struct r_bin_java_obj_t*)arch->bin_obj);
return R_TRUE;
}
static RList* entries(RBin *bin) {
static RList* entries(RBinArch *arch) {
RList *ret;
RBinAddr *ptr = NULL;
@ -29,16 +27,16 @@ static RList* entries(RBin *bin) {
if (!(ptr = R_NEW (RBinAddr)))
return ret;
memset (ptr, '\0', sizeof (RBinAddr));
ptr->offset = ptr->rva = r_bin_java_get_entrypoint (bin->bin_obj);
ptr->offset = ptr->rva = r_bin_java_get_entrypoint (arch->bin_obj);
r_list_append (ret, ptr);
return ret;
}
static ut64 baddr(RBin *bin) {
static ut64 baddr(RBinArch *arch) {
return 0;
}
static RList* symbols(RBin *bin) {
static RList* symbols(RBinArch *arch) {
RList *ret = NULL;
RBinSymbol *ptr = NULL;
struct r_bin_java_sym_t *symbols = NULL;
@ -47,7 +45,7 @@ static RList* symbols(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(symbols = r_bin_java_get_symbols ((struct r_bin_java_obj_t*)bin->bin_obj)))
if (!(symbols = r_bin_java_get_symbols ((struct r_bin_java_obj_t*)arch->bin_obj)))
return ret;
for (i = 0; !symbols[i].last; i++) {
if (!(ptr = R_NEW (RBinSymbol)))
@ -65,7 +63,7 @@ static RList* symbols(RBin *bin) {
return ret;
}
static RList* strings(RBin *bin) {
static RList* strings(RBinArch *arch) {
RList *ret = NULL;
RBinString *ptr = NULL;
struct r_bin_java_str_t *strings = NULL;
@ -74,7 +72,7 @@ static RList* strings(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(strings = r_bin_java_get_strings((struct r_bin_java_obj_t*)bin->bin_obj)))
if (!(strings = r_bin_java_get_strings((struct r_bin_java_obj_t*)arch->bin_obj)))
return ret;
for (i = 0; !strings[i].last; i++) {
if (!(ptr = R_NEW (RBinString)))
@ -88,17 +86,17 @@ static RList* strings(RBin *bin) {
return ret;
}
static RBinInfo* info(RBin *bin) {
static RBinInfo* info(RBinArch *arch) {
RBinInfo *ret = NULL;
char *version;
if (!(ret = R_NEW (RBinInfo)))
return NULL;
memset (ret, '\0', sizeof (RBinInfo));
strncpy (ret->file, bin->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy (ret->type, "JAVA CLASS", R_BIN_SIZEOF_STRINGS);
version = r_bin_java_get_version (bin->bin_obj);
version = r_bin_java_get_version (arch->bin_obj);
strncpy (ret->bclass, version, R_BIN_SIZEOF_STRINGS);
free (version);
strncpy (ret->rclass, "class", R_BIN_SIZEOF_STRINGS);
@ -112,25 +110,21 @@ static RBinInfo* info(RBin *bin) {
return ret;
}
static int check(RBin *bin) {
ut8 *filebuf, buf[4];
int off, filesize, ret = R_FALSE;
static int check(RBinArch *arch) {
int off, ret = R_FALSE;
if ((filebuf = (ut8*)r_file_slurp (bin->file, &filesize))) {
if (!memcmp (filebuf, "\xca\xfe\xba\xbe", 4)) {
ret = R_TRUE;
memcpy (&off, filebuf+4*sizeof(int), sizeof(int));
r_mem_copyendian ((ut8*)&off, (ut8*)&off, sizeof(int), !LIL_ENDIAN);
if (off > 0 && off < filesize) {
memcpy (buf, filebuf+off, 4);
if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
!memcmp (buf, "\xfe\xed\xfa\xce", 4) ||
!memcmp (buf, "\xfe\xed\xfa\xcf", 4) ||
!memcmp (buf, "\xcf\xfa\xed\xfe", 4))
ret = R_FALSE;
}
if (!memcmp (arch->buf->buf, "\xca\xfe\xba\xbe", 4)) {
ret = R_TRUE;
memcpy (&off, arch->buf->buf+4*sizeof(int), sizeof(int));
r_mem_copyendian ((ut8*)&off, (ut8*)&off, sizeof(int), !LIL_ENDIAN);
if (off > 0 && off < arch->buf->length) {
memcpy (arch->buf->buf, arch->buf->buf+off, 4);
if (!memcmp (arch->buf->buf, "\xce\xfa\xed\xfe", 4) ||
!memcmp (arch->buf->buf, "\xfe\xed\xfa\xce", 4) ||
!memcmp (arch->buf->buf, "\xfe\xed\xfa\xcf", 4) ||
!memcmp (arch->buf->buf, "\xcf\xfa\xed\xfe", 4))
ret = R_FALSE;
}
free (filebuf);
}
return ret;
}
@ -141,7 +135,6 @@ struct r_bin_plugin_t r_bin_plugin_java = {
.init = NULL,
.fini = NULL,
.load = &load,
.extract = NULL,
.destroy = &destroy,
.check = &check,
.baddr = &baddr,

View File

@ -6,24 +6,22 @@
#include <r_bin.h>
#include "mach0/mach0.h"
static int load(RBin *bin) {
if(!(bin->bin_obj = MACH0_(r_bin_mach0_new) (bin->file)))
static int load(RBinArch *arch) {
if(!(arch->bin_obj = MACH0_(r_bin_mach0_new_buf) (arch->buf)))
return R_FALSE;
bin->size = ((struct MACH0_(r_bin_mach0_obj_t)*) (bin->bin_obj))->size;
bin->buf = ((struct MACH0_(r_bin_mach0_obj_t)*) (bin->bin_obj))->b;
return R_TRUE;
}
static int destroy(RBin *bin) {
MACH0_(r_bin_mach0_free) (bin->bin_obj);
static int destroy(RBinArch *arch) {
MACH0_(r_bin_mach0_free) (arch->bin_obj);
return R_TRUE;
}
static ut64 baddr(RBin *bin) {
return MACH0_(r_bin_mach0_get_baddr) (bin->bin_obj);
static ut64 baddr(RBinArch *arch) {
return MACH0_(r_bin_mach0_get_baddr) (arch->bin_obj);
}
static RList* entries(RBin *bin) {
static RList* entries(RBinArch *arch) {
RList *ret;
RBinAddr *ptr = NULL;
struct r_bin_mach0_addr_t *entry = NULL;
@ -31,7 +29,7 @@ static RList* entries(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(entry = MACH0_(r_bin_mach0_get_entrypoint) (bin->bin_obj)))
if (!(entry = MACH0_(r_bin_mach0_get_entrypoint) (arch->bin_obj)))
return ret;
if ((ptr = R_NEW (RBinAddr))) {
memset (ptr, '\0', sizeof (RBinAddr));
@ -43,7 +41,7 @@ static RList* entries(RBin *bin) {
return ret;
}
static RList* sections(RBin *bin) {
static RList* sections(RBinArch *arch) {
RList *ret = NULL;
RBinSection *ptr = NULL;
struct r_bin_mach0_section_t *sections = NULL;
@ -52,7 +50,7 @@ static RList* sections(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(sections = MACH0_(r_bin_mach0_get_sections) (bin->bin_obj)))
if (!(sections = MACH0_(r_bin_mach0_get_sections) (arch->bin_obj)))
return ret;
for (i = 0; !sections[i].last; i++) {
if (!(ptr = R_NEW (RBinSection)))
@ -69,7 +67,7 @@ static RList* sections(RBin *bin) {
return ret;
}
static RList* symbols(RBin *bin) {
static RList* symbols(RBinArch *arch) {
RList *ret = NULL;
RBinSymbol *ptr = NULL;
struct r_bin_mach0_symbol_t *symbols = NULL;
@ -78,7 +76,7 @@ static RList* symbols(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(symbols = MACH0_(r_bin_mach0_get_symbols) (bin->bin_obj)))
if (!(symbols = MACH0_(r_bin_mach0_get_symbols) (arch->bin_obj)))
return ret;
for (i = 0; !symbols[i].last; i++) {
if (!(ptr = R_NEW (RBinSymbol)))
@ -99,7 +97,7 @@ static RList* symbols(RBin *bin) {
return ret;
}
static RList* imports(RBin *bin) {
static RList* imports(RBinArch *arch) {
RList *ret = NULL;
RBinImport *ptr = NULL;
struct r_bin_mach0_import_t *imports = NULL;
@ -108,7 +106,7 @@ static RList* imports(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(imports = MACH0_(r_bin_mach0_get_imports) (bin->bin_obj)))
if (!(imports = MACH0_(r_bin_mach0_get_imports) (arch->bin_obj)))
return ret;
for (i = 0; !imports[i].last; i++) {
if (!(ptr = R_NEW (RBinImport)))
@ -129,7 +127,7 @@ static RList* imports(RBin *bin) {
return ret;
}
static RList* libs(RBin *bin) {
static RList* libs(RBinArch *arch) {
RList *ret = NULL;
char *ptr = NULL;
struct r_bin_mach0_lib_t *libs = NULL;
@ -138,7 +136,7 @@ static RList* libs(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(libs = MACH0_(r_bin_mach0_get_libs) (bin->bin_obj)))
if (!(libs = MACH0_(r_bin_mach0_get_libs) (arch->bin_obj)))
return ret;
for (i = 0; !libs[i].last; i++) {
ptr = strdup (libs[i].name);
@ -148,16 +146,16 @@ static RList* libs(RBin *bin) {
return ret;
}
static RBinInfo* info(RBin *bin) {
static RBinInfo* info(RBinArch *arch) {
char *str;
RBinInfo *ret = NULL;
if((ret = R_NEW (RBinInfo)) == NULL)
return NULL;
memset(ret, '\0', sizeof (RBinInfo));
strncpy (ret->file, bin->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
if ((str = MACH0_(r_bin_mach0_get_class) (bin->bin_obj))) {
if ((str = MACH0_(r_bin_mach0_get_class) (arch->bin_obj))) {
strncpy (ret->bclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
@ -165,37 +163,31 @@ static RBinInfo* info(RBin *bin) {
/* TODO get os*/
strncpy(ret->os, "macos", R_BIN_SIZEOF_STRINGS);
strncpy(ret->subsystem, "macos", R_BIN_SIZEOF_STRINGS);
if ((str = MACH0_(r_bin_mach0_get_cputype) (bin->bin_obj))) {
if ((str = MACH0_(r_bin_mach0_get_cputype) (arch->bin_obj))) {
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = MACH0_(r_bin_mach0_get_cpusubtype) (bin->bin_obj))) {
if ((str = MACH0_(r_bin_mach0_get_cpusubtype) (arch->bin_obj))) {
strncpy (ret->machine, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = MACH0_(r_bin_mach0_get_filetype) (bin->bin_obj))) {
if ((str = MACH0_(r_bin_mach0_get_filetype) (arch->bin_obj))) {
strncpy (ret->type, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
ret->bits = MACH0_(r_bin_mach0_get_bits) (bin->bin_obj);
ret->big_endian = MACH0_(r_bin_mach0_is_big_endian) (bin->bin_obj);
ret->bits = MACH0_(r_bin_mach0_get_bits) (arch->bin_obj);
ret->big_endian = MACH0_(r_bin_mach0_is_big_endian) (arch->bin_obj);
/* TODO detailed debug info */
ret->dbg_info = 0;
return ret;
}
#if !R_BIN_MACH064
static int check(RBin *bin) {
ut8 *buf;
int n, ret = R_FALSE;
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 4, &n))) {
if (n==4)
if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
!memcmp (buf, "\xfe\xed\xfa\xce", 4))
ret = R_TRUE;
free (buf);
}
return ret;
static int check(RBinArch *arch) {
if (!memcmp (arch->buf->buf, "\xce\xfa\xed\xfe", 4) ||
!memcmp (arch->buf->buf, "\xfe\xed\xfa\xce", 4))
return R_TRUE;
return R_FALSE;
}
struct r_bin_plugin_t r_bin_plugin_mach0 = {
@ -204,7 +196,6 @@ struct r_bin_plugin_t r_bin_plugin_mach0 = {
.init = NULL,
.fini = NULL,
.load = &load,
.extract = NULL,
.destroy = &destroy,
.check = &check,
.baddr = &baddr,

View File

@ -3,17 +3,11 @@
#define R_BIN_MACH064 1
#include "bin_mach0.c"
static int check(RBin *bin) {
ut8 *buf;
int n, ret = R_FALSE;
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 4, &n))) {
if (n==4)
if (!memcmp (buf, "\xfe\xed\xfa\xcf", 4) \
|| !memcmp (buf, "\xcf\xfa\xed\xfe", 4))
ret = R_TRUE;
free (buf);
}
return ret;
static int check(RBinArch *arch) {
if (!memcmp (arch->buf->buf, "\xfe\xed\xfa\xcf", 4) ||
!memcmp (arch->buf->buf, "\xcf\xfa\xed\xfe", 4))
return R_TRUE;
return R_FALSE;
}
struct r_bin_plugin_t r_bin_plugin_mach064 = {
@ -22,7 +16,6 @@ struct r_bin_plugin_t r_bin_plugin_mach064 = {
.init = NULL,
.fini = NULL,
.load = &load,
.extract = NULL,
.destroy = &destroy,
.check = &check,
.baddr = &baddr,

View File

@ -3,8 +3,8 @@
#include <r_types.h>
#include <r_bin.h>
static int get_line(RBin *bin, ut64 addr, char *file, int len, int *line) {
char *p, *out = r_sys_cmd_strf ("addr2line -e '%s' 0x%08"PFMT64x"", bin->file, addr);
static int get_line(RBinArch *arch, ut64 addr, char *file, int len, int *line) {
char *p, *out = r_sys_cmd_strf ("addr2line -e '%s' 0x%08"PFMT64x"", arch->file, addr);
if (out == NULL || *out=='?')
return R_FALSE;
p = strchr (out, ':');

View File

@ -6,34 +6,32 @@
#include <r_bin.h>
#include "pe/pe.h"
static int load(RBin *bin) {
if(!(bin->bin_obj = PE_(r_bin_pe_new) (bin->file)))
static int load(RBinArch *arch) {
if(!(arch->bin_obj = PE_(r_bin_pe_new_buf) (arch->buf)))
return R_FALSE;
bin->size = ((struct PE_(r_bin_pe_obj_t)*) (bin->bin_obj))->size;
bin->buf = ((struct PE_(r_bin_pe_obj_t)*) (bin->bin_obj))->b;
return R_TRUE;
}
static int destroy (RBin *bin) {
PE_(r_bin_pe_free) ((struct PE_(r_bin_pe_obj_t)*)bin->bin_obj);
static int destroy (RBinArch *arch) {
PE_(r_bin_pe_free) ((struct PE_(r_bin_pe_obj_t)*)arch->bin_obj);
return R_TRUE;
}
static ut64 baddr(RBin *bin) {
return PE_(r_bin_pe_get_image_base) (bin->bin_obj);
static ut64 baddr(RBinArch *arch) {
return PE_(r_bin_pe_get_image_base) (arch->bin_obj);
}
static RBinAddr* binmain(RBin *bin) {
static RBinAddr* binmain(RBinArch *arch) {
RBinAddr *ret = NULL;
if (!(ret = R_NEW (RBinAddr)))
return NULL;
memset (ret, '\0', sizeof (RBinAddr));
ret->offset = ret->rva = PE_(r_bin_pe_get_main_offset) (bin->bin_obj);
ret->offset = ret->rva = PE_(r_bin_pe_get_main_offset) (arch->bin_obj);
return ret;
}
static RList* entries(RBin *bin) {
static RList* entries(RBinArch *arch) {
RList* ret;
RBinAddr *ptr = NULL;
struct r_bin_pe_addr_t *entry = NULL;
@ -41,7 +39,7 @@ static RList* entries(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(entry = PE_(r_bin_pe_get_entrypoint) (bin->bin_obj)))
if (!(entry = PE_(r_bin_pe_get_entrypoint) (arch->bin_obj)))
return ret;
if ((ptr = R_NEW (RBinAddr))) {
ptr->offset = entry->offset;
@ -52,7 +50,7 @@ static RList* entries(RBin *bin) {
return ret;
}
static RList* sections(RBin *bin) {
static RList* sections(RBinArch *arch) {
RList *ret = NULL;
RBinSection *ptr = NULL;
struct r_bin_pe_section_t *sections = NULL;
@ -61,7 +59,7 @@ static RList* sections(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(sections = PE_(r_bin_pe_get_sections)(bin->bin_obj)))
if (!(sections = PE_(r_bin_pe_get_sections)(arch->bin_obj)))
return ret;
for (i = 0; !sections[i].last; i++) {
if (!(ptr = R_NEW (RBinSection)))
@ -86,7 +84,7 @@ static RList* sections(RBin *bin) {
return ret;
}
static RList* symbols(RBin *bin) {
static RList* symbols(RBinArch *arch) {
RList *ret = NULL;
RBinSymbol *ptr = NULL;
struct r_bin_pe_export_t *symbols = NULL;
@ -95,7 +93,7 @@ static RList* symbols(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(symbols = PE_(r_bin_pe_get_exports)(bin->bin_obj)))
if (!(symbols = PE_(r_bin_pe_get_exports)(arch->bin_obj)))
return ret;
for (i = 0; !symbols[i].last; i++) {
if (!(ptr = R_NEW (RBinSymbol)))
@ -114,7 +112,7 @@ static RList* symbols(RBin *bin) {
return ret;
}
static RList* imports(RBin *bin) {
static RList* imports(RBinArch *arch) {
RList *ret = NULL;
RBinImport *ptr = NULL;
struct r_bin_pe_import_t *imports = NULL;
@ -123,7 +121,7 @@ static RList* imports(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(imports = PE_(r_bin_pe_get_imports)(bin->bin_obj)))
if (!(imports = PE_(r_bin_pe_get_imports)(arch->bin_obj)))
return ret;
for (i = 0; !imports[i].last; i++) {
if (!(ptr = R_NEW (RBinImport)))
@ -142,7 +140,7 @@ static RList* imports(RBin *bin) {
return ret;
}
static RList* libs(RBin *bin) {
static RList* libs(RBinArch *arch) {
RList *ret = NULL;
char *ptr = NULL;
struct r_bin_pe_lib_t *libs = NULL;
@ -151,7 +149,7 @@ static RList* libs(RBin *bin) {
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(libs = PE_(r_bin_pe_get_libs)(bin->bin_obj)))
if (!(libs = PE_(r_bin_pe_get_libs)(arch->bin_obj)))
return ret;
for (i = 0; !libs[i].last; i++) {
ptr = strdup (libs[i].name);
@ -161,66 +159,62 @@ static RList* libs(RBin *bin) {
return ret;
}
static RBinInfo* info(RBin *bin) {
static RBinInfo* info(RBinArch *arch) {
char *str;
RBinInfo *ret = NULL;
if((ret = R_NEW (RBinInfo)) == NULL)
return NULL;
memset(ret, '\0', sizeof (RBinInfo));
strncpy (ret->file, bin->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
if ((str = PE_(r_bin_pe_get_class) (bin->bin_obj))) {
if ((str = PE_(r_bin_pe_get_class) (arch->bin_obj))) {
strncpy (ret->bclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
strncpy(ret->rclass, "pe", R_BIN_SIZEOF_STRINGS);
if ((str = PE_(r_bin_pe_get_os) (bin->bin_obj))) {
if ((str = PE_(r_bin_pe_get_os) (arch->bin_obj))) {
strncpy (ret->os, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = PE_(r_bin_pe_get_arch) (bin->bin_obj))) {
if ((str = PE_(r_bin_pe_get_arch) (arch->bin_obj))) {
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = PE_(r_bin_pe_get_machine) (bin->bin_obj))) {
if ((str = PE_(r_bin_pe_get_machine) (arch->bin_obj))) {
strncpy (ret->machine, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = PE_(r_bin_pe_get_subsystem) (bin->bin_obj))) {
if ((str = PE_(r_bin_pe_get_subsystem) (arch->bin_obj))) {
strncpy (ret->subsystem, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if (PE_(r_bin_pe_is_dll) (bin->bin_obj))
if (PE_(r_bin_pe_is_dll) (arch->bin_obj))
strncpy (ret->type, "DLL (Dynamic Link Library)", R_BIN_SIZEOF_STRINGS);
else strncpy (ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_STRINGS);
ret->bits = PE_(r_bin_pe_get_bits) (bin->bin_obj);
ret->big_endian = PE_(r_bin_pe_is_big_endian) (bin->bin_obj);
ret->bits = PE_(r_bin_pe_get_bits) (arch->bin_obj);
ret->big_endian = PE_(r_bin_pe_is_big_endian) (arch->bin_obj);
ret->dbg_info = 0;
if (!PE_(r_bin_pe_is_stripped_debug) (bin->bin_obj))
if (!PE_(r_bin_pe_is_stripped_debug) (arch->bin_obj))
ret->dbg_info |= 0x01;
if (PE_(r_bin_pe_is_stripped_line_nums) (bin->bin_obj))
if (PE_(r_bin_pe_is_stripped_line_nums) (arch->bin_obj))
ret->dbg_info |= 0x04;
if (PE_(r_bin_pe_is_stripped_local_syms) (bin->bin_obj))
if (PE_(r_bin_pe_is_stripped_local_syms) (arch->bin_obj))
ret->dbg_info |= 0x08;
if (PE_(r_bin_pe_is_stripped_relocs) (bin->bin_obj))
if (PE_(r_bin_pe_is_stripped_relocs) (arch->bin_obj))
ret->dbg_info |= 0x10;
return ret;
}
#if !R_BIN_PE64
static int check(RBin *bin) {
ut8 *buf;
int n, idx, ret = R_FALSE;
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 0xffff+0x20, &n))) {
idx = (buf[0x3c]|(buf[0x3d]<<8));
if (n>idx)
if (!memcmp (buf, "\x4d\x5a", 2) &&
!memcmp (buf+idx, "\x50\x45", 2) &&
!memcmp (buf+idx+0x18, "\x0b\x01", 2))
static int check(RBinArch *arch) {
int idx, ret = R_FALSE;
idx = (arch->buf->buf[0x3c]|(arch->buf->buf[0x3d]<<8));
if (arch->buf->length>idx)
if (!memcmp (arch->buf->buf, "\x4d\x5a", 2) &&
!memcmp (arch->buf->buf+idx, "\x50\x45", 2) &&
!memcmp (arch->buf->buf+idx+0x18, "\x0b\x01", 2))
ret = R_TRUE;
free (buf);
}
return ret;
}
@ -230,7 +224,6 @@ struct r_bin_plugin_t r_bin_plugin_pe = {
.init = NULL,
.fini = NULL,
.load = &load,
.extract = NULL,
.destroy = &destroy,
.check = &check,
.baddr = &baddr,

View File

@ -3,19 +3,15 @@
#define R_BIN_PE64 1
#include "bin_pe.c"
static int check(RBin *bin) {
ut8 *buf;
int n, idx, ret = R_FALSE;
static int check(RBinArch *arch) {
int idx, ret = R_FALSE;
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 0xffff+0x20, &n))) {
idx = buf[0x3c]|(buf[0x3d]<<8);
if (n>=idx+0x20)
if (!memcmp (buf, "\x4d\x5a", 2) &&
!memcmp (buf+idx, "\x50\x45", 2) &&
!memcmp (buf+idx+0x18, "\x0b\x02", 2))
idx = arch->buf->buf[0x3c]|(arch->buf->buf[0x3d]<<8);
if (arch->buf->length>=idx+0x20)
if (!memcmp (arch->buf->buf, "\x4d\x5a", 2) &&
!memcmp (arch->buf->buf+idx, "\x50\x45", 2) &&
!memcmp (arch->buf->buf+idx+0x18, "\x0b\x02", 2))
ret = R_TRUE;
free (buf);
}
return ret;
}
@ -25,7 +21,6 @@ struct r_bin_plugin_t r_bin_plugin_pe64 = {
.init = NULL,
.fini = NULL,
.load = &load,
.extract = NULL,
.destroy = &destroy,
.check = &check,
.baddr = &baddr,

View File

@ -4,12 +4,12 @@
#include <r_bin.h>
#include "elf/elf.h"
static ut64 scn_resize(RBin *bin, const char *name, ut64 size) {
return Elf_(r_bin_elf_resize_section) (bin->bin_obj, name, size);
static ut64 scn_resize(RBinArch *arch, const char *name, ut64 size) {
return Elf_(r_bin_elf_resize_section) (arch->bin_obj, name, size);
}
static int rpath_del(RBin *bin) {
return Elf_(r_bin_elf_del_rpath) (bin->bin_obj);
static int rpath_del(RBinArch *arch) {
return Elf_(r_bin_elf_del_rpath) (arch->bin_obj);
}
#if !R_BIN_ELF64

View File

@ -33,46 +33,37 @@ static int destroy(RBin *bin) {
return R_TRUE;
}
static int load(RBin *bin) {
if(!(bin->bin_obj = r_bin_fatmach0_new(bin->file)))
return R_FALSE;
bin->size = ((struct r_bin_fatmach0_obj_t*)(bin->bin_obj))->size;
bin->buf = ((struct r_bin_fatmach0_obj_t*)(bin->bin_obj))->b;
eprintf ("Warning: fat mach-o, use rabin2 -x to extract the bins\n");
return R_TRUE;
}
static int extract(RBin *bin) {
return r_bin_fatmach0_extract ((struct r_bin_fatmach0_obj_t*)bin->bin_obj);
struct r_bin_fatmach0_arch_t *archs;
int i;
if(!(bin->bin_obj = r_bin_fatmach0_new(bin->file)))
return 0;
archs = r_bin_fatmach0_extract ((struct r_bin_fatmach0_obj_t*)bin->bin_obj);
if (!archs)
return 0;
for (i = 0; !archs[i].last; i++) {
bin->arch[i].file = bin->file;
bin->arch[i].buf = archs[i].b;
bin->arch[i].size = archs[i].size;
}
free (archs);
return i;
}
struct r_bin_plugin_t r_bin_plugin_fatmach0 = {
struct r_bin_xtr_plugin_t r_bin_xtr_plugin_fatmach0 = {
.name = "fatmach0",
.desc = "fat mach0 bin plugin",
.desc = "fat mach0 bin extractor plugin",
.init = NULL,
.fini = NULL,
.load = &load,
.check = &check,
.extract = &extract,
.destroy = &destroy,
.check = &check,
.baddr = NULL,
.main = NULL,
.entries = NULL,
.sections = NULL,
.symbols = NULL,
.imports = NULL,
.strings = NULL,
.info = NULL,
.fields = NULL,
.libs = NULL,
.relocs = NULL,
.meta = NULL,
.write = NULL,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_fatmach0
.type = R_LIB_TYPE_BIN_XTR,
.data = &r_bin_xtr_plugin_fatmach0
};
#endif

View File

@ -1,7 +1,7 @@
OBJ_FATMACH0=bin_fatmach0.o ../format/mach0/fatmach0.o
OBJ_FATMACH0=bin_xtr_fatmach0.o ../format/mach0/fatmach0.o
STATIC_OBJ+=${OBJ_FATMACH0}
TARGET_FATMACH0=bin_fatmach0.${EXT_SO}
TARGET_FATMACH0=bin_xtr_fatmach0.${EXT_SO}
ALL_TARGETS+=${TARGET_FATMACH0}

View File

@ -20,11 +20,11 @@
#define R_BIN_DBG_RELOCS(x) x & 0x10
#define R_BIN_SIZEOF_STRINGS 256
#define R_BIN_MAX_ARCH 32
typedef struct r_bin_t {
typedef struct r_bin_arch_t {
const char *file;
int size;
void *bin_obj;
ut64 baddr;
struct r_bin_addr_t *main;
struct r_bin_info_t *info;
@ -37,31 +37,52 @@ typedef struct r_bin_t {
RList* libs;
RList* relocs;
RBuffer *buf;
void *bin_obj;
struct r_bin_plugin_t *curplugin;
} RBinArch;
typedef struct r_bin_t {
const char *file;
struct r_bin_arch_t arch[R_BIN_MAX_ARCH];
struct r_bin_arch_t *curarch;
int narch;
void *user;
struct r_bin_plugin_t *cur;
void *bin_obj;
struct r_bin_xtr_plugin_t *curxtr;
struct list_head bins;
struct list_head binxtrs;
} RBin;
typedef struct r_bin_xtr_plugin_t {
char *name;
char *desc;
int (*init)(void *user);
int (*fini)(void *user);
int (*check)(RBin *bin);
int (*extract)(RBin *bin);
int (*destroy)(RBin *bin);
struct list_head list;
} RBinXtrPlugin;
typedef struct r_bin_plugin_t {
char *name;
char *desc;
int (*init)(void *user);
int (*fini)(void *user);
int (*load)(RBin *bin);
int (*extract)(RBin *bin);
int (*destroy)(RBin *bin);
int (*check)(RBin *bin);
ut64 (*baddr)(RBin *bin);
struct r_bin_addr_t* (*main)(RBin *bin);
RList* (*entries)(RBin *bin);
RList* (*sections)(RBin *bin);
RList* (*symbols)(RBin *bin);
RList* (*imports)(RBin *bin);
RList* (*strings)(RBin *bin);
struct r_bin_info_t* (*info)(RBin *bin);
RList* (*fields)(RBin *bin);
RList* (*libs)(RBin *bin);
RList* (*relocs)(RBin *bin);
int (*load)(RBinArch *arch);
int (*destroy)(RBinArch *arch);
int (*check)(RBinArch *arch);
ut64 (*baddr)(RBinArch *arch);
struct r_bin_addr_t* (*main)(RBinArch *arch);
RList* (*entries)(RBinArch *arch);
RList* (*sections)(RBinArch *arch);
RList* (*symbols)(RBinArch *arch);
RList* (*imports)(RBinArch *arch);
RList* (*strings)(RBinArch *arch);
struct r_bin_info_t* (*info)(RBinArch *arch);
RList* (*fields)(RBinArch *arch);
RList* (*libs)(RBinArch *arch);
RList* (*relocs)(RBinArch *arch);
struct r_bin_meta_t *meta;
struct r_bin_write_t *write;
struct list_head list;
@ -147,22 +168,22 @@ typedef struct r_bin_field_t {
} RBinField;
typedef struct r_bin_meta_t {
int (*get_line)(RBin *bin, ut64 addr, char *file, int len, int *line);
int (*get_line)(RBinArch *arch, ut64 addr, char *file, int len, int *line);
} RBinMeta;
typedef struct r_bin_write_t {
ut64 (*scn_resize)(RBin *bin, const char *name, ut64 size);
int (*rpath_del)(RBin *bin);
ut64 (*scn_resize)(RBinArch *arch, const char *name, ut64 size);
int (*rpath_del)(RBinArch *arch);
} RBinWrite;
#ifdef R_API
/* bin.c */
R_API int r_bin_add(RBin *bin, RBinPlugin *foo);
R_API int r_bin_extract(RBin *bin);
R_API int r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo);
R_API void* r_bin_free(RBin *bin);
R_API int r_bin_list(RBin *bin);
R_API int r_bin_load(RBin *bin, const char *file, const char *plugin_name);
R_API int r_bin_load(RBin *bin, const char *file, int dummy);
R_API ut64 r_bin_get_baddr(RBin *bin);
R_API RBinAddr* r_bin_get_main(RBin *bin);
R_API RList* r_bin_get_entries(RBin *bin);
@ -182,6 +203,7 @@ R_API int r_bin_has_dbg_linenums (RBin *bin);
R_API int r_bin_has_dbg_syms (RBin *bin);
R_API int r_bin_has_dbg_relocs (RBin *bin);
R_API RBin* r_bin_new();
R_API int r_bin_set_arch(RBin *bin, const char *arch, int bits);
R_API void r_bin_set_user_ptr(RBin *bin, void *user);
/* bin_meta.c */
@ -200,9 +222,9 @@ extern RBinPlugin r_bin_plugin_pe;
extern RBinPlugin r_bin_plugin_pe64;
extern RBinPlugin r_bin_plugin_mach0;
extern RBinPlugin r_bin_plugin_mach064;
extern RBinPlugin r_bin_plugin_fatmach0;
extern RBinPlugin r_bin_plugin_java;
extern RBinPlugin r_bin_plugin_dummy;
extern RBinXtrPlugin r_bin_xtr_plugin_fatmach0;
#endif
#endif

View File

@ -56,6 +56,7 @@ enum {
R_LIB_TYPE_ANAL, /* analysis */
R_LIB_TYPE_PARSE, /* parsers */
R_LIB_TYPE_BIN, /* bins */
R_LIB_TYPE_BIN_XTR, /* bin extractors */
R_LIB_TYPE_BP, /* breakpoint */
R_LIB_TYPE_SYSCALL, /* syscall */
R_LIB_TYPE_FASTCALL,/* fastcall */

View File

@ -22,7 +22,7 @@ bin.pe
bin.pe64
bin.mach0
bin.mach064
bin.fatmach0
bin_xtr.fatmach0
bp.arm
bp.x86
bp.mips