class Metasm::VirtualFile
on-demand reading of a file
Attributes
fd[RW]
the underlying file descriptor
Public Class Methods
new(fd, addr_start = 0, length = nil)
click to toggle source
creates a new virtual mapping of a section of the file the file descriptor must be seekable
Calls superclass method
Metasm::VirtualString.new
# File metasm/os/main.rb, line 295 def initialize(fd, addr_start = 0, length = nil) @fd = fd if not length @fd.seek(0, File::SEEK_END) length = @fd.tell - addr_start end super(addr_start, length) end
read(path, mode='rb')
click to toggle source
returns a new VirtualFile of the whole file content (defaults readonly) returns a String if the file is small (<4096o) and readonly access
# File metasm/os/main.rb, line 281 def self.read(path, mode='rb') raise 'no filename specified' if not path if sz = File.size(path) <= 4096 and (mode == 'rb' or mode == 'r') File.open(path, mode) { |fd| fd.read } else File.open(path, mode) { |fd| new fd.dup, 0, sz } end end
Public Instance Methods
dup(addr = @addr_start, len = @length)
click to toggle source
# File metasm/os/main.rb, line 304 def dup(addr = @addr_start, len = @length) self.class.new(@fd, addr, len) end
get_page(addr, len=@pagelength)
click to toggle source
reads an aligned page from the file, at file offset addr
# File metasm/os/main.rb, line 309 def get_page(addr, len=@pagelength) @fd.pos = addr @fd.read len end
page_invalid?(addr)
click to toggle source
# File metasm/os/main.rb, line 314 def page_invalid?(addr) false end
realstring()
click to toggle source
returns the full content of the file
# File metasm/os/main.rb, line 325 def realstring @fd.pos = @addr_start @fd.read(@length) end
rewrite_at(addr, data)
click to toggle source
overwrite a section of the file
# File metasm/os/main.rb, line 319 def rewrite_at(addr, data) @fd.pos = addr @fd.write data end