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

Go to the source code of this file.

Functions

static bool get_dt_info (RzBinElfDtDynamic *ptr, ut64 key, ut64 *info)
 
static bool get_dynamic_entry_aux (ELFOBJ *bin, ut64 offset, Elf_(Dyn) *entry)
 
static bool get_dynamic_entry (ELFOBJ *bin, ut64 offset, Elf_(Dyn) *entry)
 
static bool add_dt_dynamic_entry (RzBinElfDtDynamic *ptr, ut64 key, ut64 info)
 
static bool fill_dt_dynamic (ELFOBJ *bin, RzBinElfDtDynamic *ptr, ut64 offset, ut64 size)
 
static bool init_dt_dynamic (ELFOBJ *bin, RzBinElfDtDynamic *ptr)
 
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)
 

Function Documentation

◆ add_dt_dynamic_entry()

static bool add_dt_dynamic_entry ( RzBinElfDtDynamic ptr,
ut64  key,
ut64  info 
)
static

Definition at line 36 of file elf_dynamic.c.

36  {
37  if (key == DT_NEEDED) {
38  return !!rz_vector_push(&ptr->dt_needed, &info);
39  } else {
40  return ht_uu_insert(ptr->info, key, info);
41  }
42 }
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
#define DT_NEEDED
Definition: common.h:538
RZ_API void * rz_vector_push(RzVector *vec, void *x)
Definition: vector.c:197

References DT_NEEDED, rz_bin_elf_dt_dynamic_t::dt_needed, rz_bin_elf_dt_dynamic_t::info, info(), key, and rz_vector_push().

Referenced by fill_dt_dynamic().

◆ fill_dt_dynamic()

static bool fill_dt_dynamic ( ELFOBJ bin,
RzBinElfDtDynamic ptr,
ut64  offset,
ut64  size 
)
static

Definition at line 44 of file elf_dynamic.c.

44  {
45  for (ut64 entry_offset = offset; entry_offset < offset + size; entry_offset += sizeof(Elf_(Dyn))) {
46  Elf_(Dyn) entry;
47  if (!get_dynamic_entry(bin, entry_offset, &entry)) {
48  return false;
49  }
50 
51  if (entry.d_tag == DT_NULL) {
52  break;
53  }
54 
55  if (get_dt_info(ptr, entry.d_tag, NULL)) {
56  RZ_LOG_WARN("DT_DYNAMIC entry (0x%" PFMT64x ") at 0x%" PFMT64x " was already handled.\n", (ut64)entry.d_tag, offset);
57  }
58 
59  if (!add_dt_dynamic_entry(ptr, entry.d_tag, entry.d_un.d_val)) {
60  return false;
61  }
62  }
63 
64  return true;
65 }
#define NULL
Definition: cris-opc.c:27
static bool get_dt_info(RzBinElfDtDynamic *ptr, ut64 key, ut64 *info)
Definition: elf_dynamic.c:7
static bool get_dynamic_entry(ELFOBJ *bin, ut64 offset, Elf_(Dyn) *entry)
Definition: elf_dynamic.c:27
static bool add_dt_dynamic_entry(RzBinElfDtDynamic *ptr, ut64 key, ut64 info)
Definition: elf_dynamic.c:36
#define Elf_(name)
Definition: elf_specs.h:32
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
#define DT_NULL
Definition: common.h:537
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define PFMT64x
Definition: rz_types.h:393
Definition: malloc.c:26
Definition: zipcmp.c:77
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References add_dt_dynamic_entry(), DT_NULL, Elf_, get_dt_info(), get_dynamic_entry(), NULL, PFMT64x, RZ_LOG_WARN, and ut64().

Referenced by init_dt_dynamic().

◆ get_dt_info()

static bool get_dt_info ( RzBinElfDtDynamic ptr,
ut64  key,
ut64 info 
)
static

Definition at line 7 of file elf_dynamic.c.

7  {
8  bool found = false;
9  ut64 tmp = ht_uu_find(ptr->info, key, &found);
10 
11  if (!found) {
12  return false;
13  }
14 
15  if (info) {
16  *info = tmp;
17  }
18 
19  return true;
20 }
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130

References found, rz_bin_elf_dt_dynamic_t::info, info(), key, autogen_x86imm::tmp, and ut64().

Referenced by fill_dt_dynamic(), and rz_bin_elf_get_dt_info().

◆ get_dynamic_entry()

static bool get_dynamic_entry ( ELFOBJ bin,
ut64  offset,
Elf_(Dyn) *  entry 
)
static

Definition at line 27 of file elf_dynamic.c.

27  {
29  RZ_LOG_WARN("Failed to read DT_DYNAMIC entry at 0x%" PFMT64x ".\n", offset);
30  return false;
31  }
32 
33  return true;
34 }
static bool get_dynamic_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Dyn) *entry)
Definition: elf_dynamic.c:22

References get_dynamic_entry_aux(), PFMT64x, and RZ_LOG_WARN.

Referenced by fill_dt_dynamic().

◆ get_dynamic_entry_aux()

static bool get_dynamic_entry_aux ( ELFOBJ bin,
ut64  offset,
Elf_(Dyn) *  entry 
)
static

Definition at line 22 of file elf_dynamic.c.

22  {
23  return Elf_(rz_bin_elf_read_sword_sxword)(bin, &offset, &entry->d_tag) &&
24  Elf_(rz_bin_elf_read_addr)(bin, &offset, &entry->d_un.d_ptr);
25 }
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: elf_misc.c:82
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: elf_misc.c:131

References Elf_, rz_bin_elf_read_addr(), and rz_bin_elf_read_sword_sxword().

Referenced by get_dynamic_entry().

◆ init_dt_dynamic()

static bool init_dt_dynamic ( ELFOBJ bin,
RzBinElfDtDynamic ptr 
)
static

Definition at line 67 of file elf_dynamic.c.

67  {
69  if (!segment) {
70  RZ_LOG_WARN("No PT_DYNAMIC segment in the ELF binary.\n")
71  return false;
72  }
73 
74  if (!segment->is_valid) {
75  RZ_LOG_WARN("The PT_DYNAMIC segment is invalid.\n");
76  return false;
77  }
78 
79  ut64 offset = Elf_(rz_bin_elf_v2p)(bin, segment->data.p_vaddr);
80  if (offset == UT64_MAX) {
81  RZ_LOG_INFO("Failed to convert PT_DYNAMIC segment p_vaddr to a physical offset.\n")
82  return false;
83  }
84 
85  return fill_dt_dynamic(bin, ptr, offset, segment->data.p_filesz);
86 }
static bool is_valid(arm_reg reg)
#define false
ut64 Elf_() rz_bin_elf_v2p(RZ_NONNULL ELFOBJ *bin, ut64 vaddr)
Convert a virtual address to the physical address.
Definition: elf.c:429
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 bool fill_dt_dynamic(ELFOBJ *bin, RzBinElfDtDynamic *ptr, ut64 offset, ut64 size)
Definition: elf_dynamic.c:44
#define PT_DYNAMIC
Definition: common.h:304
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define UT64_MAX
Definition: rz_types_base.h:86
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References Elf_, fill_dt_dynamic(), PT_DYNAMIC, rz_bin_elf_get_segment_with_type(), rz_bin_elf_v2p(), RZ_LOG_INFO, RZ_LOG_WARN, RzBinElfSegment, ut64(), and UT64_MAX.

Referenced by rz_bin_elf_dt_dynamic_new().

◆ 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_get_dt_info()

◆ 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_has_dt_dynamic()

bool Elf_() rz_bin_elf_has_dt_dynamic ( RZ_NONNULL ELFOBJ bin)