Class: MachO::FatFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FatFile

Returns a new instance of FatFile.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
# File 'lib/macho/fat_file.rb', line 5

def initialize(filename)
	raise ArgumentError.new("filename must be a String") unless filename.is_a? String

	@filename = filename
	@raw_data = open(@filename, "rb") { |f| f.read }
	@header = get_fat_header
	@fat_archs = get_fat_archs
	@machos = get_machos
end

Instance Attribute Details

#fat_archsObject (readonly)

Returns the value of attribute fat_archs.



3
4
5
# File 'lib/macho/fat_file.rb', line 3

def fat_archs
  @fat_archs
end

#headerObject (readonly)

Returns the value of attribute header.



3
4
5
# File 'lib/macho/fat_file.rb', line 3

def header
  @header
end

#machosObject (readonly)

Returns the value of attribute machos.



3
4
5
# File 'lib/macho/fat_file.rb', line 3

def machos
  @machos
end

Instance Method Details

#dylib_idObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/macho/fat_file.rb', line 19

def dylib_id
	if !machos.all?(&:dylib?)
		return nil
	end

	ids = machos.map(&:dylib_id)

	# this should never be the case, but let's be defensive
	if !ids.uniq!.size == 1
		return nil
	end

	ids.first
end

#dylib_id=(new_id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/macho/fat_file.rb', line 34

def dylib_id=(new_id)
	if !new_id.is_a?(String)
		raise ArgumentError.new("argument must be a String")
	end

	if !machos.all?(&:dylib?)
		return nil
	end

	machos.each do |macho|
		macho.dylib_id = new_id
	end

	synchronize_raw_data
end

#linked_dylibsObject



50
51
52
53
54
55
# File 'lib/macho/fat_file.rb', line 50

def linked_dylibs
	dylibs = machos.map(&:linked_dylibs)

	# can machos inside fat binaries have different dylibs?
	dylibs.uniq!
end

#serializeObject



15
16
17
# File 'lib/macho/fat_file.rb', line 15

def serialize
	@raw_data
end

#write(filename) ⇒ Object



57
58
59
# File 'lib/macho/fat_file.rb', line 57

def write(filename)
	File.open(filename, "wb") { |f| f.write(@raw_data) }
end

#write!Object



61
62
63
# File 'lib/macho/fat_file.rb', line 61

def write!
	File.open(@filename, "wb") { |f| f.write(@raw_data) }
end