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.

Constants

FORMAT

@see MachOStructure::FORMAT @api private

SIZEOF

@see MachOStructure::SIZEOF @api private

Attributes

fileoff[R]

@return [Fixnum] the file offset of the segment

filesize[R]

@return [Fixnum] the amount to map from the file

flags[R]

@return [Fixnum] any flags associated with the segment

initprot[R]

@return [Fixnum] the initial VM protection

maxprot[R]

@return [Fixnum] the maximum VM protection

nsects[R]

@return [Fixnum] the number of sections in the segment

segname[R]

@return [String] the name of the segment

vmaddr[R]

@return [Fixnum] the memory address of the segment

vmsize[R]

@return [Fixnum] the memory size of the segment

Public Class Methods

new(view, cmd, cmdsize, segname, vmaddr, vmsize, fileoff, filesize, maxprot, initprot, nsects, flags) click to toggle source

@api private

Calls superclass method MachO::LoadCommands::LoadCommand.new
# File lib/macho/load_commands.rb, line 404
def initialize(view, cmd, cmdsize, segname, vmaddr, vmsize, fileoff,
               filesize, maxprot, initprot, nsects, flags)
  super(view, cmd, cmdsize)
  @segname = segname.delete("\x00")
  @vmaddr = vmaddr
  @vmsize = vmsize
  @fileoff = fileoff
  @filesize = filesize
  @maxprot = maxprot
  @initprot = initprot
  @nsects = nsects
  @flags = flags
end

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 442
def flag?(flag)
  flag = SEGMENT_FLAGS[flag]
  return false if flag.nil?
  flags & flag == flag
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 421
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