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.



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

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.



10
11
12
# File 'lib/rex/image_source/disk.rb', line 10

def file
  @file
end

#file_offsetObject

Returns the value of attribute file_offset.



10
11
12
# File 'lib/rex/image_source/disk.rb', line 10

def file_offset
  @file_offset
end

#sizeObject

Returns the value of attribute size.



10
11
12
# File 'lib/rex/image_source/disk.rb', line 10

def size
  @size
end

Instance Method Details

#closeObject



52
53
54
# File 'lib/rex/image_source/disk.rb', line 52

def close
  file.close
end

#index(search, offset = 0) ⇒ Object



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

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



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

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



48
49
50
# File 'lib/rex/image_source/disk.rb', line 48

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