2024-10-09 23:51:15 +09:00
|
|
|
package ldd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2024-10-17 15:37:27 +09:00
|
|
|
|
2024-12-20 00:20:02 +09:00
|
|
|
"git.gensokyo.uk/security/fortify/helper"
|
|
|
|
"git.gensokyo.uk/security/fortify/helper/bwrap"
|
2024-10-09 23:51:15 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
func Exec(p string) ([]*Entry, error) {
|
2024-10-17 15:37:27 +09:00
|
|
|
var (
|
|
|
|
h helper.Helper
|
|
|
|
cmd *exec.Cmd
|
|
|
|
)
|
|
|
|
|
|
|
|
if b, err := helper.NewBwrap((&bwrap.Config{
|
|
|
|
Hostname: "fortify-ldd",
|
|
|
|
Chdir: "/",
|
|
|
|
NewSession: true,
|
|
|
|
DieWithParent: true,
|
|
|
|
}).Bind("/", "/").DevTmpfs("/dev"),
|
|
|
|
nil, "ldd", func(_, _ int) []string { return []string{p} }); err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
cmd = b.Unwrap()
|
|
|
|
h = b
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Stdout, cmd.Stderr = new(strings.Builder), os.Stderr
|
|
|
|
if err := h.Start(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := h.Wait(); err != nil {
|
2024-10-09 23:51:15 +09:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-10-17 15:37:27 +09:00
|
|
|
return Parse(cmd.Stdout.(fmt.Stringer))
|
2024-10-09 23:51:15 +09:00
|
|
|
}
|