Class: Pliney::MachO::CommonMachHeaderReader

Inherits:
Reader
  • Object
show all
Defined in:
lib/pliney/macho.rb

Direct Known Subclasses

MachHeader64Reader, MachHeaderReader

Instance Attribute Summary collapse

Attributes inherited from Reader

#fh, #startpos

Instance Method Summary collapse

Methods inherited from Reader

#initialize, parse, #rewind

Constructor Details

This class inherits a constructor from Pliney::MachO::Reader

Instance Attribute Details

#cpusubtypeObject (readonly)

Returns the value of attribute cpusubtype.



210
211
212
# File 'lib/pliney/macho.rb', line 210

def cpusubtype
  @cpusubtype
end

#cputypeObject (readonly)

Returns the value of attribute cputype.



210
211
212
# File 'lib/pliney/macho.rb', line 210

def cputype
  @cputype
end

#filetypeObject (readonly)

Returns the value of attribute filetype.



210
211
212
# File 'lib/pliney/macho.rb', line 210

def filetype
  @filetype
end

#flagsObject (readonly)

Returns the value of attribute flags.



210
211
212
# File 'lib/pliney/macho.rb', line 210

def flags
  @flags
end

#load_commandsObject (readonly)

Returns the value of attribute load_commands.



212
213
214
# File 'lib/pliney/macho.rb', line 212

def load_commands
  @load_commands
end

#magicObject (readonly)

Returns the value of attribute magic.



210
211
212
# File 'lib/pliney/macho.rb', line 210

def magic
  @magic
end

#ncmdsObject (readonly)

Returns the value of attribute ncmds.



210
211
212
# File 'lib/pliney/macho.rb', line 210

def ncmds
  @ncmds
end

#sizeofcmdsObject (readonly)

Returns the value of attribute sizeofcmds.



210
211
212
# File 'lib/pliney/macho.rb', line 210

def sizeofcmds
  @sizeofcmds
end

Instance Method Details

#all_load_commands_of_type(val) ⇒ Object



228
229
230
231
232
# File 'lib/pliney/macho.rb', line 228

def all_load_commands_of_type(val)
    v = _normalize_lc_lookup_type(val)
    return [] if v.nil?
    load_commands.select{|x| x.cmd == v }
end

#codesignatureObject



259
260
261
262
263
# File 'lib/pliney/macho.rb', line 259

def codesignature()
    cs = codesignature_data
    return nil if cs.nil?
    return AppleCodeSignature::parse(cs)
end

#codesignature_dataObject



253
254
255
256
257
# File 'lib/pliney/macho.rb', line 253

def codesignature_data()
    lc = find_load_command_of_type(:LC_CODE_SIGNATURE)
    return nil if lc.nil?
    read_at(lc.dataoff, lc.datasize)
end

#encryption_infoObject



273
274
275
276
# File 'lib/pliney/macho.rb', line 273

def encryption_info
    ectyp = (is_64?)? :LC_ENCRYPTION_INFO_64 : :LC_ENCRYPTION_INFO
    return find_load_command_of_type(ectyp)
end

#find_load_command_of_type(val) ⇒ Object



234
235
236
237
238
# File 'lib/pliney/macho.rb', line 234

def find_load_command_of_type(val)
    v = _normalize_lc_lookup_type(val)
    return nil if v.nil?
    load_commands.find{|x| x.cmd == v }
end

#is_32?Boolean

Returns:

  • (Boolean)


265
266
267
# File 'lib/pliney/macho.rb', line 265

def is_32?()
    return (@magic == MACHO_MAGIC32)
end

#is_64?Boolean

Returns:

  • (Boolean)


269
270
271
# File 'lib/pliney/macho.rb', line 269

def is_64?()
    return (@magic == MACHO_MAGIC64)
end

#is_encrypted?Boolean

Returns:

  • (Boolean)


278
279
280
281
# File 'lib/pliney/macho.rb', line 278

def is_encrypted?
    ec = encryption_info
    return (ec and ec.cryptid != 0)
end

#loaded_librariesObject



240
241
242
# File 'lib/pliney/macho.rb', line 240

def loaded_libraries()
    all_load_commands_of_type(:LC_LOAD_DYLIB).map {|lc| lc.dylib_name }
end

#parseObject



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/pliney/macho.rb', line 214

def parse()
    super()
    @magic = @fh.read_uint32
    unless MachO::is_macho_magic(@magic)
        raise(ReaderError, "Unrecognized magic value for mach header: 0x%0.8x" % @magic)
    end
    @cputype = @fh.read_uint32le
    @cpusubtype = @fh.read_uint32le
    @filetype = @fh.read_uint32le
    @ncmds = @fh.read_uint32le
    @sizeofcmds = @fh.read_uint32le
    @flags = @fh.read_uint32le
end

#read_at(offset, size) ⇒ Object



248
249
250
251
# File 'lib/pliney/macho.rb', line 248

def read_at(offset, size)
    @fh.pos = @startpos + offset
    return @fh.read(size)
end

#rpathsObject



244
245
246
# File 'lib/pliney/macho.rb', line 244

def rpaths()
    all_load_commands_of_type(:LC_RPATH).map{|lc| lc.rpath}.uniq
end

#segment_load_commandsObject



283
284
285
286
# File 'lib/pliney/macho.rb', line 283

def segment_load_commands()
    segtyp = (is_64?)? :LC_SEGMENT_64 : :LC_SEGMENT
    return all_load_commands_of_type(segtyp)
end