-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lzxpress decompression on windows. (#5)
There seems to be some problem decompression some files. This change falls back to manual decompression on if the API is not available (on older windows or non-windows system). On windows we call the windows API to decompress the prefetch file in a more reliable way. Fixes: #4
- Loading branch information
Showing
7 changed files
with
120 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module www.velocidex.com/golang/go-prefetch | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 | ||
github.com/jawher/mow.cli v1.1.0 | ||
github.com/sebdah/goldie v1.0.0 | ||
github.com/stretchr/testify v1.3.0 | ||
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666 | ||
gopkg.in/yaml.v2 v2.2.2 // indirect | ||
www.velocidex.com/golang/binparsergen v0.1.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/jawher/mow.cli v1.1.0 h1:NdtHXRc0CwZQ507wMvQ/IS+Q3W3x2fycn973/b8Zuk8= | ||
github.com/jawher/mow.cli v1.1.0/go.mod h1:aNaQlc7ozF3vw6IJ2dHjp2ZFiA4ozMIYY6PyuRJwlUg= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sebdah/goldie v1.0.0 h1:9GNhIat69MSlz/ndaBg48vl9dF5fI+NBB6kfOxgfkMc= | ||
github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= | ||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666 h1:gVCS+QOncANNPlmlO1AhlU3oxs4V9z+gTtPwIk3p2N8= | ||
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
www.velocidex.com/golang/binparsergen v0.1.0 h1:oNsMHGnlb4jrGwxKxqqmsics6FgYin3HR5UNtLXc8S0= | ||
www.velocidex.com/golang/binparsergen v0.1.0/go.mod h1:UC43Ecj0mjsidlClTYZ3H4dXdyv7CVI0HsYi4yY3qtc= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// +build !windows | ||
|
||
package prefetch | ||
|
||
// Non windows systems fall back to build in decompression. | ||
func LZXpressHuffmanDecompressWithFallback(input []byte, output_size int) ([]byte, error) { | ||
return LZXpressHuffmanDecompress(input, output_size) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// +build windows | ||
|
||
package prefetch | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
var ( | ||
ntoskrnl = windows.NewLazySystemDLL("ntdll.dll") | ||
RtlDecompressBufferEx = ntoskrnl.NewProc("RtlDecompressBufferEx") | ||
|
||
COMPRESSION_FORMAT_XPRESS_HUFF = uint16(0x0004) | ||
) | ||
|
||
func LZXpressHuffmanDecompressWithFallback(input []byte, output_size int) ([]byte, error) { | ||
|
||
// For older windows, we fall back to the build in decompression. | ||
err := RtlDecompressBufferEx.Find() | ||
if err != nil { | ||
return LZXpressHuffmanDecompress(input, output_size) | ||
} | ||
|
||
result := make([]byte, output_size) | ||
final_size := uint32(output_size) | ||
|
||
workspace := make([]byte, output_size*2) | ||
|
||
ret, _, _ := RtlDecompressBufferEx.Call( | ||
uintptr(COMPRESSION_FORMAT_XPRESS_HUFF), | ||
uintptr(unsafe.Pointer(&result[0])), | ||
uintptr(output_size), | ||
uintptr(unsafe.Pointer(&input[0])), | ||
uintptr(len(input)), | ||
uintptr(unsafe.Pointer(&final_size)), | ||
uintptr(unsafe.Pointer(&workspace[0]))) | ||
if ret != 0 { | ||
// Fallback to the built in implementation on error. | ||
return LZXpressHuffmanDecompress(input, output_size) | ||
} | ||
|
||
// Return the decompressed buffer from the API. | ||
return result[:final_size], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters