class Rex::ImageSource::Disk
Constants
- WINDOW_OVERLAP
- WINDOW_SIZE
Attributes
file[RW]
file_offset[RW]
size[RW]
Public Class Methods
new(_file, _offset = 0, _len = nil)
click to toggle source
# File lib/rex/image_source/disk.rb, line 14 def initialize(_file, _offset = 0, _len = nil) _len = _file.stat.size if !_len self.file = _file self.file_offset = _offset self.size = _len end
Public Instance Methods
close()
click to toggle source
# File lib/rex/image_source/disk.rb, line 51 def close file.close end
index(search, offset = 0)
click to toggle source
# File lib/rex/image_source/disk.rb, line 31 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)
click to toggle source
# File lib/rex/image_source/disk.rb, line 22 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)
click to toggle source
# File lib/rex/image_source/disk.rb, line 47 def subsource(offset, len) self.class.new(file, file_offset+offset, len) end