Documentation ¶
Overview ¶
Package embedexe executes a program stored in a byte array such as an executable or a directory of executables embedded in a Go binary.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FD ¶
type FD struct {
// contains filtered or unexported fields
}
func Open ¶
Open returns a file descriptor to an executable stored in memory.
Example ¶
package main import ( "fmt" "os" "codeberg.org/msantos/embedexe" ) func main() { b := []byte("#!/bin/sh\necho $@") fd, err := embedexe.Open(b, "example") if err != nil { fmt.Println(err) return } defer fd.Close() if err := fd.Exec([]string{"example", "test"}, os.Environ()); err != nil { fmt.Println(err) return } }
Output:
func (*FD) Exec ¶
Exec runs the executable referenced by the file descriptor, replacing the current running process image.
func (*FD) Path ¶
Path returns the path to the executable file descriptor. Running the executable using the file descriptor path directly is an alternative to running by file descriptor in Exec.
Example ¶
package main import ( "fmt" "os" "os/exec" "codeberg.org/msantos/embedexe" ) func main() { b, err := os.ReadFile("/bin/echo") if err != nil { fmt.Println(err) return } fd, err := embedexe.Open(b, "echo") if err != nil { fmt.Println(err) return } cmd := exec.Command(fd.Path(), "-n", "test", "abc") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { fmt.Println(err) return } }
Output: test abc
Example (Sh) ¶
An example of running a script contained in a memfd without execute permissions.
package main import ( "fmt" "os" "os/exec" "codeberg.org/msantos/embedexe" ) func main() { b := []byte("#!/bin/sh\necho $@") fd, err := embedexe.Open(b, "sh") if err != nil { fmt.Println(err) return } cmd := exec.Command("/bin/sh", fd.Path(), "-n", "test", "abc") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { fmt.Println(err) return } }
Output: test abc
func (*FD) SetCloseExec ¶
SetCloseExec enables or disables the O_CLOEXEC flag on the file descriptor.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
fileexe
Fileexe forks and runs an embedded executable.
|
Fileexe forks and runs an embedded executable. |
fsexe
Fsexe forks and runs an executable from an embedded directory of executables.
|
Fsexe forks and runs an executable from an embedded directory of executables. |
Package exec runs a command stored as bytes in memory.
|
Package exec runs a command stored as bytes in memory. |
Package fdexec runs a command by file descriptor.
|
Package fdexec runs a command by file descriptor. |
internal
|
|
reexec
Package reexec reexecs the process image using a file descriptor.
|
Package reexec reexecs the process image using a file descriptor. |