Esempio n. 1
0
func CreateService(scManager syscall.Handle, serviceName *uint16, databaseName *uint16, desiredAccess uint32, serviceType uint32, startType uint32, errorControl uint32, binaryPathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (syscall.Handle, error) {
	r1, _, e1 := syscall.Syscall15(
		procCreateServiceW.Addr(),
		13,
		uintptr(scManager),
		uintptr(unsafe.Pointer(serviceName)),
		uintptr(unsafe.Pointer(databaseName)),
		uintptr(desiredAccess),
		uintptr(serviceType),
		uintptr(startType),
		uintptr(errorControl),
		uintptr(unsafe.Pointer(binaryPathName)),
		uintptr(unsafe.Pointer(loadOrderGroup)),
		uintptr(unsafe.Pointer(tagId)),
		uintptr(unsafe.Pointer(dependencies)),
		uintptr(unsafe.Pointer(serviceStartName)),
		uintptr(unsafe.Pointer(password)),
		0,
		0)
	if r1 == 0 {
		if e1 != ERROR_SUCCESS {
			return 0, e1
		} else {
			return 0, syscall.EINVAL
		}
	}
	return syscall.Handle(r1), nil
}
Esempio n. 2
0
func Call(proc uintptr, args ...uintptr) (r1, r2 uintptr, lastErr error) {
	addr := proc
	switch len(args) {
	case 0:
		return syscall.Syscall(addr, uintptr(len(args)), 0, 0, 0)
	case 1:
		return syscall.Syscall(addr, uintptr(len(args)), args[0], 0, 0)
	case 2:
		return syscall.Syscall(addr, uintptr(len(args)), args[0], args[1], 0)
	case 3:
		return syscall.Syscall(addr, uintptr(len(args)), args[0], args[1], args[2])
	case 4:
		return syscall.Syscall6(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], 0, 0)
	case 5:
		return syscall.Syscall6(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], 0)
	case 6:
		return syscall.Syscall6(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5])
	case 7:
		return syscall.Syscall9(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], 0, 0)
	case 8:
		return syscall.Syscall9(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], 0)
	case 9:
		return syscall.Syscall9(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8])
	case 10:
		return syscall.Syscall12(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], 0, 0)
	case 11:
		return syscall.Syscall12(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], 0)
	case 12:
		return syscall.Syscall12(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11])
	case 13:
		return syscall.Syscall15(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], 0, 0)
	case 14:
		return syscall.Syscall15(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], 0)
	case 15:
		return syscall.Syscall15(addr, uintptr(len(args)), args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14])
	default:
		panic(fmt.Sprintf("Call \"%d\" with too many arguments @ %d.", proc, len(args)))
	}

	return
}
Esempio n. 3
0
func CreateService(mgr syscall.Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle syscall.Handle, err error) {
	r0, _, e1 := syscall.Syscall15(procCreateServiceW.Addr(), 13, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(unsafe.Pointer(displayName)), uintptr(access), uintptr(srvType), uintptr(startType), uintptr(errCtl), uintptr(unsafe.Pointer(pathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), 0, 0)
	handle = syscall.Handle(r0)
	if handle == 0 {
		if e1 != 0 {
			err = error(e1)
		} else {
			err = syscall.EINVAL
		}
	}
	return
}
Esempio n. 4
0
// Call executes procedure p with arguments a. It will panic, if more then 15 arguments
// are supplied.
//
// The returned error is always non-nil, constructed from the result of GetLastError.
// Callers must inspect the primary return value to decide whether an error occurred
// (according to the semantics of the specific function being called) before consulting
// the error. The error will be guaranteed to contain windows.Errno.
func (p *Proc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) {
	switch len(a) {
	case 0:
		return syscall.Syscall(p.Addr(), uintptr(len(a)), 0, 0, 0)
	case 1:
		return syscall.Syscall(p.Addr(), uintptr(len(a)), a[0], 0, 0)
	case 2:
		return syscall.Syscall(p.Addr(), uintptr(len(a)), a[0], a[1], 0)
	case 3:
		return syscall.Syscall(p.Addr(), uintptr(len(a)), a[0], a[1], a[2])
	case 4:
		return syscall.Syscall6(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], 0, 0)
	case 5:
		return syscall.Syscall6(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], 0)
	case 6:
		return syscall.Syscall6(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5])
	case 7:
		return syscall.Syscall9(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], 0, 0)
	case 8:
		return syscall.Syscall9(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], 0)
	case 9:
		return syscall.Syscall9(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8])
	case 10:
		return syscall.Syscall12(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], 0, 0)
	case 11:
		return syscall.Syscall12(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], 0)
	case 12:
		return syscall.Syscall12(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11])
	case 13:
		return syscall.Syscall15(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], 0, 0)
	case 14:
		return syscall.Syscall15(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], 0)
	case 15:
		return syscall.Syscall15(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14])
	default:
		panic("Call " + p.Name + " with too many arguments " + itoa(len(a)) + ".")
	}
	return
}
Esempio n. 5
0
func (p comProc) Call(a ...uintptr) (r1, r2 uintptr, lastErr syscall.Errno) {
	switch len(a) {
	case 0:
		return syscall.Syscall(uintptr(p), uintptr(len(a)), 0, 0, 0)
	case 1:
		return syscall.Syscall(uintptr(p), uintptr(len(a)), a[0], 0, 0)
	case 2:
		return syscall.Syscall(uintptr(p), uintptr(len(a)), a[0], a[1], 0)
	case 3:
		return syscall.Syscall(uintptr(p), uintptr(len(a)), a[0], a[1], a[2])
	case 4:
		return syscall.Syscall6(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], 0, 0)
	case 5:
		return syscall.Syscall6(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], 0)
	case 6:
		return syscall.Syscall6(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5])
	case 7:
		return syscall.Syscall9(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], 0, 0)
	case 8:
		return syscall.Syscall9(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], 0)
	case 9:
		return syscall.Syscall9(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8])
	case 10:
		return syscall.Syscall12(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], 0, 0)
	case 11:
		return syscall.Syscall12(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], 0)
	case 12:
		return syscall.Syscall12(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11])
	case 13:
		return syscall.Syscall15(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], 0, 0)
	case 14:
		return syscall.Syscall15(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], 0)
	case 15:
		return syscall.Syscall15(uintptr(p), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14])
	}
	panic("too many arguments")
}
Esempio n. 6
0
//为调用DLL中的方法提供一个统一的接口
func CallProc(handle uintptr, args ...uintptr) (r1, r2 uintptr, err syscall.Errno) {
	l := uintptr(len(args))
	switch {
	case l <= 3:
		tmp := make([]uintptr, 3)
		for i, v := range args {
			tmp[i] = v
		}
		return syscall.Syscall(handle, l, tmp[0], tmp[1], tmp[2])
	case l <= 6:
		tmp := make([]uintptr, 6)
		for i, v := range args {
			tmp[i] = v
		}
		return syscall.Syscall6(handle, l, tmp[0], tmp[1], tmp[2],
			tmp[3], tmp[4], tmp[5])
	case l <= 9:
		tmp := make([]uintptr, 9)
		for i, v := range args {
			tmp[i] = v
		}
		return syscall.Syscall9(handle, l, tmp[0], tmp[1], tmp[2],
			tmp[3], tmp[4], tmp[5], tmp[6],
			tmp[7], tmp[8])
	case l <= 12:
		tmp := make([]uintptr, 12)
		for i, v := range args {
			tmp[i] = v
		}
		return syscall.Syscall12(handle, l, tmp[0], tmp[1], tmp[2],
			tmp[3], tmp[4], tmp[5], tmp[6],
			tmp[7], tmp[8], tmp[9],
			tmp[10], tmp[11])
	case l <= 15:
		tmp := make([]uintptr, 15)
		for i, v := range args {
			tmp[i] = v
		}
		return syscall.Syscall15(handle, l, tmp[0], tmp[1], tmp[2],
			tmp[3], tmp[4], tmp[5], tmp[6],
			tmp[7], tmp[8], tmp[9],
			tmp[10], tmp[11], tmp[12],
			tmp[13], tmp[14])
	default:
		return uintptr(0), uintptr(0), syscall.E2BIG
	}
}
Esempio n. 7
0
func CreateFontA(nHeight, nWidth, nEscapement, nOrientation, fnWeight int32, fdwItalic, fdwUnderline, fdwStrikeOut, fdwCharSet, fdwOutputPrecision, fdwClipPrecision, fdwQuality, fdwPitchAndFamily uint32, lpszFace *uint16) HFONT {
	ret, _, _ := syscall.Syscall15(MustGetProcAddress(libgdi32, "CreateFontA"), 14,
		uintptr(nHeight),
		uintptr(nWidth),
		uintptr(nEscapement),
		uintptr(nOrientation),
		uintptr(fnWeight),
		uintptr(fdwItalic),
		uintptr(fdwUnderline),
		uintptr(fdwStrikeOut),
		uintptr(fdwCharSet),
		uintptr(fdwOutputPrecision),
		uintptr(fdwClipPrecision),
		uintptr(fdwQuality),
		uintptr(fdwPitchAndFamily),
		uintptr(unsafe.Pointer(lpszFace)),
		0)

	return HFONT(ret)
}
Esempio n. 8
0
func StretchDIBits(hdcDest HDC, nXDest, nYDest, nWidthDest, nHeightDest int32, nXSrc, nYSrc, nWidthSrc, nHeightSrc int32, lpBits uintptr, lpBitsInfo *BITMAPINFO, iUsage uint32, dwRop int64) bool {
	ret, _, _ := syscall.Syscall15(stretchDIBits, 13,
		uintptr(hdcDest),
		uintptr(nXDest),
		uintptr(nYDest),
		uintptr(nWidthDest),
		uintptr(nHeightDest),
		uintptr(nXSrc),
		uintptr(nYSrc),
		uintptr(nWidthSrc),
		uintptr(nHeightSrc),
		uintptr(lpBits),
		uintptr(unsafe.Pointer(lpBitsInfo)),
		uintptr(iUsage),
		uintptr(dwRop),
		0,
		0)

	return ret != 0
}
Esempio n. 9
0
// Call calls f with the argument list specified by argPtr and argLen.
// The argument list needs to have the same layout in memory as the arguments
// that f expects.
// argPtr points to the first argument in the list. argLen is the number of
// CPU words in the argument list. Normally this is the same as the number of
// arguments, but it is larger if any of the arguments is larger than a CPU
// word.
//
// There are two main options for how to construct the argument list.
// One is to use the argument list of a wrapper function; take the address of
// the first argument (or potentially the method receiver).
// The other is to create a custom struct type to hold the argument list.
func (f Func) Call(argPtr unsafe.Pointer, argLen uintptr) (r1 uintptr, r2 uintptr, err error) {
	if argLen <= 3 {
		argPtrs := (*Args)(argPtr)
		args := make([]uintptr, 3, 3)
		for i := uintptr(0); i < argLen; i++ {
			args[i] = argPtrs.Args[i]
		}
		return syscall.Syscall(uintptr(f), argLen, args[0], args[1], args[2])
	} else if argLen <= 6 {
		argPtrs := (*Args)(argPtr)
		args := make([]uintptr, 6, 6)
		for i := uintptr(0); i < argLen; i++ {
			args[i] = argPtrs.Args[i]
		}
		return syscall.Syscall6(uintptr(f), argLen, args[0], args[1], args[2], args[3], args[4], args[5])
	} else if argLen <= 9 {
		argPtrs := (*Args)(argPtr)
		args := make([]uintptr, 9, 9)
		for i := uintptr(0); i < argLen; i++ {
			args[i] = argPtrs.Args[i]
		}
		return syscall.Syscall9(uintptr(f), argLen, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8])
	} else if argLen <= 12 {
		argPtrs := (*Args)(argPtr)
		args := make([]uintptr, 12, 12)
		for i := uintptr(0); i < argLen; i++ {
			args[i] = argPtrs.Args[i]
		}
		return syscall.Syscall12(uintptr(f), argLen, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11])
	} else {
		argPtrs := (*Args)(argPtr)
		args := make([]uintptr, 15, 15)
		for i := uintptr(0); i < argLen; i++ {
			args[i] = argPtrs.Args[i]
		}
		return syscall.Syscall15(uintptr(f), argLen, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14])
	}
}
Esempio n. 10
0
//export qtdrv
func qtdrv(p unsafe.Pointer, typeid, funcid C.int, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 unsafe.Pointer) C.int {
	r0, _, _ := syscall.Syscall15(proc_qtdrv_addr, 15, uintptr(p), uintptr(typeid), uintptr(funcid), uintptr(p1), uintptr(p2), uintptr(p3), uintptr(p4), uintptr(p5), uintptr(p6), uintptr(p7), uintptr(p8), uintptr(p9), uintptr(p10), uintptr(p11), uintptr(p12))
	return C.int(r0)
}
Esempio n. 11
0
func (dllCls *DLLClass) Call(apiName interface{}, argvs ...uintptr) uintptr {
	var nArgvs = uintptr(len(argvs))
	var apiFunc uintptr

	switch apiName.(type) {
	case string:
		apiFunc = MustGetProcAddress(dllCls.Handle, apiName.(string))
	case uintptr:
		apiFunc = apiName.(uintptr)
	default:
		panic("The parameters of the function < " + apiName.(string) + " > must be uintptr or string type")
	}

	if nArgvs <= 3 {
		cArgs := []uintptr{0, 0, 0}
		for k, v := range argvs {
			cArgs[k] = v
		}

		apiRet, _, _ := syscall.Syscall(apiFunc, nArgvs,
			cArgs[0],
			cArgs[1],
			cArgs[2])

		return apiRet
	} else if nArgvs <= 6 {
		cArgs := []uintptr{0, 0, 0, 0, 0, 0}
		for k, v := range argvs {
			cArgs[k] = v
		}

		apiRet, _, _ := syscall.Syscall6(apiFunc, nArgvs,
			cArgs[0],
			cArgs[1],
			cArgs[2],
			cArgs[3],
			cArgs[4],
			cArgs[5])

		return apiRet
	} else if nArgvs <= 9 {
		cArgs := []uintptr{0, 0, 0, 0, 0, 0, 0, 0, 0}
		for k, v := range argvs {
			cArgs[k] = v
		}

		apiRet, _, _ := syscall.Syscall9(apiFunc, nArgvs,
			cArgs[0],
			cArgs[1],
			cArgs[2],
			cArgs[3],
			cArgs[4],
			cArgs[5],
			cArgs[6],
			cArgs[7],
			cArgs[8])

		return apiRet
	} else if nArgvs <= 12 {
		cArgs := []uintptr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for k, v := range argvs {
			cArgs[k] = v
		}

		apiRet, _, _ := syscall.Syscall12(apiFunc, nArgvs,
			cArgs[0],
			cArgs[1],
			cArgs[2],
			cArgs[3],
			cArgs[4],
			cArgs[5],
			cArgs[6],
			cArgs[7],
			cArgs[8],
			cArgs[9],
			cArgs[10],
			cArgs[11])

		return apiRet
	} else if nArgvs <= 15 {
		cArgs := []uintptr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for k, v := range argvs {
			cArgs[k] = v
		}

		apiRet, _, _ := syscall.Syscall15(apiFunc, nArgvs,
			cArgs[0],
			cArgs[1],
			cArgs[2],
			cArgs[3],
			cArgs[4],
			cArgs[5],
			cArgs[6],
			cArgs[7],
			cArgs[8],
			cArgs[9],
			cArgs[10],
			cArgs[11],
			cArgs[12],
			cArgs[13],
			cArgs[14])

		return apiRet
	} else {
		panic("Function < " + apiName.(string) + " > Call too many parameters.")
	}
}
Esempio n. 12
0
func (p *Dll) Call(funcName string, funcParams ...interface{}) (result FuncCallResult, err error) {
	var lenParam uintptr = uintptr(len(funcParams))

	if p.funcProcs == nil {
		err = errors.New("function address not initaled")
		return
	}

	var funcAddress uintptr
	if addr, exist := p.funcProcs[funcName]; !exist {
		err = errors.New("function address not exist")
		return
	} else {
		funcAddress = addr
	}

	var r1, r2 uintptr
	var errno syscall.Errno

	var a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr

	for parmIndex, param := range funcParams {
		var vPtr uintptr = 0

		switch v := param.(type) {
		case string:
			vPtr = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v)))
		case *string:
			vPtr = uintptr(unsafe.Pointer(syscall.StringBytePtr(*v)))
		case bool:
			vPtr = uintptr(unsafe.Pointer(&v))
		case int:
			vPtr = uintptr(v)
		case int8:
			vPtr = uintptr(v)
		case uint8:
			vPtr = uintptr(v)
		case *uint8:
			vPtr = uintptr(unsafe.Pointer(v))
		case int16:
			vPtr = uintptr(v)
		case uint16:
			vPtr = uintptr(v)
		case *uint16:
			vPtr = uintptr(unsafe.Pointer(v))
		case int32:
			vPtr = uintptr(v)
		case uint32:
			vPtr = uintptr(v)
		case *uint32:
			vPtr = uintptr(unsafe.Pointer(v))
		case int64:
			vPtr = uintptr(v)
		case uint64:
			vPtr = uintptr(v)
		case *uint64:
			vPtr = uintptr(unsafe.Pointer(v))
		case float32:
			vPtr = uintptr(v)
		case float64:
			vPtr = uintptr(v)
		case []byte:
			vPtr = uintptr(unsafe.Pointer(&v[0]))
		case uintptr:
			ptr, _ := param.(uintptr)
			vPtr = ptr
		default:
			err = fmt.Errorf("unsupport convert type %v to uintptr", reflect.TypeOf(param))
			return
		}

		switch parmIndex + 1 {
		case 1:
			a1 = vPtr
		case 2:
			a2 = vPtr
		case 3:
			a3 = vPtr
		case 4:
			a4 = vPtr
		case 5:
			a5 = vPtr
		case 6:
			a6 = vPtr
		case 7:
			a7 = vPtr
		case 8:
			a8 = vPtr
		case 9:
			a9 = vPtr
		case 10:
			a10 = vPtr
		case 11:
			a11 = vPtr
		case 12:
			a12 = vPtr
		case 13:
			a13 = vPtr
		case 14:
			a14 = vPtr
		case 15:
			a15 = vPtr
		}
	}

	r1, r2, errno = syscall.Syscall15(funcAddress, lenParam, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
	result.Ret1 = r1
	result.Ret2 = r2
	result.Errno = errno

	return
}