Class: MachO::LoadCommands::DylibCommand

Inherits:
LoadCommand show all
Defined in:
lib/macho/load_commands.rb

Overview

A load command representing some aspect of shared libraries, depending on filetype. Corresponds to LC_ID_DYLIB, LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, and LC_REEXPORT_DYLIB.

Direct Known Subclasses

DylibUseCommand

Instance Method Summary collapse

Methods inherited from LoadCommand

#cmd, #cmdsize, create, new_from_bin, #offset, #serializable?, #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

#compatibility_versionInteger

Returns the library's compatibility version number.

Returns:

  • the library's compatibility version number



556
# File 'lib/macho/load_commands.rb', line 556

field :compatibility_version, :uint32

#current_versionInteger

Returns the library's current version number.

Returns:

  • the library's current version number



553
# File 'lib/macho/load_commands.rb', line 553

field :current_version, :uint32

#flag?(flag) ⇒ Boolean

Returns true if flag applies to this dylib command.

Examples:

puts "this dylib is weakly loaded" if dylib_command.flag?(:DYLIB_USE_WEAK_LINK)

Parameters:

  • a dylib use command flag symbol

Returns:

  • true if flag applies to this dylib command



562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/macho/load_commands.rb', line 562

def flag?(flag)
  case cmd
  when LOAD_COMMAND_CONSTANTS[:LC_LOAD_WEAK_DYLIB]
    flag == :DYLIB_USE_WEAK_LINK
  when LOAD_COMMAND_CONSTANTS[:LC_REEXPORT_DYLIB]
    flag == :DYLIB_USE_REEXPORT
  when LOAD_COMMAND_CONSTANTS[:LC_LOAD_UPWARD_DYLIB]
    flag == :DYLIB_USE_UPWARD
  else
    false
  end
end

#nameLCStr

Returns the library's path name as an LCStr.

Returns:

  • the library's path name as an LCStr



547
# File 'lib/macho/load_commands.rb', line 547

field :name, :lcstr, :to_s => true

#serialize(context) ⇒ String

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 the serialized fields of the load command.

Parameters:

  • the context

Returns:

  • the serialized fields of the load command

API:

  • private



579
580
581
582
583
584
585
586
587
# File 'lib/macho/load_commands.rb', line 579

def serialize(context)
  format = Utils.specialize_format(self.class.format, context.endianness)
  string_payload, string_offsets = Utils.pack_strings(self.class.bytesize,
                                                      context.alignment,
                                                      :name => name.to_s)
  cmdsize = self.class.bytesize + string_payload.bytesize
  [cmd, cmdsize, string_offsets[:name], timestamp, current_version,
   compatibility_version].pack(format) + string_payload
end

#timestampInteger

Returns the library's build time stamp.

Returns:

  • the library's build time stamp



550
# File 'lib/macho/load_commands.rb', line 550

field :timestamp, :uint32

#to_hHash

Returns a hash representation of this MachO::LoadCommands::DylibCommand.

Returns:



590
591
592
593
594
595
596
597
# File 'lib/macho/load_commands.rb', line 590

def to_h
  {
    "name" => name.to_h,
    "timestamp" => timestamp,
    "current_version" => current_version,
    "compatibility_version" => compatibility_version,
  }.merge super
end