Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support older Go compilers #2

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Velocidex/go-vmdk

go 1.23
go 1.23.2

require (
github.com/alecthomas/kingpin/v2 v2.4.0
Expand Down
29 changes: 15 additions & 14 deletions parser/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"io"
"regexp"
"slices"
"sort"
"strings"
)

Expand Down Expand Up @@ -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
}

Expand Down