mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 21:29:49 +00:00
* r_bin
- Add function r_bin_extract() - Add lib r_bin_fatmach0 into format/mach0/ - Complete mach0_specs with fat mach-o stuff - Add plugin bin_fatmach0 - Initial import of mach-ex into r_bin - Remove mach-ex * rabin2 - Add flag -x for extracting bins from file * Build - Update plugins.def.cfg - Remove mach-ex stuff from libr/Makefile
This commit is contained in:
parent
495fc15d89
commit
bb8cfd866d
@ -16,18 +16,19 @@
|
||||
#include <r_util.h>
|
||||
|
||||
#define ACTION_UNK 0x0000
|
||||
#define ACTION_ENTRIES 0x0001
|
||||
#define ACTION_IMPORTS 0x0002
|
||||
#define ACTION_SYMBOLS 0x0004
|
||||
#define ACTION_SECTIONS 0x0008
|
||||
#define ACTION_ENTRIES 0x0001
|
||||
#define ACTION_IMPORTS 0x0002
|
||||
#define ACTION_SYMBOLS 0x0004
|
||||
#define ACTION_SECTIONS 0x0008
|
||||
#define ACTION_INFO 0x0010
|
||||
#define ACTION_OPERATION 0x0020
|
||||
#define ACTION_HELP 0x0040
|
||||
#define ACTION_STRINGS 0x0080
|
||||
#define ACTION_FIELDS 0x0100
|
||||
#define ACTION_LIBS 0x0200
|
||||
#define ACTION_SRCLINE 0x0400
|
||||
#define ACTION_MAIN 0x0800
|
||||
#define ACTION_STRINGS 0x0080
|
||||
#define ACTION_FIELDS 0x0100
|
||||
#define ACTION_LIBS 0x0200
|
||||
#define ACTION_SRCLINE 0x0400
|
||||
#define ACTION_MAIN 0x0800
|
||||
#define ACTION_EXTRACT 0x1000
|
||||
|
||||
static struct r_lib_t *l;
|
||||
static struct r_bin_t *bin = NULL;
|
||||
@ -56,6 +57,7 @@ static int rabin_show_help() {
|
||||
" -m [addr] Show source line at addr\n"
|
||||
" -L List supported bin plugins\n"
|
||||
" -@ [addr] Show section, symbol or import at addr\n"
|
||||
" -x Extract bins contained in file\n"
|
||||
" -V Show version information\n"
|
||||
" -h This help\n");
|
||||
return R_TRUE;
|
||||
@ -108,6 +110,17 @@ static int rabin_show_main() {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int rabin_extract() {
|
||||
int n;
|
||||
|
||||
n = r_bin_extract (bin);
|
||||
if (n != 0) {
|
||||
printf ("%i bins extracted\n", n);
|
||||
return R_TRUE;
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
static int rabin_show_libs() {
|
||||
RList *libs;
|
||||
RListIter *iter;
|
||||
@ -550,7 +563,7 @@ int main(int argc, char **argv)
|
||||
r_lib_opendir (l, LIBDIR"/radare2/");
|
||||
}
|
||||
|
||||
while ((c = getopt (argc, argv, "Mm:@:VisSzIHelwO:o:f:rvLh")) != -1) {
|
||||
while ((c = getopt (argc, argv, "Mm:@:VisSzIHelwO:o:f:rvLhx")) != -1) {
|
||||
switch(c) {
|
||||
case 'm':
|
||||
at = r_num_math (NULL, optarg);
|
||||
@ -582,6 +595,9 @@ int main(int argc, char **argv)
|
||||
case 'l':
|
||||
action |= ACTION_LIBS;
|
||||
break;
|
||||
case 'x':
|
||||
action |= ACTION_EXTRACT;
|
||||
break;
|
||||
case 'w':
|
||||
rw = R_TRUE;
|
||||
break;
|
||||
@ -649,6 +665,8 @@ int main(int argc, char **argv)
|
||||
rabin_show_libs();
|
||||
if (action&ACTION_SRCLINE)
|
||||
rabin_show_srcline(at);
|
||||
if (action&ACTION_EXTRACT)
|
||||
rabin_extract();
|
||||
if (op != NULL && action&ACTION_OPERATION)
|
||||
rabin_do_operation (op);
|
||||
|
||||
|
@ -82,8 +82,6 @@ install-symlink:
|
||||
fi ; \
|
||||
done ; \
|
||||
done
|
||||
# XXX mach-ex will be deprecated soon
|
||||
ln -fs ${PWD}/bin/t/mach-ex${EXT_EXE} ${PFX}/bin/mach-ex${EXT_EXE}
|
||||
|
||||
install: install-includes install-pkgconfig
|
||||
# TODO :Use INSTALL_DATA_DIR instead of mkdir
|
||||
@ -103,9 +101,6 @@ install: install-includes install-pkgconfig
|
||||
${INSTALL_DATA} $$a ${PFX}/lib/radare2 ; done
|
||||
${INSTALL_DATA} lang/p/radare.* ${PFX}/lib/radare2
|
||||
echo "lang/p/radare.* ${PFX}/lib/radare2"
|
||||
# XXX mach-ex will be deprecated soon
|
||||
mkdir -p ${PFX}/bin
|
||||
cp bin/t/mach-ex${EXT_EXE} ${PFX}/bin
|
||||
|
||||
deinstall uninstall:
|
||||
# libraries
|
||||
@ -139,8 +134,6 @@ deinstall uninstall:
|
||||
rm -rf ${PFX}/lib/libr.a
|
||||
rm -rf ${PFX}/share/doc/radare2
|
||||
@echo libr aka radare2 has been uninstalled from PREFIX=${PFX}
|
||||
# XXX mach-ex will be deprecated soon
|
||||
rm -f ${PFX}/bin/mach-ex${EXT_EXE}
|
||||
|
||||
clean:
|
||||
for lib in ${LIBLIST}; do ( cd $${lib} && ${MAKE} clean ); done
|
||||
|
@ -132,6 +132,13 @@ 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 void* r_bin_free(RBin *bin) {
|
||||
if (!bin)
|
||||
return NULL;
|
||||
|
@ -1,7 +1,10 @@
|
||||
/* mach-ex :: mach-O extractor
|
||||
* Copyleft 2010 nibble <at develsec dot org> */
|
||||
/* radare - LGPL - Copyright 2010 nibble at develsec.org */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include "fatmach0.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -9,26 +12,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <r_userconf.h>
|
||||
|
||||
#define ut32 unsigned int
|
||||
#define ut8 unsigned char
|
||||
|
||||
#define FAT_MAGIC 0xcafebabe
|
||||
#define FAT_CIGAM 0xbebafeca
|
||||
|
||||
struct fat_header {
|
||||
ut32 magic;
|
||||
ut32 nfat_arch;
|
||||
};
|
||||
|
||||
struct fat_arch {
|
||||
int cputype;
|
||||
int cpusubtype;
|
||||
ut32 offset;
|
||||
ut32 size;
|
||||
ut32 align;
|
||||
};
|
||||
|
||||
char *file = NULL;
|
||||
int fd;
|
||||
int file_size;
|
||||
int endian = LIL_ENDIAN;
|
||||
@ -103,7 +86,7 @@ static int init() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int extract() {
|
||||
static int extract(const char *file) {
|
||||
ut8 *buf = NULL;
|
||||
char output[256];
|
||||
int i, fdo;
|
||||
@ -141,12 +124,7 @@ static int extract() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 2) {
|
||||
fprintf (stderr, "Usage: %s <fat mach-o file>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
file = argv[1];
|
||||
int r_bin_fatmach0_extract(const char *file) {
|
||||
if ((fd = open (file , O_RDONLY)) == -1) {
|
||||
fprintf (stderr, "Cannot open file\n");
|
||||
return 1;
|
||||
@ -156,7 +134,7 @@ int main(int argc, char **argv) {
|
||||
fprintf (stderr, "Invalid file type\n");
|
||||
return 1;
|
||||
}
|
||||
if (!extract ()) {
|
||||
if (!extract (file)) {
|
||||
fprintf (stderr, "Cannot extract mach-o files\n");
|
||||
return 1;
|
||||
}
|
11
libr/bin/format/mach0/fatmach0.h
Normal file
11
libr/bin/format/mach0/fatmach0.h
Normal file
@ -0,0 +1,11 @@
|
||||
/* radare - GPL3 - Copyright 2009-2010 nibble<.ds@gmail.com> */
|
||||
|
||||
#include <r_types.h>
|
||||
#include "mach0_specs.h"
|
||||
|
||||
#ifndef _INCLUDE_R_BIN_FATMACH0_H_
|
||||
#define _INCLUDE_R_BIN_FATMACH0_H_
|
||||
|
||||
int r_bin_fatmach0_extract(const char *file);
|
||||
|
||||
#endif
|
@ -8,13 +8,13 @@
|
||||
#define MACH0_(name) name##_64
|
||||
#define MH_MAGIC 0xfeedfacf
|
||||
#define MH_CIGAM 0xcffaedfe
|
||||
#define FAT_CIGAM 0xbabefeca /* XXX */
|
||||
#else
|
||||
#define MACH0_(name) name
|
||||
#define MH_MAGIC 0xfeedface
|
||||
#define MH_CIGAM 0xcefaedfe
|
||||
#define FAT_CIGAM 0xcafebabe
|
||||
#endif
|
||||
#define FAT_MAGIC 0xcafebabe
|
||||
#define FAT_CIGAM 0xbebafeca
|
||||
|
||||
#ifndef _INCLUDE_MACHO_SPECS_H_
|
||||
#define _INCLUDE_MACHO_SPECS_H_
|
||||
@ -1729,4 +1729,17 @@ extern int nlist (const char *filename, struct nlist *list);
|
||||
*/
|
||||
#define N_PC 0x30 /* global pascal symbol: name,,NO_SECT,subtype,line */
|
||||
|
||||
struct fat_header {
|
||||
uint32_t magic;
|
||||
uint32_t nfat_arch;
|
||||
};
|
||||
|
||||
struct fat_arch {
|
||||
int cputype;
|
||||
int cpusubtype;
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
uint32_t align;
|
||||
};
|
||||
|
||||
#endif /* _MACHO_LOADER_H_ */
|
||||
|
@ -9,7 +9,7 @@ CFLAGS+=-L../../util -lr_util
|
||||
foo: all
|
||||
|
||||
ALL_TARGETS=
|
||||
FORMATS=elf.mk elf64.mk pe.mk pe64.mk mach0.mk mach064.mk java.mk dummy.mk
|
||||
FORMATS=elf.mk elf64.mk pe.mk pe64.mk mach0.mk mach064.mk fatmach0.mk java.mk dummy.mk
|
||||
include $(FORMATS)
|
||||
|
||||
all: ${ALL_TARGETS}
|
||||
|
@ -33,6 +33,7 @@ struct r_bin_plugin_t r_bin_plugin_dummy = {
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = NULL,
|
||||
.destroy = &destroy,
|
||||
.check = NULL,
|
||||
.baddr = &baddr,
|
||||
@ -46,6 +47,7 @@ struct r_bin_plugin_t r_bin_plugin_dummy = {
|
||||
.fields = NULL,
|
||||
.libs = NULL,
|
||||
.meta = NULL,
|
||||
.write = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -251,6 +251,7 @@ struct r_bin_plugin_t r_bin_plugin_elf = {
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = NULL,
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
|
@ -25,6 +25,7 @@ struct r_bin_plugin_t r_bin_plugin_elf64 = {
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = NULL,
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
|
60
libr/bin/p/bin_fatmach0.c
Normal file
60
libr/bin/p/bin_fatmach0.c
Normal file
@ -0,0 +1,60 @@
|
||||
/* radare - GPL3 - Copyright 2009-2010 nibble<.ds@gmail.com> */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_bin.h>
|
||||
#include "mach0/fatmach0.h"
|
||||
|
||||
static int check(RBin *bin) {
|
||||
ut8 *buf;
|
||||
int n, ret = R_FALSE;
|
||||
|
||||
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 8, &n))) {
|
||||
if (n == 8)
|
||||
/* XXX HACK to avoid conflicts with java class */
|
||||
if (!memcmp (buf, "\xca\xfe\xba\xbe\x00\x00\x00\x02", 8))
|
||||
ret = R_TRUE;
|
||||
free (buf);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int load(RBin *bin) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int extract(RBin *bin) {
|
||||
return r_bin_fatmach0_extract (bin->file);
|
||||
}
|
||||
|
||||
struct r_bin_plugin_t r_bin_plugin_fatmach0 = {
|
||||
.name = "fatmach0",
|
||||
.desc = "fat mach0 bin plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = &extract,
|
||||
.destroy = NULL,
|
||||
.check = &check,
|
||||
.baddr = NULL,
|
||||
.main = NULL,
|
||||
.entries = NULL,
|
||||
.sections = NULL,
|
||||
.symbols = NULL,
|
||||
.imports = NULL,
|
||||
.strings = NULL,
|
||||
.info = NULL,
|
||||
.fields = NULL,
|
||||
.libs = NULL,
|
||||
.meta = NULL,
|
||||
.write = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_BIN,
|
||||
.data = &r_bin_plugin_fatmach0
|
||||
};
|
||||
#endif
|
||||
|
@ -112,6 +112,7 @@ static RBinInfo* info(RBin *bin) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* TODO: Avoid conflict with mach0 */
|
||||
static int check(RBin *bin) {
|
||||
ut8 *buf;
|
||||
int n, ret = R_FALSE;
|
||||
@ -130,6 +131,7 @@ struct r_bin_plugin_t r_bin_plugin_java = {
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = NULL,
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
@ -143,6 +145,7 @@ struct r_bin_plugin_t r_bin_plugin_java = {
|
||||
.fields = NULL,
|
||||
.libs = NULL,
|
||||
.meta = NULL,
|
||||
.write = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -183,18 +183,11 @@ static RBinInfo* info(RBin *bin) {
|
||||
static int check(RBin *bin) {
|
||||
ut8 *buf;
|
||||
int n, ret = R_FALSE;
|
||||
|
||||
if ((buf = (ut8*)r_file_slurp_range (bin->file, 0, 8, &n))) {
|
||||
if (n == 8) {
|
||||
/* XXX HACK to avoid conflicts with java class */
|
||||
if (!memcmp (buf, "\xca\xfe\xba\xbe\x00\x00\x00\x02", 8)) {
|
||||
eprintf ("Warning: fat mach-o, use mach-ex to extract the bins\n");
|
||||
ret = R_TRUE;
|
||||
} else
|
||||
if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) ||
|
||||
!memcmp (buf, "\xfe\xed\xfa\xce", 4))
|
||||
ret = R_TRUE;
|
||||
}
|
||||
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;
|
||||
@ -206,6 +199,7 @@ struct r_bin_plugin_t r_bin_plugin_mach0 = {
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = NULL,
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
@ -219,6 +213,7 @@ struct r_bin_plugin_t r_bin_plugin_mach0 = {
|
||||
.fields = NULL,
|
||||
.libs = &libs,
|
||||
.meta = NULL,
|
||||
.write = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -22,6 +22,7 @@ struct r_bin_plugin_t r_bin_plugin_mach064 = {
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = NULL,
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
@ -35,6 +36,7 @@ struct r_bin_plugin_t r_bin_plugin_mach064 = {
|
||||
.fields = NULL,
|
||||
.libs = &libs,
|
||||
.meta = NULL,
|
||||
.write = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -229,6 +229,7 @@ struct r_bin_plugin_t r_bin_plugin_pe = {
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = NULL,
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
@ -242,6 +243,7 @@ struct r_bin_plugin_t r_bin_plugin_pe = {
|
||||
.fields = NULL,
|
||||
.libs = &libs,
|
||||
.meta = NULL,
|
||||
.write = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -25,6 +25,7 @@ struct r_bin_plugin_t r_bin_plugin_pe64 = {
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.load = &load,
|
||||
.extract = NULL,
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
@ -38,6 +39,7 @@ struct r_bin_plugin_t r_bin_plugin_pe64 = {
|
||||
.fields = NULL,
|
||||
.libs = &libs,
|
||||
.meta = NULL,
|
||||
.write = NULL,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
10
libr/bin/p/fatmach0.mk
Normal file
10
libr/bin/p/fatmach0.mk
Normal file
@ -0,0 +1,10 @@
|
||||
OBJ_FATMACH0=bin_fatmach0.o ../format/mach0/fatmach0.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_FATMACH0}
|
||||
TARGET_FATMACH0=bin_fatmach0.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_FATMACH0}
|
||||
|
||||
${TARGET_FATMACH0}: ${OBJ_FATMACH0}
|
||||
${CC} -shared ${CFLAGS} -o ${TARGET_FATMACH0} ${OBJ_FATMACH0}
|
||||
@#strip -s ${TARGET_FATMACH0}
|
@ -7,7 +7,7 @@ LIBS+=${DL_LIBS}
|
||||
LDPATH=-L.. -L../../util
|
||||
LDPATH+=-lr_util
|
||||
|
||||
all: test_meta${EXT_EXE} mach-ex${EXT_EXE} rpathdel${EXT_EXE}
|
||||
all: test_meta${EXT_EXE} rpathdel${EXT_EXE}
|
||||
|
||||
test_meta${EXT_EXE}: test_meta.o
|
||||
${CC} test_meta.o ${LDPATH} ${LDFLAGS} -o test_meta${EXT_EXE}
|
||||
@ -15,10 +15,7 @@ test_meta${EXT_EXE}: test_meta.o
|
||||
rpathdel${EXT_EXE}: rpathdel.o
|
||||
${CC} rpathdel.o ${LDPATH} ${LDFLAGS} -o rpathdel${EXT_EXE}
|
||||
|
||||
mach-ex${EXT_EXE}:
|
||||
${CC} ${CFLAGS} -o mach-ex${EXT_EXE} ${LDFLAGS} mach-ex.c
|
||||
|
||||
myclean:
|
||||
rm -f test_meta test_meta.o mach-ex rpathdel
|
||||
rm -f test_meta test_meta.o rpathdel
|
||||
|
||||
include ../../rules.mk
|
||||
|
@ -47,6 +47,7 @@ typedef struct r_bin_plugin_t {
|
||||
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);
|
||||
@ -141,6 +142,7 @@ typedef struct r_bin_write_t {
|
||||
|
||||
/* bin.c */
|
||||
R_API int r_bin_add(RBin *bin, RBinPlugin *foo);
|
||||
R_API int r_bin_extract(RBin *bin);
|
||||
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);
|
||||
@ -180,6 +182,7 @@ 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;
|
||||
|
||||
|
@ -22,6 +22,7 @@ bin.pe
|
||||
bin.pe64
|
||||
bin.mach0
|
||||
bin.mach064
|
||||
bin.fatmach0
|
||||
bp.arm
|
||||
bp.x86
|
||||
bp.mips
|
||||
|
Loading…
Reference in New Issue
Block a user