Repository navigation
Expand file tree
/
Copy pathexpose-windows.go
More file actions
86 lines (71 loc) · 2.05 KB
/
Copy pathexpose-windows.go
File metadata and controls
86 lines (71 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//go:build windows
// +build windows
package PluginLib
import (
"bufio"
"fmt"
"log"
"net/http"
"os"
"sync"
"time"
"github.com/Microsoft/go-winio"
)
var PluginPipePath string
func getPluginPipePath() string {
if PluginPipePath != "" {
fmt.Println("Using cached PluginPipePath:", PluginPipePath) // Debug
return PluginPipePath + config.PluginName
}
PluginPipePathFile, err := os.Open("./SSUI/plugins/sockets/pipename.identifier")
if err != nil {
fmt.Println("Error opening pipename.identifier file, I have to go...:", err)
os.Exit(1)
}
defer PluginPipePathFile.Close()
scanner := bufio.NewScanner(PluginPipePathFile)
for scanner.Scan() {
PluginPipePath = scanner.Text()
fmt.Println("Read PluginPipePath:", PluginPipePath) // Debug
}
if PluginPipePath == "" {
fmt.Println("Error reading pipename.identifier file, I have to go...:", err)
os.Exit(1)
}
pipePath := PluginPipePath + config.PluginName
fmt.Println("Final plugin pipe path:", pipePath) // Debug
return pipePath
}
func ExposeAPI(wg *sync.WaitGroup) {
wg.Add(1)
defer wg.Done()
pluginPipePath := getPluginPipePath()
if !configInitialized {
log.Fatal("plugin configuration not initialized; call InitConfig first")
}
// Remove existing pipe if it exists
if err := os.RemoveAll(pluginPipePath); err != nil {
Log("Error removing existing pipe: " + err.Error())
}
// Create a named pipe listener using go-winio
listener, err := winio.ListenPipe(pluginPipePath, nil)
if err != nil {
Log("Error starting named pipe server: " + err.Error())
return
}
// Named pipes on Windows have permissions set via Security Descriptor
// Default nil config in ListenPipe provides reasonable security (creator-only access)
// Create an HTTP server
server := &http.Server{
Handler: pluginMux,
}
// Start server in a goroutine
go func() {
Log("Named pipe server running at " + pluginPipePath)
if err := server.Serve(listener); err != nil && err != http.ErrServerClosed {
Log("Named pipe server error: " + err.Error())
}
listener.Close()
}()
time.Sleep(100 * time.Millisecond)
}