-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fea #90,补充一些Chrome 125 Windows 7缺少的接口
- Loading branch information
1 parent
ea07bce
commit 5e2649f
Showing
9 changed files
with
1,083 additions
and
539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
|
||
#if defined(YY_Thunks_Implemented) | ||
namespace YY::Thunks | ||
{ | ||
namespace | ||
{ | ||
#if (YY_Thunks_Support_Version < NTDDI_WIN10) | ||
static SRWLOCK g_CompareObjectHandles; | ||
#endif | ||
} | ||
} | ||
#endif | ||
|
||
namespace YY::Thunks | ||
{ | ||
|
||
#if (YY_Thunks_Support_Version < NTDDI_WIN10) | ||
|
||
// 最低受支持的客户端 Windows 2000 专业版 [桌面应用 |UWP 应用] | ||
// 最低受支持的服务器 Windows 2000 Server[桌面应用 | UWP 应用] | ||
// 虽然2000就支持,但是为了实现CompareObjectHandles,目前需要处理一下关闭。 | ||
__DEFINE_THUNK( | ||
kernel32, | ||
4, | ||
BOOL, | ||
WINAPI, | ||
CloseHandle, | ||
_In_ _Post_ptr_invalid_ HANDLE _hObject | ||
) | ||
{ | ||
const auto _pfnCloseHandle = try_get_CloseHandle(); | ||
const auto _pfnCompareObjectHandles = try_get_CompareObjectHandles(); | ||
|
||
if (_pfnCompareObjectHandles == nullptr && _hObject && _hObject != INVALID_HANDLE_VALUE) | ||
{ | ||
::AcquireSRWLockShared(&g_CompareObjectHandles); | ||
} | ||
// 空指针故意崩溃 | ||
auto _bRet = _pfnCloseHandle(_hObject); | ||
|
||
if (_pfnCompareObjectHandles == nullptr && _hObject && _hObject != INVALID_HANDLE_VALUE) | ||
{ | ||
auto _lStatus = GetLastError(); | ||
::ReleaseSRWLockShared(&g_CompareObjectHandles); | ||
SetLastError(_lStatus); | ||
} | ||
|
||
return _bRet; | ||
} | ||
#endif | ||
|
||
|
||
#if (YY_Thunks_Support_Version < NTDDI_WIN10) | ||
|
||
// 最低受支持的客户端 Windows 2000 专业版 [桌面应用 |UWP 应用] | ||
// 最低受支持的服务器 Windows 2000 Server[桌面应用 | UWP 应用] | ||
// 虽然2000就支持,但是为了实现CompareObjectHandles,目前需要处理一下关闭。 | ||
__DEFINE_THUNK( | ||
kernel32, | ||
28, | ||
BOOL, | ||
WINAPI, | ||
DuplicateHandle, | ||
_In_ HANDLE _hSourceProcessHandle, | ||
_In_ HANDLE _hSourceHandle, | ||
_In_ HANDLE _hTargetProcessHandle, | ||
_Outptr_ LPHANDLE _phTargetHandle, | ||
_In_ DWORD _fDesiredAccess, | ||
_In_ BOOL _bInheritHandle, | ||
_In_ DWORD _uOptions | ||
) | ||
{ | ||
const auto _pfnDuplicateHandle = try_get_DuplicateHandle(); | ||
const auto _pfnCompareObjectHandles = try_get_CompareObjectHandles(); | ||
|
||
bool _bNeedLock = false; | ||
if (_pfnCompareObjectHandles) | ||
{ | ||
// 无须加锁 | ||
} | ||
if (_hTargetProcessHandle == NtGetCurrentProcess() || GetProcessId(_hTargetProcessHandle) == GetCurrentProcessId()) | ||
{ | ||
_bNeedLock = true; | ||
} | ||
else if ((DUPLICATE_CLOSE_SOURCE & _uOptions) | ||
&& (_hSourceProcessHandle == NtGetCurrentProcess() || GetProcessId(_hSourceProcessHandle) == GetCurrentProcessId())) | ||
{ | ||
_bNeedLock = true; | ||
} | ||
|
||
if (_bNeedLock) | ||
{ | ||
::AcquireSRWLockShared(&g_CompareObjectHandles); | ||
} | ||
|
||
// 空指针故意崩溃 | ||
auto _bRet = _pfnDuplicateHandle(_hSourceProcessHandle, _hSourceHandle, _hTargetProcessHandle, _phTargetHandle, _fDesiredAccess, _bInheritHandle, _uOptions); | ||
|
||
if (_bNeedLock) | ||
{ | ||
auto _lStatus = GetLastError(); | ||
::ReleaseSRWLockShared(&g_CompareObjectHandles); | ||
SetLastError(_lStatus); | ||
} | ||
return _bRet; | ||
} | ||
#endif | ||
|
||
#if (YY_Thunks_Support_Version < NTDDI_WIN10) | ||
|
||
// 最低受支持的客户端 Windows 10 [桌面应用 |UWP 应用] | ||
// 最低受支持的服务器 Windows Server 2016[桌面应用 | UWP 应用] | ||
__DEFINE_THUNK( | ||
api_ms_win_core_handle_l1_1_0, | ||
8, | ||
BOOL, | ||
WINAPI, | ||
CompareObjectHandles, | ||
_In_ HANDLE _hFirstObjectHandle, | ||
_In_ HANDLE _hSecondObjectHandle | ||
) | ||
{ | ||
if (const auto _pfnCompareObjectHandles = try_get_CompareObjectHandles()) | ||
{ | ||
return _pfnCompareObjectHandles(_hFirstObjectHandle, _hSecondObjectHandle); | ||
} | ||
|
||
if (_hFirstObjectHandle == _hSecondObjectHandle) | ||
{ | ||
if (NtGetCurrentProcess() == _hFirstObjectHandle | ||
|| NtGetCurrentThread() == _hFirstObjectHandle) | ||
{ | ||
return TRUE; | ||
} | ||
|
||
const auto _pfnNtQueryObject = try_get_NtQueryObject(); | ||
if (!_pfnNtQueryObject) | ||
return FALSE; | ||
|
||
// 用来检测句柄是否合法 | ||
OBJECT_BASIC_INFORMATION _FirstObjectBaseInfo = {}; | ||
LONG _Status = _pfnNtQueryObject(_hFirstObjectHandle, ObjectBasicInformation, &_FirstObjectBaseInfo, sizeof(_FirstObjectBaseInfo), nullptr); | ||
if (_Status < 0) | ||
{ | ||
return FALSE; | ||
} | ||
return TRUE; | ||
} | ||
|
||
const auto _pfnNtQueryObject = try_get_NtQueryObject(); | ||
if (!_pfnNtQueryObject) | ||
return FALSE; | ||
|
||
OBJECT_BASIC_INFORMATION _FirstObjectBaseInfo = {}; | ||
OBJECT_BASIC_INFORMATION _SecondObjectBaseInfo = {}; | ||
LONG _Status = _pfnNtQueryObject(_hFirstObjectHandle, ObjectBasicInformation, &_FirstObjectBaseInfo, sizeof(_FirstObjectBaseInfo), nullptr); | ||
|
||
// 实际测试,ObjectBasicInformation 只出现无效句柄错误 | ||
if (_Status < 0) | ||
{ | ||
return FALSE; | ||
} | ||
|
||
if (_FirstObjectBaseInfo.HandleCount == 1) | ||
{ | ||
// 引用计数为 1,这肯定不可能与另外一个句柄是同一个内核对象 | ||
return FALSE; | ||
} | ||
|
||
_Status = _pfnNtQueryObject(_hSecondObjectHandle, ObjectBasicInformation, &_SecondObjectBaseInfo, sizeof(_SecondObjectBaseInfo), nullptr); | ||
if (_Status < 0) | ||
{ | ||
return FALSE; | ||
} | ||
|
||
if (_SecondObjectBaseInfo.HandleCount == 1) | ||
{ | ||
// 引用计数为 1,这肯定不可能与另外一个句柄是同一个内核对象 | ||
return FALSE; | ||
} | ||
|
||
if (_FirstObjectBaseInfo.NameInfoSize != _SecondObjectBaseInfo.NameInfoSize | ||
|| _FirstObjectBaseInfo.TypeInfoSize != _SecondObjectBaseInfo.TypeInfoSize | ||
|| _FirstObjectBaseInfo.SecurityDescriptorSize != _SecondObjectBaseInfo.SecurityDescriptorSize | ||
|| _FirstObjectBaseInfo.CreationTime.QuadPart != _SecondObjectBaseInfo.CreationTime.QuadPart) | ||
{ | ||
return FALSE; | ||
} | ||
|
||
const auto _pfnDuplicateHandle = try_get_DuplicateHandle(); | ||
const auto _pfnCloseHandle = try_get_CloseHandle(); | ||
|
||
if (_pfnDuplicateHandle == nullptr || _pfnCloseHandle == nullptr) | ||
return FALSE; | ||
|
||
HANDLE _hFirstTmp = NULL; | ||
BOOL _bHandleIsSame = FALSE; | ||
|
||
::AcquireSRWLockExclusive(&g_CompareObjectHandles); | ||
|
||
for (;;) | ||
{ | ||
if (!_pfnDuplicateHandle(NtGetCurrentProcess(), _hFirstObjectHandle, NtGetCurrentProcess(), &_hFirstTmp, 0, FALSE, 0)) | ||
{ | ||
break; | ||
} | ||
|
||
_Status = _pfnNtQueryObject(_hFirstObjectHandle, ObjectBasicInformation, &_FirstObjectBaseInfo, sizeof(_FirstObjectBaseInfo), nullptr); | ||
|
||
// 实际测试,ObjectBasicInformation 只出现无效句柄错误 | ||
if (_Status < 0) | ||
{ | ||
break; | ||
} | ||
|
||
if (_FirstObjectBaseInfo.HandleCount == 1) | ||
{ | ||
// 引用计数为 1,这肯定不可能与另外一个句柄是同一个内核对象 | ||
break; | ||
} | ||
|
||
_Status = _pfnNtQueryObject(_hSecondObjectHandle, ObjectBasicInformation, &_SecondObjectBaseInfo, sizeof(_SecondObjectBaseInfo), nullptr); | ||
if (_Status < 0) | ||
{ | ||
break; | ||
} | ||
|
||
if (_SecondObjectBaseInfo.HandleCount != _FirstObjectBaseInfo.HandleCount) | ||
{ | ||
// 引用计数为 1,这肯定不可能与另外一个句柄是同一个内核对象 | ||
break; | ||
} | ||
|
||
_pfnCloseHandle(_hFirstTmp); | ||
_hFirstTmp = NULL; | ||
|
||
_Status = _pfnNtQueryObject(_hFirstObjectHandle, ObjectBasicInformation, &_FirstObjectBaseInfo, sizeof(_FirstObjectBaseInfo), nullptr); | ||
|
||
// 实际测试,ObjectBasicInformation 只出现无效句柄错误 | ||
if (_Status < 0) | ||
{ | ||
break; | ||
} | ||
|
||
if (_FirstObjectBaseInfo.HandleCount == 1) | ||
{ | ||
// 引用计数为 1,这肯定不可能与另外一个句柄是同一个内核对象 | ||
break; | ||
} | ||
|
||
_Status = _pfnNtQueryObject(_hSecondObjectHandle, ObjectBasicInformation, &_SecondObjectBaseInfo, sizeof(_SecondObjectBaseInfo), nullptr); | ||
if (_Status < 0) | ||
{ | ||
break; | ||
} | ||
|
||
if (_SecondObjectBaseInfo.HandleCount != _FirstObjectBaseInfo.HandleCount) | ||
{ | ||
// 引用计数为 1,这肯定不可能与另外一个句柄是同一个内核对象 | ||
break; | ||
} | ||
|
||
_bHandleIsSame = TRUE; | ||
break; | ||
} | ||
|
||
::ReleaseSRWLockExclusive(&g_CompareObjectHandles); | ||
|
||
if(_hFirstTmp) | ||
_pfnCloseHandle(_hFirstTmp); | ||
|
||
return _bHandleIsSame; | ||
} | ||
#endif | ||
} |
Oops, something went wrong.