Class: MachO::LoadCommands::DylibUseCommand

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

Overview

The newer format of load command representing some aspect of shared libraries, depending on filetype. Corresponds to LC_LOAD_DYLIB or LC_LOAD_WEAK_DYLIB.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DylibCommand

#compatibility_version, #current_version, #name, #timestamp

Methods inherited from LoadCommand

#cmd, #cmdsize, create, #offset, #serializable?, #to_s, #type, #view

Methods inherited from MachOStructure

bytesize, format, #initialize

Constructor Details

This class inherits a constructor from MachO::MachOStructure

Class Method Details

.new_from_bin(view) ⇒ DylibCommand

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.

Instantiates a new DylibCommand or DylibUseCommand. macOS 15 and later use a new format for dylib commands (DylibUseCommand), which is determined based on a special timestamp and the name offset.

Parameters:

Returns:



608
609
610
611
612
613
614
615
616
617
# File 'lib/macho/load_commands.rb', line 608

def self.new_from_bin(view)
  dylib_command = DylibCommand.new_from_bin(view)

  if dylib_command.timestamp == DYLIB_USE_MARKER &&
     dylib_command.name.to_i == DylibUseCommand.bytesize
    super(view)
  else
    dylib_command
  end
end

Instance Method Details

#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:

  • flag (Symbol)

    a dylib use command flag symbol

Returns:

  • (Boolean)

    true if flag applies to this dylib command



623
624
625
626
627
628
629
# File 'lib/macho/load_commands.rb', line 623

def flag?(flag)
  flag = DYLIB_USE_FLAGS[flag]

  return false if flag.nil?

  flags & flag == flag
end

#flagsInteger

Returns any flags associated with this dylib use command.

Returns:

  • (Integer)

    any flags associated with this dylib use command



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

field :flags, :uint32

#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:

Returns:

  • (String)

    the serialized fields of the load command



635
636
637
638
639
640
641
642
643
# File 'lib/macho/load_commands.rb', line 635

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], marker, current_version,
   compatibility_version, flags].pack(format) + string_payload
end

#to_hHash

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

Returns:



646
647
648
649
650
# File 'lib/macho/load_commands.rb', line 646

def to_h
  {
    "flags" => flags,
  }.merge super
end