class MachO::LoadCommands::SegmentCommand
A load command indicating that part of this file is to be mapped into the task’s address space. Corresponds to LC_SEGMENT.
Public Instance Methods
flag?(flag)
click to toggle source
@example
puts "this segment relocated in/to it" if sect.flag?(:SG_NORELOC)
@param flag [Symbol] a segment flag symbol @return [Boolean] true if ‘flag` is present in the segment’s flag field
# File lib/macho/load_commands.rb, line 474 def flag?(flag) flag = SEGMENT_FLAGS[flag] return false if flag.nil? flags & flag == flag end
guess_align()
click to toggle source
Guesses the alignment of the segment. @return [Integer] the guessed alignment, as a power of 2 @note See ‘guess_align` in `cctools/misc/lipo.c`
# File lib/macho/load_commands.rb, line 485 def guess_align return Sections::MAX_SECT_ALIGN if vmaddr.zero? align = 0 segalign = 1 while (segalign & vmaddr).zero? segalign <<= 1 align += 1 end return 2 if align < 2 return Sections::MAX_SECT_ALIGN if align > Sections::MAX_SECT_ALIGN align end
sections()
click to toggle source
All sections referenced within this segment. @return [Array<MachO::Sections::Section>] if the Mach-O is 32-bit @return [Array<MachO::Sections::Section64>] if the Mach-O is 64-bit
# File lib/macho/load_commands.rb, line 453 def sections klass = case self when SegmentCommand64 MachO::Sections::Section64 when SegmentCommand MachO::Sections::Section end offset = view.offset + self.class.bytesize length = nsects * klass.bytesize bins = view.raw_data[offset, length] bins.unpack("a#{klass.bytesize}" * nsects).map do |bin| klass.new_from_bin(view.endianness, bin) end end
to_h()
click to toggle source
@return [Hash] a hash representation of this {SegmentCommand}
Calls superclass method
MachO::LoadCommands::LoadCommand#to_h
# File lib/macho/load_commands.rb, line 503 def to_h { "segname" => segname, "vmaddr" => vmaddr, "vmsize" => vmsize, "fileoff" => fileoff, "filesize" => filesize, "maxprot" => maxprot, "initprot" => initprot, "nsects" => nsects, "flags" => flags, "sections" => sections.map(&:to_h), }.merge super end