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



697
698
699
# File 'lib/macho/headers.rb', line 697

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



667
668
669
# File 'lib/macho/headers.rb', line 667

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



647
648
649
# File 'lib/macho/headers.rb', line 647

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



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

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



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

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



672
673
674
# File 'lib/macho/headers.rb', line 672

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



657
658
659
# File 'lib/macho/headers.rb', line 657

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



662
663
664
# File 'lib/macho/headers.rb', line 662

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



637
638
639
# File 'lib/macho/headers.rb', line 637

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



682
683
684
# File 'lib/macho/headers.rb', line 682

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



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

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



623
624
625
626
627
628
629
# File 'lib/macho/headers.rb', line 623

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



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

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



642
643
644
# File 'lib/macho/headers.rb', line 642

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



677
678
679
# File 'lib/macho/headers.rb', line 677

def kext?
  filetype == Headers::MH_KEXT_BUNDLE
end

#magicInteger

Returns the magic number.

Returns:

  • (Integer)

    the magic number



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

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



687
688
689
# File 'lib/macho/headers.rb', line 687

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



692
693
694
# File 'lib/macho/headers.rb', line 692

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



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

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



632
633
634
# File 'lib/macho/headers.rb', line 632

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



652
653
654
# File 'lib/macho/headers.rb', line 652

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



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

field :sizeofcmds, :uint32

#to_hHash

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

Returns:



702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
# File 'lib/macho/headers.rb', line 702

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