Class: MachO::LoadCommands::SegmentCommand
- Inherits:
-
LoadCommand
- Object
- MachOStructure
- LoadCommand
- MachO::LoadCommands::SegmentCommand
- Defined in:
- lib/macho/load_commands.rb
Overview
A load command indicating that part of this file is to be mapped into the task's address space. Corresponds to LC_SEGMENT.
Direct Known Subclasses
Instance Method Summary collapse
-
#fileoff ⇒ Integer
The file offset of the segment.
-
#filesize ⇒ Integer
The amount to map from the file.
-
#flag?(flag) ⇒ Boolean
True if
flag
is present in the segment's flag field. -
#flags ⇒ Integer
Any flags associated with the segment.
-
#guess_align ⇒ Integer
Guesses the alignment of the segment.
-
#initprot ⇒ Integer
The initial VM protection.
-
#maxprot ⇒ Integer
The maximum VM protection.
-
#nsects ⇒ Integer
The number of sections in the segment.
-
#sections ⇒ Array<MachO::Sections::Section>, Array<MachO::Sections::Section64>
All sections referenced within this segment.
-
#segname ⇒ String
The name of the segment.
-
#to_h ⇒ Hash
A hash representation of this SegmentCommand.
-
#vmaddr ⇒ Integer
The memory address of the segment.
-
#vmsize ⇒ Integer
The memory size of the segment.
Methods inherited from LoadCommand
#cmd, #cmdsize, create, new_from_bin, #offset, #serializable?, #serialize, #to_s, #type, #view
Methods inherited from MachOStructure
bytesize, format, #initialize, new_from_bin
Constructor Details
This class inherits a constructor from MachO::MachOStructure
Instance Method Details
#fileoff ⇒ Integer
Returns the file offset of the segment.
433 |
# File 'lib/macho/load_commands.rb', line 433 field :fileoff, :uint32 |
#filesize ⇒ Integer
Returns the amount to map from the file.
436 |
# File 'lib/macho/load_commands.rb', line 436 field :filesize, :uint32 |
#flag?(flag) ⇒ Boolean
Returns true if flag
is present in the segment's flag field.
474 475 476 477 478 479 480 |
# File 'lib/macho/load_commands.rb', line 474 def flag?(flag) flag = SEGMENT_FLAGS[flag] return false if flag.nil? flags & flag == flag end |
#flags ⇒ Integer
Returns any flags associated with the segment.
448 |
# File 'lib/macho/load_commands.rb', line 448 field :flags, :uint32 |
#guess_align ⇒ Integer
See guess_align
in cctools/misc/lipo.c
Guesses the alignment of the segment.
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/macho/load_commands.rb', line 485 def guess_align return Sections::MAX_SECT_ALIGN if vmaddr.zero? align = 0 segalign = 1 while (segalign & vmaddr).zero? segalign <<= 1 align += 1 end return 2 if align < 2 return Sections::MAX_SECT_ALIGN if align > Sections::MAX_SECT_ALIGN align end |
#initprot ⇒ Integer
Returns the initial VM protection.
442 |
# File 'lib/macho/load_commands.rb', line 442 field :initprot, :int32 |
#maxprot ⇒ Integer
Returns the maximum VM protection.
439 |
# File 'lib/macho/load_commands.rb', line 439 field :maxprot, :int32 |
#nsects ⇒ Integer
Returns the number of sections in the segment.
445 |
# File 'lib/macho/load_commands.rb', line 445 field :nsects, :uint32 |
#sections ⇒ Array<MachO::Sections::Section>, Array<MachO::Sections::Section64>
All sections referenced within this segment.
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/macho/load_commands.rb', line 453 def sections klass = case self when SegmentCommand64 MachO::Sections::Section64 when SegmentCommand MachO::Sections::Section end offset = view.offset + self.class.bytesize length = nsects * klass.bytesize bins = view.raw_data[offset, length] bins.unpack("a#{klass.bytesize}" * nsects).map do |bin| klass.new_from_bin(view.endianness, bin) end end |
#segname ⇒ String
Returns the name of the segment.
424 |
# File 'lib/macho/load_commands.rb', line 424 field :segname, :string, :padding => :null, :size => 16, :to_s => true |
#to_h ⇒ Hash
Returns a hash representation of this MachO::LoadCommands::SegmentCommand.
503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/macho/load_commands.rb', line 503 def to_h { "segname" => segname, "vmaddr" => vmaddr, "vmsize" => vmsize, "fileoff" => fileoff, "filesize" => filesize, "maxprot" => maxprot, "initprot" => initprot, "nsects" => nsects, "flags" => flags, "sections" => sections.map(&:to_h), }.merge super end |
#vmaddr ⇒ Integer
Returns the memory address of the segment.
427 |
# File 'lib/macho/load_commands.rb', line 427 field :vmaddr, :uint32 |
#vmsize ⇒ Integer
Returns the memory size of the segment.
430 |
# File 'lib/macho/load_commands.rb', line 430 field :vmsize, :uint32 |