class MachO::LoadCommands::LoadCommand

Mach-O load command structure This is the most generic load command - only cmd ID and size are represented, and no actual data. Used when a more specific class isn't available/implemented.

Constants

FORMAT

@see MachOStructure::FORMAT @api private

SIZEOF

@see MachOStructure::SIZEOF @api private

Attributes

cmd[R]

@return [Fixnum] the load command's identifying number

cmdsize[R]

@return [Fixnum] the size of the load command, in bytes

view[R]

@return [MachO::MachOView] the raw view associated with the load command

Public Class Methods

create(cmd_sym, *args) click to toggle source

Creates a new (viewless) command corresponding to the symbol provided @param cmd_sym [Symbol] the symbol of the load command being created @param args [Array] the arguments for the load command being created

# File lib/macho/load_commands.rb, line 204
def self.create(cmd_sym, *args)
  raise LoadCommandNotCreatableError, cmd_sym unless CREATABLE_LOAD_COMMANDS.include?(cmd_sym)

  klass = LoadCommands.const_get LC_STRUCTURES[cmd_sym]
  cmd = LOAD_COMMAND_CONSTANTS[cmd_sym]

  # cmd will be filled in, view and cmdsize will be left unpopulated
  klass_arity = klass.instance_method(:initialize).arity - 3

  raise LoadCommandCreationArityError.new(cmd_sym, klass_arity, args.size) if klass_arity != args.size

  klass.new(nil, cmd, nil, *args)
end
new(view, cmd, cmdsize) click to toggle source

@param view [MachO::MachOView] the load command's raw view @param cmd [Fixnum] the load command's identifying number @param cmdsize [Fixnum] the size of the load command in bytes @api private

# File lib/macho/load_commands.rb, line 222
def initialize(view, cmd, cmdsize)
  @view = view
  @cmd = cmd
  @cmdsize = cmdsize
end
new_from_bin(view) click to toggle source

Instantiates a new LoadCommand given a view into its origin Mach-O @param view [MachO::MachOView] the load command's raw view @return [LoadCommand] the new load command @api private

# File lib/macho/load_commands.rb, line 194
def self.new_from_bin(view)
  bin = view.raw_data.slice(view.offset, bytesize)
  format = Utils.specialize_format(self::FORMAT, view.endianness)

  new(view, *bin.unpack(format))
end

Public Instance Methods

offset() click to toggle source

@return [Fixnum] the load command's offset in the source file @deprecated use {#view} instead

# File lib/macho/load_commands.rb, line 246
def offset
  view.offset
end
serializable?() click to toggle source

@return [Boolean] whether the load command can be serialized

# File lib/macho/load_commands.rb, line 229
def serializable?
  CREATABLE_LOAD_COMMANDS.include?(LOAD_COMMANDS[cmd])
end
serialize(context) click to toggle source

@param context [SerializationContext] the context

to serialize into

@return [String, nil] the serialized fields of the load command, or nil

if the load command can't be serialized

@api private

# File lib/macho/load_commands.rb, line 238
def serialize(context)
  raise LoadCommandNotSerializableError, LOAD_COMMANDS[cmd] unless serializable?
  format = Utils.specialize_format(FORMAT, context.endianness)
  [cmd, SIZEOF].pack(format)
end
to_s() click to toggle source

@return [String] a string representation of the load command's

identifying number
# File lib/macho/load_commands.rb, line 260
def to_s
  type.to_s
end
to_sym()
Alias for: type
type() click to toggle source

@return [Symbol] a symbol representation of the load command's

identifying number
# File lib/macho/load_commands.rb, line 252
def type
  LOAD_COMMANDS[cmd]
end
Also aliased as: to_sym