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

Go to the source code of this file.

Functions

static bool buffer_read_32_signed (ELFOBJ *bin, ut64 *offset, st32 *result)
 
static bool buffer_read_64_signed (ELFOBJ *bin, ut64 *offset, st64 *result)
 
bool Elf_() rz_bin_elf_check_array (RZ_NONNULL ELFOBJ *bin, Elf_(Off) offset, Elf_(Off) length, Elf_(Off) entry_size)
 
bool Elf_() rz_bin_elf_read_char (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT ut8 *result)
 
bool Elf_() rz_bin_elf_read_half (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Half) *result)
 
bool Elf_() rz_bin_elf_read_word (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Word) *result)
 
bool Elf_() rz_bin_elf_read_sword (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Sword) *result)
 
bool Elf_() rz_bin_elf_read_xword (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Xword) *result)
 
bool Elf_() rz_bin_elf_read_sxword (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Sxword) *result)
 
bool Elf_() rz_bin_elf_read_addr (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Addr) *result)
 
bool Elf_() rz_bin_elf_read_off (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Off) *result)
 
bool Elf_() rz_bin_elf_read_section (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Section) *result)
 
bool Elf_() rz_bin_elf_read_versym (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Versym) *result)
 
bool Elf_() rz_bin_elf_read_word_xword (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Word) *result)
 
bool Elf_() rz_bin_elf_read_sword_sxword (RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Sword) *result)
 
bool Elf_() rz_bin_elf_add_addr (Elf_(Addr) *result, Elf_(Addr) addr, Elf_(Addr) value)
 
bool Elf_() rz_bin_elf_add_off (Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
 
bool Elf_() rz_bin_elf_mul_addr (Elf_(Addr) *result, Elf_(Addr) addr, Elf_(Addr) value)
 
bool Elf_() rz_bin_elf_mul_off (Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
 

Function Documentation

◆ buffer_read_32_signed()

static bool buffer_read_32_signed ( ELFOBJ bin,
ut64 offset,
st32 result 
)
static

Definition at line 7 of file elf_misc.c.

7  {
8  ut32 tmp;
9  if (!rz_buf_read_ble32_at(bin->b, *offset, &tmp, bin->big_endian)) {
10  return false;
11  }
12 
13  *result = convert_to_two_complement_32(tmp);
14  *offset += 4;
15 
16  return true;
17 }
uint32_t ut32
voidpf uLong offset
Definition: ioapi.h:144
Definition: malloc.c:26

References autogen_x86imm::tmp.

Referenced by rz_bin_elf_read_sword().

◆ buffer_read_64_signed()

static bool buffer_read_64_signed ( ELFOBJ bin,
ut64 offset,
st64 result 
)
static

Definition at line 19 of file elf_misc.c.

19  {
20  ut64 tmp;
21 
22  if (!rz_buf_read_ble64_at(bin->b, *offset, &tmp, bin->big_endian)) {
23  return false;
24  }
25 
26  *result = convert_to_two_complement_64(tmp);
27  *offset += 8;
28 
29  return true;
30 }
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References autogen_x86imm::tmp, and ut64().

Referenced by rz_bin_elf_read_sxword().

◆ rz_bin_elf_add_addr()

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

Definition at line 138 of file elf_misc.c.

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

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

Referenced by verify_phdr_entry(), and verify_shdr_entry().

◆ rz_bin_elf_add_off()

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

Definition at line 146 of file elf_misc.c.

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

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

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

◆ rz_bin_elf_check_array()

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

Definition at line 32 of file elf_misc.c.

32  {
33  rz_return_val_if_fail(bin, false);
34 
35  Elf_(Off) array_size;
36  if (!Elf_(rz_bin_elf_mul_off)(&array_size, length, entry_size)) {
37  return false;
38  }
39 
40  Elf_(Off) end_off;
41  if (!Elf_(rz_bin_elf_add_off)(&end_off, offset, array_size)) {
42  return false;
43  }
44 
45  if (!array_size || end_off > bin->size) {
46  return false;
47  }
48 
49  return true;
50 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
bool Elf_() rz_bin_elf_add_off(Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
Definition: elf_misc.c:146
bool Elf_() rz_bin_elf_mul_off(Elf_(Off) *result, Elf_(Off) addr, Elf_(Off) value)
Definition: elf_misc.c:162
#define Elf_(name)
Definition: elf_specs.h:32
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

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

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

◆ rz_bin_elf_mul_addr()

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

Definition at line 154 of file elf_misc.c.

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

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

Referenced by parse_note_file().

◆ rz_bin_elf_mul_off()

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

Definition at line 162 of file elf_misc.c.

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

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

Referenced by rz_bin_elf_check_array().

◆ rz_bin_elf_read_addr()

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

Definition at line 82 of file elf_misc.c.

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

References rz_return_val_if_fail, and ut64().

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

◆ rz_bin_elf_read_char()

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

Definition at line 52 of file elf_misc.c.

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

References rz_buf_read8_offset, and rz_return_val_if_fail.

Referenced by Elf_(), and get_symbol_entry_aux().

◆ rz_bin_elf_read_half()

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

Definition at line 57 of file elf_misc.c.

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

References rz_return_val_if_fail.

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

◆ rz_bin_elf_read_off()

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

Definition at line 91 of file elf_misc.c.

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

References rz_return_val_if_fail, and ut64().

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

◆ rz_bin_elf_read_section()

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

Definition at line 100 of file elf_misc.c.

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

References rz_return_val_if_fail.

Referenced by get_symbol_entry_aux().

◆ rz_bin_elf_read_sword()

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

Definition at line 67 of file elf_misc.c.

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

References buffer_read_32_signed(), and rz_return_val_if_fail.

Referenced by rz_bin_elf_read_sword_sxword().

◆ rz_bin_elf_read_sword_sxword()

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

Definition at line 131 of file elf_misc.c.

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

References Elf_, rz_bin_elf_read_sword(), and rz_return_val_if_fail.

Referenced by get_dynamic_entry_aux(), and read_reloc_entry_aux().

◆ rz_bin_elf_read_sxword()

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

Definition at line 77 of file elf_misc.c.

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

References buffer_read_64_signed(), rz_return_val_if_fail, and st64.

◆ rz_bin_elf_read_versym()

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

Definition at line 105 of file elf_misc.c.

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

References Elf_, rz_bin_elf_read_half(), and rz_return_val_if_fail.

Referenced by get_gnu_versym().

◆ rz_bin_elf_read_word()

◆ rz_bin_elf_read_word_xword()

bool Elf_() rz_bin_elf_read_word_xword ( RZ_NONNULL ELFOBJ bin,
RZ_NONNULL RZ_INOUT ut64 offset,
RZ_NONNULL RZ_OUT Elf_(Word) *  result 
)

Definition at line 117 of file elf_misc.c.

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

References Elf_, rz_bin_elf_read_word(), and rz_return_val_if_fail.

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

◆ rz_bin_elf_read_xword()

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

Definition at line 72 of file elf_misc.c.

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

References rz_return_val_if_fail, and ut64().

Referenced by get_symbol_entry_aux().