github.com/Coalfire-Research/Slackor@v0.0.0-20191010164036-aa32a7f9250b/pkg/windows/version.go (about)

     1  // +build windows
     2  
     3  package windows
     4  
     5  import (
     6  	"fmt"
     7  	"syscall"
     8  
     9  	"github.com/Coalfire-Research/Slackor/internal/config"
    10  	"github.com/Coalfire-Research/Slackor/pkg/command"
    11  )
    12  
    13  // Version gets the OS version
    14  type Version struct{}
    15  
    16  // Name is the name of the command
    17  func (ver Version) Name() string {
    18  	return "version"
    19  }
    20  
    21  // Run gets the OS version
    22  func (ver Version) Run(clientID string, jobID string, args []string) (string, error) {
    23  	if config.OSVersion != "" {
    24  		return config.OSVersion, nil
    25  	}
    26  	dll := syscall.MustLoadDLL("kernel32.dll")
    27  	p := dll.MustFindProc("GetVersion")
    28  	v, _, _ := p.Call()
    29  	version := fmt.Sprintf("Windows version %d.%d (Build %d)\n", byte(v), uint8(v>>8), uint16(v>>16))
    30  	config.OSVersion = version
    31  	return config.OSVersion, nil
    32  }
    33  
    34  func init() {
    35  	command.RegisterCommand(Version{})
    36  }