mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 13:19:54 +00:00
* r_util
- Add r_str_dup_printf * r_bin_elf - Huge refactoring r_bin_elf_get_{imports, symbols} will be modified soon r_buf|r_io will be used, so 'swap-endian' and 'malloc-lseek-read' calls will be removed Need to rethink section resize (temporary disabled) * rabin2 - Refactoring
This commit is contained in:
parent
b02e61bc01
commit
811f39c833
@ -25,7 +25,7 @@ static struct r_bin_string_t *get_strings(struct r_bin_t *bin, int min)
|
||||
u8 *buf = NULL;
|
||||
u64 len, max_str = 0;
|
||||
int i, matches = 0, ctr = 0;
|
||||
char str[R_BIN_SIZEOF_NAMES];
|
||||
char str[R_BIN_SIZEOF_STRINGS];
|
||||
|
||||
len = lseek(bin->fd, 0, SEEK_END);
|
||||
max_str = (u64)(len/min);
|
||||
@ -52,8 +52,8 @@ static struct r_bin_string_t *get_strings(struct r_bin_t *bin, int min)
|
||||
ret[ctr].rva = ret[ctr].offset = i-matches;
|
||||
ret[ctr].size = matches;
|
||||
ret[ctr].ordinal = ctr;
|
||||
memcpy(ret[ctr].string, str, R_BIN_SIZEOF_NAMES);
|
||||
ret[ctr].string[R_BIN_SIZEOF_NAMES-1] = '\0';
|
||||
memcpy(ret[ctr].string, str, R_BIN_SIZEOF_STRINGS);
|
||||
ret[ctr].string[R_BIN_SIZEOF_STRINGS-1] = '\0';
|
||||
ret[ctr].last = 0;
|
||||
ctr++;
|
||||
}
|
||||
@ -127,7 +127,7 @@ int r_bin_open(struct r_bin_t *bin, const char *file, int rw, char *plugin_name)
|
||||
{
|
||||
if (file != NULL)
|
||||
bin->file = file;
|
||||
else return R_FALSE;
|
||||
else return -1;
|
||||
bin->rw = rw;
|
||||
|
||||
struct list_head *pos;
|
||||
@ -141,7 +141,7 @@ int r_bin_open(struct r_bin_t *bin, const char *file, int rw, char *plugin_name)
|
||||
if (bin->cur && bin->cur->open)
|
||||
return bin->cur->open(bin);
|
||||
if (plugin_name && !strcmp(plugin_name, "bin_dummy"))
|
||||
return R_FALSE;
|
||||
return -1;
|
||||
return r_bin_open(bin, file, rw, "bin_dummy");
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ int r_bin_close(struct r_bin_t *bin)
|
||||
if (bin->cur && bin->cur->close)
|
||||
return bin->cur->close(bin);
|
||||
|
||||
return R_FALSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
u64 r_bin_get_baddr(struct r_bin_t *bin)
|
||||
@ -158,7 +158,7 @@ u64 r_bin_get_baddr(struct r_bin_t *bin)
|
||||
if (bin->cur && bin->cur->baddr)
|
||||
return bin->cur->baddr(bin);
|
||||
|
||||
return R_FALSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct r_bin_entry_t* r_bin_get_entry(struct r_bin_t *bin)
|
||||
@ -218,32 +218,32 @@ struct r_bin_field_t* r_bin_get_fields(struct r_bin_t *bin)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*XXX*/
|
||||
#if 0
|
||||
u64 r_bin_resize_section(struct r_bin_t *bin, char *name, u64 size)
|
||||
{
|
||||
if (bin->cur && bin->cur->resize_section)
|
||||
return bin->cur->resize_section(bin, name, size);
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
u64 r_bin_get_section_offset(struct r_bin_t *bin, char *name)
|
||||
{
|
||||
struct r_bin_section_t *sections, *sectionsp;
|
||||
struct r_bin_section_t *sections;
|
||||
u64 ret = -1;
|
||||
int i;
|
||||
|
||||
if (!(sections = r_bin_get_sections(bin)))
|
||||
return R_FALSE;
|
||||
|
||||
sectionsp = sections;
|
||||
while (!sectionsp->last) {
|
||||
if (!strcmp(sectionsp->name, name)) {
|
||||
ret = sectionsp->offset;
|
||||
for (i = 0; !sections[i].last; i++)
|
||||
if (!strcmp(sections[i].name, name)) {
|
||||
ret = sections[i].offset;
|
||||
break;
|
||||
}
|
||||
|
||||
sectionsp++;
|
||||
}
|
||||
|
||||
free(sections);
|
||||
|
||||
return ret;
|
||||
@ -251,20 +251,18 @@ u64 r_bin_get_section_offset(struct r_bin_t *bin, char *name)
|
||||
|
||||
u64 r_bin_get_section_rva(struct r_bin_t *bin, char *name)
|
||||
{
|
||||
struct r_bin_section_t *sections, *sectionsp;
|
||||
struct r_bin_section_t *sections;
|
||||
u64 ret = -1;
|
||||
int i;
|
||||
|
||||
if (!(sections = r_bin_get_sections(bin)))
|
||||
return R_FALSE;
|
||||
|
||||
sectionsp = sections;
|
||||
while (!sectionsp->last) {
|
||||
if (!strcmp(sectionsp->name, name)) {
|
||||
ret = sectionsp->rva;
|
||||
for (i = 0; !sections[i].last; i++) {
|
||||
if (!strcmp(sections[i].name, name)) {
|
||||
ret = sections[i].rva;
|
||||
break;
|
||||
}
|
||||
|
||||
sectionsp++;
|
||||
}
|
||||
|
||||
free(sections);
|
||||
@ -274,19 +272,18 @@ u64 r_bin_get_section_rva(struct r_bin_t *bin, char *name)
|
||||
|
||||
u64 r_bin_get_section_size(struct r_bin_t *bin, char *name)
|
||||
{
|
||||
struct r_bin_section_t *sections, *sectionsp;
|
||||
struct r_bin_section_t *sections;
|
||||
u64 ret = -1;
|
||||
int i;
|
||||
|
||||
if (!(sections = r_bin_get_sections(bin)))
|
||||
return R_FALSE;
|
||||
|
||||
sectionsp = sections;
|
||||
while (!sectionsp->last) {
|
||||
if (!strcmp(sectionsp->name, name)) {
|
||||
ret = sectionsp->size;
|
||||
for (i = 0; !sections[i].last; i++) {
|
||||
if (!strcmp(sections[i].name, name)) {
|
||||
ret = sections[i].size;
|
||||
break;
|
||||
}
|
||||
sectionsp++;
|
||||
}
|
||||
|
||||
free(sections);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -11,77 +11,75 @@
|
||||
#define R_BIN_ELF_SCN_IS_READABLE(x) x & SHF_ALLOC
|
||||
#define R_BIN_ELF_SCN_IS_WRITABLE(x) x & SHF_WRITE
|
||||
|
||||
typedef struct {
|
||||
struct r_bin_elf_section_t {
|
||||
u64 offset;
|
||||
u64 size;
|
||||
u64 align;
|
||||
u32 flags;
|
||||
char name[ELF_NAME_LENGTH];
|
||||
} r_bin_elf_section;
|
||||
char name[ELF_STRING_LENGTH];
|
||||
int last;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct r_bin_elf_import_t {
|
||||
u64 offset;
|
||||
char bind[ELF_NAME_LENGTH];
|
||||
char type[ELF_NAME_LENGTH];
|
||||
char name[ELF_NAME_LENGTH];
|
||||
} r_bin_elf_import;
|
||||
char bind[ELF_STRING_LENGTH];
|
||||
char type[ELF_STRING_LENGTH];
|
||||
char name[ELF_STRING_LENGTH];
|
||||
int last;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct r_bin_elf_symbol_t {
|
||||
u64 offset;
|
||||
u64 size;
|
||||
char bind[ELF_NAME_LENGTH];
|
||||
char type[ELF_NAME_LENGTH];
|
||||
char name[ELF_NAME_LENGTH];
|
||||
} r_bin_elf_symbol;
|
||||
char bind[ELF_STRING_LENGTH];
|
||||
char type[ELF_STRING_LENGTH];
|
||||
char name[ELF_STRING_LENGTH];
|
||||
int last;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct r_bin_elf_field_t {
|
||||
u64 offset;
|
||||
char name[ELF_NAME_LENGTH];
|
||||
} r_bin_elf_field;
|
||||
char name[ELF_STRING_LENGTH];
|
||||
int last;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct r_bin_elf_string_t {
|
||||
u64 offset;
|
||||
u64 size;
|
||||
char type;
|
||||
char string[ELF_STRING_LENGTH];
|
||||
} r_bin_elf_string;
|
||||
int last;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
ELF_(Ehdr) ehdr;
|
||||
ELF_(Phdr)* phdr;
|
||||
ELF_(Shdr)* shdr;
|
||||
int plen;
|
||||
char** section;
|
||||
char* string;
|
||||
struct Elf_(r_bin_elf_obj_t) {
|
||||
Elf_(Ehdr) ehdr;
|
||||
Elf_(Phdr)* phdr;
|
||||
Elf_(Shdr)* shdr;
|
||||
char* strtab;
|
||||
int bss;
|
||||
u64 base_addr;
|
||||
u64 baddr;
|
||||
int endian;
|
||||
const char* file;
|
||||
int fd;
|
||||
} ELF_(r_bin_elf_obj);
|
||||
};
|
||||
|
||||
int ELF_(r_bin_elf_close)(ELF_(r_bin_elf_obj)*);
|
||||
const char* ELF_(r_bin_elf_get_arch)(ELF_(r_bin_elf_obj)*);
|
||||
u64 ELF_(r_bin_elf_get_base_addr)(ELF_(r_bin_elf_obj)*);
|
||||
const char* ELF_(r_bin_elf_get_data_encoding)(ELF_(r_bin_elf_obj)*);
|
||||
const char* ELF_(r_bin_elf_get_elf_class)(ELF_(r_bin_elf_obj)*);
|
||||
u64 ELF_(r_bin_elf_get_entry_offset)(ELF_(r_bin_elf_obj)*);
|
||||
const char* ELF_(r_bin_elf_get_file_type)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_get_imports)(ELF_(r_bin_elf_obj)*, r_bin_elf_import*);
|
||||
int ELF_(r_bin_elf_get_imports_count)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_get_libs)(ELF_(r_bin_elf_obj)*, int, r_bin_elf_string*);
|
||||
const char* ELF_(r_bin_elf_get_machine_name)(ELF_(r_bin_elf_obj)*);
|
||||
const char* ELF_(r_bin_elf_get_osabi_name)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_get_sections)(ELF_(r_bin_elf_obj)*, r_bin_elf_section*);
|
||||
int ELF_(r_bin_elf_get_sections_count)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_get_static)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_get_strings)(ELF_(r_bin_elf_obj)*, int, int, r_bin_elf_string*);
|
||||
int ELF_(r_bin_elf_get_stripped)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_get_symbols)(ELF_(r_bin_elf_obj)*, r_bin_elf_symbol*);
|
||||
int ELF_(r_bin_elf_get_symbols_count)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_get_fields)(ELF_(r_bin_elf_obj)*, r_bin_elf_field*);
|
||||
int ELF_(r_bin_elf_get_fields_count)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_is_big_endian)(ELF_(r_bin_elf_obj)*);
|
||||
int ELF_(r_bin_elf_open)(ELF_(r_bin_elf_obj)*, const char*, int);
|
||||
u64 ELF_(r_bin_elf_resize_section)(ELF_(r_bin_elf_obj)*, const char*, u64);
|
||||
u64 Elf_(r_bin_elf_get_baddr)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
u64 Elf_(r_bin_elf_get_entry_offset)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
int Elf_(r_bin_elf_get_stripped)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
int Elf_(r_bin_elf_get_static)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
char* Elf_(r_bin_elf_get_data_encoding)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
char* Elf_(r_bin_elf_get_arch)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
char* Elf_(r_bin_elf_get_machine_name)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
char* Elf_(r_bin_elf_get_file_type)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
char* Elf_(r_bin_elf_get_elf_class)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
char* Elf_(r_bin_elf_get_osabi_name)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
int Elf_(r_bin_elf_is_big_endian)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
/*XXX Section resize? */
|
||||
struct r_bin_elf_section_t* Elf_(r_bin_elf_get_sections)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
struct r_bin_elf_import_t* Elf_(r_bin_elf_get_imports)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
struct r_bin_elf_symbol_t* Elf_(r_bin_elf_get_symbols)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
struct r_bin_elf_field_t* Elf_(r_bin_elf_get_fields)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
int Elf_(r_bin_elf_open)(struct Elf_(r_bin_elf_obj_t) *bin, const char *file, int rw);
|
||||
int Elf_(r_bin_elf_close)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
|
@ -17,7 +17,8 @@
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#undef ELF_
|
||||
#undef Elf_
|
||||
#undef Elf_Vword
|
||||
#undef ELF_ST_BIND
|
||||
#undef ELF_ST_TYPE
|
||||
#undef ELF_ST_INFO
|
||||
@ -28,39 +29,42 @@
|
||||
#undef ELF_M_SYM
|
||||
#undef ELF_M_SIZE
|
||||
#undef ELF_M_INFO
|
||||
#undef ELF_Vword
|
||||
|
||||
#ifdef R_BIN_ELF64
|
||||
#define ELF_(name) Elf64_##name
|
||||
#define ELF_ST_BIND ELF64_ST_BIND
|
||||
#define ELF_ST_TYPE ELF64_ST_TYPE
|
||||
#define ELF_ST_INFO ELF64_ST_INFO
|
||||
#define ELF_ST_VISIBILITY ELF64_ST_VISIBILITY
|
||||
#define ELF_R_SYM ELF64_R_SYM
|
||||
#define ELF_R_TYPE ELF64_R_TYPE
|
||||
#define ELF_R_INFO ELF64_R_INFO
|
||||
#define ELF_M_SYM ELF64_M_SYM
|
||||
#define ELF_M_SIZE ELF64_M_SIZE
|
||||
#define ELF_M_INFO ELF64_M_INFO
|
||||
#define ELF_Vword Elf64_Xword
|
||||
# define Elf_(name) Elf64_##name
|
||||
# define Elf_Vword Elf64_Xword
|
||||
# define ELF_ST_BIND ELF64_ST_BIND
|
||||
# define ELF_ST_TYPE ELF64_ST_TYPE
|
||||
# define ELF_ST_INFO ELF64_ST_INFO
|
||||
# define ELF_ST_VISIBILITY ELF64_ST_VISIBILITY
|
||||
# define ELF_R_SYM ELF64_R_SYM
|
||||
# define ELF_R_TYPE ELF64_R_TYPE
|
||||
# define ELF_R_INFO ELF64_R_INFO
|
||||
# define ELF_M_SYM ELF64_M_SYM
|
||||
# define ELF_M_SIZE ELF64_M_SIZE
|
||||
# define ELF_M_INFO ELF64_M_INFO
|
||||
#else
|
||||
#define ELF_(name) Elf32_##name
|
||||
#define ELF_ST_BIND ELF32_ST_BIND
|
||||
#define ELF_ST_TYPE ELF32_ST_TYPE
|
||||
#define ELF_ST_INFO ELF32_ST_INFO
|
||||
#define ELF_ST_VISIBILITY ELF32_ST_VISIBILITY
|
||||
#define ELF_R_SYM ELF32_R_SYM
|
||||
#define ELF_R_TYPE ELF32_R_TYPE
|
||||
#define ELF_R_INFO ELF32_R_INFO
|
||||
#define ELF_M_SYM ELF32_M_SYM
|
||||
#define ELF_M_SIZE ELF32_M_SIZE
|
||||
#define ELF_M_INFO ELF32_M_INFO
|
||||
#define ELF_Vword Elf32_Word
|
||||
# define Elf_(name) Elf32_##name
|
||||
# define Elf_Vword Elf32_Word
|
||||
# define ELF_ST_BIND ELF32_ST_BIND
|
||||
# define ELF_ST_TYPE ELF32_ST_TYPE
|
||||
# define ELF_ST_INFO ELF32_ST_INFO
|
||||
# define ELF_ST_VISIBILITY ELF32_ST_VISIBILITY
|
||||
# define ELF_R_SYM ELF32_R_SYM
|
||||
# define ELF_R_TYPE ELF32_R_TYPE
|
||||
# define ELF_R_INFO ELF32_R_INFO
|
||||
# define ELF_M_SYM ELF32_M_SYM
|
||||
# define ELF_M_SIZE ELF32_M_SIZE
|
||||
# define ELF_M_INFO ELF32_M_INFO
|
||||
#endif
|
||||
|
||||
#ifndef _INCLUDE_ELF_SPECS_H
|
||||
#define _INCLUDE_ELF_SPECS_H
|
||||
|
||||
#define ELF_STRING_LENGTH 256
|
||||
#define ELF_ADDR_MASK 0xFFFFFFFFFFFF8000LL
|
||||
#define ELF_GOTOFF_MASK 0xFFFFFFFFFFFFF000LL
|
||||
|
||||
/* Type for a 16-bit quantity. */
|
||||
typedef unsigned short Elf32_Half;
|
||||
typedef unsigned short Elf64_Half;
|
||||
@ -93,12 +97,6 @@ typedef unsigned short Elf64_Section;
|
||||
typedef Elf32_Half Elf32_Versym;
|
||||
typedef Elf64_Half Elf64_Versym;
|
||||
|
||||
|
||||
#define ELF_NAME_LENGTH 256
|
||||
#define ELF_STRING_LENGTH 256
|
||||
#define ELF_ADDR_MASK 0xffffffffffff8000LL
|
||||
#define ELF_GOTOFF_MASK 0xfffffffffffff000LL
|
||||
|
||||
/* The ELF file header. This appears at the start of every ELF file. */
|
||||
|
||||
#define EI_NIDENT (16)
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
static int bopen(struct r_bin_t *bin)
|
||||
{
|
||||
if((bin->bin_obj = MALLOC_STRUCT(ELF_(r_bin_elf_obj))) == NULL)
|
||||
if((bin->bin_obj = MALLOC_STRUCT(struct Elf_(r_bin_elf_obj_t))) == NULL)
|
||||
return R_FALSE;
|
||||
|
||||
if ((bin->fd = ELF_(r_bin_elf_open)(bin->bin_obj,bin->file,bin->rw)) == -1) {
|
||||
if ((bin->fd = Elf_(r_bin_elf_open)(bin->bin_obj,bin->file,bin->rw)) == -1) {
|
||||
free(bin->bin_obj);
|
||||
return R_FALSE;
|
||||
}
|
||||
@ -20,12 +20,12 @@ static int bopen(struct r_bin_t *bin)
|
||||
|
||||
static int bclose(struct r_bin_t *bin)
|
||||
{
|
||||
return ELF_(r_bin_elf_close)(bin->bin_obj);
|
||||
return Elf_(r_bin_elf_close)(bin->bin_obj);
|
||||
}
|
||||
|
||||
static u64 baddr(struct r_bin_t *bin)
|
||||
{
|
||||
return ELF_(r_bin_elf_get_base_addr)(bin->bin_obj);
|
||||
return Elf_(r_bin_elf_get_baddr)(bin->bin_obj);
|
||||
}
|
||||
|
||||
static struct r_bin_entry_t* entry(struct r_bin_t *bin)
|
||||
@ -36,28 +36,24 @@ static struct r_bin_entry_t* entry(struct r_bin_t *bin)
|
||||
return NULL;
|
||||
memset(ret, '\0', sizeof(struct r_bin_entry_t));
|
||||
|
||||
ret->offset = ret->rva = ELF_(r_bin_elf_get_entry_offset)(bin->bin_obj);
|
||||
ret->offset = ret->rva = Elf_(r_bin_elf_get_entry_offset)(bin->bin_obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct r_bin_section_t* sections(struct r_bin_t *bin)
|
||||
{
|
||||
int sections_count, i;
|
||||
struct r_bin_section_t *ret = NULL;
|
||||
r_bin_elf_section *section = NULL;
|
||||
struct r_bin_elf_section_t *section = NULL;
|
||||
int i, sections_count;
|
||||
|
||||
sections_count = ELF_(r_bin_elf_get_sections_count)(bin->bin_obj);
|
||||
|
||||
if((section = malloc(sections_count * sizeof(r_bin_elf_section))) == NULL)
|
||||
if ((section = Elf_(r_bin_elf_get_sections)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
if((ret = malloc((sections_count + 1) * sizeof(struct r_bin_section_t))) == NULL)
|
||||
for (sections_count = 0; !section[sections_count].last; sections_count++);
|
||||
if ((ret = malloc((sections_count + 1) * sizeof(struct r_bin_section_t))) == NULL)
|
||||
return NULL;
|
||||
memset(ret, '\0', (sections_count + 1) * sizeof(struct r_bin_section_t));
|
||||
|
||||
ELF_(r_bin_elf_get_sections)(bin->bin_obj,section);
|
||||
|
||||
for (i = 0; i < sections_count; i++) {
|
||||
strncpy(ret[i].name, (char*)section[i].name, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].name, (char*)section[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].size = section[i].size;
|
||||
ret[i].vsize = section[i].size;
|
||||
ret[i].offset = section[i].offset;
|
||||
@ -82,23 +78,18 @@ static struct r_bin_symbol_t* symbols(struct r_bin_t *bin)
|
||||
{
|
||||
int symbols_count, i;
|
||||
struct r_bin_symbol_t *ret = NULL;
|
||||
r_bin_elf_symbol *symbol = NULL;
|
||||
struct r_bin_elf_symbol_t *symbol = NULL;
|
||||
|
||||
symbols_count = ELF_(r_bin_elf_get_symbols_count)(bin->bin_obj);
|
||||
|
||||
if ((symbol = malloc(symbols_count * sizeof(r_bin_elf_symbol))) == NULL)
|
||||
return NULL;
|
||||
symbol = Elf_(r_bin_elf_get_symbols)(bin->bin_obj);
|
||||
for (symbols_count = 0; !symbol[symbols_count].last; symbols_count++);
|
||||
if ((ret = malloc((symbols_count + 1) * sizeof(struct r_bin_symbol_t))) == NULL)
|
||||
return NULL;
|
||||
memset(ret, '\0', (symbols_count + 1) * sizeof(struct r_bin_symbol_t));
|
||||
|
||||
ELF_(r_bin_elf_get_symbols)(bin->bin_obj, symbol);
|
||||
|
||||
for (i = 0; i < symbols_count; i++) {
|
||||
strncpy(ret[i].name, symbol[i].name, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].forwarder, "NONE", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].bind, symbol[i].bind, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].type, symbol[i].type, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].name, symbol[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].forwarder, "NONE", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].bind, symbol[i].bind, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].type, symbol[i].type, R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].rva = symbol[i].offset;
|
||||
ret[i].offset = symbol[i].offset;
|
||||
ret[i].size = symbol[i].size;
|
||||
@ -116,22 +107,17 @@ static struct r_bin_import_t* imports(struct r_bin_t *bin)
|
||||
{
|
||||
int imports_count, i;
|
||||
struct r_bin_import_t *ret = NULL;
|
||||
r_bin_elf_import *import = NULL;
|
||||
struct r_bin_elf_import_t *import = NULL;
|
||||
|
||||
imports_count = ELF_(r_bin_elf_get_imports_count)(bin->bin_obj);
|
||||
|
||||
if ((import = malloc(imports_count * sizeof(r_bin_elf_import))) == NULL)
|
||||
return NULL;
|
||||
import = Elf_(r_bin_elf_get_imports)(bin->bin_obj);
|
||||
for (imports_count = 0; !import[imports_count].last; imports_count++);
|
||||
if ((ret = malloc((imports_count + 1) * sizeof(struct r_bin_import_t))) == NULL)
|
||||
return NULL;
|
||||
memset(ret, '\0', (imports_count + 1) * sizeof(struct r_bin_import_t));
|
||||
|
||||
ELF_(r_bin_elf_get_imports)(bin->bin_obj,import);
|
||||
|
||||
for (i = 0; i < imports_count; i++) {
|
||||
strncpy(ret[i].name, import[i].name, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].bind, import[i].bind, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].type, import[i].type, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].name, import[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].bind, import[i].bind, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].type, import[i].type, R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].rva = import[i].offset;
|
||||
ret[i].offset = import[i].offset;
|
||||
ret[i].ordinal = 0;
|
||||
@ -139,35 +125,63 @@ static struct r_bin_import_t* imports(struct r_bin_t *bin)
|
||||
ret[i].last = 0;
|
||||
}
|
||||
ret[i].last = 1;
|
||||
|
||||
free(import);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct r_bin_info_t* info(struct r_bin_t *bin)
|
||||
{
|
||||
struct r_bin_info_t *ret = NULL;
|
||||
char *string;
|
||||
|
||||
if((ret = malloc(sizeof(struct r_bin_info_t))) == NULL)
|
||||
return NULL;
|
||||
memset(ret, '\0', sizeof(struct r_bin_info_t));
|
||||
|
||||
strncpy(ret->type, ELF_(r_bin_elf_get_file_type)(bin->bin_obj), R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->class, ELF_(r_bin_elf_get_elf_class)(bin->bin_obj), R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->rclass, "elf", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->os, ELF_(r_bin_elf_get_osabi_name)(bin->bin_obj), R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->subsystem, ELF_(r_bin_elf_get_osabi_name)(bin->bin_obj), R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->machine, ELF_(r_bin_elf_get_machine_name)(bin->bin_obj), R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->arch, ELF_(r_bin_elf_get_arch)(bin->bin_obj), R_BIN_SIZEOF_NAMES);
|
||||
ret->big_endian=ELF_(r_bin_elf_is_big_endian)(bin->bin_obj);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_file_type)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->type, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_elf_class)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->class, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_osabi_name)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->os, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_osabi_name)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->subsystem, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_machine_name)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->machine, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
|
||||
if ((string = Elf_(r_bin_elf_get_arch)(bin->bin_obj)) == NULL)
|
||||
return NULL;
|
||||
strncpy(ret->arch, string, R_BIN_SIZEOF_STRINGS);
|
||||
free(string);
|
||||
|
||||
strncpy(ret->rclass, "elf", R_BIN_SIZEOF_STRINGS);
|
||||
ret->big_endian=Elf_(r_bin_elf_is_big_endian)(bin->bin_obj);
|
||||
ret->dbg_info = 0;
|
||||
if (ELF_(r_bin_elf_get_stripped)(bin->bin_obj)) {
|
||||
if (Elf_(r_bin_elf_get_stripped)(bin->bin_obj)) {
|
||||
ret->dbg_info |= 0x01;
|
||||
} else {
|
||||
ret->dbg_info |= 0x04;
|
||||
ret->dbg_info |= 0x08;
|
||||
ret->dbg_info |= 0x10;
|
||||
}
|
||||
if (ELF_(r_bin_elf_get_static)(bin->bin_obj))
|
||||
if (Elf_(r_bin_elf_get_static)(bin->bin_obj))
|
||||
ret->dbg_info |= 0x02;
|
||||
return ret;
|
||||
}
|
||||
@ -175,21 +189,15 @@ static struct r_bin_info_t* info(struct r_bin_t *bin)
|
||||
static struct r_bin_field_t* fields(struct r_bin_t *bin)
|
||||
{
|
||||
struct r_bin_field_t *ret = NULL;
|
||||
r_bin_elf_field *field = NULL;
|
||||
struct r_bin_elf_field_t *field = NULL;
|
||||
int i, fields_count;
|
||||
|
||||
fields_count = ELF_(r_bin_elf_get_fields_count)(bin->bin_obj);
|
||||
|
||||
if ((field = malloc(fields_count * sizeof(r_bin_elf_field))) == NULL)
|
||||
return NULL;
|
||||
field = Elf_(r_bin_elf_get_fields)(bin->bin_obj);
|
||||
for (fields_count = 0; !field[fields_count].last; fields_count++);
|
||||
if ((ret = malloc((fields_count + 1) * sizeof(struct r_bin_field_t))) == NULL)
|
||||
return NULL;
|
||||
memset(ret, '\0', (fields_count + 1) * sizeof(struct r_bin_field_t));
|
||||
|
||||
ELF_(r_bin_elf_get_fields)(bin->bin_obj,field);
|
||||
|
||||
for (i = 0; i < fields_count; i++) {
|
||||
strncpy(ret[i].name, field[i].name, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].name, field[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].rva = field[i].offset;
|
||||
ret[i].offset = field[i].offset;
|
||||
ret[i].last = 0;
|
||||
@ -201,10 +209,13 @@ static struct r_bin_field_t* fields(struct r_bin_t *bin)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*XXX*/
|
||||
#if 0
|
||||
static u64 resize_section(struct r_bin_t *bin, char *name, u64 size)
|
||||
{
|
||||
return ELF_(r_bin_elf_resize_section)(bin->bin_obj, name, size);
|
||||
return Elf_(r_bin_elf_resize_section)(bin->bin_obj, name, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !R_BIN_ELF64
|
||||
static int check(struct r_bin_t *bin)
|
||||
@ -239,7 +250,8 @@ struct r_bin_handle_t r_bin_plugin_elf = {
|
||||
.strings = NULL,
|
||||
.info = &info,
|
||||
.fields = &fields,
|
||||
.resize_section = &resize_section
|
||||
.resize_section = NULL
|
||||
/*XXX .resize_section = &resize_section */
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -36,7 +36,8 @@ struct r_bin_handle_t r_bin_plugin_elf64 = {
|
||||
.strings = NULL,
|
||||
.info = &info,
|
||||
.fields = &fields,
|
||||
.resize_section = &resize_section
|
||||
.resize_section = NULL
|
||||
/*XXX .resize_section = &resize_section */
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -57,10 +57,10 @@ static struct r_bin_symbol_t* symbols(struct r_bin_t *bin)
|
||||
r_bin_java_get_symbols(bin->bin_obj,symbol);
|
||||
|
||||
for (i = 0; i < symbols_count; i++) {
|
||||
strncpy(ret[i].name, symbol[i].name, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].forwarder, "NONE", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].bind, "NONE", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].type, "FUNC", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].name, symbol[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].forwarder, "NONE", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].bind, "NONE", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].type, "FUNC", R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].rva = ret[i].offset = symbol[i].offset;
|
||||
ret[i].size = symbol[i].size;
|
||||
ret[i].ordinal = 0;
|
||||
@ -90,7 +90,7 @@ static struct r_bin_string_t* strings(struct r_bin_t *bin)
|
||||
r_bin_java_get_strings(bin->bin_obj,string);
|
||||
|
||||
for (i = 0; i < strings_count; i++) {
|
||||
strncpy(ret[i].string, string[i].str, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].string, string[i].str, R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].rva = ret[i].offset = string[i].offset;
|
||||
ret[i].size = string[i].size;
|
||||
ret[i].ordinal = string[i].ordinal;
|
||||
@ -115,13 +115,13 @@ static struct r_bin_info_t* info(struct r_bin_t *bin)
|
||||
version[0] = '\0';
|
||||
r_bin_java_get_version(bin->bin_obj, version);
|
||||
|
||||
strncpy(ret->type, "JAVA CLASS", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->class, version, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->rclass, "class", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->os, "any", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->subsystem, "any", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->machine, "Java VM", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->arch, "javavm", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->type, "JAVA CLASS", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret->class, version, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret->rclass, "class", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret->os, "any", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret->subsystem, "any", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret->machine, "Java VM", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret->arch, "javavm", R_BIN_SIZEOF_STRINGS);
|
||||
ret->big_endian= 0;
|
||||
ret->dbg_info = 0x04 | 0x08; /* LineNums | Syms */
|
||||
|
||||
|
@ -61,7 +61,7 @@ static struct r_bin_section_t* sections(struct r_bin_t *bin)
|
||||
PE_(r_bin_pe_get_sections)(bin->bin_obj, section);
|
||||
|
||||
for (i = 0; i < sections_count; i++) {
|
||||
strncpy(ret[i].name, (char*)section[i].name, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].name, (char*)section[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].size = section[i].size;
|
||||
ret[i].vsize = section->vsize;
|
||||
ret[i].offset = section[i].offset;
|
||||
@ -101,10 +101,10 @@ static struct r_bin_symbol_t* symbols(struct r_bin_t *bin)
|
||||
PE_(r_bin_pe_get_exports)(bin->bin_obj, symbol);
|
||||
|
||||
for (i = 0; i < symbols_count; i++) {
|
||||
strncpy(ret[i].name, (char*)symbol[i].name, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].forwarder, (char*)symbol[i].forwarder, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].bind, "NONE", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].type, "NONE", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].name, (char*)symbol[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].forwarder, (char*)symbol[i].forwarder, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].bind, "NONE", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].type, "NONE", R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].rva = symbol[i].rva;
|
||||
ret[i].offset = symbol[i].offset;
|
||||
ret[i].size = 0;
|
||||
@ -136,9 +136,9 @@ static struct r_bin_import_t* imports(struct r_bin_t *bin)
|
||||
PE_(r_bin_pe_get_imports)(bin->bin_obj, import);
|
||||
|
||||
for (i = 0; i < imports_count; i++) {
|
||||
strncpy(ret[i].name, (char*)import[i].name, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].bind, "NONE", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].type, "NONE", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret[i].name, (char*)import[i].name, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].bind, "NONE", R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret[i].type, "NONE", R_BIN_SIZEOF_STRINGS);
|
||||
ret[i].rva = import[i].rva;
|
||||
ret[i].offset = import[i].offset;
|
||||
ret[i].ordinal = import[i].ordinal;
|
||||
@ -161,20 +161,20 @@ static struct r_bin_info_t* info(struct r_bin_t *bin)
|
||||
memset(ret, '\0', sizeof(struct r_bin_info_t));
|
||||
|
||||
if (PE_(r_bin_pe_get_class)(bin->bin_obj, pe_class_str))
|
||||
strncpy(ret->class, pe_class_str, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->rclass, "pe", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->class, pe_class_str, R_BIN_SIZEOF_STRINGS);
|
||||
strncpy(ret->rclass, "pe", R_BIN_SIZEOF_STRINGS);
|
||||
if (PE_(r_bin_pe_get_os)(bin->bin_obj, pe_os_str))
|
||||
strncpy(ret->os, pe_os_str, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->os, pe_os_str, R_BIN_SIZEOF_STRINGS);
|
||||
if (PE_(r_bin_pe_get_arch)(bin->bin_obj, pe_arch_str))
|
||||
strncpy(ret->arch, pe_arch_str, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->arch, pe_arch_str, R_BIN_SIZEOF_STRINGS);
|
||||
if (PE_(r_bin_pe_get_machine)(bin->bin_obj, pe_machine_str))
|
||||
strncpy(ret->machine, pe_machine_str, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->machine, pe_machine_str, R_BIN_SIZEOF_STRINGS);
|
||||
if (PE_(r_bin_pe_get_subsystem)(bin->bin_obj, pe_subsystem_str))
|
||||
strncpy(ret->subsystem, pe_subsystem_str, R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->subsystem, pe_subsystem_str, R_BIN_SIZEOF_STRINGS);
|
||||
if (PE_(r_bin_pe_is_dll)(bin->bin_obj))
|
||||
strncpy(ret->type, "DLL (Dynamic Link Library)", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->type, "DLL (Dynamic Link Library)", R_BIN_SIZEOF_STRINGS);
|
||||
else
|
||||
strncpy(ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_NAMES);
|
||||
strncpy(ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_STRINGS);
|
||||
ret->big_endian = PE_(r_bin_pe_is_big_endian)(bin->bin_obj);
|
||||
|
||||
ret->dbg_info = 0;
|
||||
|
@ -82,9 +82,9 @@ static int rabin_show_entrypoint()
|
||||
|
||||
static int rabin_show_imports()
|
||||
{
|
||||
int ctr = 0;
|
||||
struct r_bin_import_t *imports;
|
||||
u64 baddr;
|
||||
struct r_bin_import_t *imports, *importsp;
|
||||
int i;
|
||||
|
||||
baddr = r_bin_get_baddr(&bin);
|
||||
|
||||
@ -95,21 +95,19 @@ static int rabin_show_imports()
|
||||
printf("fs imports\n");
|
||||
else printf("[Imports]\n");
|
||||
|
||||
importsp = imports;
|
||||
while (!importsp->last) {
|
||||
for (i = 0; !imports[i].last; i++) {
|
||||
if (rad) {
|
||||
r_flag_name_filter(importsp->name);
|
||||
r_flag_name_filter(imports[i].name);
|
||||
printf("f imp.%s @ 0x%08llx\n",
|
||||
importsp->name, baddr+importsp->rva);
|
||||
imports[i].name, baddr+imports[i].rva);
|
||||
} else printf("address=0x%08llx offset=0x%08llx ordinal=%03lli "
|
||||
"hint=%03lli bind=%s type=%s name=%s\n",
|
||||
baddr+importsp->rva, importsp->offset,
|
||||
importsp->ordinal, importsp->hint, importsp->bind,
|
||||
importsp->type, importsp->name);
|
||||
importsp++; ctr++;
|
||||
baddr+imports[i].rva, imports[i].offset,
|
||||
imports[i].ordinal, imports[i].hint, imports[i].bind,
|
||||
imports[i].type, imports[i].name);
|
||||
}
|
||||
|
||||
if (!rad) printf("\n%i imports\n", ctr);
|
||||
if (!rad) printf("\n%i imports\n", i);
|
||||
|
||||
free(imports);
|
||||
|
||||
@ -118,9 +116,9 @@ static int rabin_show_imports()
|
||||
|
||||
static int rabin_show_symbols()
|
||||
{
|
||||
int ctr = 0;
|
||||
struct r_bin_symbol_t *symbols;
|
||||
u64 baddr;
|
||||
struct r_bin_symbol_t *symbols, *symbolsp;
|
||||
int i;
|
||||
|
||||
baddr = r_bin_get_baddr(&bin);
|
||||
|
||||
@ -130,33 +128,31 @@ static int rabin_show_symbols()
|
||||
if (rad) printf("fs symbols\n");
|
||||
else printf("[Symbols]\n");
|
||||
|
||||
symbolsp = symbols;
|
||||
while (!symbolsp->last) {
|
||||
for (i = 0; !symbols[i].last; i++) {
|
||||
if (rad) {
|
||||
r_flag_name_filter(symbolsp->name);
|
||||
if (symbolsp->size) {
|
||||
if (!strncmp(symbolsp->type,"FUNC", 4))
|
||||
r_flag_name_filter(symbols[i].name);
|
||||
if (symbols[i].size) {
|
||||
if (!strncmp(symbols[i].type,"FUNC", 4))
|
||||
printf("CF %lli @ 0x%08llx\n",
|
||||
symbolsp->size, baddr+symbolsp->rva);
|
||||
symbols[i].size, baddr+symbols[i].rva);
|
||||
else
|
||||
if (!strncmp(symbolsp->type,"OBJECT", 6))
|
||||
if (!strncmp(symbols[i].type,"OBJECT", 6))
|
||||
printf("Cd %lli @ 0x%08llx\n",
|
||||
symbolsp->size, baddr+symbolsp->rva);
|
||||
symbols[i].size, baddr+symbols[i].rva);
|
||||
printf("f sym.%s %lli @ 0x%08llx\n",
|
||||
symbolsp->name, symbolsp->size,
|
||||
baddr+symbolsp->rva);
|
||||
symbols[i].name, symbols[i].size,
|
||||
baddr+symbols[i].rva);
|
||||
} else printf("f sym.%s @ 0x%08llx\n",
|
||||
symbolsp->name, baddr+symbolsp->rva);
|
||||
symbols[i].name, baddr+symbols[i].rva);
|
||||
} else printf("address=0x%08llx offset=0x%08llx ordinal=%03lli "
|
||||
"forwarder=%s size=%08lli bind=%s type=%s name=%s\n",
|
||||
baddr+symbolsp->rva, symbolsp->offset,
|
||||
symbolsp->ordinal, symbolsp->forwarder,
|
||||
symbolsp->size, symbolsp->bind, symbolsp->type,
|
||||
symbolsp->name);
|
||||
symbolsp++; ctr++;
|
||||
baddr+symbols[i].rva, symbols[i].offset,
|
||||
symbols[i].ordinal, symbols[i].forwarder,
|
||||
symbols[i].size, symbols[i].bind, symbols[i].type,
|
||||
symbols[i].name);
|
||||
}
|
||||
|
||||
if (!rad) printf("\n%i symbols\n", ctr);
|
||||
if (!rad) printf("\n%i symbols\n", i);
|
||||
|
||||
free(symbols);
|
||||
|
||||
@ -165,9 +161,9 @@ static int rabin_show_symbols()
|
||||
|
||||
static int rabin_show_strings()
|
||||
{
|
||||
int ctr = 0;
|
||||
struct r_bin_string_t *strings;
|
||||
u64 baddr;
|
||||
struct r_bin_string_t *strings, *stringsp;
|
||||
int i;
|
||||
|
||||
baddr = r_bin_get_baddr(&bin);
|
||||
|
||||
@ -178,22 +174,20 @@ static int rabin_show_strings()
|
||||
printf("fs strings\n");
|
||||
else printf("[strings]\n");
|
||||
|
||||
stringsp = strings;
|
||||
while (!stringsp->last) {
|
||||
for (i = 0; !strings[i].last; i++) {
|
||||
if (rad) {
|
||||
r_flag_name_filter(stringsp->string);
|
||||
r_flag_name_filter(strings[i].string);
|
||||
printf( "f str.%s %lli @ 0x%08llx\n"
|
||||
"Cs %lli @ 0x%08llx\n",
|
||||
stringsp->string, stringsp->size, baddr+stringsp->rva,
|
||||
stringsp->size, baddr+stringsp->rva);
|
||||
strings[i].string, strings[i].size, baddr+strings[i].rva,
|
||||
strings[i].size, baddr+strings[i].rva);
|
||||
} else printf("address=0x%08llx offset=0x%08llx ordinal=%03lli "
|
||||
"size=%08lli string=%s\n",
|
||||
baddr+stringsp->rva, stringsp->offset,
|
||||
stringsp->ordinal, stringsp->size, stringsp->string);
|
||||
stringsp++; ctr++;
|
||||
baddr+strings[i].rva, strings[i].offset,
|
||||
strings[i].ordinal, strings[i].size, strings[i].string);
|
||||
}
|
||||
|
||||
if (!rad) printf("\n%i strings\n", ctr);
|
||||
if (!rad) printf("\n%i strings\n", i);
|
||||
|
||||
free(strings);
|
||||
|
||||
@ -202,9 +196,9 @@ static int rabin_show_strings()
|
||||
|
||||
static int rabin_show_sections()
|
||||
{
|
||||
int ctr = 0;
|
||||
struct r_bin_section_t *sections;
|
||||
u64 baddr;
|
||||
struct r_bin_section_t *sections, *sectionsp;
|
||||
int i;
|
||||
|
||||
baddr = r_bin_get_baddr(&bin);
|
||||
|
||||
@ -214,34 +208,32 @@ static int rabin_show_sections()
|
||||
if (rad) printf("fs sections\n");
|
||||
else printf("[Sections]\n");
|
||||
|
||||
sectionsp = sections;
|
||||
while (!sectionsp->last) {
|
||||
for (i = 0; !sections[i].last; i++) {
|
||||
if (rad) {
|
||||
r_flag_name_filter(sectionsp->name);
|
||||
r_flag_name_filter(sections[i].name);
|
||||
printf("f section.%s @ 0x%08llx\n",
|
||||
sectionsp->name, baddr+sectionsp->rva);
|
||||
sections[i].name, baddr+sections[i].rva);
|
||||
printf("f section.%s_end @ 0x%08llx\n",
|
||||
sectionsp->name, baddr+sectionsp->rva+sectionsp->size);
|
||||
sections[i].name, baddr+sections[i].rva+sections[i].size);
|
||||
printf("[%02i] address=0x%08llx offset=0x%08llx size=%08lli "
|
||||
"privileges=%c%c%c%c name=%s\n",
|
||||
ctr, baddr+sectionsp->rva, sectionsp->offset, sectionsp->size,
|
||||
R_BIN_SCN_SHAREABLE(sectionsp->characteristics)?'s':'-',
|
||||
R_BIN_SCN_READABLE(sectionsp->characteristics)?'r':'-',
|
||||
R_BIN_SCN_WRITABLE(sectionsp->characteristics)?'w':'-',
|
||||
R_BIN_SCN_EXECUTABLE(sectionsp->characteristics)?'x':'-',
|
||||
sectionsp->name);
|
||||
i, baddr+sections[i].rva, sections[i].offset, sections[i].size,
|
||||
R_BIN_SCN_SHAREABLE(sections[i].characteristics)?'s':'-',
|
||||
R_BIN_SCN_READABLE(sections[i].characteristics)?'r':'-',
|
||||
R_BIN_SCN_WRITABLE(sections[i].characteristics)?'w':'-',
|
||||
R_BIN_SCN_EXECUTABLE(sections[i].characteristics)?'x':'-',
|
||||
sections[i].name);
|
||||
} else printf("idx=%02i address=0x%08llx offset=0x%08llx size=%08lli "
|
||||
"privileges=%c%c%c%c name=%s\n",
|
||||
ctr, baddr+sectionsp->rva, sectionsp->offset, sectionsp->size,
|
||||
R_BIN_SCN_SHAREABLE(sectionsp->characteristics)?'s':'-',
|
||||
R_BIN_SCN_READABLE(sectionsp->characteristics)?'r':'-',
|
||||
R_BIN_SCN_WRITABLE(sectionsp->characteristics)?'w':'-',
|
||||
R_BIN_SCN_EXECUTABLE(sectionsp->characteristics)?'x':'-',
|
||||
sectionsp->name);
|
||||
sectionsp++; ctr++;
|
||||
i, baddr+sections[i].rva, sections[i].offset, sections[i].size,
|
||||
R_BIN_SCN_SHAREABLE(sections[i].characteristics)?'s':'-',
|
||||
R_BIN_SCN_READABLE(sections[i].characteristics)?'r':'-',
|
||||
R_BIN_SCN_WRITABLE(sections[i].characteristics)?'w':'-',
|
||||
R_BIN_SCN_EXECUTABLE(sections[i].characteristics)?'x':'-',
|
||||
sections[i].name);
|
||||
}
|
||||
|
||||
if (!rad) printf("\n%i sections\n", ctr);
|
||||
if (!rad) printf("\n%i sections\n", i);
|
||||
|
||||
free(sections);
|
||||
|
||||
@ -292,9 +284,9 @@ static int rabin_show_info()
|
||||
|
||||
static int rabin_show_fields()
|
||||
{
|
||||
int ctr = 0;
|
||||
struct r_bin_field_t *fields;
|
||||
u64 baddr;
|
||||
struct r_bin_field_t *fields, *fieldsp;
|
||||
int i;
|
||||
|
||||
baddr = r_bin_get_baddr(&bin);
|
||||
|
||||
@ -304,20 +296,18 @@ static int rabin_show_fields()
|
||||
if (rad) printf("fs header\n");
|
||||
else printf("[Header fields]\n");
|
||||
|
||||
fieldsp = fields;
|
||||
while (!fieldsp->last) {
|
||||
for (i = 0; !fields[i].last; i++) {
|
||||
if (rad) {
|
||||
r_flag_name_filter(fieldsp->name);
|
||||
r_flag_name_filter(fields[i].name);
|
||||
printf("f header.%s @ 0x%08llx\n",
|
||||
fieldsp->name, baddr+fieldsp->rva);
|
||||
fields[i].name, baddr+fields[i].rva);
|
||||
printf("[%02i] address=0x%08llx offset=0x%08llx name=%s\n",
|
||||
ctr, baddr+fieldsp->rva, fieldsp->offset, fieldsp->name);
|
||||
i, baddr+fields[i].rva, fields[i].offset, fields[i].name);
|
||||
} else printf("idx=%02i address=0x%08llx offset=0x%08llx name=%s\n",
|
||||
ctr, baddr+fieldsp->rva, fieldsp->offset, fieldsp->name);
|
||||
fieldsp++; ctr++;
|
||||
i, baddr+fields[i].rva, fields[i].offset, fields[i].name);
|
||||
}
|
||||
|
||||
if (!rad) printf("\n%i fields\n", ctr);
|
||||
if (!rad) printf("\n%i fields\n", i);
|
||||
|
||||
free(fields);
|
||||
|
||||
@ -327,33 +317,30 @@ static int rabin_show_fields()
|
||||
|
||||
static int rabin_dump_symbols(int len)
|
||||
{
|
||||
struct r_bin_symbol_t *symbols, *symbolsp;
|
||||
int olen = len;
|
||||
struct r_bin_symbol_t *symbols;
|
||||
u8 *buf;
|
||||
char *ret;
|
||||
int olen = len, i;
|
||||
|
||||
if ((symbols = r_bin_get_symbols(&bin)) == NULL)
|
||||
return R_FALSE;
|
||||
|
||||
symbolsp = symbols;
|
||||
while (!symbolsp->last) {
|
||||
if (symbolsp->size != 0 && (olen > symbolsp->size || olen == 0))
|
||||
len = symbolsp->size;
|
||||
else if (symbolsp->size == 0 && olen == 0)
|
||||
for (i = 0; !symbols[i].last; i++) {
|
||||
if (symbols[i].size != 0 && (olen > symbols[i].size || olen == 0))
|
||||
len = symbols[i].size;
|
||||
else if (symbols[i].size == 0 && olen == 0)
|
||||
len = 32;
|
||||
else len = olen;
|
||||
|
||||
if (!(buf = malloc(len)) ||
|
||||
!(ret = malloc(len*2+1)))
|
||||
return R_FALSE;
|
||||
lseek(bin.fd, symbolsp->offset, SEEK_SET);
|
||||
lseek(bin.fd, symbols[i].offset, SEEK_SET);
|
||||
read(bin.fd, buf, len);
|
||||
r_hex_bin2str(buf, len, ret);
|
||||
printf("%s %s\n", symbolsp->name, ret);
|
||||
printf("%s %s\n", symbols[i].name, ret);
|
||||
free(buf);
|
||||
free(ret);
|
||||
|
||||
symbolsp++;
|
||||
}
|
||||
|
||||
free(symbols);
|
||||
@ -363,29 +350,27 @@ static int rabin_dump_symbols(int len)
|
||||
|
||||
static int rabin_dump_sections(char *name)
|
||||
{
|
||||
struct r_bin_section_t *sections, *sectionsp;
|
||||
struct r_bin_section_t *sections;
|
||||
u8 *buf;
|
||||
char *ret;
|
||||
int i;
|
||||
|
||||
if ((sections = r_bin_get_sections(&bin)) == NULL)
|
||||
return R_FALSE;
|
||||
|
||||
sectionsp = sections;
|
||||
while (!sectionsp->last) {
|
||||
if (!strcmp(name, sectionsp->name)) {
|
||||
if (!(buf = malloc(sectionsp->size)) ||
|
||||
!(ret = malloc(sectionsp->size*2+1)))
|
||||
for (i = 0; !sections[i].last; i++)
|
||||
if (!strcmp(name, sections[i].name)) {
|
||||
if (!(buf = malloc(sections[i].size)) ||
|
||||
!(ret = malloc(sections[i].size*2+1)))
|
||||
return R_FALSE;
|
||||
lseek(bin.fd, sectionsp->offset, SEEK_SET);
|
||||
read(bin.fd, buf, sectionsp->size);
|
||||
r_hex_bin2str(buf, sectionsp->size, ret);
|
||||
lseek(bin.fd, sections[i].offset, SEEK_SET);
|
||||
read(bin.fd, buf, sections[i].size);
|
||||
r_hex_bin2str(buf, sections[i].size, ret);
|
||||
printf("%s\n", ret);
|
||||
free(buf);
|
||||
free(ret);
|
||||
break;
|
||||
}
|
||||
sectionsp++;
|
||||
}
|
||||
|
||||
free(sections);
|
||||
|
||||
@ -399,8 +384,8 @@ static int rabin_do_operation(const char *op)
|
||||
if (!strcmp(op, "help")) {
|
||||
printf( "Operation string:\n"
|
||||
" Dump symbols: d/s/1024\n"
|
||||
" Dump section: d/S/.text\n"
|
||||
" Resize section: r/.data/1024\n");
|
||||
" Dump section: d/S/.text\n");
|
||||
//" Resize section: r/.data/1024\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
arg = alloca(strlen(op)+1);
|
||||
@ -416,6 +401,8 @@ static int rabin_do_operation(const char *op)
|
||||
}
|
||||
|
||||
switch(arg[0]) {
|
||||
/*XXX*/
|
||||
#if 0
|
||||
case 'r':
|
||||
if (!rw) {
|
||||
printf("File must be opened in rw mode\n");
|
||||
@ -428,6 +415,7 @@ static int rabin_do_operation(const char *op)
|
||||
return R_FALSE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case 'd':
|
||||
if (!ptr)
|
||||
goto _rabin_do_operation_error;
|
||||
|
@ -17,7 +17,7 @@
|
||||
#define R_BIN_DBG_SYMS(x) x & 0x08
|
||||
#define R_BIN_DBG_RELOCS(x) x & 0x10
|
||||
|
||||
#define R_BIN_SIZEOF_NAMES 256
|
||||
#define R_BIN_SIZEOF_STRINGS 256
|
||||
|
||||
/* types */
|
||||
struct r_bin_t {
|
||||
@ -56,7 +56,7 @@ struct r_bin_entry_t {
|
||||
};
|
||||
|
||||
struct r_bin_section_t {
|
||||
char name[R_BIN_SIZEOF_NAMES];
|
||||
char name[R_BIN_SIZEOF_STRINGS];
|
||||
u64 size;
|
||||
u64 vsize;
|
||||
u64 rva;
|
||||
@ -66,10 +66,10 @@ struct r_bin_section_t {
|
||||
};
|
||||
|
||||
struct r_bin_symbol_t {
|
||||
char name[R_BIN_SIZEOF_NAMES];
|
||||
char forwarder[R_BIN_SIZEOF_NAMES];
|
||||
char bind[R_BIN_SIZEOF_NAMES];
|
||||
char type[R_BIN_SIZEOF_NAMES];
|
||||
char name[R_BIN_SIZEOF_STRINGS];
|
||||
char forwarder[R_BIN_SIZEOF_STRINGS];
|
||||
char bind[R_BIN_SIZEOF_STRINGS];
|
||||
char type[R_BIN_SIZEOF_STRINGS];
|
||||
u64 rva;
|
||||
u64 offset;
|
||||
u64 size;
|
||||
@ -78,9 +78,9 @@ struct r_bin_symbol_t {
|
||||
};
|
||||
|
||||
struct r_bin_import_t {
|
||||
char name[R_BIN_SIZEOF_NAMES];
|
||||
char bind[R_BIN_SIZEOF_NAMES];
|
||||
char type[R_BIN_SIZEOF_NAMES];
|
||||
char name[R_BIN_SIZEOF_STRINGS];
|
||||
char bind[R_BIN_SIZEOF_STRINGS];
|
||||
char type[R_BIN_SIZEOF_STRINGS];
|
||||
u64 rva;
|
||||
u64 offset;
|
||||
u64 ordinal;
|
||||
@ -89,7 +89,7 @@ struct r_bin_import_t {
|
||||
};
|
||||
|
||||
struct r_bin_string_t {
|
||||
char string[R_BIN_SIZEOF_NAMES];
|
||||
char string[R_BIN_SIZEOF_STRINGS];
|
||||
u64 rva;
|
||||
u64 offset;
|
||||
u64 ordinal;
|
||||
@ -98,19 +98,19 @@ struct r_bin_string_t {
|
||||
};
|
||||
|
||||
struct r_bin_info_t {
|
||||
char type[R_BIN_SIZEOF_NAMES];
|
||||
char class[R_BIN_SIZEOF_NAMES];
|
||||
char rclass[R_BIN_SIZEOF_NAMES];
|
||||
char arch[R_BIN_SIZEOF_NAMES];
|
||||
char machine[R_BIN_SIZEOF_NAMES];
|
||||
char os[R_BIN_SIZEOF_NAMES];
|
||||
char subsystem[R_BIN_SIZEOF_NAMES];
|
||||
char type[R_BIN_SIZEOF_STRINGS];
|
||||
char class[R_BIN_SIZEOF_STRINGS];
|
||||
char rclass[R_BIN_SIZEOF_STRINGS];
|
||||
char arch[R_BIN_SIZEOF_STRINGS];
|
||||
char machine[R_BIN_SIZEOF_STRINGS];
|
||||
char os[R_BIN_SIZEOF_STRINGS];
|
||||
char subsystem[R_BIN_SIZEOF_STRINGS];
|
||||
int big_endian;
|
||||
u64 dbg_info;
|
||||
};
|
||||
|
||||
struct r_bin_field_t {
|
||||
char name[R_BIN_SIZEOF_NAMES];
|
||||
char name[R_BIN_SIZEOF_STRINGS];
|
||||
u64 rva;
|
||||
u64 offset;
|
||||
int last;
|
||||
@ -133,7 +133,7 @@ struct r_bin_import_t* r_bin_get_imports(struct r_bin_t *bin);
|
||||
struct r_bin_string_t* r_bin_get_strings(struct r_bin_t *bin);
|
||||
struct r_bin_info_t* r_bin_get_info(struct r_bin_t *bin);
|
||||
struct r_bin_field_t* r_bin_get_fields(struct r_bin_t *bin);
|
||||
u64 r_bin_resize_section(struct r_bin_t *bin, char *name, u64 size);
|
||||
/*XXX u64 r_bin_resize_section(struct r_bin_t *bin, char *name, u64 size); */
|
||||
u64 r_bin_get_section_offset(struct r_bin_t *bin, char *name);
|
||||
u64 r_bin_get_section_rva(struct r_bin_t *bin, char *name);
|
||||
u64 r_bin_get_section_size(struct r_bin_t *bin, char *name);
|
||||
|
@ -86,6 +86,7 @@ R_API int r_str_cmp(const char *dst, const char *orig, int len);
|
||||
R_API int r_str_ccpy(char *dst, char *orig, int ch);
|
||||
R_API const char *r_str_get(const char *str);
|
||||
R_API char *r_str_dup(char *ptr, const char *string);
|
||||
R_API char *r_str_dup_printf(const char *fmt, ...);
|
||||
R_API void *r_str_free(void *ptr);
|
||||
R_API int r_str_inject(char *begin, char *end, char *str, int maxlen);
|
||||
R_API int r_str_delta(char *p, char a, char b);
|
||||
|
@ -23,6 +23,7 @@ int r_mem_cmp_mask(const u8 *dest, const u8 *orig, const u8 *mask, int len)
|
||||
void r_mem_copyendian (u8 *dest, const u8 *orig, int size, int endian)
|
||||
{
|
||||
if (endian) {
|
||||
if (dest != orig)
|
||||
memcpy(dest, orig, size);
|
||||
} else {
|
||||
unsigned char buffer[8];
|
||||
|
@ -245,6 +245,18 @@ char *r_str_dup(char *ptr, const char *string)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char *r_str_dup_printf(const char *fmt, ...)
|
||||
{
|
||||
char *ret;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if ((ret = malloc(1024)) == NULL)
|
||||
return NULL;
|
||||
vsnprintf(ret, 1023, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *r_str_concat(char *ptr, const char *string)
|
||||
{
|
||||
if (!ptr)
|
||||
|
Loading…
Reference in New Issue
Block a user