Class: MachO::LoadCommands::LoadCommand
- Inherits:
-
MachOStructure
- Object
- MachOStructure
- MachO::LoadCommands::LoadCommand
- 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.
Direct Known Subclasses
DyldInfoCommand, DylibCommand, DylinkerCommand, DysymtabCommand, EncryptionInfoCommand, EncryptionInfoCommand64, EntryPointCommand, FvmfileCommand, FvmlibCommand, IdentCommand, LinkeditDataCommand, LinkerOptionCommand, PrebindCksumCommand, PreboundDylibCommand, RoutinesCommand, RpathCommand, SegmentCommand, SourceVersionCommand, SubClientCommand, SubFrameworkCommand, SubLibraryCommand, SubUmbrellaCommand, SymsegCommand, SymtabCommand, ThreadCommand, TwolevelHintsCommand, UUIDCommand, VersionMinCommand
Defined Under Namespace
Classes: LCStr, SerializationContext
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=2".freeze
- 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.
8
Instance Attribute Summary collapse
-
#cmd ⇒ Fixnum
readonly
The load command's identifying number.
-
#cmdsize ⇒ Fixnum
readonly
The size of the load command, in bytes.
-
#view ⇒ MachO::MachOView
readonly
The raw view associated with the load command.
Class Method Summary collapse
-
.create(cmd_sym, *args) ⇒ Object
Creates a new (viewless) command corresponding to the symbol provided.
-
.new_from_bin(view) ⇒ MachO::LoadCommands::LoadCommand
private
Instantiates a new LoadCommand given a view into its origin Mach-O.
Instance Method Summary collapse
-
#initialize(view, cmd, cmdsize) ⇒ LoadCommand
constructor
private
A new instance of LoadCommand.
-
#offset ⇒ Fixnum
deprecated
Deprecated.
use #view instead
-
#serializable? ⇒ Boolean
True if the load command can be serialized, false otherwise.
-
#serialize(context) ⇒ String?
private
The serialized fields of the load command, or nil if the load command can't be serialized.
-
#to_s ⇒ String
A string representation of the load command's identifying number.
-
#type ⇒ Symbol
(also: #to_sym)
A symbol representation of the load command's identifying number.
Methods inherited from MachOStructure
Constructor Details
#initialize(view, 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.
215 216 217 218 219 |
# File 'lib/macho/load_commands.rb', line 215 def initialize(view, cmd, cmdsize) @view = view @cmd = cmd @cmdsize = cmdsize end |
Instance Attribute Details
#cmd ⇒ Fixnum (readonly)
Returns the load command's identifying number.
170 171 172 |
# File 'lib/macho/load_commands.rb', line 170 def cmd @cmd end |
#cmdsize ⇒ Fixnum (readonly)
Returns the size of the load command, in bytes.
173 174 175 |
# File 'lib/macho/load_commands.rb', line 173 def cmdsize @cmdsize end |
#view ⇒ MachO::MachOView (readonly)
Returns the raw view associated with the load command.
167 168 169 |
# File 'lib/macho/load_commands.rb', line 167 def view @view end |
Class Method Details
.create(cmd_sym, *args) ⇒ Object
Creates a new (viewless) command corresponding to the symbol provided
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/macho/load_commands.rb', line 197 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_from_bin(view) ⇒ MachO::LoadCommands::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.
Instantiates a new LoadCommand given a view into its origin Mach-O
187 188 189 190 191 192 |
# File 'lib/macho/load_commands.rb', line 187 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 |
Instance Method Details
#offset ⇒ Fixnum
use #view instead
Returns the load command's offset in the source file.
239 240 241 |
# File 'lib/macho/load_commands.rb', line 239 def offset view.offset end |
#serializable? ⇒ Boolean
Returns true if the load command can be serialized, false otherwise.
222 223 224 |
# File 'lib/macho/load_commands.rb', line 222 def serializable? CREATABLE_LOAD_COMMANDS.include?(LOAD_COMMANDS[cmd]) end |
#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, or nil if the load command can't be serialized.
231 232 233 234 235 |
# File 'lib/macho/load_commands.rb', line 231 def serialize(context) raise LoadCommandNotSerializableError, LOAD_COMMANDS[cmd] unless serializable? format = Utils.specialize_format(FORMAT, context.endianness) [cmd, SIZEOF].pack(format) end |
#to_s ⇒ String
Returns a string representation of the load command's identifying number.
251 252 253 |
# File 'lib/macho/load_commands.rb', line 251 def to_s type.to_s end |
#type ⇒ Symbol Also known as: to_sym
Returns a symbol representation of the load command's identifying number.
244 245 246 |
# File 'lib/macho/load_commands.rb', line 244 def type LOAD_COMMANDS[cmd] end |