Class: ELFTools::Structs::Fields
- Inherits:
-
Object
- Object
- ELFTools::Structs::Fields
- Defined in:
- lib/elftools/structs.rb
Overview
What a structure the file records at an offset holds, read without building the structure.
Reading a table of structures costs a structure for every entry of it otherwise, and setting up the fields of one is most of what it costs. #struct builds one for whatever wants the structure itself, which is what assigning to a field takes, and what is assigned is answered with from then on.
Instance Attribute Summary collapse
-
#elf_class ⇒ Integer
readonly
32 or 64.
-
#endian ⇒ :little, :big
readonly
The endianness the file records it in.
Class Method Summary collapse
-
.from(klass, fields, elf_class:, endian:, offset:) ⇒ ELFTools::Structs::Fields
Fields nothing in the file records, for what a file states some other way than by recording a structure of it.
-
.of(struct) ⇒ ELFTools::Structs::Fields
What a structure already built holds, for a caller that has one.
Instance Method Summary collapse
-
#[](name) ⇒ Integer
What one field of the structure records.
-
#[]=(name, value) ⇒ void
Assigns to one field.
-
#initialize(klass, stream, offset, elf_class:, endian:) ⇒ Fields
constructor
A new instance of Fields.
-
#struct ⇒ ELFTools::Structs::ELFStruct
The structure itself, read from where the file records it, or built from these fields where it records none.
Constructor Details
#initialize(klass, stream, offset, elf_class:, endian:) ⇒ Fields
Returns a new instance of Fields.
289 290 291 292 293 294 295 296 |
# File 'lib/elftools/structs.rb', line 289 def initialize(klass, stream, offset, elf_class:, endian:) @klass = klass @stream = stream @offset = offset @elf_class = elf_class @endian = endian @fields = unpack end |
Instance Attribute Details
#elf_class ⇒ Integer (readonly)
Returns 32 or 64.
256 257 258 |
# File 'lib/elftools/structs.rb', line 256 def elf_class @elf_class end |
#endian ⇒ :little, :big (readonly)
Returns The endianness the file records it in.
257 258 259 |
# File 'lib/elftools/structs.rb', line 257 def endian @endian end |
Class Method Details
.from(klass, fields, elf_class:, endian:, offset:) ⇒ ELFTools::Structs::Fields
Fields nothing in the file records, for what a file states some other way than by recording a structure of it.
There is nothing to read and nothing to patch, so a structure is only built if something asks for one, and is built from these.
279 280 281 |
# File 'lib/elftools/structs.rb', line 279 def self.from(klass, fields, elf_class:, endian:, offset:) allocate.tap { |made| made.send(:made_of, klass, fields, elf_class, endian, offset) } end |
.of(struct) ⇒ ELFTools::Structs::Fields
What a structure already built holds, for a caller that has one.
262 263 264 |
# File 'lib/elftools/structs.rb', line 262 def self.of(struct) allocate.tap { |fields| fields.send(:built_from, struct) } end |
Instance Method Details
#[](name) ⇒ Integer
What one field of the structure records.
The structure answers once there is one, so that a field assigned to reads back as it was assigned.
307 308 309 310 311 |
# File 'lib/elftools/structs.rb', line 307 def [](name) return @struct[name].to_i if @struct @fields[name] end |
#[]=(name, value) ⇒ void
This method returns an undefined value.
Assigns to one field.
The structure takes the assignment wherever the file records one, so that ELFFile#patches reports it. Fields the file records no structure of take it themselves, there being nothing to patch.
321 322 323 324 325 326 327 |
# File 'lib/elftools/structs.rb', line 321 def []=(name, value) if @struct.nil? && @stream.nil? @fields[name] = value else struct[name] = value end end |
#struct ⇒ ELFTools::Structs::ELFStruct
The structure itself, read from where the file records it, or built from these fields where it records none.
The same one however often it is asked for, so that assigning to a field of it is not forgotten.
335 336 337 |
# File 'lib/elftools/structs.rb', line 335 def struct @struct ||= @stream.nil? ? build : read end |