Class: ELFTools::Sections::Symbol
- Inherits:
-
Object
- Object
- ELFTools::Sections::Symbol
- Defined in:
- lib/elftools/sections/symbol.rb
Overview
Class of symbol.
Instance Attribute Summary collapse
-
#stream ⇒ #pos=, #read
readonly
Streaming object.
Instance Method Summary collapse
-
#bind ⇒ Integer
How this symbol is linked against others with the same name.
-
#bind=(bind) ⇒ Object
Sets how this symbol is linked against others with the same name.
-
#bind_name ⇒ String
The name of #bind.
-
#header ⇒ ELFTools::Structs::ELF32_sym, ELFTools::Structs::ELF64_sym
The structure the file records this symbol in.
-
#initialize(header, stream, symstr: nil, machine: nil, version: nil) ⇒ Symbol
constructor
Instantiate a Symbol object.
-
#name ⇒ String
Return the symbol name.
-
#section_index ⇒ Integer
The index of the section this symbol is defined in.
-
#size ⇒ Integer
How many bytes what this symbol names takes.
-
#type ⇒ Integer
What kind of entity this symbol refers to.
-
#type=(type) ⇒ Object
Sets what kind of entity this symbol refers to.
-
#type_name ⇒ String
The name of #type.
-
#value ⇒ Integer
What this symbol is worth, which for most of them is the address of what they name.
-
#version ⇒ String?
The version this symbol binds to.
-
#version_hidden? ⇒ Boolean
Whether #version is one the symbol asks for by name rather than the default one of its name.
-
#visibility ⇒ Integer
How this symbol is accessed once it becomes part of an executable or shared object.
-
#visibility=(visibility) ⇒ Object
Sets how this symbol is accessed once it becomes part of an executable or shared object.
-
#visibility_name ⇒ String
The name of #visibility.
Constructor Details
#initialize(header, stream, symstr: nil, machine: nil, version: nil) ⇒ Symbol
Instantiate a ELFTools::Sections::Symbol object.
28 29 30 31 32 33 34 |
# File 'lib/elftools/sections/symbol.rb', line 28 def initialize(header, stream, symstr: nil, machine: nil, version: nil) @fields = header.is_a?(Structs::Fields) ? header : Structs::Fields.of(header) @stream = stream @symstr = symstr @machine = machine @version = version end |
Instance Attribute Details
#stream ⇒ #pos=, #read (readonly)
Returns Streaming object.
11 12 13 |
# File 'lib/elftools/sections/symbol.rb', line 11 def stream @stream end |
Instance Method Details
#bind ⇒ Integer
How this symbol is linked against others with the same name.
The available bindings are listed in Constants::STB.
136 137 138 |
# File 'lib/elftools/sections/symbol.rb', line 136 def bind @fields[:st_info] >> 4 end |
#bind=(bind) ⇒ Object
Sets how this symbol is linked against others with the same name.
145 146 147 |
# File 'lib/elftools/sections/symbol.rb', line 145 def bind=(bind) header.st_info = (Util.fits!(bind, 4, 'Symbol binding') << 4) | type end |
#bind_name ⇒ String
The name of #bind.
154 155 156 |
# File 'lib/elftools/sections/symbol.rb', line 154 def bind_name Constants::STB.mapping(@machine, bind) end |
#header ⇒ ELFTools::Structs::ELF32_sym, ELFTools::Structs::ELF64_sym
The structure the file records this symbol in.
One is built here for a symbol read without it, which is what assigning to a field of a symbol needs and what ELFFile#patches reports the changes of.
42 43 44 |
# File 'lib/elftools/sections/symbol.rb', line 42 def header @fields.struct end |
#name ⇒ String
Return the symbol name.
48 49 50 |
# File 'lib/elftools/sections/symbol.rb', line 48 def name @name ||= @symstr.call.name_at(@fields[:st_name]) end |
#section_index ⇒ Integer
The index of the section this symbol is defined in.
Values in Constants::SHN have special meanings instead of being an index.
209 210 211 |
# File 'lib/elftools/sections/symbol.rb', line 209 def section_index @fields[:st_shndx] end |
#size ⇒ Integer
How many bytes what this symbol names takes.
93 94 95 |
# File 'lib/elftools/sections/symbol.rb', line 93 def size @fields[:st_size] end |
#type ⇒ Integer
What kind of entity this symbol refers to.
The available types are listed in Constants::STT.
104 105 106 |
# File 'lib/elftools/sections/symbol.rb', line 104 def type @fields[:st_info] & 0xf end |
#type=(type) ⇒ Object
Sets what kind of entity this symbol refers to.
113 114 115 |
# File 'lib/elftools/sections/symbol.rb', line 113 def type=(type) header.st_info = (bind << 4) | Util.fits!(type, 4, 'Symbol type') end |
#type_name ⇒ String
The name of #type.
A machine names types of its own, so the name is only known when the machine of the file is.
125 126 127 |
# File 'lib/elftools/sections/symbol.rb', line 125 def type_name Constants::STT.mapping(@machine, type) end |
#value ⇒ Integer
What this symbol is worth, which for most of them is the address of what they name.
A symbol of a file that is not loaded anywhere records an offset into the section holding it instead, and one the linker is still to place, which Constants::SHN::SHN_COMMON marks, records the alignment it needs. The ABI leaves the field to the kind of symbol for that reason, and this answers with what is recorded either way.
84 85 86 |
# File 'lib/elftools/sections/symbol.rb', line 84 def value @fields[:st_value] end |
#version ⇒ String?
The version this symbol binds to.
Only the symbols a file is loaded by have one, and only where the file records the versions at all. #name is left as the file records it, without the version appended.
61 62 63 |
# File 'lib/elftools/sections/symbol.rb', line 61 def version binding_version&.name end |
#version_hidden? ⇒ Boolean
Whether #version is one the symbol asks for by name rather than the default one of its name.
68 69 70 |
# File 'lib/elftools/sections/symbol.rb', line 68 def version_hidden? binding_version&.hidden? || false end |
#visibility ⇒ Integer
How this symbol is accessed once it becomes part of an executable or shared object.
The available visibilities are listed in Constants::STV.
166 167 168 |
# File 'lib/elftools/sections/symbol.rb', line 166 def visibility @fields[:st_other] & 0x3 end |
#visibility=(visibility) ⇒ Object
Sets how this symbol is accessed once it becomes part of an executable or shared object.
The rest of st_other is left alone, which some machines record their
own thing in.
179 180 181 |
# File 'lib/elftools/sections/symbol.rb', line 179 def visibility=(visibility) header.st_other = (header.st_other.to_i & 0xfc) | Util.fits!(visibility, 2, 'Symbol visibility') end |
#visibility_name ⇒ String
The name of #visibility.
188 189 190 |
# File 'lib/elftools/sections/symbol.rb', line 188 def visibility_name Constants::STV.mapping(@machine, visibility) end |