32-bit Mach-O file header structure
@see MachOStructure::FORMAT @api private
@see MachOStructure::SIZEOF @api private
@return [Fixnum] the CPU subtype of the Mach-O
@return [Fixnum] the CPU type of the Mach-O
@return [Fixnum] the file type of the Mach-O
@return [Fixnum] the header flags associated with the Mach-O
@return [Fixnum] the magic number
@return [Fixnum] the number of load commands in the Mach-O
@return [Fixnum] the size of all load commands, in bytes, in the Mach-O
@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
@return [Fixnum] the file's internal alignment
# File lib/macho/headers.rb, line 639 def alignment magic32? ? 4 : 8 end
@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
@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
@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
@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
@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
@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
@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
@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
@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
@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
@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
@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
@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