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

Function pluginFileFromPath

internal/pluginhost/platform.go:62–96  ·  view source on GitHub ↗
(filePath string, requiredExtension string)

Source from the content-addressed store, hash-verified

60}
61
62func pluginFileFromPath(filePath string, requiredExtension string) (pluginFile, bool) {
63 base := filepath.Base(filePath)
64 lowerBase := strings.ToLower(base)
65 extension := strings.TrimSpace(requiredExtension)
66 if extension != "" {
67 if !strings.HasSuffix(lowerBase, strings.ToLower(extension)) {
68 return pluginFile{}, false
69 }
70 } else {
71 for _, candidateExtension := range []string{".so", ".dylib", ".dll"} {
72 if strings.HasSuffix(lowerBase, candidateExtension) {
73 extension = candidateExtension
74 break
75 }
76 }
77 if extension == "" {
78 return pluginFile{}, false
79 }
80 }
81 name := base[:len(base)-len(extension)]
82 id := name
83 version := ""
84 if versionIndex := strings.LastIndex(name, "-v"); versionIndex > 0 {
85 candidateID := name[:versionIndex]
86 candidateVersion := name[versionIndex+2:]
87 if validPluginID(candidateID) && validPluginVersion(candidateVersion) {
88 id = candidateID
89 version = candidateVersion
90 }
91 }
92 if !validPluginID(id) {
93 return pluginFile{}, false
94 }
95 return pluginFile{ID: id, Path: filePath, Version: version}, true
96}
97
98// PluginExtension returns the dynamic library file extension used for goos.
99func PluginExtension(goos string) string {

Callers 2

pluginIDFromPathFunction · 0.70

Calls 2

validPluginIDFunction · 0.70
validPluginVersionFunction · 0.70

Tested by

no test coverage detected