Class: Rex::ImageSource::Disk
- Inherits:
-
Rex::ImageSource
- Object
- Rex::ImageSource
- Rex::ImageSource::Disk
- Defined in:
- lib/rex/image_source/disk.rb
Constant Summary collapse
- WINDOW_SIZE =
4096
- WINDOW_OVERLAP =
64
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#file_offset ⇒ Object
Returns the value of attribute file_offset.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #close ⇒ Object
- #index(search, offset = 0) ⇒ Object
-
#initialize(_file, _offset = 0, _len = nil) ⇒ Disk
constructor
A new instance of Disk.
- #read(offset, len) ⇒ Object
- #subsource(offset, len) ⇒ Object
Constructor Details
#initialize(_file, _offset = 0, _len = nil) ⇒ Disk
Returns a new instance of Disk.
18 19 20 21 22 23 24 |
# File 'lib/rex/image_source/disk.rb', line 18 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
#file ⇒ Object
Returns the value of attribute file.
13 14 15 |
# File 'lib/rex/image_source/disk.rb', line 13 def file @file end |
#file_offset ⇒ Object
Returns the value of attribute file_offset.
13 14 15 |
# File 'lib/rex/image_source/disk.rb', line 13 def file_offset @file_offset end |
#size ⇒ Object
Returns the value of attribute size.
13 14 15 |
# File 'lib/rex/image_source/disk.rb', line 13 def size @size end |
Instance Method Details
#close ⇒ Object
55 56 57 |
# File 'lib/rex/image_source/disk.rb', line 55 def close file.close end |
#index(search, offset = 0) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rex/image_source/disk.rb', line 35 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
26 27 28 29 30 31 32 33 |
# File 'lib/rex/image_source/disk.rb', line 26 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
51 52 53 |
# File 'lib/rex/image_source/disk.rb', line 51 def subsource(offset, len) self.class.new(file, file_offset+offset, len) end |