Sha256: a9a80761d7f0391a7acdd580a37895cd9f03275c96514daf85f3ffb0b3b5554c

Contents?: true

Size: 1.16 KB

Versions: 43

Compression:

Stored size: 1.16 KB

Contents

#!/usr/bin/env ruby

# $Id: disk.rb 5401 2008-02-09 04:35:21Z ramon $

require 'rex/image_source/image_source'
require 'rex/struct2'

module Rex
module ImageSource
class Disk < ImageSource

	attr_accessor :file, :file_offset, :size

	WINDOW_SIZE     = 4096
	WINDOW_OVERLAP  = 64

	def initialize(_file, _offset = 0, _len = nil)
		_len = _file.stat.size if !_len

		self.file         = _file
		self.file_offset  = _offset
		self.size         = _len
	end

	def read(offset, len)
		if offset < 0 || offset+len > size
			raise RangeError, "Offset #{offset} outside of image source", caller
		end

		file.seek(file_offset + offset)
		file.read(len)
	end
	
	def index(search, offset = 0)
		# do a sliding window search across the disk
		while offset < size

			# get a full window size if we can, we
			# don't want to read past our boundaries
			wsize = size - offset
			wsize = WINDOW_SIZE if wsize > WINDOW_SIZE

			window = self.read(offset, wsize)
			res = window.index(search)
			return res + offset if res
			offset += WINDOW_SIZE - WINDOW_OVERLAP
		end
	end

	def subsource(offset, len)
		self.class.new(file, file_offset+offset, len)
	end

	def close
		file.close
	end
end

end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/image_source/disk.rb
librex-0.0.63 lib/rex/image_source/disk.rb
librex-0.0.54 lib/rex/image_source/disk.rb
librex-0.0.53 lib/rex/image_source/disk.rb
librex-0.0.52 lib/rex/image_source/disk.rb
librex-0.0.51 lib/rex/image_source/disk.rb
librex-0.0.50 lib/rex/image_source/disk.rb
librex-0.0.49 lib/rex/image_source/disk.rb
librex-0.0.48 lib/rex/image_source/disk.rb
librex-0.0.47 lib/rex/image_source/disk.rb
librex-0.0.46 lib/rex/image_source/disk.rb
librex-0.0.44 lib/rex/image_source/disk.rb
librex-0.0.43 lib/rex/image_source/disk.rb
librex-0.0.42 lib/rex/image_source/disk.rb
librex-0.0.41 lib/rex/image_source/disk.rb
librex-0.0.40 lib/rex/image_source/disk.rb
librex-0.0.39 lib/rex/image_source/disk.rb
librex-0.0.38 lib/rex/image_source/disk.rb
librex-0.0.37 lib/rex/image_source/disk.rb
librex-0.0.36 lib/rex/image_source/disk.rb