Class: MachO::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 =
"VVVVVVV"
SIZEOF =
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.



314
315
316
317
318
319
320
321
322
323
# File 'lib/macho/headers.rb', line 314

def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds,
		flags)
	@magic = magic
	@cputype = cputype
	@cpusubtype = cpusubtype
	@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



296
297
298
# File 'lib/macho/headers.rb', line 296

def cpusubtype
  @cpusubtype
end

#cputypeFixnum (readonly)

Returns the CPU type of the Mach-O.

Returns:

  • (Fixnum)

    the CPU type of the Mach-O



293
294
295
# File 'lib/macho/headers.rb', line 293

def cputype
  @cputype
end

#filetypeFixnum (readonly)

Returns the file type of the Mach-O.

Returns:

  • (Fixnum)

    the file type of the Mach-O



299
300
301
# File 'lib/macho/headers.rb', line 299

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



308
309
310
# File 'lib/macho/headers.rb', line 308

def flags
  @flags
end

#magicFixnum (readonly)

Returns the magic number.

Returns:

  • (Fixnum)

    the magic number



290
291
292
# File 'lib/macho/headers.rb', line 290

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



302
303
304
# File 'lib/macho/headers.rb', line 302

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



305
306
307
# File 'lib/macho/headers.rb', line 305

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 (Fixnum)

    a mach header flag constant

Returns:

  • (Boolean)

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



329
330
331
# File 'lib/macho/headers.rb', line 329

def flag?(flag)
	flags & flag == flag
end