go-upx is a command-line wrapper library for upx
utility.
For package reference, visit https://pkg.go.dev/github.com/alegrey91/go-upx.
UPX is a free, secure, portable, extendable, high-performance executable packer for several executable formats. More info at https://upx.github.io/.
The idea was to create a nice interface for this utility in my favorite programming language. So you can automate tasks in a bigger project that makes use of the utility.
To install the module, run the following command:
go get github.com/alegrey91/go-upx
Let's see how you can use go-upx
to compress a file from a Go program:
import (
...
"github.com/alegrey91/go-upx"
)
...
// UPX options definition
options := goupx.Options{
Output: "/tmp/file",
Force: true,
Verbose: false,
CompressionTuningOpt: goupx.CompressionTuningOptions{
Brute: 1,
},
}
// command execution
upx := goupx.NewUPX()
_, err := upx.Compress("/path/to/file/to_be_compressed", 9, options)
if err != nil {
fmt.Println(err)
}
// display the results
fmt.Println(upx.CmdExecution.GetFormat())
fmt.Println(upx.CmdExecution.GetOriginalFileSize())
fmt.Println(upx.CmdExecution.GetCompressedFileSize())
fmt.Println(upx.CmdExecution.GetRatio())
fmt.Println(upx.CmdExecution.GetFormat())
fmt.Println(upx.CmdExecution.GetName())
...
Here you can find more code examples here: examples
To test the code locally, run the following command:
go test -v .
go-upx is available under MIT license.