示例#1
0
	def lzma_cable_extractor(self, fname):
		# Try extracting the LZMA file without modification first
		if not self.binwalk.extractor.execute(self.original_cmd, fname):
			out_name = os.path.splitext(fname)[0] + '-patched' + os.path.splitext(fname)[1]
			fp_out = open(out_name, 'wb')
			fp_in = BlockFile(fname)
			fp_in.MAX_TRAILING_SIZE = 0
			i = 0

			while i < fp_in.length:
				(data, dlen) = fp_in.read_block()
				
				if i == 0:
					out_data = data[0:5] + self.FAKE_LZMA_SIZE + data[5:]
				else:
					out_data = data
				
				fp_out.write(str2bytes(out_data))
	
				i += dlen

			fp_in.close()
			fp_out.close()

			# Overwrite the original file so that it can be cleaned up if -r was specified
			shutil.move(out_name, fname)
			self.binwalk.extractor.execute(self.original_cmd, fname)