2010-03-08 19:40:21 +01:00
|
|
|
/* radare - LGPL - Copyright 2008-2010 nibble<.ds@gmail.com> */
|
2009-02-05 22:08:46 +01:00
|
|
|
|
|
|
|
#ifndef _INCLUDE_R_BIN_H_
|
|
|
|
#define _INCLUDE_R_BIN_H_
|
|
|
|
|
2010-02-07 14:11:05 +01:00
|
|
|
#include <r_util.h>
|
2009-03-08 16:49:15 +01:00
|
|
|
#include <r_types.h>
|
2010-01-14 12:13:48 +01:00
|
|
|
#include <r_list.h>
|
2009-03-08 16:49:15 +01:00
|
|
|
#include <list.h>
|
2009-02-05 22:08:46 +01:00
|
|
|
|
|
|
|
#define R_BIN_SCN_EXECUTABLE(x) x & 0x1
|
|
|
|
#define R_BIN_SCN_WRITABLE(x) x & 0x2
|
|
|
|
#define R_BIN_SCN_READABLE(x) x & 0x4
|
|
|
|
#define R_BIN_SCN_SHAREABLE(x) x & 0x8
|
|
|
|
|
|
|
|
#define R_BIN_DBG_STRIPPED(x) x & 0x01
|
|
|
|
#define R_BIN_DBG_STATIC(x) x & 0x02
|
|
|
|
#define R_BIN_DBG_LINENUMS(x) x & 0x04
|
|
|
|
#define R_BIN_DBG_SYMS(x) x & 0x08
|
|
|
|
#define R_BIN_DBG_RELOCS(x) x & 0x10
|
|
|
|
|
2009-07-05 16:49:47 +02:00
|
|
|
#define R_BIN_SIZEOF_STRINGS 256
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2010-02-08 11:28:17 +01:00
|
|
|
typedef struct r_bin_t {
|
2009-02-05 22:08:46 +01:00
|
|
|
const char *file;
|
2010-01-24 12:40:48 +01:00
|
|
|
int size;
|
2009-03-08 16:49:15 +01:00
|
|
|
void *bin_obj;
|
2010-02-07 13:17:51 +01:00
|
|
|
ut64 baddr;
|
2010-05-30 06:06:25 +02:00
|
|
|
struct r_bin_addr_t *main;
|
2010-02-08 11:28:17 +01:00
|
|
|
struct r_bin_info_t *info;
|
2010-03-10 11:01:38 +01:00
|
|
|
RList* entries;
|
|
|
|
RList* sections;
|
|
|
|
RList* symbols;
|
|
|
|
RList* imports;
|
|
|
|
RList* strings;
|
|
|
|
RList* fields;
|
|
|
|
RList* libs;
|
2010-02-07 14:11:05 +01:00
|
|
|
RBuffer *buf;
|
2009-03-08 16:49:15 +01:00
|
|
|
void *user;
|
2010-05-26 01:42:22 +02:00
|
|
|
struct r_bin_plugin_t *cur;
|
2009-03-08 16:49:15 +01:00
|
|
|
struct list_head bins;
|
2010-02-08 11:28:17 +01:00
|
|
|
} RBin;
|
2009-03-08 16:49:15 +01:00
|
|
|
|
2010-05-26 01:42:22 +02:00
|
|
|
typedef struct r_bin_plugin_t {
|
2009-03-08 16:49:15 +01:00
|
|
|
char *name;
|
|
|
|
char *desc;
|
|
|
|
int (*init)(void *user);
|
|
|
|
int (*fini)(void *user);
|
2010-02-07 13:17:51 +01:00
|
|
|
int (*load)(RBin *bin);
|
2010-07-29 16:04:18 +02:00
|
|
|
int (*extract)(RBin *bin);
|
2010-02-07 13:17:51 +01:00
|
|
|
int (*destroy)(RBin *bin);
|
|
|
|
int (*check)(RBin *bin);
|
|
|
|
ut64 (*baddr)(RBin *bin);
|
2010-05-30 06:06:25 +02:00
|
|
|
struct r_bin_addr_t* (*main)(RBin *bin);
|
2010-03-10 11:01:38 +01:00
|
|
|
RList* (*entries)(RBin *bin);
|
|
|
|
RList* (*sections)(RBin *bin);
|
|
|
|
RList* (*symbols)(RBin *bin);
|
|
|
|
RList* (*imports)(RBin *bin);
|
|
|
|
RList* (*strings)(RBin *bin);
|
2010-02-08 11:28:17 +01:00
|
|
|
struct r_bin_info_t* (*info)(RBin *bin);
|
2010-03-10 11:01:38 +01:00
|
|
|
RList* (*fields)(RBin *bin);
|
|
|
|
RList* (*libs)(RBin *bin);
|
2010-02-22 04:30:34 +01:00
|
|
|
struct r_bin_meta_t *meta;
|
2010-03-08 19:40:21 +01:00
|
|
|
struct r_bin_write_t *write;
|
2009-03-08 16:49:15 +01:00
|
|
|
struct list_head list;
|
2010-05-26 01:42:22 +02:00
|
|
|
} RBinPlugin;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2010-05-30 06:06:25 +02:00
|
|
|
typedef struct r_bin_addr_t {
|
2009-07-08 13:49:55 +02:00
|
|
|
ut64 rva;
|
|
|
|
ut64 offset;
|
2010-05-30 06:06:25 +02:00
|
|
|
} RBinAddr;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2010-02-08 11:28:17 +01:00
|
|
|
typedef struct r_bin_section_t {
|
2009-07-05 16:49:47 +02:00
|
|
|
char name[R_BIN_SIZEOF_STRINGS];
|
2009-07-08 13:49:55 +02:00
|
|
|
ut64 size;
|
|
|
|
ut64 vsize;
|
|
|
|
ut64 rva;
|
|
|
|
ut64 offset;
|
2010-06-17 18:45:27 +02:00
|
|
|
ut64 srwx;
|
2010-02-08 11:28:17 +01:00
|
|
|
} RBinSection;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2010-02-08 11:28:17 +01:00
|
|
|
typedef struct r_bin_symbol_t {
|
2009-07-05 16:49:47 +02:00
|
|
|
char name[R_BIN_SIZEOF_STRINGS];
|
|
|
|
char forwarder[R_BIN_SIZEOF_STRINGS];
|
|
|
|
char bind[R_BIN_SIZEOF_STRINGS];
|
|
|
|
char type[R_BIN_SIZEOF_STRINGS];
|
2009-07-08 13:49:55 +02:00
|
|
|
ut64 rva;
|
|
|
|
ut64 offset;
|
|
|
|
ut64 size;
|
|
|
|
ut64 ordinal;
|
2010-02-08 11:28:17 +01:00
|
|
|
} RBinSymbol;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2010-02-08 11:28:17 +01:00
|
|
|
typedef struct r_bin_import_t {
|
2009-07-05 16:49:47 +02:00
|
|
|
char name[R_BIN_SIZEOF_STRINGS];
|
|
|
|
char bind[R_BIN_SIZEOF_STRINGS];
|
|
|
|
char type[R_BIN_SIZEOF_STRINGS];
|
2009-07-08 13:49:55 +02:00
|
|
|
ut64 rva;
|
|
|
|
ut64 offset;
|
|
|
|
ut64 ordinal;
|
|
|
|
ut64 hint;
|
2010-02-08 11:28:17 +01:00
|
|
|
} RBinImport;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2010-02-08 11:28:17 +01:00
|
|
|
typedef struct r_bin_string_t {
|
2009-07-05 16:49:47 +02:00
|
|
|
char string[R_BIN_SIZEOF_STRINGS];
|
2009-07-08 13:49:55 +02:00
|
|
|
ut64 rva;
|
|
|
|
ut64 offset;
|
|
|
|
ut64 ordinal;
|
|
|
|
ut64 size;
|
2010-02-08 11:28:17 +01:00
|
|
|
} RBinString;
|
2009-03-16 21:07:31 +01:00
|
|
|
|
2010-02-08 11:28:17 +01:00
|
|
|
typedef struct r_bin_info_t {
|
2010-02-19 19:59:22 +01:00
|
|
|
char file[R_BIN_SIZEOF_STRINGS];
|
2009-07-05 16:49:47 +02:00
|
|
|
char type[R_BIN_SIZEOF_STRINGS];
|
2010-02-08 11:28:17 +01:00
|
|
|
char bclass[R_BIN_SIZEOF_STRINGS];
|
2009-07-05 16:49:47 +02:00
|
|
|
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];
|
2010-03-16 02:24:12 +01:00
|
|
|
char rpath[R_BIN_SIZEOF_STRINGS];
|
2010-02-21 11:35:49 +01:00
|
|
|
int bits;
|
2009-02-05 22:08:46 +01:00
|
|
|
int big_endian;
|
2009-07-08 13:49:55 +02:00
|
|
|
ut64 dbg_info;
|
2010-02-08 11:28:17 +01:00
|
|
|
} RBinInfo;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2010-02-08 11:28:17 +01:00
|
|
|
typedef struct r_bin_field_t {
|
2009-07-05 16:49:47 +02:00
|
|
|
char name[R_BIN_SIZEOF_STRINGS];
|
2009-07-08 13:49:55 +02:00
|
|
|
ut64 rva;
|
|
|
|
ut64 offset;
|
2010-02-08 11:28:17 +01:00
|
|
|
} RBinField;
|
2009-04-24 12:12:15 +02:00
|
|
|
|
2010-03-09 15:12:04 +01:00
|
|
|
typedef struct r_bin_meta_t {
|
|
|
|
int (*get_line)(RBin *bin, ut64 addr, char *file, int len, int *line);
|
|
|
|
} RBinMeta;
|
|
|
|
|
|
|
|
typedef struct r_bin_write_t {
|
2010-03-11 02:14:34 +01:00
|
|
|
ut64 (*scn_resize)(RBin *bin, const char *name, ut64 size);
|
2010-03-16 02:24:12 +01:00
|
|
|
int (*rpath_del)(RBin *bin);
|
2010-03-09 15:12:04 +01:00
|
|
|
} RBinWrite;
|
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
#ifdef R_API
|
2010-02-22 04:30:34 +01:00
|
|
|
|
|
|
|
/* bin.c */
|
2010-05-26 01:42:22 +02:00
|
|
|
R_API int r_bin_add(RBin *bin, RBinPlugin *foo);
|
2010-07-29 16:04:18 +02:00
|
|
|
R_API int r_bin_extract(RBin *bin);
|
2010-02-07 13:17:51 +01:00
|
|
|
R_API void* r_bin_free(RBin *bin);
|
|
|
|
R_API int r_bin_list(RBin *bin);
|
|
|
|
R_API int r_bin_load(RBin *bin, const char *file, const char *plugin_name);
|
|
|
|
R_API ut64 r_bin_get_baddr(RBin *bin);
|
2010-05-30 06:06:25 +02:00
|
|
|
R_API RBinAddr* r_bin_get_main(RBin *bin);
|
2010-03-10 11:01:38 +01:00
|
|
|
R_API RList* r_bin_get_entries(RBin *bin);
|
|
|
|
R_API RList* r_bin_get_fields(RBin *bin);
|
|
|
|
R_API RList* r_bin_get_imports(RBin *bin);
|
2010-02-07 14:11:05 +01:00
|
|
|
R_API RBinInfo* r_bin_get_info(RBin *bin);
|
2010-03-10 11:01:38 +01:00
|
|
|
R_API RList* r_bin_get_libs(RBin *bin);
|
|
|
|
R_API RList* r_bin_get_sections(RBin *bin);
|
2010-02-23 18:26:02 +01:00
|
|
|
R_API RBinSection* r_bin_get_section_at(RBin *bin, ut64 off, int va);
|
2010-03-10 11:01:38 +01:00
|
|
|
R_API RList* r_bin_get_strings(RBin *bin);
|
|
|
|
R_API RList* r_bin_get_symbols(RBin *bin);
|
2010-03-13 20:25:03 +01:00
|
|
|
R_API int r_bin_is_big_endian (RBin *bin);
|
|
|
|
R_API int r_bin_is_stripped (RBin *bin);
|
|
|
|
R_API int r_bin_is_static (RBin *bin);
|
|
|
|
R_API int r_bin_has_dbg_linenums (RBin *bin);
|
|
|
|
R_API int r_bin_has_dbg_syms (RBin *bin);
|
|
|
|
R_API int r_bin_has_dbg_relocs (RBin *bin);
|
2010-02-07 13:17:51 +01:00
|
|
|
R_API RBin* r_bin_new();
|
|
|
|
R_API void r_bin_set_user_ptr(RBin *bin, void *user);
|
2010-02-22 04:30:34 +01:00
|
|
|
|
2010-02-22 04:47:19 +01:00
|
|
|
/* bin_meta.c */
|
2010-02-22 04:30:34 +01:00
|
|
|
R_API int r_bin_meta_get_line(RBin *bin, ut64 addr, char *file, int len, int *line);
|
2010-03-19 01:45:52 +01:00
|
|
|
R_API char *r_bin_meta_get_source_line(RBin *bin, ut64 addr);
|
2010-02-22 04:30:34 +01:00
|
|
|
|
2010-03-08 19:40:21 +01:00
|
|
|
/* bin_write.c */
|
2010-03-11 02:14:34 +01:00
|
|
|
R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size);
|
2010-03-16 02:24:12 +01:00
|
|
|
R_API int r_bin_wr_rpath_del(RBin *bin);
|
2010-03-11 02:14:34 +01:00
|
|
|
R_API int r_bin_wr_output(RBin *bin, const char *filename);
|
2009-03-09 13:03:42 +01:00
|
|
|
|
2010-05-27 19:58:54 +02:00
|
|
|
/* plugin pointers */
|
|
|
|
extern RBinPlugin r_bin_plugin_elf;
|
|
|
|
extern RBinPlugin r_bin_plugin_elf64;
|
|
|
|
extern RBinPlugin r_bin_plugin_pe;
|
|
|
|
extern RBinPlugin r_bin_plugin_pe64;
|
|
|
|
extern RBinPlugin r_bin_plugin_mach0;
|
|
|
|
extern RBinPlugin r_bin_plugin_mach064;
|
2010-07-29 16:04:18 +02:00
|
|
|
extern RBinPlugin r_bin_plugin_fatmach0;
|
2010-05-27 19:58:54 +02:00
|
|
|
extern RBinPlugin r_bin_plugin_java;
|
|
|
|
extern RBinPlugin r_bin_plugin_dummy;
|
|
|
|
|
|
|
|
#endif
|
2009-02-05 22:08:46 +01:00
|
|
|
#endif
|