radare2/libr/include/r_bin.h

888 lines
27 KiB
C
Raw Normal View History

2014-03-27 16:34:17 +01:00
#ifndef R2_BIN_H
#define R2_BIN_H
2010-02-07 14:11:05 +01:00
#include <r_util.h>
#include <r_types.h>
2013-12-09 04:56:13 +01:00
#include <r_io.h>
#include <r_cons.h>
#include <r_list.h>
typedef struct r_bin_t RBin;
#include <r_bin_dwarf.h>
#include <r_pdb.h>
#ifdef __cplusplus
extern "C" {
#endif
R_LIB_VERSION_HEADER (r_bin);
#define R_BIN_DBG_STRIPPED 0x01
#define R_BIN_DBG_STATIC 0x02
#define R_BIN_DBG_LINENUMS 0x04
#define R_BIN_DBG_SYMS 0x08
#define R_BIN_DBG_RELOCS 0x10
#define R_BIN_ENTRY_TYPE_PROGRAM 0
#define R_BIN_ENTRY_TYPE_MAIN 1
#define R_BIN_ENTRY_TYPE_INIT 2
#define R_BIN_ENTRY_TYPE_FINI 3
#define R_BIN_ENTRY_TYPE_TLS 4
2018-04-09 14:32:51 +08:00
#define R_BIN_ENTRY_TYPE_PREINIT 5
2013-04-25 03:42:17 +02:00
#define R_BIN_SIZEOF_STRINGS 512
#define R_BIN_MAX_ARCH 1024
#define R_BIN_REQ_ALL UT64_MAX
#define R_BIN_REQ_UNK 0x000000
#define R_BIN_REQ_ENTRIES 0x000001
#define R_BIN_REQ_IMPORTS 0x000002
#define R_BIN_REQ_SYMBOLS 0x000004
#define R_BIN_REQ_SECTIONS 0x000008
#define R_BIN_REQ_INFO 0x000010
#define R_BIN_REQ_OPERATION 0x000020
#define R_BIN_REQ_HELP 0x000040
#define R_BIN_REQ_STRINGS 0x000080
#define R_BIN_REQ_FIELDS 0x000100
#define R_BIN_REQ_LIBS 0x000200
#define R_BIN_REQ_SRCLINE 0x000400
#define R_BIN_REQ_MAIN 0x000800
#define R_BIN_REQ_EXTRACT 0x001000
#define R_BIN_REQ_RELOCS 0x002000
#define R_BIN_REQ_LISTARCHS 0x004000
#define R_BIN_REQ_CREATE 0x008000
#define R_BIN_REQ_CLASSES 0x010000
#define R_BIN_REQ_DWARF 0x020000
#define R_BIN_REQ_SIZE 0x040000
#define R_BIN_REQ_PDB 0x080000
#define R_BIN_REQ_PDB_DWNLD 0x100000
#define R_BIN_REQ_DLOPEN 0x200000
#define R_BIN_REQ_EXPORTS 0x400000
#define R_BIN_REQ_VERSIONINFO 0x800000
#define R_BIN_REQ_PACKAGE 0x1000000
#define R_BIN_REQ_HEADER 0x2000000
#define R_BIN_REQ_LISTPLUGINS 0x4000000
#define R_BIN_REQ_RESOURCES 0x8000000
#define R_BIN_REQ_INITFINI 0x10000000
#define R_BIN_REQ_SEGMENTS 0x20000000
#define R_BIN_REQ_HASHES 0x40000000
#define R_BIN_REQ_SIGNATURE 0x80000000
#define R_BIN_REQ_TRYCATCH 0x100000000
#define R_BIN_REQ_SECTIONS_MAPPING 0x200000000
/* RBinSymbol->method_flags : */
#define R_BIN_METH_CLASS 0x0000000000000001L
#define R_BIN_METH_STATIC 0x0000000000000002L
#define R_BIN_METH_PUBLIC 0x0000000000000004L
#define R_BIN_METH_PRIVATE 0x0000000000000008L
#define R_BIN_METH_PROTECTED 0x0000000000000010L
#define R_BIN_METH_INTERNAL 0x0000000000000020L
#define R_BIN_METH_OPEN 0x0000000000000040L
#define R_BIN_METH_FILEPRIVATE 0x0000000000000080L
#define R_BIN_METH_FINAL 0x0000000000000100L
#define R_BIN_METH_VIRTUAL 0x0000000000000200L
#define R_BIN_METH_CONST 0x0000000000000400L
#define R_BIN_METH_MUTATING 0x0000000000000800L
#define R_BIN_METH_ABSTRACT 0x0000000000001000L
#define R_BIN_METH_SYNCHRONIZED 0x0000000000002000L
#define R_BIN_METH_NATIVE 0x0000000000004000L
#define R_BIN_METH_BRIDGE 0x0000000000008000L
#define R_BIN_METH_VARARGS 0x0000000000010000L
#define R_BIN_METH_SYNTHETIC 0x0000000000020000L
#define R_BIN_METH_STRICT 0x0000000000040000L
#define R_BIN_METH_MIRANDA 0x0000000000080000L
#define R_BIN_METH_CONSTRUCTOR 0x0000000000100000L
#define R_BIN_METH_DECLARED_SYNCHRONIZED 0x0000000000200000L
#define R_BIN_BIND_LOCAL_STR "LOCAL"
#define R_BIN_BIND_GLOBAL_STR "GLOBAL"
#define R_BIN_BIND_WEAK_STR "WEAK"
#define R_BIN_BIND_NUM_STR "NUM"
#define R_BIN_BIND_LOOS_STR "LOOS"
#define R_BIN_BIND_HIOS_STR "HIOS"
#define R_BIN_BIND_LOPROC_STR "LOPROC"
#define R_BIN_BIND_HIPROC_STR "HIPROC"
#define R_BIN_BIND_UNKNOWN_STR "UNKNOWN"
#define R_BIN_TYPE_NOTYPE_STR "NOTYPE"
#define R_BIN_TYPE_OBJECT_STR "OBJ"
#define R_BIN_TYPE_FUNC_STR "FUNC"
#define R_BIN_TYPE_METH_STR "METH"
2019-03-28 14:38:11 +05:30
#define R_BIN_TYPE_STATIC_STR "STATIC"
#define R_BIN_TYPE_SECTION_STR "SECT"
#define R_BIN_TYPE_FILE_STR "FILE"
#define R_BIN_TYPE_COMMON_STR "COMMON"
#define R_BIN_TYPE_TLS_STR "TLS"
#define R_BIN_TYPE_NUM_STR "NUM"
#define R_BIN_TYPE_LOOS_STR "LOOS"
#define R_BIN_TYPE_HIOS_STR "HIOS"
#define R_BIN_TYPE_LOPROC_STR "LOPROC"
#define R_BIN_TYPE_HIPROC_STR "HIPROC"
2019-05-09 11:35:01 +02:00
#define R_BIN_TYPE_SPECIAL_SYM_STR "SPCL"
#define R_BIN_TYPE_UNKNOWN_STR "UNK"
enum {
R_BIN_SYM_ENTRY,
R_BIN_SYM_INIT,
R_BIN_SYM_MAIN,
R_BIN_SYM_FINI,
R_BIN_SYM_LAST
};
// name mangling types
// TODO: Rename to R_BIN_LANG_
enum {
R_BIN_NM_NONE = 0,
R_BIN_NM_JAVA = 1,
R_BIN_NM_C = 1<<1,
R_BIN_NM_GO = 1<<2,
R_BIN_NM_CXX = 1<<3,
R_BIN_NM_OBJC = 1<<4,
R_BIN_NM_SWIFT = 1<<5,
R_BIN_NM_DLANG = 1<<6,
R_BIN_NM_MSVC = 1<<7,
R_BIN_NM_RUST = 1<<8,
2019-07-22 20:44:20 +02:00
R_BIN_NM_KOTLIN = 1<<9,
R_BIN_NM_BLOCKS = 1<<31,
R_BIN_NM_ANY = -1,
};
enum {
R_STRING_TYPE_DETECT = '?',
R_STRING_TYPE_ASCII = 'a',
R_STRING_TYPE_UTF8 = 'u',
R_STRING_TYPE_WIDE = 'w', // utf16 / widechar string
R_STRING_TYPE_WIDE32 = 'W', // utf32
R_STRING_TYPE_BASE64 = 'b',
};
enum {
R_BIN_CLASS_PRIVATE,
R_BIN_CLASS_PUBLIC,
R_BIN_CLASS_FRIENDLY,
R_BIN_CLASS_PROTECTED,
};
enum {
2014-04-05 12:09:41 +02:00
R_BIN_RELOC_8 = 8,
R_BIN_RELOC_16 = 16,
R_BIN_RELOC_32 = 32,
R_BIN_RELOC_64 = 64
};
enum {
R_BIN_TYPE_DEFAULT = 0,
R_BIN_TYPE_CORE = 1
};
2012-07-21 14:11:21 +04:00
typedef struct r_bin_addr_t {
ut64 vaddr;
ut64 paddr;
ut64 hvaddr;
ut64 hpaddr;
int type;
2016-06-18 01:12:19 +02:00
int bits;
2012-07-21 14:11:21 +04:00
} RBinAddr;
2013-04-11 01:25:25 +02:00
typedef struct r_bin_hash_t {
const char *type;
ut64 addr;
int len;
ut64 from;
ut64 to;
ut8 buf[32];
const char *cmd;
} RBinHash;
typedef struct r_bin_file_hash_t {
const char *type;
const char *hex;
} RBinFileHash;
2012-07-21 14:11:21 +04:00
typedef struct r_bin_info_t {
2015-03-25 14:49:33 +01:00
char *file;
char *type;
char *bclass;
char *rclass;
char *arch;
char *cpu;
char *machine;
char *head_flag;
char *features;
2015-03-25 14:49:33 +01:00
char *os;
char *subsystem;
char *rpath;
char *guid;
char *debug_file_name;
const char *lang;
char *default_cc;
RList/*<RBinFileHash>*/ *file_hashes;
2012-07-21 14:11:21 +04:00
int bits;
int has_va;
int has_pi; // pic/pie
2014-04-28 14:45:02 +02:00
int has_canary;
int has_retguard;
int has_sanitizers;
int has_crypto;
2014-05-09 19:25:12 +02:00
int has_nx;
2012-07-21 14:11:21 +04:00
int big_endian;
bool has_lit;
char *actual_checksum;
char *claimed_checksum;
int pe_overlay;
bool signature;
2012-07-21 14:11:21 +04:00
ut64 dbg_info;
RBinHash sum[3];
ut64 baddr;
char *intrp;
char *compiler;
2012-07-21 14:11:21 +04:00
} RBinInfo;
typedef struct r_bin_object_t {
ut64 baddr;
st64 baddr_shift;
ut64 loadaddr;
ut64 boffset;
ut64 size;
ut64 obj_size;
RList/*<RBinSection>*/ *sections;
RList/*<RBinImport>*/ *imports;
RList/*<RBinSymbol>*/ *symbols;
RList/*<??>*/ *entries;
RList/*<??>*/ *fields;
RList/*<??>*/ *libs;
RBNode/*<RBinReloc>*/ *relocs;
RList/*<??>*/ *strings;
RList/*<RBinClass>*/ *classes;
HtPP *classes_ht;
HtPP *methods_ht;
RList/*<RBinDwarfRow>*/ *lines;
HtUP *strings_db;
RList/*<??>*/ *mem; //RBinMem maybe?
RList/*<BinMap*/ *maps;
char *regstate;
RBinInfo *info;
RBinAddr *binsym[R_BIN_SYM_LAST];
struct r_bin_plugin_t *plugin;
int lang;
Sdb *kv;
Sdb *addr2klassmethod;
void *bin_obj; // internal pointer used by formats
} RBinObject;
2018-08-06 09:27:27 +02:00
// XXX: RbinFile may hold more than one RBinObject
/// XX curplugin == o->plugin
2014-01-20 03:29:50 +01:00
typedef struct r_bin_file_t {
char *file;
int fd;
int size;
int rawstr;
2018-01-12 14:02:33 +05:30
int strmode;
ut32 id;
RBuffer *buf;
ut64 offset;
RBinObject *o;
2014-01-22 16:58:23 -06:00
void *xtr_obj;
ut64 loadaddr;
/* values used when searching the strings */
int minstrlen;
int maxstrlen;
int narch;
struct r_bin_xtr_plugin_t *curxtr;
// struct r_bin_plugin_t *curplugin; // use o->plugin
RList *xtr_data;
Sdb *sdb;
Sdb *sdb_info;
2014-04-21 19:13:52 +04:00
Sdb *sdb_addrinfo;
struct r_bin_t *rbin;
} RBinFile;
typedef struct r_bin_file_options_t {
int rawstr;
ut64 baddr; // base address
ut64 laddr; // load address
ut64 paddr; // offset
const char *plugname; // force a plugin? why do i need this?
// const char *xtrname;
} RBinFileOptions;
struct r_bin_t {
const char *file;
RBinFile *cur; // TODO: deprecate
int narch;
void *user;
/* preconfigured values */
int debase64;
int minstrlen;
int maxstrlen;
ut64 maxstrbuf;
int rawstr;
Sdb *sdb;
RIDStorage *ids;
RList/*<RBinPlugin>*/ *plugins;
RList/*<RBinXtrPlugin>*/ *binxtrs;
RList/*<RBinLdrPlugin>*/ *binldrs;
RList/*<RBinFile>*/ *binfiles;
PrintfCallback cb_printf;
int loadany;
RIOBind iob;
RConsBind consb;
char *force;
bool want_dbginfo;
int filter; // symbol filtering
char strfilter; // string filtering
char *strpurge; // purge false positive strings
char *srcdir; // dir.source
2015-10-22 20:26:24 +02:00
char *prefix; // bin.prefix
char *strenc;
ut64 filter_rules;
bool demanglercmd;
bool verbose;
bool use_xtr; // use extract plugins when loading a file?
bool use_ldr; // use loader plugins when loading a file?
RStrConstPool constpool;
bool is_reloc_patched; // used to indicate whether relocations were patched or not
};
typedef struct r_bin_xtr_metadata_t {
char *arch;
int bits;
char *libname;
char *machine;
char *type;
2018-08-05 16:22:11 -07:00
const char *xtr_type;
} RBinXtrMetadata;
typedef int (*FREE_XTR)(void *xtr_obj);
typedef struct r_bin_xtr_extract_t {
char *file;
RBuffer *buf;
ut64 size;
ut64 offset;
ut64 baddr;
ut64 laddr;
int file_count;
int loaded;
RBinXtrMetadata *metadata;
} RBinXtrData;
R_API RBinXtrData *r_bin_xtrdata_new(RBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RBinXtrMetadata *metadata);
R_API void r_bin_xtrdata_free(void /*RBinXtrData*/ *data);
typedef struct r_bin_xtr_plugin_t {
char *name;
char *desc;
char *license;
int (*init)(void *user);
int (*fini)(void *user);
bool (*check_buffer)(RBuffer *b);
RBinXtrData *(*extract_from_bytes)(RBin *bin, const ut8 *buf, ut64 size, int idx);
RBinXtrData *(*extract_from_buffer)(RBin *bin, RBuffer *buf, int idx);
RList *(*extractall_from_bytes)(RBin *bin, const ut8 *buf, ut64 size);
RList *(*extractall_from_buffer)(RBin *bin, RBuffer *buf);
RBinXtrData *(*extract)(RBin *bin, int idx);
RList *(*extractall)(RBin *bin);
2016-02-04 15:44:49 +01:00
bool (*load)(RBin *bin);
int (*size)(RBin *bin);
void (*destroy)(RBin *bin);
void (*free_xtr)(void *xtr_obj);
} RBinXtrPlugin;
typedef struct r_bin_ldr_plugin_t {
char *name;
char *desc;
char *license;
int (*init)(void *user);
int (*fini)(void *user);
bool (*load)(RBin *bin);
} RBinLdrPlugin;
typedef struct r_bin_arch_options_t {
const char *arch;
int bits;
} RBinArchOptions;
typedef struct r_bin_trycatch_t {
ut64 source;
ut64 from;
ut64 to;
ut64 handler;
ut64 filter;
// TODO: add type/name of exception
} RBinTrycatch;
R_API RBinTrycatch *r_bin_trycatch_new(ut64 source, ut64 from, ut64 to, ut64 handler, ut64 filter);
R_API void r_bin_trycatch_free(RBinTrycatch *tc);
typedef struct r_bin_plugin_t {
char *name;
char *desc;
char *author;
char *version;
char *license;
int (*init)(void *user);
int (*fini)(void *user);
Sdb * (*get_sdb)(RBinFile *obj);
bool (*load_buffer)(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb);
ut64 (*size)(RBinFile *bin); // return ut64 maybe? meh
void (*destroy)(RBinFile *bf);
bool (*check_bytes)(const ut8 *buf, ut64 length);
bool (*check_buffer)(RBuffer *buf);
ut64 (*baddr)(RBinFile *bf);
ut64 (*boffset)(RBinFile *bf);
RBinAddr* (*binsym)(RBinFile *bf, int num);
RList/*<RBinAddr>*/* (*entries)(RBinFile *bf);
RList/*<RBinSection>*/* (*sections)(RBinFile *bf);
R_BORROW RList/*<RBinDwarfRow>*/* (*lines)(RBinFile *bf);
RList/*<RBinSymbol>*/* (*symbols)(RBinFile *bf);
RList/*<RBinImport>*/* (*imports)(RBinFile *bf);
RList/*<RBinString>*/* (*strings)(RBinFile *bf);
RBinInfo/*<RBinInfo>*/* (*info)(RBinFile *bf);
RList/*<RBinField>*/* (*fields)(RBinFile *bf);
RList/*<char *>*/* (*libs)(RBinFile *bf);
RList/*<RBinReloc>*/* (*relocs)(RBinFile *bf);
RList/*<RBinTrycatch>*/* (*trycatch)(RBinFile *bf);
RList/*<RBinClass>*/* (*classes)(RBinFile *bf);
RList/*<RBinMem>*/* (*mem)(RBinFile *bf);
2016-09-07 19:18:03 +02:00
RList/*<RBinReloc>*/* (*patch_relocs)(RBin *bin);
RList/*<RBinMap>*/* (*maps)(RBinFile *bf);
RList/*<RBinFileHash>*/* (*hashes)(RBinFile *bf);
void (*header)(RBinFile *bf);
char* (*signature)(RBinFile *bf, bool json);
int (*demangle_type)(const char *str);
2014-03-10 02:27:32 +01:00
struct r_bin_dbginfo_t *dbginfo;
struct r_bin_write_t *write;
int (*get_offset)(RBinFile *bf, int type, int idx);
const char* (*get_name)(RBinFile *bf, int type, int idx, bool simplified);
ut64 (*get_vaddr)(RBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr);
RBuffer* (*create)(RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt);
char* (*demangle)(const char *str);
char* (*regstate)(RBinFile *bf);
int (*file_type)(RBinFile *bf);
/* default value if not specified by user */
int minstrlen;
char strfilter;
void *user;
} RBinPlugin;
typedef void (*RBinSymbollCallback)(RBinObject *obj, void *symbol);
typedef struct r_bin_section_t {
char *name;
ut64 size;
ut64 vsize;
ut64 vaddr;
ut64 paddr;
ut32 perm;
// per section platform info
const char *arch;
char *format;
int bits;
bool has_strings;
2015-12-12 22:27:17 +01:00
bool add; // indicates when you want to add the section to io `S` command
bool is_data;
bool is_segment;
} RBinSection;
typedef struct r_bin_class_t {
char *name;
2016-04-25 18:45:10 +02:00
// TODO: char *module;
char *super;
char *visibility_str; // XXX only used by java
int index;
2015-07-06 00:05:03 +02:00
ut64 addr;
RList *methods; // <RBinSymbol>
RList *fields; // <RBinField>
// RList *interfaces; // <char *>
int visibility;
} RBinClass;
#define RBinSectionName r_offsetof(RBinSection, name)
#define RBinSectionOffset r_offsetof(RBinSection, offset)
#define REBASE_PADDR(o, l, type_t)\
do { \
RListIter *_it;\
type_t *_el;\
r_list_foreach ((l), _it, _el) { \
_el->paddr += (o)->loadaddr;\
}\
} while (0)
typedef struct r_bin_symbol_t {
2015-11-09 12:12:18 +01:00
/* heap-allocated */
char *name;
char *dname;
char *libname;
char *classname;
2015-11-09 12:12:18 +01:00
/* const-unique-strings */
const char *forwarder;
const char *bind;
const char *type;
const char *rtype;
bool is_imported;
2015-11-09 12:12:18 +01:00
/* only used by java */
const char *visibility_str;
// ----------------
//char descriptor[R_BIN_SIZEOF_STRINGS+1];
ut64 vaddr;
ut64 paddr;
ut32 size;
ut32 ordinal;
ut32 visibility;
int bits;
/* see R_BIN_METH_* constants */
ut64 method_flags;
int dup_count;
} RBinSymbol;
typedef struct r_bin_import_t {
char *name;
char *libname;
const char *bind;
const char *type;
char *classname;
char *descriptor;
ut32 ordinal;
ut32 visibility;
} RBinImport;
typedef struct r_bin_reloc_t {
ut8 type;
ut8 additive;
RBinSymbol *symbol;
RBinImport *import;
st64 addend;
ut64 vaddr;
ut64 paddr;
ut32 visibility;
/* is_ifunc: indirect function, `addend` points to a resolver function
* that returns the actual relocation value, e.g. chooses
* an optimized version depending on the CPU.
* cf. https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
*/
bool is_ifunc;
RBNode vrb;
} RBinReloc;
typedef struct r_bin_string_t {
// TODO: rename string->name (avoid colisions)
char *string;
ut64 vaddr;
ut64 paddr;
ut32 ordinal;
ut32 size; // size of buffer containing the string in bytes
ut32 length; // length of string in chars
char type; // Ascii Wide cp850 utf8 base64 ...
} RBinString;
typedef struct r_bin_field_t {
ut64 vaddr;
ut64 paddr;
int size;
int offset;
ut32 visibility;
char *name;
char *type;
char *comment;
char *format;
bool format_named; // whether format is the name of a format or a raw pf format string
2017-06-27 17:02:14 +02:00
ut64 flags;
} RBinField;
R_API RBinField *r_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *name, const char *comment, const char *format, bool format_named);
R_API void r_bin_field_free(void *);
typedef struct r_bin_mem_t {
2015-11-09 12:12:18 +01:00
char *name;
ut64 addr;
int size;
int perms;
RList *mirrors; //for mirror access; stuff here should only create new maps not new fds
} RBinMem;
typedef struct r_bin_map_t {
ut64 addr;
ut64 offset;
int size;
int perms;
char *file;
} RBinMap;
2014-03-10 02:27:32 +01:00
typedef struct r_bin_dbginfo_t {
bool (*get_line)(RBinFile *arch, ut64 addr, char *file, int len, int *line);
2014-03-10 02:27:32 +01:00
} RBinDbgInfo;
typedef struct r_bin_write_t {
ut64 (*scn_resize)(RBinFile *bf, const char *name, ut64 size);
bool (*scn_perms)(RBinFile *bf, const char *name, int perms);
int (*rpath_del)(RBinFile *bf);
bool (*entry)(RBinFile *bf, ut64 addr);
bool (*addlib)(RBinFile *bf, const char *lib);
} RBinWrite;
// TODO: deprecate r_bin_is_big_endian
// TODO: has_dbg_syms... maybe flags?
typedef int (*RBinGetOffset)(RBin *bin, int type, int idx);
typedef const char *(*RBinGetName)(RBin *bin, int type, int idx, bool sd);
typedef RList *(*RBinGetSections)(RBin *bin);
typedef RBinSection *(*RBinGetSectionAt)(RBin *bin, ut64 addr);
typedef char *(*RBinDemangle)(RBinFile *bf, const char *def, const char *str, ut64 vaddr, bool libs);
typedef struct r_bin_bind_t {
RBin *bin;
RBinGetOffset get_offset;
RBinGetName get_name;
RBinGetSections get_sections;
RBinGetSectionAt get_vsect_at;
RBinDemangle demangle;
ut32 visibility;
} RBinBind;
R_IPI RBinSection *r_bin_section_new(const char *name);
R_IPI void r_bin_section_free(RBinSection *bs);
R_API void r_bin_info_free(RBinInfo *rb);
R_API void r_bin_import_free(void *_imp);
R_API void r_bin_symbol_free(void *_sym);
R_API RBinSymbol *r_bin_symbol_new(const char *name, ut64 paddr, ut64 vaddr);
R_API void r_bin_string_free(void *_str);
#ifdef R_API
2012-08-26 11:07:09 +02:00
typedef struct r_bin_options_t {
const char *pluginname;
ut64 baseaddr; // where the linker maps the binary in memory
ut64 loadaddr; // starting physical address to read from the target file
ut64 sz;
int xtr_idx; // load Nth binary
int rawstr;
int fd;
const char *filename;
} RBinOptions;
R_API RBinImport *r_bin_import_clone(RBinImport *o);
R_API const char *r_bin_symbol_name(RBinSymbol *s);
typedef void (*RBinSymbolCallback)(RBinObject *obj, RBinSymbol *symbol);
// options functions
R_API void r_bin_options_init(RBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, int rawstr);
R_API void r_bin_arch_options_init(RBinArchOptions *opt, const char *arch, int bits);
// open/close/reload functions
R_API RBin *r_bin_new(void);
R_API void r_bin_free(RBin *bin);
R_API bool r_bin_open(RBin *bin, const char *file, RBinOptions *opt);
R_API bool r_bin_open_io(RBin *bin, RBinOptions *opt);
R_API bool r_bin_open_buf(RBin *bin, RBuffer *buf, RBinOptions *opt);
R_API bool r_bin_reload(RBin *bin, ut32 bf_id, ut64 baseaddr);
// plugins/bind functions
R_API void r_bin_bind(RBin *b, RBinBind *bnd);
R_API bool r_bin_add(RBin *bin, RBinPlugin *foo);
R_API bool r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo);
R_API bool r_bin_ldr_add(RBin *bin, RBinLdrPlugin *foo);
2021-01-02 17:48:49 -05:00
R_API void r_bin_list(RBin *bin, PJ *pj, int format);
R_API bool r_bin_list_plugin(RBin *bin, const char *name, PJ *pj, int json);
R_API RBinPlugin *r_bin_get_binplugin_by_bytes(RBin *bin, const ut8 *bytes, ut64 sz);
R_API RBinPlugin *r_bin_get_binplugin_by_buffer(RBin *bin, RBuffer *buf);
R_API void r_bin_force_plugin(RBin *bin, const char *pname);
// get/set various bin information
R_API ut64 r_bin_get_baddr(RBin *bin);
R_API ut64 r_bin_file_get_baddr(RBinFile *bf);
R_API void r_bin_set_user_ptr(RBin *bin, void *user);
R_API RBinInfo *r_bin_get_info(RBin *bin);
R_API void r_bin_set_baddr(RBin *bin, ut64 baddr);
R_API ut64 r_bin_get_laddr(RBin *bin);
R_API ut64 r_bin_get_size(RBin *bin);
R_API RBinAddr *r_bin_get_sym(RBin *bin, int sym);
2018-06-17 15:12:54 +02:00
R_API RList *r_bin_raw_strings(RBinFile *a, int min);
2018-08-09 20:17:43 +01:00
R_API RList *r_bin_dump_strings(RBinFile *a, int min, int raw);
// use RBinFile instead
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);
R_API RList *r_bin_get_libs(RBin *bin);
R_API RBNode *r_bin_patch_relocs(RBin *bin);
R_API RList *r_bin_patch_relocs_list(RBin *bin);
R_API RBNode *r_bin_get_relocs(RBin *bin);
R_API RList *r_bin_get_relocs_list(RBin *bin);
R_API RList *r_bin_get_sections(RBin *bin);
R_API RList *r_bin_get_classes(RBin *bin);
R_API RList *r_bin_get_strings(RBin *bin);
R_API RList *r_bin_file_get_trycatch(RBinFile *bf);
R_API RList *r_bin_get_symbols(RBin *bin);
R_API RList *r_bin_reset_strings(RBin *bin);
R_API int r_bin_is_string(RBin *bin, ut64 va);
R_API int r_bin_is_big_endian(RBin *bin);
R_API int r_bin_is_static(RBin *bin);
R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr);
R_API ut64 r_bin_file_get_vaddr(RBinFile *bf, ut64 paddr, ut64 vaddr);
R_API ut64 r_bin_a2b(RBin *bin, ut64 addr);
R_API int r_bin_load_languages(RBinFile *binfile);
R_API RBinFile *r_bin_cur(RBin *bin);
R_API RBinObject *r_bin_cur_object(RBin *bin);
// select/list binfiles functions
R_API bool r_bin_select(RBin *bin, const char *arch, int bits, const char *name);
R_API bool r_bin_select_bfid(RBin *bin, ut32 bf_id);
R_API bool r_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name);
2021-01-02 17:48:49 -05:00
R_API void r_bin_list_archs(RBin *bin, PJ *pj, int mode);
R_API RBuffer *r_bin_create(RBin *bin, const char *plugin_name, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt);
R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RList *files);
R_API const char *r_bin_string_type(int type);
R_API const char *r_bin_entry_type_string(int etype);
2015-08-24 00:30:05 +02:00
R_API bool r_bin_file_object_new_from_xtr_data(RBin *bin, RBinFile *bf, ut64 baseaddr, ut64 loadaddr, RBinXtrData *data);
// RBinFile lifecycle
// R_IPI RBinFile *r_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr);
R_API bool r_bin_file_close(RBin *bin, int bd);
R_API void r_bin_file_free(void /*RBinFile*/ *bf_);
// RBinFile.get
R_API RBinFile *r_bin_file_at(RBin *bin, ut64 addr);
R_API RBinFile *r_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id);
R_API RList *r_bin_file_get_symbols(RBinFile *bf);
//
R_API ut64 r_bin_file_get_vaddr(RBinFile *bf, ut64 paddr, ut64 vaddr);
// RBinFile.add
R_API RBinClass *r_bin_file_add_class(RBinFile *binfile, const char *name, const char *super, int view);
R_API RBinSymbol *r_bin_file_add_method(RBinFile *bf, const char *classname, const char *name, int nargs);
R_API RBinField *r_bin_file_add_field(RBinFile *binfile, const char *classname, const char *name);
// RBinFile.find
R_API RBinFile *r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits);
R_API RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 bin_id);
R_API RBinFile *r_bin_file_find_by_fd(RBin *bin, ut32 bin_fd);
R_API RBinFile *r_bin_file_find_by_name(RBin *bin, const char *name);
R_API bool r_bin_file_set_cur_binfile(RBin *bin, RBinFile *bf);
R_API bool r_bin_file_set_cur_by_name(RBin *bin, const char *name);
R_API bool r_bin_file_deref(RBin *bin, RBinFile *a);
R_API bool r_bin_file_set_cur_by_fd(RBin *bin, ut32 bin_fd);
R_API bool r_bin_file_set_cur_by_id(RBin *bin, ut32 bin_id);
R_API bool r_bin_file_set_cur_by_name(RBin *bin, const char *name);
2019-06-07 13:53:14 +02:00
R_API ut64 r_bin_file_delete_all(RBin *bin);
R_API bool r_bin_file_delete(RBin *bin, ut32 bin_id);
R_API RList *r_bin_file_compute_hashes(RBin *bin, ut64 limit);
R_API RList *r_bin_file_set_hashes(RBin *bin, RList *new_hashes);
R_API RBinPlugin *r_bin_file_cur_plugin(RBinFile *binfile);
R_API void r_bin_file_hash_free(RBinFileHash *fhash);
2018-10-02 00:46:25 +02:00
// binobject functions
R_API int r_bin_object_set_items(RBinFile *binfile, RBinObject *o);
R_API bool r_bin_object_delete(RBin *bin, ut32 binfile_id);
R_API void r_bin_mem_free(void *data);
// demangle functions
R_API char *r_bin_demangle(RBinFile *binfile, const char *lang, const char *str, ut64 vaddr, bool libs);
R_API char *r_bin_demangle_java(const char *str);
R_API char *r_bin_demangle_cxx(RBinFile *binfile, const char *str, ut64 vaddr);
2015-02-19 19:39:55 +02:00
R_API char *r_bin_demangle_msvc(const char *str);
R_API char *r_bin_demangle_swift(const char *s, bool syscmd);
R_API char *r_bin_demangle_objc(RBinFile *binfile, const char *sym);
R_API char *r_bin_demangle_rust(RBinFile *binfile, const char *str, ut64 vaddr);
R_API int r_bin_demangle_type(const char *str);
R_API void r_bin_demangle_list(RBin *bin);
R_API char *r_bin_demangle_plugin(RBin *bin, const char *name, const char *str);
R_API const char *r_bin_get_meth_flag_string(ut64 flag, bool compact);
R_API RBinSection *r_bin_get_section_at(RBinObject *o, ut64 off, int va);
2014-03-10 02:27:32 +01:00
/* dbginfo.c */
R_API bool r_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line);
R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin);
2014-03-10 02:27:32 +01:00
R_API char *r_bin_addr2fileline(RBin *bin, ut64 addr);
/* bin_write.c */
2016-04-07 15:42:06 +02:00
R_API bool r_bin_wr_addlib(RBin *bin, const char *lib);
R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size);
2015-11-27 20:35:40 +01:00
R_API bool r_bin_wr_scn_perms(RBin *bin, const char *name, int perms);
R_API bool r_bin_wr_rpath_del(RBin *bin);
R_API bool r_bin_wr_entry(RBin *bin, ut64 addr);
2017-09-03 17:59:53 -07:00
R_API bool r_bin_wr_output(RBin *bin, const char *filename);
R_API RList *r_bin_get_mem(RBin *bin);
/* filter.c */
R_API void r_bin_load_filter(RBin *bin, ut64 rules);
R_API void r_bin_filter_symbols(RBinFile *bf, RList *list);
R_API void r_bin_filter_sections(RBinFile *bf, RList *list);
R_API char *r_bin_filter_name(RBinFile *bf, Sdb *db, ut64 addr, char *name);
R_API void r_bin_filter_sym(RBinFile *bf, HtPP *ht, ut64 vaddr, RBinSymbol *sym);
R_API bool r_bin_strpurge(RBin *bin, const char *str, ut64 addr);
R_API bool r_bin_string_filter(RBin *bin, const char *str, ut64 addr);
/* plugin pointers */
extern RBinPlugin r_bin_plugin_any;
extern RBinPlugin r_bin_plugin_fs;
2015-09-08 20:35:57 +02:00
extern RBinPlugin r_bin_plugin_cgc;
extern RBinPlugin r_bin_plugin_elf;
extern RBinPlugin r_bin_plugin_elf64;
extern RBinPlugin r_bin_plugin_p9;
extern RBinPlugin r_bin_plugin_ne;
extern RBinPlugin r_bin_plugin_le;
extern RBinPlugin r_bin_plugin_pe;
extern RBinPlugin r_bin_plugin_mz;
extern RBinPlugin r_bin_plugin_pe64;
2014-11-30 16:53:36 +01:00
extern RBinPlugin r_bin_plugin_pebble;
2013-06-09 02:11:17 +02:00
extern RBinPlugin r_bin_plugin_bios;
extern RBinPlugin r_bin_plugin_bf;
2013-03-03 03:09:51 +04:00
extern RBinPlugin r_bin_plugin_te;
extern RBinPlugin r_bin_plugin_symbols;
extern RBinPlugin r_bin_plugin_mach0;
extern RBinPlugin r_bin_plugin_mach064;
extern RBinPlugin r_bin_plugin_mdmp;
extern RBinPlugin r_bin_plugin_java;
extern RBinPlugin r_bin_plugin_dex;
2014-02-17 00:02:47 +04:00
extern RBinPlugin r_bin_plugin_coff;
2014-09-24 23:51:40 +02:00
extern RBinPlugin r_bin_plugin_ningb;
extern RBinPlugin r_bin_plugin_ningba;
2014-09-24 23:51:40 +02:00
extern RBinPlugin r_bin_plugin_ninds;
extern RBinPlugin r_bin_plugin_nin3ds;
2014-05-26 20:07:24 +02:00
extern RBinPlugin r_bin_plugin_xbe;
extern RBinPlugin r_bin_plugin_bflt;
extern RBinXtrPlugin r_bin_xtr_plugin_xtr_fatmach0;
2016-02-04 15:44:49 +01:00
extern RBinXtrPlugin r_bin_xtr_plugin_xtr_dyldcache;
extern RBinXtrPlugin r_bin_xtr_plugin_xtr_pemixed;
2019-12-13 15:49:35 +01:00
extern RBinXtrPlugin r_bin_xtr_plugin_xtr_sep64;
extern RBinLdrPlugin r_bin_ldr_plugin_ldr_linux;
2015-04-06 21:48:21 -04:00
extern RBinPlugin r_bin_plugin_zimg;
extern RBinPlugin r_bin_plugin_omf;
extern RBinPlugin r_bin_plugin_art;
extern RBinPlugin r_bin_plugin_bootimg;
extern RBinPlugin r_bin_plugin_dol;
2015-09-19 20:48:38 +02:00
extern RBinPlugin r_bin_plugin_nes;
extern RBinPlugin r_bin_plugin_qnx;
extern RBinPlugin r_bin_plugin_mbn;
extern RBinPlugin r_bin_plugin_smd;
2015-10-27 09:19:34 +08:00
extern RBinPlugin r_bin_plugin_sms;
extern RBinPlugin r_bin_plugin_psxexe;
Adds VSF (VICE Snapshot File) support as a bin format VICE is the most popular C64/C128 emulator and allows users to save snapshots of the games. Analyzing VICE snapshots are more useful than analyzing .prg (the "standard" c64 program) because usually all .prg are compressed, and are decompressed in runtime. commit 796297c6cd3a099fd17ad3715b4ed5646a6a9e65 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Nov 27 12:28:58 2015 -0800 no sbd for the moment commit c785b22318c3cacf7771ab21198aa759777224af Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Nov 27 10:06:12 2015 -0800 bank 0 and bank 1 commit 63304876b6f84df001c39f5b35084ff6e61bc01b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Nov 27 09:47:12 2015 -0800 c128 includes basic, monitor and editor sections commit 1a8995a644df6d9e871a586e57c3cd8e00cce7ae Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Nov 26 14:45:36 2015 -0800 c128 roms... uses sdb which is not used at all more vic symbols commit 8a29c3c7736fcf689b9248e65093277347ae38bc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Nov 24 10:39:44 2015 -0800 ram last entry commit fca46301b2fd68e230cf547047a5278e098c9340 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Nov 24 00:10:20 2015 -0800 more tidy code commit 03b8a12b319bd0eb9f21b60d882da2030c2c35f1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Nov 23 22:52:20 2015 -0800 VSF works for C64... still many things to fix commit a118a930cb40441b412db916deb4c0ca30e30309 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Nov 23 13:37:32 2015 -0800 initial commit... compiles and detects VICE but nothing more
2015-11-27 13:42:08 -08:00
extern RBinPlugin r_bin_plugin_vsf;
2016-02-04 15:44:49 +01:00
extern RBinPlugin r_bin_plugin_dyldcache;
extern RBinPlugin r_bin_plugin_xnu_kernelcache;
extern RBinPlugin r_bin_plugin_avr;
2016-11-03 23:38:15 +01:00
extern RBinPlugin r_bin_plugin_menuet;
extern RBinPlugin r_bin_plugin_wasm;
extern RBinPlugin r_bin_plugin_nro;
extern RBinPlugin r_bin_plugin_nso;
extern RBinPlugin r_bin_plugin_sfc;
2018-01-10 23:20:18 +01:00
extern RBinPlugin r_bin_plugin_z64;
extern RBinPlugin r_bin_plugin_prg;
extern RBinPlugin r_bin_plugin_dmp64;
2020-05-13 10:37:09 +08:00
extern RBinPlugin r_bin_plugin_pyc;
#ifdef __cplusplus
}
#endif
#endif
#endif