Rizin
unix-like reverse engineering framework and cli tools
elf.h File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>
#include "elf_specs.h"

Go to the source code of this file.

Classes

struct  gnu_hash_table
 
struct  rz_bin_elf_gnu_hash_table_t
 
struct  elf_hash_table
 
struct  rz_bin_elf_hash_table_
 
struct  prstatus_layout_t
 Information about the binary layout in a NT_PRSTATUS note for core files of a certain architecture and os. More...
 
struct  rz_bin_elf_section_t
 
struct  rz_bin_elf_symbol_t
 
struct  rz_bin_elf_reloc_t
 
struct  rz_bin_elf_note_prstatus_t
 Parsed PT_NOTE of type NT_PRSTATUS. More...
 

Macros

#define RZ_BIN_ELF_SCN_IS_EXECUTABLE(x)   x &SHF_EXECINSTR
 
#define RZ_BIN_ELF_SCN_IS_READABLE(x)   x &SHF_ALLOC
 
#define RZ_BIN_ELF_SCN_IS_WRITABLE(x)   x &SHF_WRITE
 
#define RZ_BIN_ELF_NO_RELRO   0
 
#define RZ_BIN_ELF_PART_RELRO   1
 
#define RZ_BIN_ELF_FULL_RELRO   2
 
#define ELFOBJ   struct Elf_(rz_bin_elf_obj_t)
 
#define rz_bin_elf_foreach_segments(bin, segment)
 
#define rz_bin_elf_foreach_sections(bin, section)
 
#define rz_bin_elf_enumerate_sections(bin, section, i)
 
#define rz_bin_elf_foreach_relocs(bin, reloc)
 
#define rz_bin_elf_foreach_notes_segment(bin, notes)
 
#define rz_bin_elf_foreach_symbols(bin, symbol)
 
#define rz_bin_elf_foreach_imports(bin, import)
 
#define rz_bin_elf_fix_arm_thumb_object_dispatch(object)    Elf_(rz_bin_elf_fix_arm_thumb_object)(&object->paddr, &object->vaddr, &object->bits)
 

Typedefs

typedef struct rz_bin_elf_gnu_hash_table_t RzBinElfGnuHashTable
 
typedef struct rz_bin_elf_hash_table_ RzBinElfHashTable
 
typedef struct prstatus_layout_t RzBinElfPrStatusLayout
 Information about the binary layout in a NT_PRSTATUS note for core files of a certain architecture and os. More...
 
typedef struct rz_bin_elf_section_t RzBinElfSection
 
typedef struct rz_bin_elf_symbol_t RzBinElfSymbol
 
typedef struct rz_bin_elf_reloc_t RzBinElfReloc
 
typedef struct rz_bin_elf_dt_dynamic_t RzBinElfDtDynamic
 
typedef struct rz_bin_elf_note_prstatus_t RzBinElfNotePrStatus
 Parsed PT_NOTE of type NT_PRSTATUS. More...
 
typedef struct rz_bin_elf_strtab RzBinElfStrtab
 
typedef bool(* RzBinElfSymbolFilter) (ELFOBJ *bin, Elf_(Sym) *entry, bool is_dynamic)
 

Functions

struct Elf_ (rz_bin_elf_segment_t)
 
struct Elf_ (rz_bin_elf_note_file_t)
 A single file entry in a PT_NOTE of type NT_FILE. More...
 
struct Elf_ (rz_bin_elf_note_t)
 A single PT_NOTE entry, parsed from an ElfW(Nhdr) and associated data. More...
 
struct Elf_ (rz_bin_elf_obj_t)
 
RZ_OWN ELFOBJ *Elf_() rz_bin_elf_new_buf (RZ_NONNULL RzBuffer *buf, RZ_NONNULL RzBinObjectLoadOptions *options)
 
void Elf_() rz_bin_elf_free (RZ_NONNULL ELFOBJ *bin)
 Free the elf binary. More...
 
ut64 Elf_() rz_bin_elf_p2v (RZ_NONNULL ELFOBJ *bin, ut64 paddr)
 Convert a physical address to the virtual address. More...
 
ut64 Elf_() rz_bin_elf_v2p (RZ_NONNULL ELFOBJ *bin, ut64 vaddr)
 Convert a virtual address to the physical address. More...
 
bool Elf_() rz_bin_elf_is_arm_binary_supporting_thumb (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_is_thumb_addr (ut64 addr)
 
void Elf_() rz_bin_elf_fix_arm_thumb_addr (ut64 *addr)
 
void Elf_() rz_bin_elf_fix_arm_thumb_object (RZ_NONNULL ut64 *paddr, RZ_NONNULL ut64 *vaddr, RZ_NONNULL int *bits)
 
void Elf_() rz_bin_elf_fix_arm_thumb_symbol (RZ_NONNULL RzBinSymbol *symbol)
 
ut64 Elf_() rz_bin_elf_get_sp_val (RZ_NONNULL ELFOBJ *bin)
 Get the stack pointer value. More...
 
RZ_BORROW RzVector *Elf_() rz_bin_elf_get_dt_needed (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN RzBinElfDtDynamic *Elf_() rz_bin_elf_dt_dynamic_new (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_get_dt_info (RZ_NONNULL ELFOBJ *bin, ut64 key, RZ_OUT ut64 *info)
 
bool Elf_() rz_bin_elf_has_dt_dynamic (RZ_NONNULL ELFOBJ *bin)
 
void Elf_() rz_bin_elf_dt_dynamic_free (RzBinElfDtDynamic *ptr)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_ehsize_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_entry_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_flags_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_indent_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_machine_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_phentsize_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_phnum_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_phoff_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_shentsize_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_shnum_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_shoff_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_shstrndx_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_type_as_string (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_get_e_version_as_string (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_get_ehdr (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_print_ehdr (ELFOBJ *bin, RZ_NONNULL PrintfCallback cb)
 
bool Elf_() rz_bin_elf_get_gnu_hash_table (RZ_NONNULL ELFOBJ *bin, RzBinElfGnuHashTable *result)
 
bool Elf_() rz_bin_elf_get_hash_table (RZ_NONNULL ELFOBJ *bin, RzBinElfHashTable *result)
 
size_t Elf_() rz_bin_elf_get_number_of_symbols_from_gnu_hash_table (RZ_NONNULL ELFOBJ *bin)
 
size_t Elf_() rz_bin_elf_get_number_of_symbols_from_hash_table (RZ_NONNULL ELFOBJ *bin)
 
RZ_BORROW RzBinElfSymbol *Elf_() rz_bin_elf_get_import (RZ_NONNULL ELFOBJ *bin, ut32 ordinal)
 
RZ_OWN RzVector *Elf_() rz_bin_elf_analyse_imports (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_has_imports (RZ_NONNULL ELFOBJ *bin)
 
ut64 Elf_() rz_bin_elf_get_targets_map_base (ELFOBJ *bin)
 
RZ_OWN RzList *Elf_() rz_bin_elf_get_libs (RZ_NONNULL ELFOBJ *bin)
 List all imported lib. More...
 
RZ_OWN Sdb *Elf_() rz_bin_elf_get_symbols_info (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. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_arch (RZ_NONNULL ELFOBJ *bin)
 Get the elf binary architecture. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_compiler (RZ_NONNULL ELFOBJ *bin)
 Get the compiler info from the .comment section. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_cpu (RZ_NONNULL ELFOBJ *bin)
 Return a string representing the cpu. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_elf_class (RZ_NONNULL ELFOBJ *bin)
 Return a string representing the elf class. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_file_type (RZ_NONNULL ELFOBJ *bin)
 Return a string representing the file type. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_head_flag (RZ_NONNULL ELFOBJ *bin)
 Return the head flag. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_intrp (RZ_NONNULL ELFOBJ *bin)
 Get the program interpreter. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_machine_name (RZ_NONNULL ELFOBJ *bin)
 Return a string representing the machine name. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_osabi_name (RZ_NONNULL ELFOBJ *bin)
 Return the os application binary interface name. More...
 
RZ_OWN char *Elf_() rz_bin_elf_get_rpath (RZ_NONNULL ELFOBJ *bin)
 Get the rpath. More...
 
bool Elf_() rz_bin_elf_has_nx (RZ_NONNULL ELFOBJ *bin)
 Check if the stack is not executable. More...
 
bool Elf_() rz_bin_elf_has_va (ELFOBJ *bin)
 Check if the elf use virtual address. More...
 
bool Elf_() rz_bin_elf_is_big_endian (RZ_NONNULL ELFOBJ *bin)
 Check the binary endianness. More...
 
bool Elf_() rz_bin_elf_is_executable (RZ_NONNULL ELFOBJ *bin)
 Check if the elf binary is executable. More...
 
bool Elf_() rz_bin_elf_is_relocatable (RZ_NONNULL ELFOBJ *bin)
 Check if the elf binary is relocatable. More...
 
bool Elf_() rz_bin_elf_is_static (RZ_NONNULL ELFOBJ *bin)
 Check if the binary is statically-linked library. More...
 
bool Elf_() rz_bin_elf_is_stripped (RZ_NONNULL ELFOBJ *bin)
 Check if the binary is stripped. More...
 
int Elf_() rz_bin_elf_get_bits (RZ_NONNULL ELFOBJ *bin)
 Return the elf bits. More...
 
int Elf_() rz_bin_elf_has_relro (RZ_NONNULL ELFOBJ *bin)
 Analyse if the elf binary has relro or partial relro. More...
 
ut64 Elf_() rz_bin_elf_get_baddr (RZ_NONNULL ELFOBJ *bin)
 Compute the base address of the binary. More...
 
ut64 Elf_() rz_bin_elf_get_boffset (RZ_NONNULL ELFOBJ *bin)
 Compute the base offset of the binary. More...
 
ut64 Elf_() rz_bin_elf_get_entry_offset (RZ_NONNULL ELFOBJ *bin)
 Get the entry offset. More...
 
ut64 Elf_() rz_bin_elf_get_fini_offset (RZ_NONNULL ELFOBJ *bin)
 Compute the fini offset of the binary. More...
 
ut64 Elf_() rz_bin_elf_get_init_offset (RZ_NONNULL ELFOBJ *bin)
 Compute the init offset of the binary. More...
 
ut64 Elf_() rz_bin_elf_get_main_offset (RZ_NONNULL ELFOBJ *bin)
 Compute the main offset of the binary. More...
 
RZ_BORROW RzBinElfPrStatusLayout *Elf_() rz_bin_elf_get_prstatus_layout (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN RzVector *Elf_() rz_bin_elf_notes_new (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_has_notes (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_check_array (RZ_NONNULL ELFOBJ *bin, Elf_(Off) offset, Elf_(Off) length, Elf_(Off) entry_size)
 
bool Elf_() rz_bin_elf_read_addr (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Addr) *result)
 
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_read_half (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Half) *result)
 
bool Elf_() rz_bin_elf_read_off (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Off) *result)
 
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 (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Sword) *result)
 
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_versym (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Versym) *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)
 
bool Elf_() rz_bin_elf_read_xword (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Xword) *result)
 
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_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_add_addr (Elf_(Addr) *result, Elf_(Addr) addr, Elf_(Addr) value)
 
bool Elf_() rz_bin_elf_add_off (Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
 
bool Elf_() rz_bin_elf_mul_addr (Elf_(Addr) *result, Elf_(Addr) addr, Elf_(Addr) value)
 
bool Elf_() rz_bin_elf_mul_off (Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
 
RZ_OWN RzVector *Elf_() rz_bin_elf_relocs_new (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_has_relocs (RZ_NONNULL ELFOBJ *bin)
 
size_t Elf_() rz_bin_elf_get_relocs_count (RZ_NONNULL ELFOBJ *bin)
 
ut64 Elf_() rz_bin_elf_get_num_relocs_dynamic_plt (RZ_NONNULL ELFOBJ *bin)
 
RZ_BORROW RzBinElfSegment *Elf_() rz_bin_elf_get_segment_with_type (RZ_NONNULL ELFOBJ *bin, Elf_(Word) type)
 
RZ_OWN RzVector *Elf_() rz_bin_elf_segments_new (RZ_NONNULL ELFOBJ *bin, RzVector *sections, RZ_NONNULL RzBinObjectLoadOptions *options)
 
bool Elf_() rz_bin_elf_has_segments (RZ_NONNULL ELFOBJ *bin)
 
RZ_BORROW RzBinElfSection *Elf_() rz_bin_elf_get_section (RZ_NONNULL ELFOBJ *bin, Elf_(Half) index)
 
RZ_BORROW RzBinElfSection *Elf_() rz_bin_elf_get_section_with_name (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL const char *name)
 
RZ_OWN RzList *Elf_() rz_bin_elf_section_flag_to_rzlist (ut64 flag)
 Return a list of string representing flag options. More...
 
RZ_OWN RzVector *Elf_() rz_bin_elf_convert_sections (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RzBinObjectLoadOptions *options, RzVector *sections)
 
RZ_OWN RzVector *Elf_() rz_bin_elf_sections_new (RZ_NONNULL ELFOBJ *bin)
 
RZ_OWN char *Elf_() rz_bin_elf_section_type_to_string (ut64 type)
 Return a string representing the elf type. More...
 
bool Elf_() rz_bin_elf_has_sections (RZ_NONNULL ELFOBJ *bin)
 
RZ_BORROW const char *Elf_() rz_bin_elf_strtab_get (RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
 
RZ_OWN RzBinElfStrtab *Elf_() rz_bin_elf_strtab_new (RZ_NONNULL ELFOBJ *bin, ut64 offset, ut64 size)
 
RZ_OWN char *Elf_() rz_bin_elf_strtab_get_dup (RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
 
bool Elf_() rz_bin_elf_strtab_has_index (RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
 
void Elf_() rz_bin_elf_strtab_free (RzBinElfStrtab *ptr)
 
 Elf_ (Word) Elf_(rz_bin_elf_get_number_of_dynamic_symbols)(RZ_NONNULL ELFOBJ *bin)
 
RZ_BORROW RzBinElfSymbol *Elf_() rz_bin_elf_get_symbol (RZ_NONNULL ELFOBJ *bin, ut32 ordinal)
 
RZ_OWN RzVector *Elf_() rz_bin_elf_compute_symbols (ELFOBJ *bin, RzBinElfSymbolFilter filter)
 
RZ_OWN RzVector *Elf_() rz_bin_elf_symbols_new (RZ_NONNULL ELFOBJ *bin)
 
bool Elf_() rz_bin_elf_has_symbols (RZ_NONNULL ELFOBJ *bin)
 

Variables

 RzBinElfSegment
 
 RzBinElfNoteFile
 
 RzBinElfNote
 

Macro Definition Documentation

◆ ELFOBJ

#define ELFOBJ   struct Elf_(rz_bin_elf_obj_t)

Definition at line 24 of file elf.h.

◆ rz_bin_elf_enumerate_sections

#define rz_bin_elf_enumerate_sections (   bin,
  section,
  i 
)
Value:
rz_vector_enumerate((bin)->sections, section, i)
lzma_index ** i
Definition: index.h:629
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
struct Elf_(rz_bin_elf_segment_t)
Definition: elf.h:127
bool Elf_() rz_bin_elf_has_sections(RZ_NONNULL ELFOBJ *bin)
Definition: elf_sections.c:440
Definition: malloc.c:26

Definition at line 34 of file elf.h.

◆ rz_bin_elf_fix_arm_thumb_object_dispatch

#define rz_bin_elf_fix_arm_thumb_object_dispatch (   object)     Elf_(rz_bin_elf_fix_arm_thumb_object)(&object->paddr, &object->vaddr, &object->bits)

Definition at line 228 of file elf.h.

◆ rz_bin_elf_foreach_imports

#define rz_bin_elf_foreach_imports (   bin,
  import 
)
Value:
rz_vector_foreach(bin->imports, import)
bool Elf_() rz_bin_elf_has_imports(RZ_NONNULL ELFOBJ *bin)
Definition: elf_imports.c:342

Definition at line 50 of file elf.h.

◆ rz_bin_elf_foreach_notes_segment

#define rz_bin_elf_foreach_notes_segment (   bin,
  notes 
)
Value:
rz_vector_foreach((bin)->notes, notes)
bool Elf_() rz_bin_elf_has_notes(RZ_NONNULL ELFOBJ *bin)
Definition: elf_notes.c:255

Definition at line 42 of file elf.h.

◆ rz_bin_elf_foreach_relocs

#define rz_bin_elf_foreach_relocs (   bin,
  reloc 
)
Value:
rz_vector_foreach((bin)->relocs, reloc)
RzList * relocs(RzBinFile *bf)
Definition: bin_ne.c:114
bool Elf_() rz_bin_elf_has_relocs(RZ_NONNULL ELFOBJ *bin)
Definition: elf_relocs.c:239

Definition at line 38 of file elf.h.

◆ rz_bin_elf_foreach_sections

#define rz_bin_elf_foreach_sections (   bin,
  section 
)
Value:
rz_vector_foreach((bin)->sections, section)

Definition at line 30 of file elf.h.

◆ rz_bin_elf_foreach_segments

#define rz_bin_elf_foreach_segments (   bin,
  segment 
)
Value:
rz_vector_foreach((bin)->segments, segment)
bool Elf_() rz_bin_elf_has_segments(RZ_NONNULL ELFOBJ *bin)
Definition: elf_segments.c:149

Definition at line 26 of file elf.h.

◆ rz_bin_elf_foreach_symbols

#define rz_bin_elf_foreach_symbols (   bin,
  symbol 
)
Value:
rz_vector_foreach(bin->symbols, symbol)
bool Elf_() rz_bin_elf_has_symbols(RZ_NONNULL ELFOBJ *bin)
Definition: elf_symbols.c:534

Definition at line 46 of file elf.h.

◆ RZ_BIN_ELF_FULL_RELRO

#define RZ_BIN_ELF_FULL_RELRO   2

Definition at line 22 of file elf.h.

◆ RZ_BIN_ELF_NO_RELRO

#define RZ_BIN_ELF_NO_RELRO   0

Definition at line 20 of file elf.h.

◆ RZ_BIN_ELF_PART_RELRO

#define RZ_BIN_ELF_PART_RELRO   1

Definition at line 21 of file elf.h.

◆ RZ_BIN_ELF_SCN_IS_EXECUTABLE

#define RZ_BIN_ELF_SCN_IS_EXECUTABLE (   x)    x &SHF_EXECINSTR

Definition at line 16 of file elf.h.

◆ RZ_BIN_ELF_SCN_IS_READABLE

#define RZ_BIN_ELF_SCN_IS_READABLE (   x)    x &SHF_ALLOC

Definition at line 17 of file elf.h.

◆ RZ_BIN_ELF_SCN_IS_WRITABLE

#define RZ_BIN_ELF_SCN_IS_WRITABLE (   x)    x &SHF_WRITE

Definition at line 18 of file elf.h.

Typedef Documentation

◆ RzBinElfDtDynamic

Definition at line 131 of file elf.h.

◆ RzBinElfGnuHashTable

◆ RzBinElfHashTable

◆ RzBinElfNotePrStatus

Parsed PT_NOTE of type NT_PRSTATUS.

◆ RzBinElfPrStatusLayout

Information about the binary layout in a NT_PRSTATUS note for core files of a certain architecture and os.

◆ RzBinElfReloc

◆ RzBinElfSection

◆ RzBinElfStrtab

Definition at line 182 of file elf.h.

◆ RzBinElfSymbol

◆ RzBinElfSymbolFilter

typedef bool(* RzBinElfSymbolFilter) (ELFOBJ *bin, Elf_(Sym) *entry, bool is_dynamic)

Definition at line 366 of file elf.h.

Function Documentation

◆ Elf_() [1/5]

struct Elf_ ( rz_bin_elf_note_file_t  )

A single file entry in a PT_NOTE of type NT_FILE.

Definition at line 131 of file elf.h.

159  {
160  Elf_(Addr) start_vaddr;
161  Elf_(Addr) end_vaddr;
162  Elf_(Addr) file_off;
163  char *file;
164 }
static int file
Definition: z80asm.c:58

◆ Elf_() [2/5]

struct Elf_ ( rz_bin_elf_note_t  )

A single PT_NOTE entry, parsed from an ElfW(Nhdr) and associated data.

Definition at line 165 of file elf.h.

175  {
176  Elf_(Word) type;
177  union {
178  RzBinElfNoteFile file; //< for type == NT_FILE
179  RzBinElfNotePrStatus prstatus; //< for type = NT_PRSTATUS
180  };
181 }
RzBinElfNoteFile
Definition: elf.h:165
int type
Definition: mipsasm.c:17
Parsed PT_NOTE of type NT_PRSTATUS.
Definition: elf.h:168

◆ Elf_() [3/5]

struct Elf_ ( rz_bin_elf_obj_t  )

< overlay over the original file with relocs patched

Definition at line 182 of file elf.h.

186  {
187  RzBuffer *b;
188 
189  RzBuffer *buf_patched;
190  bool relocs_patched;
192 
193  Sdb *kv;
194 
195  ut64 size;
196 
197  bool big_endian;
198  int bits;
199  ut64 baddr;
200  ut64 boffset;
201 
202  Elf_(Ehdr) ehdr;
203 
204  RzVector *segments; // should be use with elf_segments.c
205  RzVector *sections; // should be use with elf_sections.c
206 
207  RzBinElfDtDynamic *dt_dynamic; // should be use with elf_dynamic.c
208 
209  RzBinElfStrtab *dynstr; // should be use with elf_strtab.c
210  RzBinElfStrtab *shstrtab; // should be use with elf_strtab.c
211 
212  RzVector *relocs; // should be use with elf_relocs.c
213 
214  // This is RzVector of note segment reprensented as RzVector<RzBinElfNote>
215  RzVector *notes; // RzVector<RzVector<RzBinElfNote>>
216 
217  RzVector *symbols; // RzVector<RzBinElfSymbol>
218  RzVector *imports; // RzVector<RzBinElfSymbol>
219 };
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
RzList * imports(RzBinFile *bf)
Definition: bin_ne.c:106
static ut64 boffset(RzBinFile *bf)
Definition: bin_ninds.c:39
int bits(struct state *s, int need)
Definition: blast.c:72
voidpf void uLong size
Definition: ioapi.h:138
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
Definition: mach0_relocs.c:556
#define b(i)
Definition: sha256.c:42
Definition: sdb.h:63
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

◆ Elf_() [4/5]

struct Elf_ ( rz_bin_elf_segment_t  )

Definition at line 1 of file elf.h.

127  {
128  Elf_(Phdr) data;
129  bool is_valid;
130 }
static bool is_valid(arm_reg reg)

◆ Elf_() [5/5]

Elf_ ( Word  )

Definition at line 75 of file elf_symbols.c.

75  {
76  ut64 symtab_addr;
77  ut64 strtab_addr;
78  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_SYMTAB, &symtab_addr) || !Elf_(rz_bin_elf_get_dt_info)(bin, DT_STRTAB, &strtab_addr)) {
79  return 0;
80  }
81 
82  ut64 symtab_offset = Elf_(rz_bin_elf_v2p)(bin, symtab_addr);
83  ut64 strtab_offset = Elf_(rz_bin_elf_v2p)(bin, strtab_addr);
84  if (symtab_offset == UT64_MAX || strtab_offset == UT64_MAX) {
85  return 0;
86  }
87 
88  return get_number_of_symbols_from_heuristic_aux(bin, symtab_offset, strtab_offset);
89 }
ut64 Elf_() rz_bin_elf_v2p(RZ_NONNULL ELFOBJ *bin, ut64 vaddr)
Convert a virtual address to the physical address.
Definition: elf.c:429
bool Elf_() rz_bin_elf_get_dt_info(RZ_NONNULL ELFOBJ *bin, ut64 key, RZ_OUT ut64 *info)
Definition: elf_dynamic.c:120
static Elf_(Word)
Definition: elf_symbols.c:66
#define DT_SYMTAB
Definition: common.h:543
#define DT_STRTAB
Definition: common.h:542
#define UT64_MAX
Definition: rz_types_base.h:86

References DT_STRTAB, DT_SYMTAB, Elf_(), rz_bin_elf_get_dt_info(), rz_bin_elf_v2p(), ut64(), and UT64_MAX.

◆ rz_bin_elf_add_addr()

bool Elf_() rz_bin_elf_add_addr ( Elf_(Addr) *  result,
Elf_(Addr)  addr,
Elf_(Addr)  value 
)

Definition at line 138 of file elf_misc.c.

138  {
139 #if RZ_BIN_ELF64
140  return UT64_ADD((ut64 *)result, addr, value);
141 #else
142  return UT32_ADD((ut32 *)result, addr, value);
143 #endif
144 }
static int value
Definition: cmd_api.c:93
uint32_t ut32
static int UT64_ADD(ut64 *r, ut64 a, ut64 b)
Definition: rz_endian.h:603
static int UT32_ADD(ut32 *r, ut32 a, ut32 b)
Definition: rz_endian.h:633
static int addr
Definition: z80asm.c:58

References addr, UT32_ADD(), ut64(), UT64_ADD(), and value.

Referenced by verify_phdr_entry(), and verify_shdr_entry().

◆ rz_bin_elf_add_off()

bool Elf_() rz_bin_elf_add_off ( Elf_(Off) *  result,
Elf_(Off)  addr,
Elf_(Off)  value 
)

Definition at line 146 of file elf_misc.c.

146  {
147 #if RZ_BIN_ELF64
148  return UT64_ADD((ut64 *)result, addr, value);
149 #else
150  return UT32_ADD((ut32 *)result, addr, value);
151 #endif
152 }

References addr, UT32_ADD(), ut64(), UT64_ADD(), and value.

Referenced by rz_bin_elf_check_array(), verify_phdr_entry(), and verify_shdr_entry().

◆ rz_bin_elf_analyse_imports()

RZ_OWN RzVector* Elf_() rz_bin_elf_analyse_imports ( RZ_NONNULL ELFOBJ bin)

Definition at line 329 of file elf_imports.c.

329  {
331 
333  if (!result) {
334  return NULL;
335  }
336 
338 
339  return result;
340 }
#define NULL
Definition: cris-opc.c:27
RZ_OWN RzVector *Elf_() rz_bin_elf_compute_symbols(ELFOBJ *bin, RzBinElfSymbolFilter filter)
Definition: elf_symbols.c:486
static bool filter_import(ELFOBJ *bin, Elf_(Sym) *symbol, bool is_dynamic)
Definition: elf_imports.c:312
static void convert_elf_symbols_to_elf_imports(ELFOBJ *bin, RzVector *symbols)
Definition: elf_imports.c:305
#define Elf_(name)
Definition: elf_specs.h:32
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

References convert_elf_symbols_to_elf_imports(), Elf_, filter_import(), NULL, rz_bin_elf_compute_symbols(), and rz_return_val_if_fail.

Referenced by init().

◆ rz_bin_elf_check_array()

bool Elf_() rz_bin_elf_check_array ( RZ_NONNULL ELFOBJ bin,
Elf_(Off)  offset,
Elf_(Off)  length,
Elf_(Off)  entry_size 
)

Definition at line 32 of file elf_misc.c.

32  {
33  rz_return_val_if_fail(bin, false);
34 
35  Elf_(Off) array_size;
36  if (!Elf_(rz_bin_elf_mul_off)(&array_size, length, entry_size)) {
37  return false;
38  }
39 
40  Elf_(Off) end_off;
41  if (!Elf_(rz_bin_elf_add_off)(&end_off, offset, array_size)) {
42  return false;
43  }
44 
45  if (!array_size || end_off > bin->size) {
46  return false;
47  }
48 
49  return true;
50 }
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
Definition: sflib.h:133
bool Elf_() rz_bin_elf_add_off(Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
Definition: elf_misc.c:146
bool Elf_() rz_bin_elf_mul_off(Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
Definition: elf_misc.c:162
voidpf uLong offset
Definition: ioapi.h:144

References Elf_, length, rz_bin_elf_add_off(), rz_bin_elf_mul_off(), and rz_return_val_if_fail.

Referenced by rz_bin_elf_sections_new(), rz_bin_elf_segments_new(), and rz_bin_elf_strtab_new().

◆ rz_bin_elf_compute_symbols()

RZ_OWN RzVector* Elf_() rz_bin_elf_compute_symbols ( ELFOBJ bin,
RzBinElfSymbolFilter  filter 
)

Definition at line 486 of file elf_symbols.c.

486  {
488  if (!result) {
489  return NULL;
490  }
491 
492  HtUU *set = ht_uu_new0();
493  if (!set) {
494  rz_vector_free(result);
495  return NULL;
496  }
497 
498  if (!get_dynamic_elf_symbols(bin, result, filter, set)) {
499  rz_vector_free(result);
500  ht_uu_free(set);
501  return NULL;
502  }
503 
504  if (!get_section_elf_symbols(bin, result, filter, set)) {
505  rz_vector_free(result);
506  ht_uu_free(set);
507  return NULL;
508  }
509 
510  // Parsing .gnu_debugdata is completely optional, ignore errors if any and just continue
511  (void)get_gnu_debugdata_elf_symbols(bin, result, filter, set);
512 
513  ht_uu_free(set);
514 
515  if (!rz_vector_len(result)) {
516  rz_vector_free(result);
517  return NULL;
518  }
519 
520  return result;
521 }
static bool get_section_elf_symbols(ELFOBJ *bin, RzVector *result, RzBinElfSymbolFilter filter, HtUU *set)
Definition: elf_symbols.c:325
static bool get_gnu_debugdata_elf_symbols(ELFOBJ *bin, RzVector *result, RzBinElfSymbolFilter filter, HtUU *set)
Definition: elf_symbols.c:367
static void elf_symbol_fini(void *e, RZ_UNUSED void *user)
Definition: elf_symbols.c:250
static bool get_dynamic_elf_symbols(ELFOBJ *bin, RzVector *result, RzBinElfSymbolFilter filter, HtUU *set)
Definition: elf_symbols.c:295
RZ_API void rz_vector_free(RzVector *vec)
Definition: vector.c:75
RZ_API RzVector * rz_vector_new(size_t elem_size, RzVectorFree free, void *free_user)
Definition: vector.c:42
static size_t rz_vector_len(const RzVector *vec)
Definition: rz_vector.h:82

References elf_symbol_fini(), get_dynamic_elf_symbols(), get_gnu_debugdata_elf_symbols(), get_section_elf_symbols(), NULL, rz_vector_free(), rz_vector_len(), and rz_vector_new().

Referenced by get_gnu_debugdata_elf_symbols(), rz_bin_elf_analyse_imports(), and rz_bin_elf_symbols_new().

◆ rz_bin_elf_convert_sections()

RZ_OWN RzVector* Elf_() rz_bin_elf_convert_sections ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RzBinObjectLoadOptions options,
RzVector sections 
)

Definition at line 362 of file elf_sections.c.

362  {
364 
366  if (!result) {
367  return NULL;
368  }
369 
370  if (!rz_vector_len(result)) {
371  rz_vector_free(result);
372  return NULL;
373  }
374 
375  return result;
376 }
static RzVector * convert_sections(ELFOBJ *bin, RzBinObjectLoadOptions *options, RzVector *sections)
Definition: elf_sections.c:349
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145

References convert_sections(), NULL, options, rz_return_val_if_fail, rz_vector_free(), rz_vector_len(), and sections().

Referenced by init_shdr_aux().

◆ rz_bin_elf_dt_dynamic_free()

void Elf_() rz_bin_elf_dt_dynamic_free ( RzBinElfDtDynamic ptr)

Definition at line 135 of file elf_dynamic.c.

135  {
136  if (!ptr) {
137  return;
138  }
139 
140  ht_uu_free(ptr->info);
141  rz_vector_fini(&ptr->dt_needed);
142  free(ptr);
143 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_vector_fini(RzVector *vec)
Definition: vector.c:61

References free(), and rz_vector_fini().

Referenced by rz_bin_elf_dt_dynamic_new(), and rz_bin_elf_free().

◆ rz_bin_elf_dt_dynamic_new()

RZ_OWN RzBinElfDtDynamic* Elf_() rz_bin_elf_dt_dynamic_new ( RZ_NONNULL ELFOBJ bin)

Definition at line 98 of file elf_dynamic.c.

98  {
100  if (!result) {
101  return NULL;
102  }
103 
104  result->info = ht_uu_new0();
105  if (!result->info) {
107  return NULL;
108  }
109 
110  rz_vector_init(&result->dt_needed, sizeof(ut64), NULL, NULL);
111 
112  if (!init_dt_dynamic(bin, result)) {
114  return NULL;
115  }
116 
117  return result;
118 }
static bool init_dt_dynamic(ELFOBJ *bin, RzBinElfDtDynamic *ptr)
Definition: elf_dynamic.c:67
void Elf_() rz_bin_elf_dt_dynamic_free(RzBinElfDtDynamic *ptr)
Definition: elf_dynamic.c:135
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API void rz_vector_init(RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user)
Definition: vector.c:33

References rz_bin_elf_dt_dynamic_t::dt_needed, Elf_, rz_bin_elf_dt_dynamic_t::info, init_dt_dynamic(), NULL, rz_bin_elf_dt_dynamic_free(), RZ_NEW0, rz_vector_init(), and ut64().

Referenced by init_dt_dynamic_aux().

◆ rz_bin_elf_fix_arm_thumb_addr()

void Elf_() rz_bin_elf_fix_arm_thumb_addr ( ut64 addr)

Definition at line 28 of file elf_arm.c.

28  {
30  *addr -= 1;
31 }
bool Elf_() rz_bin_elf_is_thumb_addr(ut64 addr)
Definition: elf_arm.c:24
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References addr, Elf_, rz_bin_elf_is_thumb_addr(), and rz_return_if_fail.

Referenced by rz_bin_elf_fix_arm_thumb_object().

◆ rz_bin_elf_fix_arm_thumb_object()

void Elf_() rz_bin_elf_fix_arm_thumb_object ( RZ_NONNULL ut64 paddr,
RZ_NONNULL ut64 vaddr,
RZ_NONNULL int bits 
)

Definition at line 33 of file elf_arm.c.

33  {
34  rz_return_if_fail(paddr && vaddr && bits);
35 
36  *bits = 32;
37 
38  if (Elf_(rz_bin_elf_is_thumb_addr)(*paddr)) {
40  *bits = 16;
41  }
42 
43  if (Elf_(rz_bin_elf_is_thumb_addr)(*vaddr)) {
45  *bits = 16;
46  }
47 }
void Elf_() rz_bin_elf_fix_arm_thumb_addr(ut64 *addr)
Definition: elf_arm.c:28

References bits(), Elf_, rz_bin_elf_fix_arm_thumb_addr(), rz_bin_elf_is_thumb_addr(), and rz_return_if_fail.

◆ rz_bin_elf_fix_arm_thumb_symbol()

void Elf_() rz_bin_elf_fix_arm_thumb_symbol ( RZ_NONNULL RzBinSymbol symbol)

Definition at line 49 of file elf_arm.c.

49  {
50  rz_return_if_fail(symbol && symbol->name);
51 
52  if (start_a_sequence_of_instruction(symbol)) {
53  symbol->bits = 32;
54  } else if (start_a_sequence_of_thumb_instruction(symbol) || !start_a_sequence_of_data(symbol)) {
56  }
57 }
#define rz_bin_elf_fix_arm_thumb_object_dispatch(object)
Definition: elf.h:228
static bool start_a_sequence_of_thumb_instruction(RzBinSymbol *symbol)
Definition: elf_arm.c:11
static bool start_a_sequence_of_data(RzBinSymbol *symbol)
Definition: elf_arm.c:15
static bool start_a_sequence_of_instruction(RzBinSymbol *symbol)
Definition: elf_arm.c:7

References rz_bin_elf_fix_arm_thumb_object_dispatch, rz_return_if_fail, start_a_sequence_of_data(), start_a_sequence_of_instruction(), and start_a_sequence_of_thumb_instruction().

◆ rz_bin_elf_free()

void Elf_() rz_bin_elf_free ( RZ_NONNULL ELFOBJ bin)

Free the elf binary.

Parameters
elfbinary

...

Definition at line 366 of file elf.c.

366  {
368 
369  rz_buf_free(bin->b);
370  rz_buf_free(bin->buf_patched);
371 
372  sdb_free(bin->kv);
373 
374  rz_vector_free(bin->segments);
375  rz_vector_free(bin->sections);
376 
377  Elf_(rz_bin_elf_dt_dynamic_free)(bin->dt_dynamic);
378 
379  Elf_(rz_bin_elf_strtab_free)(bin->dynstr);
380  Elf_(rz_bin_elf_strtab_free)(bin->shstrtab);
381 
382  rz_vector_free(bin->relocs);
383 
384  rz_vector_free(bin->notes);
385 
386  rz_vector_free(bin->symbols);
387  rz_vector_free(bin->imports);
388 
389  free(bin);
390 }
void Elf_() rz_bin_elf_dt_dynamic_free(RzBinElfDtDynamic *ptr)
Definition: elf_dynamic.c:135
void Elf_() rz_bin_elf_strtab_free(RzBinElfStrtab *ptr)
Definition: elf_strtab.c:72
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206

References Elf_, free(), rz_bin_elf_dt_dynamic_free(), rz_bin_elf_strtab_free(), rz_buf_free(), rz_return_if_fail, rz_vector_free(), and sdb_free().

Referenced by get_gnu_debugdata_elf_symbols(), and rz_bin_elf_new_buf().

◆ rz_bin_elf_get_abi()

RZ_OWN char* Elf_() rz_bin_elf_get_abi ( RZ_NONNULL ELFOBJ bin)

Return a string representing the application binary interface.

Parameters
elftype
Returns
allocated string

Only work on mips right now. Use the elf header to deduce the application binary interface

Definition at line 1386 of file elf_info.c.

1386  {
1388 
1389  if (bin->ehdr.e_machine == EM_MIPS) {
1390  return get_abi_mips(bin);
1391  }
1392 
1393  return NULL;
1394 }
static char * get_abi_mips(ELFOBJ *bin)
Definition: elf_info.c:854
#define EM_MIPS
Definition: common.h:110

References EM_MIPS, get_abi_mips(), NULL, and rz_return_val_if_fail.

Referenced by add_abi_info().

◆ rz_bin_elf_get_arch()

RZ_OWN char* Elf_() rz_bin_elf_get_arch ( RZ_NONNULL ELFOBJ bin)

Get the elf binary architecture.

Parameters
elfbinary
Returns
an allocated string

With the elf header (e_machine) deduce the elf architecture

Definition at line 1403 of file elf_info.c.

1403  {
1405 
1406  for (size_t i = 0; i < RZ_ARRAY_SIZE(arch_translation_table); i++) {
1407  if (bin->ehdr.e_machine == arch_translation_table[i].arch) {
1409  }
1410  }
1411 
1412  return strdup("");
1413 }
static const struct arch_translation arch_translation_table[]
Definition: elf_info.c:244
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
Definition: z80asm.h:102

References arch_translation_table, i, NULL, RZ_ARRAY_SIZE, rz_return_val_if_fail, and strdup().

◆ rz_bin_elf_get_baddr()

ut64 Elf_() rz_bin_elf_get_baddr ( RZ_NONNULL ELFOBJ bin)

Compute the base address of the binary.

Parameters
elfbinary
Returns
the base address

To compute the base address, one determines the memory address associated with the lowest p_vaddr value for a PT_LOAD segment.

Definition at line 1772 of file elf_info.c.

1772  {
1774 
1776  return 0x08000000;
1777  }
1778 
1780  return compute_baddr_from_phdr(bin);
1781  }
1782 
1783  return 0;
1784 }
static ut64 compute_baddr_from_phdr(ELFOBJ *bin)
Definition: elf_info.c:539
bool Elf_() rz_bin_elf_is_relocatable(RZ_NONNULL ELFOBJ *bin)
Check if the elf binary is relocatable.
Definition: elf_info.c:1662
static Elf_(Xword)
Definition: elf_info.c:672

References compute_baddr_from_phdr(), Elf_(), rz_bin_elf_has_segments(), rz_bin_elf_is_relocatable(), and rz_return_val_if_fail.

Referenced by get_main_offset_x86_pie(), and init().

◆ rz_bin_elf_get_bits()

int Elf_() rz_bin_elf_get_bits ( RZ_NONNULL ELFOBJ bin)

Return the elf bits.

Parameters
elfbinary
Returns
the number of bits

...

Definition at line 1697 of file elf_info.c.

1697  {
1699 
1700  /* Hack for ARCompact */
1701  if (arch_is_arcompact(bin)) {
1702  return 16;
1703  }
1704 
1705  /* Hack for Ps2 */
1706  if (arch_is_mips(bin)) {
1707  return get_bits_mips(bin);
1708  }
1709 
1710  /* Hack for Thumb */
1713  return 16;
1714  }
1715 
1718  return 16;
1719  }
1720  }
1721 
1722  return get_bits_common(bin);
1723 }
bool Elf_() rz_bin_elf_is_arm_binary_supporting_thumb(RZ_NONNULL ELFOBJ *bin)
Definition: elf_arm.c:19
bool Elf_() rz_bin_elf_is_thumb_addr(ut64 addr)
Definition: elf_arm.c:24
static bool arch_is_mips(ELFOBJ *bin)
Definition: elf_info.c:622
static int get_bits_common(ELFOBJ *bin)
Definition: elf_info.c:575
bool Elf_() rz_bin_elf_is_static(RZ_NONNULL ELFOBJ *bin)
Check if the binary is statically-linked library.
Definition: elf_info.c:1674
static bool arch_is_arcompact(ELFOBJ *bin)
Definition: elf_info.c:626
static int get_bits_mips(ELFOBJ *bin)
Definition: elf_info.c:612
static bool has_thumb_symbol(ELFOBJ *bin)
Definition: elf_info.c:587
ut64 Elf_() rz_bin_elf_get_entry_offset(RZ_NONNULL ELFOBJ *bin)
Get the entry offset.
Definition: elf_info.c:1813
Definition: zipcmp.c:77

References arch_is_arcompact(), arch_is_mips(), Elf_(), get_bits_common(), get_bits_mips(), has_thumb_symbol(), rz_bin_elf_get_entry_offset(), rz_bin_elf_is_arm_binary_supporting_thumb(), rz_bin_elf_is_static(), rz_bin_elf_is_thumb_addr(), rz_return_val_if_fail, and ut64().

Referenced by init().

◆ rz_bin_elf_get_boffset()

ut64 Elf_() rz_bin_elf_get_boffset ( RZ_NONNULL ELFOBJ bin)

Compute the base offset of the binary.

Parameters
elfbinary
Returns
the base offset

To compute the base address, one determines the memory address associated with the lowest p_offset value for a PT_LOAD segment.

Definition at line 1795 of file elf_info.c.

1795  {
1797 
1800  }
1801 
1802  return 0;
1803 }
static ut64 compute_boffset_from_phdr(ELFOBJ *bin)
Definition: elf_info.c:526

References compute_boffset_from_phdr(), Elf_(), rz_bin_elf_has_segments(), and rz_return_val_if_fail.

Referenced by init().

◆ rz_bin_elf_get_compiler()

RZ_OWN char* Elf_() rz_bin_elf_get_compiler ( RZ_NONNULL ELFOBJ bin)

Get the compiler info from the .comment section.

Parameters
elfbinary
Returns
a ptr to an allocated string

...

Definition at line 1339 of file elf_info.c.

1339  {
1341 
1343  if (!section) {
1344  return NULL;
1345  }
1346 
1348  ut64 size = RZ_MIN(section->size, 128);
1349  if (size < 1) {
1350  return NULL;
1351  }
1352 
1353  char *result = malloc(size + 1);
1354  if (!result) {
1355  return NULL;
1356  }
1357 
1358  if (rz_buf_read_at(bin->b, offset, (ut8 *)result, size) < 1) {
1359  free(result);
1360  return NULL;
1361  }
1362  result[size] = 0;
1363 
1364  size_t result_len = strlen(result);
1365  char *end = result + result_len;
1366 
1367  if (result_len != size && end[1]) {
1368  end[0] = ' ';
1369  }
1370 
1371  rz_str_trim(result);
1372  char *res = rz_str_escape(result);
1373 
1374  free(result);
1375  return res;
1376 }
RZ_BORROW RzBinElfSection *Elf_() rz_bin_elf_get_section_with_name(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL const char *name)
Definition: elf_sections.c:278
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136
RZ_API RZ_OWN char * rz_str_escape(RZ_NONNULL const char *buf)
Definition: str.c:1550
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
#define RZ_MIN(x, y)
uint32_t offset
uint32_t size

References Elf_(), test_evm::end, free(), malloc(), NULL, section::offset, rz_bin_elf_get_section_with_name(), rz_buf_read_at(), RZ_MIN, rz_return_val_if_fail, rz_str_escape(), rz_str_trim(), section::size, and ut64().

◆ rz_bin_elf_get_cpu()

RZ_OWN char* Elf_() rz_bin_elf_get_cpu ( RZ_NONNULL ELFOBJ bin)

Return a string representing the cpu.

Parameters
elftype
Returns
allocated string

Only work on mips right now. Use the elf header to deduce the cpu

Definition at line 1422 of file elf_info.c.

1422  {
1424 
1425  if (!Elf_(rz_bin_elf_has_segments)(bin)) {
1426  return NULL;
1427  }
1428 
1429  if (bin->ehdr.e_machine == EM_MIPS) {
1430  return get_cpu_mips(bin);
1431  }
1432 
1433  return NULL;
1434 }
static char * get_cpu_mips(ELFOBJ *bin)
Definition: elf_info.c:810

References Elf_(), EM_MIPS, get_cpu_mips(), NULL, rz_bin_elf_has_segments(), and rz_return_val_if_fail.

Referenced by add_cpu_info().

◆ rz_bin_elf_get_dt_info()

bool Elf_() rz_bin_elf_get_dt_info ( RZ_NONNULL ELFOBJ bin,
ut64  key,
RZ_OUT ut64 info 
)

Definition at line 120 of file elf_dynamic.c.

120  {
121  rz_return_val_if_fail(bin, false);
122 
124  return false;
125  }
126 
127  return get_dt_info(bin->dt_dynamic, key, info);
128 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
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
Definition: sflib.h:118
static bool get_dt_info(RzBinElfDtDynamic *ptr, ut64 key, ut64 *info)
Definition: elf_dynamic.c:7
bool Elf_() rz_bin_elf_has_dt_dynamic(RZ_NONNULL ELFOBJ *bin)
Definition: elf_dynamic.c:130

References Elf_, get_dt_info(), info(), key, rz_bin_elf_has_dt_dynamic(), and rz_return_val_if_fail.

Referenced by create_section_plt(), Elf_(), elf_is_bind_now(), get_dynamic_elf_symbols(), get_gnu_verneed(), get_gnu_versym(), get_import_addr_arm(), get_import_addr_mips(), get_import_addr_ppc(), get_import_addr_riscv(), get_import_addr_x86(), get_import_addr_x86_manual(), get_main_offset_mips(), get_plt_name(), get_relocs_entry_from_dt_dynamic(), get_relocs_entry_from_dt_dynamic_aux(), get_sections_from_dt_dynamic(), get_versym_entry_sdb_from_verdef(), get_versym_entry_sdb_from_verneed(), has_dt_rpath_entry(), init_dynstr_aux(), rz_bin_elf_get_fini_offset(), rz_bin_elf_get_gnu_hash_table(), rz_bin_elf_get_hash_table(), rz_bin_elf_get_init_offset(), and rz_bin_elf_get_num_relocs_dynamic_plt().

◆ rz_bin_elf_get_dt_needed()

RZ_BORROW RzVector* Elf_() rz_bin_elf_get_dt_needed ( RZ_NONNULL ELFOBJ bin)

Definition at line 88 of file elf_dynamic.c.

88  {
90 
92  return NULL;
93  }
94 
95  return &bin->dt_dynamic->dt_needed;
96 }

References Elf_, NULL, rz_bin_elf_has_dt_dynamic(), and rz_return_val_if_fail.

Referenced by rz_bin_elf_get_libs().

◆ rz_bin_elf_get_e_ehsize_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_ehsize_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 82 of file elf_ehdr.c.

82  {
84 
85  return rz_str_newf("%d", bin->ehdr.e_ehsize);
86 }
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_entry_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_entry_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 88 of file elf_ehdr.c.

88  {
90 
91  return rz_str_newf("0x%08" PFMT64x, (ut64)bin->ehdr.e_entry);
92 }
#define PFMT64x
Definition: rz_types.h:393

References NULL, PFMT64x, rz_return_val_if_fail, rz_str_newf(), and ut64().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_flags_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_flags_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 94 of file elf_ehdr.c.

94  {
96 
97  return rz_str_newf("0x%04x", bin->ehdr.e_flags);
98 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_indent_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_indent_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 100 of file elf_ehdr.c.

100  {
102 
103  return rz_str_newf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
104  bin->ehdr.e_ident[0],
105  bin->ehdr.e_ident[1],
106  bin->ehdr.e_ident[2],
107  bin->ehdr.e_ident[3],
108  bin->ehdr.e_ident[4],
109  bin->ehdr.e_ident[5],
110  bin->ehdr.e_ident[6],
111  bin->ehdr.e_ident[7],
112  bin->ehdr.e_ident[8],
113  bin->ehdr.e_ident[9],
114  bin->ehdr.e_ident[10],
115  bin->ehdr.e_ident[11],
116  bin->ehdr.e_ident[12],
117  bin->ehdr.e_ident[13],
118  bin->ehdr.e_ident[14],
119  bin->ehdr.e_ident[15]);
120 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_machine_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_machine_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 122 of file elf_ehdr.c.

122  {
124 
125  return rz_str_newf("0x%04x", bin->ehdr.e_machine);
126 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_phentsize_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_phentsize_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 128 of file elf_ehdr.c.

128  {
130 
131  return rz_str_newf("%d", bin->ehdr.e_phentsize);
132 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_phnum_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_phnum_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 134 of file elf_ehdr.c.

134  {
136 
137  return rz_str_newf("%d", bin->ehdr.e_phnum);
138 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_phoff_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_phoff_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 140 of file elf_ehdr.c.

140  {
142 
143  return rz_str_newf("0x%08" PFMT64x, (ut64)bin->ehdr.e_phoff);
144 }

References NULL, PFMT64x, rz_return_val_if_fail, rz_str_newf(), and ut64().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_shentsize_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_shentsize_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 146 of file elf_ehdr.c.

146  {
148 
149  return rz_str_newf("%d", bin->ehdr.e_shentsize);
150 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_shnum_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_shnum_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 152 of file elf_ehdr.c.

152  {
154 
155  return rz_str_newf("%d", bin->ehdr.e_shnum);
156 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_shoff_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_shoff_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 158 of file elf_ehdr.c.

158  {
160 
161  return rz_str_newf("0x%08" PFMT64x, (ut64)bin->ehdr.e_shoff);
162 }

References NULL, PFMT64x, rz_return_val_if_fail, rz_str_newf(), and ut64().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_shstrndx_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_shstrndx_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 164 of file elf_ehdr.c.

164  {
166 
167  return rz_str_newf("%d", bin->ehdr.e_shstrndx);
168 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_type_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_type_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 170 of file elf_ehdr.c.

170  {
172 
173  return rz_str_newf("0x%04x", bin->ehdr.e_type);
174 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_e_version_as_string()

RZ_OWN char* Elf_() rz_bin_elf_get_e_version_as_string ( RZ_NONNULL ELFOBJ bin)

Definition at line 176 of file elf_ehdr.c.

176  {
178 
179  return rz_str_newf("0x%08x", bin->ehdr.e_version);
180 }

References NULL, rz_return_val_if_fail, and rz_str_newf().

Referenced by rz_bin_elf_print_ehdr().

◆ rz_bin_elf_get_ehdr()

bool Elf_() rz_bin_elf_get_ehdr ( RZ_NONNULL ELFOBJ bin)

Definition at line 182 of file elf_ehdr.c.

182  {
183  rz_return_val_if_fail(bin, false);
184 
185  memset(&bin->ehdr, 0, sizeof(Elf_(Ehdr)));
186 
187  if (rz_buf_read_at(bin->b, 0, bin->ehdr.e_ident, EI_NIDENT) < EI_NIDENT) {
188  RZ_LOG_WARN("Failed to read ELF header e_ident.\n")
189  return false;
190  }
191 
192  if (!is_valid_elf_ident(bin->ehdr.e_ident)) {
193  RZ_LOG_WARN("Invalid ELF identification.\n");
194  return false;
195  }
196 
197  bin->big_endian = bin->ehdr.e_ident[EI_DATA] == ELFDATA2MSB;
198 
199  return read_ehdr_other(bin);
200 }
#define false
static bool read_ehdr_other(ELFOBJ *bin)
Definition: elf_ehdr.c:34
static Elf_(Half)
Definition: elf_ehdr.c:7
static bool is_valid_elf_ident(ut8 *e_ident)
Definition: elf_ehdr.c:66
return memset(p, 0, total)
#define ELFDATA2MSB
Definition: common.h:59
#define EI_DATA
Definition: common.h:56
#define EI_NIDENT
Definition: internal.h:43
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References EI_DATA, EI_NIDENT, Elf_(), ELFDATA2MSB, is_valid_elf_ident(), memset(), read_ehdr_other(), rz_buf_read_at(), RZ_LOG_WARN, and rz_return_val_if_fail.

Referenced by init_ehdr().

◆ rz_bin_elf_get_elf_class()

RZ_OWN char* Elf_() rz_bin_elf_get_elf_class ( RZ_NONNULL ELFOBJ bin)

Return a string representing the elf class.

Parameters
elfbinary
Returns
allocated string

Check the elf header (e_ident) to deduce the elf class

Definition at line 1443 of file elf_info.c.

1443  {
1445 
1446  for (size_t i = 0; i < RZ_ARRAY_SIZE(class_translation_table); i++) {
1447  if (bin->ehdr.e_ident[EI_CLASS] == class_translation_table[i].class) {
1449  }
1450  }
1451 
1452  return rz_str_newf("<unknown: %x>", bin->ehdr.e_ident[EI_CLASS]);
1453 }
static const struct class_translation class_translation_table[]
Definition: elf_info.c:226
#define EI_CLASS
Definition: common.h:51
unsigned char class
Definition: elf_info.c:31

References class_translation::class, class_translation_table, EI_CLASS, i, NULL, RZ_ARRAY_SIZE, rz_return_val_if_fail, rz_str_newf(), and strdup().

◆ rz_bin_elf_get_entry_offset()

ut64 Elf_() rz_bin_elf_get_entry_offset ( RZ_NONNULL ELFOBJ bin)

Get the entry offset.

Parameters
elfbinary
Returns
the entry offset

Get the entry offset from the elf header (e_entry), and if the information isn't defined section header will be used.

Definition at line 1813 of file elf_info.c.

1813  {
1815 
1817  return UT64_MAX;
1818  }
1819 
1820  ut64 entry = bin->ehdr.e_entry;
1821  if (entry) {
1823  if (tmp == UT64_MAX) {
1824  return entry;
1825  }
1826 
1827  return tmp;
1828  }
1829 
1831 }
bool Elf_() rz_bin_elf_is_executable(RZ_NONNULL ELFOBJ *bin)
Check if the elf binary is executable.
Definition: elf_info.c:1648
static ut64 get_entry_offset_from_shdr(ELFOBJ *bin)
Definition: elf_info.c:507

References Elf_(), get_entry_offset_from_shdr(), rz_bin_elf_is_executable(), rz_bin_elf_v2p(), rz_return_val_if_fail, autogen_x86imm::tmp, ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_bits(), and rz_bin_elf_get_main_offset().

◆ rz_bin_elf_get_file_type()

RZ_OWN char* Elf_() rz_bin_elf_get_file_type ( RZ_NONNULL ELFOBJ bin)

Return a string representing the file type.

Parameters
elfbinary
Returns
allocated string

Use the elf header (e_type) to deduce the file type

Definition at line 1462 of file elf_info.c.

1462  {
1464 
1465  char *result = get_file_type_basic(bin);
1466  if (result) {
1467  return result;
1468  }
1469 
1471  return rz_str_newf("Processor Specific: %x", bin->ehdr.e_type);
1472  }
1473 
1475  return rz_str_newf("OS Specific: %x", bin->ehdr.e_type);
1476  }
1477 
1478  return rz_str_newf("<unknown>: %x", bin->ehdr.e_type);
1479 }
static bool file_type_is_processor_specific(ELFOBJ *bin)
Definition: elf_info.c:785
static bool file_type_is_os_specific(ELFOBJ *bin)
Definition: elf_info.c:789
static char * get_file_type_basic(RZ_NONNULL ELFOBJ *bin)
Definition: elf_info.c:793

References file_type_is_os_specific(), file_type_is_processor_specific(), get_file_type_basic(), NULL, rz_return_val_if_fail, and rz_str_newf().

◆ rz_bin_elf_get_fini_offset()

ut64 Elf_() rz_bin_elf_get_fini_offset ( RZ_NONNULL ELFOBJ bin)

Compute the fini offset of the binary.

Parameters
elfbinary
Returns
the init offset

Get the offset from the vaddr store in the dynamic section (dt_fini)

Definition at line 1840 of file elf_info.c.

1840  {
1842 
1843  ut64 addr;
1844 
1846  return 0;
1847  }
1848 
1850  return 0;
1851  }
1852 
1853  return Elf_(rz_bin_elf_v2p)(bin, addr);
1854 }
bool Elf_() rz_bin_elf_has_dt_dynamic(RZ_NONNULL ELFOBJ *bin)
Definition: elf_dynamic.c:130
#define DT_FINI
Definition: common.h:550

References addr, DT_FINI, Elf_(), rz_bin_elf_get_dt_info(), rz_bin_elf_has_dt_dynamic(), rz_bin_elf_v2p(), rz_return_val_if_fail, and ut64().

◆ rz_bin_elf_get_gnu_hash_table()

bool Elf_() rz_bin_elf_get_gnu_hash_table ( RZ_NONNULL ELFOBJ bin,
RzBinElfGnuHashTable result 
)

Definition at line 64 of file elf_hash.c.

64  {
65  rz_return_val_if_fail(bin && result, false);
66 
67  ut64 addr;
69  return false;
70  }
71 
72  result->offset = Elf_(rz_bin_elf_v2p)(bin, addr);
73  if (result->offset == UT64_MAX) {
74  return false;
75  }
76 
77  if (!read_gnu_hash_table(bin, result)) {
78  RZ_LOG_WARN("Failed to read the GNU hash table (DT_GNU_HASH) at 0x%" PFMT64x ".\n", result->offset);
79  return false;
80  }
81 
82  return true;
83 }
static bool read_gnu_hash_table(ELFOBJ *bin, RzBinElfGnuHashTable *result)
Definition: elf_hash.c:7
#define DT_GNU_HASH
Definition: common.h:602

References addr, DT_GNU_HASH, Elf_, PFMT64x, read_gnu_hash_table(), rz_bin_elf_get_dt_info(), rz_bin_elf_v2p(), RZ_LOG_WARN, rz_return_val_if_fail, ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_number_of_symbols_from_gnu_hash_table().

◆ rz_bin_elf_get_hash_table()

bool Elf_() rz_bin_elf_get_hash_table ( RZ_NONNULL ELFOBJ bin,
RzBinElfHashTable result 
)

Definition at line 85 of file elf_hash.c.

85  {
86  rz_return_val_if_fail(bin && result, false);
87 
88  ut64 addr;
90  return false;
91  }
92 
93  result->offset = Elf_(rz_bin_elf_v2p)(bin, addr);
94  if (result->offset == UT64_MAX) {
95  return false;
96  }
97 
98  if (!read_hash_table(bin, result)) {
99  RZ_LOG_WARN("Failed to read the hash table (DT_HASH) at 0x%" PFMT64x ".\n", result->offset);
100  return false;
101  }
102 
103  return true;
104 }
static bool read_hash_table(ELFOBJ *bin, RzBinElfHashTable *result)
Definition: elf_hash.c:16
#define DT_HASH
Definition: common.h:541

References addr, DT_HASH, Elf_, PFMT64x, read_hash_table(), rz_bin_elf_get_dt_info(), rz_bin_elf_v2p(), RZ_LOG_WARN, rz_return_val_if_fail, ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_number_of_symbols_from_hash_table().

◆ rz_bin_elf_get_head_flag()

RZ_OWN char* Elf_() rz_bin_elf_get_head_flag ( RZ_NONNULL ELFOBJ bin)

Return the head flag.

Returns
allocated string

...

Definition at line 1487 of file elf_info.c.

1487  {
1489 
1490  char *head_flag = get_head_flag(bin);
1491 
1492  if (RZ_STR_ISEMPTY(head_flag)) {
1493  free(head_flag);
1494  return strdup("unknown_flag");
1495  }
1496 
1497  return head_flag;
1498 }
static char * get_head_flag(ELFOBJ *bin)
Definition: elf_info.c:776
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67

References free(), get_head_flag(), NULL, rz_return_val_if_fail, RZ_STR_ISEMPTY, and strdup().

◆ rz_bin_elf_get_import()

RZ_BORROW RzBinElfSymbol* Elf_() rz_bin_elf_get_import ( RZ_NONNULL ELFOBJ bin,
ut32  ordinal 
)

Definition at line 316 of file elf_imports.c.

316  {
318 
319  RzBinElfSymbol *import;
321  if (import->ordinal == ordinal) {
322  return import;
323  }
324  }
325 
326  return NULL;
327 }
#define rz_bin_elf_foreach_imports(bin, import)
Definition: elf.h:50

References NULL, rz_bin_elf_foreach_imports, and rz_return_val_if_fail.

◆ rz_bin_elf_get_init_offset()

ut64 Elf_() rz_bin_elf_get_init_offset ( RZ_NONNULL ELFOBJ bin)

Compute the init offset of the binary.

Parameters
elfbinary
Returns
the init offset

Get the offset from the vaddr store in the dynamic section (dt_init)

Definition at line 1863 of file elf_info.c.

1863  {
1865 
1866  ut64 addr;
1867 
1869  return 0;
1870  }
1871 
1873  return 0;
1874  }
1875 
1876  return Elf_(rz_bin_elf_v2p)(bin, addr);
1877 }
#define DT_INIT
Definition: common.h:549

References addr, DT_INIT, Elf_(), rz_bin_elf_get_dt_info(), rz_bin_elf_has_dt_dynamic(), rz_bin_elf_v2p(), rz_return_val_if_fail, and ut64().

◆ rz_bin_elf_get_intrp()

RZ_OWN char* Elf_() rz_bin_elf_get_intrp ( RZ_NONNULL ELFOBJ bin)

Get the program interpreter.

Parameters
elfbinary
Returns
an allocated string

Get the program interpreter from the phdr

Definition at line 1568 of file elf_info.c.

1568  {
1570 
1571  if (!Elf_(rz_bin_elf_has_segments)(bin)) {
1572  return NULL;
1573  }
1574 
1576  if (!segment || !segment->is_valid) {
1577  return NULL;
1578  }
1579 
1580  return get_elf_intrp(bin, segment);
1581 }
RzBinElfSegment
Definition: elf.h:131
RZ_BORROW RzBinElfSegment *Elf_() rz_bin_elf_get_segment_with_type(RZ_NONNULL ELFOBJ *bin, Elf_(Word) type)
Definition: elf_segments.c:120
static char * get_elf_intrp(ELFOBJ *bin, RzBinElfSegment *segment)
Definition: elf_info.c:646
#define PT_INTERP
Definition: common.h:305

References Elf_(), get_elf_intrp(), NULL, PT_INTERP, rz_bin_elf_get_segment_with_type(), rz_bin_elf_has_segments(), rz_return_val_if_fail, and RzBinElfSegment.

◆ rz_bin_elf_get_libs()

RZ_OWN RzList* Elf_() rz_bin_elf_get_libs ( RZ_NONNULL ELFOBJ bin)

List all imported lib.

Parameters
elfbinary
Returns
an allocated list of RzBinElfLib

Use dynamic information (dt_needed) to generate a list of imported lib

Definition at line 877 of file elf_info.c.

877  {
879 
880  if (!Elf_(rz_bin_elf_has_dt_dynamic)(bin) || !bin->dynstr) {
881  return NULL;
882  }
883 
884  RzVector *dt_needed = Elf_(rz_bin_elf_get_dt_needed)(bin);
885  if (!dt_needed) {
886  return NULL;
887  }
888 
889  RzList *result = rz_list_newf(free);
890  if (!result) {
891  return NULL;
892  }
893 
894  ut64 *iter = NULL;
895  rz_vector_foreach(dt_needed, iter) {
896  char *tmp = Elf_(rz_bin_elf_strtab_get_dup)(bin->dynstr, *iter);
897  if (!tmp) {
898  rz_list_free(result);
899  return NULL;
900  }
901 
902  if (!rz_list_append(result, tmp)) {
903  rz_list_free(result);
904  return NULL;
905  }
906  }
907 
908  return result;
909 }
RZ_BORROW RzVector *Elf_() rz_bin_elf_get_dt_needed(RZ_NONNULL ELFOBJ *bin)
Definition: elf_dynamic.c:88
RZ_OWN char *Elf_() rz_bin_elf_strtab_get_dup(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
Definition: elf_strtab.c:52
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
#define rz_vector_foreach(vec, it)
Definition: rz_vector.h:169

References Elf_(), free(), NULL, rz_bin_elf_get_dt_needed(), rz_bin_elf_has_dt_dynamic(), rz_bin_elf_strtab_get_dup(), rz_list_append(), rz_list_free(), rz_list_newf(), rz_return_val_if_fail, rz_vector_foreach, autogen_x86imm::tmp, and ut64().

◆ rz_bin_elf_get_machine_name()

RZ_OWN char* Elf_() rz_bin_elf_get_machine_name ( RZ_NONNULL ELFOBJ bin)

Return a string representing the machine name.

Parameters
elftype
Returns
allocated string

Use http://www.sco.com/developers/gabi/latest/ch4.eheader.html and the elf header (e_machine)

Definition at line 1508 of file elf_info.c.

1508  {
1510 
1511  for (size_t i = 0; i < RZ_ARRAY_SIZE(machine_name_translation_table); i++) {
1512  if (bin->ehdr.e_machine == machine_name_translation_table[i].machine) {
1514  }
1515  }
1516 
1517  return rz_str_newf("<unknown>: 0x%x", bin->ehdr.e_machine);
1518 }
static const struct machine_name_translation machine_name_translation_table[]
Definition: elf_info.c:69

References i, machine_name_translation_table, NULL, RZ_ARRAY_SIZE, rz_return_val_if_fail, rz_str_newf(), and strdup().

◆ rz_bin_elf_get_main_offset()

ut64 Elf_() rz_bin_elf_get_main_offset ( RZ_NONNULL ELFOBJ bin)

Compute the main offset of the binary.

Parameters
elfbinary
Returns
the main offset

...

Definition at line 1886 of file elf_info.c.

1886  {
1888 
1889  ut8 buf[256] = { 0 };
1891  ut64 main_addr;
1892 
1893  if (entry == UT64_MAX || entry > bin->size || (entry + sizeof(buf)) > bin->size) {
1894  return UT64_MAX;
1895  }
1896 
1897  if (rz_buf_read_at(bin->b, entry, buf, sizeof(buf)) < 0) {
1898  return UT64_MAX;
1899  }
1900 
1901  main_addr = get_main_offset_arm64(bin, entry, buf);
1902  if (main_addr != UT64_MAX) {
1903  return main_addr;
1904  }
1905 
1906  main_addr = get_main_offset_arm_glibc(bin, entry, buf);
1907  if (main_addr != UT64_MAX) {
1908  return main_addr;
1909  }
1910 
1912  if (main_addr != UT64_MAX) {
1913  return main_addr;
1914  }
1915 
1916  main_addr = get_main_offset_x86_gcc(bin, entry, buf);
1917  if (main_addr != UT64_MAX) {
1918  return main_addr;
1919  }
1920 
1921  main_addr = get_main_offset_x86_pie(bin, entry, buf);
1922  if (main_addr != UT64_MAX) {
1923  return main_addr;
1924  }
1925 
1926  main_addr = get_main_offset_x86_non_pie(bin, entry, buf);
1927  if (main_addr != UT64_MAX) {
1928  return main_addr;
1929  }
1930 
1931  main_addr = get_main_offset_linux_64_pie(bin, entry, buf);
1932  if (main_addr != UT64_MAX) {
1933  return main_addr;
1934  }
1935 
1937 }
static ut64 get_main_offset_arm_glibc(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:477
static ut64 get_main_offset_x86_gcc(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:396
static ut64 get_main_offset_arm64(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:488
static ut64 get_main_offset_mips(ELFOBJ *bin, ut64 entry, ut8 *buf, size_t size)
Definition: elf_info.c:408
static ut64 get_main_offset_x86_non_pie(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:344
static ut64 get_main_offset_from_symbol(ELFOBJ *bin)
Definition: elf_info.c:296
static ut64 get_main_offset_x86_pie(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:364
static ut64 get_main_offset_linux_64_pie(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:311
voidpf void * buf
Definition: ioapi.h:138

References Elf_(), get_main_offset_arm64(), get_main_offset_arm_glibc(), get_main_offset_from_symbol(), get_main_offset_linux_64_pie(), get_main_offset_mips(), get_main_offset_x86_gcc(), get_main_offset_x86_non_pie(), get_main_offset_x86_pie(), RZ_ARRAY_SIZE, rz_bin_elf_get_entry_offset(), rz_buf_read_at(), rz_return_val_if_fail, ut64(), and UT64_MAX.

◆ rz_bin_elf_get_num_relocs_dynamic_plt()

ut64 Elf_() rz_bin_elf_get_num_relocs_dynamic_plt ( RZ_NONNULL ELFOBJ bin)

Definition at line 255 of file elf_relocs.c.

255  {
257 
258  ut64 dt_pltrel;
259  ut64 size;
260 
262  return 0;
263  }
264 
265  ut64 entry_size = get_size_rel_mode(dt_pltrel);
266  return size / entry_size;
267 }
static ut64 get_size_rel_mode(ut64 mode)
Definition: elf_relocs.c:56
#define DT_PLTREL
Definition: common.h:557
#define DT_PLTRELSZ
Definition: common.h:539

References DT_PLTREL, DT_PLTRELSZ, Elf_, relocs_segment::entry_size, get_size_rel_mode(), rz_bin_elf_get_dt_info(), rz_return_val_if_fail, and ut64().

Referenced by get_import_addr_ppc().

◆ rz_bin_elf_get_number_of_symbols_from_gnu_hash_table()

size_t Elf_() rz_bin_elf_get_number_of_symbols_from_gnu_hash_table ( RZ_NONNULL ELFOBJ bin)

Definition at line 106 of file elf_hash.c.

106  {
107  rz_return_val_if_fail(bin, false);
108 
109  RzBinElfGnuHashTable table;
110  if (!Elf_(rz_bin_elf_get_gnu_hash_table)(bin, &table)) {
111  return 0;
112  }
113 
114  ut64 bloom_offset = table.offset + sizeof(struct gnu_hash_table);
115  ut64 bucket_offset = bloom_offset + table.data.bloom_size * sizeof(Elf_(Addr));
116  ut64 chain_offset = bucket_offset + table.data.nbuckets * sizeof(Elf_(Word));
117 
118  size_t index = get_highest_chain_index_in_gnu_hash_table_buckets(bin, &table, bucket_offset);
119  return get_highest_symbol_index_in_gnu_hash_table_chains(bin, &table, chain_offset, index);
120 }
bool Elf_() rz_bin_elf_get_gnu_hash_table(RZ_NONNULL ELFOBJ *bin, RzBinElfGnuHashTable *result)
Definition: elf_hash.c:64
static size_t get_highest_chain_index_in_gnu_hash_table_buckets(ELFOBJ *bin, RzBinElfGnuHashTable *table, ut64 bucket_offset)
Definition: elf_hash.c:23
static size_t get_highest_symbol_index_in_gnu_hash_table_chains(ELFOBJ *bin, RzBinElfGnuHashTable *table, ut64 chain_offset, size_t index)
Definition: elf_hash.c:39
struct gnu_hash_table data
Definition: elf.h:66

References rz_bin_elf_gnu_hash_table_t::data, Elf_, get_highest_chain_index_in_gnu_hash_table_buckets(), get_highest_symbol_index_in_gnu_hash_table_chains(), rz_bin_elf_gnu_hash_table_t::offset, rz_bin_elf_get_gnu_hash_table(), rz_return_val_if_fail, and ut64().

◆ rz_bin_elf_get_number_of_symbols_from_hash_table()

size_t Elf_() rz_bin_elf_get_number_of_symbols_from_hash_table ( RZ_NONNULL ELFOBJ bin)

Definition at line 122 of file elf_hash.c.

122  {
123  rz_return_val_if_fail(bin, false);
124 
125  RzBinElfHashTable table;
126  if (!Elf_(rz_bin_elf_get_hash_table)(bin, &table)) {
127  return 0;
128  }
129 
130  return table.data.nchains;
131 }
bool Elf_() rz_bin_elf_get_hash_table(RZ_NONNULL ELFOBJ *bin, RzBinElfHashTable *result)
Definition: elf_hash.c:85
struct elf_hash_table data
Definition: elf.h:78

References rz_bin_elf_hash_table_::data, Elf_, rz_bin_elf_get_hash_table(), and rz_return_val_if_fail.

◆ rz_bin_elf_get_osabi_name()

RZ_OWN char* Elf_() rz_bin_elf_get_osabi_name ( RZ_NONNULL ELFOBJ bin)

Return the os application binary interface name.

Parameters
elfbinary
Returns
an allocated string

Check the ehdr or the shdr to get the os name

Definition at line 1527 of file elf_info.c.

1527  {
1529 
1531  if (name) {
1532  return name;
1533  }
1534 
1536  if (name) {
1537  return name;
1538  }
1539 
1540  return strdup("linux");
1541 }
static char * get_osabi_name_from_ehdr(ELFOBJ *bin)
Definition: elf_info.c:740
static char * get_osabi_name_from_shdr(ELFOBJ *bin)
Definition: elf_info.c:720
const char * name
Definition: op.c:541

References get_osabi_name_from_ehdr(), get_osabi_name_from_shdr(), name, NULL, rz_return_val_if_fail, and strdup().

◆ rz_bin_elf_get_prstatus_layout()

RZ_BORROW RzBinElfPrStatusLayout* Elf_() rz_bin_elf_get_prstatus_layout ( RZ_NONNULL ELFOBJ bin)

Definition at line 201 of file elf_notes.c.

201  {
203 
204  switch (bin->ehdr.e_machine) {
205  case EM_AARCH64:
206  return prstatus_layouts + AARCH64;
207  case EM_ARM:
208  return prstatus_layouts + ARM;
209  case EM_386:
210  return prstatus_layouts + X86;
211  case EM_X86_64:
212  return prstatus_layouts + X86_64;
213  }
214 
215  return NULL;
216 }
#define X86_64
Definition: elf_notes.c:12
#define X86
Definition: elf_notes.c:11
static RzBinElfPrStatusLayout prstatus_layouts[ARCH_LEN]
Definition: elf_notes.c:17
#define ARM
Definition: elf_notes.c:13
#define AARCH64
Definition: elf_notes.c:14
#define EM_AARCH64
Definition: elf_specs.h:161
#define EM_X86_64
Definition: common.h:151
#define EM_386
Definition: common.h:105
#define EM_ARM
Definition: common.h:129

References AARCH64, ARM, EM_386, EM_AARCH64, EM_ARM, EM_X86_64, NULL, prstatus_layouts, rz_return_val_if_fail, X86, and X86_64.

Referenced by parse_note_prstatus(), and rz_bin_elf_get_sp_val().

◆ rz_bin_elf_get_relocs_count()

size_t Elf_() rz_bin_elf_get_relocs_count ( RZ_NONNULL ELFOBJ bin)

Definition at line 245 of file elf_relocs.c.

245  {
247 
248  if (!bin->relocs) {
249  return 0;
250  }
251 
252  return rz_vector_len(bin->relocs);
253 }

References rz_return_val_if_fail, and rz_vector_len().

◆ rz_bin_elf_get_rpath()

RZ_OWN char* Elf_() rz_bin_elf_get_rpath ( RZ_NONNULL ELFOBJ bin)

Get the rpath.

Parameters
elfbinary
Returns
allocated string

Use DT_RPATH or DT_RUNPATH to return the string

Definition at line 1550 of file elf_info.c.

1550  {
1552 
1553  if (!Elf_(rz_bin_elf_has_segments)(bin) || !bin->dynstr || !has_dt_rpath_entry(bin)) {
1554  return NULL;
1555  }
1556 
1557  Elf_(Xword) val = get_dt_rpath(bin);
1558  return Elf_(rz_bin_elf_strtab_get_dup)(bin->dynstr, val);
1559 }
ut16 val
Definition: armass64_const.h:6
static bool has_dt_rpath_entry(ELFOBJ *bin)
Definition: elf_info.c:702

References Elf_(), has_dt_rpath_entry(), NULL, rz_bin_elf_has_segments(), rz_bin_elf_strtab_get_dup(), rz_return_val_if_fail, and val.

◆ rz_bin_elf_get_section()

RZ_BORROW RzBinElfSection* Elf_() rz_bin_elf_get_section ( RZ_NONNULL ELFOBJ bin,
Elf_(Half)  index 
)

Definition at line 264 of file elf_sections.c.

264  {
266 
267  if (!bin->sections) {
268  return NULL;
269  }
270 
271  if (index < rz_vector_len(bin->sections)) {
272  return rz_vector_index_ptr(bin->sections, index);
273  }
274 
275  return NULL;
276 }
static void * rz_vector_index_ptr(RzVector *vec, size_t index)
Definition: rz_vector.h:88

References NULL, rz_return_val_if_fail, rz_vector_index_ptr(), and rz_vector_len().

Referenced by convert_elf_symbol_entry(), fix_rva_and_offset_relocable_file(), and get_section_elf_symbols().

◆ rz_bin_elf_get_section_with_name()

RZ_BORROW RzBinElfSection* Elf_() rz_bin_elf_get_section_with_name ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL const char *  name 
)

Definition at line 278 of file elf_sections.c.

278  {
280 
283  if (section->is_valid && section->name && !strcmp(section->name, name)) {
284  return section;
285  }
286  }
287 
288  return NULL;
289 }
#define rz_bin_elf_foreach_sections(bin, section)
Definition: elf.h:30

References NULL, rz_bin_elf_foreach_sections, and rz_return_val_if_fail.

Referenced by get_entry_offset_from_shdr(), get_gnu_debugdata_elf_symbols(), get_import_addr_x86(), get_import_addr_x86_manual(), and rz_bin_elf_get_compiler().

◆ rz_bin_elf_get_segment_with_type()

RZ_BORROW RzBinElfSegment* Elf_() rz_bin_elf_get_segment_with_type ( RZ_NONNULL ELFOBJ bin,
Elf_(Word)  type 
)

Definition at line 120 of file elf_segments.c.

120  {
122 
125  if (iter->data.p_type == type) {
126  return iter;
127  }
128  }
129 
130  return NULL;
131 }
#define rz_bin_elf_foreach_segments(bin, segment)
Definition: elf.h:26

References NULL, rz_bin_elf_foreach_segments, rz_return_val_if_fail, RzBinElfSegment, and type.

Referenced by elf_has_gnu_relro(), init_dt_dynamic(), rz_bin_elf_get_intrp(), rz_bin_elf_has_nx(), and rz_bin_elf_is_static().

◆ rz_bin_elf_get_sp_val()

ut64 Elf_() rz_bin_elf_get_sp_val ( RZ_NONNULL ELFOBJ bin)

Get the stack pointer value.

Parameters
elfbinary
Returns
allocated string

Get the value of the stack pointer register in a core file from NT_PRSTATUS

Definition at line 16 of file elf_corefile.c.

16  {
18 
20  if (!layout) {
21  return UT64_MAX;
22  }
23 
24  RzVector *notes;
27  rz_vector_foreach(notes, tmp) {
28  if (tmp->type != NT_PRSTATUS) {
29  continue;
30  }
31 
32  RzBinElfNotePrStatus *note = &tmp->prstatus;
33  if (layout->sp_offset + layout->sp_size / 8 > note->regstate_size) {
34  return UT64_MAX;
35  }
36 
37  return rz_read_ble(note->regstate + layout->sp_offset, bin->big_endian, layout->sp_size);
38  }
39  }
40 
41  return UT64_MAX;
42 }
#define rz_bin_elf_foreach_notes_segment(bin, notes)
Definition: elf.h:42
RzBinElfNote
Definition: elf.h:182
RZ_BORROW RzBinElfPrStatusLayout *Elf_() rz_bin_elf_get_prstatus_layout(RZ_NONNULL ELFOBJ *bin)
Definition: elf_notes.c:201
#define NT_PRSTATUS
Definition: common.h:393
static ut64 rz_read_ble(const void *src, bool big_endian, int size)
Definition: rz_endian.h:517
Information about the binary layout in a NT_PRSTATUS note for core files of a certain architecture an...
Definition: elf.h:82
ut64 sp_offset
Definition: elf.h:108
ut8 sp_size
Size of the stack pointer register in bits.
Definition: elf.h:97

References Elf_, NT_PRSTATUS, rz_bin_elf_note_prstatus_t::regstate, rz_bin_elf_note_prstatus_t::regstate_size, rz_bin_elf_foreach_notes_segment, rz_bin_elf_get_prstatus_layout(), rz_read_ble(), rz_return_val_if_fail, rz_vector_foreach, RzBinElfNote, prstatus_layout_t::sp_offset, prstatus_layout_t::sp_size, autogen_x86imm::tmp, and UT64_MAX.

◆ rz_bin_elf_get_symbol()

RZ_BORROW RzBinElfSymbol* Elf_() rz_bin_elf_get_symbol ( RZ_NONNULL ELFOBJ bin,
ut32  ordinal 
)

Definition at line 473 of file elf_symbols.c.

473  {
475 
476  RzBinElfSymbol *symbol;
478  if (symbol->ordinal == ordinal) {
479  return symbol;
480  }
481  }
482 
483  return NULL;
484 }
#define rz_bin_elf_foreach_symbols(bin, symbol)
Definition: elf.h:46

References NULL, rz_bin_elf_symbol_t::ordinal, rz_bin_elf_foreach_symbols, and rz_return_val_if_fail.

◆ rz_bin_elf_get_symbols_info()

RZ_OWN Sdb* Elf_() rz_bin_elf_get_symbols_info ( RZ_NONNULL ELFOBJ bin)

Definition at line 1301 of file elf_info.c.

1301  {
1302  rz_return_val_if_fail(bin, false);
1303 
1305  return NULL;
1306  }
1307 
1308  Sdb *res = sdb_new0();
1309  if (!res) {
1310  return NULL;
1311  }
1312 
1313  Sdb *sdb = get_gnu_verneed(bin);
1314  if (sdb && !sdb_ns_set(res, "verneed", sdb)) {
1315  sdb_free(res);
1316  sdb_free(sdb);
1317  return NULL;
1318  }
1319  sdb_free(sdb);
1320 
1321  sdb = get_gnu_versym(bin);
1322  if (sdb && !sdb_ns_set(res, "versym", sdb)) {
1323  sdb_free(res);
1324  sdb_free(sdb);
1325  return NULL;
1326  }
1327  sdb_free(sdb);
1328 
1329  return res;
1330 }
static Sdb * get_gnu_verneed(ELFOBJ *bin)
Definition: elf_info.c:1247
static Sdb * get_gnu_versym(ELFOBJ *bin)
Definition: elf_info.c:1089
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43

References Elf_(), get_gnu_verneed(), get_gnu_versym(), NULL, rz_bin_elf_is_executable(), rz_return_val_if_fail, sdb_free(), sdb_new0(), and sdb_ns_set().

Referenced by init_symbols_info_aux().

◆ rz_bin_elf_get_targets_map_base()

ut64 Elf_() rz_bin_elf_get_targets_map_base ( ELFOBJ bin)

Definition at line 44 of file elf_map.c.

44  {
45  ut64 result = get_targets_map_base(bin);
46  result += 0x8; // small additional shift to not overlap with symbols like _end
47  return result + rz_num_align_delta(result, sizeof(Elf_(Addr)));
48 }
static ut64 get_targets_map_base(ELFOBJ *bin)
Definition: elf_map.c:36
static ut64 rz_num_align_delta(ut64 v, ut64 alignment)
Padding to align v to the next alignment-boundary.
Definition: rz_num.h:116

References Elf_, get_targets_map_base(), rz_num_align_delta(), and ut64().

Referenced by init().

◆ rz_bin_elf_has_dt_dynamic()

bool Elf_() rz_bin_elf_has_dt_dynamic ( RZ_NONNULL ELFOBJ bin)

◆ rz_bin_elf_has_imports()

bool Elf_() rz_bin_elf_has_imports ( RZ_NONNULL ELFOBJ bin)

Definition at line 342 of file elf_imports.c.

342  {
343  rz_return_val_if_fail(bin, false);
344  return bin->imports;
345 }

References rz_return_val_if_fail.

◆ rz_bin_elf_has_notes()

bool Elf_() rz_bin_elf_has_notes ( RZ_NONNULL ELFOBJ bin)

Definition at line 255 of file elf_notes.c.

255  {
256  rz_return_val_if_fail(bin, false);
257  return bin->notes;
258 }

References rz_return_val_if_fail.

◆ rz_bin_elf_has_nx()

bool Elf_() rz_bin_elf_has_nx ( RZ_NONNULL ELFOBJ bin)

Check if the stack is not executable.

Parameters
elfbinary
Returns
true, false

Check p_flags from the segment PT_GNU_STACK

Definition at line 1615 of file elf_info.c.

1615  {
1616  rz_return_val_if_fail(bin, false);
1617 
1618  if (!Elf_(rz_bin_elf_has_segments)(bin)) {
1619  return false;
1620  }
1621 
1623  if (!segment || !segment->is_valid) {
1624  return false;
1625  }
1626 
1627  return !(segment->data.p_flags & PF_X);
1628 }
#define PF_X
Definition: common.h:322
#define PT_GNU_STACK
Definition: common.h:317

References Elf_(), PF_X, PT_GNU_STACK, rz_bin_elf_get_segment_with_type(), rz_bin_elf_has_segments(), rz_return_val_if_fail, and RzBinElfSegment.

◆ rz_bin_elf_has_relocs()

bool Elf_() rz_bin_elf_has_relocs ( RZ_NONNULL ELFOBJ bin)

Definition at line 239 of file elf_relocs.c.

239  {
240  rz_return_val_if_fail(bin, false);
241 
242  return bin->relocs;
243 }

References rz_return_val_if_fail.

Referenced by get_import_addr().

◆ rz_bin_elf_has_relro()

int Elf_() rz_bin_elf_has_relro ( RZ_NONNULL ELFOBJ bin)

Analyse if the elf binary has relro or partial relro.

Parameters
elfbinary
Returns
RZ_BIN_ELF_NO_RELRO, RZ_BIN_ELF_PART_RELRO or RZ_BIN_ELF_FULL_RELRO

Check if the elf has bind now enable and with PT_GNU_RELRO can deduct the relro type

Definition at line 1733 of file elf_info.c.

1733  {
1735 
1736  bool is_bind_now = elf_is_bind_now(bin);
1737  bool has_gnu_relro = elf_has_gnu_relro(bin);
1738 
1739  if (has_gnu_relro) {
1740  if (is_bind_now) {
1741  return RZ_BIN_ELF_FULL_RELRO;
1742  }
1743 
1744  return RZ_BIN_ELF_PART_RELRO;
1745  }
1746 
1747  return RZ_BIN_ELF_NO_RELRO;
1748 }
#define RZ_BIN_ELF_NO_RELRO
Definition: elf.h:20
#define RZ_BIN_ELF_FULL_RELRO
Definition: elf.h:22
#define RZ_BIN_ELF_PART_RELRO
Definition: elf.h:21
static bool elf_is_bind_now(ELFOBJ *bin)
Definition: elf_info.c:552
static bool elf_has_gnu_relro(ELFOBJ *bin)
Definition: elf_info.c:566

References elf_has_gnu_relro(), elf_is_bind_now(), RZ_BIN_ELF_FULL_RELRO, RZ_BIN_ELF_NO_RELRO, RZ_BIN_ELF_PART_RELRO, and rz_return_val_if_fail.

Referenced by get_import_addr_x86_manual(), and init_dt_dynamic_sdb().

◆ rz_bin_elf_has_sections()

bool Elf_() rz_bin_elf_has_sections ( RZ_NONNULL ELFOBJ bin)

Definition at line 440 of file elf_sections.c.

440  {
441  rz_return_val_if_fail(bin, false);
442 
443  return bin->sections;
444 }

References rz_return_val_if_fail.

Referenced by rz_bin_elf_is_stripped().

◆ rz_bin_elf_has_segments()

◆ rz_bin_elf_has_symbols()

bool Elf_() rz_bin_elf_has_symbols ( RZ_NONNULL ELFOBJ bin)

Definition at line 534 of file elf_symbols.c.

534  {
535  rz_return_val_if_fail(bin, false);
536  return bin->symbols;
537 }

References rz_return_val_if_fail.

◆ rz_bin_elf_has_va()

bool Elf_() rz_bin_elf_has_va ( ELFOBJ bin)

Check if the elf use virtual address.

Parameters
elfbinary
Returns
always true

Return always true

Definition at line 1637 of file elf_info.c.

1637  {
1638  return true;
1639 }

◆ rz_bin_elf_is_arm_binary_supporting_thumb()

bool Elf_() rz_bin_elf_is_arm_binary_supporting_thumb ( RZ_NONNULL ELFOBJ bin)

Definition at line 19 of file elf_arm.c.

19  {
20  rz_return_val_if_fail(bin, false);
21  return bin->ehdr.e_machine == EM_ARM;
22 }

References EM_ARM, and rz_return_val_if_fail.

Referenced by rz_bin_elf_get_bits().

◆ rz_bin_elf_is_big_endian()

bool Elf_() rz_bin_elf_is_big_endian ( RZ_NONNULL ELFOBJ bin)

Check the binary endianness.

Parameters
elftype
Returns
is_big_endian ?

Use the elf header (e_ident[EI_DATA]) to check the binary endianness

Definition at line 1757 of file elf_info.c.

1757  {
1758  rz_return_val_if_fail(bin, false);
1759 
1760  return bin->ehdr.e_ident[EI_DATA] == ELFDATA2MSB;
1761 }

References EI_DATA, ELFDATA2MSB, and rz_return_val_if_fail.

◆ rz_bin_elf_is_executable()

bool Elf_() rz_bin_elf_is_executable ( RZ_NONNULL ELFOBJ bin)

Check if the elf binary is executable.

Parameters
elfbinary
Returns
is_executable ?

Use the elf header entry e_type to deduct if the elf is executable.

Definition at line 1648 of file elf_info.c.

1648  {
1649  rz_return_val_if_fail(bin, false);
1650 
1651  const Elf_(Half) type = bin->ehdr.e_type;
1652  return type == ET_EXEC || type == ET_DYN;
1653 }
#define ET_DYN
Definition: common.h:91
#define ET_EXEC
Definition: common.h:90

References Elf_(), ET_DYN, ET_EXEC, rz_return_val_if_fail, and type.

Referenced by get_dynamic_elf_symbols(), is_playstation_hack(), rz_bin_elf_get_entry_offset(), and rz_bin_elf_get_symbols_info().

◆ rz_bin_elf_is_relocatable()

bool Elf_() rz_bin_elf_is_relocatable ( RZ_NONNULL ELFOBJ bin)

Check if the elf binary is relocatable.

Parameters
elfbinary
Returns
is_relocatable ?

Use the elf header entry e_type to deduct if the elf is relocatable.

Definition at line 1662 of file elf_info.c.

1662  {
1663  rz_return_val_if_fail(bin, false);
1664  return bin->ehdr.e_type == ET_REL;
1665 }
#define ET_REL
Definition: common.h:89

References ET_REL, and rz_return_val_if_fail.

Referenced by convert_elf_symbol_entry(), filter_import(), fix_rva_and_offset(), init(), rz_bin_elf_get_baddr(), rz_bin_elf_p2v(), rz_bin_elf_v2p(), and set_elf_section_aux().

◆ rz_bin_elf_is_static()

bool Elf_() rz_bin_elf_is_static ( RZ_NONNULL ELFOBJ bin)

Check if the binary is statically-linked library.

Parameters
elfbinary
Returns
is_static ?

Check the presence of PT_INTERP or PT_DYNAMIC in the program header

Definition at line 1674 of file elf_info.c.

1674  {
1675  rz_return_val_if_fail(bin, false);
1676 
1678  if (segment && segment->is_valid) {
1679  return false;
1680  }
1681 
1683  if (segment && segment->is_valid) {
1684  return false;
1685  }
1686 
1687  return true;
1688 }
#define PT_DYNAMIC
Definition: common.h:304

References Elf_(), PT_DYNAMIC, PT_INTERP, rz_bin_elf_get_segment_with_type(), rz_return_val_if_fail, and RzBinElfSegment.

Referenced by init(), is_playstation_hack(), and rz_bin_elf_get_bits().

◆ rz_bin_elf_is_stripped()

bool Elf_() rz_bin_elf_is_stripped ( RZ_NONNULL ELFOBJ bin)

Check if the binary is stripped.

Parameters
elfbinary
is_stripped?
Returns
a ptr to a new allocated RzBinSymbol

Use the shdr to check if the binary is stripped

Definition at line 1591 of file elf_info.c.

1591  {
1592  rz_return_val_if_fail(bin, false);
1593 
1594  if (!Elf_(rz_bin_elf_has_sections)(bin)) {
1595  return false;
1596  }
1597 
1600  if (section->type == SHT_SYMTAB) {
1601  return false;
1602  }
1603  }
1604 
1605  return true;
1606 }
#define SHT_SYMTAB
Definition: common.h:333

References Elf_(), rz_bin_elf_foreach_sections, rz_bin_elf_has_sections(), rz_return_val_if_fail, and SHT_SYMTAB.

◆ rz_bin_elf_is_thumb_addr()

bool Elf_() rz_bin_elf_is_thumb_addr ( ut64  addr)

◆ rz_bin_elf_mul_addr()

bool Elf_() rz_bin_elf_mul_addr ( Elf_(Addr) *  result,
Elf_(Addr)  addr,
Elf_(Addr)  value 
)

Definition at line 154 of file elf_misc.c.

154  {
155 #if RZ_BIN_ELF64
156  return UT64_MUL((ut64 *)result, addr, value);
157 #else
158  return UT32_MUL((ut32 *)result, addr, value);
159 #endif
160 }
static int UT32_MUL(ut32 *r, ut32 a, ut32 b)
Definition: rz_endian.h:643
static int UT64_MUL(ut64 *r, ut64 a, ut64 b)
Definition: rz_endian.h:613

References addr, UT32_MUL(), ut64(), UT64_MUL(), and value.

Referenced by parse_note_file().

◆ rz_bin_elf_mul_off()

bool Elf_() rz_bin_elf_mul_off ( Elf_(Off) *  result,
Elf_(Off)  addr,
Elf_(Off)  value 
)

Definition at line 162 of file elf_misc.c.

162  {
163 #if RZ_BIN_ELF64
164  return UT64_MUL((ut64 *)result, addr, value);
165 #else
166  return UT32_MUL((ut32 *)result, addr, value);
167 #endif
168 }

References addr, UT32_MUL(), ut64(), UT64_MUL(), and value.

Referenced by rz_bin_elf_check_array().

◆ rz_bin_elf_new_buf()

RZ_OWN ELFOBJ* Elf_() rz_bin_elf_new_buf ( RZ_NONNULL RzBuffer buf,
RZ_NONNULL RzBinObjectLoadOptions options 
)

Definition at line 339 of file elf.c.

339  {
341 
342  ELFOBJ *bin = RZ_NEW0(ELFOBJ);
343  if (!bin) {
344  return NULL;
345  }
346 
347  bin->b = rz_buf_ref(buf);
348  bin->kv = sdb_new0();
349 
350  bin->size = rz_buf_size(buf);
351 
352  if (!init(bin, options)) {
354  return NULL;
355  }
356 
357  return bin;
358 }
static bool init(ELFOBJ *bin, RzBinObjectLoadOptions *options)
Definition: elf.c:296
void Elf_() rz_bin_elf_free(RZ_NONNULL ELFOBJ *bin)
Free the elf binary.
Definition: elf.c:366
#define ELFOBJ
Definition: elf.h:24
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225

References Elf_, ELFOBJ, init(), NULL, options, rz_bin_elf_free(), rz_buf_ref(), rz_buf_size(), RZ_NEW0, rz_return_val_if_fail, and sdb_new0().

Referenced by get_gnu_debugdata_elf_symbols().

◆ rz_bin_elf_notes_new()

RZ_OWN RzVector* Elf_() rz_bin_elf_notes_new ( RZ_NONNULL ELFOBJ bin)

Definition at line 218 of file elf_notes.c.

218  {
219  rz_return_val_if_fail(bin, false);
220 
222  if (!result) {
223  return NULL;
224  }
225 
226  RzBinElfSegment *segment;
227  rz_bin_elf_foreach_segments(bin, segment) {
228  if (!segment->is_valid || segment->data.p_type != PT_NOTE) {
229  continue;
230  }
231 
232  RzVector *notes = rz_vector_push(result, NULL);
233  if (!notes) {
234  rz_vector_free(result);
235  return NULL;
236  }
237 
238  rz_vector_init(notes, sizeof(RzBinElfNote), note_free, NULL);
239 
240  if (!set_note_segment(bin, notes, segment)) {
241  rz_vector_fini(notes);
242  rz_vector_free(result);
243  return NULL;
244  }
245  }
246 
247  if (!rz_vector_len(result)) {
248  rz_vector_free(result);
249  return NULL;
250  }
251 
252  return result;
253 }
static void note_free(void *e, RZ_UNUSED void *user)
Definition: elf_notes.c:183
static bool set_note_segment(ELFOBJ *bin, RzVector *notes, RzBinElfSegment *segment)
Definition: elf_notes.c:153
static void note_segment_free(void *e, RZ_UNUSED void *user)
Definition: elf_notes.c:196
#define PT_NOTE
Definition: common.h:306
RZ_API void * rz_vector_push(RzVector *vec, void *x)
Definition: vector.c:197

References note_free(), note_segment_free(), NULL, PT_NOTE, rz_bin_elf_foreach_segments, rz_return_val_if_fail, rz_vector_fini(), rz_vector_free(), rz_vector_init(), rz_vector_len(), rz_vector_new(), rz_vector_push(), RzBinElfNote, RzBinElfSegment, and set_note_segment().

Referenced by init().

◆ rz_bin_elf_p2v()

ut64 Elf_() rz_bin_elf_p2v ( RZ_NONNULL ELFOBJ bin,
ut64  paddr 
)

Convert a physical address to the virtual address.

Parameters
elfbinary
Returns
virtual addr

Converts a physical address to the virtual address, looking at the program headers in the binary bin

Definition at line 400 of file elf.c.

400  {
402 
405  return bin->baddr + paddr;
406  }
407 
408  return UT64_MAX;
409  }
410 
411  RzBinElfSegment *segment;
412  rz_bin_elf_foreach_segments(bin, segment) {
413  if (segment->data.p_type == PT_LOAD && in_physical_phdr(segment, paddr)) {
414  return segment->data.p_vaddr + paddr - segment->data.p_offset;
415  }
416  }
417 
418  return UT64_MAX;
419 }
static bool in_physical_phdr(RzBinElfSegment *segment, ut64 addr)
Definition: elf.c:109
bool Elf_() rz_bin_elf_is_relocatable(RZ_NONNULL ELFOBJ *bin)
Check if the elf binary is relocatable.
Definition: elf_info.c:1662
#define PT_LOAD
Definition: common.h:303

References Elf_, in_physical_phdr(), PT_LOAD, rz_bin_elf_foreach_segments, rz_bin_elf_has_segments(), rz_bin_elf_is_relocatable(), rz_return_val_if_fail, RzBinElfSegment, and UT64_MAX.

Referenced by convert_elf_symbol_entry(), fix_rva_and_offset_relocable_file(), get_main_offset_arm64(), get_main_offset_linux_64_pie(), get_main_offset_x86_gcc(), and get_main_offset_x86_pie().

◆ rz_bin_elf_print_ehdr()

bool Elf_() rz_bin_elf_print_ehdr ( ELFOBJ bin,
RZ_NONNULL PrintfCallback  cb 
)

Definition at line 202 of file elf_ehdr.c.

202  {
203  rz_return_val_if_fail(bin && cb, false);
204 
219 }
RZ_OWN char *Elf_() rz_bin_elf_get_e_type_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:170
RZ_OWN char *Elf_() rz_bin_elf_get_e_ehsize_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:82
RZ_OWN char *Elf_() rz_bin_elf_get_e_phnum_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:134
RZ_OWN char *Elf_() rz_bin_elf_get_e_shstrndx_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:164
RZ_OWN char *Elf_() rz_bin_elf_get_e_entry_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:88
RZ_OWN char *Elf_() rz_bin_elf_get_e_shoff_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:158
RZ_OWN char *Elf_() rz_bin_elf_get_e_shentsize_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:146
RZ_OWN char *Elf_() rz_bin_elf_get_e_machine_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:122
RZ_OWN char *Elf_() rz_bin_elf_get_e_flags_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:94
RZ_OWN char *Elf_() rz_bin_elf_get_e_version_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:176
RZ_OWN char *Elf_() rz_bin_elf_get_e_phoff_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:140
RZ_OWN char *Elf_() rz_bin_elf_get_e_indent_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:100
RZ_OWN char *Elf_() rz_bin_elf_get_e_shnum_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:152
static bool print_ehdr_aux(ELFOBJ *bin, PrintfCallback cb, ut64 offset, const char *name, char *(*get_value)(ELFOBJ *bin))
Definition: elf_ehdr.c:70
RZ_OWN char *Elf_() rz_bin_elf_get_e_phentsize_as_string(RZ_NONNULL ELFOBJ *bin)
Definition: elf_ehdr.c:128
#define E_PHENTSIZE_OFFSET
Definition: elf_specs.h:54
#define E_MACHINE_OFFSET
Definition: elf_specs.h:47
#define E_TYPE_OFFSET
Definition: elf_specs.h:46
#define E_SHNUM_OFFSET
Definition: elf_specs.h:57
#define E_VERSION_OFFSET
Definition: elf_specs.h:48
#define E_IDENT_OFFSET
Definition: elf_specs.h:45
#define E_FLAGS_OFFSET
Definition: elf_specs.h:52
#define E_SHENTSIZE_OFFSET
Definition: elf_specs.h:56
#define E_PHOFF_OFFSET
Definition: elf_specs.h:50
#define E_ENTRYPOINT_OFFSET
Definition: elf_specs.h:49
#define E_SHOFF_OFFSET
Definition: elf_specs.h:51
#define E_PHNUM_OFFSET
Definition: elf_specs.h:55
#define E_SHSTRNDX_OFFSET
Definition: elf_specs.h:58
#define E_EHSIZE_OFFSET
Definition: elf_specs.h:53
static const char * cb[]
Definition: z80_tab.h:176

References cb, E_EHSIZE_OFFSET, E_ENTRYPOINT_OFFSET, E_FLAGS_OFFSET, E_IDENT_OFFSET, E_MACHINE_OFFSET, E_PHENTSIZE_OFFSET, E_PHNUM_OFFSET, E_PHOFF_OFFSET, E_SHENTSIZE_OFFSET, E_SHNUM_OFFSET, E_SHOFF_OFFSET, E_SHSTRNDX_OFFSET, E_TYPE_OFFSET, E_VERSION_OFFSET, Elf_(), print_ehdr_aux(), rz_bin_elf_get_e_ehsize_as_string(), rz_bin_elf_get_e_entry_as_string(), rz_bin_elf_get_e_flags_as_string(), rz_bin_elf_get_e_indent_as_string(), rz_bin_elf_get_e_machine_as_string(), rz_bin_elf_get_e_phentsize_as_string(), rz_bin_elf_get_e_phnum_as_string(), rz_bin_elf_get_e_phoff_as_string(), rz_bin_elf_get_e_shentsize_as_string(), rz_bin_elf_get_e_shnum_as_string(), rz_bin_elf_get_e_shoff_as_string(), rz_bin_elf_get_e_shstrndx_as_string(), rz_bin_elf_get_e_type_as_string(), rz_bin_elf_get_e_version_as_string(), and rz_return_val_if_fail.

◆ rz_bin_elf_read_addr()

bool Elf_() rz_bin_elf_read_addr ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Addr) *  result 
)

Definition at line 82 of file elf_misc.c.

82  {
83  rz_return_val_if_fail(bin && offset && result, false);
84 #if RZ_BIN_ELF64
85  return rz_buf_read_ble64_offset(bin->b, offset, (ut64 *)result, bin->big_endian);
86 #else
87  return rz_buf_read_ble32_offset(bin->b, offset, (ut32 *)result, bin->big_endian);
88 #endif
89 }

References rz_return_val_if_fail, and ut64().

Referenced by get_dynamic_entry_aux(), get_got_entry(), get_note_file_aux(), get_phdr_entry(), get_shdr_entry_aux(), get_symbol_entry_aux(), parse_note_file(), read_ehdr_other_aux(), and read_reloc_entry_aux().

◆ rz_bin_elf_read_char()

bool Elf_() rz_bin_elf_read_char ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT ut8 result 
)

Definition at line 52 of file elf_misc.c.

52  {
53  rz_return_val_if_fail(bin && offset && result, false);
54  return rz_buf_read8_offset(bin->b, offset, result);
55 }
#define rz_buf_read8_offset(b, offset, result)
Definition: rz_buf.h:274

References rz_buf_read8_offset, and rz_return_val_if_fail.

Referenced by Elf_(), and get_symbol_entry_aux().

◆ rz_bin_elf_read_half()

bool Elf_() rz_bin_elf_read_half ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Half) *  result 
)

Definition at line 57 of file elf_misc.c.

57  {
58  rz_return_val_if_fail(bin && offset && result, false);
59  return rz_buf_read_ble16_offset(bin->b, offset, result, bin->big_endian);
60 }

References rz_return_val_if_fail.

Referenced by get_verdef_entry_aux(), get_vernaux_entry_aux(), get_verneed_entry_aux(), read_ehdr_other(), read_ehdr_other_aux(), and rz_bin_elf_read_versym().

◆ rz_bin_elf_read_off()

bool Elf_() rz_bin_elf_read_off ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Off) *  result 
)

Definition at line 91 of file elf_misc.c.

91  {
92  rz_return_val_if_fail(bin && offset && result, false);
93 #if RZ_BIN_ELF64
94  return rz_buf_read_ble64_offset(bin->b, offset, (ut64 *)result, bin->big_endian);
95 #else
96  return rz_buf_read_ble32_offset(bin->b, offset, (ut32 *)result, bin->big_endian);
97 #endif
98 }

References rz_return_val_if_fail, and ut64().

Referenced by get_note_file_aux(), get_phdr_entry(), get_shdr_entry_aux(), and read_ehdr_other_aux().

◆ rz_bin_elf_read_section()

bool Elf_() rz_bin_elf_read_section ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Section) *  result 
)

Definition at line 100 of file elf_misc.c.

100  {
101  rz_return_val_if_fail(bin && offset && result, false);
102  return rz_buf_read_ble16_offset(bin->b, offset, (ut16 *)result, bin->big_endian);
103 }
uint16_t ut16

References rz_return_val_if_fail.

Referenced by get_symbol_entry_aux().

◆ rz_bin_elf_read_sword()

bool Elf_() rz_bin_elf_read_sword ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Sword) *  result 
)

Definition at line 67 of file elf_misc.c.

67  {
68  rz_return_val_if_fail(bin && offset && result, false);
69  return buffer_read_32_signed(bin, offset, result);
70 }
static bool buffer_read_32_signed(ELFOBJ *bin, ut64 *offset, st32 *result)
Definition: elf_misc.c:7

References buffer_read_32_signed(), and rz_return_val_if_fail.

Referenced by rz_bin_elf_read_sword_sxword().

◆ rz_bin_elf_read_sword_sxword()

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 
)

Definition at line 131 of file elf_misc.c.

131  {
132  rz_return_val_if_fail(bin && offset && result, false);
133 
134  return Elf_(rz_bin_elf_read_sword)(bin, offset, result);
135 }
bool Elf_() rz_bin_elf_read_sword(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Sword) *result)
Definition: elf_misc.c:67

References Elf_, rz_bin_elf_read_sword(), and rz_return_val_if_fail.

Referenced by get_dynamic_entry_aux(), and read_reloc_entry_aux().

◆ rz_bin_elf_read_sxword()

bool Elf_() rz_bin_elf_read_sxword ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Sxword) *  result 
)

Definition at line 77 of file elf_misc.c.

77  {
78  rz_return_val_if_fail(bin && offset && result, false);
79  return buffer_read_64_signed(bin, offset, (st64 *)result);
80 }
static bool buffer_read_64_signed(ELFOBJ *bin, ut64 *offset, st64 *result)
Definition: elf_misc.c:19
#define st64
Definition: rz_types_base.h:10

References buffer_read_64_signed(), rz_return_val_if_fail, and st64.

◆ rz_bin_elf_read_versym()

bool Elf_() rz_bin_elf_read_versym ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Versym) *  result 
)

Definition at line 105 of file elf_misc.c.

105  {
106  rz_return_val_if_fail(bin && offset && result, false);
107  return Elf_(rz_bin_elf_read_half)(bin, offset, result);
108 }
bool Elf_() rz_bin_elf_read_half(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Half) *result)
Definition: elf_misc.c:57

References Elf_, rz_bin_elf_read_half(), and rz_return_val_if_fail.

Referenced by get_gnu_versym().

◆ rz_bin_elf_read_word()

◆ rz_bin_elf_read_word_xword()

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 
)

Definition at line 117 of file elf_misc.c.

117  {
118  rz_return_val_if_fail(bin && offset && result, false);
119 
120  return Elf_(rz_bin_elf_read_word)(bin, offset, result);
121 }
bool Elf_() rz_bin_elf_read_word(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Word) *result)
Definition: elf_misc.c:62

References Elf_, rz_bin_elf_read_word(), and rz_return_val_if_fail.

Referenced by get_phdr_entry(), get_shdr_entry_aux(), and read_reloc_entry_aux().

◆ rz_bin_elf_read_xword()

bool Elf_() rz_bin_elf_read_xword ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Xword) *  result 
)

Definition at line 72 of file elf_misc.c.

72  {
73  rz_return_val_if_fail(bin && offset && result, false);
74  return rz_buf_read_ble64_offset(bin->b, offset, (ut64 *)result, bin->big_endian);
75 }

References rz_return_val_if_fail, and ut64().

Referenced by get_symbol_entry_aux().

◆ rz_bin_elf_relocs_new()

RZ_OWN RzVector* Elf_() rz_bin_elf_relocs_new ( RZ_NONNULL ELFOBJ bin)

Definition at line 202 of file elf_relocs.c.

202  {
204 
205  HtUU *set = ht_uu_new0();
206  if (!set) {
207  return NULL;
208  }
209 
210  RzVector *result = rz_vector_new(sizeof(RzBinElfReloc), NULL, NULL);
211  if (!result) {
212  ht_uu_free(set);
213  return NULL;
214  }
215 
216  if (!get_relocs_entry_from_dt_dynamic(bin, result, set)) {
217  rz_vector_free(result);
218  ht_uu_free(set);
219  return NULL;
220  }
221 
222  if (!get_relocs_entry_from_sections(bin, result, set)) {
223  rz_vector_free(result);
224  ht_uu_free(set);
225  return NULL;
226  }
227 
228  if (!rz_vector_len(result)) {
229  rz_vector_free(result);
230  ht_uu_free(set);
231  return NULL;
232  }
233 
234  ht_uu_free(set);
235 
236  return result;
237 }
static bool get_relocs_entry_from_sections(ELFOBJ *bin, RzVector *relocs, HtUU *set)
Definition: elf_relocs.c:182
static bool get_relocs_entry_from_dt_dynamic(ELFOBJ *bin, RzVector *relocs, HtUU *set)
Definition: elf_relocs.c:148

References get_relocs_entry_from_dt_dynamic(), get_relocs_entry_from_sections(), NULL, rz_return_val_if_fail, rz_vector_free(), rz_vector_len(), and rz_vector_new().

Referenced by init().

◆ rz_bin_elf_section_flag_to_rzlist()

RZ_OWN RzList* Elf_() rz_bin_elf_section_flag_to_rzlist ( ut64  flag)

Return a list of string representing flag options.

Parameters
elfflag
Returns
RzList of string representing flag options

Compare the flag to common option such as SHF_WRITE, SHF_ALLOC, ect

Definition at line 298 of file elf_sections.c.

298  {
299  RzList *flag_list = rz_list_new();
300  if (!flag_list) {
301  return NULL;
302  }
303 
304  for (size_t i = 0; i < RZ_ARRAY_SIZE(flag_translation_table); i++) {
305  if (flag & flag_translation_table[i].flag) {
306  if (!rz_list_append(flag_list, flag_translation_table[i].name)) {
307  rz_list_free(flag_list);
308  return NULL;
309  }
310  }
311  }
312 
313  return flag_list;
314 }
static const struct flag_translation flag_translation_table[]
Definition: elf_sections.c:51
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235

References flag_translation::flag, flag_translation_table, i, NULL, RZ_ARRAY_SIZE, rz_list_append(), rz_list_free(), and rz_list_new().

◆ rz_bin_elf_section_type_to_string()

RZ_OWN char* Elf_() rz_bin_elf_section_type_to_string ( ut64  type)

Return a string representing the elf type.

Parameters
elftype
Returns
allocated string

Compare the type SHT_NULL, SHT_PROGBITS, etc and return the string representation

Definition at line 422 of file elf_sections.c.

422  {
423  for (size_t i = 0; i < RZ_ARRAY_SIZE(type_translation_table); i++) {
424  if (type == type_translation_table[i].type) {
426  }
427  }
428 
429  if (type >= SHT_LOPROC && type <= SHT_HIPROC) {
430  return rz_str_newf("LOPROC+0x%08" PFMT64x, type - SHT_LOPROC);
431  }
432 
433  if (type >= SHT_LOUSER && type <= SHT_HIUSER) {
434  return rz_str_newf("LOUSER+0x%08" PFMT64x, type - SHT_LOUSER);
435  }
436 
437  return rz_str_newf("0x%" PFMT64x, type);
438 }
static const struct type_translation type_translation_table[]
Definition: elf_sections.c:19
#define SHT_LOPROC
Definition: common.h:368
#define SHT_LOUSER
Definition: common.h:370
#define SHT_HIPROC
Definition: common.h:369
#define SHT_HIUSER
Definition: common.h:372
RZ_API char * rz_str_new(const char *str)
Definition: str.c:865

References i, PFMT64x, RZ_ARRAY_SIZE, rz_str_new(), rz_str_newf(), SHT_HIPROC, SHT_HIUSER, SHT_LOPROC, SHT_LOUSER, type, and type_translation_table.

◆ rz_bin_elf_sections_new()

RZ_OWN RzVector* Elf_() rz_bin_elf_sections_new ( RZ_NONNULL ELFOBJ bin)

Definition at line 378 of file elf_sections.c.

378  {
380 
381  if (!bin->ehdr.e_shnum) {
382  return NULL;
383  }
384 
385  if (!Elf_(rz_bin_elf_check_array)(bin, bin->ehdr.e_shoff, bin->ehdr.e_shnum, sizeof(Elf_(Phdr)))) {
386  RZ_LOG_WARN("Invalid section header (check array failed).\n");
387  return NULL;
388  }
389 
390  RzVector *result = rz_vector_new(sizeof(Elf_(Shdr)), NULL, NULL);
391  if (!result) {
392  return NULL;
393  }
394 
395  ut64 offset = bin->ehdr.e_shoff;
396 
397  for (size_t i = 0; i < bin->ehdr.e_shnum; i++) {
398  Elf_(Shdr) *section = rz_vector_push(result, NULL);
399  if (!section) {
400  rz_vector_free(result);
401  return NULL;
402  }
403 
404  if (!get_shdr_entry(bin, section, offset)) {
405  rz_vector_free(result);
406  return NULL;
407  }
408 
409  offset += sizeof(Elf_(Shdr));
410  }
411 
412  return result;
413 }
bool Elf_() rz_bin_elf_check_array(RZ_NONNULL ELFOBJ *bin, Elf_(Off) offset, Elf_(Off) length, Elf_(Off) entry_size)
Definition: elf_misc.c:32
static bool get_shdr_entry(ELFOBJ *bin, Elf_(Shdr) *section, ut64 offset)
Definition: elf_sections.c:181

References Elf_, get_shdr_entry(), i, NULL, rz_bin_elf_check_array(), RZ_LOG_WARN, rz_return_val_if_fail, rz_vector_free(), rz_vector_new(), rz_vector_push(), and ut64().

Referenced by init().

◆ rz_bin_elf_segments_new()

RZ_OWN RzVector* Elf_() rz_bin_elf_segments_new ( RZ_NONNULL ELFOBJ bin,
RzVector sections,
RZ_NONNULL RzBinObjectLoadOptions options 
)

Definition at line 133 of file elf_segments.c.

133  {
135 
137  if (!count) {
138  return NULL;
139  }
140 
141  if (!Elf_(rz_bin_elf_check_array)(bin, bin->ehdr.e_phoff, count, sizeof(Elf_(Phdr)))) {
142  RZ_LOG_WARN("Invalid program header (check array failed).\n");
143  return NULL;
144  }
145 
147 }
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 count
Definition: sflib.h:98
static size_t get_number_of_segments(ELFOBJ *bin, RzVector *sections)
Definition: elf_segments.c:101
static RzVector * get_segments_from_phdr(ELFOBJ *bin, size_t count, RzBinObjectLoadOptions *options)
Definition: elf_segments.c:70

References count, Elf_, get_number_of_segments(), get_segments_from_phdr(), NULL, options, rz_bin_elf_check_array(), RZ_LOG_WARN, rz_return_val_if_fail, and sections().

Referenced by init_phdr_aux().

◆ rz_bin_elf_strtab_free()

void Elf_() rz_bin_elf_strtab_free ( RzBinElfStrtab ptr)

Definition at line 72 of file elf_strtab.c.

72  {
73  if (!ptr) {
74  return;
75  }
76 
77  free(ptr->data);
78  free(ptr);
79 }

References free().

Referenced by get_section_elf_symbols(), rz_bin_elf_free(), and rz_bin_elf_strtab_new().

◆ rz_bin_elf_strtab_get()

RZ_BORROW const char* Elf_() rz_bin_elf_strtab_get ( RZ_NONNULL RzBinElfStrtab strtab,
ut64  index 
)

Definition at line 8 of file elf_strtab.c.

8  {
9  rz_return_val_if_fail(strtab, false);
10 
11  if (!Elf_(rz_bin_elf_strtab_has_index)(strtab, index)) {
12  return NULL;
13  }
14 
15  return strtab->data + index;
16 }
bool Elf_() rz_bin_elf_strtab_has_index(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
Definition: elf_strtab.c:67

References Elf_, NULL, rz_bin_elf_strtab_has_index(), and rz_return_val_if_fail.

Referenced by get_vernaux_entry_sdb(), get_verneed_entry_sdb_aux(), get_versym_entry_sdb_from_verdef(), and get_versym_entry_sdb_from_verneed().

◆ rz_bin_elf_strtab_get_dup()

RZ_OWN char* Elf_() rz_bin_elf_strtab_get_dup ( RZ_NONNULL RzBinElfStrtab strtab,
ut64  index 
)

Definition at line 52 of file elf_strtab.c.

52  {
53  rz_return_val_if_fail(strtab, NULL);
54 
55  if (!Elf_(rz_bin_elf_strtab_has_index)(strtab, index)) {
56  return NULL;
57  }
58 
59  char *result = strdup(strtab->data + index);
60  if (!result) {
61  return NULL;
62  }
63 
64  return result;
65 }

References Elf_, NULL, rz_bin_elf_strtab_has_index(), rz_return_val_if_fail, and strdup().

Referenced by rz_bin_elf_get_libs(), rz_bin_elf_get_rpath(), set_elf_section_name(), and set_elf_symbol_name().

◆ rz_bin_elf_strtab_has_index()

bool Elf_() rz_bin_elf_strtab_has_index ( RZ_NONNULL RzBinElfStrtab strtab,
ut64  index 
)

Definition at line 67 of file elf_strtab.c.

67  {
68  rz_return_val_if_fail(strtab, false);
69  return index < strtab->size;
70 }

References rz_return_val_if_fail.

Referenced by rz_bin_elf_strtab_get(), rz_bin_elf_strtab_get_dup(), and set_elf_section_name().

◆ rz_bin_elf_strtab_new()

RZ_OWN RzBinElfStrtab* Elf_() rz_bin_elf_strtab_new ( RZ_NONNULL ELFOBJ bin,
ut64  offset,
ut64  size 
)

Definition at line 18 of file elf_strtab.c.

18  {
20 
21  if (!size || !Elf_(rz_bin_elf_check_array)(bin, offset, size, sizeof(ut8))) {
22  RZ_LOG_WARN("Invalid strtab at 0x%" PFMT64x " (check array failed).\n", offset);
23  return NULL;
24  }
25 
27  if (!result) {
28  return NULL;
29  }
30 
31  result->size = size;
32  result->data = RZ_NEWS(char, size);
33  if (!result->data) {
35  return NULL;
36  }
37 
38  if (rz_buf_read_at(bin->b, offset, (ut8 *)result->data, size) < 0) {
40  return NULL;
41  }
42 
43  if (result->data[0] != '\0' || result->data[size - 1] != '\0') {
44  RZ_LOG_WARN("String table at 0x%" PFMT64x " should start and end by a NULL byte", offset);
46  return NULL;
47  }
48 
49  return result;
50 }
void Elf_() rz_bin_elf_strtab_free(RzBinElfStrtab *ptr)
Definition: elf_strtab.c:72
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
#define RZ_NEW(x)
Definition: rz_types.h:285

References rz_bin_elf_strtab::data, Elf_, NULL, PFMT64x, rz_bin_elf_check_array(), rz_bin_elf_strtab_free(), rz_buf_read_at(), RZ_LOG_WARN, RZ_NEW, RZ_NEWS, rz_return_val_if_fail, and rz_bin_elf_strtab::size.

Referenced by get_section_elf_symbols(), init_dynstr_aux(), and init_shstrtab_aux().

◆ rz_bin_elf_symbols_new()

RZ_OWN RzVector* Elf_() rz_bin_elf_symbols_new ( RZ_NONNULL ELFOBJ bin)

Definition at line 523 of file elf_symbols.c.

523  {
525 
527  if (!result) {
528  return NULL;
529  }
530 
531  return result;
532 }
static bool filter_symbol(RZ_UNUSED ELFOBJ *bin, Elf_(Sym) *symbol, RZ_UNUSED bool is_dynamic)
Definition: elf_symbols.c:439
RZ_OWN RzVector *Elf_() rz_bin_elf_compute_symbols(ELFOBJ *bin, RzBinElfSymbolFilter filter)
Definition: elf_symbols.c:486

References Elf_(), filter_symbol(), NULL, rz_bin_elf_compute_symbols(), and rz_return_val_if_fail.

Referenced by init().

◆ rz_bin_elf_v2p()

ut64 Elf_() rz_bin_elf_v2p ( RZ_NONNULL ELFOBJ bin,
ut64  vaddr 
)

Convert a virtual address to the physical address.

Parameters
elfbinary
Returns
virtual addr

Converts a virtual address to the relative physical address, looking at the program headers in the binary bin

Definition at line 429 of file elf.c.

429  {
431 
433  if (Elf_(rz_bin_elf_is_relocatable)(bin) && vaddr > bin->baddr) {
434  return vaddr - bin->baddr;
435  }
436 
437  return UT64_MAX;
438  }
439 
440  RzBinElfSegment *segment;
441  rz_bin_elf_foreach_segments(bin, segment) {
442  if (segment->data.p_type == PT_LOAD && in_virtual_phdr(segment, vaddr)) {
443  return segment->data.p_offset + vaddr - segment->data.p_vaddr;
444  }
445  }
446 
447  return UT64_MAX;
448 }
static bool in_virtual_phdr(RzBinElfSegment *segment, ut64 addr)
Definition: elf.c:105

References Elf_, in_virtual_phdr(), PT_LOAD, rz_bin_elf_foreach_segments, rz_bin_elf_has_segments(), rz_bin_elf_is_relocatable(), rz_return_val_if_fail, RzBinElfSegment, and UT64_MAX.

Referenced by convert_elf_symbol_entry(), convert_elf_symbol_to_elf_import(), create_section_from_phdr(), Elf_(), fix_rva_and_offset_exec_file(), get_dynamic_elf_symbols(), get_gnu_verneed(), get_gnu_versym(), get_import_addr_mips(), get_import_addr_ppc(), get_import_addr_x86_manual(), get_main_offset_arm64(), get_main_offset_arm_glibc_non_thumb(), get_main_offset_arm_glibc_thumb(), get_main_offset_linux_64_pie(), get_main_offset_mips(), get_main_offset_x86_gcc(), get_main_offset_x86_non_pie(), get_relocs_entry_from_dt_dynamic_aux(), get_versym_entry_sdb_from_verdef(), get_versym_entry_sdb_from_verneed(), init_dt_dynamic(), init_dynstr_aux(), rz_bin_elf_get_entry_offset(), rz_bin_elf_get_fini_offset(), rz_bin_elf_get_gnu_hash_table(), rz_bin_elf_get_hash_table(), and rz_bin_elf_get_init_offset().

Variable Documentation

◆ RzBinElfNote

RzBinElfNote

◆ RzBinElfNoteFile

RzBinElfNoteFile

Definition at line 165 of file elf.h.

◆ RzBinElfSegment