Ejemplo n.º 1
0
func XAudio2Create(ppXAudio2 **IXAudio2) (ret int32) {
	libole32, _ := syscall.LoadLibrary("ole32.dll")
	ptrcoInitializeEx, _ = syscall.GetProcAddress(syscall.Handle(libole32), "CoInitializeEx")
	ptrcoCreateInstance, _ = syscall.GetProcAddress(syscall.Handle(libole32), "CoCreateInstance")

	coInitializeEx(nil, 0)

	// XAudio 2.7 GUIDs
	clsid := guid{0x5a508685, 0xa254, 0x4fba, [8]byte{0x9b, 0x82, 0x9a, 0x24, 0xb0, 0x03, 0x06, 0xaf}}
	iid := guid{0x8bcf1f58, 0x9fe7, 0x4583, [8]byte{0x8a, 0xc6, 0xe2, 0xad, 0xc4, 0x65, 0xc8, 0xbb}}
	var com unsafe.Pointer
	ret = coCreateInstance(&clsid, nil, 1, &iid, &com)
	if ret < 0 {
		return
	}

	pXAudio2 := (*IXAudio2)(com)
	ret = pXAudio2.Initialize(0, 0xffffffff)
	if ret < 0 {
		pXAudio2.Release()
		return
	}

	*ppXAudio2 = pXAudio2
	return
}
Ejemplo n.º 2
0
func init() {
	var nStdHandle = -11
	kernel32, _ = syscall.LoadLibrary("Kernel32.dll")
	GetStdHandle, _ = syscall.GetProcAddress(syscall.Handle(kernel32), "GetStdHandle")
	SetConsoleTextAttribute, _ = syscall.GetProcAddress(syscall.Handle(kernel32), "SetConsoleTextAttribute")
	//	ReadConsoleOutputAttribute, _ := syscall.GetProcAddress(syscall.Handle(kernel32), "ReadConsoleOutputAttribute")
	GetConsoleScreenBufferInfo, _ = syscall.GetProcAddress(syscall.Handle(kernel32), "GetConsoleScreenBufferInfo")
	hnd, _, _ = syscall.Syscall(uintptr(GetStdHandle), 1, uintptr(nStdHandle), 0, 0)
}
Ejemplo n.º 3
0
func (jst *TCFinger) Initdriver(pin *driverlayer.DriverArg) {
	var err error
	jst.stdll, err = syscall.LoadLibrary("third_party/teso/TesoLive.dll")
	if err != nil {
		panic("LoadLibrary " + err.Error())
	}
	jst.getRegisterImage, err = syscall.GetProcAddress(jst.stdll, "FPIGetTemplate")
	jst.getValidteImage, err = syscall.GetProcAddress(jst.stdll, "FPIGetFeature")
	jst.matchtz, err = syscall.GetProcAddress(jst.stdll, "FPIMatch")
}
Ejemplo n.º 4
0
func init() {
	var err error
	if msvcrt, err = syscall.LoadLibrary("msvcrt.dll"); err != nil {
		abort("LoadLibrary", err)
	}
	if setlocale, err = syscall.GetProcAddress(msvcrt, "setlocale"); err != nil {
		abort("GetProcAddress", err)
	}
	if wcstombs, err = syscall.GetProcAddress(msvcrt, "wcstombs"); err != nil {
		abort("GetProcAddress", err)
	}
	if mbstowcs, err = syscall.GetProcAddress(msvcrt, "mbstowcs"); err != nil {
		abort("GetProcAddress", err)
	}
}
Ejemplo n.º 5
0
// Returns total and free bytes available in a directory.
// It returns free space available to the user (including quota limitations),
// so it can be lower than the free space of the disk.
func DiskSpace(path string) (total, free int64, err error) {
	kernel32, err := syscall.LoadLibrary("Kernel32.dll")
	if err != nil {
		return
	}
	defer syscall.FreeLibrary(kernel32)
	GetDiskFreeSpaceEx, err := syscall.GetProcAddress(
		syscall.Handle(kernel32), "GetDiskFreeSpaceExW")
	if err != nil {
		return
	}
	lpFreeBytesAvailable := int64(0)
	lpTotalNumberOfBytes := int64(0)
	lpTotalNumberOfFreeBytes := int64(0)
	r1, _, e1 := syscall.Syscall6(uintptr(GetDiskFreeSpaceEx), 4,
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
		uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)), 0, 0)
	if r1 == 0 {
		if e1 != 0 {
			err = error(e1)
		} else {
			err = syscall.EINVAL
		}
		return
	}
	total = lpTotalNumberOfBytes
	free = lpFreeBytesAvailable
	return
}
Ejemplo n.º 6
0
func getProcAddr(lib syscall.Handle, name string) uintptr {
	addr, err := syscall.GetProcAddress(lib, name)
	if err != nil {
		panic(name + " " + err.Error())
	}
	return addr
}
Ejemplo n.º 7
0
func (p *Dll) InitalFunctions(funcNames ...string) error {
	if funcNames == nil {
		return nil
	}

	if !p.IsDllLoaded() {
		return errors.New("dll should loaded befor inital functions")
	}

	if p.funcProcs == nil {
		p.funcProcs = make(map[string]uintptr)
	}

	for _, funcName := range funcNames {
		funcName = strings.TrimSpace(funcName)
		if funcName == "" {
			return errors.New("function name could not be empty")
		}
		if proc, e := syscall.GetProcAddress(p.dllHandler, funcName); e != nil {
			return e
		} else {
			p.funcProcs[funcName] = proc
		}
	}
	return nil
}
Ejemplo n.º 8
0
// *************************************************************************
// We can probably delete this, it is an alternative version in case we have
// problems with simpler version above
// *************************************************************************
func freeDiskSpaceBytes2(dir string) (uint64, error) {
	kernel32, err := syscall.LoadLibrary("Kernel32.dll")
	if err != nil {
		log.Panic(err)
	}
	defer syscall.FreeLibrary(kernel32)
	GetDiskFreeSpaceEx, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetDiskFreeSpaceExW")
	if err != nil {
		return 0, err
	}
	lpFreeBytesAvailable := int64(0)
	lpTotalNumberOfBytes := int64(0)
	lpTotalNumberOfFreeBytes := int64(0)
	r, a, b := syscall.Syscall6(
		uintptr(GetDiskFreeSpaceEx),
		4,
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("C:"))),
		uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)),
		0,
		0,
	)
	log.Print("Disk space:", r, a, b, lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes)
	return uint64(lpFreeBytesAvailable), nil
}
Ejemplo n.º 9
0
func getSysProcAddr(m uint32, pname string) uintptr {
	p, e := syscall.GetProcAddress(m, pname)
	if e != 0 {
		panic("GetProcAddress failed on " + pname)
	}
	return uintptr(p)
}
Ejemplo n.º 10
0
func (jst *IDCGeneral) Initdriver(pin *driverlayer.DriverArg) {
	var err error
	jst.termdll, err = syscall.LoadLibrary("third_party/general/sdtapi.dll")
	if err != nil {
		panic("load library error:" + err.Error())
	}

	f := func(n string, res *uintptr) bool {
		*res, err = syscall.GetProcAddress(jst.termdll, n)
		if err != nil {
			syscall.FreeLibrary(jst.termdll)
			panic("load proc " + n + " error:" + err.Error())
		}
		return true
	}

	//获得dll的各种handle
	if f("SDT_OpenPort", &jst.initcomm) &&
		f("SDT_ClosePort", &jst.closecomm) &&
		f("SDT_StartFindIDCard", &jst.findcard) &&
		f("SDT_SelectIDCard", &jst.selectcard) &&
		f("SDT_ReadBaseMsg", &jst.readbasemsg) {
	} else {
		utils.Error("Init shensi Driver error...%s", err.Error())
	}

}
Ejemplo n.º 11
0
func testFail() {
	h, err := syscall.LoadLibrary("msvcrt")
	if err != nil {
		fmt.Println(err)
		return
	}

	defer syscall.FreeLibrary(h)

	proc, err := syscall.GetProcAddress(h, "memcpy")
	if err != nil {
		fmt.Println(err)
		return
	}

	// dst := unsafe.Pointer(uintptr(1))
	// src := unsafe.Pointer(uintptr(2))
	// count := unsafe.Pointer(uintptr(4))
	dst := uintptr(1)
	src := uintptr(2)
	count := uintptr(3)

	fmt.Println("test memcpy error in go...")
	r, _, _ := syscall.Syscall(uintptr(proc), 3, dst, src, count)

	fmt.Println(r)
	fmt.Println("should not run here")

}
Ejemplo n.º 12
0
func getProcAddr(lib syscall.Handle, name string) uintptr {
	addr, err := syscall.GetProcAddress(lib, name)
	if err != 0 {
		panic(name + " " + syscall.Errstr(err))
	}
	return addr
}
Ejemplo n.º 13
0
func Rename(src, dst string) error {
	kernel32, err := syscall.LoadLibrary("kernel32.dll")
	if err != nil {
		return err
	}
	defer syscall.FreeLibrary(kernel32)
	moveFileExUnicode, err := syscall.GetProcAddress(kernel32, "MoveFileExW")
	if err != nil {
		return err
	}

	srcString, err := syscall.UTF16PtrFromString(src)
	if err != nil {
		return err
	}

	dstString, err := syscall.UTF16PtrFromString(dst)
	if err != nil {
		return err
	}

	srcPtr := uintptr(unsafe.Pointer(srcString))
	dstPtr := uintptr(unsafe.Pointer(dstString))

	MOVEFILE_REPLACE_EXISTING := 0x1
	flag := uintptr(MOVEFILE_REPLACE_EXISTING)

	_, _, callErr := syscall.Syscall(uintptr(moveFileExUnicode), 3, srcPtr, dstPtr, flag)
	if callErr != 0 {
		return callErr
	}

	return nil
}
Ejemplo n.º 14
0
func getSysProcAddr(m uint32, pname string) uintptr {
	p, e := syscall.GetProcAddress(m, pname)
	if e != 0 {
		abortf("GetProcAddress(%s) failed with err=%d.\n", pname, e)
	}
	return uintptr(p)
}
Ejemplo n.º 15
0
func main() {
	//首先,准备输入参数, GetDiskFreeSpaceEx需要4个参数, 可查MSDN
	// dir := "C:"
	lpFreeBytesAvailable := int64(0) //注意类型需要跟API的类型相符
	lpTotalNumberOfBytes := int64(0)
	lpTotalNumberOfFreeBytes := int64(0)

	//获取方法的引用
	kernel32, err := syscall.LoadLibrary("Kernel32.dll") // 严格来说需要加上 defer syscall.FreeLibrary(kernel32)
	if err != nil {
		log.Println(err.Error())
	}
	defer syscall.FreeLibrary(kernel32)
	GetDiskFreeSpaceEx, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetDiskFreeSpaceExW")

	//执行之. 因为有4个参数,故取Syscall6才能放得下. 最后2个参数,自然就是0了
	r, _, errno := syscall.Syscall6(uintptr(GetDiskFreeSpaceEx), 4,
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("C:"))),
		uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)), 0, 0)

	if errno != 0 {
		log.Println(errno)
	}
	// 注意, errno并非error接口的, 不可能是nil
	// 而且,根据MSDN的说明,返回值为0就fail, 不为0就是成功
	if r != 0 {
		log.Printf("Free %dmb", lpTotalNumberOfFreeBytes/1024/1024)
	}
}
Ejemplo n.º 16
0
func init() {
	// Library
	libkernel32 = MustLoadLibrary("kernel32.dll")

	// Functions
	closeHandle = MustGetProcAddress(libkernel32, "CloseHandle")
	fileTimeToSystemTime = MustGetProcAddress(libkernel32, "FileTimeToSystemTime")
	getConsoleTitle = MustGetProcAddress(libkernel32, "GetConsoleTitleW")
	getConsoleWindow = MustGetProcAddress(libkernel32, "GetConsoleWindow")
	getLastError = MustGetProcAddress(libkernel32, "GetLastError")
	getLocaleInfo = MustGetProcAddress(libkernel32, "GetLocaleInfoW")
	getLogicalDriveStrings = MustGetProcAddress(libkernel32, "GetLogicalDriveStringsW")
	getModuleHandle = MustGetProcAddress(libkernel32, "GetModuleHandleW")
	getNumberFormat = MustGetProcAddress(libkernel32, "GetNumberFormatW")
	getProfileString = MustGetProcAddress(libkernel32, "GetProfileStringW")
	getThreadLocale = MustGetProcAddress(libkernel32, "GetThreadLocale")
	getThreadUILanguage, _ = syscall.GetProcAddress(syscall.Handle(libkernel32), "GetThreadUILanguage")
	getVersion = MustGetProcAddress(libkernel32, "GetVersion")
	globalAlloc = MustGetProcAddress(libkernel32, "GlobalAlloc")
	globalFree = MustGetProcAddress(libkernel32, "GlobalFree")
	globalLock = MustGetProcAddress(libkernel32, "GlobalLock")
	globalUnlock = MustGetProcAddress(libkernel32, "GlobalUnlock")
	moveMemory = MustGetProcAddress(libkernel32, "RtlMoveMemory")
	mulDiv = MustGetProcAddress(libkernel32, "MulDiv")
	setLastError = MustGetProcAddress(libkernel32, "SetLastError")
	systemTimeToFileTime = MustGetProcAddress(libkernel32, "SystemTimeToFileTime")

}
Ejemplo n.º 17
0
func getProcAddr(lib syscall.Handle, name string) uintptr {
	addr, err := syscall.GetProcAddress(lib, name)
	if err != nil {
		panic(fmt.Sprintf("[ERROR] getProcAddr %s: %v", name, err))
	}

	return addr
}
Ejemplo n.º 18
0
func MustGetProcAddress(lib uintptr, name string) uintptr {
	addr, errno := syscall.GetProcAddress(syscall.Handle(lib), name)
	if errno != 0 {
		panic(fmt.Sprintf(`syscall.GetProcAddress(%d, "%s") failed: %s`, lib, name, syscall.Errstr(errno)))
	}

	return uintptr(addr)
}
Ejemplo n.º 19
0
func (jst *ZZFinger) Initdriver(pin *driverlayer.DriverArg) {
	var err error
	jst.stdll, err = syscall.LoadLibrary("third_party/zhongzheng/FingerDLL.dll")
	if err != nil {
		panic("LoadLibrary " + err.Error())
	}
	jst.read, err = syscall.GetProcAddress(jst.stdll, "drive")
}
Ejemplo n.º 20
0
func (jst *HTPingjia) Initdriver(pin *driverlayer.DriverArg) {
	var err error
	jst.htdll, err = syscall.LoadLibrary("estimator_ht.dll")
	if err != nil {
		panic("LoadLibrary " + err.Error())
	}
	jst.startEstimate, err = syscall.GetProcAddress(jst.htdll, "StartEstimate")
}
Ejemplo n.º 21
0
func GetProcAddr(lib uintptr, name string) uintptr {
	addr, err := syscall.GetProcAddress(syscall.Handle(lib), name)
	if err != nil {
		panic(fmt.Sprintf("syscal.GetProcAddress(%d, '%s') failed: %s",
			lib, name, err.Error()))
	}
	return uintptr(addr)
}
Ejemplo n.º 22
0
func MustGetProcAddress(lib uintptr, name string) uintptr {
	addr, err := syscall.GetProcAddress(syscall.Handle(lib), name)
	if err != nil {
		panic("Failed to get the address function < " + name + " >," + err.Error())
	}

	return uintptr(addr)
}
Ejemplo n.º 23
0
func init() {
	dll, err := syscall.LoadLibrary("PowerPointWrapper.dll")
	if err != nil {
		panic(err)
	}

	procInitialize, err = syscall.GetProcAddress(dll, "Initialize")
	if err != nil {
		panic(err)
	}

	procUninitialize, err = syscall.GetProcAddress(dll, "Uninitialize")
	if err != nil {
		panic(err)
	}

	procPresentationCurrentSlideIndex, err = syscall.GetProcAddress(dll, "PresentationCurrentSlideIndex")
	if err != nil {
		panic(err)
	}

	procPresentationTotalSlidesCount, err = syscall.GetProcAddress(dll, "PresentationTotalSlidesCount")
	if err != nil {
		panic(err)
	}

	procPresentationPreviousSlide, err = syscall.GetProcAddress(dll, "PresentationPreviousSlide")
	if err != nil {
		panic(err)
	}

	procPresentationNextSlide, err = syscall.GetProcAddress(dll, "PresentationNextSlide")
	if err != nil {
		panic(err)
	}

	procPresentationCurrentSlideName, err = syscall.GetProcAddress(dll, "PresentationCurrentSlideName")
	if err != nil {
		panic(err)
	}

	procPresentationCurrentSlideNote, err = syscall.GetProcAddress(dll, "PresentationCurrentSlideNote")
	if err != nil {
		panic(err)
	}

	procRefreshPresentationSlidesThumbnail, err = syscall.GetProcAddress(dll, "RefreshPresentationSlidesThumbnail")
	if err != nil {
		panic(err)
	}
}
Ejemplo n.º 24
0
func init() {
	k32, err := syscall.LoadLibrary("kernel32.dll")
	if err != nil {
		panic("LoadLibrary " + err.Error())
	}
	defer syscall.FreeLibrary(k32)
	versionAddr, err = syscall.GetProcAddress(k32, "GetVersion")
}
Ejemplo n.º 25
0
func MustGetProcAddress(lib uintptr, name string) uintptr {
	addr, err := syscall.GetProcAddress(syscall.Handle(lib), name)
	if err != nil {
		panic(err)
	}

	return uintptr(addr)
}
Ejemplo n.º 26
0
func MustGetProcAddress(lib uint32, name string) uint32 {
	addr, errno := syscall.GetProcAddress(lib, name)
	if errno != 0 {
		panic(fmt.Sprintf(`syscall.GetProcAddress(%d, "%s") failed: %s`, lib, name, syscall.Errstr(errno)))
	}

	return addr
}
Ejemplo n.º 27
0
func init() {
	kernel32, loadErr := syscall.LoadLibrary("kernel32.dll")
	if loadErr != nil {
		fmt.Println("loadErr", loadErr)
	}
	defer syscall.FreeLibrary(kernel32)
	_SetConsoleTitle, _ = syscall.GetProcAddress(kernel32, "SetConsoleTitleW")

}
Ejemplo n.º 28
0
func (jst *STICCard) Initdriver(pin *driverlayer.DriverArg) {
	var err error
	jst.termdll, err = syscall.LoadLibrary("third_party/shengteng/iccard_shengteng.dll")
	if err != nil {
		panic("load library error:" + err.Error())
	}
	jst.read, err = syscall.GetProcAddress(jst.termdll, "drive")

}
Ejemplo n.º 29
0
func GetThreadUILanguage() LANGID {
	getThreadUILanguageAddr, _ := syscall.GetProcAddress(libkernel32.Handle, "GetThreadUILanguage")
	if getThreadUILanguageAddr == 0 {
		return 0
	}

	ret, _, _ := getThreadUILanguage.Call()

	return LANGID(ret)
}
Ejemplo n.º 30
0
func GetLoadLibrary() (uintptr, error) {
	handle, err := win32.GetModuleHandle(syscall.StringToUTF16Ptr("kernel32"))
	if err != nil {
		return 0, err
	}
	addr, err := syscall.GetProcAddress(handle, "LoadLibraryW")
	if err != nil {
		return 0, os.NewSyscallError("GetProcAddress", err)
	}
	return addr, nil
}