Update
This commit is contained in:
1 parent
3530afb854
commit
6903fcff27
2146 files changed
+112256
-190703
No files matched your search
+3
-3
@@ -50,8 +50,8 @@ func (bs *BSTR) String() string {
|
||||
return windows.UTF16ToString(bs.toUTF16())
|
||||
}
|
||||
|
||||
// toUTF16 is unsafe for general use because it returns a pointer that is
|
||||
// not managed by the Go GC.
|
||||
// toUTF16 is unsafe for general use because it returns a slice referencing a
|
||||
// pointer that is not managed by the Go GC.
|
||||
func (bs *BSTR) toUTF16() []uint16 {
|
||||
return unsafe.Slice(bs.toUTF16Ptr(), bs.Len())
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func (bs *BSTR) toUTF16Ptr() *uint16 {
|
||||
return (*uint16)(unsafe.Pointer(*bs))
|
||||
}
|
||||
|
||||
// ToUTF16 returns the contents of bs as C-style string pointer to UTF-16 code units.
|
||||
// ToUTF16Ptr returns the contents of bs as C-style string pointer to UTF-16 code units.
|
||||
func (bs *BSTR) ToUTF16Ptr() *uint16 {
|
||||
return unsafe.SliceData(bs.ToUTF16())
|
||||
}
|
||||
|
||||
+4
-4
@@ -47,24 +47,24 @@ var (
|
||||
)
|
||||
|
||||
func sysAllocString(str *uint16) (ret BSTR) {
|
||||
r0, _, _ := syscall.Syscall(procSysAllocString.Addr(), 1, uintptr(unsafe.Pointer(str)), 0, 0)
|
||||
r0, _, _ := syscall.SyscallN(procSysAllocString.Addr(), uintptr(unsafe.Pointer(str)))
|
||||
ret = BSTR(r0)
|
||||
return
|
||||
}
|
||||
|
||||
func sysAllocStringLen(str *uint16, strLen uint32) (ret BSTR) {
|
||||
r0, _, _ := syscall.Syscall(procSysAllocStringLen.Addr(), 2, uintptr(unsafe.Pointer(str)), uintptr(strLen), 0)
|
||||
r0, _, _ := syscall.SyscallN(procSysAllocStringLen.Addr(), uintptr(unsafe.Pointer(str)), uintptr(strLen))
|
||||
ret = BSTR(r0)
|
||||
return
|
||||
}
|
||||
|
||||
func sysFreeString(bstr BSTR) {
|
||||
syscall.Syscall(procSysFreeString.Addr(), 1, uintptr(bstr), 0, 0)
|
||||
syscall.SyscallN(procSysFreeString.Addr(), uintptr(bstr))
|
||||
return
|
||||
}
|
||||
|
||||
func sysStringLen(bstr BSTR) (ret uint32) {
|
||||
r0, _, _ := syscall.Syscall(procSysStringLen.Addr(), 1, uintptr(bstr), 0, 0)
|
||||
r0, _, _ := syscall.SyscallN(procSysStringLen.Addr(), uintptr(bstr))
|
||||
ret = uint32(r0)
|
||||
return
|
||||
}
|
||||
+1
-2
@@ -20,6 +20,5 @@ package com
|
||||
// Technically this proc is __cdecl, but since it has 0 args this doesn't matter
|
||||
//sys setOaNoCache() = oleaut32.SetOaNoCache
|
||||
|
||||
// For the following two functions we use IUnknownABI instead of IStreamABI because it makes the callsites cleaner.
|
||||
// The following function uses IUnknownABI instead of IStreamABI because it makes the callsite cleaner.
|
||||
//sys shCreateMemStream(pInit *byte, cbInit uint32) (stream *IUnknownABI) = shlwapi.SHCreateMemStream
|
||||
//sys createStreamOnHGlobal(hglobal internal.HGLOBAL, deleteOnRelease bool, stream **IUnknownABI) (hr wingoes.HRESULT) = ole32.CreateStreamOnHGlobal
|
||||
-206
@@ -13,7 +13,6 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/dblohm7/wingoes"
|
||||
"github.com/dblohm7/wingoes/internal"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -179,103 +178,6 @@ func (o SequentialStream) Write(b []byte) (int, error) {
|
||||
return p.Write(b)
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) Seek(offset int64, whence int) (n int64, _ error) {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[5]
|
||||
|
||||
if runtime.GOARCH == "386" {
|
||||
words := (*[2]uintptr)(unsafe.Pointer(&offset))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
words[0],
|
||||
words[1],
|
||||
uintptr(uint32(whence)),
|
||||
uintptr(unsafe.Pointer(&n)),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
} else {
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(offset),
|
||||
uintptr(uint32(whence)),
|
||||
uintptr(unsafe.Pointer(&n)),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
}
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return 0, e
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) SetSize(newSize uint64) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[6]
|
||||
|
||||
if runtime.GOARCH == "386" {
|
||||
words := (*[2]uintptr)(unsafe.Pointer(&newSize))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
words[0],
|
||||
words[1],
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
} else {
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(newSize),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
}
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) CopyTo(dest *IStreamABI, numBytesToCopy uint64) (bytesRead, bytesWritten uint64, _ error) {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[7]
|
||||
|
||||
if runtime.GOARCH == "386" {
|
||||
words := (*[2]uintptr)(unsafe.Pointer(&numBytesToCopy))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(unsafe.Pointer(dest)),
|
||||
words[0],
|
||||
words[1],
|
||||
uintptr(unsafe.Pointer(&bytesRead)),
|
||||
uintptr(unsafe.Pointer(&bytesWritten)),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
} else {
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(unsafe.Pointer(dest)),
|
||||
uintptr(numBytesToCopy),
|
||||
uintptr(unsafe.Pointer(&bytesRead)),
|
||||
uintptr(unsafe.Pointer(&bytesWritten)),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
}
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return bytesRead, bytesWritten, e
|
||||
}
|
||||
|
||||
return bytesRead, bytesWritten, nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) Commit(flags STGC) error {
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[8]
|
||||
|
||||
@@ -306,76 +208,6 @@ func (abi *IStreamABI) Revert() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) LockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[10]
|
||||
|
||||
if runtime.GOARCH == "386" {
|
||||
oWords := (*[2]uintptr)(unsafe.Pointer(&offset))
|
||||
nWords := (*[2]uintptr)(unsafe.Pointer(&numBytes))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
oWords[0],
|
||||
oWords[1],
|
||||
nWords[0],
|
||||
nWords[1],
|
||||
uintptr(lockType),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
} else {
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(offset),
|
||||
uintptr(numBytes),
|
||||
uintptr(lockType),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
}
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) UnlockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[11]
|
||||
|
||||
if runtime.GOARCH == "386" {
|
||||
oWords := (*[2]uintptr)(unsafe.Pointer(&offset))
|
||||
nWords := (*[2]uintptr)(unsafe.Pointer(&numBytes))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
oWords[0],
|
||||
oWords[1],
|
||||
nWords[0],
|
||||
nWords[1],
|
||||
uintptr(lockType),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
} else {
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(offset),
|
||||
uintptr(numBytes),
|
||||
uintptr(lockType),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
}
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) Stat(flags STATFLAG) (*STATSTG, error) {
|
||||
result := new(STATSTG)
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[12]
|
||||
@@ -493,19 +325,10 @@ const hrE_OUTOFMEMORY = wingoes.HRESULT(-((0x8007000E ^ 0xFFFFFFFF) + 1))
|
||||
// copy of initialBytes. Its seek pointer is guaranteed to reference the
|
||||
// beginning of the stream.
|
||||
func NewMemoryStream(initialBytes []byte) (result Stream, _ error) {
|
||||
return newMemoryStreamInternal(initialBytes, false)
|
||||
}
|
||||
|
||||
func newMemoryStreamInternal(initialBytes []byte, forceLegacy bool) (result Stream, _ error) {
|
||||
if len(initialBytes) > maxStreamRWLen {
|
||||
return result, wingoes.ErrorFromHRESULT(hrE_OUTOFMEMORY)
|
||||
}
|
||||
|
||||
// SHCreateMemStream exists on Win7 but is not safe for us to use until Win8.
|
||||
if forceLegacy || !wingoes.IsWin8OrGreater() {
|
||||
return newMemoryStreamLegacy(initialBytes)
|
||||
}
|
||||
|
||||
var base *byte
|
||||
var length uint32
|
||||
if l := uint32(len(initialBytes)); l > 0 {
|
||||
@@ -525,32 +348,3 @@ func newMemoryStreamInternal(initialBytes []byte, forceLegacy bool) (result Stre
|
||||
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
func newMemoryStreamLegacy(initialBytes []byte) (result Stream, _ error) {
|
||||
ppstream := NewABIReceiver()
|
||||
hr := createStreamOnHGlobal(internal.HGLOBAL(0), true, ppstream)
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return result, e
|
||||
}
|
||||
|
||||
obj := result.Make(ppstream).(Stream)
|
||||
|
||||
if err := obj.SetSize(uint64(len(initialBytes))); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
if len(initialBytes) == 0 {
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
_, err := obj.Write(initialBytes)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
if _, err := obj.Seek(0, io.SeekStart); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
// Copyright (c) 2023 Tailscale Inc & AUTHORS. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build windows
|
||||
|
||||
package com
|
||||
|
||||
import (
|
||||
"math"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/dblohm7/wingoes"
|
||||
)
|
||||
|
||||
const maxStreamRWLen = math.MaxInt32
|
||||
|
||||
func (abi *IStreamABI) Seek(offset int64, whence int) (n int64, _ error) {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[5]
|
||||
|
||||
words := (*[2]uintptr)(unsafe.Pointer(&offset))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
words[0],
|
||||
words[1],
|
||||
uintptr(uint32(whence)),
|
||||
uintptr(unsafe.Pointer(&n)),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return 0, e
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) SetSize(newSize uint64) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[6]
|
||||
|
||||
words := (*[2]uintptr)(unsafe.Pointer(&newSize))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
words[0],
|
||||
words[1],
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) CopyTo(dest *IStreamABI, numBytesToCopy uint64) (bytesRead, bytesWritten uint64, _ error) {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[7]
|
||||
|
||||
words := (*[2]uintptr)(unsafe.Pointer(&numBytesToCopy))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(unsafe.Pointer(dest)),
|
||||
words[0],
|
||||
words[1],
|
||||
uintptr(unsafe.Pointer(&bytesRead)),
|
||||
uintptr(unsafe.Pointer(&bytesWritten)),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return bytesRead, bytesWritten, e
|
||||
}
|
||||
|
||||
return bytesRead, bytesWritten, nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) LockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[10]
|
||||
|
||||
oWords := (*[2]uintptr)(unsafe.Pointer(&offset))
|
||||
nWords := (*[2]uintptr)(unsafe.Pointer(&numBytes))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
oWords[0],
|
||||
oWords[1],
|
||||
nWords[0],
|
||||
nWords[1],
|
||||
uintptr(lockType),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) UnlockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[11]
|
||||
|
||||
oWords := (*[2]uintptr)(unsafe.Pointer(&offset))
|
||||
nWords := (*[2]uintptr)(unsafe.Pointer(&numBytes))
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
oWords[0],
|
||||
oWords[1],
|
||||
nWords[0],
|
||||
nWords[1],
|
||||
uintptr(lockType),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+103
@@ -8,6 +8,109 @@ package com
|
||||
|
||||
import (
|
||||
"math"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/dblohm7/wingoes"
|
||||
)
|
||||
|
||||
const maxStreamRWLen = math.MaxUint32
|
||||
|
||||
func (abi *IStreamABI) Seek(offset int64, whence int) (n int64, _ error) {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[5]
|
||||
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(offset),
|
||||
uintptr(uint32(whence)),
|
||||
uintptr(unsafe.Pointer(&n)),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return 0, e
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) SetSize(newSize uint64) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[6]
|
||||
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(newSize),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) CopyTo(dest *IStreamABI, numBytesToCopy uint64) (bytesRead, bytesWritten uint64, _ error) {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[7]
|
||||
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(unsafe.Pointer(dest)),
|
||||
uintptr(numBytesToCopy),
|
||||
uintptr(unsafe.Pointer(&bytesRead)),
|
||||
uintptr(unsafe.Pointer(&bytesWritten)),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return bytesRead, bytesWritten, e
|
||||
}
|
||||
|
||||
return bytesRead, bytesWritten, nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) LockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[10]
|
||||
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(offset),
|
||||
uintptr(numBytes),
|
||||
uintptr(lockType),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (abi *IStreamABI) UnlockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
|
||||
var hr wingoes.HRESULT
|
||||
method := unsafe.Slice(abi.Vtbl, 14)[11]
|
||||
|
||||
rc, _, _ := syscall.SyscallN(
|
||||
method,
|
||||
uintptr(unsafe.Pointer(abi)),
|
||||
uintptr(offset),
|
||||
uintptr(numBytes),
|
||||
uintptr(lockType),
|
||||
)
|
||||
hr = wingoes.HRESULT(rc)
|
||||
|
||||
if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) 2024 Tailscale Inc & AUTHORS. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build windows
|
||||
|
||||
package com
|
||||
|
||||
func getTooBigSlice() []byte {
|
||||
return nil
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) 2024 Tailscale Inc & AUTHORS. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build windows && !386
|
||||
|
||||
package com
|
||||
|
||||
func getTooBigSlice() []byte {
|
||||
return make([]byte, maxStreamRWLen+1)
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
// Copyright (c) 2023 Tailscale Inc & AUTHORS. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package com
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
const maxStreamRWLen = math.MaxInt32
|
||||
+14
-26
@@ -7,7 +7,6 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/dblohm7/wingoes"
|
||||
"github.com/dblohm7/wingoes/internal"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -44,63 +43,52 @@ var (
|
||||
modoleaut32 = windows.NewLazySystemDLL("oleaut32.dll")
|
||||
modshlwapi = windows.NewLazySystemDLL("shlwapi.dll")
|
||||
|
||||
procCoCreateInstance = modole32.NewProc("CoCreateInstance")
|
||||
procCoGetApartmentType = modole32.NewProc("CoGetApartmentType")
|
||||
procCoIncrementMTAUsage = modole32.NewProc("CoIncrementMTAUsage")
|
||||
procCoInitializeEx = modole32.NewProc("CoInitializeEx")
|
||||
procCoInitializeSecurity = modole32.NewProc("CoInitializeSecurity")
|
||||
procCreateStreamOnHGlobal = modole32.NewProc("CreateStreamOnHGlobal")
|
||||
procSetOaNoCache = modoleaut32.NewProc("SetOaNoCache")
|
||||
procSHCreateMemStream = modshlwapi.NewProc("SHCreateMemStream")
|
||||
procCoCreateInstance = modole32.NewProc("CoCreateInstance")
|
||||
procCoGetApartmentType = modole32.NewProc("CoGetApartmentType")
|
||||
procCoIncrementMTAUsage = modole32.NewProc("CoIncrementMTAUsage")
|
||||
procCoInitializeEx = modole32.NewProc("CoInitializeEx")
|
||||
procCoInitializeSecurity = modole32.NewProc("CoInitializeSecurity")
|
||||
procSetOaNoCache = modoleaut32.NewProc("SetOaNoCache")
|
||||
procSHCreateMemStream = modshlwapi.NewProc("SHCreateMemStream")
|
||||
)
|
||||
|
||||
func coCreateInstance(clsid *CLSID, unkOuter *IUnknownABI, clsctx coCLSCTX, iid *IID, ppv **IUnknownABI) (hr wingoes.HRESULT) {
|
||||
r0, _, _ := syscall.Syscall6(procCoCreateInstance.Addr(), 5, uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(unkOuter)), uintptr(clsctx), uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(ppv)), 0)
|
||||
r0, _, _ := syscall.SyscallN(procCoCreateInstance.Addr(), uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(unkOuter)), uintptr(clsctx), uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(ppv)))
|
||||
hr = wingoes.HRESULT(r0)
|
||||
return
|
||||
}
|
||||
|
||||
func coGetApartmentType(aptType *coAPTTYPE, qual *coAPTTYPEQUALIFIER) (hr wingoes.HRESULT) {
|
||||
r0, _, _ := syscall.Syscall(procCoGetApartmentType.Addr(), 2, uintptr(unsafe.Pointer(aptType)), uintptr(unsafe.Pointer(qual)), 0)
|
||||
r0, _, _ := syscall.SyscallN(procCoGetApartmentType.Addr(), uintptr(unsafe.Pointer(aptType)), uintptr(unsafe.Pointer(qual)))
|
||||
hr = wingoes.HRESULT(r0)
|
||||
return
|
||||
}
|
||||
|
||||
func coIncrementMTAUsage(cookie *coMTAUsageCookie) (hr wingoes.HRESULT) {
|
||||
r0, _, _ := syscall.Syscall(procCoIncrementMTAUsage.Addr(), 1, uintptr(unsafe.Pointer(cookie)), 0, 0)
|
||||
r0, _, _ := syscall.SyscallN(procCoIncrementMTAUsage.Addr(), uintptr(unsafe.Pointer(cookie)))
|
||||
hr = wingoes.HRESULT(r0)
|
||||
return
|
||||
}
|
||||
|
||||
func coInitializeEx(reserved uintptr, flags uint32) (hr wingoes.HRESULT) {
|
||||
r0, _, _ := syscall.Syscall(procCoInitializeEx.Addr(), 2, uintptr(reserved), uintptr(flags), 0)
|
||||
r0, _, _ := syscall.SyscallN(procCoInitializeEx.Addr(), uintptr(reserved), uintptr(flags))
|
||||
hr = wingoes.HRESULT(r0)
|
||||
return
|
||||
}
|
||||
|
||||
func coInitializeSecurity(sd *windows.SECURITY_DESCRIPTOR, authSvcLen int32, authSvc *soleAuthenticationService, reserved1 uintptr, authnLevel rpcAuthnLevel, impLevel rpcImpersonationLevel, authList *soleAuthenticationList, capabilities authCapabilities, reserved2 uintptr) (hr wingoes.HRESULT) {
|
||||
r0, _, _ := syscall.Syscall9(procCoInitializeSecurity.Addr(), 9, uintptr(unsafe.Pointer(sd)), uintptr(authSvcLen), uintptr(unsafe.Pointer(authSvc)), uintptr(reserved1), uintptr(authnLevel), uintptr(impLevel), uintptr(unsafe.Pointer(authList)), uintptr(capabilities), uintptr(reserved2))
|
||||
hr = wingoes.HRESULT(r0)
|
||||
return
|
||||
}
|
||||
|
||||
func createStreamOnHGlobal(hglobal internal.HGLOBAL, deleteOnRelease bool, stream **IUnknownABI) (hr wingoes.HRESULT) {
|
||||
var _p0 uint32
|
||||
if deleteOnRelease {
|
||||
_p0 = 1
|
||||
}
|
||||
r0, _, _ := syscall.Syscall(procCreateStreamOnHGlobal.Addr(), 3, uintptr(hglobal), uintptr(_p0), uintptr(unsafe.Pointer(stream)))
|
||||
r0, _, _ := syscall.SyscallN(procCoInitializeSecurity.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(authSvcLen), uintptr(unsafe.Pointer(authSvc)), uintptr(reserved1), uintptr(authnLevel), uintptr(impLevel), uintptr(unsafe.Pointer(authList)), uintptr(capabilities), uintptr(reserved2))
|
||||
hr = wingoes.HRESULT(r0)
|
||||
return
|
||||
}
|
||||
|
||||
func setOaNoCache() {
|
||||
syscall.Syscall(procSetOaNoCache.Addr(), 0, 0, 0, 0)
|
||||
syscall.SyscallN(procSetOaNoCache.Addr())
|
||||
return
|
||||
}
|
||||
|
||||
func shCreateMemStream(pInit *byte, cbInit uint32) (stream *IUnknownABI) {
|
||||
r0, _, _ := syscall.Syscall(procSHCreateMemStream.Addr(), 2, uintptr(unsafe.Pointer(pInit)), uintptr(cbInit), 0)
|
||||
r0, _, _ := syscall.SyscallN(procSHCreateMemStream.Addr(), uintptr(unsafe.Pointer(pInit)), uintptr(cbInit))
|
||||
stream = (*IUnknownABI)(unsafe.Pointer(r0))
|
||||
return
|
||||
}
|
||||
Reference in new issue
Block a user