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
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=2Z16L=4l=2L=2"
- 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.
56
Instance Attribute Summary collapse
-
#fileoff ⇒ Integer
readonly
The file offset of the segment.
-
#filesize ⇒ Integer
readonly
The amount to map from the file.
-
#flags ⇒ Integer
readonly
Any flags associated with the segment.
-
#initprot ⇒ Integer
readonly
The initial VM protection.
-
#maxprot ⇒ Integer
readonly
The maximum VM protection.
-
#nsects ⇒ Integer
readonly
The number of sections in the segment.
-
#segname ⇒ String
readonly
The name of the segment.
-
#vmaddr ⇒ Integer
readonly
The memory address of the segment.
-
#vmsize ⇒ Integer
readonly
The memory size of the segment.
Attributes inherited from LoadCommand
Instance Method Summary collapse
-
#flag?(flag) ⇒ Boolean
True if
flag
is present in the segment's flag field. -
#guess_align ⇒ Integer
Guesses the alignment of the segment.
-
#initialize(view, cmd, cmdsize, segname, vmaddr, vmsize, fileoff, filesize, maxprot, initprot, nsects, flags) ⇒ SegmentCommand
constructor
private
A new instance of SegmentCommand.
-
#sections ⇒ Array<MachO::Sections::Section>, Array<MachO::Sections::Section64>
All sections referenced within this segment.
-
#to_h ⇒ Hash
A hash representation of this SegmentCommand.
Methods inherited from LoadCommand
create, new_from_bin, #offset, #serializable?, #serialize, #to_s, #type
Methods inherited from MachOStructure
Constructor Details
#initialize(view, cmd, cmdsize, segname, vmaddr, vmsize, fileoff, filesize, maxprot, initprot, nsects, flags) ⇒ SegmentCommand
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 SegmentCommand.
446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/macho/load_commands.rb', line 446 def initialize(view, cmd, cmdsize, segname, vmaddr, vmsize, fileoff, filesize, maxprot, initprot, nsects, flags) super(view, cmd, cmdsize) @segname = segname @vmaddr = vmaddr @vmsize = vmsize @fileoff = fileoff @filesize = filesize @maxprot = maxprot @initprot = initprot @nsects = nsects @flags = flags end |
Instance Attribute Details
#fileoff ⇒ Integer (readonly)
Returns the file offset of the segment.
420 421 422 |
# File 'lib/macho/load_commands.rb', line 420 def fileoff @fileoff end |
#filesize ⇒ Integer (readonly)
Returns the amount to map from the file.
423 424 425 |
# File 'lib/macho/load_commands.rb', line 423 def filesize @filesize end |
#flags ⇒ Integer (readonly)
Returns any flags associated with the segment.
435 436 437 |
# File 'lib/macho/load_commands.rb', line 435 def flags @flags end |
#initprot ⇒ Integer (readonly)
Returns the initial VM protection.
429 430 431 |
# File 'lib/macho/load_commands.rb', line 429 def initprot @initprot end |
#maxprot ⇒ Integer (readonly)
Returns the maximum VM protection.
426 427 428 |
# File 'lib/macho/load_commands.rb', line 426 def maxprot @maxprot end |
#nsects ⇒ Integer (readonly)
Returns the number of sections in the segment.
432 433 434 |
# File 'lib/macho/load_commands.rb', line 432 def nsects @nsects end |
#segname ⇒ String (readonly)
Returns the name of the segment.
411 412 413 |
# File 'lib/macho/load_commands.rb', line 411 def segname @segname end |
#vmaddr ⇒ Integer (readonly)
Returns the memory address of the segment.
414 415 416 |
# File 'lib/macho/load_commands.rb', line 414 def vmaddr @vmaddr end |
#vmsize ⇒ Integer (readonly)
Returns the memory size of the segment.
417 418 419 |
# File 'lib/macho/load_commands.rb', line 417 def vmsize @vmsize end |
Instance Method Details
#flag?(flag) ⇒ Boolean
Returns true if flag
is present in the segment's flag field.
484 485 486 487 488 489 490 |
# File 'lib/macho/load_commands.rb', line 484 def flag?(flag) flag = SEGMENT_FLAGS[flag] return false if flag.nil? flags & flag == flag end |
#guess_align ⇒ Integer
See guess_align
in cctools/misc/lipo.c
Guesses the alignment of the segment.
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/macho/load_commands.rb', line 495 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 |
#sections ⇒ Array<MachO::Sections::Section>, Array<MachO::Sections::Section64>
All sections referenced within this segment.
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/macho/load_commands.rb', line 463 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 |
#to_h ⇒ Hash
Returns a hash representation of this MachO::LoadCommands::SegmentCommand.
513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/macho/load_commands.rb', line 513 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 |