Skip to content

Commit

Permalink
Incorporated feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chessbyte committed Feb 28, 2020
1 parent 82cc7f9 commit 3d37db2
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/disk/modules/VMWareSparseDisk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'zlib'

module VMWareSparseDisk
SPARSE_MAGIC_NUMBER = 0x564d444b # 'V' 'M' 'D' 'K'
SPARSE_MAGIC_NUMBER = "VMDK".unpack1("L>") # 0x564d444b

SPARSE_EXTENT_HEADER = BinaryStruct.new([
# the magic number is used to verify the validity of each sparse extent when the extent is opened
Expand All @@ -15,8 +15,8 @@ module VMWareSparseDisk

# SparseExtentHeader is stored on disk in little-endian byte order, so if you examine the first eight bytes of a VMDK file,
# you see either:
# 'K' D' 'M' 'V' 0x01 0x00 0x00 0x00
# 'K' D' 'M' 'V' 0x02 0x00 0x00 0x00
# 'K' 'D' 'M' 'V' 0x01 0x00 0x00 0x00
# 'K' 'D' 'M' 'V' 0x02 0x00 0x00 0x00

# flags contains the following bits of information.
'L', 'flags', # bit 0: valid new line detection test
Expand Down Expand Up @@ -202,7 +202,7 @@ def initialize_without_markers
buf = @vmwareSparseDisk_file.read(BYTES_PER_SECTOR)
@grainDirectory = []

(0..(GDES_PER_GD - 1)).each do |index|
GDES_PER_GD.times do |index|
@grainDirectory[index] = buf[index, GDE_SIZE].unpack1('L')
end

Expand Down Expand Up @@ -263,11 +263,7 @@ def allocGrain(gn)
end

def parseGrainTable(buffer)
gt = []
(0..(GTES_PER_GT - 1)).each do |index|
gt[index] = buffer[index, GTE_SIZE].unpack1('L')
end
gt
GTES_PER_GT.times.map { |index| buffer[index, GTE_SIZE].unpack1('L') }
end

def readGrainTable(gde)
Expand Down Expand Up @@ -303,8 +299,8 @@ def findFreeSector
def read_compressed_grain(grain_offset)
@vmwareSparseDisk_file.seek(grain_offset, IO::SEEK_SET)
buffer = @vmwareSparseDisk_file.read(SIZEOF_SPARSE_EXTENT_COMPRESSED_GRAIN_HEADER)
compressed_grain_header = OpenStruct.new(SPARSE_EXTENT_COMPRESSED_GRAIN_HEADER.decode(buffer))
buffer = @vmwareSparseDisk_file.read(compressed_grain_header.size)
compressed_grain_header = SPARSE_EXTENT_COMPRESSED_GRAIN_HEADER.decode(buffer)
buffer = @vmwareSparseDisk_file.read(compressed_grain_header['size'])
Zlib::Inflate.inflate(buffer)
end

Expand Down

0 comments on commit 3d37db2

Please sign in to comment.