diff --git a/go.mod b/go.mod index 83efbd4..ffd31a4 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,5 @@ module github.com/Velocidex/go-vmdk -go 1.23 - require ( github.com/alecthomas/kingpin/v2 v2.4.0 github.com/sebdah/goldie v1.0.0 diff --git a/parser/context.go b/parser/context.go index 8baf5bf..d0a7b37 100644 --- a/parser/context.go +++ b/parser/context.go @@ -5,7 +5,7 @@ import ( "fmt" "io" "regexp" - "slices" + "sort" "strings" ) @@ -47,26 +47,27 @@ func (self *VMDKContext) Close() { func (self *VMDKContext) getExtentForOffset(offset int64) ( extent Extent, err error) { - n, found := slices.BinarySearchFunc(self.extents, - offset, func(item Extent, offset int64) int { - if offset < item.VirtualOffset() { - return 1 - } else if offset == item.VirtualOffset() { - return 0 - } - return -1 + n := sort.Search(len(self.extents), + func(i int) bool { + extent := self.extents[i] + virtual_offset := extent.VirtualOffset() + + return virtual_offset > offset }) - if found { - n++ - } if n < 1 || n > len(self.extents) { return nil, io.EOF } extent = self.extents[n-1] - if extent.VirtualOffset() > offset || - extent.VirtualOffset()+extent.TotalSize() < offset { + virtual_offset := extent.VirtualOffset() + extent_size := extent.TotalSize() + + // extent starts after offset. + if virtual_offset > offset || + + // extent ends before offset + virtual_offset+extent_size < offset { return nil, io.EOF }