on-demand reading of a file
the underlying file descriptor
creates a new virtual mapping of a section of the file the file descriptor must be seekable
# 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
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
# File metasm/os/main.rb, line 304 def dup(addr = @addr_start, len = @length) self.class.new(@fd, addr, len) end
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
# File metasm/os/main.rb, line 314 def page_invalid?(addr) false end
returns the full content of the file
# File metasm/os/main.rb, line 325 def realstring @fd.pos = @addr_start @fd.read(@length) end
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