|
|
@@ -92,11 +92,11 @@ func UTF16FromString(s string) ([]uint16, error) {
|
|
|
}
|
|
|
|
|
|
// UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
|
|
|
-// with a terminating NUL removed.
|
|
|
+// with a terminating NUL and any bytes after the NUL removed.
|
|
|
func UTF16ToString(s []uint16) string {
|
|
|
for i, v := range s {
|
|
|
if v == 0 {
|
|
|
- s = s[0:i]
|
|
|
+ s = s[:i]
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
@@ -120,7 +120,7 @@ func UTF16PtrFromString(s string) (*uint16, error) {
|
|
|
}
|
|
|
|
|
|
// UTF16PtrToString takes a pointer to a UTF-16 sequence and returns the corresponding UTF-8 encoded string.
|
|
|
-// If the pointer is nil, this returns the empty string. This assumes that the UTF-16 sequence is terminated
|
|
|
+// If the pointer is nil, it returns the empty string. It assumes that the UTF-16 sequence is terminated
|
|
|
// at a zero word; if the zero word is not present, the program may crash.
|
|
|
func UTF16PtrToString(p *uint16) string {
|
|
|
if p == nil {
|
|
|
@@ -270,9 +270,11 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
|
|
//sys RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegEnumKeyExW
|
|
|
//sys RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegQueryValueExW
|
|
|
//sys GetCurrentProcessId() (pid uint32) = kernel32.GetCurrentProcessId
|
|
|
+//sys ProcessIdToSessionId(pid uint32, sessionid *uint32) (err error) = kernel32.ProcessIdToSessionId
|
|
|
//sys GetConsoleMode(console Handle, mode *uint32) (err error) = kernel32.GetConsoleMode
|
|
|
//sys SetConsoleMode(console Handle, mode uint32) (err error) = kernel32.SetConsoleMode
|
|
|
//sys GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) = kernel32.GetConsoleScreenBufferInfo
|
|
|
+//sys SetConsoleCursorPosition(console Handle, position Coord) (err error) = kernel32.SetConsoleCursorPosition
|
|
|
//sys WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) = kernel32.WriteConsoleW
|
|
|
//sys ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) = kernel32.ReadConsoleW
|
|
|
//sys CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) [failretval==InvalidHandle] = kernel32.CreateToolhelp32Snapshot
|
|
|
@@ -303,6 +305,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
|
|
//sys ResumeThread(thread Handle) (ret uint32, err error) [failretval==0xffffffff] = kernel32.ResumeThread
|
|
|
//sys SetPriorityClass(process Handle, priorityClass uint32) (err error) = kernel32.SetPriorityClass
|
|
|
//sys GetPriorityClass(process Handle) (ret uint32, err error) = kernel32.GetPriorityClass
|
|
|
+//sys QueryInformationJobObject(job Handle, JobObjectInformationClass int32, JobObjectInformation uintptr, JobObjectInformationLength uint32, retlen *uint32) (err error) = kernel32.QueryInformationJobObject
|
|
|
//sys SetInformationJobObject(job Handle, JobObjectInformationClass uint32, JobObjectInformation uintptr, JobObjectInformationLength uint32) (ret int, err error)
|
|
|
//sys GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err error)
|
|
|
//sys GetProcessId(process Handle) (id uint32, err error)
|
|
|
@@ -387,11 +390,7 @@ func GetProcAddressByOrdinal(module Handle, ordinal uintptr) (proc uintptr, err
|
|
|
r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), ordinal, 0)
|
|
|
proc = uintptr(r0)
|
|
|
if proc == 0 {
|
|
|
- if e1 != 0 {
|
|
|
- err = errnoErr(e1)
|
|
|
- } else {
|
|
|
- err = syscall.EINVAL
|
|
|
- }
|
|
|
+ err = errnoErr(e1)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
@@ -1088,11 +1087,7 @@ func WSASendMsg(fd Handle, msg *WSAMsg, flags uint32, bytesSent *uint32, overlap
|
|
|
}
|
|
|
r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.sendAddr, 6, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(flags), uintptr(unsafe.Pointer(bytesSent)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
|
|
|
if r1 == socket_error {
|
|
|
- if e1 != 0 {
|
|
|
- err = errnoErr(e1)
|
|
|
- } else {
|
|
|
- err = syscall.EINVAL
|
|
|
- }
|
|
|
+ err = errnoErr(e1)
|
|
|
}
|
|
|
return err
|
|
|
}
|
|
|
@@ -1104,11 +1099,7 @@ func WSARecvMsg(fd Handle, msg *WSAMsg, bytesReceived *uint32, overlapped *Overl
|
|
|
}
|
|
|
r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.recvAddr, 5, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(unsafe.Pointer(bytesReceived)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0)
|
|
|
if r1 == socket_error {
|
|
|
- if e1 != 0 {
|
|
|
- err = errnoErr(e1)
|
|
|
- } else {
|
|
|
- err = syscall.EINVAL
|
|
|
- }
|
|
|
+ err = errnoErr(e1)
|
|
|
}
|
|
|
return err
|
|
|
}
|