class Pliney::MachO::CommonMachHeaderReader
Attributes
cpusubtype[R]
cputype[R]
filetype[R]
flags[R]
load_commands[R]
magic[R]
ncmds[R]
sizeofcmds[R]
Public Instance Methods
all_load_commands_of_type(val)
click to toggle source
# 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
codesignature()
click to toggle source
# File lib/pliney/macho.rb, line 259 def codesignature() cs = codesignature_data return nil if cs.nil? return AppleCodeSignature::parse(cs) end
codesignature_data()
click to toggle source
# 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_info()
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# File lib/pliney/macho.rb, line 265 def is_32?() return (@magic == MACHO_MAGIC32) end
is_64?()
click to toggle source
# File lib/pliney/macho.rb, line 269 def is_64?() return (@magic == MACHO_MAGIC64) end
is_encrypted?()
click to toggle source
# File lib/pliney/macho.rb, line 278 def is_encrypted? ec = encryption_info return (ec and ec.cryptid != 0) end
loaded_libraries()
click to toggle source
# File lib/pliney/macho.rb, line 240 def loaded_libraries() all_load_commands_of_type(:LC_LOAD_DYLIB).map {|lc| lc.dylib_name } end
parse()
click to toggle source
Calls superclass method
Pliney::MachO::Reader::parse
# 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)
click to toggle source
# File lib/pliney/macho.rb, line 248 def read_at(offset, size) @fh.pos = @startpos + offset return @fh.read(size) end
rpaths()
click to toggle source
# File lib/pliney/macho.rb, line 244 def rpaths() all_load_commands_of_type(:LC_RPATH).map{|lc| lc.rpath}.uniq end
segment_load_commands()
click to toggle source
# 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
Private Instance Methods
_normalize_lc_lookup_type(val)
click to toggle source
# File lib/pliney/macho.rb, line 299 def _normalize_lc_lookup_type(val) if val.is_a?(Integer) return val elsif val.is_a?(Symbol) return MachO::lcmap[val] elsif val.is_a?(String) return MachO::lcmap[val.to_sym] else raise(ArgumentError, "Invalid load command lookup type: #{typ.class}") end end
_parse_load_commands()
click to toggle source
called privately by subclasses after parse()
# File lib/pliney/macho.rb, line 290 def _parse_load_commands() @load_commands = Array.new(@ncmds) do cmd = @fh.read_uint32le @fh.pos -= 4 klass = MachO.reader_for_lc(cmd) klass.parse(@fh) end end