class MachO::Headers::MachHeader

32-bit Mach-O file header structure

Constants

FORMAT

@see MachOStructure::FORMAT @api private

SIZEOF

@see MachOStructure::SIZEOF @api private

Attributes

cpusubtype[R]

@return [Fixnum] the CPU subtype of the Mach-O

cputype[R]

@return [Fixnum] the CPU type of the Mach-O

filetype[R]

@return [Fixnum] the file type of the Mach-O

flags[R]

@return [Fixnum] the header flags associated with the Mach-O

magic[R]

@return [Fixnum] the magic number

ncmds[R]

@return [Fixnum] the number of load commands in the Mach-O

sizeofcmds[R]

@return [Fixnum] the size of all load commands, in bytes, in the Mach-O

Public Class Methods

new(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags) click to toggle source

@api private

# File lib/macho/headers.rb, line 555
def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds,
               flags)
  @magic = magic
  @cputype = cputype
  # For now we're not interested in additional capability bits also to be
  # found in the `cpusubtype` field. We only care about the CPU sub-type.
  @cpusubtype = cpusubtype & ~CPU_SUBTYPE_MASK
  @filetype = filetype
  @ncmds = ncmds
  @sizeofcmds = sizeofcmds
  @flags = flags
end

Public Instance Methods

alignment() click to toggle source

@return [Fixnum] the file's internal alignment

# File lib/macho/headers.rb, line 639
def alignment
  magic32? ? 4 : 8
end
bundle?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_BUNDLE`

# File lib/macho/headers.rb, line 614
def bundle?
  filetype == Headers::MH_BUNDLE
end
core?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_CORE`

# File lib/macho/headers.rb, line 594
def core?
  filetype == Headers::MH_CORE
end
dsym?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_DSYM`

# File lib/macho/headers.rb, line 619
def dsym?
  filetype == Headers::MH_DSYM
end
dylib?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_DYLIB`

# File lib/macho/headers.rb, line 604
def dylib?
  filetype == Headers::MH_DYLIB
end
dylinker?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_DYLINKER`

# File lib/macho/headers.rb, line 609
def dylinker?
  filetype == Headers::MH_DYLINKER
end
executable?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_EXECUTE`

# File lib/macho/headers.rb, line 584
def executable?
  filetype == Headers::MH_EXECUTE
end
flag?(flag) click to toggle source

@example

puts "this mach-o has position-independent execution" if header.flag?(:MH_PIE)

@param flag [Symbol] a mach header flag symbol @return [Boolean] true if `flag` is present in the header's flag section

# File lib/macho/headers.rb, line 572
def flag?(flag)
  flag = MH_FLAGS[flag]
  return false if flag.nil?
  flags & flag == flag
end
fvmlib?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_FVMLIB`

# File lib/macho/headers.rb, line 589
def fvmlib?
  filetype == Headers::MH_FVMLIB
end
kext?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_KEXT_BUNDLE`

# File lib/macho/headers.rb, line 624
def kext?
  filetype == Headers::MH_KEXT_BUNDLE
end
magic32?() click to toggle source

@return [Boolean] true if the Mach-O has 32-bit magic, false otherwise

# File lib/macho/headers.rb, line 629
def magic32?
  Utils.magic32?(magic)
end
magic64?() click to toggle source

@return [Boolean] true if the Mach-O has 64-bit magic, false otherwise

# File lib/macho/headers.rb, line 634
def magic64?
  Utils.magic64?(magic)
end
object?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_OBJECT`

# File lib/macho/headers.rb, line 579
def object?
  filetype == Headers::MH_OBJECT
end
preload?() click to toggle source

@return [Boolean] whether or not the file is of type `MH_PRELOAD`

# File lib/macho/headers.rb, line 599
def preload?
  filetype == Headers::MH_PRELOAD
end