goupx

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2023 License: MIT Imports: 5 Imported by: 1

README

go-upx

go-upx

Test Go Reference

go-upx is a command-line wrapper library for upx utility.

For package reference, visit https://pkg.go.dev/github.com/alegrey91/go-upx.

What is UPX

UPX is a free, secure, portable, extendable, high-performance executable packer for several executable formats. More info at https://upx.github.io/.

Why

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.

Install

To install the module, run the following command:

go get github.com/alegrey91/go-upx

Example

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

Test

To test the code locally, run the following command:

go test -v .

License

go-upx is available under MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackupOptions

type BackupOptions struct {
	// Backup keep backup files
	Backup bool
}

Read description for Options struct.

type CmdExecution added in v0.2.0

type CmdExecution struct {
	// contains filtered or unexported fields
}

CmdExecution describe the command after its execution. It collects info about its stderr/stdout, exit status, etc.

func (*CmdExecution) GetCompressedFileSize added in v0.2.0

func (po *CmdExecution) GetCompressedFileSize() uint64

GetCompressedFileSize return the compressed file size value from the command execution.

func (*CmdExecution) GetErrorMessage added in v0.2.0

func (pe *CmdExecution) GetErrorMessage() error

GetErrorMessage return the error value from the command execution.

func (*CmdExecution) GetFormat added in v0.2.0

func (po *CmdExecution) GetFormat() string

GetFormat return the format value from the command execution.

func (*CmdExecution) GetName added in v0.2.0

func (po *CmdExecution) GetName() string

GetName return the name value from the command execution.

func (*CmdExecution) GetOriginalFileSize added in v0.2.0

func (po *CmdExecution) GetOriginalFileSize() uint64

GetOriginalFileSize return the original file size value from the command execution.

func (*CmdExecution) GetRatio added in v0.2.0

func (po *CmdExecution) GetRatio() float64

GetRatio return the ratio value from the command execution.

type CompressionTuningOptions

type CompressionTuningOptions struct {
	// Brute try all available compression methods, filters and variants
	Brute int
}

Read description for Options struct.

type Options

type Options struct {
	// Output write output to 'FILE'
	Output string

	// Force force compression of suspicious files
	Force bool

	// Verbose enable/disable verbosity
	Verbose bool

	// CompressionTuningOpt keep track of CompressionTuningOptions
	CompressionTuningOpt CompressionTuningOptions

	// BackupOpt keep track of BackupOptions
	BackupOpt BackupOptions
}

Options describe the command args provided by the upx utility. Here's an example: --- Options:

-q     be quiet                          -v    be verbose
-oFILE write output to 'FILE'
-f     force compression of suspicious files
--no-color, --mono, --color, --no-progress   change look

Compression tuning options:

--brute             try all available compression methods & filters [slow]
--ultra-brute       try even more compression variants [very slow]

Backup options:

-k, --backup        keep backup files
--no-backup         no backup files [default]

type UPX

type UPX struct {
	// Binary file for upx (it is visible in case you have different binary name)
	Binary string

	// UPX command execution results
	CmdExecution
	// contains filtered or unexported fields
}

UPX describe the execution of upx utility.

func NewUPX

func NewUPX() *UPX

NewUPX return a new instance of upx object.

func NewUPXWithBinary added in v0.2.1

func NewUPXWithBinary(binPath string) *UPX

NewUPXWithBinary return a new instance of upx object, not in PATH.

func (*UPX) Compress

func (upx *UPX) Compress(file string, intensity int, options Options) (bool, error)

Compress execute a compression with upx. It return false with an error message in case of fail, true with nil otherwhise.

func (*UPX) Decompress

func (upx *UPX) Decompress(file string, options Options) (bool, error)

Decompress execute a decompression with upx. It return false with an error message in case of fail, true with nil otherwhise.

func (*UPX) GetArgs

func (upx *UPX) GetArgs() []string

GetArgs return the list of command args.

func (*UPX) GetCompressedFileSize added in v0.2.0

func (po *UPX) GetCompressedFileSize() uint64

GetCompressedFileSize return the compressed file size value from the command execution.

func (*UPX) GetErrorMessage added in v0.2.0

func (pe *UPX) GetErrorMessage() error

GetErrorMessage return the error value from the command execution.

func (*UPX) GetFormat added in v0.2.0

func (po *UPX) GetFormat() string

GetFormat return the format value from the command execution.

func (*UPX) GetName added in v0.2.0

func (po *UPX) GetName() string

GetName return the name value from the command execution.

func (*UPX) GetOriginalFileSize added in v0.2.0

func (po *UPX) GetOriginalFileSize() uint64

GetOriginalFileSize return the original file size value from the command execution.

func (*UPX) GetRatio added in v0.2.0

func (po *UPX) GetRatio() float64

GetRatio return the ratio value from the command execution.

func (*UPX) ListCompressedFile added in v0.2.0

func (upx *UPX) ListCompressedFile(file string, options Options) (bool, error)

func (*UPX) TestCompressedFile

func (upx *UPX) TestCompressedFile(file string) (bool, error)

TestCompressedFile execute test with upx. It return false with an error message in case it fail, true with nil otherwise.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL