Skip to content

Commit

Permalink
Fea #71, 让qt5.15.12支持XP,改进iphlpapi支持
Browse files Browse the repository at this point in the history
  - 添加 ConvertInterfaceLuidToIndex
  - 添加 ConvertInterfaceLuidToGuid
  • Loading branch information
mingkuang-Chuyu committed May 20, 2024
1 parent 8c80dbf commit 241874c
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
| ConvertInterfaceNameToLuidW(A) | 不存在时,内部实现。
| if_nametoindex | 不存在时,调用GetIfEntry。
| if_indextoname | 不存在时,调用ConvertInterfaceIndexToLuid、ConvertInterfaceLuidToNameA。
| ConvertInterfaceLuidToGuid | 不存在时,调用GetIfEntry。
| ConvertInterfaceLuidToIndex | 不存在时,内部实现。

## kernel32.dll
| 函数 | Fallback
Expand Down
72 changes: 71 additions & 1 deletion src/Thunks/Iphlpapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ namespace YY
#endif



#if (YY_Thunks_Support_Version < NTDDI_WIN6)

// 最低受支持的客户端 Windows Vista [桌面应用|UWP 应用]
Expand Down Expand Up @@ -663,5 +662,76 @@ namespace YY
return InterfaceName;
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN6)

// 最低受支持的客户端 Windows Vista [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008[仅限桌面应用]
__DEFINE_THUNK(
iphlpapi,
8,
NETIO_STATUS,
NETIOAPI_API_,
ConvertInterfaceLuidToGuid,
_In_ CONST NET_LUID* _pInterfaceLuid,
_Out_ GUID* _pInterfaceGuid
)
{
if (const auto _pfnConvertInterfaceLuidToGuid = try_get_ConvertInterfaceLuidToGuid())
{
return _pfnConvertInterfaceLuidToGuid(_pInterfaceLuid, _pInterfaceGuid);
}

if (_pInterfaceLuid == nullptr || _pInterfaceGuid == nullptr)
{
return ERROR_INVALID_PARAMETER;
}

MIB_IFROW _IfRow;
_IfRow.dwIndex = _pInterfaceLuid->Info.NetLuidIndex;

auto _lStatus = GetIfEntry(&_IfRow);
if (NO_ERROR != _lStatus)
return _lStatus;

if (!internal::StringToGuid(wcsrchr(_IfRow.wszName, L'{'), _pInterfaceGuid))
{
return ERROR_BAD_FORMAT;
}

return ERROR_SUCCESS;
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN6)

// 最低受支持的客户端 Windows Vista [仅限桌面应用]
// 最低受支持的服务器 Windows Server 2008[仅限桌面应用]
__DEFINE_THUNK(
iphlpapi,
8,
NETIO_STATUS,
NETIOAPI_API_,
ConvertInterfaceLuidToIndex,
_In_ CONST NET_LUID* _pInterfaceLuid,
_Out_ PNET_IFINDEX _pInterfaceIndex
)
{
if (const auto _pfnConvertInterfaceLuidToIndex = try_get_ConvertInterfaceLuidToIndex())
{
return _pfnConvertInterfaceLuidToIndex(_pInterfaceLuid, _pInterfaceIndex);
}

if (_pInterfaceLuid == nullptr || _pInterfaceIndex == nullptr)
{
return ERROR_INVALID_PARAMETER;
}

*_pInterfaceIndex = _pInterfaceLuid->Info.NetLuidIndex;
return ERROR_SUCCESS;
}
#endif
}
}
34 changes: 34 additions & 0 deletions src/YY-Thunks.UnitTest/Iphlpapi.UnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,38 @@ namespace Iphlpapi
Assert::AreEqual(_uResultIndex, NET_IFINDEX(1));
}
};


TEST_CLASS(ConvertInterfaceLuidToGuid)
{
public:
ConvertInterfaceLuidToGuid()
{
}

TEST_METHOD(交叉验证)
{
NET_LUID InterfaceLuid;
auto _lStatus = ConvertInterfaceIndexToLuid(1, &InterfaceLuid);
Assert::AreEqual(_lStatus, (DWORD)ERROR_SUCCESS);

GUID InterfaceGuid1;
_lStatus = ::ConvertInterfaceLuidToGuid(&InterfaceLuid, &InterfaceGuid1);
Assert::AreEqual(_lStatus, (DWORD)ERROR_SUCCESS);

{
AwaysNullGuard Guard;
Guard |= YY::Thunks::aways_null_try_get_ConvertInterfaceLuidToGuid;

GUID InterfaceGuid2;
NET_LUID InterfaceLuid = {};
InterfaceLuid.Info.NetLuidIndex = 1;
_lStatus = ::ConvertInterfaceLuidToGuid(&InterfaceLuid, &InterfaceGuid2);
Assert::AreEqual(_lStatus, (DWORD)ERROR_SUCCESS);

Assert::AreEqual(InterfaceGuid1, InterfaceGuid2);

}
}
};
}
13 changes: 13 additions & 0 deletions src/YY-Thunks.UnitTest/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,18 @@ inline std::string ToHexString(const BYTE (&_Data)[kDataLength])
return ToHexString(_Data, kDataLength);
}

namespace Microsoft::VisualStudio::CppUnitTestFramework
{
template<>
inline std::wstring ToString<GUID>(const GUID& t)
{
wchar_t _szResult[128] = {};

swprintf_s(_szResult, L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", t.Data1, t.Data2, t.Data3,
t.Data4[0], t.Data4[1], t.Data4[2], t.Data4[3], t.Data4[4], t.Data4[5], t.Data4[7], t.Data4[7]);

return _szResult;
}
}

#endif //PCH_H

0 comments on commit 241874c

Please sign in to comment.