Class: MachO::Headers::MachHeader
- Inherits:
-
MachOStructure
- Object
- MachOStructure
- MachO::Headers::MachHeader
- Defined in:
- lib/macho/headers.rb
Overview
32-bit Mach-O file header structure
Direct Known Subclasses
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"- 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
-
#cpusubtype ⇒ Integer
readonly
The CPU subtype of the Mach-O.
-
#cputype ⇒ Integer
readonly
The CPU type of the Mach-O.
-
#filetype ⇒ Integer
readonly
The file type of the Mach-O.
-
#flags ⇒ Integer
readonly
The header flags associated with the Mach-O.
-
#magic ⇒ Integer
readonly
The magic number.
-
#ncmds ⇒ Integer
readonly
The number of load commands in the Mach-O.
-
#sizeofcmds ⇒ Integer
readonly
The size of all load commands, in bytes, in the Mach-O.
Instance Method Summary collapse
-
#alignment ⇒ Integer
The file's internal alignment.
-
#bundle? ⇒ Boolean
Whether or not the file is of type
MH_BUNDLE. -
#core? ⇒ Boolean
Whether or not the file is of type
MH_CORE. -
#dsym? ⇒ Boolean
Whether or not the file is of type
MH_DSYM. -
#dylib? ⇒ Boolean
Whether or not the file is of type
MH_DYLIB. -
#dylinker? ⇒ Boolean
Whether or not the file is of type
MH_DYLINKER. -
#executable? ⇒ Boolean
Whether or not the file is of type
MH_EXECUTE. -
#flag?(flag) ⇒ Boolean
True if
flagis present in the header's flag section. -
#fvmlib? ⇒ Boolean
Whether or not the file is of type
MH_FVMLIB. -
#initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags) ⇒ MachHeader
constructor
private
A new instance of MachHeader.
-
#kext? ⇒ Boolean
Whether or not the file is of type
MH_KEXT_BUNDLE. -
#magic32? ⇒ Boolean
True if the Mach-O has 32-bit magic, false otherwise.
-
#magic64? ⇒ Boolean
True if the Mach-O has 64-bit magic, false otherwise.
-
#object? ⇒ Boolean
Whether or not the file is of type
MH_OBJECT. -
#preload? ⇒ Boolean
Whether or not the file is of type
MH_PRELOAD. -
#to_h ⇒ Hash
A hash representation of this MachHeader.
Methods inherited from MachOStructure
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.
649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'lib/macho/headers.rb', line 649 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
#cpusubtype ⇒ Integer (readonly)
Returns the CPU subtype of the Mach-O.
626 627 628 |
# File 'lib/macho/headers.rb', line 626 def cpusubtype @cpusubtype end |
#cputype ⇒ Integer (readonly)
Returns the CPU type of the Mach-O.
623 624 625 |
# File 'lib/macho/headers.rb', line 623 def cputype @cputype end |
#filetype ⇒ Integer (readonly)
Returns the file type of the Mach-O.
629 630 631 |
# File 'lib/macho/headers.rb', line 629 def filetype @filetype end |
#flags ⇒ Integer (readonly)
Returns the header flags associated with the Mach-O.
638 639 640 |
# File 'lib/macho/headers.rb', line 638 def flags @flags end |
#magic ⇒ Integer (readonly)
Returns the magic number.
620 621 622 |
# File 'lib/macho/headers.rb', line 620 def magic @magic end |
#ncmds ⇒ Integer (readonly)
Returns the number of load commands in the Mach-O.
632 633 634 |
# File 'lib/macho/headers.rb', line 632 def ncmds @ncmds end |
#sizeofcmds ⇒ Integer (readonly)
Returns the size of all load commands, in bytes, in the Mach-O.
635 636 637 |
# File 'lib/macho/headers.rb', line 635 def sizeofcmds @sizeofcmds end |
Instance Method Details
#alignment ⇒ Integer
Returns the file's internal alignment.
735 736 737 |
# File 'lib/macho/headers.rb', line 735 def alignment magic32? ? 4 : 8 end |
#bundle? ⇒ Boolean
Returns whether or not the file is of type MH_BUNDLE.
710 711 712 |
# File 'lib/macho/headers.rb', line 710 def bundle? filetype == Headers::MH_BUNDLE end |
#core? ⇒ Boolean
Returns whether or not the file is of type MH_CORE.
690 691 692 |
# File 'lib/macho/headers.rb', line 690 def core? filetype == Headers::MH_CORE end |
#dsym? ⇒ Boolean
Returns whether or not the file is of type MH_DSYM.
715 716 717 |
# File 'lib/macho/headers.rb', line 715 def dsym? filetype == Headers::MH_DSYM end |
#dylib? ⇒ Boolean
Returns whether or not the file is of type MH_DYLIB.
700 701 702 |
# File 'lib/macho/headers.rb', line 700 def dylib? filetype == Headers::MH_DYLIB end |
#dylinker? ⇒ Boolean
Returns whether or not the file is of type MH_DYLINKER.
705 706 707 |
# File 'lib/macho/headers.rb', line 705 def dylinker? filetype == Headers::MH_DYLINKER end |
#executable? ⇒ Boolean
Returns whether or not the file is of type MH_EXECUTE.
680 681 682 |
# File 'lib/macho/headers.rb', line 680 def executable? filetype == Headers::MH_EXECUTE end |
#flag?(flag) ⇒ Boolean
Returns true if flag is present in the header's flag section.
666 667 668 669 670 671 672 |
# File 'lib/macho/headers.rb', line 666 def flag?(flag) flag = MH_FLAGS[flag] return false if flag.nil? flags & flag == flag end |
#fvmlib? ⇒ Boolean
Returns whether or not the file is of type MH_FVMLIB.
685 686 687 |
# File 'lib/macho/headers.rb', line 685 def fvmlib? filetype == Headers::MH_FVMLIB end |
#kext? ⇒ Boolean
Returns whether or not the file is of type MH_KEXT_BUNDLE.
720 721 722 |
# File 'lib/macho/headers.rb', line 720 def kext? filetype == Headers::MH_KEXT_BUNDLE end |
#magic32? ⇒ Boolean
Returns true if the Mach-O has 32-bit magic, false otherwise.
725 726 727 |
# File 'lib/macho/headers.rb', line 725 def magic32? Utils.magic32?(magic) end |
#magic64? ⇒ Boolean
Returns true if the Mach-O has 64-bit magic, false otherwise.
730 731 732 |
# File 'lib/macho/headers.rb', line 730 def magic64? Utils.magic64?(magic) end |
#object? ⇒ Boolean
Returns whether or not the file is of type MH_OBJECT.
675 676 677 |
# File 'lib/macho/headers.rb', line 675 def object? filetype == Headers::MH_OBJECT end |
#preload? ⇒ Boolean
Returns whether or not the file is of type MH_PRELOAD.
695 696 697 |
# File 'lib/macho/headers.rb', line 695 def preload? filetype == Headers::MH_PRELOAD end |
#to_h ⇒ Hash
Returns a hash representation of this MachO::Headers::MachHeader.
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/macho/headers.rb', line 740 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 |