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".freeze
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.



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

def initialize(sectname, segname, addr, size, offset, align, reloff,
               nreloc, flags, reserved1, reserved2)
  @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)



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

def addr
  @addr
end

#alignInteger (readonly)



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

def align
  @align
end

#flagsInteger (readonly)



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

def flags
  @flags
end

#nrelocInteger (readonly)



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

def nreloc
  @nreloc
end

#offsetInteger (readonly)



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

def offset
  @offset
end

#reloffInteger (readonly)



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

def reloff
  @reloff
end

#reserved1void (readonly)



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

def reserved1
  @reserved1
end

#reserved2void (readonly)



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

def reserved2
  @reserved2
end

#sectnameString (readonly)



77
78
79
# File 'lib/macho/sections.rb', line 77

def sectname
  @sectname
end

#segnameString (readonly)



81
82
83
# File 'lib/macho/sections.rb', line 81

def segname
  @segname
end

#sizeInteger (readonly)



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

def size
  @size
end

Instance Method Details

#empty?Boolean



143
144
145
# File 'lib/macho/sections.rb', line 143

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)


151
152
153
154
155
156
157
# File 'lib/macho/sections.rb', line 151

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

  return false if flag.nil?

  flags & flag == flag
end

#section_nameString



133
134
135
# File 'lib/macho/sections.rb', line 133

def section_name
  sectname
end

#segment_nameString



138
139
140
# File 'lib/macho/sections.rb', line 138

def segment_name
  segname
end

#to_hHash



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/macho/sections.rb', line 160

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