From 9239a65c96da883c12c5899b8deda8549ea7ce1b Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Fri, 3 Nov 2023 22:03:29 +0800 Subject: [PATCH] =?UTF-8?q?Opt=20#86,=20=E5=B0=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B0=83=E6=95=B4=E4=B8=BAUTF8=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E8=A7=84=E8=8C=83=E6=8E=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Thunks/bluetoothapis.hpp | 347 ++++++++++++++++++----------------- src/Thunks/mfplat.hpp | 183 +++++++++--------- src/Thunks/netapi32.hpp | 93 +++++----- src/Thunks/ntdll.hpp | 59 +++--- src/Thunks/powrprof.hpp | 48 ++--- src/Thunks/userenv.hpp | 212 ++++++++++----------- 6 files changed, 481 insertions(+), 461 deletions(-) diff --git a/src/Thunks/bluetoothapis.hpp b/src/Thunks/bluetoothapis.hpp index 9c286b6..7cc5cc2 100644 --- a/src/Thunks/bluetoothapis.hpp +++ b/src/Thunks/bluetoothapis.hpp @@ -1,225 +1,234 @@ -#if (YY_Thunks_Support_Version < NTDDI_WIN8) +#if (YY_Thunks_Support_Version < NTDDI_WIN8) #include #endif -namespace YY +#if (YY_Thunks_Support_Version < NTDDI_WIN8) && !defined(__Comment_Lib_bluetoothapis) +#define __Comment_Lib_bluetoothapis +#pragma comment(lib, "BluetoothAPIs.lib") +#endif + +namespace YY::Thunks { - namespace Thunks - { #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8߰汾 Windows ֧֡ - __DEFINE_THUNK( - bluetoothapis, - 24, - HRESULT, - WINAPI, - BluetoothGATTGetCharacteristicValue, - _In_ HANDLE _hDevice, - _In_ PBTH_LE_GATT_CHARACTERISTIC _pCharacteristic, - _In_ ULONG _cbCharacteristicValueDataSize, - _Out_opt_ PBTH_LE_GATT_CHARACTERISTIC_VALUE _pCharacteristicValue, - _Out_opt_ USHORT* _pCharacteristicValueSizeRequired, - _In_ ULONG _fFlags - ) + // 最低受支持的客户端 Windows 8及更高版本的 Windows 中受支持。 + __DEFINE_THUNK( + bluetoothapis, + 24, + HRESULT, + WINAPI, + BluetoothGATTGetCharacteristicValue, + _In_ HANDLE _hDevice, + _In_ PBTH_LE_GATT_CHARACTERISTIC _pCharacteristic, + _In_ ULONG _cbCharacteristicValueDataSize, + _Out_opt_ PBTH_LE_GATT_CHARACTERISTIC_VALUE _pCharacteristicValue, + _Out_opt_ USHORT* _pCharacteristicValueSizeRequired, + _In_ ULONG _fFlags + ) + { + if (const auto _pfnBluetoothGATTGetCharacteristicValue = try_get_BluetoothGATTGetCharacteristicValue()) { - if (const auto _pfnBluetoothGATTGetCharacteristicValue = try_get_BluetoothGATTGetCharacteristicValue()) - { - return _pfnBluetoothGATTGetCharacteristicValue(_hDevice, _pCharacteristic, _cbCharacteristicValueDataSize, _pCharacteristicValue, _pCharacteristicValueSizeRequired, _fFlags); - } + return _pfnBluetoothGATTGetCharacteristicValue(_hDevice, _pCharacteristic, _cbCharacteristicValueDataSize, _pCharacteristicValue, _pCharacteristicValueSizeRequired, _fFlags); + } - if (_pCharacteristicValueSizeRequired) - *_pCharacteristicValueSizeRequired = 0; + if (_pCharacteristicValueSizeRequired) + *_pCharacteristicValueSizeRequired = 0; - if (_pCharacteristicValue && _cbCharacteristicValueDataSize >= sizeof(DWORD)) - _pCharacteristicValue->DataSize = 0; + if (_pCharacteristicValue && _cbCharacteristicValueDataSize >= sizeof(DWORD)) + _pCharacteristicValue->DataSize = 0; - return ERROR_NOT_SUPPORTED; - } + return ERROR_NOT_SUPPORTED; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8߰汾 Windows ֧֡ - __DEFINE_THUNK( - bluetoothapis, - 24, - HRESULT, - WINAPI, - BluetoothGATTGetCharacteristics, - _In_ HANDLE _hDevice, - _In_opt_ PBTH_LE_GATT_SERVICE _pService, - _In_ USHORT _uCharacteristicsBufferCount, - _Out_writes_to_opt_(_uCharacteristicsBufferCount, *_puCharacteristicsBufferActual) PBTH_LE_GATT_CHARACTERISTIC _pCharacteristicsBuffer, - _Out_ USHORT* _puCharacteristicsBufferActual, - _In_ ULONG _fFlags - ) + // 最低受支持的客户端 Windows 8及更高版本的 Windows 中受支持。 + __DEFINE_THUNK( + bluetoothapis, + 24, + HRESULT, + WINAPI, + BluetoothGATTGetCharacteristics, + _In_ HANDLE _hDevice, + _In_opt_ PBTH_LE_GATT_SERVICE _pService, + _In_ USHORT _uCharacteristicsBufferCount, + _Out_writes_to_opt_(_uCharacteristicsBufferCount, *_puCharacteristicsBufferActual) PBTH_LE_GATT_CHARACTERISTIC _pCharacteristicsBuffer, + _Out_ USHORT* _puCharacteristicsBufferActual, + _In_ ULONG _fFlags + ) + { + if (const auto _pfnBluetoothGATTGetCharacteristics = try_get_BluetoothGATTGetCharacteristics()) { - if (const auto _pfnBluetoothGATTGetCharacteristics = try_get_BluetoothGATTGetCharacteristics()) - { - return _pfnBluetoothGATTGetCharacteristics(_hDevice, _pService, _uCharacteristicsBufferCount, _pCharacteristicsBuffer, _puCharacteristicsBufferActual, _fFlags); - } + return _pfnBluetoothGATTGetCharacteristics(_hDevice, _pService, _uCharacteristicsBufferCount, _pCharacteristicsBuffer, _puCharacteristicsBufferActual, _fFlags); + } - if (_puCharacteristicsBufferActual) - *_puCharacteristicsBufferActual = 0; + if (_puCharacteristicsBufferActual) + *_puCharacteristicsBufferActual = 0; - return ERROR_NOT_SUPPORTED; - } + return ERROR_NOT_SUPPORTED; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8߰汾 Windows ֧֡ - __DEFINE_THUNK( - bluetoothapis, - 24, - HRESULT, - WINAPI, - BluetoothGATTGetDescriptors, - _In_ HANDLE _hDevice, - _In_ PBTH_LE_GATT_CHARACTERISTIC _pCharacteristic, - _In_ USHORT _uDescriptorsBufferCount, - _Out_writes_to_opt_(_uDescriptorsBufferCount, *_puDescriptorsBufferActual) PBTH_LE_GATT_DESCRIPTOR _pDescriptorsBuffer, - _Out_ USHORT* _puDescriptorsBufferActual, - _In_ ULONG _fFlags - ) + // 最低受支持的客户端 Windows 8及更高版本的 Windows 中受支持。 + __DEFINE_THUNK( + bluetoothapis, + 24, + HRESULT, + WINAPI, + BluetoothGATTGetDescriptors, + _In_ HANDLE _hDevice, + _In_ PBTH_LE_GATT_CHARACTERISTIC _pCharacteristic, + _In_ USHORT _uDescriptorsBufferCount, + _Out_writes_to_opt_(_uDescriptorsBufferCount, *_puDescriptorsBufferActual) PBTH_LE_GATT_DESCRIPTOR _pDescriptorsBuffer, + _Out_ USHORT* _puDescriptorsBufferActual, + _In_ ULONG _fFlags + ) + { + if (const auto _pfnBluetoothGATTGetDescriptors = try_get_BluetoothGATTGetDescriptors()) { - if (const auto _pfnBluetoothGATTGetDescriptors = try_get_BluetoothGATTGetDescriptors()) - { - return _pfnBluetoothGATTGetDescriptors(_hDevice, _pCharacteristic, _uDescriptorsBufferCount, _pDescriptorsBuffer, _puDescriptorsBufferActual, _fFlags); - } + return _pfnBluetoothGATTGetDescriptors(_hDevice, _pCharacteristic, _uDescriptorsBufferCount, _pDescriptorsBuffer, _puDescriptorsBufferActual, _fFlags); + } - if (_puDescriptorsBufferActual) - *_puDescriptorsBufferActual = 0; + if (_puDescriptorsBufferActual) + *_puDescriptorsBufferActual = 0; - return ERROR_NOT_SUPPORTED; - } + return ERROR_NOT_SUPPORTED; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8߰汾 Windows ֧֡ - __DEFINE_THUNK( - bluetoothapis, - 20, - HRESULT, - WINAPI, - BluetoothGATTGetServices, - _In_ HANDLE _hDevice, - _In_ USHORT _uServicesBufferCount, - _Out_writes_to_opt_(_uServicesBufferCount, *_puServicesBufferActual) PBTH_LE_GATT_SERVICE _pServicesBuffer, - _Out_ USHORT* _puServicesBufferActual, - _In_ ULONG _fFlags - ) + // 最低受支持的客户端 Windows 8及更高版本的 Windows 中受支持。 + __DEFINE_THUNK( + bluetoothapis, + 20, + HRESULT, + WINAPI, + BluetoothGATTGetServices, + _In_ HANDLE _hDevice, + _In_ USHORT _uServicesBufferCount, + _Out_writes_to_opt_(_uServicesBufferCount, *_puServicesBufferActual) PBTH_LE_GATT_SERVICE _pServicesBuffer, + _Out_ USHORT* _puServicesBufferActual, + _In_ ULONG _fFlags + ) + { + if (const auto _pfnBluetoothGATTGetServices = try_get_BluetoothGATTGetServices()) { - if (const auto _pfnBluetoothGATTGetServices = try_get_BluetoothGATTGetServices()) - { - return _pfnBluetoothGATTGetServices(_hDevice, _uServicesBufferCount, _pServicesBuffer, _puServicesBufferActual, _fFlags); - } + return _pfnBluetoothGATTGetServices(_hDevice, _uServicesBufferCount, _pServicesBuffer, _puServicesBufferActual, _fFlags); + } - if (_puServicesBufferActual) - *_puServicesBufferActual = 0; + if (_puServicesBufferActual) + *_puServicesBufferActual = 0; - return ERROR_NOT_SUPPORTED; - } + return ERROR_NOT_SUPPORTED; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8߰汾 Windows ֧֡ - __DEFINE_THUNK( - bluetoothapis, - 28, - HRESULT, - WINAPI, - BluetoothGATTRegisterEvent, - _In_ HANDLE _hService, - _In_ BTH_LE_GATT_EVENT_TYPE _eEventType, - _In_ PVOID _pEventParameterIn, - _In_ PFNBLUETOOTH_GATT_EVENT_CALLBACK _pfnCallback, - _In_opt_ PVOID _pCallbackContext, - _Out_ BLUETOOTH_GATT_EVENT_HANDLE * _pEventHandle, - _In_ ULONG _fFlags - ) + // 最低受支持的客户端 Windows 8及更高版本的 Windows 中受支持。 + __DEFINE_THUNK( + bluetoothapis, + 28, + HRESULT, + WINAPI, + BluetoothGATTRegisterEvent, + _In_ HANDLE _hService, + _In_ BTH_LE_GATT_EVENT_TYPE _eEventType, + _In_ PVOID _pEventParameterIn, + _In_ PFNBLUETOOTH_GATT_EVENT_CALLBACK _pfnCallback, + _In_opt_ PVOID _pCallbackContext, + _Out_ BLUETOOTH_GATT_EVENT_HANDLE * _pEventHandle, + _In_ ULONG _fFlags + ) + { + if (const auto _pfnBluetoothGATTRegisterEvent = try_get_BluetoothGATTRegisterEvent()) { - if (const auto _pfnBluetoothGATTRegisterEvent = try_get_BluetoothGATTRegisterEvent()) - { - return _pfnBluetoothGATTRegisterEvent(_hService, _eEventType, _pEventParameterIn, _pfnCallback, _pCallbackContext, _pEventHandle, _fFlags); - } - - return ERROR_NOT_SUPPORTED; + return _pfnBluetoothGATTRegisterEvent(_hService, _eEventType, _pEventParameterIn, _pfnCallback, _pCallbackContext, _pEventHandle, _fFlags); } + + return ERROR_NOT_SUPPORTED; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8߰汾 Windows ֧֡ - __DEFINE_THUNK( - bluetoothapis, - 24, - HRESULT, - WINAPI, - BluetoothGATTSetCharacteristicValue, - _In_ HANDLE _hDevice, - _In_ PBTH_LE_GATT_CHARACTERISTIC _pCharacteristic, - _In_ PBTH_LE_GATT_CHARACTERISTIC_VALUE _pCharacteristicValue, - _In_opt_ BTH_LE_GATT_RELIABLE_WRITE_CONTEXT _ReliableWriteContext, - _In_ ULONG _fFlags - ) + // 最低受支持的客户端 Windows 8及更高版本的 Windows 中受支持。 + __DEFINE_THUNK( + bluetoothapis, + 24, + HRESULT, + WINAPI, + BluetoothGATTSetCharacteristicValue, + _In_ HANDLE _hDevice, + _In_ PBTH_LE_GATT_CHARACTERISTIC _pCharacteristic, + _In_ PBTH_LE_GATT_CHARACTERISTIC_VALUE _pCharacteristicValue, + _In_opt_ BTH_LE_GATT_RELIABLE_WRITE_CONTEXT _ReliableWriteContext, + _In_ ULONG _fFlags + ) + { + if (const auto _pfnBluetoothGATTSetCharacteristicValue = try_get_BluetoothGATTSetCharacteristicValue()) { - if (const auto _pfnBluetoothGATTSetCharacteristicValue = try_get_BluetoothGATTSetCharacteristicValue()) - { - return _pfnBluetoothGATTSetCharacteristicValue(_hDevice, _pCharacteristic, _pCharacteristicValue, _ReliableWriteContext, _fFlags); - } - - return ERROR_NOT_SUPPORTED; + return _pfnBluetoothGATTSetCharacteristicValue(_hDevice, _pCharacteristic, _pCharacteristicValue, _ReliableWriteContext, _fFlags); } + + return ERROR_NOT_SUPPORTED; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8߰汾 Windows ֧֡ - __DEFINE_THUNK( - bluetoothapis, - 16, - HRESULT, - WINAPI, - BluetoothGATTSetDescriptorValue, - _In_ HANDLE _hDevice, - _In_ PBTH_LE_GATT_DESCRIPTOR _pDescriptor, - _In_ PBTH_LE_GATT_DESCRIPTOR_VALUE _pDescriptorValue, - _In_ ULONG _fFlags - ) + // 最低受支持的客户端 Windows 8及更高版本的 Windows 中受支持。 + __DEFINE_THUNK( + bluetoothapis, + 16, + HRESULT, + WINAPI, + BluetoothGATTSetDescriptorValue, + _In_ HANDLE _hDevice, + _In_ PBTH_LE_GATT_DESCRIPTOR _pDescriptor, + _In_ PBTH_LE_GATT_DESCRIPTOR_VALUE _pDescriptorValue, + _In_ ULONG _fFlags + ) + { + if (const auto _pfnBluetoothGATTSetDescriptorValue = try_get_BluetoothGATTSetDescriptorValue()) { - if (const auto _pfnBluetoothGATTSetDescriptorValue = try_get_BluetoothGATTSetDescriptorValue()) - { - return _pfnBluetoothGATTSetDescriptorValue(_hDevice, _pDescriptor, _pDescriptorValue, _fFlags); - } - - return ERROR_NOT_SUPPORTED; + return _pfnBluetoothGATTSetDescriptorValue(_hDevice, _pDescriptor, _pDescriptorValue, _fFlags); } + + return ERROR_NOT_SUPPORTED; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8߰汾 Windows ֧֡ - __DEFINE_THUNK( - bluetoothapis, - 8, - HRESULT, - WINAPI, - BluetoothGATTUnregisterEvent, - _In_ BLUETOOTH_GATT_EVENT_HANDLE _hEventHandle, - _In_ ULONG _fFlags - ) + // 最低受支持的客户端 Windows 8及更高版本的 Windows 中受支持。 + __DEFINE_THUNK( + bluetoothapis, + 8, + HRESULT, + WINAPI, + BluetoothGATTUnregisterEvent, + _In_ BLUETOOTH_GATT_EVENT_HANDLE _hEventHandle, + _In_ ULONG _fFlags + ) + { + if (const auto _pfnBluetoothGATTUnregisterEvent = try_get_BluetoothGATTUnregisterEvent()) { - if (const auto _pfnBluetoothGATTUnregisterEvent = try_get_BluetoothGATTUnregisterEvent()) - { - return _pfnBluetoothGATTUnregisterEvent(_hEventHandle, _fFlags); - } - - return ERROR_NOT_SUPPORTED; + return _pfnBluetoothGATTUnregisterEvent(_hEventHandle, _fFlags); } -#endif + + return ERROR_NOT_SUPPORTED; } -} \ No newline at end of file +#endif +} // namespace YY::Thunks diff --git a/src/Thunks/mfplat.hpp b/src/Thunks/mfplat.hpp index 797936e..a312731 100644 --- a/src/Thunks/mfplat.hpp +++ b/src/Thunks/mfplat.hpp @@ -1,118 +1,121 @@ -#if (YY_Thunks_Support_Version < NTDDI_WIN8) +#if (YY_Thunks_Support_Version < NTDDI_WIN8) #include #endif -namespace YY +#if (YY_Thunks_Support_Version < NTDDI_WIN8) && !defined(__Comment_Lib_mfplat) +#define __Comment_Lib_mfplat +#pragma comment(lib, "Mfplat.lib") +#endif + +namespace YY::Thunks { - namespace Thunks - { #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ|UWP Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ | UWP Ӧ] - __DEFINE_THUNK( - mfplat, - 8, - HRESULT, - STDAPICALLTYPE, - MFCreateDXGIDeviceManager, - _Out_ UINT* _puResetToken, - _Outptr_ IMFDXGIDeviceManager** _ppDeviceManager - ) + // 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用] + // 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用] + __DEFINE_THUNK( + mfplat, + 8, + HRESULT, + STDAPICALLTYPE, + MFCreateDXGIDeviceManager, + _Out_ UINT* _puResetToken, + _Outptr_ IMFDXGIDeviceManager** _ppDeviceManager + ) + { + if (const auto _pfnMFCreateDXGIDeviceManager = try_get_MFCreateDXGIDeviceManager()) { - if (const auto _pfnMFCreateDXGIDeviceManager = try_get_MFCreateDXGIDeviceManager()) - { - return _pfnMFCreateDXGIDeviceManager(_puResetToken, _ppDeviceManager); - } + return _pfnMFCreateDXGIDeviceManager(_puResetToken, _ppDeviceManager); + } - if (_puResetToken) - *_puResetToken = 0; - if (_ppDeviceManager) - *_ppDeviceManager = nullptr; + if (_puResetToken) + *_puResetToken = 0; + if (_ppDeviceManager) + *_ppDeviceManager = nullptr; - if (_puResetToken == nullptr || _ppDeviceManager == nullptr) - return E_INVALIDARG; - return E_NOTIMPL; - } + if (_puResetToken == nullptr || _ppDeviceManager == nullptr) + return E_INVALIDARG; + return E_NOTIMPL; + } #endif #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ|UWP Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ | UWP Ӧ] - __DEFINE_THUNK( - mfplat, - 20, - HRESULT, - STDAPICALLTYPE, - MFCreateDXGISurfaceBuffer, - _In_ REFIID _id, - _In_ IUnknown* _punkSurface, - _In_ UINT _uSubresourceIndex, - _In_ BOOL _bBottomUpWhenLinear, - _Outptr_ IMFMediaBuffer** _ppBuffer - ) + // 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用] + // 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用] + __DEFINE_THUNK( + mfplat, + 20, + HRESULT, + STDAPICALLTYPE, + MFCreateDXGISurfaceBuffer, + _In_ REFIID _id, + _In_ IUnknown* _punkSurface, + _In_ UINT _uSubresourceIndex, + _In_ BOOL _bBottomUpWhenLinear, + _Outptr_ IMFMediaBuffer** _ppBuffer + ) + { + if (const auto _pfnMFCreateDXGISurfaceBuffer = try_get_MFCreateDXGISurfaceBuffer()) { - if (const auto _pfnMFCreateDXGISurfaceBuffer = try_get_MFCreateDXGISurfaceBuffer()) - { - return _pfnMFCreateDXGISurfaceBuffer(_id, _punkSurface, _uSubresourceIndex, _bBottomUpWhenLinear, _ppBuffer); - } - - if(!_ppBuffer) - return E_INVALIDARG; - *_ppBuffer = nullptr; - return E_NOTIMPL; + return _pfnMFCreateDXGISurfaceBuffer(_id, _punkSurface, _uSubresourceIndex, _bBottomUpWhenLinear, _ppBuffer); } + + if(!_ppBuffer) + return E_INVALIDARG; + *_ppBuffer = nullptr; + return E_NOTIMPL; + } #endif #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ|UWP Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ | UWP Ӧ] - __DEFINE_THUNK( - mfplat, - 8, - HRESULT, - STDAPICALLTYPE, - MFLockDXGIDeviceManager, - _Out_opt_ UINT* _puResetToken, - _Outptr_ IMFDXGIDeviceManager** _ppManager - ) + // 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用] + // 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用] + __DEFINE_THUNK( + mfplat, + 8, + HRESULT, + STDAPICALLTYPE, + MFLockDXGIDeviceManager, + _Out_opt_ UINT* _puResetToken, + _Outptr_ IMFDXGIDeviceManager** _ppManager + ) + { + if (const auto _pfnMFLockDXGIDeviceManager = try_get_MFLockDXGIDeviceManager()) { - if (const auto _pfnMFLockDXGIDeviceManager = try_get_MFLockDXGIDeviceManager()) - { - return _pfnMFLockDXGIDeviceManager(_puResetToken, _ppManager); - } - - if (_puResetToken) - *_puResetToken = 0; - if (_ppManager) - *_ppManager = nullptr; - if(_puResetToken == nullptr || _ppManager == nullptr) - return E_INVALIDARG; - return E_NOTIMPL; + return _pfnMFLockDXGIDeviceManager(_puResetToken, _ppManager); } + + if (_puResetToken) + *_puResetToken = 0; + if (_ppManager) + *_ppManager = nullptr; + if(_puResetToken == nullptr || _ppManager == nullptr) + return E_INVALIDARG; + return E_NOTIMPL; + } #endif #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ|UWP Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ | UWP Ӧ] - __DEFINE_THUNK( - mfplat, - 0, - HRESULT, - STDAPICALLTYPE, - MFUnlockDXGIDeviceManager, - ) + // 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用] + // 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用] + __DEFINE_THUNK( + mfplat, + 0, + HRESULT, + STDAPICALLTYPE, + MFUnlockDXGIDeviceManager, + ) + { + if (const auto _pfnMFUnlockDXGIDeviceManager = try_get_MFUnlockDXGIDeviceManager()) { - if (const auto _pfnMFUnlockDXGIDeviceManager = try_get_MFUnlockDXGIDeviceManager()) - { - return _pfnMFUnlockDXGIDeviceManager(); - } - - return E_NOTIMPL; + return _pfnMFUnlockDXGIDeviceManager(); } -#endif + + return E_NOTIMPL; } -} +#endif + +} // namespace YY::Thunks diff --git a/src/Thunks/netapi32.hpp b/src/Thunks/netapi32.hpp index 871089d..974f2bb 100644 --- a/src/Thunks/netapi32.hpp +++ b/src/Thunks/netapi32.hpp @@ -1,59 +1,62 @@ -#if (YY_Thunks_Support_Version < NTDDI_WIN10) +#if (YY_Thunks_Support_Version < NTDDI_WIN10) #include #endif -namespace YY +#if (YY_Thunks_Support_Version < NTDDI_WIN10) && !defined(__Comment_Lib_netapi32) +#define __Comment_Lib_netapi32 +#pragma comment(lib, "Netapi32.lib") +#endif + +namespace YY::Thunks { - namespace Thunks - { #if (YY_Thunks_Support_Version < NTDDI_WIN10) - // ֵ֧Ŀͻ Windows 10 [Ӧ] - // ֵ֧ķ Windows Server 2016[Ӧ] - __DEFINE_THUNK( - netapi32, - 8, - HRESULT, - NET_API_FUNCTION, - NetGetAadJoinInformation, - _In_opt_ LPCWSTR _szTenantId, - _Outptr_result_maybenull_ PDSREG_JOIN_INFO* _ppJoinInfo - ) + // 最低受支持的客户端 Windows 10 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2016[仅限桌面应用] + __DEFINE_THUNK( + netapi32, + 8, + HRESULT, + NET_API_FUNCTION, + NetGetAadJoinInformation, + _In_opt_ LPCWSTR _szTenantId, + _Outptr_result_maybenull_ PDSREG_JOIN_INFO* _ppJoinInfo + ) + { + if (const auto _pfnNetGetAadJoinInformation = try_get_NetGetAadJoinInformation()) { - if (const auto _pfnNetGetAadJoinInformation = try_get_NetGetAadJoinInformation()) - { - return _pfnNetGetAadJoinInformation(_szTenantId, _ppJoinInfo); - } - if (!_ppJoinInfo) - return E_INVALIDARG; - - // ΪԼûм Azure AD ʻ - *_ppJoinInfo = nullptr; - return S_OK; + return _pfnNetGetAadJoinInformation(_szTenantId, _ppJoinInfo); } + if (!_ppJoinInfo) + return E_INVALIDARG; + + // 总是认为自己没有加入 Azure AD 帐户。 + *_ppJoinInfo = nullptr; + return S_OK; + } #endif - + + #if (YY_Thunks_Support_Version < NTDDI_WIN10) - // ֵ֧Ŀͻ Windows 10 [Ӧ] - // ֵ֧ķ Windows Server 2016[Ӧ] - __DEFINE_THUNK( - netapi32, - 8, - VOID, - NET_API_FUNCTION, - NetFreeAadJoinInformation, - _In_opt_ PDSREG_JOIN_INFO _pJoinInfo - ) + // 最低受支持的客户端 Windows 10 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2016[仅限桌面应用] + __DEFINE_THUNK( + netapi32, + 8, + VOID, + NET_API_FUNCTION, + NetFreeAadJoinInformation, + _In_opt_ PDSREG_JOIN_INFO _pJoinInfo + ) + { + if (const auto _pfnNetFreeAadJoinInformation = try_get_NetFreeAadJoinInformation()) { - if (const auto _pfnNetFreeAadJoinInformation = try_get_NetFreeAadJoinInformation()) - { - return _pfnNetFreeAadJoinInformation(_pJoinInfo); - } - - // ʲôҲϰ汾ϵͳܻõϢ - UNREFERENCED_PARAMETER(_pJoinInfo); + return _pfnNetFreeAadJoinInformation(_pJoinInfo); } -#endif + + // 什么也不做,老版本系统不可能会拿到这个信息。 + UNREFERENCED_PARAMETER(_pJoinInfo); } -} +#endif +} // namespace YY::Thunks diff --git a/src/Thunks/ntdll.hpp b/src/Thunks/ntdll.hpp index 20a1df3..53bceb9 100644 --- a/src/Thunks/ntdll.hpp +++ b/src/Thunks/ntdll.hpp @@ -1,36 +1,33 @@ -namespace YY +namespace YY::Thunks { - namespace Thunks - { #if (YY_Thunks_Support_Version < NTDDI_WIN6) - // ֵ֧Ŀͻ Windows Vista [Ӧ|UWP Ӧ] - // ֵ֧ķ Windows Server 2008[Ӧ | UWP Ӧ] - __DEFINE_THUNK( - ntdll, - 12, - NTSTATUS, - NTAPI, - NtCancelIoFileEx, - HANDLE handle, - IO_STATUS_BLOCK* io, - IO_STATUS_BLOCK* io_status - ) - { - if (const auto _pfnNtCancelIoFileEx = try_get_NtCancelIoFileEx()) - { - return _pfnNtCancelIoFileEx(handle, io, io_status); - } + // 最低受支持的客户端 Windows Vista [桌面应用|UWP 应用] + // 最低受支持的服务器 Windows Server 2008[桌面应用 | UWP 应用] + __DEFINE_THUNK( + ntdll, + 12, + NTSTATUS, + NTAPI, + NtCancelIoFileEx, + HANDLE handle, + IO_STATUS_BLOCK* io, + IO_STATUS_BLOCK* io_status + ) + { + if (const auto _pfnNtCancelIoFileEx = try_get_NtCancelIoFileEx()) + { + return _pfnNtCancelIoFileEx(handle, io, io_status); + } - // 㣬еĵ - if (const auto _pfnNtCancelIoFile = try_get_NtCancelIoFile()) - { - return _pfnNtCancelIoFile(handle, io_status); - } - - // ˵Ӧߵ - return STATUS_NOT_SUPPORTED; - } -#endif + // 最坏打算,清除所有的调用 + if (const auto _pfnNtCancelIoFile = try_get_NtCancelIoFile()) + { + return _pfnNtCancelIoFile(handle, io_status); + } + + // 正常来说不应该走到这里 + return STATUS_NOT_SUPPORTED; } -} +#endif +} // namespace YY::Thunks diff --git a/src/Thunks/powrprof.hpp b/src/Thunks/powrprof.hpp index 4c515ba..2c528f0 100644 --- a/src/Thunks/powrprof.hpp +++ b/src/Thunks/powrprof.hpp @@ -1,31 +1,33 @@ -#if (YY_Thunks_Support_Version < NTDDI_VISTA) +#if (YY_Thunks_Support_Version < NTDDI_VISTA) #include #endif -namespace YY +#if (YY_Thunks_Support_Version < NTDDI_VISTA) && !defined(__Comment_Lib_powrProf) +#define __Comment_Lib_powrProf +#pragma comment(lib, "PowrProf.lib") +#endif + +namespace YY::Thunks { - namespace Thunks - { #if (YY_Thunks_Support_Version < NTDDI_VISTA) - // ֵ֧Ŀͻ Windows 8 [Ӧ|UWP Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ | UWP Ӧ] - __DEFINE_THUNK( - powrprof, - 0, - POWER_PLATFORM_ROLE, - WINAPI, - PowerDeterminePlatformRole, - ) - { - if (auto const _pfnPowerDeterminePlatformRole = try_get_PowerDeterminePlatformRole()) - { - return _pfnPowerDeterminePlatformRole(); - } + // 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用] + // 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用] + __DEFINE_THUNK( + powrprof, + 0, + POWER_PLATFORM_ROLE, + WINAPI, + PowerDeterminePlatformRole, + ) + { + if (auto const _pfnPowerDeterminePlatformRole = try_get_PowerDeterminePlatformRole()) + { + return _pfnPowerDeterminePlatformRole(); + } - // ٶԼûе - return PlatformRoleDesktop; - } + // 假定自己没有电池 + return PlatformRoleDesktop; + } #endif - } -} +} // namespace YY::Thunks diff --git a/src/Thunks/userenv.hpp b/src/Thunks/userenv.hpp index 391da1d..a4d3820 100644 --- a/src/Thunks/userenv.hpp +++ b/src/Thunks/userenv.hpp @@ -1,136 +1,142 @@ -#if (YY_Thunks_Support_Version < NTDDI_WIN8) +#if (YY_Thunks_Support_Version < NTDDI_WIN8) #include #endif -namespace YY +#if (YY_Thunks_Support_Version < NTDDI_WIN8) && !defined(__Comment_Lib_userenv) +#define __Comment_Lib_userenv +#pragma comment(lib, "Userenv.lib") +#endif + +namespace YY::Thunks { - namespace Thunks - { #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ] - __DEFINE_THUNK( - userenv, - 24, - HRESULT, - WINAPI, - CreateAppContainerProfile, - _In_ PCWSTR _szAppContainerName, - _In_ PCWSTR _szDisplayName, - _In_ PCWSTR _szDescription, - _In_reads_opt_(_uCapabilityCount) PSID_AND_ATTRIBUTES _pCapabilities, - _In_ DWORD _uCapabilityCount, - _Outptr_ PSID* _ppSidAppContainerSid - ) + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012[仅限桌面应用] + __DEFINE_THUNK( + userenv, + 24, + HRESULT, + WINAPI, + CreateAppContainerProfile, + _In_ PCWSTR _szAppContainerName, + _In_ PCWSTR _szDisplayName, + _In_ PCWSTR _szDescription, + _In_reads_opt_(_uCapabilityCount) PSID_AND_ATTRIBUTES _pCapabilities, + _In_ DWORD _uCapabilityCount, + _Outptr_ PSID* _ppSidAppContainerSid + ) + { + if (const auto _pfnCreateAppContainerProfile = try_get_CreateAppContainerProfile()) { - if (const auto _pfnCreateAppContainerProfile = try_get_CreateAppContainerProfile()) - { - return _pfnCreateAppContainerProfile(_szAppContainerName, _szDisplayName, _szDescription, _pCapabilities, _uCapabilityCount, _ppSidAppContainerSid); - } - - if (!_ppSidAppContainerSid) - return E_INVALIDARG; - *_ppSidAppContainerSid = nullptr; - return E_NOTIMPL; + return _pfnCreateAppContainerProfile(_szAppContainerName, _szDisplayName, _szDescription, _pCapabilities, _uCapabilityCount, _ppSidAppContainerSid); } + + if (!_ppSidAppContainerSid) + return E_INVALIDARG; + *_ppSidAppContainerSid = nullptr; + return E_NOTIMPL; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ] - __DEFINE_THUNK( - userenv, - 4, - HRESULT, - WINAPI, - DeleteAppContainerProfile, - _In_ PCWSTR _szAppContainerName - ) + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012[仅限桌面应用] + __DEFINE_THUNK( + userenv, + 4, + HRESULT, + WINAPI, + DeleteAppContainerProfile, + _In_ PCWSTR _szAppContainerName + ) + { + if (const auto _pfnDeleteAppContainerProfile = try_get_DeleteAppContainerProfile()) { - if (const auto _pfnDeleteAppContainerProfile = try_get_DeleteAppContainerProfile()) - { - return _pfnDeleteAppContainerProfile(_szAppContainerName); - } - - return E_NOTIMPL; + return _pfnDeleteAppContainerProfile(_szAppContainerName); } + + return E_NOTIMPL; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ] - __DEFINE_THUNK( - userenv, - 8, - HRESULT, - WINAPI, - DeriveAppContainerSidFromAppContainerName, - _In_ PCWSTR _szAppContainerName, - _Outptr_ PSID* _ppsidAppContainerSid - ) + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012[仅限桌面应用] + __DEFINE_THUNK( + userenv, + 8, + HRESULT, + WINAPI, + DeriveAppContainerSidFromAppContainerName, + _In_ PCWSTR _szAppContainerName, + _Outptr_ PSID* _ppsidAppContainerSid + ) + { + if (const auto _pfnDeriveAppContainerSidFromAppContainerName = try_get_DeriveAppContainerSidFromAppContainerName()) { - if (const auto _pfnDeriveAppContainerSidFromAppContainerName = try_get_DeriveAppContainerSidFromAppContainerName()) - { - return _pfnDeriveAppContainerSidFromAppContainerName(_szAppContainerName, _ppsidAppContainerSid); - } - if (!_ppsidAppContainerSid) - return E_INVALIDARG; - *_ppsidAppContainerSid = nullptr; - return E_NOTIMPL; + return _pfnDeriveAppContainerSidFromAppContainerName(_szAppContainerName, _ppsidAppContainerSid); } + if (!_ppsidAppContainerSid) + return E_INVALIDARG; + *_ppsidAppContainerSid = nullptr; + return E_NOTIMPL; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ] - __DEFINE_THUNK( - userenv, - 8, - HRESULT, - WINAPI, - GetAppContainerFolderPath, - _In_ PCWSTR _szAppContainerSid, - _Outptr_ PWSTR* _ppszPath - ) + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012[仅限桌面应用] + __DEFINE_THUNK( + userenv, + 8, + HRESULT, + WINAPI, + GetAppContainerFolderPath, + _In_ PCWSTR _szAppContainerSid, + _Outptr_ PWSTR* _ppszPath + ) + { + if (const auto _pfnGetAppContainerFolderPath = try_get_GetAppContainerFolderPath()) { - if (const auto _pfnGetAppContainerFolderPath = try_get_GetAppContainerFolderPath()) - { - return _pfnGetAppContainerFolderPath(_szAppContainerSid, _ppszPath); - } - if (!_ppszPath) - return E_INVALIDARG; - *_ppszPath = nullptr; - return E_NOTIMPL; + return _pfnGetAppContainerFolderPath(_szAppContainerSid, _ppszPath); } + if (!_ppszPath) + return E_INVALIDARG; + *_ppszPath = nullptr; + return E_NOTIMPL; + } #endif + #if (YY_Thunks_Support_Version < NTDDI_WIN8) - // ֵ֧Ŀͻ Windows 8 [Ӧ] - // ֵ֧ķ Windows Server 2012[Ӧ] - __DEFINE_THUNK( - userenv, - 8, - HRESULT, - WINAPI, - GetAppContainerRegistryLocation, - _In_ REGSAM _DesiredAccess, - _Outptr_ PHKEY _phAppContainerKey - ) + // 最低受支持的客户端 Windows 8 [仅限桌面应用] + // 最低受支持的服务器 Windows Server 2012[仅限桌面应用] + __DEFINE_THUNK( + userenv, + 8, + HRESULT, + WINAPI, + GetAppContainerRegistryLocation, + _In_ REGSAM _DesiredAccess, + _Outptr_ PHKEY _phAppContainerKey + ) + { + if (const auto _pfnGetAppContainerRegistryLocation = try_get_GetAppContainerRegistryLocation()) { - if (const auto _pfnGetAppContainerRegistryLocation = try_get_GetAppContainerRegistryLocation()) - { - return _pfnGetAppContainerRegistryLocation(_DesiredAccess, _phAppContainerKey); - } - if (!_phAppContainerKey) - return E_INVALIDARG; - *_phAppContainerKey = NULL; - return E_NOTIMPL; + return _pfnGetAppContainerRegistryLocation(_DesiredAccess, _phAppContainerKey); } -#endif + if (!_phAppContainerKey) + return E_INVALIDARG; + *_phAppContainerKey = NULL; + return E_NOTIMPL; } -} +#endif +} // namespace YY::Thunks