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
-
#header ⇒ ELFTools::Structs::ELF32_sym, ELFTools::Structs::ELF64_sym
readonly
Section header.
-
#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.
-
#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.
26 27 28 29 30 31 32 |
# File 'lib/elftools/sections/symbol.rb', line 26 def initialize(header, stream, symstr: nil, machine: nil, version: nil) @header = header @stream = stream @symstr = symstr @machine = machine @version = version end |
Instance Attribute Details
#header ⇒ ELFTools::Structs::ELF32_sym, ELFTools::Structs::ELF64_sym (readonly)
Returns Section header.
10 11 12 |
# File 'lib/elftools/sections/symbol.rb', line 10 def header @header end |
#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.
124 125 126 |
# File 'lib/elftools/sections/symbol.rb', line 124 def bind header.st_info >> 4 end |
#bind=(bind) ⇒ Object
Sets how this symbol is linked against others with the same name.
133 134 135 |
# File 'lib/elftools/sections/symbol.rb', line 133 def bind=(bind) header.st_info = (Util.fits!(bind, 4, 'Symbol binding') << 4) | type end |
#bind_name ⇒ String
The name of #bind.
142 143 144 |
# File 'lib/elftools/sections/symbol.rb', line 142 def bind_name Constants::STB.mapping(@machine, bind) end |
#name ⇒ String
Return the symbol name.
36 37 38 |
# File 'lib/elftools/sections/symbol.rb', line 36 def name @name ||= @symstr.call.name_at(header.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.
197 198 199 |
# File 'lib/elftools/sections/symbol.rb', line 197 def section_index header.st_shndx.to_i end |
#size ⇒ Integer
How many bytes what this symbol names takes.
81 82 83 |
# File 'lib/elftools/sections/symbol.rb', line 81 def size header.st_size.to_i end |
#type ⇒ Integer
What kind of entity this symbol refers to.
The available types are listed in Constants::STT.
92 93 94 |
# File 'lib/elftools/sections/symbol.rb', line 92 def type header.st_info & 0xf end |
#type=(type) ⇒ Object
Sets what kind of entity this symbol refers to.
101 102 103 |
# File 'lib/elftools/sections/symbol.rb', line 101 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.
113 114 115 |
# File 'lib/elftools/sections/symbol.rb', line 113 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.
72 73 74 |
# File 'lib/elftools/sections/symbol.rb', line 72 def value header.st_value.to_i 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.
49 50 51 |
# File 'lib/elftools/sections/symbol.rb', line 49 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.
56 57 58 |
# File 'lib/elftools/sections/symbol.rb', line 56 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.
154 155 156 |
# File 'lib/elftools/sections/symbol.rb', line 154 def visibility header.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.
167 168 169 |
# File 'lib/elftools/sections/symbol.rb', line 167 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.
176 177 178 |
# File 'lib/elftools/sections/symbol.rb', line 176 def visibility_name Constants::STV.mapping(@machine, visibility) end |