Class: MachO::Sections::Section

Inherits:
MachOStructure show all
Defined in:
lib/macho/sections.rb

Overview

Represents a section of a segment for 32-bit architectures.

Direct Known Subclasses

Section64

Instance Method Summary collapse

Methods inherited from MachOStructure

bytesize, format, #initialize, new_from_bin

Constructor Details

This class inherits a constructor from MachO::MachOStructure

Instance Method Details

#addrInteger

Returns the memory address of the section.

Returns:

  • (Integer)

    the memory address of the section



99
# File 'lib/macho/sections.rb', line 99

field :addr, :uint32

#alignInteger

Returns the section alignment (power of 2) of the section.

Returns:

  • (Integer)

    the section alignment (power of 2) of the section



108
# File 'lib/macho/sections.rb', line 108

field :align, :uint32

#attribute?(attr_sym) ⇒ Boolean

Returns whether this section is of the given type.

Examples:

puts "pure instructions" if sect.attribute?(:S_ATTR_PURE_INSTRUCTIONS)

Parameters:

  • attr_sym (Symbol)

    a section attribute symbol

Returns:

  • (Boolean)

    whether this section is of the given type



162
163
164
# File 'lib/macho/sections.rb', line 162

def attribute?(attr_sym)
  !!(attributes & SECTION_ATTRIBUTES[attr_sym])
end

#attributesInteger

Returns the raw numeric attributes of this section.

Returns:

  • (Integer)

    the raw numeric attributes of this section



154
155
156
# File 'lib/macho/sections.rb', line 154

def attributes
  flags & SECTION_ATTRIBUTES_MASK
end

#empty?Boolean

Returns whether the section is empty (i.e, #size is 0).

Returns:

  • (Boolean)

    whether the section is empty (i.e, #size is 0)



136
137
138
# File 'lib/macho/sections.rb', line 136

def empty?
  size.zero?
end

#flag?(flag) ⇒ Boolean

Deprecated.

Use #type? or #attribute? instead.

Returns whether the flag is present in the section's #flags.

Examples:

puts "this section is regular" if sect.flag?(:S_REGULAR)

Parameters:

  • flag (Symbol)

    a section flag symbol

Returns:

  • (Boolean)

    whether the flag is present in the section's #flags



171
172
173
174
175
176
177
# File 'lib/macho/sections.rb', line 171

def flag?(flag)
  flag = SECTION_FLAGS[flag]

  return false if flag.nil?

  flags & flag == flag
end

#flagsInteger

Returns flags for type and attributes of the section.

Returns:

  • (Integer)

    flags for type and attributes of the section



117
# File 'lib/macho/sections.rb', line 117

field :flags, :uint32

#nrelocInteger

Returns the number of relocation entries.

Returns:

  • (Integer)

    the number of relocation entries



114
# File 'lib/macho/sections.rb', line 114

field :nreloc, :uint32

#offsetInteger

Returns the file offset of the section.

Returns:

  • (Integer)

    the file offset of the section



105
# File 'lib/macho/sections.rb', line 105

field :offset, :uint32

#reloffInteger

Returns the file offset of the section's relocation entries.

Returns:

  • (Integer)

    the file offset of the section's relocation entries



111
# File 'lib/macho/sections.rb', line 111

field :reloff, :uint32

#reserved1void

This method returns an undefined value.

Returns reserved (for offset or index).



120
# File 'lib/macho/sections.rb', line 120

field :reserved1, :uint32

#reserved2void

This method returns an undefined value.

Returns reserved (for count or sizeof).



123
# File 'lib/macho/sections.rb', line 123

field :reserved2, :uint32

#section_nameString

Returns the section's name.

Returns:

  • (String)

    the section's name



126
127
128
# File 'lib/macho/sections.rb', line 126

def section_name
  sectname
end

#sectnameString

Returns the name of the section, including null pad bytes.

Returns:

  • (String)

    the name of the section, including null pad bytes



92
# File 'lib/macho/sections.rb', line 92

field :sectname, :string, :padding => :null, :size => 16

#segment_nameString

Returns the parent segment's name.

Returns:

  • (String)

    the parent segment's name



131
132
133
# File 'lib/macho/sections.rb', line 131

def segment_name
  segname
end

#segnameString

Returns the name of the segment's section, including null pad bytes.

Returns:

  • (String)

    the name of the segment's section, including null pad bytes



96
# File 'lib/macho/sections.rb', line 96

field :segname, :string, :padding => :null, :size => 16

#sizeInteger

Returns the size, in bytes, of the section.

Returns:

  • (Integer)

    the size, in bytes, of the section



102
# File 'lib/macho/sections.rb', line 102

field :size, :uint32

#to_hHash

Returns a hash representation of this MachO::Sections::Section.

Returns:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/macho/sections.rb', line 180

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

#typeInteger

Returns the raw numeric type of this section.

Returns:

  • (Integer)

    the raw numeric type of this section



141
142
143
# File 'lib/macho/sections.rb', line 141

def type
  flags & SECTION_TYPE_MASK
end

#type?(type_sym) ⇒ Boolean

Returns whether this section is of the given type.

Examples:

puts "this section is regular" if sect.type?(:S_REGULAR)

Parameters:

  • type_sym (Symbol)

    a section type symbol

Returns:

  • (Boolean)

    whether this section is of the given type



149
150
151
# File 'lib/macho/sections.rb', line 149

def type?(type_sym)
  type == SECTION_TYPES[type_sym]
end