Skip to content

Commit

Permalink
Fea #90,补充一些Chrome 125 Windows 7缺少的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Jun 15, 2024
1 parent 45d7751 commit a2ac7cc
Show file tree
Hide file tree
Showing 13 changed files with 2,111 additions and 801 deletions.
17 changes: 16 additions & 1 deletion ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

> 开头带`*`的函数并不建议使用,存在一些较大负面影响,仅用于编译通过处理,具体负面影响可参考注释内容。
## api-ms-win-core-handle-l1-1-0.dll
| 函数 | Fallback
| ---- | -----------
| CompareObjectHandles | 不存在时,调用NtQueryObject以及DuplicateHandle。

## api-ms-win-core-path-l1-1-0.dll
| 函数 | Fallback
| ---- | -----------
Expand Down Expand Up @@ -175,6 +180,11 @@
| ---- | -----------
| D3D11CreateDevice | 不存在时,返回 `E_NOINTERFACE`

## d3d12.dll
| 函数 | Fallback
| ---- | -----------
| D3D12CreateDevice | 不存在时,返回 `E_NOINTERFACE`

## DbgHelp.dll
| 函数 | Fallback
| ---- | -----------
Expand Down Expand Up @@ -518,7 +528,7 @@
| CreateRemoteThreadEx | 不存在时,调用CreateRemoteThread。
| WerRegisterRuntimeExceptionModule | 不存在时,返回S_OK。
| WerUnregisterRuntimeExceptionModule | 不存在时,返回S_OK。
| Wow64GetThreadContext | 不存在时,返回ERROR_INVALID_PARAMETER
| Wow64GetThreadContext | 不存在时,调用GetThreadContext或者返回ERROR_INVALID_PARAMETER

## mfplat.dll
| 函数 | Fallback
Expand Down Expand Up @@ -649,6 +659,11 @@
| DisplayConfigGetDeviceInfo | 不存在时,报告没有安装驱动。
| GetDisplayConfigBufferSizes | 不存在时,报告没有安装驱动。
| QueryDisplayConfig | 不存在时,报告没有安装驱动。
| RegisterPointerDeviceNotifications | 不存在时,假装成功。
| GetPointerDevices | 不存在时,假装没有触摸设备。
| GetPointerDevice | 不存在时,假装没有触摸设备。
| GetPointerPenInfo | 不存在时,假装没有触摸设备。
| GetPointerType | 不存在时,假装没有触摸设备。

## userenv.dll
| 函数 | Fallback
Expand Down
17 changes: 17 additions & 0 deletions src/Shared/km.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@

#define NtGetCurrentProcess() (HANDLE)-1

#define NtGetCurrentThread() (HANDLE)-2

// begin_access
#define DUPLICATE_CLOSE_SOURCE 0x00000001
#define DUPLICATE_SAME_ACCESS 0x00000002
Expand Down Expand Up @@ -1580,6 +1582,21 @@ NtQueryDirectoryFile (

};

typedef struct _OBJECT_BASIC_INFORMATION
{
ULONG Attributes;
ACCESS_MASK GrantedAccess;
ULONG HandleCount;
ULONG PointerCount;
ULONG PagedPoolCharge;
ULONG NonPagedPoolCharge;
ULONG Reserved[3];
ULONG NameInfoSize;
ULONG TypeInfoSize;
ULONG SecurityDescriptorSize;
LARGE_INTEGER CreationTime;
} OBJECT_BASIC_INFORMATION, * POBJECT_BASIC_INFORMATION;

typedef struct _OBJECT_NAME_INFORMATION
{
UNICODE_STRING Name;
Expand Down
10 changes: 5 additions & 5 deletions src/Thunks/DllMainCRTStartup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace YY::Thunks::internal
static volatile LONG uStatus = 0;
static TlsRawItem* volatile pRoot = nullptr;

static ULONG __fastcall GetTlsIndexBufferCount(TEB* _pTeb)
static SIZE_T __fastcall GetTlsIndexBufferCount(TEB* _pTeb)
{
auto _ppThreadLocalStoragePointer = (void**)_pTeb->ThreadLocalStoragePointer;
if (!_ppThreadLocalStoragePointer)
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace YY::Thunks::internal
if (!_pfnNtQuerySystemInformation)
return nullptr;

ULONG _cbBuffer = max(4096, _szBuffer.uBufferLength);
auto _cbBuffer = max(4096, _szBuffer.uBufferLength);
ULONG _cbRet = 0;
for (;;)
{
Expand All @@ -157,7 +157,7 @@ namespace YY::Thunks::internal
auto _pInfo = (SYSTEM_PROCESS_INFORMATION*)_szBuffer.GetBuffer(0);
for (;;)
{
if (_pInfo->ProcessId == (HANDLE)_uCurrentProcessId)
if (static_cast<DWORD>(reinterpret_cast<UINT_PTR>(_pInfo->ProcessId)) == _uCurrentProcessId)
return _pInfo;

if (_pInfo->NextEntryDelta == 0)
Expand Down Expand Up @@ -316,10 +316,10 @@ namespace YY::Thunks::internal
{
auto& _Thread = _pProcessInfo->Threads[i];

if (_uCurrentThreadId == (DWORD)_Thread.ClientId.UniqueThread)
if (_uCurrentThreadId == static_cast<DWORD>(reinterpret_cast<UINT_PTR>(_Thread.ClientId.UniqueThread)))
continue;

auto _hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE, (DWORD)_Thread.ClientId.UniqueThread);
auto _hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE, static_cast<DWORD>(reinterpret_cast<UINT_PTR>(_Thread.ClientId.UniqueThread)));
if (!_hThread)
{
continue;
Expand Down
52 changes: 52 additions & 0 deletions src/Thunks/YY_Thunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
_APPLY(dwmapi, "dwmapi" , 0 ) \
_APPLY(d3d9, "d3d9" , 0 ) \
_APPLY(d3d11, "d3d11" , 0 ) \
_APPLY(d3d12, "d3d12" , 0 ) \
_APPLY(dbghelp, "dbghelp" , USING_UNSAFE_LOAD ) \
_APPLY(dxgi, "dxgi" , 0 ) \
_APPLY(dwrite, "dwrite" , 0 ) \
Expand Down Expand Up @@ -38,6 +39,7 @@
_APPLY(wevtapi, "wevtapi" , 0 ) \
_APPLY(winhttp, "winhttp" , 0 ) \
_APPLY(zipfldr, "zipfldr" , LOAD_AS_DATA_FILE ) \
_APPLY(api_ms_win_core_handle_l1_1_0, "api-ms-win-core-handle-l1-1-0" , 0 ) \
_APPLY(api_ms_win_core_realtime_l1_1_1, "api-ms-win-core-realtime-l1-1-1" , 0 ) \
_APPLY(api_ms_win_core_winrt_l1_1_0, "api-ms-win-core-winrt-l1-1-0" , 0 ) \
_APPLY(api_ms_win_core_winrt_string_l1_1_0, "api-ms-win-core-winrt-string-l1-1-0", 0 ) \
Expand Down Expand Up @@ -252,6 +254,34 @@ namespace YY::Thunks::internal
return internal::MakeVersion(_pPeb->OSMajorVersion, _pPeb->OSMinorVersion);
}

const SYSTEM_INFO& GetNativeSystemInfo()
{
static SYSTEM_INFO s_SystemInfo;
// 0: 尚未初始化
// 1:正在初始化
// 2:已经初始化完成
static volatile LONG s_InitOnce;

auto _nResult = InterlockedCompareExchange(&s_InitOnce, 1, 0);
if (_nResult == 0)
{
// 成功锁定
::GetNativeSystemInfo(&s_SystemInfo);
InterlockedExchange(&s_InitOnce, 2);
}
else if (_nResult == 1)
{
// 其他线程正在初始化
do
{
YieldProcessor();

} while (s_InitOnce == 1);
}

return s_SystemInfo;
}

_Check_return_
_Ret_maybenull_
_Post_writable_byte_size_(_cbBytes)
Expand Down Expand Up @@ -783,6 +813,28 @@ namespace YY::Thunks::internal
return ERROR_SUCCESS;
}

static bool __fastcall IsEqualI(const UNICODE_STRING& _Left, const UNICODE_STRING& _Right)
{
if (_Left.Length != _Right.Length)
return false;

return __wcsnicmp_ascii(_Left.Buffer, _Right.Buffer, _Left.Length / 2) == 0;
}

static bool __fastcall IsEqual(const UNICODE_STRING& _Left, const UNICODE_STRING& _Right)
{
if (_Left.Length != _Right.Length)
return false;

return memcmp(_Left.Buffer, _Right.Buffer, _Left.Length) == 0;
}

template<size_t kLength>
static constexpr UNICODE_STRING __fastcall MakeStaticUnicodeString(const wchar_t (&_Right)[kLength])
{
UNICODE_STRING _Result = { (kLength - 1)* sizeof(_Right[0]), kLength * sizeof(_Right[0]), const_cast<PWSTR>(_Right) };
return _Result;
}
}

} //namespace YY
Expand Down
Loading

0 comments on commit a2ac7cc

Please sign in to comment.