- Major refactoring (using r_lib infrastructure)
  - Removed outdated test programs
  - Updated rabin2

--HG--
rename : libr/bin/elf.c => libr/bin/p/elf/elf.c
rename : libr/include/r_bin_elf.h => libr/bin/p/elf/elf.h
rename : libr/bin/elf64.c => libr/bin/p/elf/elf64.c
rename : libr/include/r_bin_elf64.h => libr/bin/p/elf/elf64.h
rename : libr/include/r_bin_elf_specs.h => libr/bin/p/elf/elf_specs.h
rename : libr/bin/mach0.c => libr/bin/p/mach0/mach0.c
rename : libr/include/r_bin_mach0.h => libr/bin/p/mach0/mach0.h
rename : libr/bin/pe.c => libr/bin/p/pe/pe.c
rename : libr/include/r_bin_pe.h => libr/bin/p/pe/pe.h
rename : libr/include/r_bin_pe_specs.h => libr/bin/p/pe/pe_specs.h
This commit is contained in:
Nibble 2009-03-08 16:49:15 +01:00
parent 73343076a8
commit 04c9a3f5d1
28 changed files with 934 additions and 844 deletions

View file

@ -1,6 +1,5 @@
NAME=r_bin
OBJ=bin.o elf.o elf64.o pe.o
# XXX
CFLAGS+=-DLIL_ENDIAN=1 -D__UNIX__ -Wall -g
DEPS=r_lib r_util
OBJ=bin.o
include ../rules.mk

View file

@ -15,441 +15,175 @@
#include <unistd.h>
#include <sys/stat.h>
#include "r_types.h"
#include "r_bin.h"
#include <r_types.h>
#include <r_lib.h>
#include <r_bin.h>
#define ELF_CALL(func, bin, args...)\
bin->format==R_BIN_FMT_ELF64?\
Elf64_##func(&bin->object.elf.e64,##args):\
Elf32_##func(&bin->object.elf.e32,##args)
enum {
R_BIN_FMT_ELF32,
R_BIN_FMT_ELF64,
R_BIN_FMT_PE
};
static int r_bin_identify(r_bin_obj *bin)
struct r_bin_t *r_bin_new(char *file, int rw)
{
int fd;
unsigned char buf[1024];
if ((fd = open(bin->file, 0)) == -1) {
return -1;
}
lseek(fd, 0, SEEK_SET);
read(fd, buf, 1024);
close(fd);
if (!memcmp(buf, "\x7F\x45\x4c\x46", 4)) {
if (buf[EI_CLASS] == ELFCLASS64)
bin->format = R_BIN_FMT_ELF64;
else bin->format = R_BIN_FMT_ELF32;
return 0;
} else if (!memcmp(buf, "\x4d\x5a", 2)) {
bin->format = R_BIN_FMT_PE;
return 0;
}
return -1;
}
r_bin_obj *r_bin_new(char *file, int rw)
{
r_bin_obj *bin = MALLOC_STRUCT(r_bin_obj);
struct r_bin_t *bin = MALLOC_STRUCT(struct r_bin_t);
r_bin_init(bin, file, rw);
return bin;
}
void r_bin_free(r_bin_obj *bin)
void r_bin_free(struct r_bin_t *bin)
{
free(bin);
}
int r_bin_init(r_bin_obj *bin, const char *file, int rw)
int r_bin_init(struct r_bin_t *bin, const char *file, int rw)
{
int fd;
bin->user = NULL;
INIT_LIST_HEAD(&bin->bins);
bin->file = file;
bin->rw = rw;
if (r_bin_identify(bin) == -1)
return R_TRUE;
}
void r_bin_set_user_ptr(struct r_bin_t *bin, void *user)
{
bin->user = user;
}
int r_bin_add(struct r_bin_t *bin, struct r_bin_handle_t *foo)
{
if (foo->init)
foo->init(bin->user);
list_add_tail(&(foo->list), &(bin->bins));
return R_TRUE;
}
int r_bin_list(struct r_bin_t *bin)
{
struct list_head *pos;
list_for_each_prev(pos, &bin->bins) {
struct r_bin_handle_t *h = list_entry(pos, struct r_bin_handle_t, list);
printf(" %s: %s\n", h->name, h->desc);
}
return R_FALSE;
}
int r_bin_set(struct r_bin_t *bin, const char *name)
{
struct list_head *pos;
list_for_each_prev(pos, &bin->bins) {
struct r_bin_handle_t *h = list_entry(pos, struct r_bin_handle_t, list);
if (!strcmp(h->name, name)) {
bin->cur = h;
return R_TRUE;
}
}
return R_FALSE;
}
/*XXX*/
int r_bin_autoset(struct r_bin_t *bin)
{
unsigned char buf[1024];
if ((bin->fd = open(bin->file, 0)) == -1) {
return -1;
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
if ((fd = ELF_CALL(r_bin_elf_open,bin,file,rw)) != -1) {
bin->fd = fd;
return fd;
}
break;
case R_BIN_FMT_PE:
if ((fd = r_bin_pe_open(&bin->object.pe, file)) != -1) {
bin->fd = fd;
return fd;
}
break;
}
return -1;
lseek(bin->fd, 0, SEEK_SET);
read(bin->fd, buf, 1024);
close(bin->fd);
if (!memcmp(buf, "\x7F\x45\x4c\x46", 4)) {
if (buf[4] == 2) /* buf[EI_CLASS] == ELFCLASS64 */
r_bin_set(bin, "bin_elf64");
else r_bin_set(bin, "bin_elf");
return R_TRUE;
} else if (!memcmp(buf, "\x4d\x5a", 2)) {
r_bin_set(bin, "bin_pe");
return R_TRUE;
}
return R_FALSE;
}
int r_bin_close(r_bin_obj *bin)
int r_bin_open(struct r_bin_t *bin)
{
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
return ELF_CALL(r_bin_elf_close, bin);
case R_BIN_FMT_PE:
return r_bin_pe_close(&bin->object.pe);
}
return -1;
if (bin->cur && bin->cur->open)
return bin->cur->open(bin);
return R_FALSE;
}
u64 r_bin_get_baddr(r_bin_obj *bin)
int r_bin_close(struct r_bin_t *bin)
{
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
return ELF_CALL(r_bin_elf_get_base_addr, bin);
case R_BIN_FMT_PE:
return r_bin_pe_get_image_base(&bin->object.pe);
}
return -1;
if (bin->cur && bin->cur->close)
return bin->cur->close(bin);
return R_FALSE;
}
r_bin_entry* r_bin_get_entry(r_bin_obj *bin)
u64 r_bin_get_baddr(struct r_bin_t *bin)
{
r_bin_entry *ret;
r_bin_pe_entrypoint entry;
if((ret = malloc(sizeof(r_bin_entry))) == NULL)
return NULL;
memset(ret, '\0', sizeof(r_bin_entry));
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
ret->offset = ret->rva = ELF_CALL(r_bin_elf_get_entry_offset, bin);
return ret;
case R_BIN_FMT_PE:
r_bin_pe_get_entrypoint(&bin->object.pe, &entry);
ret->offset = entry.offset;
ret->rva = entry.rva;
return ret;
}
if (bin->cur && bin->cur->baddr)
return bin->cur->baddr(bin);
return R_FALSE;
}
struct r_bin_entry_t* r_bin_get_entry(struct r_bin_t *bin)
{
if (bin->cur && bin->cur->entry)
return bin->cur->entry(bin);
return NULL;
}
r_bin_section* r_bin_get_sections(r_bin_obj *bin)
struct r_bin_section_t* r_bin_get_sections(struct r_bin_t *bin)
{
int sections_count, i;
r_bin_section *ret, *retp;
union {
r_bin_elf_section* elf;
r_bin_pe_section* pe;
} section, sectionp;
ret = retp = NULL;
section.elf = sectionp.elf = NULL;
section.pe = section.pe = NULL;
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
sections_count = ELF_CALL(r_bin_elf_get_sections_count,bin);
if((section.elf = malloc(sections_count * sizeof(r_bin_elf_section))) == NULL)
return NULL;
if((ret = malloc((sections_count + 1) * sizeof(r_bin_section))) == NULL)
return NULL;
memset(ret, '\0', (sections_count + 1) * sizeof(r_bin_section));
ELF_CALL(r_bin_elf_get_sections,bin,section.elf);
retp = ret;
sectionp.elf = section.elf;
for (i = 0; i < sections_count; i++, sectionp.elf++, retp++) {
strncpy(retp->name, (char*)sectionp.elf->name, R_BIN_SIZEOF_NAMES);
retp->size = sectionp.elf->size;
retp->vsize = sectionp.elf->size;
retp->offset = sectionp.elf->offset;
retp->rva = sectionp.elf->offset;
retp->characteristics = 0;
if (R_BIN_ELF_SCN_IS_EXECUTABLE(sectionp.elf->flags))
retp->characteristics |= 0x1;
if (R_BIN_ELF_SCN_IS_WRITABLE(sectionp.elf->flags))
retp->characteristics |= 0x2;
if (R_BIN_ELF_SCN_IS_READABLE(sectionp.elf->flags))
retp->characteristics |= 0x4;
retp->last = 0;
}
retp->last = 1;
free(section.elf);
return ret;
case R_BIN_FMT_PE:
sections_count = r_bin_pe_get_sections_count(&bin->object.pe);
if ((section.pe = malloc(sections_count * sizeof(r_bin_pe_section))) == NULL)
return NULL;
if ((ret = malloc((sections_count + 1) * sizeof(r_bin_section))) == NULL)
return NULL;
memset(ret, '\0', (sections_count + 1) * sizeof(r_bin_section));
r_bin_pe_get_sections(&bin->object.pe, section.pe);
retp = ret;
sectionp.pe = section.pe;
for (i = 0; i < sections_count; i++, sectionp.pe++, retp++) {
strncpy(retp->name, (char*)sectionp.pe->name, R_BIN_SIZEOF_NAMES);
retp->size = sectionp.pe->size;
retp->vsize = section.pe->vsize;
retp->offset = sectionp.pe->offset;
retp->rva = sectionp.pe->rva;
retp->characteristics = 0;
if (R_BIN_PE_SCN_IS_EXECUTABLE(sectionp.pe->characteristics))
retp->characteristics |= 0x1;
if (R_BIN_PE_SCN_IS_WRITABLE(sectionp.pe->characteristics))
retp->characteristics |= 0x2;
if (R_BIN_PE_SCN_IS_READABLE(sectionp.pe->characteristics))
retp->characteristics |= 0x4;
if (R_BIN_PE_SCN_IS_SHAREABLE(sectionp.pe->characteristics))
retp->characteristics |= 0x8;
retp->last = 0;
}
retp->last = 1;
free(section.pe);
return ret;
}
if (bin->cur && bin->cur->sections)
return bin->cur->sections(bin);
return NULL;
}
r_bin_symbol* r_bin_get_symbols(r_bin_obj *bin)
struct r_bin_symbol_t* r_bin_get_symbols(struct r_bin_t *bin)
{
int symbols_count, i;
r_bin_symbol *ret, *retp;
union {
r_bin_elf_symbol* elf;
r_bin_pe_export* pe;
} symbol, symbolp;
ret = retp = NULL;
symbol.elf = symbolp.elf = NULL;
symbol.pe = symbolp.pe = NULL;
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
symbols_count = ELF_CALL(r_bin_elf_get_symbols_count,bin);
if ((symbol.elf = malloc(symbols_count * sizeof(r_bin_elf_symbol))) == NULL)
return NULL;
if ((ret = malloc((symbols_count + 1) * sizeof(r_bin_symbol))) == NULL)
return NULL;
memset(ret, '\0', (symbols_count + 1) * sizeof(r_bin_symbol));
ELF_CALL(r_bin_elf_get_symbols,bin,symbol.elf);
retp = ret;
symbolp.elf = symbol.elf;
for (i = 0; i < symbols_count; i++, symbolp.elf++, retp++) {
strncpy(retp->name, symbolp.elf->name, R_BIN_SIZEOF_NAMES);
strncpy(retp->forwarder, "NONE", R_BIN_SIZEOF_NAMES);
strncpy(retp->bind, symbolp.elf->bind, R_BIN_SIZEOF_NAMES);
strncpy(retp->type, symbolp.elf->type, R_BIN_SIZEOF_NAMES);
retp->rva = symbolp.elf->offset;
retp->offset = symbolp.elf->offset;
retp->size = symbolp.elf->size;
retp->ordinal = 0;
retp->last = 0;
}
retp->last = 1;
free(symbol.elf);
return ret;
case R_BIN_FMT_PE:
symbols_count = r_bin_pe_get_exports_count(&bin->object.pe);
if ((symbol.pe = malloc(symbols_count * sizeof(r_bin_pe_export))) == NULL)
return NULL;
if ((ret = malloc((symbols_count + 1) * sizeof(r_bin_symbol))) == NULL)
return NULL;
memset(ret, '\0', (symbols_count + 1) * sizeof(r_bin_symbol));
r_bin_pe_get_exports(&bin->object.pe, symbol.pe);
retp = ret;
symbolp.pe = symbol.pe;
for (i = 0; i < symbols_count; i++, symbolp.pe++, retp++) {
strncpy(retp->name, (char*)symbolp.pe->name, R_BIN_SIZEOF_NAMES);
strncpy(retp->forwarder, (char*)symbolp.pe->forwarder, R_BIN_SIZEOF_NAMES);
strncpy(retp->bind, "NONE", R_BIN_SIZEOF_NAMES);
strncpy(retp->type, "NONE", R_BIN_SIZEOF_NAMES);
retp->rva = symbolp.pe->rva;
retp->offset = symbolp.pe->offset;
retp->size = 0;
retp->ordinal = symbolp.pe->ordinal;
retp->last = 0;
}
retp->last = 1;
free(symbol.pe);
return ret;
}
if (bin->cur && bin->cur->symbols)
return bin->cur->symbols(bin);
return NULL;
}
r_bin_import* r_bin_get_imports(r_bin_obj *bin)
struct r_bin_import_t* r_bin_get_imports(struct r_bin_t *bin)
{
int imports_count, i;
r_bin_import *ret, *retp;
union {
r_bin_elf_import* elf;
r_bin_pe_import* pe;
} import, importp;
ret = retp = NULL;
import.elf = importp.elf = NULL;
import.pe = importp.pe = NULL;
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
imports_count = ELF_CALL(r_bin_elf_get_imports_count,bin);
if ((import.elf = malloc(imports_count * sizeof(r_bin_elf_import))) == NULL)
return NULL;
if ((ret = malloc((imports_count + 1) * sizeof(r_bin_import))) == NULL)
return NULL;
memset(ret, '\0', (imports_count + 1) * sizeof(r_bin_import));
ELF_CALL(r_bin_elf_get_imports,bin,import.elf);
retp = ret;
importp.elf = import.elf;
for (i = 0; i < imports_count; i++, importp.elf++, retp++) {
strncpy(retp->name, importp.elf->name, R_BIN_SIZEOF_NAMES);
strncpy(retp->bind, importp.elf->bind, R_BIN_SIZEOF_NAMES);
strncpy(retp->type, importp.elf->type, R_BIN_SIZEOF_NAMES);
retp->rva = importp.elf->offset;
retp->offset = importp.elf->offset;
retp->ordinal = 0;
retp->hint = 0;
retp->last = 0;
}
retp->last = 1;
free(import.elf);
return ret;
case R_BIN_FMT_PE:
imports_count = r_bin_pe_get_imports_count(&bin->object.pe);
if ((import.pe = malloc(imports_count * sizeof(r_bin_pe_import))) == NULL)
return NULL;
if ((ret = malloc((imports_count + 1) * sizeof(r_bin_import))) == NULL)
return NULL;
memset(ret, '\0', (imports_count + 1) * sizeof(r_bin_import));
r_bin_pe_get_imports(&bin->object.pe, import.pe);
retp = ret;
importp.pe = import.pe;
for (i = 0; i < imports_count; i++, importp.pe++, retp++) {
strncpy(retp->name, (char*)importp.pe->name, R_BIN_SIZEOF_NAMES);
strncpy(retp->bind, "NONE", R_BIN_SIZEOF_NAMES);
strncpy(retp->type, "NONE", R_BIN_SIZEOF_NAMES);
retp->rva = importp.pe->rva;
retp->offset = importp.pe->offset;
retp->ordinal = importp.pe->ordinal;
retp->hint = importp.pe->hint;
retp->last = 0;
}
retp->last = 1;
free(import.pe);
return ret;
}
if (bin->cur && bin->cur->imports)
return bin->cur->imports(bin);
return NULL;
}
r_bin_info* r_bin_get_info(r_bin_obj *bin)
struct r_bin_info_t* r_bin_get_info(struct r_bin_t *bin)
{
char pe_class_str[PE_NAME_LENGTH], pe_os_str[PE_NAME_LENGTH], pe_machine_str[PE_NAME_LENGTH];
char pe_arch_str[PE_NAME_LENGTH], pe_subsystem_str[PE_NAME_LENGTH];
r_bin_info *ret = NULL;
if((ret = malloc(sizeof(r_bin_info))) == NULL)
return NULL;
memset(ret, '\0', sizeof(r_bin_info));
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
strncpy(ret->type, ELF_CALL(r_bin_elf_get_file_type,bin), R_BIN_SIZEOF_NAMES);
strncpy(ret->class, ELF_CALL(r_bin_elf_get_elf_class,bin), R_BIN_SIZEOF_NAMES);
strncpy(ret->rclass, "elf", R_BIN_SIZEOF_NAMES);
strncpy(ret->os, ELF_CALL(r_bin_elf_get_osabi_name,bin), R_BIN_SIZEOF_NAMES);
strncpy(ret->subsystem, ELF_CALL(r_bin_elf_get_osabi_name,bin), R_BIN_SIZEOF_NAMES);
strncpy(ret->machine, ELF_CALL(r_bin_elf_get_machine_name,bin), R_BIN_SIZEOF_NAMES);
strncpy(ret->arch, ELF_CALL(r_bin_elf_get_arch,bin), R_BIN_SIZEOF_NAMES);
ret->big_endian=ELF_CALL(r_bin_elf_is_big_endian,bin);
ret->dbg_info = 0;
if (ELF_CALL(r_bin_elf_get_stripped,bin)) {
ret->dbg_info |= 0x01;
} else {
ret->dbg_info |= 0x04;
ret->dbg_info |= 0x08;
ret->dbg_info |= 0x10;
}
if (ELF_CALL(r_bin_elf_get_static,bin))
ret->dbg_info |= 0x02;
return ret;
case R_BIN_FMT_PE:
if (r_bin_pe_get_class(&bin->object.pe, pe_class_str))
strncpy(ret->class, pe_class_str, R_BIN_SIZEOF_NAMES);
strncpy(ret->rclass, "pe", R_BIN_SIZEOF_NAMES);
if (r_bin_pe_get_os(&bin->object.pe, pe_os_str))
strncpy(ret->os, pe_os_str, R_BIN_SIZEOF_NAMES);
if (r_bin_pe_get_arch(&bin->object.pe, pe_arch_str))
strncpy(ret->arch, pe_arch_str, R_BIN_SIZEOF_NAMES);
if (r_bin_pe_get_machine(&bin->object.pe, pe_machine_str))
strncpy(ret->machine, pe_machine_str, R_BIN_SIZEOF_NAMES);
if (r_bin_pe_get_subsystem(&bin->object.pe, pe_subsystem_str))
strncpy(ret->subsystem, pe_subsystem_str, R_BIN_SIZEOF_NAMES);
if (r_bin_pe_is_dll(&bin->object.pe))
strncpy(ret->type, "DLL (Dynamic Link Library)", R_BIN_SIZEOF_NAMES);
else
strncpy(ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_NAMES);
ret->big_endian = r_bin_pe_is_big_endian(&bin->object.pe);
ret->dbg_info = 0;
if (!r_bin_pe_is_stripped_debug(&bin->object.pe))
ret->dbg_info |= 0x01;
if (r_bin_pe_is_stripped_line_nums(&bin->object.pe))
ret->dbg_info |= 0x04;
if (r_bin_pe_is_stripped_local_syms(&bin->object.pe))
ret->dbg_info |= 0x08;
if (r_bin_pe_is_stripped_relocs(&bin->object.pe))
ret->dbg_info |= 0x10;
return ret;
}
if (bin->cur && bin->cur->info)
return bin->cur->info(bin);
return NULL;
}
u64 r_bin_get_section_offset(r_bin_obj *bin, char *name)
u64 r_bin_resize_section(struct r_bin_t *bin, char *name, u64 size)
{
r_bin_section *sections, *sectionsp;
if (bin->cur && bin->cur->resize_section)
return bin->cur->resize_section(bin, name, size);
return 0;
}
u64 r_bin_get_section_offset(struct r_bin_t *bin, char *name)
{
struct r_bin_section_t *sections, *sectionsp;
u64 ret = -1;
sections = r_bin_get_sections(bin);
if (!(sections = r_bin_get_sections(bin)))
return R_FALSE;
sectionsp = sections;
while (!sectionsp->last) {
@ -466,12 +200,13 @@ u64 r_bin_get_section_offset(r_bin_obj *bin, char *name)
return ret;
}
u64 r_bin_get_section_rva(r_bin_obj *bin, char *name)
u64 r_bin_get_section_rva(struct r_bin_t *bin, char *name)
{
r_bin_section *sections, *sectionsp;
struct r_bin_section_t *sections, *sectionsp;
u64 ret = -1;
sections = r_bin_get_sections(bin);
if (!(sections = r_bin_get_sections(bin)))
return R_FALSE;
sectionsp = sections;
while (!sectionsp->last) {
@ -488,12 +223,13 @@ u64 r_bin_get_section_rva(r_bin_obj *bin, char *name)
return ret;
}
u32 r_bin_get_section_size(r_bin_obj *bin, char *name)
u64 r_bin_get_section_size(struct r_bin_t *bin, char *name)
{
r_bin_section *sections, *sectionsp;
struct r_bin_section_t *sections, *sectionsp;
u64 ret = -1;
sections = r_bin_get_sections(bin);
if (!(sections = r_bin_get_sections(bin)))
return R_FALSE;
sectionsp = sections;
while (!sectionsp->last) {
@ -509,19 +245,6 @@ u32 r_bin_get_section_size(r_bin_obj *bin, char *name)
return ret;
}
u64 r_bin_resize_section(r_bin_obj *bin, char *name, u64 size)
{
switch (bin->format) {
case R_BIN_FMT_ELF32:
case R_BIN_FMT_ELF64:
return ELF_CALL(r_bin_elf_resize_section, bin, name, size);
case R_BIN_FMT_PE:
return 0;
}
return 0;
}
#if 0
int r_bin_get_libs()
{

25
libr/bin/p/Makefile Normal file
View file

@ -0,0 +1,25 @@
CFLAGS=-I../../include -Wall -fPIC -shared -Wl,-R..
# XXX
CFLAGS+=-DLIL_ENDIAN=1 -D__UNIX__ -g
OBJ_ELF=bin_elf.o elf/elf.o
OBJ_ELF64=bin_elf64.o elf/elf64.o
OBJ_PE=bin_pe.o pe/pe.o
all: bin_elf.so bin_elf64.so bin_pe.so
@true
bin_elf.so: ${OBJ_ELF}
${CC} ${CFLAGS} -o bin_elf.so ${OBJ_ELF}
@#strip -s bin_elf.so
bin_elf64.so: ${OBJ_ELF64}
${CC} ${CFLAGS} -o bin_elf64.so ${OBJ_ELF64}
@#strip -s bin_elf64.so
bin_pe.so: ${OBJ_PE}
${CC} ${CFLAGS} -o bin_pe.so ${OBJ_PE}
@#strip -s bin_pe.so
clean:
-rm -f *.so *.o ${OBJ_ELF} ${OBJ_ELF64} ${OBJ_PE}

199
libr/bin/p/bin_elf.c Normal file
View file

@ -0,0 +1,199 @@
/* radare - GPL3 - Copyright 2009 nibble<.ds@gmail.com> */
#include <r_types.h>
#include <r_lib.h>
#include <r_bin.h>
#include "elf/elf.h"
static int bopen(struct r_bin_t *bin)
{
if((bin->bin_obj = MALLOC_STRUCT(Elf32_r_bin_elf_obj)) == NULL)
return R_FALSE;
if ((bin->fd = Elf32_r_bin_elf_open(bin->bin_obj,bin->file,bin->rw)) == -1) {
free(bin->bin_obj);
return R_FALSE;
}
return bin->fd;
}
static int bclose(struct r_bin_t *bin)
{
return Elf32_r_bin_elf_close(bin->bin_obj);
}
static u64 baddr(struct r_bin_t *bin)
{
return Elf32_r_bin_elf_get_base_addr(bin->bin_obj);
}
static struct r_bin_entry_t* entry(struct r_bin_t *bin)
{
struct r_bin_entry_t *ret = NULL;
if((ret = MALLOC_STRUCT(struct r_bin_entry_t)) == NULL)
return NULL;
memset(ret, '\0', sizeof(struct r_bin_entry_t));
ret->offset = ret->rva = Elf32_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;
sections_count = Elf32_r_bin_elf_get_sections_count(bin->bin_obj);
if((section = malloc(sections_count * sizeof(r_bin_elf_section))) == NULL)
return NULL;
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));
Elf32_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);
ret[i].size = section[i].size;
ret[i].vsize = section[i].size;
ret[i].offset = section[i].offset;
ret[i].rva = section[i].offset;
ret[i].characteristics = 0;
if (R_BIN_ELF_SCN_IS_EXECUTABLE(section[i].flags))
ret[i].characteristics |= 0x1;
if (R_BIN_ELF_SCN_IS_WRITABLE(section[i].flags))
ret[i].characteristics |= 0x2;
if (R_BIN_ELF_SCN_IS_READABLE(section[i].flags))
ret[i].characteristics |= 0x4;
ret[i].last = 0;
}
ret[i].last = 1;
free(section);
return ret;
}
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;
symbols_count = Elf32_r_bin_elf_get_symbols_count(bin->bin_obj);
if ((symbol = malloc(symbols_count * sizeof(r_bin_elf_symbol))) == NULL)
return NULL;
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));
Elf32_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);
ret[i].rva = symbol[i].offset;
ret[i].offset = symbol[i].offset;
ret[i].size = symbol[i].size;
ret[i].ordinal = 0;
ret[i].last = 0;
}
ret[i].last = 1;
free(symbol);
return ret;
}
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;
imports_count = Elf32_r_bin_elf_get_imports_count(bin->bin_obj);
if ((import = malloc(imports_count * sizeof(r_bin_elf_import))) == NULL)
return NULL;
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));
Elf32_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);
ret[i].rva = import[i].offset;
ret[i].offset = import[i].offset;
ret[i].ordinal = 0;
ret[i].hint = 0;
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;
if((ret = malloc(sizeof(struct r_bin_info_t))) == NULL)
return NULL;
memset(ret, '\0', sizeof(struct r_bin_info_t));
strncpy(ret->type, Elf32_r_bin_elf_get_file_type(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->class, Elf32_r_bin_elf_get_elf_class(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->rclass, "elf", R_BIN_SIZEOF_NAMES);
strncpy(ret->os, Elf32_r_bin_elf_get_osabi_name(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->subsystem, Elf32_r_bin_elf_get_osabi_name(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->machine, Elf32_r_bin_elf_get_machine_name(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->arch, Elf32_r_bin_elf_get_arch(bin->bin_obj), R_BIN_SIZEOF_NAMES);
ret->big_endian=Elf32_r_bin_elf_is_big_endian(bin->bin_obj);
ret->dbg_info = 0;
if (Elf32_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 (Elf32_r_bin_elf_get_static(bin->bin_obj))
ret->dbg_info |= 0x02;
return ret;
}
static u64 resize_section(struct r_bin_t *bin, char *name, u64 size)
{
return Elf32_r_bin_elf_resize_section(bin->bin_obj, name, size);
}
static struct r_bin_handle_t r_bin_plugin_elf = {
.name = "bin_elf",
.desc = "elf bin plugin",
.init = NULL,
.fini = NULL,
.open = &bopen,
.close = &bclose,
.baddr = &baddr,
.entry = &entry,
.sections = &sections,
.symbols = &symbols,
.imports = &imports,
.info = &info,
.resize_section = &resize_section
};
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_elf
};

199
libr/bin/p/bin_elf64.c Normal file
View file

@ -0,0 +1,199 @@
/* radare - GPL3 - Copyright 2009 nibble<.ds@gmail.com> */
#include <r_types.h>
#include <r_lib.h>
#include <r_bin.h>
#include "elf/elf64.h"
static int bopen(struct r_bin_t *bin)
{
if((bin->bin_obj = MALLOC_STRUCT(Elf64_r_bin_elf_obj)) == NULL)
return R_FALSE;
if ((bin->fd = Elf64_r_bin_elf_open(bin->bin_obj,bin->file,bin->rw)) == -1) {
free(bin->bin_obj);
return R_FALSE;
}
return bin->fd;
}
static int bclose(struct r_bin_t *bin)
{
return Elf64_r_bin_elf_close(bin->bin_obj);
}
static u64 baddr(struct r_bin_t *bin)
{
return Elf64_r_bin_elf_get_base_addr(bin->bin_obj);
}
static struct r_bin_entry_t* entry(struct r_bin_t *bin)
{
struct r_bin_entry_t *ret = NULL;
if((ret = MALLOC_STRUCT(struct r_bin_entry_t)) == NULL)
return NULL;
memset(ret, '\0', sizeof(struct r_bin_entry_t));
ret->offset = ret->rva = Elf64_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;
sections_count = Elf64_r_bin_elf_get_sections_count(bin->bin_obj);
if((section = malloc(sections_count * sizeof(r_bin_elf_section))) == NULL)
return NULL;
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));
Elf64_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);
ret[i].size = section[i].size;
ret[i].vsize = section[i].size;
ret[i].offset = section[i].offset;
ret[i].rva = section[i].offset;
ret[i].characteristics = 0;
if (R_BIN_ELF_SCN_IS_EXECUTABLE(section[i].flags))
ret[i].characteristics |= 0x1;
if (R_BIN_ELF_SCN_IS_WRITABLE(section[i].flags))
ret[i].characteristics |= 0x2;
if (R_BIN_ELF_SCN_IS_READABLE(section[i].flags))
ret[i].characteristics |= 0x4;
ret[i].last = 0;
}
ret[i].last = 1;
free(section);
return ret;
}
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;
symbols_count = Elf64_r_bin_elf_get_symbols_count(bin->bin_obj);
if ((symbol = malloc(symbols_count * sizeof(r_bin_elf_symbol))) == NULL)
return NULL;
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));
Elf64_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);
ret[i].rva = symbol[i].offset;
ret[i].offset = symbol[i].offset;
ret[i].size = symbol[i].size;
ret[i].ordinal = 0;
ret[i].last = 0;
}
ret[i].last = 1;
free(symbol);
return ret;
}
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;
imports_count = Elf64_r_bin_elf_get_imports_count(bin->bin_obj);
if ((import = malloc(imports_count * sizeof(r_bin_elf_import))) == NULL)
return NULL;
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));
Elf64_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);
ret[i].rva = import[i].offset;
ret[i].offset = import[i].offset;
ret[i].ordinal = 0;
ret[i].hint = 0;
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;
if((ret = malloc(sizeof(struct r_bin_info_t))) == NULL)
return NULL;
memset(ret, '\0', sizeof(struct r_bin_info_t));
strncpy(ret->type, Elf64_r_bin_elf_get_file_type(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->class, Elf64_r_bin_elf_get_elf_class(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->rclass, "elf", R_BIN_SIZEOF_NAMES);
strncpy(ret->os, Elf64_r_bin_elf_get_osabi_name(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->subsystem, Elf64_r_bin_elf_get_osabi_name(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->machine, Elf64_r_bin_elf_get_machine_name(bin->bin_obj), R_BIN_SIZEOF_NAMES);
strncpy(ret->arch, Elf64_r_bin_elf_get_arch(bin->bin_obj), R_BIN_SIZEOF_NAMES);
ret->big_endian=Elf64_r_bin_elf_is_big_endian(bin->bin_obj);
ret->dbg_info = 0;
if (Elf64_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 (Elf64_r_bin_elf_get_static(bin->bin_obj))
ret->dbg_info |= 0x02;
return ret;
}
static u64 resize_section(struct r_bin_t *bin, char *name, u64 size)
{
return Elf64_r_bin_elf_resize_section(bin->bin_obj, name, size);
}
static struct r_bin_handle_t r_bin_plugin_elf64 = {
.name = "bin_elf64",
.desc = "elf64 bin plugin",
.init = NULL,
.fini = NULL,
.open = &bopen,
.close = &bclose,
.baddr = &baddr,
.entry = &entry,
.sections = &sections,
.symbols = &symbols,
.imports = &imports,
.info = &info,
.resize_section = &resize_section
};
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_elf64
};

208
libr/bin/p/bin_pe.c Normal file
View file

@ -0,0 +1,208 @@
/* radare - GPL3 - Copyright 2009 nibble<.ds@gmail.com> */
#include <r_types.h>
#include <r_lib.h>
#include <r_bin.h>
#include "pe/pe.h"
static int bopen(struct r_bin_t *bin)
{
if((bin->bin_obj = MALLOC_STRUCT(r_bin_pe_obj)) == NULL)
return R_FALSE;
if ((bin->fd = r_bin_pe_open(bin->bin_obj, bin->file)) == -1) {
free(bin->bin_obj);
return R_FALSE;
}
return bin->fd;
}
static int bclose(struct r_bin_t *bin)
{
return r_bin_pe_close(bin->bin_obj);
}
static u64 baddr(struct r_bin_t *bin)
{
return r_bin_pe_get_image_base(bin->bin_obj);
}
static struct r_bin_entry_t* entry(struct r_bin_t *bin)
{
struct r_bin_entry_t *ret;
r_bin_pe_entrypoint entry;
if((ret = malloc(sizeof(struct r_bin_entry_t))) == NULL)
return NULL;
memset(ret, '\0', sizeof(struct r_bin_entry_t));
r_bin_pe_get_entrypoint(bin->bin_obj, &entry);
ret->offset = entry.offset;
ret->rva = entry.rva;
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_pe_section *section = NULL;
sections_count = r_bin_pe_get_sections_count(bin->bin_obj);
if ((section = malloc(sections_count * sizeof(r_bin_pe_section))) == NULL)
return NULL;
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));
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);
ret[i].size = section[i].size;
ret[i].vsize = section->vsize;
ret[i].offset = section[i].offset;
ret[i].rva = section[i].rva;
ret[i].characteristics = 0;
if (R_BIN_PE_SCN_IS_EXECUTABLE(section[i].characteristics))
ret[i].characteristics |= 0x1;
if (R_BIN_PE_SCN_IS_WRITABLE(section[i].characteristics))
ret[i].characteristics |= 0x2;
if (R_BIN_PE_SCN_IS_READABLE(section[i].characteristics))
ret[i].characteristics |= 0x4;
if (R_BIN_PE_SCN_IS_SHAREABLE(section[i].characteristics))
ret[i].characteristics |= 0x8;
ret[i].last = 0;
}
ret[i].last = 1;
free(section);
return ret;
}
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_pe_export *symbol = NULL;
symbols_count = r_bin_pe_get_exports_count(bin->bin_obj);
if ((symbol = malloc(symbols_count * sizeof(r_bin_pe_export))) == NULL)
return NULL;
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));
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);
ret[i].rva = symbol[i].rva;
ret[i].offset = symbol[i].offset;
ret[i].size = 0;
ret[i].ordinal = symbol[i].ordinal;
ret[i].last = 0;
}
ret[i].last = 1;
free(symbol);
return ret;
}
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_pe_import *import = NULL;
imports_count = r_bin_pe_get_imports_count(bin->bin_obj);
if ((import = malloc(imports_count * sizeof(r_bin_pe_import))) == NULL)
return NULL;
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));
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);
ret[i].rva = import[i].rva;
ret[i].offset = import[i].offset;
ret[i].ordinal = import[i].ordinal;
ret[i].hint = import[i].hint;
ret[i].last = 0;
}
ret[i].last = 1;
free(import);
return ret;
}
static struct r_bin_info_t* info(struct r_bin_t *bin)
{
char pe_class_str[PE_NAME_LENGTH], pe_os_str[PE_NAME_LENGTH], pe_machine_str[PE_NAME_LENGTH];
char pe_arch_str[PE_NAME_LENGTH], pe_subsystem_str[PE_NAME_LENGTH];
struct r_bin_info_t *ret = NULL;
if((ret = malloc(sizeof(struct r_bin_info_t))) == NULL)
return NULL;
memset(ret, '\0', sizeof(struct r_bin_info_t));
if (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);
if (r_bin_pe_get_os(bin->bin_obj, pe_os_str))
strncpy(ret->os, pe_os_str, R_BIN_SIZEOF_NAMES);
if (r_bin_pe_get_arch(bin->bin_obj, pe_arch_str))
strncpy(ret->arch, pe_arch_str, R_BIN_SIZEOF_NAMES);
if (r_bin_pe_get_machine(bin->bin_obj, pe_machine_str))
strncpy(ret->machine, pe_machine_str, R_BIN_SIZEOF_NAMES);
if (r_bin_pe_get_subsystem(bin->bin_obj, pe_subsystem_str))
strncpy(ret->subsystem, pe_subsystem_str, R_BIN_SIZEOF_NAMES);
if (r_bin_pe_is_dll(bin->bin_obj))
strncpy(ret->type, "DLL (Dynamic Link Library)", R_BIN_SIZEOF_NAMES);
else
strncpy(ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_NAMES);
ret->big_endian = r_bin_pe_is_big_endian(bin->bin_obj);
ret->dbg_info = 0;
if (!r_bin_pe_is_stripped_debug(bin->bin_obj))
ret->dbg_info |= 0x01;
if (r_bin_pe_is_stripped_line_nums(bin->bin_obj))
ret->dbg_info |= 0x04;
if (r_bin_pe_is_stripped_local_syms(bin->bin_obj))
ret->dbg_info |= 0x08;
if (r_bin_pe_is_stripped_relocs(bin->bin_obj))
ret->dbg_info |= 0x10;
return ret;
}
static struct r_bin_handle_t r_bin_plugin_pe = {
.name = "bin_pe",
.desc = "pe bin plugin",
.init = NULL,
.fini = NULL,
.open = &bopen,
.close = &bclose,
.baddr = &baddr,
.entry = &entry,
.sections = &sections,
.symbols = &symbols,
.imports = &imports,
.info = &info,
.resize_section = NULL
};
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_pe
};

View file

@ -10,8 +10,9 @@
#include <sys/mman.h>
#endif
#include "r_types.h"
#include "r_bin_elf.h"
#include <r_types.h>
#include "elf.h"
/* TODO: move into bin_t */
static int endian = 0;

View file

@ -1,11 +1,11 @@
/* radare - LGPL - Copyright 2008 nibble<.ds@gmail.com> */
#include "r_types.h"
#include <r_types.h>
#include "r_bin_elf_specs.h"
#include "elf_specs.h"
#ifndef _INCLUDE_R_BIN_ELF_H_
#define _INCLUDE_R_BIN_ELF_H_
#ifndef _INCLUDE_ELF_H_
#define _INCLUDE_ELF_H_
#define R_BIN_ELF_SCN_IS_EXECUTABLE(x) x & SHF_EXECINSTR
#define R_BIN_ELF_SCN_IS_READABLE(x) x & SHF_ALLOC

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008 nibble<.ds@gmail.com> */
#define R_BIN_ELF64 1
#include "r_bin_elf.h"
#include "elf.h"

View file

@ -25,8 +25,8 @@
#define ELF_(name) Elf32_##name
#endif
#ifndef _INCLUDE_R_BIN_ELF_SPECS_H
#define _INCLUDE_R_BIN_ELF_SPECS_H
#ifndef _INCLUDE_ELF_SPECS_H
#define _INCLUDE_ELF_SPECS_H
/* Type for a 16-bit quantity. */
typedef unsigned short Elf32_Half;

View file

@ -14,7 +14,7 @@
#include <sys/mman.h>
#endif
#include <r_bin_pe.h>
#include "pe.h"
enum {
ENCODING_ASCII = 0,

View file

@ -5,7 +5,7 @@
#include "r_types.h"
#include "r_bin_pe_specs.h"
#include "pe_specs.h"
#define R_BIN_PE_SCN_IS_SHAREABLE(x) x & PE_IMAGE_SCN_MEM_SHARED
#define R_BIN_PE_SCN_IS_EXECUTABLE(x) x & PE_IMAGE_SCN_MEM_EXECUTE

View file

@ -1,22 +1,6 @@
all: baddr entry info sections symbols imports data_resize rabin2
OBJ=rabin2.o
BIN=rabin2
BINDEPS=r_util r_lib r_bin r_flags
LIBS+=-ldl
baddr:
${CC} -g -I ../../include baddr.c ../*.o -o baddr
entry:
${CC} -g -I ../../include entry.c ../*.o -o entry
info:
${CC} -g -I ../../include info.c ../*.o -o info
sections:
${CC} -g -I ../../include sections.c ../*.o -o sections
symbols:
${CC} -g -I ../../include symbols.c ../*.o -o symbols
imports:
${CC} -g -I ../../include imports.c ../*.o -o imports
data_resize:
${CC} -g -I ../../include data_resize.c ../*.o -o data_resize
rabin2:
${CC} -g -I ../../include rabin2.c -lr_bin -lr_util -lr_flags \
-L.. -L../..bin -L../../flags -L../../util -o rabin2
clean:
rm -f baddr entry info sections symbols imports data_resize rabin2
include ../../rules.mk

View file

@ -1,30 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "r_types.h"
#include "r_bin.h"
int main(int argc, char *argv[])
{
r_bin_obj bin;
u64 baddr;
if (argc != 2) {
fprintf(stderr, "Usage: %s file\n", argv[0]);
return 1;
}
if (r_bin_init(&bin, argv[1], 0) == -1) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
baddr = r_bin_get_baddr(&bin);
printf("Base addr: 0x%08x\n", baddr);
r_bin_close(&bin);
return 0;
}

View file

@ -1,26 +0,0 @@
#include <stdio.h>
#include "r_types.h"
#include "r_bin_elf.h"
int main(int argc, char *argv[])
{
Elf32_r_bin_elf_obj bin;
if (argc != 4) {
printf("Usage: %s <ELF32 file> <section> <size>\n", argv[0]);
return 1;
}
if (Elf32_r_bin_elf_open(&bin, argv[1], 1) == -1) {
fprintf(stderr, "cannot open file\n");
return 1;
}
Elf32_r_bin_elf_resize_section(&bin, argv[2], atoi(argv[3]));
Elf32_r_bin_elf_close(&bin);
return 0;
}

View file

@ -1,36 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "r_types.h"
#include "r_bin.h"
int main(int argc, char *argv[])
{
r_bin_obj bin;
r_bin_entry *entry;
u64 baddr;
if (argc != 2) {
fprintf(stderr, "Usage: %s file\n", argv[0]);
return 1;
}
if (r_bin_init(&bin, argv[1], 0) == -1) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
baddr = r_bin_get_baddr(&bin);
entry = r_bin_get_entry(&bin);
printf("[Entrypoint]\n");
printf("address=0x%08llx offset=0x%08llx\n",
baddr+entry->rva, entry->offset);
r_bin_close(&bin);
free(entry);
return 0;
}

View file

@ -1,48 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "r_types.h"
#include "r_bin.h"
int main(int argc, char *argv[])
{
int ctr = 0;
r_bin_obj bin;
u64 baddr;
r_bin_import *imports, *importsp;
if (argc != 2) {
fprintf(stderr, "Usage: %s file\n", argv[0]);
return 1;
}
if (r_bin_init(&bin, argv[1], 0) == -1) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
baddr = r_bin_get_baddr(&bin);
imports = r_bin_get_imports(&bin);
printf("[imports]\n");
importsp = imports;
while (!importsp->last) {
printf("address=0x%08llx offset=0x%08llx ordinal=%03i hint=%03i "
"bind=%s type=%s name=%s\n",
baddr + importsp->rva, importsp->offset,
importsp->ordinal, importsp->hint, importsp->bind,
importsp->type, importsp->name);
importsp++; ctr++;
}
printf("\n%i imports\n", ctr);
r_bin_close(&bin);
free(imports);
return 0;
}

View file

@ -1,53 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "r_types.h"
#include "r_bin.h"
int main(int argc, char *argv[])
{
r_bin_obj bin;
r_bin_info *info;
if (argc != 2) {
fprintf(stderr, "Usage: %s file\n", argv[0]);
return 1;
}
if (r_bin_init(&bin, argv[1], 0) == -1) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
info = r_bin_get_info(&bin);
printf("[File info]\n");
printf("Type: %s\n"
"Class: %s\n"
"Arch: %s\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",
info->type, info->class, info->arch, 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"
);
r_bin_close(&bin);
free(info);
return 0;
}

View file

@ -12,6 +12,7 @@
#include <getopt.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_bin.h>
#include <r_flags.h>
#include <r_util.h>
@ -23,33 +24,38 @@
#define ACTION_SECTIONS 0x0008
#define ACTION_INFO 0x0010
#define ACTION_OPERATION 0x0020
#define ACTION_HELP 0x0040
static struct r_lib_t l;
static struct r_bin_t bin;
static int verbose = 0;
static int rad = 0;
static int rabin_show_help()
{
printf( "rabin2 [options] [file]\n"
" -e Entrypoint\n"
" -i Imports (symbols imported from libraries)\n"
" -s Symbols (exports)\n"
" -S Sections\n"
" -I Binary info\n"
" -o [str] Operation action (str=help for help)\n"
" -r Radare output\n"
" -h This help\n" );
" -e Entrypoint\n"
" -i Imports (symbols imported from libraries)\n"
" -s Symbols (exports)\n"
" -S Sections\n"
" -I Binary info\n"
" -o [str] Operation action (str=help for help)\n"
" -p [plugin] Force plugin\n"
" -r Radare output\n"
" -h This help\n"
"Available plugins:\n");
r_bin_list(&bin);
return 1;
}
static int rabin_show_entrypoint(const char *file)
static int rabin_show_entrypoint()
{
r_bin_obj bin;
r_bin_entry *entry;
struct r_bin_entry_t *entry;
u64 baddr;
char *env;
if (r_bin_init(&bin, file, 0) == -1) {
if (r_bin_open(&bin) == R_FALSE) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
@ -76,15 +82,13 @@ static int rabin_show_entrypoint(const char *file)
return 0;
}
static int rabin_show_imports(const char *file)
static int rabin_show_imports()
{
int ctr = 0;
r_bin_obj bin;
u64 baddr;
char name[R_BIN_SIZEOF_NAMES];
r_bin_import *imports, *importsp;
struct r_bin_import_t *imports, *importsp;
if (r_bin_init(&bin, file, 0) == -1) {
if (r_bin_open(&bin) == R_FALSE) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
@ -103,8 +107,8 @@ static int rabin_show_imports(const char *file)
r_flag_name_filter(importsp->name);
printf("f imp.%s @ 0x%08llx\n",
importsp->name, baddr+importsp->rva);
} else printf("address=0x%08llx offset=0x%08llx ordinal=%03i "
"hint=%03i bind=%s type=%s name=%s\n",
} 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);
@ -119,14 +123,13 @@ static int rabin_show_imports(const char *file)
return 0;
}
static int rabin_show_symbols(const char *file)
static int rabin_show_symbols()
{
int ctr = 0;
r_bin_obj bin;
u64 baddr;
r_bin_symbol *symbols, *symbolsp;
struct r_bin_symbol_t *symbols, *symbolsp;
if (r_bin_init(&bin, file, 0) == -1) {
if (r_bin_open(&bin) == R_FALSE) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
@ -144,18 +147,18 @@ static int rabin_show_symbols(const char *file)
r_flag_name_filter(symbolsp->name);
if (symbolsp->size) {
if (!strncmp(symbolsp->type,"FUNC", 4))
printf("CF %li @ 0x%08llx\n",
printf("CF %lli @ 0x%08llx\n",
symbolsp->size, baddr+symbolsp->rva);
else
if (!strncmp(symbolsp->type,"OBJECT", 6))
printf("Cd %li @ 0x%08llx\n",
printf("Cd %lli @ 0x%08llx\n",
symbolsp->size, baddr+symbolsp->rva);
printf("b %li && ", symbolsp->size);
printf("b %lli && ", symbolsp->size);
}
printf("f sym.%s @ 0x%08llx\n",
symbolsp->name, baddr+symbolsp->rva);
} else printf("address=0x%08llx offset=0x%08llx ordinal=%03i "
"forwarder=%s size=%08i bind=%s type=%s name=%s\n",
} 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,
@ -171,14 +174,13 @@ static int rabin_show_symbols(const char *file)
return 0;
}
static int rabin_show_sections(const char *file)
static int rabin_show_sections()
{
int ctr = 0;
r_bin_obj bin;
u64 baddr;
r_bin_section *sections, *sectionsp;
struct r_bin_section_t *sections, *sectionsp;
if (r_bin_init(&bin, file, 0) == -1) {
if (r_bin_open(&bin) == R_FALSE) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
@ -198,7 +200,7 @@ static int rabin_show_sections(const char *file)
sectionsp->name, baddr+sectionsp->rva);
printf("f section.%s_end @ 0x%08llx\n",
sectionsp->name, baddr+sectionsp->rva+sectionsp->size);
printf("[%02i] address=0x%08llx offset=0x%08llx size=%08li "
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':'-',
@ -206,7 +208,7 @@ static int rabin_show_sections(const char *file)
R_BIN_SCN_WRITABLE(sectionsp->characteristics)?'w':'-',
R_BIN_SCN_EXECUTABLE(sectionsp->characteristics)?'x':'-',
sectionsp->name);
} else printf("idx=%02i address=0x%08llx offset=0x%08llx size=%08li "
} 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':'-',
@ -226,12 +228,11 @@ static int rabin_show_sections(const char *file)
}
static int rabin_show_info(const char *file)
static int rabin_show_info()
{
r_bin_obj bin;
r_bin_info *info;
struct r_bin_info_t *info;
if (r_bin_init(&bin, file, 0) == -1) {
if (r_bin_open(&bin) == R_FALSE) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
@ -273,9 +274,8 @@ static int rabin_show_info(const char *file)
return 0;
}
static int rabin_do_operation(const char *file, const char *op)
static int rabin_do_operation(const char *op)
{
r_bin_obj bin;
char *arg, *ptr, *ptr2;
if (!strcmp(op, "help")) {
@ -292,7 +292,7 @@ static int rabin_do_operation(const char *file, const char *op)
return 1;
}
if (r_bin_init(&bin, file, 1) == -1) {
if (r_bin_open(&bin) == R_FALSE) {
fprintf(stderr, "cannot open file\n");
return 1;
}
@ -314,14 +314,24 @@ static int rabin_do_operation(const char *file, const char *op)
return 0;
}
/* bin callback */
static int __lib_bin_cb(struct r_lib_plugin_t *pl, void *user, void *data)
{
struct r_bin_handle_t *hand = (struct r_bin_handle_t *)data;
//printf(" * Added (dis)assembly handler\n");
r_bin_add(&bin, hand);
return R_TRUE;
}
static int __lib_bin_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_TRUE; }
int main(int argc, char **argv)
{
int c;
int action = ACTION_UNK;
const char *file = NULL;
int action = ACTION_UNK, rw = 0;
const char *file = NULL, *plugin = NULL;
const char *op = NULL;
while ((c = getopt(argc, argv, "isSIeo:rvh")) != -1)
while ((c = getopt(argc, argv, "isSIeo:p:rvh")) != -1)
{
switch( c ) {
case 'i':
@ -342,6 +352,10 @@ int main(int argc, char **argv)
case 'o':
op = optarg;
action |= ACTION_OPERATION;
rw = 1;
break;
case 'p':
plugin = optarg;
break;
case 'r':
rad = 1;
@ -351,29 +365,45 @@ int main(int argc, char **argv)
break;
case 'h':
default:
return rabin_show_help();
action |= ACTION_HELP;
}
}
file = argv[optind];
if (action == ACTION_UNK)
return rabin_show_help();
else if (file == NULL)
r_bin_init(&bin, file, rw);
r_lib_init(&l, "radare_plugin");
r_lib_add_handler(&l, R_LIB_TYPE_BIN, "bin plugins",
&__lib_bin_cb, &__lib_bin_dt, NULL);
r_lib_opendir(&l, getenv("LIBR_PLUGINS"));
if (plugin) {
if (!r_bin_set(&bin, plugin)) {
fprintf(stderr, "Unknown plugin\n");
return 1;
}
} else {
if (!r_bin_autoset(&bin)) {
fprintf(stderr, "Not supported format\n");
return 1;
}
}
if (action == ACTION_HELP || action == ACTION_UNK || file == NULL)
return rabin_show_help();
if (action&ACTION_ENTRY)
rabin_show_entrypoint(file);
rabin_show_entrypoint();
if (action&ACTION_IMPORTS)
rabin_show_imports(file);
rabin_show_imports();
if (action&ACTION_SYMBOLS)
rabin_show_symbols(file);
rabin_show_symbols();
if (action&ACTION_SECTIONS)
rabin_show_sections(file);
rabin_show_sections();
if (action&ACTION_INFO)
rabin_show_info(file);
rabin_show_info();
if (op != NULL && action&ACTION_OPERATION)
rabin_do_operation(file, op);
rabin_do_operation(op);
return 0;
}

View file

@ -1,8 +0,0 @@
cd ..
make
cd t
make clean
make
cp /bin/ls l
./data_resize l .data `rax 0x9000`
./l

View file

@ -1,51 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "r_types.h"
#include "r_bin.h"
int main(int argc, char *argv[])
{
int ctr = 0;
r_bin_obj bin;
u64 baddr;
r_bin_section *sections, *sectionsp;
if (argc != 2) {
fprintf(stderr, "Usage: %s file\n", argv[0]);
return 1;
}
if (r_bin_init(&bin, argv[1], 0) == -1) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
baddr = r_bin_get_baddr(&bin);
sections = r_bin_get_sections(&bin);
printf("[Sections]\n");
sectionsp = sections;
while (!sectionsp->last) {
printf("idx=%02i address=0x%08llx offset=0x%08llx size=%08lli privileges=%c%c%c%c name=%s\n",
ctr, (u64) (baddr + sectionsp->rva),
(u64) (sectionsp->offset), (u64) (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++;
}
printf("\n%i sections\n", ctr);
r_bin_close(&bin);
free(sections);
return 0;
}

View file

@ -1,48 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "r_types.h"
#include "r_bin.h"
int main(int argc, char *argv[])
{
int ctr = 0;
r_bin_obj bin;
u64 baddr;
r_bin_symbol *symbols, *symbolsp;
if (argc != 2) {
fprintf(stderr, "Usage: %s file\n", argv[0]);
return 1;
}
if (r_bin_init(&bin, argv[1], 0) == -1) {
fprintf(stderr, "Cannot open file\n");
return 1;
}
baddr = r_bin_get_baddr(&bin);
symbols = r_bin_get_symbols(&bin);
printf("[Symbols]\n");
symbolsp = symbols;
while (!symbolsp->last) {
printf("address=0x%08llx offset=0x%08llx ordinal=%03i forwarder=%s "
"size=%08i 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++;
}
printf("\n%i symbols\n", ctr);
r_bin_close(&bin);
free(symbols);
return 0;
}

View file

@ -3,11 +3,8 @@
#ifndef _INCLUDE_R_BIN_H_
#define _INCLUDE_R_BIN_H_
#include "r_types.h"
#include "r_bin_elf.h"
#include "r_bin_elf64.h"
#include "r_bin_pe.h"
#include <r_types.h>
#include <list.h>
#define R_BIN_SCN_EXECUTABLE(x) x & 0x1
#define R_BIN_SCN_WRITABLE(x) x & 0x2
@ -22,61 +19,79 @@
#define R_BIN_SIZEOF_NAMES 64
/* types */
typedef union {
Elf32_r_bin_elf_obj e32;
Elf64_r_bin_elf_obj e64;
} r_bin_elf_obj;
enum {
R_BIN_FMT_ELF32,
R_BIN_FMT_ELF64,
R_BIN_FMT_PE
};
typedef struct {
union {
r_bin_elf_obj elf;
r_bin_pe_obj pe;
} object;
u32 format;
/* types */
struct r_bin_t {
const char *file;
int fd;
} r_bin_obj;
int rw;
void *bin_obj;
void *user;
struct r_bin_handle_t *cur;
struct list_head bins;
};
typedef struct {
struct r_bin_handle_t {
char *name;
char *desc;
int (*init)(void *user);
int (*fini)(void *user);
int (*open)(struct r_bin_t *bin);
int (*close)(struct r_bin_t *bin);
u64 (*baddr)(struct r_bin_t *bin);
struct r_bin_entry_t* (*entry)(struct r_bin_t *bin);
struct r_bin_section_t* (*sections)(struct r_bin_t *bin);
struct r_bin_symbol_t* (*symbols)(struct r_bin_t *bin);
struct r_bin_import_t* (*imports)(struct r_bin_t *bin);
struct r_bin_info_t* (*info)(struct r_bin_t *bin);
u64 (*resize_section)(struct r_bin_t *bin, char *name, u64 size);
struct list_head list;
};
struct r_bin_entry_t {
u64 rva;
u64 offset;
} r_bin_entry;
};
typedef struct {
struct r_bin_section_t {
char name[R_BIN_SIZEOF_NAMES];
u32 size;
u32 vsize;
u64 size;
u64 vsize;
u64 rva;
u64 offset;
u32 characteristics;
u64 characteristics;
int last;
} r_bin_section;
};
typedef struct {
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];
u64 rva;
u64 offset;
u32 size;
u32 ordinal;
u64 size;
u64 ordinal;
int last;
} r_bin_symbol;
};
typedef struct {
struct r_bin_import_t {
char name[R_BIN_SIZEOF_NAMES];
char bind[R_BIN_SIZEOF_NAMES];
char type[R_BIN_SIZEOF_NAMES];
u64 rva;
u64 offset;
u32 ordinal;
u32 hint;
u64 ordinal;
u64 hint;
int last;
} r_bin_import;
};
typedef struct {
struct r_bin_info_t {
char type[R_BIN_SIZEOF_NAMES];
char class[R_BIN_SIZEOF_NAMES];
char rclass[R_BIN_SIZEOF_NAMES];
@ -85,23 +100,29 @@ typedef struct {
char os[R_BIN_SIZEOF_NAMES];
char subsystem[R_BIN_SIZEOF_NAMES];
int big_endian;
u32 dbg_info;
} r_bin_info;
u64 dbg_info;
};
/* bin/r_bin.c */
r_bin_obj *r_bin_new(char *file, int rw);
void r_bin_free(r_bin_obj *bin);
int r_bin_init(r_bin_obj *bin, const char *file, int rw);
int r_bin_close(r_bin_obj *bin);
u64 r_bin_get_baddr(r_bin_obj *bin);
r_bin_entry* r_bin_get_entry(r_bin_obj *bin);
r_bin_section* r_bin_get_sections(r_bin_obj *bin);
u64 r_bin_get_section_offset(r_bin_obj *bin, char *name);
u64 r_bin_get_section_rva(r_bin_obj *bin, char *name);
u32 r_bin_get_section_size(r_bin_obj *bin, char *name);
r_bin_symbol* r_bin_get_symbols(r_bin_obj *bin);
r_bin_import* r_bin_get_imports(r_bin_obj *bin);
r_bin_info* r_bin_get_info(r_bin_obj *bin);
u64 r_bin_resize_section(r_bin_obj *bin, char *name, u64 size);
/* bin.c */
struct r_bin_t *r_bin_new(char *file, int rw);
void r_bin_free(struct r_bin_t *bin);
int r_bin_init(struct r_bin_t *bin, const char *file, int rw);
void r_bin_set_user_ptr(struct r_bin_t *bin, void *user);
int r_bin_add(struct r_bin_t *bin, struct r_bin_handle_t *foo);
int r_bin_list(struct r_bin_t *bin);
int r_bin_set(struct r_bin_t *bin, const char *name);
int r_bin_autoset(struct r_bin_t *bin);
int r_bin_open(struct r_bin_t *bin);
int r_bin_close(struct r_bin_t *bin);
u64 r_bin_get_baddr(struct r_bin_t *bin);
struct r_bin_entry_t* r_bin_get_entry(struct r_bin_t *bin);
struct r_bin_section_t* r_bin_get_sections(struct r_bin_t *bin);
struct r_bin_symbol_t* r_bin_get_symbols(struct r_bin_t *bin);
struct r_bin_import_t* r_bin_get_imports(struct r_bin_t *bin);
struct r_bin_info_t* r_bin_get_info(struct r_bin_t *bin);
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);
#endif

View file

@ -42,6 +42,7 @@ enum {
R_LIB_TYPE_ASM, /* assembler */
R_LIB_TYPE_ANAL, /* analysis */
R_LIB_TYPE_PARSE,/* parsers */
R_LIB_TYPE_BIN, /* bins */
};
struct r_lib_t {