MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / Open

Method Open

internal/pluginhost/loader_windows.go:71–116  ·  view source on GitHub ↗
(file pluginFile, host *Host)

Source from the content-addressed store, hash-verified

69}
70
71func (dynamicLibraryLoader) Open(file pluginFile, host *Host) (pluginClient, error) {
72 loadPath, errShadow := shadowCopyPlugin(file)
73 if errShadow != nil {
74 return nil, errShadow
75 }
76 dll, errLoad := syscall.LoadDLL(loadPath)
77 if errLoad != nil {
78 removeShadowPlugin(loadPath)
79 return nil, errLoad
80 }
81 proc, errProc := dll.FindProc("cliproxy_plugin_init")
82 if errProc != nil {
83 _ = dll.Release()
84 removeShadowPlugin(loadPath)
85 return nil, errProc
86 }
87 id := windowsHostCallbackID.Add(1)
88 hostCtx := new(uintptr)
89 *hostCtx = id
90 windowsHostCallbackEntries.Store(id, dynamicHostCallbackEntry{host: host, pluginID: file.ID})
91 client := &dynamicLibraryClient{
92 dll: dll,
93 tempPath: loadPath,
94 hostCtx: hostCtx,
95 hostAPI: &windowsHostAPI{
96 abiVersion: pluginHostABIVersion,
97 hostCtx: uintptr(unsafe.Pointer(hostCtx)),
98 call: windowsHostCallCallback,
99 freeBuffer: windowsHostFreeCallback,
100 },
101 }
102 rc, _, errCall := proc.Call(uintptr(unsafe.Pointer(client.hostAPI)), uintptr(unsafe.Pointer(&client.api)))
103 if rc != 0 {
104 client.closeAfterOpenFailure()
105 return nil, fmt.Errorf("cliproxy_plugin_init returned %d: %v", rc, errCall)
106 }
107 if client.api.abiVersion != pluginHostABIVersion {
108 client.closeAfterOpenFailure()
109 return nil, fmt.Errorf("plugin ABI version %d is not supported", client.api.abiVersion)
110 }
111 if client.api.call == 0 || client.api.freeBuffer == 0 {
112 client.closeAfterOpenFailure()
113 return nil, fmt.Errorf("plugin function table is incomplete")
114 }
115 return client, nil
116}
117
118func shadowCopyPlugin(file pluginFile) (string, error) {
119 dir, errDir := shadowPluginDir()

Callers

nothing calls this directly

Calls 4

closeAfterOpenFailureMethod · 0.95
shadowCopyPluginFunction · 0.85
removeShadowPluginFunction · 0.85
CallMethod · 0.65

Tested by

no test coverage detected