- 修正 WTS 会话相关类型、枚举与活动会话选择逻辑 - 对齐 FILE_ID_DESCRIPTOR 布局与 FILE_ID_TYPE 语义,修复 OpenFileById 调用前提 - 修正 user32/shell32/kernel32 部分 API 的返回值、参数个数与错误处理 - 完善剪贴板更新格式读取的缓冲区重试逻辑 - 补充常用进程、线程、调试、桌面与会话 helper - 增加结构体布局、会话查询、剪贴板、CreateProcess 等回归测试 - 将默认 CreateProcess 相关测试切到 helper 进程,并保留显式开启的 cmd.exe 集成覆盖
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package win32api
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func WTSQueryUserToken(SessionId DWORD, phToken *HANDLE) error {
|
|
WTGet, err := getProcAddr("wtsapi32.dll", "WTSQueryUserToken")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
r, _, errno := syscall.Syscall(WTGet, 2, uintptr(SessionId), uintptr(unsafe.Pointer(phToken)), 0)
|
|
if r == 0 {
|
|
if errno != 0 {
|
|
return error(errno)
|
|
}
|
|
return syscall.EINVAL
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func WTSEnumerateSessions(hServer HANDLE, Reserved, Version DWORD, ppSessionInfo *HANDLE, pCount *DWORD) error {
|
|
WT, err := getProcAddr("wtsapi32.dll", "WTSEnumerateSessionsW")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
r, _, errno := syscall.Syscall6(WT, 5, uintptr(hServer), uintptr(Reserved), uintptr(Version), uintptr(unsafe.Pointer(ppSessionInfo)), uintptr(unsafe.Pointer(pCount)), 0)
|
|
if r == 0 {
|
|
if errno != 0 {
|
|
return error(errno)
|
|
}
|
|
return syscall.EINVAL
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func WTSFreeMemory(pMemory HANDLE) error {
|
|
wfm, err := getProcAddr("wtsapi32.dll", "WTSFreeMemory")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
syscall.Syscall(wfm, 1, uintptr(pMemory), 0, 0)
|
|
return nil
|
|
}
|
|
|
|
func WTSQuerySessionInformation(hServer HANDLE, sessionID DWORD, wtsInfoClass WTS_INFO_CLASS, ppBuffer *HANDLE, pBytesReturned *DWORD) error {
|
|
if ppBuffer == nil || pBytesReturned == nil {
|
|
return syscall.EINVAL
|
|
}
|
|
|
|
proc, err := getProcAddr("wtsapi32.dll", "WTSQuerySessionInformationW")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
r, _, errno := syscall.Syscall6(
|
|
proc,
|
|
5,
|
|
uintptr(hServer),
|
|
uintptr(sessionID),
|
|
uintptr(wtsInfoClass),
|
|
uintptr(unsafe.Pointer(ppBuffer)),
|
|
uintptr(unsafe.Pointer(pBytesReturned)),
|
|
0,
|
|
)
|
|
if r == 0 {
|
|
if errno != 0 {
|
|
return error(errno)
|
|
}
|
|
return syscall.EINVAL
|
|
}
|
|
return nil
|
|
}
|