Class: Rex::ImageSource::Disk

Inherits:
Rex::ImageSource show all
Defined in:
lib/rex/image_source/disk.rb

Constant Summary collapse

WINDOW_SIZE =
4096
WINDOW_OVERLAP =
64

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_file, _offset = 0, _len = nil) ⇒ Disk

Returns a new instance of Disk.



17
18
19
20
21
22
23
# File 'lib/rex/image_source/disk.rb', line 17

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

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

Instance Attribute Details

#fileObject

Returns the value of attribute file.



12
13
14
# File 'lib/rex/image_source/disk.rb', line 12

def file
  @file
end

#file_offsetObject

Returns the value of attribute file_offset.



12
13
14
# File 'lib/rex/image_source/disk.rb', line 12

def file_offset
  @file_offset
end

#sizeObject

Returns the value of attribute size.



12
13
14
# File 'lib/rex/image_source/disk.rb', line 12

def size
  @size
end

Instance Method Details

#closeObject



54
55
56
# File 'lib/rex/image_source/disk.rb', line 54

def close
	file.close
end

#index(search, offset = 0) ⇒ Object



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

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

#read(offset, len) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/rex/image_source/disk.rb', line 25

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

#subsource(offset, len) ⇒ Object



50
51
52
# File 'lib/rex/image_source/disk.rb', line 50

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