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

Go to the source code of this file.

Functions

ut64 Elf_() rz_bin_elf_get_sp_val (RZ_NONNULL ELFOBJ *bin)
 Get the stack pointer value. More...
 

Function Documentation

◆ rz_bin_elf_get_sp_val()

ut64 Elf_() rz_bin_elf_get_sp_val ( RZ_NONNULL ELFOBJ bin)

Get the stack pointer value.

Parameters
elfbinary
Returns
allocated string

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

Definition at line 16 of file elf_corefile.c.

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

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