Class: Pliney::MachO::CommonMachHeaderReader
- Inherits:
-
Reader
- Object
- Reader
- Pliney::MachO::CommonMachHeaderReader
show all
- Defined in:
- lib/pliney/macho.rb
Instance Attribute Summary collapse
Attributes inherited from Reader
#fh, #startpos
Instance Method Summary
collapse
Methods inherited from Reader
#initialize, parse, #rewind
Instance Attribute Details
#cpusubtype ⇒ Object
Returns the value of attribute cpusubtype.
210
211
212
|
# File 'lib/pliney/macho.rb', line 210
def cpusubtype
@cpusubtype
end
|
#cputype ⇒ Object
Returns the value of attribute cputype.
210
211
212
|
# File 'lib/pliney/macho.rb', line 210
def cputype
@cputype
end
|
#filetype ⇒ Object
Returns the value of attribute filetype.
210
211
212
|
# File 'lib/pliney/macho.rb', line 210
def filetype
@filetype
end
|
#flags ⇒ Object
Returns the value of attribute flags.
210
211
212
|
# File 'lib/pliney/macho.rb', line 210
def flags
@flags
end
|
#load_commands ⇒ Object
Returns the value of attribute load_commands.
212
213
214
|
# File 'lib/pliney/macho.rb', line 212
def load_commands
@load_commands
end
|
#magic ⇒ Object
Returns the value of attribute magic.
210
211
212
|
# File 'lib/pliney/macho.rb', line 210
def magic
@magic
end
|
#ncmds ⇒ Object
Returns the value of attribute ncmds.
210
211
212
|
# File 'lib/pliney/macho.rb', line 210
def ncmds
@ncmds
end
|
#sizeofcmds ⇒ Object
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
|
#codesignature ⇒ Object
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_data ⇒ Object
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_info ⇒ Object
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
265
266
267
|
# File 'lib/pliney/macho.rb', line 265
def is_32?()
return (@magic == MACHO_MAGIC32)
end
|
#is_64? ⇒ Boolean
269
270
271
|
# File 'lib/pliney/macho.rb', line 269
def is_64?()
return (@magic == MACHO_MAGIC64)
end
|
#is_encrypted? ⇒ 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_libraries ⇒ Object
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
|
#parse ⇒ Object
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
|
#rpaths ⇒ Object
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_commands ⇒ Object
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
|