2023-07-03 20:21:30 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-03-20 20:25:53 +00:00
|
|
|
//go:build windows
|
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"debug/elf"
|
|
|
|
"debug/macho"
|
|
|
|
"debug/pe"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// additionalNotesAboutCommand tries to get additional information about a command that might help diagnose
|
|
|
|
// why it won't run correctly. It runs as a best effort only.
|
|
|
|
func additionalNotesAboutCommand(path string) string {
|
|
|
|
notes := ""
|
|
|
|
stat, err := os.Stat(path)
|
|
|
|
if err != nil {
|
|
|
|
return notes
|
|
|
|
}
|
|
|
|
|
|
|
|
notes += "\nAdditional notes about plugin:\n"
|
|
|
|
notes += fmt.Sprintf(" Path: %s\n", path)
|
|
|
|
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode())
|
|
|
|
|
|
|
|
if elfFile, err := elf.Open(path); err == nil {
|
2023-07-03 20:21:30 +00:00
|
|
|
defer elfFile.Close()
|
2023-03-20 20:25:53 +00:00
|
|
|
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
|
|
|
|
} else if machoFile, err := macho.Open(path); err == nil {
|
2023-07-03 20:21:30 +00:00
|
|
|
defer machoFile.Close()
|
2023-03-20 20:25:53 +00:00
|
|
|
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
|
|
|
|
} else if peFile, err := pe.Open(path); err == nil {
|
2023-07-03 20:21:30 +00:00
|
|
|
defer peFile.Close()
|
2023-03-20 20:25:53 +00:00
|
|
|
machine, ok := peTypes[peFile.Machine]
|
|
|
|
if !ok {
|
|
|
|
machine = "unknown"
|
|
|
|
}
|
|
|
|
notes += fmt.Sprintf(" PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH)
|
|
|
|
}
|
|
|
|
return notes
|
|
|
|
}
|