Class: MachO::LoadCommands::LoadCommand
- Inherits:
-
MachOStructure
- Object
- MachOStructure
- MachO::LoadCommands::LoadCommand
- Defined in:
- lib/macho/load_commands.rb
Overview
The top-level Mach-O load command structure.
This is the most generic load command -- only the type ID and size are represented. Used when a more specific class isn't available or isn't implemented.
Direct Known Subclasses
BuildVersionCommand, DyldInfoCommand, DylibCommand, DylinkerCommand, DysymtabCommand, EncryptionInfoCommand, EntryPointCommand, FvmfileCommand, FvmlibCommand, IdentCommand, LinkeditDataCommand, LinkerOptionCommand, NoteCommand, 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 ⇒ Integer
readonly
The load command's type ID.
-
#cmdsize ⇒ Integer
readonly
The size of the load command, in bytes.
-
#view ⇒ MachO::MachOView?
readonly
The raw view associated with the load command, or nil if the load command was created via LoadCommand.create.
Class Method Summary collapse
-
.create(cmd_sym, *args) ⇒ Object
Creates a new (viewless) command corresponding to the symbol provided.
-
.new_from_bin(view) ⇒ 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 ⇒ Integer
deprecated
Deprecated.
use #view instead
-
#serializable? ⇒ Boolean
Whether the load command can be serialized.
-
#serialize(context) ⇒ String?
private
The serialized fields of the load command, or nil if the load command can't be serialized.
-
#to_h ⇒ Hash
A hash representation of this load command.
-
#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 type ID, or nil if the ID doesn't correspond to a known load command class.
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.
227 228 229 230 231 |
# File 'lib/macho/load_commands.rb', line 227 def initialize(view, cmd, cmdsize) @view = view @cmd = cmd @cmdsize = cmdsize end |
Instance Attribute Details
#cmd ⇒ Integer (readonly)
Returns the load command's type ID.
182 183 184 |
# File 'lib/macho/load_commands.rb', line 182 def cmd @cmd end |
#cmdsize ⇒ Integer (readonly)
Returns the size of the load command, in bytes.
185 186 187 |
# File 'lib/macho/load_commands.rb', line 185 def cmdsize @cmdsize end |
#view ⇒ MachO::MachOView? (readonly)
Returns the raw view associated with the load command, or nil if the load command was created via create.
179 180 181 |
# File 'lib/macho/load_commands.rb', line 179 def view @view end |
Class Method Details
.create(cmd_sym, *args) ⇒ Object
Creates a new (viewless) command corresponding to the symbol provided
209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/macho/load_commands.rb', line 209 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) ⇒ 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
199 200 201 202 203 204 |
# File 'lib/macho/load_commands.rb', line 199 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 ⇒ Integer
use #view instead
Returns the load command's offset in the source file.
252 253 254 |
# File 'lib/macho/load_commands.rb', line 252 def offset view.offset end |
#serializable? ⇒ Boolean
Returns whether the load command can be serialized.
234 235 236 |
# File 'lib/macho/load_commands.rb', line 234 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.
243 244 245 246 247 248 |
# File 'lib/macho/load_commands.rb', line 243 def serialize(context) raise LoadCommandNotSerializableError, LOAD_COMMANDS[cmd] unless serializable? format = Utils.specialize_format(FORMAT, context.endianness) [cmd, SIZEOF].pack(format) end |
#to_h ⇒ Hash
Children should override this to include additional information.
Returns a hash representation of this load command.
272 273 274 275 276 277 278 279 |
# File 'lib/macho/load_commands.rb', line 272 def to_h { "view" => view.to_h, "cmd" => cmd, "cmdsize" => cmdsize, "type" => type, }.merge super end |
#to_s ⇒ String
Returns a string representation of the load command's identifying number.
266 267 268 |
# File 'lib/macho/load_commands.rb', line 266 def to_s type.to_s end |
#type ⇒ Symbol? Also known as: to_sym
Returns a symbol representation of the load command's type ID, or nil if the ID doesn't correspond to a known load command class.
258 259 260 |
# File 'lib/macho/load_commands.rb', line 258 def type LOAD_COMMANDS[cmd] end |