Module: ELFTools::Note

Included in:
Sections::NoteSection, Segments::NoteSegment
Defined in:
lib/elftools/note.rb

Overview

Note:

This module can only be included in Sections::NoteSection and Segments::NoteSegment since some methods here assume some attributes already exist.

Since both note sections and note segments refer to notes, this module defines common methods for Sections::NoteSection and Segments::NoteSegment.

Defined Under Namespace

Classes: Note

Constant Summary collapse

SIZE_OF_NHDR =

Since size of Structs::ELF_Nhdr will not change no matter in what endian and what arch, we can do this here. This value should equal to 12.

Structs::ELF_Nhdr.new(endian: :little).num_bytes

Instance Method Summary collapse

Instance Method Details

#each_notesEnumerator<ELFTools::Note::Note>, Array<ELFTools::Note::Note>

Note:

This method assume following methods exist:

stream
note_start
note_total_size

Iterate all notes in a note section or segment.

Structure of notes are:

+---------------+
| Note 1 header |
+---------------+
|  Note 1 name  |
+---------------+
|  Note 1 desc  |
+---------------+
| Note 2 header |
+---------------+
|      ...      |
+---------------+

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/elftools/note.rb', line 44

def each_notes
  return enum_for(:each_notes) unless block_given?

  @notes_offset_map ||= {}
  cur = note_start
  notes = []
  while cur < note_start + note_total_size
    stream.pos = cur
    @notes_offset_map[cur] ||= create_note(cur)
    note = @notes_offset_map[cur]
    # name and desc size needs to be 4-bytes align
    name_size = Util.align(note.header.n_namesz, 2)
    desc_size = Util.align(note.header.n_descsz, 2)
    cur += SIZE_OF_NHDR + name_size + desc_size
    notes << note
    yield note
  end
  notes
end

#notesArray<ELFTools::Note::Note>

Simply #notes to get all notes.

Returns:



67
68
69
# File 'lib/elftools/note.rb', line 67

def notes
  each_notes.to_a
end