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 =
"a16a16L=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.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/macho/sections.rb', line 112

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

#addrFixnum (readonly)

Returns the memory address of the section.

Returns:

  • (Fixnum)

    the memory address of the section



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

def addr
  @addr
end

#alignFixnum (readonly)

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

Returns:

  • (Fixnum)

    the section alignment (power of 2) of the section



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

def align
  @align
end

#flagsFixnum (readonly)

Returns flags for type and attributes of the section.

Returns:

  • (Fixnum)

    flags for type and attributes of the section



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

def flags
  @flags
end

#nrelocFixnum (readonly)

Returns the number of relocation entries.

Returns:

  • (Fixnum)

    the number of relocation entries



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

def nreloc
  @nreloc
end

#offsetFixnum (readonly)

Returns the file offset of the section.

Returns:

  • (Fixnum)

    the file offset of the section



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

def offset
  @offset
end

#reloffFixnum (readonly)

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

Returns:

  • (Fixnum)

    the file offset of the section's relocation entries



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

def reloff
  @reloff
end

#reserved1void (readonly)

This method returns an undefined value.

Returns reserved (for offset or index).



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

def reserved1
  @reserved1
end

#reserved2void (readonly)

This method returns an undefined value.

Returns reserved (for count or sizeof).



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

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



73
74
75
# File 'lib/macho/sections.rb', line 73

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



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

def segname
  @segname
end

#sizeFixnum (readonly)

Returns the size, in bytes, of the section.

Returns:

  • (Fixnum)

    the size, in bytes, of the section



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

def size
  @size
end

Instance Method Details

#empty?Boolean

Returns true if the section has no contents (i.e, size is 0).

Returns:

  • (Boolean)

    true if the section has no contents (i.e, size is 0)



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

def empty?
  size.zero?
end

#flag?(flag) ⇒ Boolean

Returns true if flag is present in the section's flag field.

Examples:

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

Parameters:

  • flag (Symbol)

    a section flag symbol

Returns:

  • (Boolean)

    true if flag is present in the section's flag field



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

def flag?(flag)
  flag = SECTION_FLAGS[flag]
  return false if flag.nil?
  flags & flag == flag
end

#section_nameString

Returns the section's name, with any trailing NULL characters removed.

Returns:

  • (String)

    the section's name, with any trailing NULL characters removed



128
129
130
# File 'lib/macho/sections.rb', line 128

def section_name
  sectname.delete("\x00")
end

#segment_nameString

Returns the parent segment's name, with any trailing NULL characters removed.

Returns:

  • (String)

    the parent segment's name, with any trailing NULL characters removed



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

def segment_name
  segname.delete("\x00")
end