Rizin
unix-like reverse engineering framework and cli tools
elf_info.c File Reference
#include "elf.h"

Go to the source code of this file.

Classes

struct  mips_bits_translation
 
struct  section_note_osabi_translation
 
struct  machine_name_translation
 
struct  class_translation
 
struct  cpu_mips_translation
 
struct  arch_translation
 
struct  ver_flags_translation
 

Macros

#define EF_MIPS_ABI_O32   0x00001000 /* O32 ABI. */
 
#define EF_MIPS_ABI_O64   0x00002000 /* O32 extended for 64 bit. */
 
#define EF_MIPS_ABI   0x0000f000
 
#define VERSYM_VERSION   0x7fff
 

Functions

static ut64 get_main_offset_from_symbol (ELFOBJ *bin)
 
static ut64 get_main_offset_linux_64_pie (ELFOBJ *bin, ut64 entry, ut8 *buf)
 
static ut64 get_main_offset_x86_non_pie (ELFOBJ *bin, ut64 entry, ut8 *buf)
 
static ut64 get_main_offset_x86_pie (ELFOBJ *bin, ut64 entry, ut8 *buf)
 
static ut64 get_main_offset_x86_gcc (ELFOBJ *bin, ut64 entry, ut8 *buf)
 
static ut64 get_main_offset_mips (ELFOBJ *bin, ut64 entry, ut8 *buf, size_t size)
 
static ut64 get_main_offset_arm_glibc_thumb (ELFOBJ *bin, ut64 entry, ut8 *buf)
 
static ut64 get_main_offset_arm_glibc_non_thumb (ELFOBJ *bin, ut64 entry, ut8 *buf)
 
static ut64 get_main_offset_arm_glibc (ELFOBJ *bin, ut64 entry, ut8 *buf)
 
static ut64 get_main_offset_arm64 (ELFOBJ *bin, ut64 entry, ut8 *buf)
 
static ut64 get_entry_offset_from_shdr (ELFOBJ *bin)
 
static ut64 compute_boffset_from_phdr (ELFOBJ *bin)
 
static ut64 compute_baddr_from_phdr (ELFOBJ *bin)
 
static bool elf_is_bind_now (ELFOBJ *bin)
 
static bool elf_has_gnu_relro (ELFOBJ *bin)
 
static int get_bits_common (ELFOBJ *bin)
 
static bool has_thumb_symbol (ELFOBJ *bin)
 
static int get_bits_mips_common (Elf_(Word) mips_type)
 
static int is_playstation_hack (ELFOBJ *bin, Elf_(Word) mips_type)
 
static int get_bits_mips (ELFOBJ *bin)
 
static bool arch_is_mips (ELFOBJ *bin)
 
static bool arch_is_arcompact (ELFOBJ *bin)
 
static char * read_elf_intrp (ELFOBJ *bin, ut64 addr, size_t size)
 
static char * get_elf_intrp (ELFOBJ *bin, RzBinElfSegment *segment)
 
static Elf_ (Xword)
 
static char * get_ver_flags (ut32 flags)
 
static bool has_dt_rpath_entry (ELFOBJ *bin)
 
static char * get_osabi_name_from_section_note (ELFOBJ *bin, RzBinElfSection *section)
 
static char * get_osabi_name_from_shdr (ELFOBJ *bin)
 
static char * get_osabi_name_from_ehdr (ELFOBJ *bin)
 
static char * add_abi_info (ELFOBJ *bin, char *head_flag)
 
static char * add_cpu_info (ELFOBJ *bin, char *head_flag)
 
static char * get_head_flag (ELFOBJ *bin)
 
static bool file_type_is_processor_specific (ELFOBJ *bin)
 
static bool file_type_is_os_specific (ELFOBJ *bin)
 
static char * get_file_type_basic (RZ_NONNULL ELFOBJ *bin)
 
static char * get_cpu_mips (ELFOBJ *bin)
 
static bool is_elf_class64 (ELFOBJ *bin)
 
static bool is_mips_o32 (ELFOBJ *bin)
 
static bool is_mips_n32 (ELFOBJ *bin)
 
static char * get_abi_mips (ELFOBJ *bin)
 
RZ_OWN RzList *Elf_() rz_bin_elf_get_libs (RZ_NONNULL ELFOBJ *bin)
 List all imported lib. More...
 
static bool get_verdaux_entry_aux (ELFOBJ *bin, ut64 offset, Elf_(Verdaux) *entry)
 
static bool get_verdaux_entry (ELFOBJ *bin, ut64 offset, Elf_(Verdaux) *entry)
 
static bool get_verdef_entry_aux (ELFOBJ *bin, ut64 offset, Elf_(Verdef) *entry)
 
static bool get_verdef_entry (ELFOBJ *bin, ut64 offset, Elf_(Verdef) *entry)
 
static bool get_vernaux_entry_aux (ELFOBJ *bin, ut64 offset, Elf_(Vernaux) *entry)
 
static bool get_vernaux_entry (ELFOBJ *bin, ut64 offset, Elf_(Vernaux) *entry)
 
static bool get_verneed_entry_aux (ELFOBJ *bin, ut64 offset, Elf_(Verneed) *entry)
 
static bool get_verneed_entry (ELFOBJ *bin, ut64 offset, Elf_(Verneed) *entry)
 
static bool get_versym_entry_sdb_from_verneed (ELFOBJ *bin, Sdb *sdb, const char *key, Elf_(Versym) versym)
 
static bool get_versym_entry_sdb_from_verdef (ELFOBJ *bin, Sdb *sdb, const char *key, Elf_(Versym) versym)
 
static Sdbget_gnu_versym (ELFOBJ *bin)
 
static Sdbget_vernaux_entry_sdb (ELFOBJ *bin, Elf_(Vernaux) vernaux_entry, size_t index)
 
static Sdbget_verneed_entry_sdb_aux (ELFOBJ *bin, Elf_(Verneed) verneed_entry, size_t index)
 
static Sdbget_verneed_entry_sdb (ELFOBJ *bin, Elf_(Verneed) verneed_entry, size_t offset)
 
static Sdbget_gnu_verneed (ELFOBJ *bin)
 
RZ_IPI RZ_OWN Sdb *Elf_() rz_bin_elf_get_symbols_info (RZ_NONNULL ELFOBJ *bin)
 
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_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_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_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...
 
RZ_OWN char *Elf_() rz_bin_elf_get_intrp (RZ_NONNULL ELFOBJ *bin)
 Get the program interpreter. More...
 
bool Elf_() rz_bin_elf_is_stripped (RZ_NONNULL ELFOBJ *bin)
 Check if the binary is stripped. 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_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...
 
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...
 
bool Elf_() rz_bin_elf_is_big_endian (RZ_NONNULL ELFOBJ *bin)
 Check the binary endianness. 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...
 

Variables

static const struct mips_bits_translation mips_bits_translation_table []
 
static const struct section_note_osabi_translation section_note_osabi_translation_table []
 
static const struct machine_name_translation machine_name_translation_table []
 
static const struct class_translation class_translation_table []
 
static const struct cpu_mips_translation cpu_mips_translation_table []
 
static const struct arch_translation arch_translation_table []
 
static const struct ver_flags_translation ver_flags_translation_table []
 

Macro Definition Documentation

◆ EF_MIPS_ABI

#define EF_MIPS_ABI   0x0000f000

Definition at line 11 of file elf_info.c.

◆ EF_MIPS_ABI_O32

#define EF_MIPS_ABI_O32   0x00001000 /* O32 ABI. */

Definition at line 9 of file elf_info.c.

◆ EF_MIPS_ABI_O64

#define EF_MIPS_ABI_O64   0x00002000 /* O32 extended for 64 bit. */

Definition at line 10 of file elf_info.c.

◆ VERSYM_VERSION

#define VERSYM_VERSION   0x7fff

Definition at line 13 of file elf_info.c.

Function Documentation

◆ add_abi_info()

static char* add_abi_info ( ELFOBJ bin,
char *  head_flag 
)
static

Definition at line 755 of file elf_info.c.

755  {
756  char *str = Elf_(rz_bin_elf_get_abi)(bin);
757 
758  if (str) {
759  head_flag = rz_str_appendf(head_flag, " %s", str);
760  free(str);
761  }
762 
763  return head_flag;
764 }
RZ_OWN char *Elf_() rz_bin_elf_get_abi(RZ_NONNULL ELFOBJ *bin)
Return a string representing the application binary interface.
Definition: elf_info.c:1386
static Elf_(Xword)
Definition: elf_info.c:672
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
Definition: malloc.c:26

References Elf_(), free(), rz_bin_elf_get_abi(), rz_str_appendf(), and cmd_descs_generate::str.

Referenced by get_head_flag().

◆ add_cpu_info()

static char* add_cpu_info ( ELFOBJ bin,
char *  head_flag 
)
static

Definition at line 766 of file elf_info.c.

766  {
767  char *str = Elf_(rz_bin_elf_get_cpu)(bin);
768 
769  if (str) {
770  head_flag = rz_str_append_owned(head_flag, str);
771  }
772 
773  return head_flag;
774 }
RZ_OWN char *Elf_() rz_bin_elf_get_cpu(RZ_NONNULL ELFOBJ *bin)
Return a string representing the cpu.
Definition: elf_info.c:1422
RZ_API char * rz_str_append_owned(char *ptr, char *string)
Definition: str.c:1050

References Elf_(), rz_bin_elf_get_cpu(), rz_str_append_owned(), and cmd_descs_generate::str.

Referenced by get_head_flag().

◆ arch_is_arcompact()

static bool arch_is_arcompact ( ELFOBJ bin)
static

Definition at line 626 of file elf_info.c.

626  {
627  return bin->ehdr.e_machine == EM_ARC_A5;
628 }
#define EM_ARC_A5
Definition: common.h:182

References EM_ARC_A5.

Referenced by rz_bin_elf_get_bits().

◆ arch_is_mips()

static bool arch_is_mips ( ELFOBJ bin)
static

Definition at line 622 of file elf_info.c.

622  {
623  return Elf_(rz_bin_elf_has_segments)(bin) && bin->ehdr.e_machine == EM_MIPS;
624 }
bool Elf_() rz_bin_elf_has_segments(RZ_NONNULL ELFOBJ *bin)
Definition: elf_segments.c:149
#define EM_MIPS
Definition: common.h:110

References Elf_(), EM_MIPS, and rz_bin_elf_has_segments().

Referenced by rz_bin_elf_get_bits().

◆ compute_baddr_from_phdr()

static ut64 compute_baddr_from_phdr ( ELFOBJ bin)
static

Definition at line 539 of file elf_info.c.

539  {
540  ut64 base = UT64_MAX;
541 
544  if (iter->data.p_type == PT_LOAD) {
545  base = RZ_MIN(base, iter->data.p_vaddr);
546  }
547  }
548 
549  return base == UT64_MAX ? 0 : base;
550 }
#define rz_bin_elf_foreach_segments(bin, segment)
Definition: elf.h:26
RzBinElfSegment
Definition: elf.h:131
#define PT_LOAD
Definition: common.h:303
#define RZ_MIN(x, y)
#define UT64_MAX
Definition: rz_types_base.h:86
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References PT_LOAD, rz_bin_elf_foreach_segments, RZ_MIN, RzBinElfSegment, ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_baddr().

◆ compute_boffset_from_phdr()

static ut64 compute_boffset_from_phdr ( ELFOBJ bin)
static

Definition at line 526 of file elf_info.c.

526  {
527  ut64 base = UT64_MAX;
528 
531  if (iter->data.p_type == PT_LOAD) {
532  base = RZ_MIN(base, iter->data.p_offset);
533  }
534  }
535 
536  return base == UT64_MAX ? 0 : base;
537 }

References PT_LOAD, rz_bin_elf_foreach_segments, RZ_MIN, RzBinElfSegment, ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_boffset().

◆ Elf_()

static Elf_ ( Xword  )
static

Definition at line 672 of file elf_info.c.

672  {
673  ut64 path;
674 
676  return path;
677  }
678 
680  return path;
681  }
682 
683  return 0;
684 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
bool Elf_() rz_bin_elf_get_dt_info(RZ_NONNULL ELFOBJ *bin, ut64 key, RZ_OUT ut64 *info)
Definition: elf_dynamic.c:120
#define DT_RPATH
Definition: common.h:552
#define DT_RUNPATH
Definition: common.h:566

References DT_RPATH, DT_RUNPATH, path, rz_bin_elf_get_dt_info(), and ut64().

Referenced by add_abi_info(), add_cpu_info(), arch_is_mips(), elf_has_gnu_relro(), elf_is_bind_now(), get_bits_mips(), get_cpu_mips(), get_entry_offset_from_shdr(), get_gnu_verneed(), get_gnu_versym(), get_main_offset_arm64(), get_main_offset_arm_glibc(), 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_main_offset_x86_pie(), get_verdaux_entry_aux(), get_verdef_entry_aux(), get_vernaux_entry_aux(), get_vernaux_entry_sdb(), get_verneed_entry_aux(), get_verneed_entry_sdb(), get_verneed_entry_sdb_aux(), get_versym_entry_sdb_from_verdef(), get_versym_entry_sdb_from_verneed(), has_dt_rpath_entry(), has_thumb_symbol(), is_playstation_hack(), rz_bin_elf_get_baddr(), rz_bin_elf_get_bits(), rz_bin_elf_get_boffset(), rz_bin_elf_get_compiler(), rz_bin_elf_get_cpu(), rz_bin_elf_get_entry_offset(), rz_bin_elf_get_fini_offset(), rz_bin_elf_get_init_offset(), rz_bin_elf_get_intrp(), rz_bin_elf_get_libs(), rz_bin_elf_get_main_offset(), rz_bin_elf_get_rpath(), rz_bin_elf_get_symbols_info(), rz_bin_elf_has_nx(), rz_bin_elf_is_executable(), rz_bin_elf_is_static(), and rz_bin_elf_is_stripped().

◆ elf_has_gnu_relro()

static bool elf_has_gnu_relro ( ELFOBJ bin)
static

Definition at line 566 of file elf_info.c.

566  {
568  return false;
569  }
570 
572  return segment && segment->is_valid;
573 }
RZ_BORROW RzBinElfSegment *Elf_() rz_bin_elf_get_segment_with_type(RZ_NONNULL ELFOBJ *bin, Elf_(Word) type)
Definition: elf_segments.c:120
#define PT_GNU_RELRO
Definition: common.h:318

References Elf_(), PT_GNU_RELRO, rz_bin_elf_get_segment_with_type(), rz_bin_elf_has_segments(), and RzBinElfSegment.

Referenced by rz_bin_elf_has_relro().

◆ elf_is_bind_now()

static bool elf_is_bind_now ( ELFOBJ bin)
static

Definition at line 552 of file elf_info.c.

552  {
553  ut64 flags_1;
554 
556  return true;
557  }
558 
559  if (Elf_(rz_bin_elf_get_dt_info)(bin, DT_FLAGS_1, &flags_1)) {
560  return flags_1 & DF_1_NOW;
561  }
562 
563  return false;
564 }
#define NULL
Definition: cris-opc.c:27
#define DF_1_NOW
Definition: common.h:651
#define DT_BIND_NOW
Definition: common.h:561
#define DT_FLAGS_1
Definition: common.h:617

References DF_1_NOW, DT_BIND_NOW, DT_FLAGS_1, Elf_(), NULL, rz_bin_elf_get_dt_info(), and ut64().

Referenced by rz_bin_elf_has_relro().

◆ file_type_is_os_specific()

static bool file_type_is_os_specific ( ELFOBJ bin)
static

Definition at line 789 of file elf_info.c.

789  {
790  return bin->ehdr.e_type >= ET_LOOS && bin->ehdr.e_type <= ET_HIOS;
791 }
#define ET_LOOS
Definition: common.h:93
#define ET_HIOS
Definition: common.h:94

References ET_HIOS, and ET_LOOS.

Referenced by rz_bin_elf_get_file_type().

◆ file_type_is_processor_specific()

static bool file_type_is_processor_specific ( ELFOBJ bin)
static

Definition at line 785 of file elf_info.c.

785  {
786  return bin->ehdr.e_type >= ET_LOPROC && bin->ehdr.e_type <= ET_HIPROC;
787 }
#define ET_HIPROC
Definition: common.h:96
#define ET_LOPROC
Definition: common.h:95

References ET_HIPROC, and ET_LOPROC.

Referenced by rz_bin_elf_get_file_type().

◆ get_abi_mips()

static char* get_abi_mips ( ELFOBJ bin)
static

Definition at line 854 of file elf_info.c.

854  {
855  if (is_elf_class64(bin)) {
856  return strdup("n64");
857  }
858 
859  if (is_mips_n32(bin)) {
860  return strdup("n32");
861  }
862 
863  if (is_mips_o32(bin)) {
864  return strdup("o32");
865  }
866 
867  return NULL;
868 }
static bool is_mips_o32(ELFOBJ *bin)
Definition: elf_info.c:826
static bool is_mips_n32(ELFOBJ *bin)
Definition: elf_info.c:842
static bool is_elf_class64(ELFOBJ *bin)
Definition: elf_info.c:822
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")

References is_elf_class64(), is_mips_n32(), is_mips_o32(), NULL, and strdup().

Referenced by rz_bin_elf_get_abi().

◆ get_bits_common()

static int get_bits_common ( ELFOBJ bin)
static

Definition at line 575 of file elf_info.c.

575  {
576  switch (bin->ehdr.e_ident[EI_CLASS]) {
577  case ELFCLASS32:
578  return 32;
579  case ELFCLASS64:
580  return 64;
581  case ELFCLASSNONE:
582  default:
583  return 32;
584  }
585 }
#define EI_CLASS
Definition: common.h:51
#define ELFCLASS32
Definition: common.h:53
#define ELFCLASS64
Definition: common.h:54
#define ELFCLASSNONE
Definition: common.h:52

References EI_CLASS, ELFCLASS32, ELFCLASS64, and ELFCLASSNONE.

Referenced by rz_bin_elf_get_bits().

◆ get_bits_mips()

static int get_bits_mips ( ELFOBJ bin)
static

Definition at line 612 of file elf_info.c.

612  {
613  const Elf_(Word) mips_type = bin->ehdr.e_flags & EF_MIPS_ARCH;
614 
615  if (is_playstation_hack(bin, mips_type)) {
616  return 64;
617  }
618 
619  return get_bits_mips_common(mips_type);
620 }
static int get_bits_mips_common(Elf_(Word) mips_type)
Definition: elf_info.c:598
static int is_playstation_hack(ELFOBJ *bin, Elf_(Word) mips_type)
Definition: elf_info.c:608
#define EF_MIPS_ARCH

References EF_MIPS_ARCH, Elf_(), get_bits_mips_common(), and is_playstation_hack().

Referenced by rz_bin_elf_get_bits().

◆ get_bits_mips_common()

static int get_bits_mips_common ( Elf_(Word)  mips_type)
static

Definition at line 598 of file elf_info.c.

598  {
599  for (size_t i = 0; i < RZ_ARRAY_SIZE(mips_bits_translation_table); i++) {
600  if (mips_type == mips_bits_translation_table[i].type) {
601  return mips_bits_translation_table[i].bits;
602  }
603  }
604 
605  return 32;
606 }
lzma_index ** i
Definition: index.h:629
static const struct mips_bits_translation mips_bits_translation_table[]
Definition: elf_info.c:50
int type
Definition: mipsasm.c:17
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300

References i, mips_bits_translation_table, RZ_ARRAY_SIZE, and type.

Referenced by get_bits_mips().

◆ get_cpu_mips()

static char* get_cpu_mips ( ELFOBJ bin)
static

Definition at line 810 of file elf_info.c.

810  {
811  Elf_(Word) mips_arch = bin->ehdr.e_flags & EF_MIPS_ARCH;
812 
813  for (size_t i = 0; i < RZ_ARRAY_SIZE(cpu_mips_translation_table); i++) {
814  if (mips_arch == cpu_mips_translation_table[i].arch) {
816  }
817  }
818 
819  return strdup(" Unknown mips ISA");
820 }
cs_arch arch
Definition: cstool.c:13
static const struct cpu_mips_translation cpu_mips_translation_table[]
Definition: elf_info.c:232
Definition: z80asm.h:102

References arch, cpu_mips_translation_table, EF_MIPS_ARCH, Elf_(), i, RZ_ARRAY_SIZE, and strdup().

Referenced by rz_bin_elf_get_cpu().

◆ get_elf_intrp()

static char* get_elf_intrp ( ELFOBJ bin,
RzBinElfSegment segment 
)
static

Definition at line 646 of file elf_info.c.

646  {
647  ut64 addr = segment->data.p_offset;
648  size_t size = segment->data.p_filesz;
649 
650  if (!sdb_num_set(bin->kv, "elf_header.intrp_addr", addr, 0) ||
651  !sdb_num_set(bin->kv, "elf_header.intrp_size", size, 0)) {
652  return NULL;
653  }
654 
656  return NULL;
657  }
658 
659  char *str = read_elf_intrp(bin, addr, size);
660  if (!str) {
661  return NULL;
662  }
663 
664  if (!sdb_set(bin->kv, "elf_header.intrp", str, 0)) {
665  free(str);
666  return NULL;
667  }
668 
669  return str;
670 }
static char * read_elf_intrp(ELFOBJ *bin, ut64 addr, size_t size)
Definition: elf_info.c:630
voidpf void uLong size
Definition: ioapi.h:138
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
static int addr
Definition: z80asm.c:58

References addr, free(), NULL, read_elf_intrp(), rz_buf_size(), sdb_num_set(), sdb_set(), cmd_descs_generate::str, and ut64().

Referenced by rz_bin_elf_get_intrp().

◆ get_entry_offset_from_shdr()

static ut64 get_entry_offset_from_shdr ( ELFOBJ bin)
static

Definition at line 507 of file elf_info.c.

507  {
509  if (section) {
510  return section->offset;
511  }
512 
514  if (section) {
515  return section->offset;
516  }
517 
519  if (section) {
520  return section->offset;
521  }
522 
523  return UT64_MAX;
524 }
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
uint32_t offset

References Elf_(), section::offset, rz_bin_elf_get_section_with_name(), and UT64_MAX.

Referenced by rz_bin_elf_get_entry_offset().

◆ get_file_type_basic()

static char* get_file_type_basic ( RZ_NONNULL ELFOBJ bin)
static

Definition at line 793 of file elf_info.c.

793  {
794  switch (bin->ehdr.e_type) {
795  case ET_NONE:
796  return strdup("NONE (None)");
797  case ET_REL:
798  return strdup("REL (Relocatable file)");
799  case ET_EXEC:
800  return strdup("EXEC (Executable file)");
801  case ET_DYN:
802  return strdup("DYN (Shared object file)");
803  case ET_CORE:
804  return strdup("CORE (Core file)");
805  }
806 
807  return NULL;
808 }
#define ET_REL
Definition: common.h:89
#define ET_CORE
Definition: common.h:92
#define ET_NONE
Definition: common.h:88
#define ET_DYN
Definition: common.h:91
#define ET_EXEC
Definition: common.h:90

References ET_CORE, ET_DYN, ET_EXEC, ET_NONE, ET_REL, NULL, and strdup().

Referenced by rz_bin_elf_get_file_type().

◆ get_gnu_verneed()

static Sdb* get_gnu_verneed ( ELFOBJ bin)
static

Definition at line 1247 of file elf_info.c.

1247  {
1248  ut64 verneed_addr;
1249  ut64 verneed_num;
1250 
1251  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERNEED, &verneed_addr) || !Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERNEEDNUM, &verneed_num)) {
1252  return NULL;
1253  }
1254 
1255  ut64 verneed_offset = Elf_(rz_bin_elf_v2p(bin, verneed_addr));
1256  if (verneed_offset == UT64_MAX) {
1257  RZ_LOG_WARN("Failed to convert verneed virtual address to physical address.\n");
1258  return NULL;
1259  }
1260 
1261  Sdb *sdb = sdb_new0();
1262  if (!sdb) {
1263  return NULL;
1264  }
1265 
1266  if (!sdb_num_set(sdb, "num_entries", verneed_num, 0) ||
1267  !sdb_num_set(sdb, "addr", verneed_addr, 0) ||
1268  !sdb_num_set(sdb, "offset", verneed_offset, 0)) {
1269  sdb_free(sdb);
1270  return NULL;
1271  }
1272 
1273  for (size_t i = 0; i < verneed_num; i++) {
1274  Elf_(Verneed) verneed_entry;
1275  if (!get_verneed_entry(bin, verneed_offset, &verneed_entry)) {
1276  sdb_free(sdb);
1277  return NULL;
1278  }
1279 
1280  Sdb *sdb_version = get_verneed_entry_sdb(bin, verneed_entry, verneed_offset);
1281  if (!sdb_version) {
1282  sdb_free(sdb);
1283  return NULL;
1284  }
1285 
1286  char key[32];
1287  if (!sdb_ns_set(sdb, rz_strf(key, "version%zu", i), sdb_version)) {
1288  sdb_free(sdb_version);
1289  sdb_free(sdb);
1290  return NULL;
1291  }
1292 
1293  sdb_free(sdb_version);
1294 
1295  verneed_offset += verneed_entry.vn_next;
1296  }
1297 
1298  return sdb;
1299 }
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
ut64 Elf_() rz_bin_elf_v2p(RZ_NONNULL ELFOBJ *bin, ut64 vaddr)
Convert a virtual address to the physical address.
Definition: elf.c:429
static bool get_verneed_entry(ELFOBJ *bin, ut64 offset, Elf_(Verneed) *entry)
Definition: elf_info.c:968
static Sdb * get_verneed_entry_sdb(ELFOBJ *bin, Elf_(Verneed) verneed_entry, size_t offset)
Definition: elf_info.c:1211
#define DT_VERNEEDNUM
Definition: common.h:621
#define DT_VERNEED
Definition: common.h:620
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
Definition: sdb.h:63

References DT_VERNEED, DT_VERNEEDNUM, Elf_(), get_verneed_entry(), get_verneed_entry_sdb(), i, key, NULL, rz_bin_elf_get_dt_info(), rz_bin_elf_v2p(), RZ_LOG_WARN, rz_strf, sdb_free(), sdb_new0(), sdb_ns_set(), sdb_num_set(), ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_symbols_info().

◆ get_gnu_versym()

static Sdb* get_gnu_versym ( ELFOBJ bin)
static

Definition at line 1089 of file elf_info.c.

1089  {
1090  ut64 versym_addr;
1091 
1092  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERSYM, &versym_addr)) {
1093  return false;
1094  }
1095 
1096  ut64 versym_offset = Elf_(rz_bin_elf_v2p(bin, versym_addr));
1097 
1098  if (versym_offset == UT64_MAX) {
1099  return NULL;
1100  }
1101 
1102  ut64 number_of_symbols = Elf_(rz_bin_elf_get_number_of_dynamic_symbols)(bin);
1103  if (!number_of_symbols) {
1104  return NULL;
1105  }
1106 
1107  Sdb *sdb = sdb_new0();
1108  if (!sdb) {
1109  return NULL;
1110  }
1111 
1112  if (!sdb_num_set(sdb, "num_entries", number_of_symbols, 0) ||
1113  !sdb_num_set(sdb, "addr", versym_addr, 0) ||
1114  !sdb_num_set(sdb, "offset", versym_offset, 0)) {
1115  sdb_free(sdb);
1116  return NULL;
1117  }
1118 
1119  ut64 versym_entry_offset = versym_offset;
1120 
1121  for (size_t i = 0; i < number_of_symbols; i++) {
1122  char key[32];
1123  if (rz_strf(key, "entry%zu", i) == NULL) {
1124  sdb_free(sdb);
1125  return NULL;
1126  }
1127 
1128  Elf_(Versym) versym_entry;
1129  if (!Elf_(rz_bin_elf_read_versym)(bin, &versym_entry_offset, &versym_entry)) {
1130  sdb_free(sdb);
1131  return NULL;
1132  }
1133 
1134  switch (versym_entry) {
1135  case VER_NDX_LOCAL:
1136  if (!sdb_set(sdb, key, "0 (*local*)", 0)) {
1137  sdb_free(sdb);
1138  return NULL;
1139  }
1140  break;
1141  case VER_NDX_GLOBAL:
1142  if (!sdb_set(sdb, key, "1 (*global*)", 0)) {
1143  sdb_free(sdb);
1144  return NULL;
1145  }
1146  break;
1147  default:
1148  if (get_versym_entry_sdb_from_verneed(bin, sdb, key, versym_entry)) {
1149  break;
1150  }
1151 
1152  if (!get_versym_entry_sdb_from_verdef(bin, sdb, key, versym_entry)) {
1153  sdb_free(sdb);
1154  return NULL;
1155  }
1156  }
1157  }
1158 
1159  return sdb;
1160 }
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: elf_misc.c:105
static bool get_versym_entry_sdb_from_verneed(ELFOBJ *bin, Sdb *sdb, const char *key, Elf_(Versym) versym)
Definition: elf_info.c:977
static bool get_versym_entry_sdb_from_verdef(ELFOBJ *bin, Sdb *sdb, const char *key, Elf_(Versym) versym)
Definition: elf_info.c:1035
#define DT_VERSYM
Definition: common.h:624
#define VER_NDX_LOCAL
Definition: common.h:687
#define VER_NDX_GLOBAL
Definition: common.h:688

References DT_VERSYM, Elf_(), get_versym_entry_sdb_from_verdef(), get_versym_entry_sdb_from_verneed(), i, key, NULL, rz_bin_elf_get_dt_info(), rz_bin_elf_read_versym(), rz_bin_elf_v2p(), rz_strf, sdb_free(), sdb_new0(), sdb_num_set(), sdb_set(), ut64(), UT64_MAX, VER_NDX_GLOBAL, and VER_NDX_LOCAL.

Referenced by rz_bin_elf_get_symbols_info().

◆ get_head_flag()

static char* get_head_flag ( ELFOBJ bin)
static

Definition at line 776 of file elf_info.c.

776  {
777  char *head_flag = NULL;
778 
779  head_flag = add_cpu_info(bin, head_flag);
780  head_flag = add_abi_info(bin, head_flag);
781 
782  return head_flag;
783 }
static char * add_abi_info(ELFOBJ *bin, char *head_flag)
Definition: elf_info.c:755
static char * add_cpu_info(ELFOBJ *bin, char *head_flag)
Definition: elf_info.c:766

References add_abi_info(), add_cpu_info(), and NULL.

Referenced by rz_bin_elf_get_head_flag().

◆ get_main_offset_arm64()

static ut64 get_main_offset_arm64 ( ELFOBJ bin,
ut64  entry,
ut8 buf 
)
static

Definition at line 488 of file elf_info.c.

488  {
489  if (buf[0x18 + 3] != 0x58 || buf[0x2f] != 0x00) {
490  return UT64_MAX;
491  }
492 
493  ut64 entry_vaddr = Elf_(rz_bin_elf_p2v)(bin, entry);
494  if (entry_vaddr == UT64_MAX) {
495  return UT64_MAX;
496  }
497 
498  ut64 main_addr = rz_read_le32(buf + 0x30);
499 
500  if (main_addr >> 16 == entry_vaddr >> 16) {
501  return Elf_(rz_bin_elf_v2p)(bin, main_addr);
502  }
503 
504  return UT64_MAX;
505 }
ut64 Elf_() rz_bin_elf_p2v(RZ_NONNULL ELFOBJ *bin, ut64 paddr)
Convert a physical address to the virtual address.
Definition: elf.c:400
voidpf void * buf
Definition: ioapi.h:138
static ut32 rz_read_le32(const void *src)
Definition: rz_endian.h:239
Definition: zipcmp.c:77

References Elf_(), rz_bin_elf_p2v(), rz_bin_elf_v2p(), rz_read_le32(), ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_main_offset().

◆ get_main_offset_arm_glibc()

static ut64 get_main_offset_arm_glibc ( ELFOBJ bin,
ut64  entry,
ut8 buf 
)
static

Definition at line 477 of file elf_info.c.

477  {
478  // ARM Glibc
481  } else {
483  }
484 
485  return UT64_MAX;
486 }
bool Elf_() rz_bin_elf_is_thumb_addr(ut64 addr)
Definition: elf_arm.c:24
static ut64 get_main_offset_arm_glibc_thumb(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:443
static ut64 get_main_offset_arm_glibc_non_thumb(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:465

References Elf_(), get_main_offset_arm_glibc_non_thumb(), get_main_offset_arm_glibc_thumb(), rz_bin_elf_is_thumb_addr(), and UT64_MAX.

Referenced by rz_bin_elf_get_main_offset().

◆ get_main_offset_arm_glibc_non_thumb()

static ut64 get_main_offset_arm_glibc_non_thumb ( ELFOBJ bin,
ut64  entry,
ut8 buf 
)
static

Definition at line 465 of file elf_info.c.

465  {
466  if (!memcmp(buf, "\x00\xb0\xa0\xe3\x00\xe0\xa0\xe3", 8)) {
467  return Elf_(rz_bin_elf_v2p)(bin, rz_read_le32(buf + 0x34) & ~1);
468  }
469 
470  if (!memcmp(buf, "\x24\xc0\x9f\xe5\x00\xb0\xa0\xe3", 8)) {
471  return Elf_(rz_bin_elf_v2p)(bin, rz_read_le32(buf + 0x30) & ~1);
472  }
473 
474  return UT64_MAX;
475 }

References Elf_(), rz_bin_elf_v2p(), rz_read_le32(), and UT64_MAX.

Referenced by get_main_offset_arm_glibc().

◆ get_main_offset_arm_glibc_thumb()

static ut64 get_main_offset_arm_glibc_thumb ( ELFOBJ bin,
ut64  entry,
ut8 buf 
)
static

Definition at line 443 of file elf_info.c.

443  {
444  size_t delta = 0;
445 
446  if (!memcmp(buf, "\xf0\x00\x0b\x4f\xf0\x00\x0e\x02\xbc\x6a\x46", 11)) {
447  /* newer versions of gcc use push/pop */
448  delta = 0x28;
449  } else if (!memcmp(buf, "\xf0\x00\x0b\x4f\xf0\x00\x0e\x5d\xf8\x04\x1b", 11)) {
450  /* older versions of gcc (4.5.x) use ldr/str */
451  delta = 0x30;
452  }
453 
454  if (delta) {
455  ut64 tmp = rz_read_le32(buf + delta - 1) & ~1;
456  ut64 pa = Elf_(rz_bin_elf_v2p)(bin, tmp);
457  if (pa < rz_buf_size(bin->b)) {
458  return pa;
459  }
460  }
461 
462  return UT64_MAX;
463 }
static st64 delta
Definition: vmenus.c:2425

References delta, Elf_(), rz_bin_elf_v2p(), rz_buf_size(), rz_read_le32(), autogen_x86imm::tmp, ut64(), and UT64_MAX.

Referenced by get_main_offset_arm_glibc().

◆ get_main_offset_from_symbol()

static ut64 get_main_offset_from_symbol ( ELFOBJ bin)
static

Definition at line 296 of file elf_info.c.

296  {
297  RzBinElfSymbol *symbol;
299  if (symbol->name && !strcmp(symbol->name, "main")) {
300  if (symbol->paddr != UT64_MAX) {
301  return symbol->paddr;
302  }
303 
304  return symbol->vaddr;
305  }
306  }
307 
308  return UT64_MAX;
309 }
#define rz_bin_elf_foreach_symbols(bin, symbol)
Definition: elf.h:46
RZ_OWN char * name
Definition: elf.h:140

References rz_bin_elf_symbol_t::name, rz_bin_elf_symbol_t::paddr, rz_bin_elf_foreach_symbols, UT64_MAX, and rz_bin_elf_symbol_t::vaddr.

Referenced by rz_bin_elf_get_main_offset().

◆ get_main_offset_linux_64_pie()

static ut64 get_main_offset_linux_64_pie ( ELFOBJ bin,
ut64  entry,
ut8 buf 
)
static

Definition at line 311 of file elf_info.c.

311  {
312  /* linux64 pie main -- probably buggy in some cases */
313  int bo = 29; // Begin offset may vary depending on the entry prelude
314  // endbr64 - fedora bins have this
315  if (buf[0] == 0xf3 && buf[1] == 0x0f && buf[2] == 0x1e && buf[3] == 0xfa) {
316  // Change begin offset if binary starts with 'endbr64'
317  bo = 33;
318  // double xor for init and fini
319  if (!memcmp(buf + 19, "\x45\x31\xc0\x31\xc9", 5)) {
320  bo = 24;
321  }
322  }
323  if (buf[bo] == 0x48) {
324  ut8 ch = buf[bo + 1];
325  if (ch == 0x8d) { // lea rdi, qword [rip + MAINDELTA]
326  ut8 *p = buf + bo + 3;
327  st32 maindelta = (st32)rz_read_le32(p);
328  ut64 ventry = Elf_(rz_bin_elf_p2v)(bin, entry);
329  if (ventry == UT64_MAX) {
330  return UT64_MAX;
331  }
332  ut64 vmain = (ut64)(ventry + bo + maindelta) + 7;
333  return Elf_(rz_bin_elf_v2p)(bin, vmain);
334  } else if (ch == 0xc7) { // mov rdi, 0xADDR
335  ut8 *p = buf + bo + 3;
337  return Elf_(rz_bin_elf_v2p)(bin, addr);
338  }
339  }
340 
341  return UT64_MAX;
342 }
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
#define st32
Definition: rz_types_base.h:12

References addr, Elf_(), p, rz_bin_elf_p2v(), rz_bin_elf_v2p(), rz_read_le32(), st32, ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_main_offset().

◆ get_main_offset_mips()

static ut64 get_main_offset_mips ( ELFOBJ bin,
ut64  entry,
ut8 buf,
size_t  size 
)
static

Definition at line 408 of file elf_info.c.

408  {
409  /* get .got, calculate offset of main symbol */
410  if (memcmp(buf, "\x21\x00\xe0\x03\x01\x00\x11\x04", 8)) {
411  return UT64_MAX;
412  }
413 
414  /*
415  assuming the startup code looks like
416  got = gp-0x7ff0
417  got[index__libc_start_main] ( got[index_main] );
418 
419  looking for the instruction generating the first argument to find main
420  lw a0, offset(gp)
421  */
422  ut64 got_addr;
423 
424  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_PLTGOT, &got_addr)) {
425  return 0;
426  }
427 
428  ut64 got_offset = Elf_(rz_bin_elf_v2p)(bin, got_addr);
429  ut64 gp = got_offset + 0x7ff0;
430 
431  for (size_t i = 0; i < size; i += 4) {
432  const ut32 instr = rz_read_le32(buf + i);
433  if ((instr & 0xffff0000) == 0x8f840000) { // lw a0, offset(gp)
434  const short delta = instr & 0x0000ffff;
435  rz_buf_read_at(bin->b, /* got_entry_offset = */ gp + delta, buf, 4);
437  }
438  }
439 
440  return 0;
441 }
uint32_t ut32
#define DT_PLTGOT
Definition: common.h:540
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

References delta, DT_PLTGOT, Elf_(), i, rz_bin_elf_get_dt_info(), rz_bin_elf_v2p(), rz_buf_read_at(), rz_read_le32(), ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_main_offset().

◆ get_main_offset_x86_gcc()

static ut64 get_main_offset_x86_gcc ( ELFOBJ bin,
ut64  entry,
ut8 buf 
)
static

Definition at line 396 of file elf_info.c.

396  {
397  if (buf[0] != 0xe8 && memcmp(buf + 5, "\x50\xe8\x00\x00\x00\x00\xb8\x01\x00\x00\x00\x53", 12)) {
398  return UT64_MAX;
399  }
400 
401  size_t SIZEOF_CALL = 5;
402  ut64 rel_addr = (ut64)(buf[1] + (buf[2] << 8) + (buf[3] << 16) + (buf[4] << 24));
403  ut64 addr = Elf_(rz_bin_elf_p2v)(bin, entry + SIZEOF_CALL);
404  addr += rel_addr;
405  return Elf_(rz_bin_elf_v2p)(bin, addr);
406 }

References addr, Elf_(), rz_bin_elf_p2v(), rz_bin_elf_v2p(), ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_main_offset().

◆ get_main_offset_x86_non_pie()

static ut64 get_main_offset_x86_non_pie ( ELFOBJ bin,
ut64  entry,
ut8 buf 
)
static

Definition at line 344 of file elf_info.c.

344  {
345  // X86-NONPIE
346 #if RZ_BIN_ELF64
347  if (!memcmp(buf, "\x49\x89\xd9", 3) && buf[156] == 0xe8) { // openbsd
348  return rz_read_le32(buf + 157) + entry + 156 + 5;
349  }
350  if (!memcmp(buf + 29, "\x48\xc7\xc7", 3)) { // linux
351  ut64 addr = (ut64)rz_read_le32(buf + 29 + 3);
352  return Elf_(rz_bin_elf_v2p)(bin, addr);
353  }
354 #else
355  if (buf[23] == '\x68') {
356  ut64 addr = (ut64)rz_read_le32(buf + 23 + 1);
357  return Elf_(rz_bin_elf_v2p)(bin, addr);
358  }
359 #endif
360 
361  return UT64_MAX;
362 }

References addr, Elf_(), rz_bin_elf_v2p(), rz_read_le32(), ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_main_offset().

◆ get_main_offset_x86_pie()

static ut64 get_main_offset_x86_pie ( ELFOBJ bin,
ut64  entry,
ut8 buf 
)
static

Definition at line 364 of file elf_info.c.

364  {
365  // X86-PIE
366  if (buf[0x00] == 0x48 && buf[0x1e] == 0x8d && buf[0x11] == 0xe8) {
367  ut32 *pmain = (ut32 *)(buf + 0x30);
368  ut64 vmain = Elf_(rz_bin_elf_p2v)(bin, (ut64)*pmain);
369  ut64 ventry = Elf_(rz_bin_elf_p2v)(bin, entry);
370  if (vmain >> 16 == ventry >> 16) {
371  return vmain;
372  }
373  }
374  // X86-PIE
375  if (buf[0x1d] == 0x48 && buf[0x1e] == 0x8b) {
376  if (!memcmp(buf, "\x31\xed\x49\x89", 4)) { // linux
377  ut64 maddr, baddr;
378  ut8 n32s[sizeof(ut32)] = { 0 };
379  maddr = entry + 0x24 + rz_read_le32(buf + 0x20);
380  if (rz_buf_read_at(bin->b, maddr, n32s, sizeof(ut32)) == -1) {
381  return 0;
382  }
383  maddr = (ut64)rz_read_le32(&n32s[0]);
384  baddr = (bin->ehdr.e_entry >> 16) << 16;
387  }
388  maddr += baddr;
389  return maddr;
390  }
391  }
392 
393  return UT64_MAX;
394 }
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
ut64 Elf_() rz_bin_elf_get_baddr(RZ_NONNULL ELFOBJ *bin)
Compute the base address of the binary.
Definition: elf_info.c:1772

References baddr(), Elf_(), rz_bin_elf_get_baddr(), rz_bin_elf_has_segments(), rz_bin_elf_p2v(), rz_buf_read_at(), rz_read_le32(), ut64(), and UT64_MAX.

Referenced by rz_bin_elf_get_main_offset().

◆ get_osabi_name_from_ehdr()

static char* get_osabi_name_from_ehdr ( ELFOBJ bin)
static

Definition at line 740 of file elf_info.c.

740  {
741  switch (bin->ehdr.e_ident[EI_OSABI]) {
742  case ELFOSABI_LINUX:
743  return strdup("linux");
744  case ELFOSABI_SOLARIS:
745  return strdup("solaris");
746  case ELFOSABI_FREEBSD:
747  return strdup("freebsd");
748  case ELFOSABI_HPUX:
749  return strdup("hpux");
750  }
751 
752  return NULL;
753 }
#define ELFOSABI_HPUX
Definition: common.h:65
#define EI_OSABI
Definition: common.h:63
#define ELFOSABI_SOLARIS
Definition: common.h:69
#define ELFOSABI_FREEBSD
Definition: common.h:72
#define ELFOSABI_LINUX
Definition: common.h:67

References EI_OSABI, ELFOSABI_FREEBSD, ELFOSABI_HPUX, ELFOSABI_LINUX, ELFOSABI_SOLARIS, NULL, and strdup().

Referenced by rz_bin_elf_get_osabi_name().

◆ get_osabi_name_from_section_note()

static char* get_osabi_name_from_section_note ( ELFOBJ bin,
RzBinElfSection section 
)
static

Definition at line 706 of file elf_info.c.

706  {
707  if (section->type != SHT_NOTE) {
708  return NULL;
709  }
710 
711  for (size_t i = 0; i < RZ_ARRAY_SIZE(section_note_osabi_translation_table); i++) {
714  }
715  }
716 
717  return NULL;
718 }
static const struct section_note_osabi_translation section_note_osabi_translation_table[]
Definition: elf_info.c:62
#define SHT_NOTE
Definition: common.h:338

References i, section_note_osabi_translation::note_name, NULL, RZ_ARRAY_SIZE, section_note_osabi_translation_table, SHT_NOTE, and strdup().

Referenced by get_osabi_name_from_shdr().

◆ get_osabi_name_from_shdr()

static char* get_osabi_name_from_shdr ( ELFOBJ bin)
static

Definition at line 720 of file elf_info.c.

720  {
721  if (!bin->shstrtab) {
722  return NULL;
723  }
724 
727  if (!section->is_valid) {
728  continue;
729  }
730 
732  if (tmp) {
733  return tmp;
734  }
735  }
736 
737  return NULL;
738 }
#define rz_bin_elf_foreach_sections(bin, section)
Definition: elf.h:30
static char * get_osabi_name_from_section_note(ELFOBJ *bin, RzBinElfSection *section)
Definition: elf_info.c:706

References get_osabi_name_from_section_note(), NULL, rz_bin_elf_foreach_sections, and autogen_x86imm::tmp.

Referenced by rz_bin_elf_get_osabi_name().

◆ get_ver_flags()

static char* get_ver_flags ( ut32  flags)
static

Definition at line 686 of file elf_info.c.

686  {
687  char *result = NULL;
688 
689  if (!flags) {
690  return strdup("none");
691  }
692 
693  for (size_t i = 0; i < RZ_ARRAY_SIZE(ver_flags_translation_table); i++) {
694  if (flags & ver_flags_translation_table[i].flag) {
695  result = rz_str_append(result, ver_flags_translation_table[i].name);
696  }
697  }
698 
699  return result;
700 }
static const struct ver_flags_translation ver_flags_translation_table[]
Definition: elf_info.c:289
RZ_API char * rz_str_append(char *ptr, const char *string)
Definition: str.c:1063
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123

References ver_flags_translation::flag, flags, i, NULL, RZ_ARRAY_SIZE, rz_str_append(), strdup(), and ver_flags_translation_table.

Referenced by get_vernaux_entry_sdb().

◆ get_verdaux_entry()

static bool get_verdaux_entry ( ELFOBJ bin,
ut64  offset,
Elf_(Verdaux) *  entry 
)
static

Definition at line 916 of file elf_info.c.

916  {
918  RZ_LOG_WARN("Failed to read verdaux entry at 0x%" PFMT64x ".\n", offset);
919  return false;
920  }
921 
922  return true;
923 }
static bool get_verdaux_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verdaux) *entry)
Definition: elf_info.c:911
voidpf uLong offset
Definition: ioapi.h:144
#define PFMT64x
Definition: rz_types.h:393

References get_verdaux_entry_aux(), PFMT64x, and RZ_LOG_WARN.

Referenced by get_versym_entry_sdb_from_verdef().

◆ get_verdaux_entry_aux()

static bool get_verdaux_entry_aux ( ELFOBJ bin,
ut64  offset,
Elf_(Verdaux) *  entry 
)
static

Definition at line 911 of file elf_info.c.

911  {
912  return Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vda_name) &&
913  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vda_next);
914 }
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_(), and rz_bin_elf_read_word().

Referenced by get_verdaux_entry().

◆ get_verdef_entry()

static bool get_verdef_entry ( ELFOBJ bin,
ut64  offset,
Elf_(Verdef) *  entry 
)
static

Definition at line 935 of file elf_info.c.

935  {
937  RZ_LOG_WARN("Failed to read verdef entry at 0x%" PFMT64x ".\n", offset);
938  return false;
939  }
940 
941  return true;
942 }
static bool get_verdef_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verdef) *entry)
Definition: elf_info.c:925

References get_verdef_entry_aux(), PFMT64x, and RZ_LOG_WARN.

Referenced by get_versym_entry_sdb_from_verdef().

◆ get_verdef_entry_aux()

static bool get_verdef_entry_aux ( ELFOBJ bin,
ut64  offset,
Elf_(Verdef) *  entry 
)
static

Definition at line 925 of file elf_info.c.

925  {
926  return Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vd_version) &&
927  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vd_flags) &&
928  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vd_ndx) &&
929  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vd_cnt) &&
930  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vd_hash) &&
931  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vd_aux) &&
932  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vd_next);
933 }
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_bin_elf_read_word().

Referenced by get_verdef_entry().

◆ get_vernaux_entry()

static bool get_vernaux_entry ( ELFOBJ bin,
ut64  offset,
Elf_(Vernaux) *  entry 
)
static

Definition at line 952 of file elf_info.c.

952  {
954  RZ_LOG_WARN("Failed to read vernaux entry at 0x%" PFMT64x ".\n", offset);
955  return false;
956  }
957 
958  return true;
959 }
static bool get_vernaux_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Vernaux) *entry)
Definition: elf_info.c:944

References get_vernaux_entry_aux(), PFMT64x, and RZ_LOG_WARN.

Referenced by get_verneed_entry_sdb(), and get_versym_entry_sdb_from_verneed().

◆ get_vernaux_entry_aux()

static bool get_vernaux_entry_aux ( ELFOBJ bin,
ut64  offset,
Elf_(Vernaux) *  entry 
)
static

Definition at line 944 of file elf_info.c.

944  {
945  return Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vna_hash) &&
946  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vna_flags) &&
947  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vna_other) &&
948  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vna_name) &&
949  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vna_next);
950 }

References Elf_(), rz_bin_elf_read_half(), and rz_bin_elf_read_word().

Referenced by get_vernaux_entry().

◆ get_vernaux_entry_sdb()

static Sdb* get_vernaux_entry_sdb ( ELFOBJ bin,
Elf_(Vernaux)  vernaux_entry,
size_t  index 
)
static

Definition at line 1162 of file elf_info.c.

1162  {
1163  const char *tmp = Elf_(rz_bin_elf_strtab_get)(bin->dynstr, vernaux_entry.vna_name);
1164  if (!tmp) {
1165  return NULL;
1166  }
1167 
1168  Sdb *sdb_vernaux = sdb_new0();
1169  if (!sdb_vernaux) {
1170  return NULL;
1171  }
1172 
1173  char *flags = get_ver_flags(vernaux_entry.vna_flags);
1174  if (!sdb_set_owned(sdb_vernaux, "flags", flags, 0)) {
1175  sdb_free(sdb_vernaux);
1176  return NULL;
1177  }
1178 
1179  if (!sdb_num_set(sdb_vernaux, "idx", index, 0) ||
1180  !sdb_num_set(sdb_vernaux, "version", vernaux_entry.vna_other, 0) ||
1181  !sdb_set(sdb_vernaux, "name", tmp, 0)) {
1182  sdb_free(sdb_vernaux);
1183  return NULL;
1184  }
1185 
1186  return sdb_vernaux;
1187 }
RZ_BORROW const char *Elf_() rz_bin_elf_strtab_get(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
Definition: elf_strtab.c:8
static char * get_ver_flags(ut32 flags)
Definition: elf_info.c:686
RZ_API int sdb_set_owned(Sdb *s, const char *key, char *val, ut32 cas)
Definition: sdb.c:607

References Elf_(), flags, get_ver_flags(), NULL, rz_bin_elf_strtab_get(), sdb_free(), sdb_new0(), sdb_num_set(), sdb_set(), sdb_set_owned(), and autogen_x86imm::tmp.

Referenced by get_verneed_entry_sdb().

◆ get_verneed_entry()

static bool get_verneed_entry ( ELFOBJ bin,
ut64  offset,
Elf_(Verneed) *  entry 
)
static

Definition at line 968 of file elf_info.c.

968  {
970  RZ_LOG_WARN("Failed to read verneed entry at 0x%" PFMT64x ".\n", offset);
971  return false;
972  }
973 
974  return true;
975 }
static bool get_verneed_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verneed) *entry)
Definition: elf_info.c:960

References get_verneed_entry_aux(), PFMT64x, and RZ_LOG_WARN.

Referenced by get_gnu_verneed(), and get_versym_entry_sdb_from_verneed().

◆ get_verneed_entry_aux()

static bool get_verneed_entry_aux ( ELFOBJ bin,
ut64  offset,
Elf_(Verneed) *  entry 
)
static

Definition at line 960 of file elf_info.c.

960  {
961  return Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vn_version) &&
962  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vn_cnt) &&
963  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vn_file) &&
964  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vn_aux) &&
965  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vn_next);
966 }

References Elf_(), rz_bin_elf_read_half(), and rz_bin_elf_read_word().

Referenced by get_verneed_entry().

◆ get_verneed_entry_sdb()

static Sdb* get_verneed_entry_sdb ( ELFOBJ bin,
Elf_(Verneed)  verneed_entry,
size_t  offset 
)
static

Definition at line 1211 of file elf_info.c.

1211  {
1212  Sdb *sdb_version = get_verneed_entry_sdb_aux(bin, verneed_entry, offset);
1213  if (!sdb_version) {
1214  return NULL;
1215  }
1216 
1217  ut64 vernaux_entry_offset = offset + verneed_entry.vn_aux;
1218 
1219  for (size_t i = 0; i < verneed_entry.vn_cnt; i++) {
1220  Elf_(Vernaux) vernaux_entry;
1221  if (!get_vernaux_entry(bin, vernaux_entry_offset, &vernaux_entry)) {
1222  sdb_free(sdb_version);
1223  return NULL;
1224  }
1225 
1226  Sdb *sdb_vernaux = get_vernaux_entry_sdb(bin, vernaux_entry, vernaux_entry_offset);
1227  if (!sdb_vernaux) {
1228  sdb_free(sdb_version);
1229  return NULL;
1230  }
1231 
1232  char key[32];
1233  if (!sdb_ns_set(sdb_version, rz_strf(key, "vernaux%zu", i), sdb_vernaux)) {
1234  sdb_free(sdb_vernaux);
1235  sdb_free(sdb_version);
1236  return NULL;
1237  }
1238 
1239  sdb_free(sdb_vernaux);
1240 
1241  vernaux_entry_offset += vernaux_entry.vna_next;
1242  }
1243 
1244  return sdb_version;
1245 }
static Sdb * get_vernaux_entry_sdb(ELFOBJ *bin, Elf_(Vernaux) vernaux_entry, size_t index)
Definition: elf_info.c:1162
static Sdb * get_verneed_entry_sdb_aux(ELFOBJ *bin, Elf_(Verneed) verneed_entry, size_t index)
Definition: elf_info.c:1189
static bool get_vernaux_entry(ELFOBJ *bin, ut64 offset, Elf_(Vernaux) *entry)
Definition: elf_info.c:952

References Elf_(), get_vernaux_entry(), get_vernaux_entry_sdb(), get_verneed_entry_sdb_aux(), i, key, NULL, rz_strf, sdb_free(), sdb_ns_set(), and ut64().

Referenced by get_gnu_verneed().

◆ get_verneed_entry_sdb_aux()

static Sdb* get_verneed_entry_sdb_aux ( ELFOBJ bin,
Elf_(Verneed)  verneed_entry,
size_t  index 
)
static

Definition at line 1189 of file elf_info.c.

1189  {
1190  const char *tmp = Elf_(rz_bin_elf_strtab_get)(bin->dynstr, verneed_entry.vn_file);
1191  if (!tmp) {
1192  return NULL;
1193  }
1194 
1195  Sdb *sdb_version = sdb_new0();
1196  if (!sdb_version) {
1197  return NULL;
1198  }
1199 
1200  if (!sdb_num_set(sdb_version, "cnt", verneed_entry.vn_cnt, 0) ||
1201  !sdb_num_set(sdb_version, "idx", index, 0) ||
1202  !sdb_num_set(sdb_version, "vn_version", verneed_entry.vn_version, 0) ||
1203  !sdb_set(sdb_version, "file_name", tmp, 0)) {
1204  sdb_free(sdb_version);
1205  return NULL;
1206  }
1207 
1208  return sdb_version;
1209 }

References Elf_(), NULL, rz_bin_elf_strtab_get(), sdb_free(), sdb_new0(), sdb_num_set(), sdb_set(), and autogen_x86imm::tmp.

Referenced by get_verneed_entry_sdb().

◆ get_versym_entry_sdb_from_verdef()

static bool get_versym_entry_sdb_from_verdef ( ELFOBJ bin,
Sdb sdb,
const char *  key,
Elf_(Versym)  versym 
)
static

Definition at line 1035 of file elf_info.c.

1035  {
1036  ut64 verdef_addr;
1037  ut64 verdef_num;
1038 
1039  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERDEF, &verdef_addr) || !Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERDEFNUM, &verdef_num)) {
1040  return false;
1041  }
1042 
1043  ut64 verdef_offset = Elf_(rz_bin_elf_v2p(bin, verdef_addr));
1044 
1045  if (verdef_offset == UT64_MAX) {
1046  return false;
1047  }
1048 
1049  ut64 verdef_entry_offset = verdef_offset;
1050 
1051  for (size_t i = 0; i < verdef_num; i++) {
1052  Elf_(Verdef) verdef_entry;
1053  if (!get_verdef_entry(bin, verdef_entry_offset, &verdef_entry)) {
1054  return false;
1055  }
1056 
1057  if (!verdef_entry.vd_cnt || verdef_entry.vd_ndx != (versym & VERSYM_VERSION)) {
1058  verdef_entry_offset += verdef_entry.vd_next;
1059  continue;
1060  }
1061 
1062  ut64 verdaux_entry_offset = verdef_entry_offset + verdef_entry.vd_aux;
1063 
1064  Elf_(Verdaux) verdaux_entry;
1065  if (!get_verdaux_entry(bin, verdaux_entry_offset, &verdaux_entry)) {
1066  return false;
1067  }
1068 
1069  const char *tmp = Elf_(rz_bin_elf_strtab_get)(bin->dynstr, verdaux_entry.vda_name);
1070  if (!tmp) {
1071  return false;
1072  }
1073 
1074  char *value = rz_str_newf("%u (%s)", versym & VERSYM_VERSION, tmp);
1075  if (!value) {
1076  return false;
1077  }
1078 
1079  if (!sdb_set_owned(sdb, key, value, 0)) {
1080  return false;
1081  }
1082 
1083  return true;
1084  }
1085 
1086  return false;
1087 }
static int value
Definition: cmd_api.c:93
#define VERSYM_VERSION
Definition: elf_info.c:13
static bool get_verdef_entry(ELFOBJ *bin, ut64 offset, Elf_(Verdef) *entry)
Definition: elf_info.c:935
static bool get_verdaux_entry(ELFOBJ *bin, ut64 offset, Elf_(Verdaux) *entry)
Definition: elf_info.c:916
#define DT_VERDEF
Definition: common.h:618
#define DT_VERDEFNUM
Definition: common.h:619
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1

References DT_VERDEF, DT_VERDEFNUM, Elf_(), get_verdaux_entry(), get_verdef_entry(), i, key, rz_bin_elf_get_dt_info(), rz_bin_elf_strtab_get(), rz_bin_elf_v2p(), rz_str_newf(), sdb_set_owned(), autogen_x86imm::tmp, ut64(), UT64_MAX, value, and VERSYM_VERSION.

Referenced by get_gnu_versym().

◆ get_versym_entry_sdb_from_verneed()

static bool get_versym_entry_sdb_from_verneed ( ELFOBJ bin,
Sdb sdb,
const char *  key,
Elf_(Versym)  versym 
)
static

Definition at line 977 of file elf_info.c.

977  {
978  ut64 verneed_addr;
979  ut64 verneed_num;
980 
981  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERNEED, &verneed_addr) || !Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERNEEDNUM, &verneed_num)) {
982  return false;
983  }
984 
985  ut64 verneed_offset = Elf_(rz_bin_elf_v2p(bin, verneed_addr));
986 
987  if (verneed_offset == UT64_MAX) {
988  return false;
989  }
990 
991  ut64 verneed_entry_offset = verneed_offset;
992 
993  for (size_t i = 0; i < verneed_num; i++) {
994  Elf_(Verneed) verneed_entry;
995  if (!get_verneed_entry(bin, verneed_entry_offset, &verneed_entry)) {
996  return false;
997  }
998 
999  ut64 vernaux_entry_offset = verneed_entry_offset + verneed_entry.vn_aux;
1000 
1001  for (size_t j = 0; j < verneed_entry.vn_cnt; j++) {
1002  Elf_(Vernaux) vernaux_entry;
1003  if (!get_vernaux_entry(bin, vernaux_entry_offset, &vernaux_entry)) {
1004  return false;
1005  }
1006 
1007  if (vernaux_entry.vna_other != versym) {
1008  vernaux_entry_offset += vernaux_entry.vna_next;
1009  continue;
1010  }
1011 
1012  const char *tmp = Elf_(rz_bin_elf_strtab_get)(bin->dynstr, vernaux_entry.vna_name);
1013  if (!tmp) {
1014  return false;
1015  }
1016 
1017  char *value = rz_str_newf("%u (%s)", versym & VERSYM_VERSION, tmp);
1018  if (!value) {
1019  return false;
1020  }
1021 
1022  if (!sdb_set_owned(sdb, key, value, 0)) {
1023  return false;
1024  }
1025 
1026  return true;
1027  }
1028 
1029  verneed_entry_offset += verneed_entry.vn_next;
1030  }
1031 
1032  return false;
1033 }

References DT_VERNEED, DT_VERNEEDNUM, Elf_(), get_vernaux_entry(), get_verneed_entry(), i, key, rz_bin_elf_get_dt_info(), rz_bin_elf_strtab_get(), rz_bin_elf_v2p(), rz_str_newf(), sdb_set_owned(), autogen_x86imm::tmp, ut64(), UT64_MAX, value, and VERSYM_VERSION.

Referenced by get_gnu_versym().

◆ has_dt_rpath_entry()

static bool has_dt_rpath_entry ( ELFOBJ bin)
static

Definition at line 702 of file elf_info.c.

References DT_RPATH, DT_RUNPATH, Elf_(), NULL, and rz_bin_elf_get_dt_info().

Referenced by rz_bin_elf_get_rpath().

◆ has_thumb_symbol()

static bool has_thumb_symbol ( ELFOBJ bin)
static

Definition at line 587 of file elf_info.c.

587  {
588  RzBinElfSymbol *symbol;
591  return true;
592  }
593  }
594 
595  return false;
596 }

References Elf_(), rz_bin_elf_symbol_t::paddr, rz_bin_elf_foreach_symbols, rz_bin_elf_is_thumb_addr(), and rz_bin_elf_symbol_t::vaddr.

Referenced by rz_bin_elf_get_bits().

◆ is_elf_class64()

static bool is_elf_class64 ( ELFOBJ bin)
static

Definition at line 822 of file elf_info.c.

822  {
823  return bin->ehdr.e_ident[EI_CLASS] == ELFCLASS64;
824 }

References EI_CLASS, and ELFCLASS64.

Referenced by get_abi_mips().

◆ is_mips_n32()

static bool is_mips_n32 ( ELFOBJ bin)
static

Definition at line 842 of file elf_info.c.

842  {
843  if (bin->ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
844  return false;
845  }
846 
847  if ((bin->ehdr.e_flags & EF_MIPS_ABI2) == 0 || (bin->ehdr.e_flags & EF_MIPS_ABI) != 0) {
848  return false;
849  }
850 
851  return true;
852 }
#define EF_MIPS_ABI
Definition: elf_info.c:11
#define EF_MIPS_ABI2

References EF_MIPS_ABI, EF_MIPS_ABI2, EI_CLASS, and ELFCLASS32.

Referenced by get_abi_mips().

◆ is_mips_o32()

static bool is_mips_o32 ( ELFOBJ bin)
static

Definition at line 826 of file elf_info.c.

826  {
827  if (bin->ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
828  return false;
829  }
830 
831  if ((bin->ehdr.e_flags & EF_MIPS_ABI2) != 0) {
832  return false;
833  }
834 
835  if ((bin->ehdr.e_flags & EF_MIPS_ABI) != 0 && (bin->ehdr.e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32) {
836  return false;
837  }
838 
839  return true;
840 }
#define EF_MIPS_ABI_O32
Definition: elf_info.c:9

References EF_MIPS_ABI, EF_MIPS_ABI2, EF_MIPS_ABI_O32, EI_CLASS, and ELFCLASS32.

Referenced by get_abi_mips().

◆ is_playstation_hack()

static int is_playstation_hack ( ELFOBJ bin,
Elf_(Word)  mips_type 
)
static

Definition at line 608 of file elf_info.c.

608  {
610 }
bool Elf_() rz_bin_elf_is_static(RZ_NONNULL ELFOBJ *bin)
Check if the binary is statically-linked library.
Definition: elf_info.c:1674
bool Elf_() rz_bin_elf_is_executable(RZ_NONNULL ELFOBJ *bin)
Check if the elf binary is executable.
Definition: elf_info.c:1648
#define EF_MIPS_ARCH_3
Definition: glibc_elf.h:1595

References EF_MIPS_ARCH_3, Elf_(), rz_bin_elf_is_executable(), and rz_bin_elf_is_static().

Referenced by get_bits_mips().

◆ read_elf_intrp()

static char* read_elf_intrp ( ELFOBJ bin,
ut64  addr,
size_t  size 
)
static

Definition at line 630 of file elf_info.c.

630  {
631  char *str = malloc(size + 1);
632  if (!str) {
633  return NULL;
634  }
635 
636  if (rz_buf_read_at(bin->b, addr, (ut8 *)str, size) < 0) {
637  free(str);
638  return NULL;
639  }
640 
641  str[size] = 0;
642 
643  return str;
644 }
void * malloc(size_t size)
Definition: malloc.c:123

References addr, free(), malloc(), NULL, rz_buf_read_at(), and cmd_descs_generate::str.

Referenced by get_elf_intrp().

◆ 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 rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

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

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

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
static bool arch_is_mips(ELFOBJ *bin)
Definition: elf_info.c:622
static int get_bits_common(ELFOBJ *bin)
Definition: elf_info.c:575
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

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_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
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_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
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 }
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_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_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 }
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

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_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_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_symbols_info()

RZ_IPI 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

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_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_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_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_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 }
#define ELFDATA2MSB
Definition: common.h:59
#define EI_DATA
Definition: common.h:56

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 }

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 }

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 }
bool Elf_() rz_bin_elf_has_sections(RZ_NONNULL ELFOBJ *bin)
Definition: elf_sections.c:440
#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.

Variable Documentation

◆ arch_translation_table

const struct arch_translation arch_translation_table[]
static

Definition at line 1 of file elf_info.c.

Referenced by rz_bin_elf_get_arch().

◆ class_translation_table

const struct class_translation class_translation_table[]
static
Initial value:
= {
{ ELFCLASSNONE, "none" },
{ ELFCLASS32, "ELF32" },
{ ELFCLASS64, "ELF64" }
}

Definition at line 1 of file elf_info.c.

Referenced by rz_bin_elf_get_elf_class().

◆ cpu_mips_translation_table

const struct cpu_mips_translation cpu_mips_translation_table[]
static
Initial value:
= {
{ EF_MIPS_ARCH_1, "mips1" },
{ EF_MIPS_ARCH_2, "mips2" },
{ EF_MIPS_ARCH_3, "mips3" },
{ EF_MIPS_ARCH_4, "mips4" },
{ EF_MIPS_ARCH_5, "mips5" },
{ EF_MIPS_ARCH_32, "mips32" },
{ EF_MIPS_ARCH_64, "mips64" },
{ EF_MIPS_ARCH_32R2, "mips32r2" },
{ EF_MIPS_ARCH_64R2, "mips64r2" },
}
#define EF_MIPS_ARCH_2
Definition: glibc_elf.h:1594
#define EF_MIPS_ARCH_4
Definition: glibc_elf.h:1596
#define EF_MIPS_ARCH_32R2
Definition: glibc_elf.h:1600
#define EF_MIPS_ARCH_64
Definition: glibc_elf.h:1599
#define EF_MIPS_ARCH_5
Definition: glibc_elf.h:1597
#define EF_MIPS_ARCH_32
Definition: glibc_elf.h:1598
#define EF_MIPS_ARCH_1
Definition: glibc_elf.h:1593
#define EF_MIPS_ARCH_64R2
Definition: glibc_elf.h:1601

Definition at line 1 of file elf_info.c.

Referenced by get_cpu_mips().

◆ machine_name_translation_table

const struct machine_name_translation machine_name_translation_table[]
static

Definition at line 1 of file elf_info.c.

Referenced by rz_bin_elf_get_machine_name().

◆ mips_bits_translation_table

const struct mips_bits_translation mips_bits_translation_table[]
static
Initial value:
= {
{ EF_MIPS_ARCH_1, 32 },
{ EF_MIPS_ARCH_2, 32 },
{ EF_MIPS_ARCH_3, 32 },
{ EF_MIPS_ARCH_4, 32 },
{ EF_MIPS_ARCH_5, 32 },
{ EF_MIPS_ARCH_32, 32 },
{ EF_MIPS_ARCH_64, 64 },
}

Definition at line 1 of file elf_info.c.

Referenced by get_bits_mips_common().

◆ section_note_osabi_translation_table

const struct section_note_osabi_translation section_note_osabi_translation_table[]
static
Initial value:
= {
{ ".note.openbsd.ident", "openbsd" },
{ ".note.minix.ident", "minix" },
{ ".note.netbsd.ident", "netbsd" },
{ ".note.android.ident", "android" }
}

Definition at line 1 of file elf_info.c.

Referenced by get_osabi_name_from_section_note().

◆ ver_flags_translation_table

const struct ver_flags_translation ver_flags_translation_table[]
static
Initial value:
= {
{ VER_FLG_BASE, "BASE " },
{ VER_FLG_WEAK, "WEAK " },
{ ~(VER_FLG_BASE | VER_FLG_WEAK), "| <unknown>" }
}
#define VER_FLG_WEAK
Definition: common.h:683
#define VER_FLG_BASE
Definition: common.h:682

Definition at line 1 of file elf_info.c.

Referenced by get_ver_flags().