-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.go
48 lines (37 loc) · 857 Bytes
/
plugin.go
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
package malvales
import (
"net/rpc"
"github.com/hashicorp/go-plugin"
rt "github.com/arnodel/golua/runtime"
)
type Module interface{
Loader() rt.Value
}
type entryRPCClient struct{
client *rpc.Client
}
func (e *entryRPCClient) Loader() rt.Value {
var resp *rt.Value
err := e.client.Call("Plugin.Loader", new(interface{}), &resp)
if err != nil {
// TODO: return nil (or some value to indicate err)
panic(err)
}
return *resp
}
type entryRPCServer struct{
M Module
}
func (s *entryRPCServer) Loader(_ interface{}, resp *rt.Value) error {
*resp = s.M.Loader()
return nil
}
type Entry struct{
M Module
}
func (e *Entry) Server(b *plugin.MuxBroker) (interface{}, error) {
return &entryRPCServer{M: e.M}, nil
}
func (e *Entry) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &entryRPCClient{client: c}, nil
}