Class: Indis::MachO::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/indis-macho/command.rb

Constant Summary collapse

LC_REQ_DYLD =
0x80000000
CMD =
{
  0x1 => :LC_SEGMENT,
  0x2 => :LC_SYMTAB,
  0x3 => :LC_SYMSEG,
  0x4 => :LC_THREAD,
  0x5 => :LC_UNIXTHREAD,
  0x6 => :LC_LOADFVMLIB,
  0x7 => :LC_IDFVMLIB,
  0x8 => :LC_IDENT,
  0x9 => :LC_FVMFILE,
  0xa => :LC_PREPAGE,
  0xb => :LC_DYSYMTAB,
  0xc => :LC_LOAD_DYLIB,
  0xd => :LC_ID_DYLIB,
  0xe => :LC_LOAD_DYLINKER,
  0xf => :LC_ID_DYLINKER,
  0x10 => :LC_PREBOUND_DYLIB,
  0x11 => :LC_ROUTINES,
  0x12 => :LC_SUB_FRAMEWORK,
  0x13 => :LC_SUB_UMBRELLA,
  0x14 => :LC_SUB_CLIENT,
  0x15 => :LC_SUB_LIBRARY,
  0x16 => :LC_TWOLEVEL_HINTS,
  0x17 => :LC_PREBIND_CKSUM,
  
  0x18 | LC_REQ_DYLD => :LC_LOAD_WEAK_DYLIB,
  0x19 => :LC_SEGMENT_64,
  0x1a => :LC_ROUTINES_64,
  0x1b => :LC_UUID,
  0x1c | LC_REQ_DYLD => :LC_RPATH,
  0x1d => :LC_CODE_SIGNATURE,
  0x1e => :LC_SEGMENT_SPLIT_INFO,
  0x1f | LC_REQ_DYLD => :LC_REEXPORT_DYLIB,
  0x20 => :LC_LAZY_LOAD_DYLIB,
  0x21 => :LC_ENCRYPTION_INFO,
  0x22 => :LC_DYLD_INFO,
  0x22|LC_REQ_DYLD => :LC_DYLD_INFO_ONLY,
  
  0x23 | LC_REQ_DYLD => :LC_LOAD_UPWARD_DYLIB,
  0x24 => :LC_VERSION_MIN_MACOSX,
  0x25 => :LC_VERSION_MIN_IPHONEOS,
  0x26 => :LC_FUNCTION_STARTS,
  0x27 => :LC_DYLD_ENVIRONMENT,
}
CMD_CLASS =
{
  LC_SEGMENT: :SegmentCommand,
  LC_DYLD_INFO_ONLY: :DyldInfoOnlyCommand,
  LC_SYMTAB: :SymTabCommand,
  LC_DYSYMTAB: :DySymTabCommand,
  LC_LOAD_DYLINKER: :LoadDyLinkerCommand,
  LC_UUID: :UUIDCommand,
  LC_UNIXTHREAD: :ARMUnixThreadCommand,
  LC_ENCRYPTION_INFO: :EncryptionInfoCommand,
  LC_LOAD_DYLIB: :LoadDyLibCommand,
  LC_CODE_SIGNATURE: :CodeSignatureCommand,
  LC_VERSION_MIN_IPHONEOS: :VersionMinIPhoneOSCommand,
  LC_FUNCTION_STARTS: :FunctionStartsCommand,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, length, payload) ⇒ Command

Returns a new instance of Command.



92
93
94
95
96
97
98
# File 'lib/indis-macho/command.rb', line 92

def initialize(cmd, length, payload)
  @cmd = CMD[cmd]
  @length = length
  raise "Unknown mach-o command" unless @cmd
    
  process(payload)
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



90
91
92
# File 'lib/indis-macho/command.rb', line 90

def cmd
  @cmd
end

#lengthObject (readonly)

Returns the value of attribute length.



90
91
92
# File 'lib/indis-macho/command.rb', line 90

def length
  @length
end

Class Method Details

.class_of_command(c) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/indis-macho/command.rb', line 100

def self.class_of_command(c)
  cmd = CMD[c]
  raise UnknownCommandError, "Unknown mach-o command #{c.to_s(16)}" unless cmd
  clsnm = CMD_CLASS[cmd]
  raise "Unsupported mach-o command #{c.to_s(16)} (#{cmd})" unless clsnm
  cls = Indis::MachO.const_get(clsnm)
end