MCPcopy Index your code
hub / github.com/amenzhinsky/go-memexec

github.com/amenzhinsky/go-memexec @v0.7.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.7.1 ↗ · + Follow
29 symbols 80 edges 7 files 7 documented · 24%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-memexec

Small library that executes binaries from the memory.

Usage

Static Binary

Running static binaries is quite simple, it's only needed to embed it into the app and pass its content to memexec.New:

import (
    _ "embed"

    "github.com/amenzhinsky/go-memexec"
)

// go:embed path-to-binary
var mybinary []byte

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

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

Dynamic Binary (Linux only)

With dynamic linked binaries things get more complicated, it's needed to embed all dependencies along with the executable.

At the runtime deps are copied to a temp dir and executable receives the corresponding LD_LIBRARY_PATH that forces the dynamic linker to use the copied libraries.

The dynamic linker must be the same on both building and running machines since it's not included in the resulting binary (there's no interoperability between musl and GNU systems).

The following script helps generating packages, say python3:

go install github.com/amenzhinsky/go-memexec/cmd/memexec-gen@latest
PATH=$(go env GOPATH)/bin:$PATH memexec-gen /usr/bin/python3

It produces python3 directory with binaries are to embed and gen.go file, that is a go package:

import "mypackagename/python3"

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

b, err := exe.Command("-c", "print('Hello World')").CombinedOutput()
if err != nil {
    return err
}

Extension points exported contracts — how you extend this code

Option (FuncType)
(no doc)
memexec.go

Core symbols most depended-on inside this repo

out
called by 32
cmd/memexec-gen/main.go
Close
called by 10
memexec.go
Command
called by 6
memexec.go
goName
called by 3
cmd/memexec-gen/main.go
clean
called by 2
memexec_all.go
New
called by 2
memexec.go
CommandContext
called by 2
memexec.go
open
called by 1
memexec_all.go

Shape

Function 24
Method 3
FuncType 1
Struct 1

Languages

Go100%

Modules by API surface

memexec_test.go8 symbols
memexec.go8 symbols
cmd/memexec-gen/main.go7 symbols
memexec_linux.go2 symbols
memexec_all.go2 symbols
testdata/main.go1 symbols
memexec_linux_test.go1 symbols

For agents

$ claude mcp add go-memexec \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page