Class: MachO::LoadCommand

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

Overview

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.

Defined Under Namespace

Classes: LCStr

Constant Summary collapse

FORMAT =
"VV"
SIZEOF =
8

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MachOStructure

bytesize

Constructor Details

#initialize(raw_data, offset, cmd, cmdsize) ⇒ LoadCommand

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 LoadCommand.

Parameters:

  • offset (Fixnum)

    the offset to initialize with

  • cmd (Fixnum)

    the load command's identifying number

  • cmdsize (Fixnum)

    the size of the load command in bytes



172
173
174
175
176
177
# File 'lib/macho/load_commands.rb', line 172

def initialize(raw_data, offset, cmd, cmdsize)
  @raw_data = raw_data
  @offset = offset
  @cmd = cmd
  @cmdsize = cmdsize
end

Instance Attribute Details

#cmdFixnum (readonly)

Returns the load command's identifying number.

Returns:

  • (Fixnum)

    the load command's identifying number



151
152
153
# File 'lib/macho/load_commands.rb', line 151

def cmd
  @cmd
end

#cmdsizeFixnum (readonly)

Returns the size of the load command, in bytes.

Returns:

  • (Fixnum)

    the size of the load command, in bytes



154
155
156
# File 'lib/macho/load_commands.rb', line 154

def cmdsize
  @cmdsize
end

#offsetFixnum (readonly)

Returns the offset in the file the command was created from.

Returns:

  • (Fixnum)

    the offset in the file the command was created from



148
149
150
# File 'lib/macho/load_commands.rb', line 148

def offset
  @offset
end

Class Method Details

.new_from_bin(raw_data, offset, bin) ⇒ MachO::LoadCommand

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.

Creates a new LoadCommand given an offset and binary string

Parameters:

  • offset (Fixnum)

    the offset to initialize with

  • bin (String)

    the binary string to initialize with

Returns:



164
165
166
# File 'lib/macho/load_commands.rb', line 164

def self.new_from_bin(raw_data, offset, bin)
  self.new(raw_data, offset, *bin.unpack(self::FORMAT))
end

Instance Method Details

#to_sString

Returns a string representation of the load command's identifying number.

Returns:

  • (String)

    a string representation of the load command's identifying number



187
188
189
# File 'lib/macho/load_commands.rb', line 187

def to_s
  type.to_s
end

#typeSymbol Also known as: to_sym

Returns a symbol representation of the load command's identifying number.

Returns:

  • (Symbol)

    a symbol representation of the load command's identifying number



180
181
182
# File 'lib/macho/load_commands.rb', line 180

def type
  LOAD_COMMANDS[cmd]
end