mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-01 00:23:56 +08:00 
			
		
		
		
	
							
								
								
									
										81
									
								
								vendor/golang.org/x/sys/windows/exec_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										81
									
								
								vendor/golang.org/x/sys/windows/exec_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -9,6 +9,8 @@ package windows | ||||
| import ( | ||||
| 	errorspkg "errors" | ||||
| 	"unsafe" | ||||
|  | ||||
| 	"golang.org/x/sys/internal/unsafeheader" | ||||
| ) | ||||
|  | ||||
| // EscapeArg rewrites command line argument s as prescribed | ||||
| @@ -78,6 +80,40 @@ func EscapeArg(s string) string { | ||||
| 	return string(qs[:j]) | ||||
| } | ||||
|  | ||||
| // ComposeCommandLine escapes and joins the given arguments suitable for use as a Windows command line, | ||||
| // in CreateProcess's CommandLine argument, CreateService/ChangeServiceConfig's BinaryPathName argument, | ||||
| // or any program that uses CommandLineToArgv. | ||||
| func ComposeCommandLine(args []string) string { | ||||
| 	var commandLine string | ||||
| 	for i := range args { | ||||
| 		if i > 0 { | ||||
| 			commandLine += " " | ||||
| 		} | ||||
| 		commandLine += EscapeArg(args[i]) | ||||
| 	} | ||||
| 	return commandLine | ||||
| } | ||||
|  | ||||
| // DecomposeCommandLine breaks apart its argument command line into unescaped parts using CommandLineToArgv, | ||||
| // as gathered from GetCommandLine, QUERY_SERVICE_CONFIG's BinaryPathName argument, or elsewhere that | ||||
| // command lines are passed around. | ||||
| func DecomposeCommandLine(commandLine string) ([]string, error) { | ||||
| 	if len(commandLine) == 0 { | ||||
| 		return []string{}, nil | ||||
| 	} | ||||
| 	var argc int32 | ||||
| 	argv, err := CommandLineToArgv(StringToUTF16Ptr(commandLine), &argc) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	defer LocalFree(Handle(unsafe.Pointer(argv))) | ||||
| 	var args []string | ||||
| 	for _, v := range (*argv)[:argc] { | ||||
| 		args = append(args, UTF16ToString((*v)[:])) | ||||
| 	} | ||||
| 	return args, nil | ||||
| } | ||||
|  | ||||
| func CloseOnExec(fd Handle) { | ||||
| 	SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0) | ||||
| } | ||||
| @@ -101,8 +137,8 @@ func FullPath(name string) (path string, err error) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // NewProcThreadAttributeList allocates a new ProcThreadAttributeList, with the requested maximum number of attributes. | ||||
| func NewProcThreadAttributeList(maxAttrCount uint32) (*ProcThreadAttributeList, error) { | ||||
| // NewProcThreadAttributeList allocates a new ProcThreadAttributeListContainer, with the requested maximum number of attributes. | ||||
| func NewProcThreadAttributeList(maxAttrCount uint32) (*ProcThreadAttributeListContainer, error) { | ||||
| 	var size uintptr | ||||
| 	err := initializeProcThreadAttributeList(nil, maxAttrCount, 0, &size) | ||||
| 	if err != ERROR_INSUFFICIENT_BUFFER { | ||||
| @@ -111,10 +147,9 @@ func NewProcThreadAttributeList(maxAttrCount uint32) (*ProcThreadAttributeList, | ||||
| 		} | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	const psize = unsafe.Sizeof(uintptr(0)) | ||||
| 	// size is guaranteed to be ≥1 by InitializeProcThreadAttributeList. | ||||
| 	al := (*ProcThreadAttributeList)(unsafe.Pointer(&make([]unsafe.Pointer, (size+psize-1)/psize)[0])) | ||||
| 	err = initializeProcThreadAttributeList(al, maxAttrCount, 0, &size) | ||||
| 	al := &ProcThreadAttributeListContainer{data: (*ProcThreadAttributeList)(unsafe.Pointer(&make([]byte, size)[0]))} | ||||
| 	err = initializeProcThreadAttributeList(al.data, maxAttrCount, 0, &size) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -122,11 +157,39 @@ func NewProcThreadAttributeList(maxAttrCount uint32) (*ProcThreadAttributeList, | ||||
| } | ||||
|  | ||||
| // Update modifies the ProcThreadAttributeList using UpdateProcThreadAttribute. | ||||
| func (al *ProcThreadAttributeList) Update(attribute uintptr, flags uint32, value unsafe.Pointer, size uintptr, prevValue unsafe.Pointer, returnedSize *uintptr) error { | ||||
| 	return updateProcThreadAttribute(al, flags, attribute, value, size, prevValue, returnedSize) | ||||
| // Note that the value passed to this function will be copied into memory | ||||
| // allocated by LocalAlloc, the contents of which should not contain any | ||||
| // Go-managed pointers, even if the passed value itself is a Go-managed | ||||
| // pointer. | ||||
| func (al *ProcThreadAttributeListContainer) Update(attribute uintptr, value unsafe.Pointer, size uintptr) error { | ||||
| 	alloc, err := LocalAlloc(LMEM_FIXED, uint32(size)) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	var src, dst []byte | ||||
| 	hdr := (*unsafeheader.Slice)(unsafe.Pointer(&src)) | ||||
| 	hdr.Data = value | ||||
| 	hdr.Cap = int(size) | ||||
| 	hdr.Len = int(size) | ||||
| 	hdr = (*unsafeheader.Slice)(unsafe.Pointer(&dst)) | ||||
| 	hdr.Data = unsafe.Pointer(alloc) | ||||
| 	hdr.Cap = int(size) | ||||
| 	hdr.Len = int(size) | ||||
| 	copy(dst, src) | ||||
| 	al.heapAllocations = append(al.heapAllocations, alloc) | ||||
| 	return updateProcThreadAttribute(al.data, 0, attribute, unsafe.Pointer(alloc), size, nil, nil) | ||||
| } | ||||
|  | ||||
| // Delete frees ProcThreadAttributeList's resources. | ||||
| func (al *ProcThreadAttributeList) Delete() { | ||||
| 	deleteProcThreadAttributeList(al) | ||||
| func (al *ProcThreadAttributeListContainer) Delete() { | ||||
| 	deleteProcThreadAttributeList(al.data) | ||||
| 	for i := range al.heapAllocations { | ||||
| 		LocalFree(Handle(al.heapAllocations[i])) | ||||
| 	} | ||||
| 	al.heapAllocations = nil | ||||
| } | ||||
|  | ||||
| // List returns the actual ProcThreadAttributeList to be passed to StartupInfoEx. | ||||
| func (al *ProcThreadAttributeListContainer) List() *ProcThreadAttributeList { | ||||
| 	return al.data | ||||
| } | ||||
|   | ||||
							
								
								
									
										1
									
								
								vendor/golang.org/x/sys/windows/syscall_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/golang.org/x/sys/windows/syscall_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -220,6 +220,7 @@ func NewCallbackCDecl(fn interface{}) uintptr { | ||||
| //sys	CancelIo(s Handle) (err error) | ||||
| //sys	CancelIoEx(s Handle, o *Overlapped) (err error) | ||||
| //sys	CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) = CreateProcessW | ||||
| //sys	CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) = advapi32.CreateProcessAsUserW | ||||
| //sys   initializeProcThreadAttributeList(attrlist *ProcThreadAttributeList, attrcount uint32, flags uint32, size *uintptr) (err error) = InitializeProcThreadAttributeList | ||||
| //sys   deleteProcThreadAttributeList(attrlist *ProcThreadAttributeList) = DeleteProcThreadAttributeList | ||||
| //sys   updateProcThreadAttribute(attrlist *ProcThreadAttributeList, flags uint32, attr uintptr, value unsafe.Pointer, size uintptr, prevvalue unsafe.Pointer, returnedsize *uintptr) (err error) = UpdateProcThreadAttribute | ||||
|   | ||||
							
								
								
									
										19
									
								
								vendor/golang.org/x/sys/windows/types_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								vendor/golang.org/x/sys/windows/types_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -680,7 +680,7 @@ const ( | ||||
| 	WTD_CHOICE_CERT    = 5 | ||||
|  | ||||
| 	WTD_STATEACTION_IGNORE           = 0x00000000 | ||||
| 	WTD_STATEACTION_VERIFY           = 0x00000010 | ||||
| 	WTD_STATEACTION_VERIFY           = 0x00000001 | ||||
| 	WTD_STATEACTION_CLOSE            = 0x00000002 | ||||
| 	WTD_STATEACTION_AUTO_CACHE       = 0x00000003 | ||||
| 	WTD_STATEACTION_AUTO_CACHE_FLUSH = 0x00000004 | ||||
| @@ -909,14 +909,15 @@ type StartupInfoEx struct { | ||||
|  | ||||
| // ProcThreadAttributeList is a placeholder type to represent a PROC_THREAD_ATTRIBUTE_LIST. | ||||
| // | ||||
| // To create a *ProcThreadAttributeList, use NewProcThreadAttributeList, and | ||||
| // free its memory using ProcThreadAttributeList.Delete. | ||||
| type ProcThreadAttributeList struct { | ||||
| 	// This is of type unsafe.Pointer, not of type byte or uintptr, because | ||||
| 	// the contents of it is mostly a list of pointers, and in most cases, | ||||
| 	// that's a list of pointers to Go-allocated objects. In order to keep | ||||
| 	// the GC from collecting these objects, we declare this as unsafe.Pointer. | ||||
| 	_ [1]unsafe.Pointer | ||||
| // To create a *ProcThreadAttributeList, use NewProcThreadAttributeList, update | ||||
| // it with ProcThreadAttributeListContainer.Update, free its memory using | ||||
| // ProcThreadAttributeListContainer.Delete, and access the list itself using | ||||
| // ProcThreadAttributeListContainer.List. | ||||
| type ProcThreadAttributeList struct{} | ||||
|  | ||||
| type ProcThreadAttributeListContainer struct { | ||||
| 	data            *ProcThreadAttributeList | ||||
| 	heapAllocations []uintptr | ||||
| } | ||||
|  | ||||
| type ProcessInformation struct { | ||||
|   | ||||
							
								
								
									
										13
									
								
								vendor/golang.org/x/sys/windows/zsyscall_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								vendor/golang.org/x/sys/windows/zsyscall_windows.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -69,6 +69,7 @@ var ( | ||||
| 	procConvertStringSecurityDescriptorToSecurityDescriptorW = modadvapi32.NewProc("ConvertStringSecurityDescriptorToSecurityDescriptorW") | ||||
| 	procConvertStringSidToSidW                               = modadvapi32.NewProc("ConvertStringSidToSidW") | ||||
| 	procCopySid                                              = modadvapi32.NewProc("CopySid") | ||||
| 	procCreateProcessAsUserW                                 = modadvapi32.NewProc("CreateProcessAsUserW") | ||||
| 	procCreateServiceW                                       = modadvapi32.NewProc("CreateServiceW") | ||||
| 	procCreateWellKnownSid                                   = modadvapi32.NewProc("CreateWellKnownSid") | ||||
| 	procCryptAcquireContextW                                 = modadvapi32.NewProc("CryptAcquireContextW") | ||||
| @@ -553,6 +554,18 @@ func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) { | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) { | ||||
| 	var _p0 uint32 | ||||
| 	if inheritHandles { | ||||
| 		_p0 = 1 | ||||
| 	} | ||||
| 	r1, _, e1 := syscall.Syscall12(procCreateProcessAsUserW.Addr(), 11, uintptr(token), uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0) | ||||
| 	if r1 == 0 { | ||||
| 		err = errnoErr(e1) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func CreateService(mgr 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 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 = Handle(r0) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 CrazyMax
					CrazyMax