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

Constant Summary collapse

FORMAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"L=7".freeze
SIZEOF =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

28

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MachOStructure

bytesize, new_from_bin

Constructor Details

#initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags) ⇒ MachHeader

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MachHeader.



545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/macho/headers.rb', line 545

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

Instance Attribute Details

#cpusubtypeFixnum (readonly)

Returns the CPU subtype of the Mach-O.

Returns:

  • (Fixnum)

    the CPU subtype of the Mach-O



522
523
524
# File 'lib/macho/headers.rb', line 522

def cpusubtype
  @cpusubtype
end

#cputypeFixnum (readonly)

Returns the CPU type of the Mach-O.

Returns:

  • (Fixnum)

    the CPU type of the Mach-O



519
520
521
# File 'lib/macho/headers.rb', line 519

def cputype
  @cputype
end

#filetypeFixnum (readonly)

Returns the file type of the Mach-O.

Returns:

  • (Fixnum)

    the file type of the Mach-O



525
526
527
# File 'lib/macho/headers.rb', line 525

def filetype
  @filetype
end

#flagsFixnum (readonly)

Returns the header flags associated with the Mach-O.

Returns:

  • (Fixnum)

    the header flags associated with the Mach-O



534
535
536
# File 'lib/macho/headers.rb', line 534

def flags
  @flags
end

#magicFixnum (readonly)

Returns the magic number.

Returns:

  • (Fixnum)

    the magic number



516
517
518
# File 'lib/macho/headers.rb', line 516

def magic
  @magic
end

#ncmdsFixnum (readonly)

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

Returns:

  • (Fixnum)

    the number of load commands in the Mach-O



528
529
530
# File 'lib/macho/headers.rb', line 528

def ncmds
  @ncmds
end

#sizeofcmdsFixnum (readonly)

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

Returns:

  • (Fixnum)

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



531
532
533
# File 'lib/macho/headers.rb', line 531

def sizeofcmds
  @sizeofcmds
end

Instance Method Details

#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



562
563
564
565
566
# File 'lib/macho/headers.rb', line 562

def flag?(flag)
  flag = MH_FLAGS[flag]
  return false if flag.nil?
  flags & flag == flag
end