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

Go to the source code of this file.

Functions

RZ_BORROW const char *Elf_() rz_bin_elf_strtab_get (RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
 
RZ_OWN RzBinElfStrtab *Elf_() rz_bin_elf_strtab_new (RZ_NONNULL ELFOBJ *bin, ut64 offset, ut64 size)
 
RZ_OWN char *Elf_() rz_bin_elf_strtab_get_dup (RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
 
bool Elf_() rz_bin_elf_strtab_has_index (RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
 
void Elf_() rz_bin_elf_strtab_free (RzBinElfStrtab *ptr)
 

Function Documentation

◆ rz_bin_elf_strtab_free()

void Elf_() rz_bin_elf_strtab_free ( RzBinElfStrtab ptr)

Definition at line 72 of file elf_strtab.c.

72  {
73  if (!ptr) {
74  return;
75  }
76 
77  free(ptr->data);
78  free(ptr);
79 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free().

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

◆ rz_bin_elf_strtab_get()

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

Definition at line 8 of file elf_strtab.c.

8  {
9  rz_return_val_if_fail(strtab, false);
10 
11  if (!Elf_(rz_bin_elf_strtab_has_index)(strtab, index)) {
12  return NULL;
13  }
14 
15  return strtab->data + index;
16 }
#define NULL
Definition: cris-opc.c:27
#define Elf_(name)
Definition: elf_specs.h:32
bool Elf_() rz_bin_elf_strtab_has_index(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
Definition: elf_strtab.c:67
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

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

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

◆ rz_bin_elf_strtab_get_dup()

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

Definition at line 52 of file elf_strtab.c.

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

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

◆ rz_bin_elf_strtab_has_index()

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

Definition at line 67 of file elf_strtab.c.

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

References rz_return_val_if_fail.

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

◆ rz_bin_elf_strtab_new()

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

Definition at line 18 of file elf_strtab.c.

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

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

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