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".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
-
#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.
577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/macho/headers.rb', line 577 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)
554 555 556 |
# File 'lib/macho/headers.rb', line 554 def cpusubtype @cpusubtype end |
#cputype ⇒ Integer (readonly)
551 552 553 |
# File 'lib/macho/headers.rb', line 551 def cputype @cputype end |
#filetype ⇒ Integer (readonly)
557 558 559 |
# File 'lib/macho/headers.rb', line 557 def filetype @filetype end |
#flags ⇒ Integer (readonly)
566 567 568 |
# File 'lib/macho/headers.rb', line 566 def flags @flags end |
#magic ⇒ Integer (readonly)
548 549 550 |
# File 'lib/macho/headers.rb', line 548 def magic @magic end |
#ncmds ⇒ Integer (readonly)
560 561 562 |
# File 'lib/macho/headers.rb', line 560 def ncmds @ncmds end |
#sizeofcmds ⇒ Integer (readonly)
563 564 565 |
# File 'lib/macho/headers.rb', line 563 def sizeofcmds @sizeofcmds end |
Instance Method Details
#alignment ⇒ Integer
661 662 663 |
# File 'lib/macho/headers.rb', line 661 def alignment magic32? ? 4 : 8 end |
#bundle? ⇒ Boolean
636 637 638 |
# File 'lib/macho/headers.rb', line 636 def bundle? filetype == Headers::MH_BUNDLE end |
#core? ⇒ Boolean
616 617 618 |
# File 'lib/macho/headers.rb', line 616 def core? filetype == Headers::MH_CORE end |
#dsym? ⇒ Boolean
641 642 643 |
# File 'lib/macho/headers.rb', line 641 def dsym? filetype == Headers::MH_DSYM end |
#dylib? ⇒ Boolean
626 627 628 |
# File 'lib/macho/headers.rb', line 626 def dylib? filetype == Headers::MH_DYLIB end |
#dylinker? ⇒ Boolean
631 632 633 |
# File 'lib/macho/headers.rb', line 631 def dylinker? filetype == Headers::MH_DYLINKER end |
#executable? ⇒ Boolean
606 607 608 |
# File 'lib/macho/headers.rb', line 606 def executable? filetype == Headers::MH_EXECUTE end |
#flag?(flag) ⇒ Boolean
Returns true if flag is present in the header's flag section.
594 595 596 597 598 |
# File 'lib/macho/headers.rb', line 594 def flag?(flag) flag = MH_FLAGS[flag] return false if flag.nil? flags & flag == flag end |
#fvmlib? ⇒ Boolean
611 612 613 |
# File 'lib/macho/headers.rb', line 611 def fvmlib? filetype == Headers::MH_FVMLIB end |
#kext? ⇒ Boolean
646 647 648 |
# File 'lib/macho/headers.rb', line 646 def kext? filetype == Headers::MH_KEXT_BUNDLE end |
#magic32? ⇒ Boolean
651 652 653 |
# File 'lib/macho/headers.rb', line 651 def magic32? Utils.magic32?(magic) end |
#magic64? ⇒ Boolean
656 657 658 |
# File 'lib/macho/headers.rb', line 656 def magic64? Utils.magic64?(magic) end |
#object? ⇒ Boolean
601 602 603 |
# File 'lib/macho/headers.rb', line 601 def object? filetype == Headers::MH_OBJECT end |
#preload? ⇒ Boolean
621 622 623 |
# File 'lib/macho/headers.rb', line 621 def preload? filetype == Headers::MH_PRELOAD end |
#to_h ⇒ Hash
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'lib/macho/headers.rb', line 666 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 |