Class: MachO::Headers::MachHeader

Inherits:
MachOStructure show all
Defined in:
lib/macho/headers.rb

Overview

32-bit Mach-O file header structure

Direct Known Subclasses

MachHeader64

Instance Method Summary collapse

Methods inherited from MachOStructure

bytesize, format, #initialize, new_from_bin

Constructor Details

This class inherits a constructor from MachO::MachOStructure

Instance Method Details

#alignmentInteger

Returns the file's internal alignment.

Returns:

  • (Integer)

    the file's internal alignment



709
710
711
# File 'lib/macho/headers.rb', line 709

def alignment
  magic32? ? 4 : 8
end

#bundle?Boolean

Returns whether or not the file is of type MH_BUNDLE.

Returns:

  • (Boolean)

    whether or not the file is of type MH_BUNDLE



679
680
681
# File 'lib/macho/headers.rb', line 679

def bundle?
  filetype == Headers::MH_BUNDLE
end

#core?Boolean

Returns whether or not the file is of type MH_CORE.

Returns:

  • (Boolean)

    whether or not the file is of type MH_CORE



659
660
661
# File 'lib/macho/headers.rb', line 659

def core?
  filetype == Headers::MH_CORE
end

#cpusubtypeInteger

Returns the CPU subtype of the Mach-O.

Returns:

  • (Integer)

    the CPU subtype of the Mach-O



617
# File 'lib/macho/headers.rb', line 617

field :cpusubtype, :uint32, :mask => CPU_SUBTYPE_MASK

#cputypeInteger

Returns the CPU type of the Mach-O.

Returns:

  • (Integer)

    the CPU type of the Mach-O



614
# File 'lib/macho/headers.rb', line 614

field :cputype, :uint32

#dsym?Boolean

Returns whether or not the file is of type MH_DSYM.

Returns:

  • (Boolean)

    whether or not the file is of type MH_DSYM



684
685
686
# File 'lib/macho/headers.rb', line 684

def dsym?
  filetype == Headers::MH_DSYM
end

#dylib?Boolean

Returns whether or not the file is of type MH_DYLIB.

Returns:

  • (Boolean)

    whether or not the file is of type MH_DYLIB



669
670
671
# File 'lib/macho/headers.rb', line 669

def dylib?
  filetype == Headers::MH_DYLIB
end

#dylinker?Boolean

Returns whether or not the file is of type MH_DYLINKER.

Returns:

  • (Boolean)

    whether or not the file is of type MH_DYLINKER



674
675
676
# File 'lib/macho/headers.rb', line 674

def dylinker?
  filetype == Headers::MH_DYLINKER
end

#executable?Boolean

Returns whether or not the file is of type MH_EXECUTE.

Returns:

  • (Boolean)

    whether or not the file is of type MH_EXECUTE



649
650
651
# File 'lib/macho/headers.rb', line 649

def executable?
  filetype == Headers::MH_EXECUTE
end

#fileset?Boolean

Returns whether or not the file is of type MH_FILESET.

Returns:

  • (Boolean)

    whether or not the file is of type MH_FILESET



694
695
696
# File 'lib/macho/headers.rb', line 694

def fileset?
  filetype == Headers::MH_FILESET
end

#filetypeInteger

Returns the file type of the Mach-O.

Returns:

  • (Integer)

    the file type of the Mach-O



620
# File 'lib/macho/headers.rb', line 620

field :filetype, :uint32

#flag?(flag) ⇒ Boolean

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

Examples:

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

Parameters:

  • flag (Symbol)

    a mach header flag symbol

Returns:

  • (Boolean)

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



635
636
637
638
639
640
641
# File 'lib/macho/headers.rb', line 635

def flag?(flag)
  flag = MH_FLAGS[flag]

  return false if flag.nil?

  flags & flag == flag
end

#flagsInteger

Returns the header flags associated with the Mach-O.

Returns:

  • (Integer)

    the header flags associated with the Mach-O



629
# File 'lib/macho/headers.rb', line 629

field :flags, :uint32

#fvmlib?Boolean

Returns whether or not the file is of type MH_FVMLIB.

Returns:

  • (Boolean)

    whether or not the file is of type MH_FVMLIB



654
655
656
# File 'lib/macho/headers.rb', line 654

def fvmlib?
  filetype == Headers::MH_FVMLIB
end

#kext?Boolean

Returns whether or not the file is of type MH_KEXT_BUNDLE.

Returns:

  • (Boolean)

    whether or not the file is of type MH_KEXT_BUNDLE



689
690
691
# File 'lib/macho/headers.rb', line 689

def kext?
  filetype == Headers::MH_KEXT_BUNDLE
end

#magicInteger

Returns the magic number.

Returns:

  • (Integer)

    the magic number



611
# File 'lib/macho/headers.rb', line 611

field :magic, :uint32

#magic32?Boolean

Returns true if the Mach-O has 32-bit magic, false otherwise.

Returns:

  • (Boolean)

    true if the Mach-O has 32-bit magic, false otherwise



699
700
701
# File 'lib/macho/headers.rb', line 699

def magic32?
  Utils.magic32?(magic)
end

#magic64?Boolean

Returns true if the Mach-O has 64-bit magic, false otherwise.

Returns:

  • (Boolean)

    true if the Mach-O has 64-bit magic, false otherwise



704
705
706
# File 'lib/macho/headers.rb', line 704

def magic64?
  Utils.magic64?(magic)
end

#ncmdsInteger

Returns the number of load commands in the Mach-O.

Returns:

  • (Integer)

    the number of load commands in the Mach-O



623
# File 'lib/macho/headers.rb', line 623

field :ncmds, :uint32

#object?Boolean

Returns whether or not the file is of type MH_OBJECT.

Returns:

  • (Boolean)

    whether or not the file is of type MH_OBJECT



644
645
646
# File 'lib/macho/headers.rb', line 644

def object?
  filetype == Headers::MH_OBJECT
end

#preload?Boolean

Returns whether or not the file is of type MH_PRELOAD.

Returns:

  • (Boolean)

    whether or not the file is of type MH_PRELOAD



664
665
666
# File 'lib/macho/headers.rb', line 664

def preload?
  filetype == Headers::MH_PRELOAD
end

#sizeofcmdsInteger

Returns the size of all load commands, in bytes, in the Mach-O.

Returns:

  • (Integer)

    the size of all load commands, in bytes, in the Mach-O



626
# File 'lib/macho/headers.rb', line 626

field :sizeofcmds, :uint32

#to_hHash

Returns a hash representation of this MachO::Headers::MachHeader.

Returns:



714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'lib/macho/headers.rb', line 714

def to_h
  {
    "magic" => magic,
    "magic_sym" => MH_MAGICS[magic],
    "cputype" => cputype,
    "cputype_sym" => CPU_TYPES[cputype],
    "cpusubtype" => cpusubtype,
    "cpusubtype_sym" => CPU_SUBTYPES[cputype][cpusubtype],
    "filetype" => filetype,
    "filetype_sym" => MH_FILETYPES[filetype],
    "ncmds" => ncmds,
    "sizeofcmds" => sizeofcmds,
    "flags" => flags,
    "alignment" => alignment,
  }.merge super
end