Skip to content

Commit

Permalink
扩充毛利分支的RuntimeObject相关接口实现 (#99)
Browse files Browse the repository at this point in the history
Fea #94, 为Windows Runtime String (HSTRING)提供内部实现
- 补充 WindowsCreateString
- 补充 WindowsCreateStringReference
- 补充 WindowsDeleteString
- 补充 WindowsDuplicateString
- 补充 WindowsGetStringLen
- 补充 WindowsGetStringRawBuffer
- 补充 WindowsIsStringEmpty
- 补充 WindowsStringHasEmbeddedNull
- 补充 WindowsCompareStringOrdinal
  • Loading branch information
mingkuang-Chuyu authored Jun 24, 2024
1 parent bee5f7c commit 8cca78f
Show file tree
Hide file tree
Showing 8 changed files with 810 additions and 181 deletions.
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

0 comments on commit 8cca78f

Please sign in to comment.