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

Constant Summary collapse

FORMAT =
"Z16Z16L=9"
SIZEOF =
68

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MachOStructure

bytesize, new_from_bin

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.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/macho/sections.rb', line 119

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

#addrInteger (readonly)

Returns the memory address of the section.

Returns:

  • (Integer)

    the memory address of the section



86
87
88
# File 'lib/macho/sections.rb', line 86

def addr
  @addr
end

#alignInteger (readonly)

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

Returns:

  • (Integer)

    the section alignment (power of 2) of the section



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

def align
  @align
end

#flagsInteger (readonly)

Returns flags for type and attributes of the section.

Returns:

  • (Integer)

    flags for type and attributes of the section



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

def flags
  @flags
end

#nrelocInteger (readonly)

Returns the number of relocation entries.

Returns:

  • (Integer)

    the number of relocation entries



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

def nreloc
  @nreloc
end

#offsetInteger (readonly)

Returns the file offset of the section.

Returns:

  • (Integer)

    the file offset of the section



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

def offset
  @offset
end

#reloffInteger (readonly)

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

Returns:

  • (Integer)

    the file offset of the section's relocation entries



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

def reloff
  @reloff
end

#reserved1void (readonly)

This method returns an undefined value.

Returns reserved (for offset or index).



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

def reserved1
  @reserved1
end

#reserved2void (readonly)

This method returns an undefined value.

Returns reserved (for count or sizeof).



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

def reserved2
  @reserved2
end

#sectnameString (readonly)

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

Returns:

  • (String)

    the name of the section, including null pad bytes



79
80
81
# File 'lib/macho/sections.rb', line 79

def sectname
  @sectname
end

#segnameString (readonly)

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



83
84
85
# File 'lib/macho/sections.rb', line 83

def segname
  @segname
end

#sizeInteger (readonly)

Returns the size, in bytes, of the section.

Returns:

  • (Integer)

    the size, in bytes, of the section



89
90
91
# File 'lib/macho/sections.rb', line 89

def size
  @size
end

Instance Method Details

#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)



146
147
148
# File 'lib/macho/sections.rb', line 146

def empty?
  size.zero?
end

#flag?(flag) ⇒ Boolean

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



154
155
156
157
158
159
160
# File 'lib/macho/sections.rb', line 154

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

  return false if flag.nil?

  flags & flag == flag
end

#section_nameString

Returns the section's name.

Returns:

  • (String)

    the section's name



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

def section_name
  sectname
end

#segment_nameString

Returns the parent segment's name.

Returns:

  • (String)

    the parent segment's name



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

def segment_name
  segname
end

#to_hHash

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

Returns:



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/macho/sections.rb', line 163

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