13 #ifndef _INCLUDE_ELF_H_
14 #define _INCLUDE_ELF_H_
16 #define RZ_BIN_ELF_SCN_IS_EXECUTABLE(x) x &SHF_EXECINSTR
17 #define RZ_BIN_ELF_SCN_IS_READABLE(x) x &SHF_ALLOC
18 #define RZ_BIN_ELF_SCN_IS_WRITABLE(x) x &SHF_WRITE
20 #define RZ_BIN_ELF_NO_RELRO 0
21 #define RZ_BIN_ELF_PART_RELRO 1
22 #define RZ_BIN_ELF_FULL_RELRO 2
24 #define ELFOBJ struct Elf_(rz_bin_elf_obj_t)
26 #define rz_bin_elf_foreach_segments(bin, segment) \
27 if (Elf_(rz_bin_elf_has_segments)(bin)) \
28 rz_vector_foreach((bin)->segments, segment)
30 #define rz_bin_elf_foreach_sections(bin, section) \
31 if (Elf_(rz_bin_elf_has_sections)(bin)) \
32 rz_vector_foreach((bin)->sections, section)
34 #define rz_bin_elf_enumerate_sections(bin, section, i) \
35 if (Elf_(rz_bin_elf_has_sections)(bin)) \
36 rz_vector_enumerate((bin)->sections, section, i)
38 #define rz_bin_elf_foreach_relocs(bin, reloc) \
39 if (Elf_(rz_bin_elf_has_relocs)(bin)) \
40 rz_vector_foreach((bin)->relocs, reloc)
42 #define rz_bin_elf_foreach_notes_segment(bin, notes) \
43 if (Elf_(rz_bin_elf_has_notes)(bin)) \
44 rz_vector_foreach((bin)->notes, notes)
46 #define rz_bin_elf_foreach_symbols(bin, symbol) \
47 if (Elf_(rz_bin_elf_has_symbols)(bin)) \
48 rz_vector_foreach(bin->symbols, symbol)
50 #define rz_bin_elf_foreach_imports(bin, import) \
51 if (Elf_(rz_bin_elf_has_imports)(bin)) \
52 rz_vector_foreach(bin->imports, import)
127 typedef struct Elf_(rz_bin_elf_segment_t) {
159 typedef struct Elf_(rz_bin_elf_note_file_t) {
160 Elf_(Addr) start_vaddr;
161 Elf_(Addr) end_vaddr;
175 typedef struct Elf_(rz_bin_elf_note_t) {
186 struct Elf_(rz_bin_elf_obj_t) {
228 #define rz_bin_elf_fix_arm_thumb_object_dispatch(object) \
229 Elf_(rz_bin_elf_fix_arm_thumb_object)(&object->paddr, &object->vaddr, &object->bits)
static bool is_valid(arm_reg reg)
static ut64 baddr(RzBinFile *bf)
RzBinInfo * info(RzBinFile *bf)
RzList * symbols(RzBinFile *bf)
RzList * imports(RzBinFile *bf)
RzList * sections(RzBinFile *bf)
RzList * relocs(RzBinFile *bf)
static ut64 boffset(RzBinFile *bf)
int bits(struct state *s, int need)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
RZ_OWN RzVector *Elf_() rz_bin_elf_relocs_new(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_is_big_endian(RZ_NONNULL ELFOBJ *bin)
Check the binary endianness.
RZ_OWN char *Elf_() rz_bin_elf_get_e_type_as_string(RZ_NONNULL ELFOBJ *bin)
bool(* RzBinElfSymbolFilter)(ELFOBJ *bin, Elf_(Sym) *entry, bool is_dynamic)
size_t Elf_() rz_bin_elf_get_number_of_symbols_from_hash_table(RZ_NONNULL ELFOBJ *bin)
RZ_OWN Sdb *Elf_() rz_bin_elf_get_symbols_info(RZ_NONNULL ELFOBJ *bin)
size_t Elf_() rz_bin_elf_get_relocs_count(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_get_e_ehsize_as_string(RZ_NONNULL ELFOBJ *bin)
RZ_BORROW RzBinElfSymbol *Elf_() rz_bin_elf_get_symbol(RZ_NONNULL ELFOBJ *bin, ut32 ordinal)
bool Elf_() rz_bin_elf_get_ehdr(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_is_static(RZ_NONNULL ELFOBJ *bin)
Check if the binary is statically-linked library.
bool Elf_() rz_bin_elf_is_stripped(RZ_NONNULL ELFOBJ *bin)
Check if the binary is stripped.
bool Elf_() rz_bin_elf_read_word_xword(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Word) *result)
bool Elf_() rz_bin_elf_strtab_has_index(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
void Elf_() rz_bin_elf_fix_arm_thumb_symbol(RZ_NONNULL RzBinSymbol *symbol)
bool Elf_() rz_bin_elf_add_off(Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
RZ_OWN char *Elf_() rz_bin_elf_get_file_type(RZ_NONNULL ELFOBJ *bin)
Return a string representing the file type.
RZ_BORROW RzBinElfSymbol *Elf_() rz_bin_elf_get_import(RZ_NONNULL ELFOBJ *bin, ut32 ordinal)
bool Elf_() rz_bin_elf_is_executable(RZ_NONNULL ELFOBJ *bin)
Check if the elf binary is executable.
bool Elf_() rz_bin_elf_get_gnu_hash_table(RZ_NONNULL ELFOBJ *bin, RzBinElfGnuHashTable *result)
RZ_OWN char *Elf_() rz_bin_elf_get_e_phnum_as_string(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_mul_off(Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
RZ_OWN char *Elf_() rz_bin_elf_get_e_shstrndx_as_string(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_has_dt_dynamic(RZ_NONNULL ELFOBJ *bin)
ut64 Elf_() rz_bin_elf_get_main_offset(RZ_NONNULL ELFOBJ *bin)
Compute the main offset of the binary.
ut64 Elf_() rz_bin_elf_p2v(RZ_NONNULL ELFOBJ *bin, ut64 paddr)
Convert a physical address to the virtual address.
bool Elf_() rz_bin_elf_has_va(ELFOBJ *bin)
Check if the elf use virtual address.
bool Elf_() rz_bin_elf_read_addr(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Addr) *result)
RZ_OWN char *Elf_() rz_bin_elf_get_elf_class(RZ_NONNULL ELFOBJ *bin)
Return a string representing the elf class.
void Elf_() rz_bin_elf_dt_dynamic_free(RzBinElfDtDynamic *ptr)
bool Elf_() rz_bin_elf_read_char(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT ut8 *result)
bool Elf_() rz_bin_elf_has_relocs(RZ_NONNULL ELFOBJ *bin)
struct rz_bin_elf_gnu_hash_table_t RzBinElfGnuHashTable
RZ_BORROW RzBinElfSection *Elf_() rz_bin_elf_get_section(RZ_NONNULL ELFOBJ *bin, Elf_(Half) index)
bool Elf_() rz_bin_elf_has_nx(RZ_NONNULL ELFOBJ *bin)
Check if the stack is not executable.
struct prstatus_layout_t RzBinElfPrStatusLayout
Information about the binary layout in a NT_PRSTATUS note for core files of a certain architecture an...
bool Elf_() rz_bin_elf_is_arm_binary_supporting_thumb(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_get_intrp(RZ_NONNULL ELFOBJ *bin)
Get the program interpreter.
struct rz_bin_elf_symbol_t RzBinElfSymbol
RZ_OWN RzBinElfDtDynamic *Elf_() rz_bin_elf_dt_dynamic_new(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_read_off(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Off) *result)
RZ_OWN char *Elf_() rz_bin_elf_get_e_entry_as_string(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_get_abi(RZ_NONNULL ELFOBJ *bin)
Return a string representing the application binary interface.
void Elf_() rz_bin_elf_fix_arm_thumb_addr(ut64 *addr)
RZ_OWN char *Elf_() rz_bin_elf_get_e_shoff_as_string(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_is_thumb_addr(ut64 addr)
ut64 Elf_() rz_bin_elf_get_baddr(RZ_NONNULL ELFOBJ *bin)
Compute the base address of the binary.
bool Elf_() rz_bin_elf_read_sxword(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Sxword) *result)
bool Elf_() rz_bin_elf_read_word(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Word) *result)
RZ_OWN char *Elf_() rz_bin_elf_get_machine_name(RZ_NONNULL ELFOBJ *bin)
Return a string representing the machine name.
RZ_OWN char *Elf_() rz_bin_elf_get_e_shentsize_as_string(RZ_NONNULL ELFOBJ *bin)
struct rz_bin_elf_section_t RzBinElfSection
RZ_OWN RzList *Elf_() rz_bin_elf_get_libs(RZ_NONNULL ELFOBJ *bin)
List all imported lib.
bool Elf_() rz_bin_elf_has_imports(RZ_NONNULL ELFOBJ *bin)
struct rz_bin_elf_note_prstatus_t RzBinElfNotePrStatus
Parsed PT_NOTE of type NT_PRSTATUS.
void Elf_() rz_bin_elf_free(RZ_NONNULL ELFOBJ *bin)
Free the elf binary.
RZ_OWN RzVector *Elf_() rz_bin_elf_compute_symbols(ELFOBJ *bin, RzBinElfSymbolFilter filter)
bool Elf_() rz_bin_elf_read_xword(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Xword) *result)
RZ_OWN RzVector *Elf_() rz_bin_elf_symbols_new(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_has_notes(RZ_NONNULL ELFOBJ *bin)
RZ_BORROW RzBinElfSection *Elf_() rz_bin_elf_get_section_with_name(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL const char *name)
bool Elf_() rz_bin_elf_read_half(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Half) *result)
ut64 Elf_() rz_bin_elf_get_targets_map_base(ELFOBJ *bin)
RZ_OWN RzVector *Elf_() rz_bin_elf_sections_new(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_get_e_machine_as_string(RZ_NONNULL ELFOBJ *bin)
RZ_OWN RzBinElfStrtab *Elf_() rz_bin_elf_strtab_new(RZ_NONNULL ELFOBJ *bin, ut64 offset, ut64 size)
void Elf_() rz_bin_elf_strtab_free(RzBinElfStrtab *ptr)
bool Elf_() rz_bin_elf_read_section(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Section) *result)
bool Elf_() rz_bin_elf_read_sword_sxword(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Sword) *result)
bool Elf_() rz_bin_elf_get_dt_info(RZ_NONNULL ELFOBJ *bin, ut64 key, RZ_OUT ut64 *info)
struct rz_bin_elf_reloc_t RzBinElfReloc
RZ_OWN char *Elf_() rz_bin_elf_get_rpath(RZ_NONNULL ELFOBJ *bin)
Get the rpath.
RZ_OWN char *Elf_() rz_bin_elf_get_e_flags_as_string(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_get_arch(RZ_NONNULL ELFOBJ *bin)
Get the elf binary architecture.
RZ_OWN ELFOBJ *Elf_() rz_bin_elf_new_buf(RZ_NONNULL RzBuffer *buf, RZ_NONNULL RzBinObjectLoadOptions *options)
bool Elf_() rz_bin_elf_read_versym(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Versym) *result)
RZ_BORROW RzVector *Elf_() rz_bin_elf_get_dt_needed(RZ_NONNULL ELFOBJ *bin)
RZ_OWN RzVector *Elf_() rz_bin_elf_segments_new(RZ_NONNULL ELFOBJ *bin, RzVector *sections, RZ_NONNULL RzBinObjectLoadOptions *options)
ut64 Elf_() rz_bin_elf_get_num_relocs_dynamic_plt(RZ_NONNULL ELFOBJ *bin)
RZ_OWN RzVector *Elf_() rz_bin_elf_analyse_imports(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_section_type_to_string(ut64 type)
Return a string representing the elf type.
struct Elf_(rz_bin_elf_segment_t)
RZ_OWN char *Elf_() rz_bin_elf_get_e_version_as_string(RZ_NONNULL ELFOBJ *bin)
int Elf_() rz_bin_elf_get_bits(RZ_NONNULL ELFOBJ *bin)
Return the elf bits.
RZ_OWN RzVector *Elf_() rz_bin_elf_notes_new(RZ_NONNULL ELFOBJ *bin)
RZ_OWN RzVector *Elf_() rz_bin_elf_convert_sections(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RzBinObjectLoadOptions *options, RzVector *sections)
bool Elf_() rz_bin_elf_has_segments(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_add_addr(Elf_(Addr) *result, Elf_(Addr) addr, Elf_(Addr) value)
bool Elf_() rz_bin_elf_has_sections(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_get_head_flag(RZ_NONNULL ELFOBJ *bin)
Return the head flag.
bool Elf_() rz_bin_elf_mul_addr(Elf_(Addr) *result, Elf_(Addr) addr, Elf_(Addr) value)
bool Elf_() rz_bin_elf_get_hash_table(RZ_NONNULL ELFOBJ *bin, RzBinElfHashTable *result)
bool Elf_() rz_bin_elf_is_relocatable(RZ_NONNULL ELFOBJ *bin)
Check if the elf binary is relocatable.
RZ_OWN char *Elf_() rz_bin_elf_get_e_phoff_as_string(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_get_osabi_name(RZ_NONNULL ELFOBJ *bin)
Return the os application binary interface name.
ut64 Elf_() rz_bin_elf_get_init_offset(RZ_NONNULL ELFOBJ *bin)
Compute the init offset of the binary.
RZ_OWN char *Elf_() rz_bin_elf_strtab_get_dup(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
bool Elf_() rz_bin_elf_read_sword(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Sword) *result)
RZ_BORROW RzBinElfPrStatusLayout *Elf_() rz_bin_elf_get_prstatus_layout(RZ_NONNULL ELFOBJ *bin)
size_t Elf_() rz_bin_elf_get_number_of_symbols_from_gnu_hash_table(RZ_NONNULL ELFOBJ *bin)
bool Elf_() rz_bin_elf_has_symbols(RZ_NONNULL ELFOBJ *bin)
ut64 Elf_() rz_bin_elf_get_entry_offset(RZ_NONNULL ELFOBJ *bin)
Get the entry offset.
ut64 Elf_() rz_bin_elf_get_boffset(RZ_NONNULL ELFOBJ *bin)
Compute the base offset of the binary.
int Elf_() rz_bin_elf_has_relro(RZ_NONNULL ELFOBJ *bin)
Analyse if the elf binary has relro or partial relro.
RZ_OWN char *Elf_() rz_bin_elf_get_e_indent_as_string(RZ_NONNULL ELFOBJ *bin)
RZ_OWN char *Elf_() rz_bin_elf_get_cpu(RZ_NONNULL ELFOBJ *bin)
Return a string representing the cpu.
RZ_OWN char *Elf_() rz_bin_elf_get_e_shnum_as_string(RZ_NONNULL ELFOBJ *bin)
ut64 Elf_() rz_bin_elf_v2p(RZ_NONNULL ELFOBJ *bin, ut64 vaddr)
Convert a virtual address to the physical address.
ut64 Elf_() rz_bin_elf_get_sp_val(RZ_NONNULL ELFOBJ *bin)
Get the stack pointer value.
RZ_BORROW const char *Elf_() rz_bin_elf_strtab_get(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
struct rz_bin_elf_hash_table_ RzBinElfHashTable
RZ_OWN char *Elf_() rz_bin_elf_get_compiler(RZ_NONNULL ELFOBJ *bin)
Get the compiler info from the .comment section.
RZ_BORROW RzBinElfSegment *Elf_() rz_bin_elf_get_segment_with_type(RZ_NONNULL ELFOBJ *bin, Elf_(Word) type)
bool Elf_() rz_bin_elf_print_ehdr(ELFOBJ *bin, RZ_NONNULL PrintfCallback cb)
RZ_OWN RzList *Elf_() rz_bin_elf_section_flag_to_rzlist(ut64 flag)
Return a list of string representing flag options.
void Elf_() rz_bin_elf_fix_arm_thumb_object(RZ_NONNULL ut64 *paddr, RZ_NONNULL ut64 *vaddr, RZ_NONNULL int *bits)
bool Elf_() rz_bin_elf_check_array(RZ_NONNULL ELFOBJ *bin, Elf_(Off) offset, Elf_(Off) length, Elf_(Off) entry_size)
RZ_OWN char *Elf_() rz_bin_elf_get_e_phentsize_as_string(RZ_NONNULL ELFOBJ *bin)
ut64 Elf_() rz_bin_elf_get_fini_offset(RZ_NONNULL ELFOBJ *bin)
Compute the fini offset of the binary.
static const char struct stat static buf struct stat static buf static vhangup int options
RZ_API ut64 MACH0_() reloc_targets_map_base(RzBinFile *bf, struct MACH0_(obj_t) *obj)
base vaddr where to map the artificial reloc target vfile
static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
Information about the binary layout in a NT_PRSTATUS note for core files of a certain architecture an...
ut8 sp_size
Size of the stack pointer register in bits.
struct gnu_hash_table data
struct elf_hash_table data
Parsed PT_NOTE of type NT_PRSTATUS.
st64 addend
exact addend value taken from the ELF, meaning depends on type
ut64 offset
exact offset value taken from the ELF, meaning depends on the binary type
ut64 target_vaddr
after patching, the target that this reloc points to
ut64 vaddr
source vaddr of the reloc, calculated from offset
ut64 paddr
absolute paddr in the file, calculated from offset, or UT64_MAX if no such addr exists
ut64(WINAPI *w32_GetEnabledXStateFeatures)()