Class: MachO::Sections::Section
- Inherits:
-
MachOStructure
- Object
- MachOStructure
- MachO::Sections::Section
- Defined in:
- lib/macho/sections.rb
Overview
Represents a section of a segment for 32-bit architectures.
Direct Known Subclasses
Constant Summary collapse
- FORMAT =
"Z16Z16L=9"- SIZEOF =
68
Instance Attribute Summary collapse
-
#addr ⇒ Integer
readonly
The memory address of the section.
-
#align ⇒ Integer
readonly
The section alignment (power of 2) of the section.
-
#flags ⇒ Integer
readonly
Flags for type and attributes of the section.
-
#nreloc ⇒ Integer
readonly
The number of relocation entries.
-
#offset ⇒ Integer
readonly
The file offset of the section.
-
#reloff ⇒ Integer
readonly
The file offset of the section's relocation entries.
-
#reserved1 ⇒ void
readonly
Reserved (for offset or index).
-
#reserved2 ⇒ void
readonly
Reserved (for count or sizeof).
-
#sectname ⇒ String
readonly
The name of the section, including null pad bytes.
-
#segname ⇒ String
readonly
The name of the segment's section, including null pad bytes.
-
#size ⇒ Integer
readonly
The size, in bytes, of the section.
Instance Method Summary collapse
-
#attribute?(attr_sym) ⇒ Boolean
Whether this section is of the given type.
-
#attributes ⇒ Integer
The raw numeric attributes of this section.
-
#empty? ⇒ Boolean
Whether the section is empty (i.e, #size is 0).
-
#flag?(flag) ⇒ Boolean
deprecated
Deprecated.
Use #type? or #attribute? instead.
-
#initialize(sectname, segname, addr, size, offset, align, reloff, nreloc, flags, reserved1, reserved2) ⇒ Section
constructor
private
A new instance of Section.
-
#section_name ⇒ String
The section's name.
-
#segment_name ⇒ String
The parent segment's name.
-
#to_h ⇒ Hash
A hash representation of this Section.
-
#type ⇒ Integer
The raw numeric type of this section.
-
#type?(type_sym) ⇒ Boolean
Whether this section is of the given type.
Methods inherited from MachOStructure
Constructor Details
#initialize(sectname, segname, addr, size, offset, align, reloff, nreloc, flags, reserved1, reserved2) ⇒ Section
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Section.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/macho/sections.rb', line 132 def initialize(sectname, segname, addr, size, offset, align, reloff, nreloc, flags, reserved1, reserved2) super() @sectname = sectname @segname = segname @addr = addr @size = size @offset = offset @align = align @reloff = reloff @nreloc = nreloc @flags = flags @reserved1 = reserved1 @reserved2 = reserved2 end |
Instance Attribute Details
#addr ⇒ Integer (readonly)
Returns the memory address of the section.
99 100 101 |
# File 'lib/macho/sections.rb', line 99 def addr @addr end |
#align ⇒ Integer (readonly)
Returns the section alignment (power of 2) of the section.
108 109 110 |
# File 'lib/macho/sections.rb', line 108 def align @align end |
#flags ⇒ Integer (readonly)
Returns flags for type and attributes of the section.
117 118 119 |
# File 'lib/macho/sections.rb', line 117 def flags @flags end |
#nreloc ⇒ Integer (readonly)
Returns the number of relocation entries.
114 115 116 |
# File 'lib/macho/sections.rb', line 114 def nreloc @nreloc end |
#offset ⇒ Integer (readonly)
Returns the file offset of the section.
105 106 107 |
# File 'lib/macho/sections.rb', line 105 def offset @offset end |
#reloff ⇒ Integer (readonly)
Returns the file offset of the section's relocation entries.
111 112 113 |
# File 'lib/macho/sections.rb', line 111 def reloff @reloff end |
#reserved1 ⇒ void (readonly)
This method returns an undefined value.
Returns reserved (for offset or index).
120 121 122 |
# File 'lib/macho/sections.rb', line 120 def reserved1 @reserved1 end |
#reserved2 ⇒ void (readonly)
This method returns an undefined value.
Returns reserved (for count or sizeof).
123 124 125 |
# File 'lib/macho/sections.rb', line 123 def reserved2 @reserved2 end |
#sectname ⇒ String (readonly)
Returns the name of the section, including null pad bytes.
92 93 94 |
# File 'lib/macho/sections.rb', line 92 def sectname @sectname end |
#segname ⇒ String (readonly)
Returns the name of the segment's section, including null pad bytes.
96 97 98 |
# File 'lib/macho/sections.rb', line 96 def segname @segname end |
#size ⇒ Integer (readonly)
Returns the size, in bytes, of the section.
102 103 104 |
# File 'lib/macho/sections.rb', line 102 def size @size end |
Instance Method Details
#attribute?(attr_sym) ⇒ Boolean
Returns whether this section is of the given type.
185 186 187 |
# File 'lib/macho/sections.rb', line 185 def attribute?(attr_sym) !!(attributes & SECTION_ATTRIBUTES[attr_sym]) end |
#attributes ⇒ Integer
Returns the raw numeric attributes of this section.
177 178 179 |
# File 'lib/macho/sections.rb', line 177 def attributes flags & SECTION_ATTRIBUTES_MASK end |
#empty? ⇒ Boolean
Returns whether the section is empty (i.e, #size is 0).
159 160 161 |
# File 'lib/macho/sections.rb', line 159 def empty? size.zero? end |
#flag?(flag) ⇒ Boolean
Use #type? or #attribute? instead.
Returns whether the flag is present in the section's #flags.
194 195 196 197 198 199 200 |
# File 'lib/macho/sections.rb', line 194 def flag?(flag) flag = SECTION_FLAGS[flag] return false if flag.nil? flags & flag == flag end |
#section_name ⇒ String
Returns the section's name.
149 150 151 |
# File 'lib/macho/sections.rb', line 149 def section_name sectname end |
#segment_name ⇒ String
Returns the parent segment's name.
154 155 156 |
# File 'lib/macho/sections.rb', line 154 def segment_name segname end |
#to_h ⇒ Hash
Returns a hash representation of this MachO::Sections::Section.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/macho/sections.rb', line 203 def to_h { "sectname" => sectname, "segname" => segname, "addr" => addr, "size" => size, "offset" => offset, "align" => align, "reloff" => reloff, "nreloc" => nreloc, "flags" => flags, "reserved1" => reserved1, "reserved2" => reserved2, }.merge super end |
#type ⇒ Integer
Returns the raw numeric type of this section.
164 165 166 |
# File 'lib/macho/sections.rb', line 164 def type flags & SECTION_TYPE_MASK end |
#type?(type_sym) ⇒ Boolean
Returns whether this section is of the given type.
172 173 174 |
# File 'lib/macho/sections.rb', line 172 def type?(type_sym) type == SECTION_TYPES[type_sym] end |