memexec

package module
v0.3.1-0...-3093477 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

go-memexec

Small library that executes code from the memory.

Usage

The following example executes ruby executable embedded into the binary:

// Asset function provided by a library such as go-bindata
b, err := Asset("/bin/ruby")
if err != nil {
	return err
}

exe, err := memexec.New(b)
if err != nil {
	return err
}
defer exe.Close()

cmd := exe.Command(argv...)
cmd.Output() // cmd is a `*exec.Cmd` from the standard library

Documentation

Index

Constants

View Source
const (
	TEMP_FILE_PREFIX = `wgcs-`
)

Variables

View Source
var (
	DEBUG_MODE = false
)

Functions

This section is empty.

Types

type Exec

type Exec struct {
	Path          string
	TmpPath       string
	Hash          string
	ProcExecution bool
	// contains filtered or unexported fields
}

Exec is an in-memory executable code unit.

func New

func New(b []byte) (*Exec, error)

New creates new memory execution object that can be used for executing commands on a memory based binary.

func (*Exec) Close

func (m *Exec) Close() error

Close closes Exec object.

Any further command will fail, it's client's responsibility to control the flow by using synchronization algorithms.

func (*Exec) Command

func (m *Exec) Command(arg ...string) *exec.Cmd

Command is an equivalent of `exec.Command`, except that the path to the executable is be omitted.

func (*Exec) Run

func (m *Exec) Run(args []string) *RunResult

type RunResult

type RunResult struct {
	Command       string
	Path          string
	TmpPath       string
	Hash          string
	Arguments     []string
	Duration      time.Duration
	Stdout        string
	Stderr        string
	ExitCode      int64
	ProcExecution bool
}

Jump to

Keyboard shortcuts

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