Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

扩充毛利分支的RuntimeObject相关接口实现 #99

Merged
merged 13 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@
## api-ms-win-core-winrt-string-l1-1-0.dll
| 函数 | Fallback
| ---- | -----------
| WindowsCreateString | 不存在时,返回 E_NOTIMPL
| WindowsCreateStringReference | 不存在时,返回 E_NOTIMPL
| WindowsDeleteString | 不存在时,返回 E_NOTIMPL
| WindowsDuplicateString | 不存在时,返回 E_NOTIMPL
| WindowsGetStringLen | 不存在时,返回 E_NOTIMPL
| WindowsGetStringRawBuffer | 不存在时,返回 E_NOTIMPL
| WindowsIsStringEmpty | 不存在时,返回 E_NOTIMPL
| WindowsStringHasEmbeddedNull | 不存在时,返回 E_NOTIMPL
| WindowsCompareStringOrdinal | 不存在时,返回 E_NOTIMPL
| WindowsCreateString | 不存在时,内部实现
| WindowsCreateStringReference | 不存在时,内部实现
| WindowsDeleteString | 不存在时,内部实现
| WindowsDuplicateString | 不存在时,内部实现
| WindowsGetStringLen | 不存在时,内部实现
| WindowsGetStringRawBuffer | 不存在时,内部实现
| WindowsIsStringEmpty | 不存在时,内部实现
| WindowsStringHasEmbeddedNull | 不存在时,内部实现
| WindowsCompareStringOrdinal | 不存在时,内部实现

## advapi32.dll
| 函数 | Fallback
Expand Down
62 changes: 62 additions & 0 deletions src/Shared/HStringPrivate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* PROJECT: YY-Thunks
* FILE: hstring_private.h
* PURPOSE: Extra definitions for the Windows Runtime String (HSTRING)
*
* LICENSE: The MIT License
*
* MAINTAINER: MouriNaruto ([email protected])
*/
#pragma once
#include <hstring.h>

#include "SharedDefs.h"

/*
* @remark The following definitions are dumped from the debug symbol from the
* Windows 10 Build 14347's combase.dll.
*/
namespace YY::Thunks::internal
{
namespace
{
/*
* @brief The flags of the Windows Runtime String.
* @remark Originally it's a C/C++ enum in the debug symbols.
*/
enum class RuntimeStringFlags : UINT32
{
WRHF_NONE = 0x00000000,
WRHF_STRING_REFERENCE = 0x00000001,
WRHF_VALID_UNICODE_FORMAT_INFO = 0x00000002,
WRHF_WELL_FORMED_UNICODE = 0x00000004,
WRHF_HAS_EMBEDDED_NULLS = 0x00000008,
WRHF_EMBEDDED_NULLS_COMPUTED = 0x00000010,
WRHF_RESERVED_FOR_PREALLOCATED_STRING_BUFFER = 0x80000000,
};
YY_APPLY_ENUM_CALSS_BIT_OPERATOR(RuntimeStringFlags)

/*
* @brief The internal structure of Windows Runtime String header.
*/
typedef struct _HSTRING_HEADER_INTERNAL
{
RuntimeStringFlags Flags;
UINT32 Length;
UINT32 Padding1;
UINT32 Padding2;
PCWSTR StringRef;
} HSTRING_HEADER_INTERNAL, * PHSTRING_HEADER_INTERNAL;
static_assert(sizeof(HSTRING_HEADER) == sizeof(HSTRING_HEADER_INTERNAL));

/*
* @brief The internal structure of heap allocated Windows Runtime String.
*/
typedef struct _STRING_OPAQUE
{
HSTRING_HEADER_INTERNAL Header;
volatile LONG RefCount;
WCHAR String[ANYSIZE_ARRAY];
} STRING_OPAQUE, * PSTRING_OPAQUE;
}
}
35 changes: 35 additions & 0 deletions src/Shared/SharedDefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <type_traits>

#define YY_APPLY_ENUM_CALSS_BIT_OPERATOR(_ENUM) \
inline constexpr _ENUM& operator|=(_ENUM& _eLeft, _ENUM _eRight) \
{ \
using _Type = std::underlying_type<_ENUM>::type; \
(_Type&)_eLeft |= (_Type)_eRight; \
return _eLeft; \
} \
\
inline constexpr _ENUM operator|(_ENUM _eLeft, _ENUM _eRight) \
{ \
using _Type = std::underlying_type<_ENUM>::type; \
auto _Result = (_Type)_eLeft | (_Type)_eRight; \
return _ENUM(_Result); \
} \
\
inline constexpr _ENUM operator&(_ENUM _eLeft, _ENUM _eRight) \
{ \
using _Type = std::underlying_type<_ENUM>::type; \
return _ENUM((_Type)_eLeft & (_Type)_eRight); \
} \
\
inline constexpr _ENUM operator~(_ENUM _eLeft) \
{ \
using _Type = std::underlying_type<_ENUM>::type; \
return _ENUM(~(_Type)_eLeft); \
} \
\
inline constexpr bool HasFlags(_ENUM _eLeft, _ENUM _eRight) \
{ \
using _Type = std::underlying_type<_ENUM>::type; \
return (_Type)_eLeft & (_Type)_eRight; \
}
4 changes: 2 additions & 2 deletions src/Thunks/YY_Thunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,15 +965,15 @@ namespace YY::Thunks::internal
static constexpr UNICODE_STRING __fastcall MakeNtString(_In_z_ const wchar_t* _szString)
{
const auto _cbString = StringLength(_szString) * sizeof(_szString[0]);
UNICODE_STRING _Result = { (USHORT)max(UINT16_MAX, _cbString), (USHORT)max(UINT16_MAX, _cbString + sizeof(_szString[0])), const_cast<PWSTR>(_szString) };
UNICODE_STRING _Result = { (USHORT)min(UINT16_MAX, _cbString), (USHORT)min(UINT16_MAX, _cbString + sizeof(_szString[0])), const_cast<PWSTR>(_szString) };
return _Result;
}

static constexpr ANSI_STRING __fastcall MakeNtString(_In_z_ const char* _szString)
{
const auto _cbString = StringLength(_szString) * sizeof(_szString[0]);

ANSI_STRING _Result = { (USHORT)max(UINT16_MAX, _cbString), (USHORT)max(UINT16_MAX, _cbString + sizeof(_szString[0])), const_cast<PSTR>(_szString)};
ANSI_STRING _Result = { (USHORT)min(UINT16_MAX, _cbString), (USHORT)min(UINT16_MAX, _cbString + sizeof(_szString[0])), const_cast<PSTR>(_szString)};
return _Result;
}

Expand Down
Loading
Loading