Class: Rex::MachParsey::Fat

Inherits:
FatBase
  • Object
show all
Defined in:
lib/rex/machparsey/mach.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(isource, offset = 0) ⇒ Fat

Returns a new instance of Fat.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/rex/machparsey/mach.rb', line 108

def initialize(isource, offset = 0)
	self.fat_archs = []
	self.machos = []
	self.isource = isource
	self.fat_header = FatHeader.new(isource.read(offset, FAT_HEADER_SIZE))

	if !self.fat_header
		raise FatHeaderError, "Could not parse FAT header"
	end

	print "Detected " +  self.fat_header.nfat_arch.to_s +  " archs in binary.\n"

	offset += FAT_HEADER_SIZE

	self.fat_header.nfat_arch.times do
		fat_arch = FatArch.new(isource.read(offset, FAT_ARCH_SIZE), self.fat_header.endian)
		self.fat_archs << fat_arch
		self.machos << Mach.new(isource, fat_arch.offset, true)
		offset += FAT_ARCH_SIZE
	end


end

Instance Attribute Details

#fat_archsObject

Returns the value of attribute fat_archs.



106
107
108
# File 'lib/rex/machparsey/mach.rb', line 106

def fat_archs
  @fat_archs
end

#fat_headerObject

Returns the value of attribute fat_header.



106
107
108
# File 'lib/rex/machparsey/mach.rb', line 106

def fat_header
  @fat_header
end

#isourceObject

Returns the value of attribute isource.



106
107
108
# File 'lib/rex/machparsey/mach.rb', line 106

def isource
  @isource
end

#machosObject

Returns the value of attribute machos.



106
107
108
# File 'lib/rex/machparsey/mach.rb', line 106

def machos
  @machos
end

Class Method Details

.new_from_file(filename, disk_backed = false) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/rex/machparsey/mach.rb', line 164

def self.new_from_file(filename, disk_backed = false)

	file = ::File.open(filename, "rb")

	if disk_backed
		return self.new(ImageSource::Disk.new(file))
	else
		obj = new_from_string(file.read)
		file.close
		return obj
	end
end

.new_from_string(data) ⇒ Object



178
179
180
# File 'lib/rex/machparsey/mach.rb', line 178

def self.new_from_string(data)
	return self.new(ImageSource::Memory.new(data))
end

Instance Method Details

#_parse_fat_header(isource, offset) ⇒ Object

this is useful for debugging but we don’t use it for anything.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rex/machparsey/mach.rb', line 133

def _parse_fat_header(isource, offset)
	archs = []
	nfat_arch = self.fat_header.nfat_arch

	print "Number of archs in binary: " + nfat_arch.to_s + "\n"

	nfat_arch.times do
		arch = FatArch.new(isource.read(offset, FAT_ARCH_SIZE), self.endian)

		case arch.cpu_type

		when CPU_TYPE_I386
			print "i386\n"

		when CPU_TYPE_X86_64
			print "x86_64\n"

		when CPU_TYPE_ARM
			print "Arm\n"

		when CPU_TYPE_POWERPC
			print "Power PC\n"

		when CPU_TYPE_POWERPC64
			print "Power PC 64\n"
		end

		offset += FAT_ARCH_SIZE
	end
end

#closeObject



202
203
204
# File 'lib/rex/machparsey/mach.rb', line 202

def close
	isource.close
end

#index(*args) ⇒ Object



198
199
200
# File 'lib/rex/machparsey/mach.rb', line 198

def index(*args)
	isource.index(*args)
end

#ptr_32?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/rex/machparsey/mach.rb', line 186

def ptr_32?
	ptr_64? == false
end

#ptr_64?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/rex/machparsey/mach.rb', line 182

def ptr_64?
	mach_header.bits == BITS_64
end

#ptr_s(vaddr) ⇒ Object



190
191
192
# File 'lib/rex/machparsey/mach.rb', line 190

def ptr_s(vaddr)
	(ptr_32?) ? ("0x%.8x" % vaddr) : ("0x%.16x" % vaddr)
end

#read(offset, len) ⇒ Object



194
195
196
# File 'lib/rex/machparsey/mach.rb', line 194

def read(offset, len)
	isource.read(offset, len)
end