mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-12 16:06:37 +00:00
logical_disk: add bitlocker status sub-collector (#2077)
This commit is contained in:
84
internal/headers/shell32/shell32.go
Normal file
84
internal/headers/shell32/shell32.go
Normal file
@@ -0,0 +1,84 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build windows
|
||||
|
||||
package shell32
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/go-ole/go-ole"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/propsys"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
//nolint:gochecknoglobals
|
||||
var (
|
||||
modShell32 = windows.NewLazySystemDLL("shell32.dll")
|
||||
procSHCreateItemFromParsingName = modShell32.NewProc("SHCreateItemFromParsingName")
|
||||
|
||||
iidIShellItem2 = ole.NewGUID("{7E9FB0D3-919F-4307-AB2E-9B1860310C93}")
|
||||
)
|
||||
|
||||
func SHCreateItemFromParsingName(path string) (*IShellItem2, error) {
|
||||
ptrPath, err := windows.UTF16PtrFromString(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert path to UTF16: %w", err)
|
||||
}
|
||||
|
||||
var result *IShellItem2
|
||||
|
||||
hr, _, err := procSHCreateItemFromParsingName.Call(
|
||||
uintptr(unsafe.Pointer(ptrPath)),
|
||||
0,
|
||||
uintptr(unsafe.Pointer(iidIShellItem2)),
|
||||
uintptr(unsafe.Pointer(&result)),
|
||||
)
|
||||
if hr != 0 {
|
||||
return nil, fmt.Errorf("syscall failed: %w", err)
|
||||
}
|
||||
|
||||
if result == nil {
|
||||
return nil, errors.New("SHCreateItemFromParsingName returned nil")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (item *IShellItem2) GetProperty(key *propsys.PROPERTYKEY, v *ole.VARIANT) error {
|
||||
hr, _, err := syscall.SyscallN(
|
||||
item.lpVtbl.GetProperty,
|
||||
uintptr(unsafe.Pointer(item)),
|
||||
uintptr(unsafe.Pointer(key)),
|
||||
uintptr(unsafe.Pointer(v)),
|
||||
)
|
||||
|
||||
if hr != 0 {
|
||||
return fmt.Errorf("GetProperty failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (item *IShellItem2) Release() {
|
||||
_, _, _ = syscall.SyscallN(
|
||||
item.lpVtbl.Release,
|
||||
uintptr(unsafe.Pointer(item)),
|
||||
)
|
||||
}
|
||||
51
internal/headers/shell32/types.go
Normal file
51
internal/headers/shell32/types.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build windows
|
||||
|
||||
package shell32
|
||||
|
||||
type IShellItem2 struct {
|
||||
lpVtbl *IShellItem2Vtbl
|
||||
}
|
||||
|
||||
type IShellItem2Vtbl struct {
|
||||
// IUnknown
|
||||
QueryInterface uintptr
|
||||
AddRef uintptr
|
||||
Release uintptr
|
||||
|
||||
// IShellItem
|
||||
BindToHandler uintptr
|
||||
GetParent uintptr
|
||||
GetDisplayName uintptr
|
||||
GetAttributes uintptr
|
||||
Compare uintptr
|
||||
|
||||
// IShellItem2
|
||||
GetPropertyStore uintptr
|
||||
GetPropertyStoreWithCreateObject uintptr
|
||||
GetPropertyStoreForKeys uintptr
|
||||
GetPropertyDescriptionList uintptr
|
||||
Update uintptr
|
||||
GetProperty uintptr
|
||||
GetCLSID uintptr
|
||||
GetFileTime uintptr
|
||||
GetInt32 uintptr
|
||||
GetString uintptr
|
||||
GetUInt32 uintptr
|
||||
GetUInt64 uintptr
|
||||
GetBool uintptr
|
||||
}
|
||||
Reference in New Issue
Block a user