module ELFTools::Note
Since both note sections and note segments refer to notes, this module defines common methods for {ELFTools::Sections::NoteSection} and {ELFTools::Segments::NoteSegment}.
@note
This module can only be included in {ELFTools::Sections::NoteSection} and {ELFTools::Segments::NoteSegment} since some methods here assume some attributes already exist.
Constants
- SIZE_OF_NHDR
Since size of {ELFTools::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.
Public Instance Methods
each_notes() { |note| ... }
click to toggle source
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 | +---------------+ | ... | +---------------+
@note
This method assume following methods exist: stream note_start note_total_size
@return [Enumerator<ELFTools::Note::Note>, Array<ELFTools::Note::Note>]
If block is not given, an enumerator will be returned. Otherwise, return the array of notes.
# 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
notes()
click to toggle source
Simply #notes
to get all notes. @return [Array<ELFTools::Note::Note>]
Whole notes.
# File lib/elftools/note.rb, line 67 def notes each_notes.to_a end
Private Instance Methods
create_note(cur)
click to toggle source
# File lib/elftools/note.rb, line 81 def create_note(cur) nhdr = Structs::ELF_Nhdr.new(endian: endian, offset: stream.pos).read(stream) ELFTools::Note::Note.new(nhdr, stream, cur) end
endian()
click to toggle source
Get the endian.
@note This method assume method header
exists. @return [Symbol] :little
or :big
.
# File lib/elftools/note.rb, line 77 def endian header.class.self_endian end