[sys] windows: add ole32 instantiation functions

23 views
Skip to first unread message

Jason A. Donenfeld (Gerrit)

unread,
Mar 4, 2021, 9:34:13 PM3/4/21
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go Bot, Brad Fitzpatrick, Alex Brainman, golang-co...@googlegroups.com

Jason A. Donenfeld submitted this change.

View Change

Approvals: Brad Fitzpatrick: Looks good to me, approved Jason A. Donenfeld: Trusted; Run TryBots Go Bot: TryBots succeeded
windows: add ole32 instantiation functions

These are basic functions for getting function pointers to instantiated
OLE objects.

Change-Id: I5a3d179d6da2af006b6e11def18280959bb9bd98
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298469
Trust: Jason A. Donenfeld <Ja...@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Ja...@zx2c4.com>
TryBot-Result: Go Bot <go...@golang.org>
Reviewed-by: Brad Fitzpatrick <brad...@golang.org>
---
M windows/syscall_windows.go
M windows/types_windows.go
M windows/zsyscall_windows.go
3 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index 8c382ad..1b79d34 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -381,6 +381,9 @@
//sys stringFromGUID2(rguid *GUID, lpsz *uint16, cchMax int32) (chars int32) = ole32.StringFromGUID2
//sys coCreateGuid(pguid *GUID) (ret error) = ole32.CoCreateGuid
//sys CoTaskMemFree(address unsafe.Pointer) = ole32.CoTaskMemFree
+//sys CoInitializeEx(reserved uintptr, coInit uint32) (ret error) = ole32.CoInitializeEx
+//sys CoUninitialize() = ole32.CoUninitialize
+//sys CoGetObject(name *uint16, bindOpts *BIND_OPTS3, guid *GUID, functionTable **uintptr) (ret error) = ole32.CoGetObject
//sys getProcessPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) = kernel32.GetProcessPreferredUILanguages
//sys getThreadPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) = kernel32.GetThreadPreferredUILanguages
//sys getUserPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) = kernel32.GetUserPreferredUILanguages
diff --git a/windows/types_windows.go b/windows/types_windows.go
index 6c7e79a..02854ff 100644
--- a/windows/types_windows.go
+++ b/windows/types_windows.go
@@ -2642,3 +2642,74 @@
RT_HTML ResourceID = 23
RT_MANIFEST ResourceID = 24
)
+
+type COAUTHIDENTITY struct {
+ User *uint16
+ UserLength uint32
+ Domain *uint16
+ DomainLength uint32
+ Password *uint16
+ PasswordLength uint32
+ Flags uint32
+}
+
+type COAUTHINFO struct {
+ AuthnSvc uint32
+ AuthzSvc uint32
+ ServerPrincName *uint16
+ AuthnLevel uint32
+ ImpersonationLevel uint32
+ AuthIdentityData *COAUTHIDENTITY
+ Capabilities uint32
+}
+
+type COSERVERINFO struct {
+ Reserved1 uint32
+ Aame *uint16
+ AuthInfo *COAUTHINFO
+ Reserved2 uint32
+}
+
+type BIND_OPTS3 struct {
+ CbStruct uint32
+ Flags uint32
+ Mode uint32
+ TickCountDeadline uint32
+ TrackFlags uint32
+ ClassContext uint32
+ Locale uint32
+ ServerInfo *COSERVERINFO
+ Hwnd HWND
+}
+
+const (
+ CLSCTX_INPROC_SERVER = 0x1
+ CLSCTX_INPROC_HANDLER = 0x2
+ CLSCTX_LOCAL_SERVER = 0x4
+ CLSCTX_INPROC_SERVER16 = 0x8
+ CLSCTX_REMOTE_SERVER = 0x10
+ CLSCTX_INPROC_HANDLER16 = 0x20
+ CLSCTX_RESERVED1 = 0x40
+ CLSCTX_RESERVED2 = 0x80
+ CLSCTX_RESERVED3 = 0x100
+ CLSCTX_RESERVED4 = 0x200
+ CLSCTX_NO_CODE_DOWNLOAD = 0x400
+ CLSCTX_RESERVED5 = 0x800
+ CLSCTX_NO_CUSTOM_MARSHAL = 0x1000
+ CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000
+ CLSCTX_NO_FAILURE_LOG = 0x4000
+ CLSCTX_DISABLE_AAA = 0x8000
+ CLSCTX_ENABLE_AAA = 0x10000
+ CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000
+ CLSCTX_ACTIVATE_32_BIT_SERVER = 0x40000
+ CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000
+ CLSCTX_ENABLE_CLOAKING = 0x100000
+ CLSCTX_APPCONTAINER = 0x400000
+ CLSCTX_ACTIVATE_AAA_AS_IU = 0x800000
+ CLSCTX_PS_DLL = 0x80000000
+
+ COINIT_MULTITHREADED = 0x0
+ COINIT_APARTMENTTHREADED = 0x2
+ COINIT_DISABLE_OLE1DDE = 0x4
+ COINIT_SPEED_OVER_MEMORY = 0x8
+)
diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index 771c804..e7a6e92 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -367,7 +367,10 @@
procRtlNtStatusToDosErrorNoTeb = modntdll.NewProc("RtlNtStatusToDosErrorNoTeb")
procCLSIDFromString = modole32.NewProc("CLSIDFromString")
procCoCreateGuid = modole32.NewProc("CoCreateGuid")
+ procCoGetObject = modole32.NewProc("CoGetObject")
+ procCoInitializeEx = modole32.NewProc("CoInitializeEx")
procCoTaskMemFree = modole32.NewProc("CoTaskMemFree")
+ procCoUninitialize = modole32.NewProc("CoUninitialize")
procStringFromGUID2 = modole32.NewProc("StringFromGUID2")
procEnumProcesses = modpsapi.NewProc("EnumProcesses")
procSubscribeServiceChangeNotifications = modsechost.NewProc("SubscribeServiceChangeNotifications")
@@ -3146,11 +3149,32 @@
return
}

+func CoGetObject(name *uint16, bindOpts *BIND_OPTS3, guid *GUID, functionTable **uintptr) (ret error) {
+ r0, _, _ := syscall.Syscall6(procCoGetObject.Addr(), 4, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bindOpts)), uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(functionTable)), 0, 0)
+ if r0 != 0 {
+ ret = syscall.Errno(r0)
+ }
+ return
+}
+
+func CoInitializeEx(reserved uintptr, coInit uint32) (ret error) {
+ r0, _, _ := syscall.Syscall(procCoInitializeEx.Addr(), 2, uintptr(reserved), uintptr(coInit), 0)
+ if r0 != 0 {
+ ret = syscall.Errno(r0)
+ }
+ return
+}
+
func CoTaskMemFree(address unsafe.Pointer) {
syscall.Syscall(procCoTaskMemFree.Addr(), 1, uintptr(address), 0, 0)
return
}

+func CoUninitialize() {
+ syscall.Syscall(procCoUninitialize.Addr(), 0, 0, 0, 0)
+ return
+}
+
func stringFromGUID2(rguid *GUID, lpsz *uint16, cchMax int32) (chars int32) {
r0, _, _ := syscall.Syscall(procStringFromGUID2.Addr(), 3, uintptr(unsafe.Pointer(rguid)), uintptr(unsafe.Pointer(lpsz)), uintptr(cchMax))
chars = int32(r0)

1 is the latest approved patch-set. The change was submitted with unreviewed changes in the following files: The name of the file: windows/types_windows.go Insertions: 0, Deletions: 16. ``` @@ -914:915, +914:919 @@ - _ [1]byte + // 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 @@ -2337:2338, +2341:2342 @@ - // Values for the Attributes member of OBJECT_ATTRIBUTES + // Values for the Attributes member of OBJECT_ATTRIBUTES. @@ -2365:2366, +2369:2370 @@ - CurDirRef RTLP_CURDIR_REF + CurDirRef *RTLP_CURDIR_REF @@ +2373:2374 @@ + // CreateDisposition flags for NtCreateFile and NtCreateNamedPipeFile. @@ +2382:2383 @@ + // CreateOptions flags for NtCreateFile and NtCreateNamedPipeFile. @@ +2406:2408 @@ + // Parameter constants for NtCreateNamedPipeFile. + @@ +2435:2552 @@ + // ProcessInformationClasses for NtQueryInformationProcess and NtSetInformationProcess. + const ( + ProcessBasicInformation = iota + ProcessQuotaLimits + ProcessIoCounters + ProcessVmCounters + ProcessTimes + ProcessBasePriority + ProcessRaisePriority + ProcessDebugPort + ProcessExceptionPort + ProcessAccessToken + ProcessLdtInformation + ProcessLdtSize + ProcessDefaultHardErrorMode + ProcessIoPortHandlers + ProcessPooledUsageAndLimits + ProcessWorkingSetWatch + ProcessUserModeIOPL + ProcessEnableAlignmentFaultFixup + ProcessPriorityClass + ProcessWx86Information + ProcessHandleCount + ProcessAffinityMask + ProcessPriorityBoost + ProcessDeviceMap + ProcessSessionInformation + ProcessForegroundInformation + ProcessWow64Information + ProcessImageFileName + ProcessLUIDDeviceMapsEnabled + ProcessBreakOnTermination + ProcessDebugObjectHandle + ProcessDebugFlags + ProcessHandleTracing + ProcessIoPriority + ProcessExecuteFlags + ProcessResourceManagement + ProcessCookie + ProcessImageInformation + ProcessCycleTime + ProcessPagePriority + ProcessInstrumentationCallback + ProcessThreadStackAllocation + ProcessWorkingSetWatchEx + ProcessImageFileNameWin32 + ProcessImageFileMapping + ProcessAffinityUpdateMode + ProcessMemoryAllocationMode + ProcessGroupInformation + ProcessTokenVirtualizationEnabled + ProcessConsoleHostProcess + ProcessWindowInformation + ProcessHandleInformation + ProcessMitigationPolicy + ProcessDynamicFunctionTableInformation + ProcessHandleCheckingMode + ProcessKeepAliveCount + ProcessRevokeFileHandles + ProcessWorkingSetControl + ProcessHandleTable + ProcessCheckStackExtentsMode + ProcessCommandLineInformation + ProcessProtectionInformation + ProcessMemoryExhaustion + ProcessFaultInformation + ProcessTelemetryIdInformation + ProcessCommitReleaseInformation + ProcessDefaultCpuSetsInformation + ProcessAllowedCpuSetsInformation + ProcessSubsystemProcess + ProcessJobMemoryInformation + ProcessInPrivate + ProcessRaiseUMExceptionOnInvalidHandleClose + ProcessIumChallengeResponse + ProcessChildProcessInformation + ProcessHighGraphicsPriorityInformation + ProcessSubsystemInformation + ProcessEnergyValues + ProcessActivityThrottleState + ProcessActivityThrottlePolicy + ProcessWin32kSyscallFilterInformation + ProcessDisableSystemAllowedCpuSets + ProcessWakeInformation + ProcessEnergyTrackingState + ProcessManageWritesToExecutableMemory + ProcessCaptureTrustletLiveDump + ProcessTelemetryCoverage + ProcessEnclaveInformation + ProcessEnableReadWriteVmLogging + ProcessUptimeInformation + ProcessImageSection + ProcessDebugAuthInformation + ProcessSystemResourceManagement + ProcessSequenceNumber + ProcessLoaderDetour + ProcessSecurityDomainInformation + ProcessCombineSecurityDomainsInformation + ProcessEnableLogging + ProcessLeapSecondInformation + ProcessFiberShadowStackAllocation + ProcessFreeFiberShadowStackAllocation + ProcessAltSystemCallInformation + ProcessDynamicEHContinuationTargets + ProcessDynamicEnforcedCetCompatibleRanges + ) + + type PROCESS_BASIC_INFORMATION struct { + ExitStatus NTStatus + PebBaseAddress *PEB + AffinityMask uintptr + BasePriority int32 + UniqueProcessId Handle + InheritedFromUniqueProcessId Handle + } + + // Constants for LocalAlloc flags. @@ +2568:2569 @@ + // Constants for the CreateNamedPipe-family of functions. @@ +2587:2588 @@ + ) @@ +2589:2591 @@ + // Constants for security attributes when opening named pipes. + const ( @@ -2474:2475, +2603:2611 @@ - // Predefined Resource Types + // ResourceID represents a 16-bit resource identifier, traditionally created with the MAKEINTRESOURCE macro. + type ResourceID uint16 + + // ResourceIDOrString must be either a ResourceID, to specify a resource or resource type by ID, + // or a string, to specify a resource or resource type by name. + type ResourceIDOrString interface{} + + // Predefined resource names and types. @@ -2476:2478, +2612:2620 @@ - VS_VERSION_INFO uint16 = 1 - VS_USER_DEFINED = 100 + // Predefined names. + CREATEPROCESS_MANIFEST_RESOURCE_ID ResourceID = 1 + ISOLATIONAWARE_MANIFEST_RESOURCE_ID ResourceID = 2 + ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID ResourceID = 3 + ISOLATIONPOLICY_MANIFEST_RESOURCE_ID ResourceID = 4 + ISOLATIONPOLICY_BROWSER_MANIFEST_RESOURCE_ID ResourceID = 5 + MINIMUM_RESERVED_MANIFEST_RESOURCE_ID ResourceID = 1 // inclusive + MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID ResourceID = 16 // inclusive @@ -2479:2508, +2621:2643 @@ - CREATEPROCESS_MANIFEST_RESOURCE_ID = 1 - ISOLATIONAWARE_MANIFEST_RESOURCE_ID = 2 - ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID = 3 - ISOLATIONPOLICY_MANIFEST_RESOURCE_ID = 4 - ISOLATIONPOLICY_BROWSER_MANIFEST_RESOURCE_ID = 5 - MINIMUM_RESERVED_MANIFEST_RESOURCE_ID = 1 // inclusive - MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID = 16 // inclusive - - RT_CURSOR = MAKEINTRESOURCE(1) - RT_BITMAP = MAKEINTRESOURCE(2) - RT_ICON = MAKEINTRESOURCE(3) - RT_MENU = MAKEINTRESOURCE(4) - RT_DIALOG = MAKEINTRESOURCE(5) - RT_STRING = MAKEINTRESOURCE(6) - RT_FONTDIR = MAKEINTRESOURCE(7) - RT_FONT = MAKEINTRESOURCE(8) - RT_ACCELERATOR = MAKEINTRESOURCE(9) - RT_RCDATA = MAKEINTRESOURCE(10) - RT_MESSAGETABLE = MAKEINTRESOURCE(11) - RT_GROUP_CURSOR = MAKEINTRESOURCE(12) - RT_GROUP_ICON = MAKEINTRESOURCE(14) - RT_VERSION = MAKEINTRESOURCE(16) - RT_DLGINCLUDE = MAKEINTRESOURCE(17) - RT_PLUGPLAY = MAKEINTRESOURCE(19) - RT_VXD = MAKEINTRESOURCE(20) - RT_ANICURSOR = MAKEINTRESOURCE(21) - RT_ANIICON = MAKEINTRESOURCE(22) - RT_HTML = MAKEINTRESOURCE(23) - RT_MANIFEST = MAKEINTRESOURCE(24) + // Predefined types. + RT_CURSOR ResourceID = 1 + RT_BITMAP ResourceID = 2 + RT_ICON ResourceID = 3 + RT_MENU ResourceID = 4 + RT_DIALOG ResourceID = 5 + RT_STRING ResourceID = 6 + RT_FONTDIR ResourceID = 7 + RT_FONT ResourceID = 8 + RT_ACCELERATOR ResourceID = 9 + RT_RCDATA ResourceID = 10 + RT_MESSAGETABLE ResourceID = 11 + RT_GROUP_CURSOR ResourceID = 12 + RT_GROUP_ICON ResourceID = 14 + RT_VERSION ResourceID = 16 + RT_DLGINCLUDE ResourceID = 17 + RT_PLUGPLAY ResourceID = 19 + RT_VXD ResourceID = 20 + RT_ANICURSOR ResourceID = 21 + RT_ANIICON ResourceID = 22 + RT_HTML ResourceID = 23 + RT_MANIFEST ResourceID = 24 @@ -2510:2526 @@ - type VS_FIXEDFILEINFO struct { - Signature uint32 - StrucVersion uint32 - FileVersionMS uint32 - FileVersionLS uint32 - ProductVersionMS uint32 - ProductVersionLS uint32 - FileFlagsMask uint32 - FileFlags uint32 - FileOS uint32 - FileType uint32 - FileSubtype uint32 - FileDateMS uint32 - FileDateLS uint32 - } - ```

To view, visit change 298469. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sys
Gerrit-Branch: master
Gerrit-Change-Id: I5a3d179d6da2af006b6e11def18280959bb9bd98
Gerrit-Change-Number: 298469
Gerrit-PatchSet: 13
Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Go Bot <go...@golang.org>
Gerrit-Reviewer: Jason A. Donenfeld <Ja...@zx2c4.com>
Gerrit-MessageType: merged
Reply all
Reply to author
Forward
0 new messages