Exemplo n.º 1
0
func GetPrinterPort(printerName string) (string, error) {
	printerPort := "LPT1"
	const flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS
	var needed, returned uint32
	buf := make([]byte, 1)
	err := EnumPrinters(flags, nil, 5, &buf[0], uint32(len(buf)), &needed, &returned)
	if err != nil {
		if err != syscall.ERROR_INSUFFICIENT_BUFFER {
			return "", err
		}
		buf = make([]byte, needed)
		err = EnumPrinters(flags, nil, 5, &buf[0], uint32(len(buf)), &needed, &returned)
		if err != nil {
			return "", err
		}
	}
	ps := (*[1024]PRINTER_INFO_5)(unsafe.Pointer(&buf[0]))[:returned]
	for _, p := range ps {
		v := (*[1024]uint16)(unsafe.Pointer(p.PrinterName))[:]
		if strings.Compare(syscall.UTF16ToString(v), printerName) == 0 {
			v := (*[1024]uint16)(unsafe.Pointer(p.PortName))[:]
			printerPort = strings.Split(syscall.UTF16ToString(v), ",")[0]
		}
	}
	return printerPort, nil
}
Exemplo n.º 2
0
func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
	snap := w32.CreateToolhelp32Snapshot(w32.TH32CS_SNAPPROCESS, uint32(pid))
	if snap == 0 {
		return 0, 0, "", syscall.GetLastError()
	}
	defer w32.CloseHandle(snap)
	var pe32 w32.PROCESSENTRY32
	pe32.DwSize = uint32(unsafe.Sizeof(pe32))
	if w32.Process32First(snap, &pe32) == false {
		return 0, 0, "", syscall.GetLastError()
	}

	if pe32.Th32ProcessID == uint32(pid) {
		szexe := syscall.UTF16ToString(pe32.SzExeFile[:])
		return int32(pe32.Th32ParentProcessID), int32(pe32.CntThreads), szexe, nil
	}

	for w32.Process32Next(snap, &pe32) {
		if pe32.Th32ProcessID == uint32(pid) {
			szexe := syscall.UTF16ToString(pe32.SzExeFile[:])
			return int32(pe32.Th32ParentProcessID), int32(pe32.CntThreads), szexe, nil
		}
	}
	return 0, 0, "", errors.New("Couldn't find pid:" + string(pid))
}
Exemplo n.º 3
0
func OpenProcess(pid uint32) (*Process, error) {
	const da = syscall.STANDARD_RIGHTS_READ | syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE

	h, err := syscall.OpenProcess(da, false, uint32(pid))
	if err != nil {
		return nil, os.NewSyscallError("OpenProcess", err)
	}

	procEntry, err := win32.FindProcessEntry(pid)
	if err != nil {
		return nil, err
	}

	modEntry, err := win32.FirstModuleEntry(pid)
	if err != nil {
		return nil, err
	}

	handleCount, err := win32.GetProcessHandleCount(h)
	if err != nil {
		return nil, err
	}

	return &Process{
		Pid:         pid,
		handle:      uintptr(h),
		ParentId:    procEntry.ParentProcessID,
		Name:        syscall.UTF16ToString(modEntry.ModuleName[:]),
		Executable:  syscall.UTF16ToString(procEntry.ExeFile[:]),
		CmdLine:     syscall.UTF16ToString(modEntry.ExePath[:]),
		HandleCount: handleCount,
		ThreadCount: procEntry.Threads,
	}, nil
}
Exemplo n.º 4
0
// Search Path Used by Windows to Locate a DLL - https://msdn.microsoft.com/en-us/library/7d83bc18.aspx
func GetDynLibDirs() (dirs []string, err error) {
	// The directory where the executable module for the current process is located.
	path, err := osx.Executable()
	if err != nil {
		return
	}
	dirs = append(dirs, path)
	// The current directory.
	path, err = os.Getwd()
	if err != nil {
		return
	}
	dirs = append(dirs, path)
	// The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
	buf := make([]uint16, syscall.MAX_PATH)
	_, err = syscallx.GetSystemDirectory(&buf[0], syscall.MAX_PATH)
	if err != nil {
		return
	}
	path = syscall.UTF16ToString(buf)
	dirs = append(dirs, path)
	// The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
	_, err = syscallx.GetWindowsDirectory(&buf[0], syscall.MAX_PATH)
	if err != nil {
		return
	}
	path = syscall.UTF16ToString(buf)
	dirs = append(dirs, path)
	// The directories listed in the PATH environment variable.
	path = os.Getenv("PATH")
	dirs = append(dirs, strings.Split(path, string(os.PathListSeparator))...)
	return
}
Exemplo n.º 5
0
func GetVolumeInfo(rootPathName string) (*VolumeInfo, error) {
	var volumeSerialNumber uint32
	var maximumComponentLength uint32
	var fileSystemFlags uint32
	volumeNameBuffer := make([]uint16, syscall.MAX_PATH+1)
	fileSystemNameBuffer := make([]uint16, syscall.MAX_PATH+1)
	err := wrappers.GetVolumeInformation(
		syscall.StringToUTF16Ptr(rootPathName),
		&volumeNameBuffer[0],
		syscall.MAX_PATH+1,
		&volumeSerialNumber,
		&maximumComponentLength,
		&fileSystemFlags,
		&fileSystemNameBuffer[0],
		syscall.MAX_PATH+1)
	if err != nil {
		return nil, NewWindowsError("GetVolumeInformation", err)
	}
	return &VolumeInfo{
		VolumeName:             syscall.UTF16ToString(volumeNameBuffer),
		VolumeSerialNumber:     uint(volumeSerialNumber),
		MaximumComponentLength: uint(maximumComponentLength),
		FileSystemFlags:        FileSystemFlags(fileSystemFlags),
		FileSystemName:         syscall.UTF16ToString(fileSystemNameBuffer),
	}, nil
}
Exemplo n.º 6
0
func getAllWindowsLocaleFrom(sysCall string) (string, error) {
	dll, err := syscall.LoadDLL("kernel32")
	if err != nil {
		return "", errors.New("Could not find kernel32 dll")
	}

	proc, err := dll.FindProc(sysCall)
	if err != nil {
		return "", err
	}

	locale, _, dllError := proc.Call()
	if locale == 0 {
		return "", errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
	}
	proc, err = dll.FindProc("GetLocaleInfoW")
	if err != nil {
		return "", err
	}
	langBuf := make([]uint16, LOCALE_SISO_NAME_MAX_LENGTH)
	r, _, dllError := proc.Call(locale, uintptr(LOCALE_SISO639LANGNAME), uintptr(unsafe.Pointer(&langBuf[0])), uintptr(LOCALE_SISO_NAME_MAX_LENGTH))
	if r == 0 {
		err = errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
		return "", err
	}
	countryBuf := make([]uint16, LOCALE_SISO_NAME_MAX_LENGTH)
	r, _, dllError = proc.Call(locale, uintptr(LOCALE_SISO3166CTRYNAME), uintptr(unsafe.Pointer(&countryBuf[0])), uintptr(LOCALE_SISO_NAME_MAX_LENGTH))
	if r == 0 {
		err = errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
		return "", err
	}
	return syscall.UTF16ToString(langBuf) + "-" + syscall.UTF16ToString(countryBuf), nil
}
Exemplo n.º 7
0
// GetModuleBase takes a module name as an argument. (e.g. "kernel32.dll")
// Returns the modules base address.
//
// (Mostly taken from genkman's gist: https://gist.github.com/henkman/3083408)
// TODO(Andoryuuta): Figure out possible licencing issues with this, or rewrite.
func (p *Process) GetModuleBase(moduleName string) (uintptr, error) {
	snap, ok := w32.CreateToolhelp32Snapshot(w32.TH32CS_SNAPMODULE32|w32.TH32CS_SNAPALL|w32.TH32CS_SNAPMODULE, uint32(p.PID))
	if !ok {
		return 0, errors.New("Error trying on create toolhelp32 snapshot.")
	}
	defer w32.CloseHandle(snap)

	var me32 w32.MODULEENTRY32
	me32.DwSize = uint32(unsafe.Sizeof(me32))

	// Get first module
	if !w32.Module32First(snap, &me32) {
		return 0, errors.New("Error trying to get first module.")
	}

	// Check first module
	if syscall.UTF16ToString(me32.SzModule[:]) == moduleName {
		return uintptr(unsafe.Pointer(me32.ModBaseAddr)), nil
	}

	// Loop all modules remaining
	for w32.Module32Next(snap, &me32) {
		// Check this module
		if syscall.UTF16ToString(me32.SzModule[:]) == moduleName {
			return uintptr(unsafe.Pointer(me32.ModBaseAddr)), nil
		}
	}

	// If this is reached, then we couldn't find the module
	return 0, errors.New("Couldn't Find Module.")
}
Exemplo n.º 8
0
func LoadVariables(etype EnvType) (map[string]string, error) {
	var hkey HKEY
	envMap := make(map[string]string)
	if etype == 0 {
		RegOpenKeyEx(HKEY_CURRENT_USER, syscall.StringToUTF16Ptr(`Environment`), 0, KEY_READ, &hkey)
	} else {
		RegOpenKeyEx(HKEY_LOCAL_MACHINE,
			syscall.StringToUTF16Ptr(`SYSTEM\CurrentControlSet\Control\Session Manager\Environment`),
			0, KEY_READ, &hkey)
	}

	for i := 0; ; i++ {

		var valueLen uint32 = 256
		valueBuffer := make([]uint16, 256)

		var dataLen uint32 = 0
		var dataType uint32 = 0

		if ERROR_NO_MORE_ITEMS == RegEnumValue(hkey, uint32(i), &valueBuffer[0], &valueLen, nil, &dataType, nil, &dataLen) {
			break
		}

		dataBuffer := make([]uint16, dataLen/2+2)

		if ERROR_SUCCESS != RegQueryValueEx(hkey, &valueBuffer[0], nil, &dataType, (*byte)(unsafe.Pointer(&dataBuffer[0])), &dataLen) {
			return nil, errors.New("ERROR2")
		}
		envMap[syscall.UTF16ToString(valueBuffer)] = syscall.UTF16ToString(dataBuffer)
		if syscall.UTF16ToString(valueBuffer) == "Path" {
			log.Println("Path = ", syscall.UTF16ToString(dataBuffer))
		}
	}
	return envMap, nil
}
Exemplo n.º 9
0
func GetProcessModules(pid uint32) ([]ModuleInfo, error) {
	hSnapshot, err := wrappers.CreateToolhelp32Snapshot(wrappers.TH32CS_SNAPMODULE, pid)
	if err != nil {
		return nil, NewWindowsError("CreateToolhelp32Snapshot", err)
	}
	defer wrappers.CloseHandle(hSnapshot)
	me := wrappers.MODULEENTRY32{}
	me.Size = uint32(unsafe.Sizeof(me))
	if err := wrappers.Module32First(hSnapshot, &me); err != nil {
		return nil, NewWindowsError("Module32First", err)
	}
	mi := []ModuleInfo{}
	for {
		mi = append(mi, ModuleInfo{
			ProcessID:         uint(me.ProcessID),
			ModuleBaseAddress: me.ModBaseAddr,
			ModuleBaseSize:    uint(me.ModBaseSize),
			ModuleHandle:      me.Module,
			ModuleName:        syscall.UTF16ToString((&me.ModuleName)[:]),
			ExePath:           syscall.UTF16ToString((&me.ExePath)[:]),
		})
		err := wrappers.Module32Next(hSnapshot, &me)
		if err == wrappers.ERROR_NO_MORE_FILES {
			return mi, nil
		} else if err != nil {
			return nil, NewWindowsError("Module32Next", err)
		}
	}
}
Exemplo n.º 10
0
func (self *FindFile) Current() FindFileItem {
	return FindFileItem{
		FileAttributes:    FileAttributes(self.current.FileAttributes),
		FileSize:          (uint64(self.current.FileSizeHigh) << 32) | uint64(self.current.FileSizeLow),
		ReparseTag:        ReparseTag(self.current.Reserved0),
		FileName:          syscall.UTF16ToString(self.current.FileName[:]),
		AlternateFileName: syscall.UTF16ToString(self.current.AlternateFileName[:]),
	}
}
Exemplo n.º 11
0
// abbrev returns the abbreviations to use for the given zone z.
func abbrev(z *syscall.Timezoneinformation) (std, dst string) {
	stdName := syscall.UTF16ToString(z.StandardName[:])
	a, ok := abbrs[stdName]
	if !ok {
		// fallback to using capital letters
		dstName := syscall.UTF16ToString(z.DaylightName[:])
		return extractCAPS(stdName), extractCAPS(dstName)
	}
	return a.std, a.dst
}
Exemplo n.º 12
0
func RegQuery(regname, installer_name, args string) (result string) {
	var handle, subtestkey syscall.Handle

	var csubkey uint32
	var list [1 << 10]string

	if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, syscall.StringToUTF16Ptr(regname), 0, syscall.KEY_READ, &handle) != nil {
		return
	}
	defer syscall.RegCloseKey(handle)
	csubkey = QueryKey(handle, &list)
	//	fmt.Println("the args is :", args)

	for j := uint32(0); j < csubkey; j++ {

		var buffer, uninstall_buf [syscall.MAX_LONG_PATH]uint16
		n := uint32(len(buffer))
		dwSize := uint32(len(uninstall_buf))
		var display_name string
		reg1 := regname + "\\" + list[j]
		//fmt.Println("reg1 is ", reg1)
		if reg1 == "Software\\Wow6432Node\\Xoreax\\IncrediBuild\\Builder" {
			if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, syscall.StringToUTF16Ptr(reg1), 0, syscall.KEY_READ, &subtestkey) == nil {

				e1 := syscall.RegQueryValueEx(subtestkey, syscall.StringToUTF16Ptr(args), nil, nil, (*byte)(unsafe.Pointer(&buffer[0])), &n)
				if e1 != nil {
					fmt.Println(e1)
				}
				result = syscall.UTF16ToString(buffer[:])
				//				fmt.Println(result, args)
				return
			}
		}
		if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, syscall.StringToUTF16Ptr(reg1), 0, syscall.KEY_READ, &subtestkey) == nil {
			syscall.RegQueryValueEx(subtestkey, syscall.StringToUTF16Ptr("DisplayName"), nil, nil, (*byte)(unsafe.Pointer(&buffer[0])), &n)
			display_name = syscall.UTF16ToString(buffer[:])

			if strings.Contains(display_name, installer_name) {

				if syscall.RegQueryValueEx(subtestkey, syscall.StringToUTF16Ptr(args), nil, nil, (*byte)(unsafe.Pointer(&uninstall_buf[0])), &dwSize) == nil {

					result = syscall.UTF16ToString(uninstall_buf[:])

					if result != "" {
						return
					}

				}
			}
		}
		defer syscall.RegCloseKey(subtestkey)
	}

	return
}
Exemplo n.º 13
0
func (c *Client) KeyInfo() (sessionKeySize uint32, sigAlg uint32, sigAlgName string, encAlg uint32, encAlgName string, err error) {
	var ki _SecPkgContext_KeyInfo
	ret := sspi.QueryContextAttributes(c.ctx.Handle, _SECPKG_ATTR_KEY_INFO, (*byte)(unsafe.Pointer(&ki)))
	if ret != sspi.SEC_E_OK {
		return 0, 0, "", 0, "", ret
	}
	defer sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ki.SignatureAlgorithmName)))
	defer sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ki.EncryptAlgorithmName)))
	saname := syscall.UTF16ToString((*[2 << 20]uint16)(unsafe.Pointer(ki.SignatureAlgorithmName))[:])
	eaname := syscall.UTF16ToString((*[2 << 20]uint16)(unsafe.Pointer(ki.EncryptAlgorithmName))[:])
	return ki.KeySize, ki.SignatureAlgorithm, saname, ki.EncryptAlgorithm, eaname, nil
}
Exemplo n.º 14
0
func init() {
	var buf [4]uint16

	win.GetLocaleInfo(win.LOCALE_USER_DEFAULT, win.LOCALE_SDECIMAL, &buf[0], int32(len(buf)))
	decimalSepB = byte(buf[0])
	decimalSepS = syscall.UTF16ToString(buf[0:1])
	decimalSepUint16 = buf[0]

	win.GetLocaleInfo(win.LOCALE_USER_DEFAULT, win.LOCALE_STHOUSAND, &buf[0], int32(len(buf)))
	groupSepB = byte(buf[0])
	groupSepS = syscall.UTF16ToString(buf[0:1])
	groupSepUint16 = buf[0]
}
Exemplo n.º 15
0
Arquivo: ds.go Projeto: shazow/mog
func DirectSoundCaptureEnumerate(dsEnumCallback func(guid *GUID, description string, module string) bool) error {
	return dllDSResult(procDirectSoundCaptureEnumerate.Call(syscall.NewCallback(func(guid *GUID, description *[maxInt >> 1]uint16, module *[maxInt >> 1]uint16, context uintptr) int {
		b := dsEnumCallback(
			guid,
			syscall.UTF16ToString(description[:]),
			syscall.UTF16ToString(module[:]),
		)
		if b {
			return 1
		}
		return 0
	}), 0))
}
Exemplo n.º 16
0
func (nle *numberLineEdit) setTextFromValue(value float64) error {
	nle.buf.Reset()

	nle.buf.WriteString(syscall.UTF16ToString(nle.prefix))

	if nle.decimals > 0 {
		nle.buf.WriteString(FormatFloatGrouped(value, nle.decimals))
	} else {
		nle.buf.WriteString(FormatFloat(value, nle.decimals))
	}

	nle.buf.WriteString(syscall.UTF16ToString(nle.suffix))

	return nle.SetText(nle.buf.String())
}
Exemplo n.º 17
0
// toEnglishName searches the registry for an English name of a time zone
// whose zone names are stdname and dstname and returns the English name.
func toEnglishName(stdname, dstname string) (string, error) {
	var zones syscall.Handle
	p, _ := syscall.UTF16PtrFromString(`SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones`)
	if err := syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, p, 0, syscall.KEY_READ, &zones); err != nil {
		return "", err
	}
	defer syscall.RegCloseKey(zones)

	var count uint32
	if err := syscall.RegQueryInfoKey(zones, nil, nil, nil, &count, nil, nil, nil, nil, nil, nil, nil); err != nil {
		return "", err
	}

	var buf [50]uint16 // buf needs to be large enough to fit zone descriptions
	for i := uint32(0); i < count; i++ {
		n := uint32(len(buf))
		if syscall.RegEnumKeyEx(zones, i, &buf[0], &n, nil, nil, nil, nil) != nil {
			continue
		}
		kname := syscall.UTF16ToString(buf[:])
		matched, err := matchZoneKey(zones, kname, stdname, dstname)
		if err == nil && matched {
			return kname, nil
		}
	}
	return "", errors.New(`English name for time zone "` + stdname + `" not found in registry`)
}
Exemplo n.º 18
0
func lookupFullName(domain, username, domainAndUser string) (string, error) {
	// try domain controller first
	name, e := syscall.TranslateAccountName(domainAndUser,
		syscall.NameSamCompatible, syscall.NameDisplay, 50)
	if e != nil {
		// domain lookup failed, perhaps this pc is not part of domain
		d, e := syscall.UTF16PtrFromString(domain)
		if e != nil {
			return "", e
		}
		u, e := syscall.UTF16PtrFromString(username)
		if e != nil {
			return "", e
		}
		var p *byte
		e = syscall.NetUserGetInfo(d, u, 10, &p)
		if e != nil {
			// path executed when a domain user is disconnected from the domain
			// pretend username is fullname
			return username, nil
		}
		defer syscall.NetApiBufferFree(p)
		i := (*syscall.UserInfo10)(unsafe.Pointer(p))
		if i.FullName == nil {
			return "", nil
		}
		name = syscall.UTF16ToString((*[1024]uint16)(unsafe.Pointer(i.FullName))[:])
	}
	return name, nil
}
Exemplo n.º 19
0
func RegGetString(hKey HKEY, subKey string, value string) string {
	var bufLen uint32
	procRegGetValue.Call(
		uintptr(hKey),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))),
		uintptr(RRF_RT_REG_SZ),
		0,
		0,
		uintptr(unsafe.Pointer(&bufLen)))

	if bufLen == 0 {
		return ""
	}

	buf := make([]uint16, bufLen)
	ret, _, _ := procRegGetValue.Call(
		uintptr(hKey),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))),
		uintptr(RRF_RT_REG_SZ),
		0,
		uintptr(unsafe.Pointer(&buf[0])),
		uintptr(unsafe.Pointer(&bufLen)))

	if ret != ERROR_SUCCESS {
		return ""
	}

	return syscall.UTF16ToString(buf)
}
Exemplo n.º 20
0
func longPathAsString(path string) (string, error) {
	longp, err := longPath(path)
	if err != nil {
		return "", err
	}
	return syscall.UTF16ToString(longp), nil
}
Exemplo n.º 21
0
// wraps SCardStatus
func (card *Card) Status() (*CardStatus, error) {
	var reader [MAX_READERNAME + 1]uint16
	var readerLen = uint32(len(reader))
	var state, proto uint32
	var atr [MAX_ATR_SIZE]byte
	var atrLen = uint32(len(atr))

	r, _, _ := procStatus.Call(
		card.handle,
		uintptr(unsafe.Pointer(&reader[0])),
		uintptr(unsafe.Pointer(&readerLen)),
		uintptr(unsafe.Pointer(&state)),
		uintptr(unsafe.Pointer(&proto)),
		uintptr(unsafe.Pointer(&atr[0])),
		uintptr(unsafe.Pointer(&atrLen)))
	if scardError(r) != S_SUCCESS {
		return nil, scardError(r)
	}

	status := &CardStatus{
		Reader:         syscall.UTF16ToString(reader[0:readerLen]),
		State:          State(state),
		ActiveProtocol: Protocol(proto),
		ATR:            atr[0:atrLen],
	}

	return status, nil
}
Exemplo n.º 22
0
// LookupSidByName looks up the SID of an account by name
func LookupSidByName(name string) (sid string, err error) {
	if name == "" {
		return "", &AccountLookupError{name, cERROR_NONE_MAPPED}
	}

	var sidSize, sidNameUse, refDomainSize uint32
	err = lookupAccountName(nil, name, nil, &sidSize, nil, &refDomainSize, &sidNameUse)
	if err != nil && err != syscall.ERROR_INSUFFICIENT_BUFFER {
		return "", &AccountLookupError{name, err}
	}
	sidBuffer := make([]byte, sidSize)
	refDomainBuffer := make([]uint16, refDomainSize)
	err = lookupAccountName(nil, name, &sidBuffer[0], &sidSize, &refDomainBuffer[0], &refDomainSize, &sidNameUse)
	if err != nil {
		return "", &AccountLookupError{name, err}
	}
	var strBuffer *uint16
	err = convertSidToStringSid(&sidBuffer[0], &strBuffer)
	if err != nil {
		return "", &AccountLookupError{name, err}
	}
	sid = syscall.UTF16ToString((*[0xffff]uint16)(unsafe.Pointer(strBuffer))[:])
	localFree(uintptr(unsafe.Pointer(strBuffer)))
	return sid, nil
}
Exemplo n.º 23
0
func listPort() (res []String) {
	var root win.HKEY
	res = make([]string, 0)
	rootpath, _ := syscall.UTF16PtrFromString("HARDWARE\\DEVICEMAP\\SERIALCOMM")
	fmt.Println(win.RegOpenKeyEx(win.HKEY_LOCAL_MACHINE, rootpath, 0, win.KEY_READ, &root))

	var callError int32
	var index uint32 = 0
	for callError == 0 {
		var name_length uint32 = 72
		var key_type uint32
		var lpDataLength uint32 = 72

		name := make([]uint16, 72)
		lpData := make([]byte, 72)

		callError = win.RegEnumValue(root, index, &name[0], &name_length, nil, &key_type, &lpData[0], &lpDataLength)

		output := make([]uint16, 72)

		for i := uint32(0); i < lpDataLength; i = i + 2 {
			fmt.Println(uint16(lpData[i])<<8, "-", lpData[i+1])
			output[i/2] = uint16(lpData[i+1])<<8 + uint16(lpData[i])
		}

		res = append(res, syscall.UTF16ToString(output))
		index++
	}

	win.RegCloseKey(root)

}
Exemplo n.º 24
0
func (*Resolver) lookupSRV(ctx context.Context, service, proto, name string) (string, []*SRV, error) {
	// TODO(bradfitz): finish ctx plumbing. Nothing currently depends on this.
	acquireThread()
	defer releaseThread()
	var target string
	if service == "" && proto == "" {
		target = name
	} else {
		target = "_" + service + "._" + proto + "." + name
	}
	var r *syscall.DNSRecord
	e := syscall.DnsQuery(target, syscall.DNS_TYPE_SRV, 0, nil, &r, nil)
	if e != nil {
		return "", nil, &DNSError{Err: winError("dnsquery", e).Error(), Name: target}
	}
	defer syscall.DnsRecordListFree(r, 1)

	srvs := make([]*SRV, 0, 10)
	for _, p := range validRecs(r, syscall.DNS_TYPE_SRV, target) {
		v := (*syscall.DNSSRVData)(unsafe.Pointer(&p.Data[0]))
		srvs = append(srvs, &SRV{absDomainName([]byte(syscall.UTF16ToString((*[256]uint16)(unsafe.Pointer(v.Target))[:]))), v.Port, v.Priority, v.Weight})
	}
	byPriorityWeight(srvs).sort()
	return absDomainName([]byte(target)), srvs, nil
}
Exemplo n.º 25
0
func nativeGetPortsList() ([]string, error) {
	subKey, err := syscall.UTF16PtrFromString("HARDWARE\\DEVICEMAP\\SERIALCOMM\\")
	if err != nil {
		return nil, &PortError{code: ErrorEnumeratingPorts}
	}

	var h syscall.Handle
	if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, subKey, 0, syscall.KEY_READ, &h) != nil {
		return nil, &PortError{code: ErrorEnumeratingPorts}
	}
	defer syscall.RegCloseKey(h)

	var valuesCount uint32
	if syscall.RegQueryInfoKey(h, nil, nil, nil, nil, nil, nil, &valuesCount, nil, nil, nil, nil) != nil {
		return nil, &PortError{code: ErrorEnumeratingPorts}
	}

	list := make([]string, valuesCount)
	for i := range list {
		var data [1024]uint16
		dataSize := uint32(len(data))
		var name [1024]uint16
		nameSize := uint32(len(name))
		if regEnumValue(h, uint32(i), &name[0], &nameSize, nil, nil, &data[0], &dataSize) != nil {
			return nil, &PortError{code: ErrorEnumeratingPorts}
		}
		list[i] = syscall.UTF16ToString(data[:])
	}
	return list, nil
}
Exemplo n.º 26
0
Arquivo: win.go Projeto: CodyGuo/win
// void * (uintptr)转换为字符串
func UINTptrToString(uintPtr uintptr) string {
	if uintPtr == 0 {
		return ""
	}

	return syscall.UTF16ToString((*[1 << 16]uint16)(unsafe.Pointer(uintPtr))[0:])
}
Exemplo n.º 27
0
func XPane_GetTitleGo(hEle HELE) string {
	buf_szize := 256
	buf := make([]uint16, buf_szize)
	XPane_GetTitle(hEle, &buf[0], buf_szize)

	return syscall.UTF16ToString(buf)
}
Exemplo n.º 28
0
func GetSpecialFolderPath(folder SpecialFolder) (string, error) {
	buf := [wrappers.MAX_PATH]uint16{}
	if hr := wrappers.SHGetFolderPath(0, uint32(folder), 0, 0, &buf[0]); wrappers.FAILED(hr) {
		return "", NewWindowsError("SHGetFolderPath", COMError(hr))
	}
	return syscall.UTF16ToString((&buf)[:]), nil
}
Exemplo n.º 29
0
// See http://blog.natefinch.com/2012/11/go-win-stuff.html
//
// This is used by workstationVMwareRoot in order to read some registry data.
func readRegString(hive syscall.Handle, subKeyPath, valueName string) (value string, err error) {
	var h syscall.Handle
	err = syscall.RegOpenKeyEx(hive, syscall.StringToUTF16Ptr(subKeyPath), 0, syscall.KEY_READ, &h)
	if err != nil {
		return
	}
	defer syscall.RegCloseKey(h)

	var typ uint32
	var bufSize uint32
	err = syscall.RegQueryValueEx(
		h,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&typ,
		nil,
		&bufSize)
	if err != nil {
		return
	}

	data := make([]uint16, bufSize/2+1)
	err = syscall.RegQueryValueEx(
		h,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&typ,
		(*byte)(unsafe.Pointer(&data[0])),
		&bufSize)
	if err != nil {
		return
	}

	return syscall.UTF16ToString(data), nil
}
Exemplo n.º 30
0
func GetOperatingSystem() (string, error) {

	var h syscall.Handle

	// Default return value
	ret := "Unknown Operating System"

	if err := syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE,
		syscall.StringToUTF16Ptr(`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\`),
		0,
		syscall.KEY_READ,
		&h); err != nil {
		return ret, err
	}
	defer syscall.RegCloseKey(h)

	var buf [1 << 10]uint16
	var typ uint32
	n := uint32(len(buf) * 2) // api expects array of bytes, not uint16

	if err := syscall.RegQueryValueEx(h,
		syscall.StringToUTF16Ptr("ProductName"),
		nil,
		&typ,
		(*byte)(unsafe.Pointer(&buf[0])),
		&n); err != nil {
		return ret, err
	}
	ret = syscall.UTF16ToString(buf[:])

	return ret, nil
}