From b77914e73c2fe0abef17b29253191820d62a0c90 Mon Sep 17 00:00:00 2001 From: Ratin Gao Date: Fri, 9 Aug 2024 18:13:06 +0800 Subject: [PATCH] [VERSION] 1.1.0-beta --- .github/workflows/msbuild.yml | 36 + .gitmodules | 3 + LICENSE | 21 + README.md | 92 + README.zh-CN.md | 92 + Source/.editorconfig | 77 + Source/.gitignore | 8 + Source/Directory.Build.AfterCppDefault.props | 10 + Source/Directory.Build.props | 73 + Source/Include/KNSoft/NDK/3rdParty/phnt | 1 + Source/Include/KNSoft/NDK/Extension/CPUID.h | 301 +++ .../Include/KNSoft/NDK/Extension/Extension.h | 73 + .../KNSoft/NDK/Extension/MSToolChain.h | 70 + Source/Include/KNSoft/NDK/Extension/SMBIOS.h | 1489 +++++++++++++++ Source/Include/KNSoft/NDK/Extension/StrSafe.h | 138 ++ Source/Include/KNSoft/NDK/NDK.h | 36 + Source/Include/KNSoft/NDK/NT/Addendum.h | 76 + Source/Include/KNSoft/NDK/NT/Dbg.h | 17 + Source/Include/KNSoft/NDK/NT/Ex.h | 15 + .../Include/KNSoft/NDK/NT/Extension/Runtime.h | 105 ++ .../KNSoft/NDK/NT/Extension/Security.h | 39 + Source/Include/KNSoft/NDK/NT/Io.h | 1629 +++++++++++++++++ Source/Include/KNSoft/NDK/NT/Ke.h | 25 + Source/Include/KNSoft/NDK/NT/Macro.h | 161 ++ Source/Include/KNSoft/NDK/NT/MinDef.h | 17 + Source/Include/KNSoft/NDK/NT/Mm.h | 47 + Source/Include/KNSoft/NDK/NT/NT.h | 100 + Source/Include/KNSoft/NDK/NT/Ob.h | 9 + .../KNSoft/NDK/NT/Private/Ntdef_Around.h | 109 ++ .../KNSoft/NDK/NT/Private/TargetArch.h | 46 + .../KNSoft/NDK/NT/Private/Winnt_Around.h | 16 + Source/Include/KNSoft/NDK/NT/Rtl/Assertion.h | 47 + Source/Include/KNSoft/NDK/NT/Rtl/Memory.h | 40 + Source/Include/KNSoft/NDK/NT/Rtl/Rtl.h | 4 + Source/Include/KNSoft/NDK/NT/Se.h | 165 ++ Source/Include/KNSoft/NDK/NT/Wow/Io.h | 51 + Source/Include/KNSoft/NDK/NT/Wow/Ldr.h | 110 ++ Source/Include/KNSoft/NDK/NT/Wow/Rtl.h | 109 ++ Source/Include/KNSoft/NDK/NT/Wow/Sxs.h | 112 ++ Source/Include/KNSoft/NDK/NT/Wow/Wow.h | 65 + Source/Include/KNSoft/NDK/UnitTest/UnitTest.h | 134 ++ .../Include/KNSoft/NDK/UnitTest/UnitTest.inl | 344 ++++ .../Include/KNSoft/NDK/Win32/API/Kernel32.h | 26 + .../Include/KNSoft/NDK/Win32/API/Ntdll.Hash.h | 101 + Source/Include/KNSoft/NDK/Win32/API/Ntdll.h | 17 + Source/Include/KNSoft/NDK/Win32/API/User32.h | 39 + .../Include/KNSoft/NDK/Win32/Def/CommCtrl.h | 21 + Source/Include/KNSoft/NDK/Win32/Def/WinUser.h | 5 + Source/KNSoft.NDK.nuspec | 26 + Source/KNSoft.NDK.sln | 54 + Source/KNSoft.NDK.targets | 12 + Source/KNSoft.NDK/KNSoft.NDK.vcxproj | 209 +++ Source/KNSoft.NDK/KNSoft.NDK.vcxproj.filters | 259 +++ .../WinAPI/KNSoft.NDK.Ntdll.Hash.xml | 13 + .../KNSoft.NDK/WinAPI/KNSoft.NDK.WinAPI.xml | 61 + Source/KNSoft.NDK/packages.config | 4 + Source/Test/Extension/MSToolChain.c | 28 + Source/Test/Main.c | 30 + Source/Test/NT/PebLdr.c | 35 + Source/Test/NT/PebTebKUSD.c | 90 + Source/Test/StrSafe.c | 36 + Source/Test/Test.h | 8 + Source/Test/Test.vcxproj | 198 ++ Source/Test/Test.vcxproj.filters | 28 + Source/Test/UnitTestFramework.c | 39 + 65 files changed, 7451 insertions(+) create mode 100644 .github/workflows/msbuild.yml create mode 100644 .gitmodules create mode 100644 LICENSE create mode 100644 README.md create mode 100644 README.zh-CN.md create mode 100644 Source/.editorconfig create mode 100644 Source/.gitignore create mode 100644 Source/Directory.Build.AfterCppDefault.props create mode 100644 Source/Directory.Build.props create mode 160000 Source/Include/KNSoft/NDK/3rdParty/phnt create mode 100644 Source/Include/KNSoft/NDK/Extension/CPUID.h create mode 100644 Source/Include/KNSoft/NDK/Extension/Extension.h create mode 100644 Source/Include/KNSoft/NDK/Extension/MSToolChain.h create mode 100644 Source/Include/KNSoft/NDK/Extension/SMBIOS.h create mode 100644 Source/Include/KNSoft/NDK/Extension/StrSafe.h create mode 100644 Source/Include/KNSoft/NDK/NDK.h create mode 100644 Source/Include/KNSoft/NDK/NT/Addendum.h create mode 100644 Source/Include/KNSoft/NDK/NT/Dbg.h create mode 100644 Source/Include/KNSoft/NDK/NT/Ex.h create mode 100644 Source/Include/KNSoft/NDK/NT/Extension/Runtime.h create mode 100644 Source/Include/KNSoft/NDK/NT/Extension/Security.h create mode 100644 Source/Include/KNSoft/NDK/NT/Io.h create mode 100644 Source/Include/KNSoft/NDK/NT/Ke.h create mode 100644 Source/Include/KNSoft/NDK/NT/Macro.h create mode 100644 Source/Include/KNSoft/NDK/NT/MinDef.h create mode 100644 Source/Include/KNSoft/NDK/NT/Mm.h create mode 100644 Source/Include/KNSoft/NDK/NT/NT.h create mode 100644 Source/Include/KNSoft/NDK/NT/Ob.h create mode 100644 Source/Include/KNSoft/NDK/NT/Private/Ntdef_Around.h create mode 100644 Source/Include/KNSoft/NDK/NT/Private/TargetArch.h create mode 100644 Source/Include/KNSoft/NDK/NT/Private/Winnt_Around.h create mode 100644 Source/Include/KNSoft/NDK/NT/Rtl/Assertion.h create mode 100644 Source/Include/KNSoft/NDK/NT/Rtl/Memory.h create mode 100644 Source/Include/KNSoft/NDK/NT/Rtl/Rtl.h create mode 100644 Source/Include/KNSoft/NDK/NT/Se.h create mode 100644 Source/Include/KNSoft/NDK/NT/Wow/Io.h create mode 100644 Source/Include/KNSoft/NDK/NT/Wow/Ldr.h create mode 100644 Source/Include/KNSoft/NDK/NT/Wow/Rtl.h create mode 100644 Source/Include/KNSoft/NDK/NT/Wow/Sxs.h create mode 100644 Source/Include/KNSoft/NDK/NT/Wow/Wow.h create mode 100644 Source/Include/KNSoft/NDK/UnitTest/UnitTest.h create mode 100644 Source/Include/KNSoft/NDK/UnitTest/UnitTest.inl create mode 100644 Source/Include/KNSoft/NDK/Win32/API/Kernel32.h create mode 100644 Source/Include/KNSoft/NDK/Win32/API/Ntdll.Hash.h create mode 100644 Source/Include/KNSoft/NDK/Win32/API/Ntdll.h create mode 100644 Source/Include/KNSoft/NDK/Win32/API/User32.h create mode 100644 Source/Include/KNSoft/NDK/Win32/Def/CommCtrl.h create mode 100644 Source/Include/KNSoft/NDK/Win32/Def/WinUser.h create mode 100644 Source/KNSoft.NDK.nuspec create mode 100644 Source/KNSoft.NDK.sln create mode 100644 Source/KNSoft.NDK.targets create mode 100644 Source/KNSoft.NDK/KNSoft.NDK.vcxproj create mode 100644 Source/KNSoft.NDK/KNSoft.NDK.vcxproj.filters create mode 100644 Source/KNSoft.NDK/WinAPI/KNSoft.NDK.Ntdll.Hash.xml create mode 100644 Source/KNSoft.NDK/WinAPI/KNSoft.NDK.WinAPI.xml create mode 100644 Source/KNSoft.NDK/packages.config create mode 100644 Source/Test/Extension/MSToolChain.c create mode 100644 Source/Test/Main.c create mode 100644 Source/Test/NT/PebLdr.c create mode 100644 Source/Test/NT/PebTebKUSD.c create mode 100644 Source/Test/StrSafe.c create mode 100644 Source/Test/Test.h create mode 100644 Source/Test/Test.vcxproj create mode 100644 Source/Test/Test.vcxproj.filters create mode 100644 Source/Test/UnitTestFramework.c diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml new file mode 100644 index 0000000..faecc1d --- /dev/null +++ b/.github/workflows/msbuild.yml @@ -0,0 +1,36 @@ +name: MSBuild + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + SOLUTION_FILE_PATH: .\Source\KNSoft.NDK.sln + +permissions: + contents: read + +jobs: + build: + strategy: + matrix: + platform: [x64, x86, ARM64] + config: [Debug, Release] + fail-fast: false + runs-on: windows-latest + steps: + - name: Source checkout + uses: actions/checkout@main + with: + submodules: recursive + - name: Prepare MSBuild + uses: microsoft/setup-msbuild@main + - name: Build + working-directory: ${{env.GITHUB_WORKSPACE}} + run: msbuild ${{env.SOLUTION_FILE_PATH}} /restore /m /p:Configuration=${{matrix.config}} /p:Platform=${{matrix.platform}} /p:RestorePackagesConfig=true + - name: Run Unit Test (x64, x86) + if: ${{ matrix.platform == 'x64' || matrix.platform == 'x86' }} + working-directory: ${{env.GITHUB_WORKSPACE}} + run: .\Source\OutDir\${{matrix.platform}}\${{matrix.config}}\Test.exe -Run diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9e9505a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Source/Include/KNSoft/NDK/3rdParty/phnt"] + path = Source/Include/KNSoft/NDK/3rdParty/phnt + url = https://github.com/RatinCN/phnt.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ee0152f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ + MIT License + + Copyright (c) KNSoft.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE diff --git a/README.md b/README.md new file mode 100644 index 0000000..c591691 --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +| **English (en-US)** | [简体中文 (zh-CN)](https://github.com/KNSoft/KNSoft.NDK/blob/main/README.zh-CN.md) | +| --- | --- | + +
+ +# KNSoft.NDK + +[![NuGet Downloads](https://img.shields.io/nuget/dt/KNSoft.NDK)](https://www.nuget.org/packages/KNSoft.NDK) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/KNSoft/KNSoft.NDK/msbuild.yml)](https://github.com/KNSoft/KNSoft.NDK/actions/workflows/msbuild.yml) ![PR Welcome](https://img.shields.io/badge/PR-welcome-0688CB.svg) [![GitHub License](https://img.shields.io/github/license/KNSoft/KNSoft.NDK)](https://github.com/KNSoft/KNSoft.NDK/blob/main/LICENSE) + +[KNSoft.NDK](https://github.com/KNSoft/KNSoft.NDK) provides native C/C++ definitions and import libraries for Windows NT development. + +## Feature + +- Windows NT + - Undocumented API declarations and type definitions, e.g. `Nt/Zw*`, `Ldr*`, `PEB`, `TEB`, `LDR_*`, ... + - Import library for Windows DLL exports, e.g. `KERNEL32.dll!CreateProcessInternalW`, `ntdll.dll!LdrRegisterDllNotification`, ... + - Addendum to Windows SDK + - Extension macros and definitions, e.g. `NtCurrentPeb()`, `PEB(64/32)`, `TEB(64/32)`, ... +- Specifications + - SMBIOS + - CPUID + - MSVC +- Kits + - Unit Test Framework + - StrSafe.h (different from `strsafe.h` in Windows SDK) + +## Usage + +[![NuGet Downloads](https://img.shields.io/nuget/dt/KNSoft.NDK)](https://www.nuget.org/packages/KNSoft.NDK) + +### TL;DR + +Include [NDK.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/NDK.h) instead of (or **BEFORE**) `Windows.h` will do. +```C +#include +``` + +NuGet package [KNSoft.NDK](https://www.nuget.org/packages/KNSoft.NDK) includes all the headers and import libraries. + +### Details + +The following features **are not enabled by default**, reference corresponding headers and libraries on demand: + +- Specifications + - CPUID: [CPUID.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/Extension/CPUID.h) + - SMBIOS: [SMBIOS.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/Extension/SMBIOS.h) +- Ntdll Hash API (`(A_SHA/MD4/MD5)(Init/Update/Final)`) + - [Ntdll.Hash.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/WinDef/API/Ntdll.Hash.h) + - KNSoft.NDK.Ntdll.Hash.lib (Generated from [KNSoft.NDK.Ntdll.Hash.xml](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.Ntdll.Hash.xml)) +- Windows API import library addendum + - KNSoft.NDK.WinAPI.lib (Generated from [KNSoft.NDK.WinAPI.xml](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.WinAPI.xml)) +- Unit Test Framework + - [UnitTest.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/UnitTest/UnitTest.h) + - [UnitTest.inl](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/UnitTest/UnitTest.inl) +- Safe string functions (different from `strsafe.h` in Windows SDK) + - [StrSafe.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/Extension/StrSafe.h) + +The following features **are enabled by default**, can be excluded by defining corresponding macro: + +| Macro | Exclude feature | +| ---- | ---- | +| _KNSOFT_NDK_NO_EXTENSION | Addendum or extension macros and definitions | +| _KNSOFT_NDK_NO_EXTENSION_MSTOOLCHAIN | Microsoft Tool Chain specific extension | + +## Compatibility + +![PR Welcome](https://img.shields.io/badge/PR-welcome-0688CB.svg) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/KNSoft/KNSoft.NDK/msbuild.yml)](https://github.com/KNSoft/KNSoft.NDK/actions/workflows/msbuild.yml) + +[KNSoft.NDK](https://github.com/KNSoft/KNSoft.NDK) always follow up the latest Windows NT and specifications, targets to x86, x64 and ARM64 platforms. + +**Only support the latest MSVC generation tools and SDKs.** + +> [!CAUTION] +> In beta stage, should be used with caution. + +## License + +[![GitHub License](https://img.shields.io/github/license/KNSoft/KNSoft.NDK)](https://github.com/KNSoft/KNSoft.NDK/blob/main/LICENSE) + +[KNSoft.NDK](https://github.com/KNSoft/KNSoft.NDK) is licensed under the [MIT](https://github.com/KNSoft/KNSoft.NDK/blob/main/LICENSE) license. + +The content from the following public sources were lawfully used: +- Microsoft WDK/DDK/SDK +- Microsoft Public Symbolic Data +- Microsoft Learning +- Microsoft Windows Protocols +- Windows Internals + +And public projects: +- [winsiderss/phnt](https://github.com/winsiderss/phnt) - [MIT](https://github.com/winsiderss/phnt/blob/master/LICENSE) ([RatinCN/phnt](https://github.com/RatinCN/phnt) fork is used) + +[KNSoft.NDK](https://github.com/KNSoft/KNSoft.NDK) also uses [KNSoft/Precomp4C](https://github.com/KNSoft/Precomp4C) to generate DLL import libraries. diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 0000000..d84123c --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,92 @@ +| [English (en-US)](https://github.com/KNSoft/KNSoft.NDK/blob/main/README.md) | **简体中文 (zh-CN)** | +| --- | --- | + +
+ +# KNSoft.NDK + +[![NuGet Downloads](https://img.shields.io/nuget/dt/KNSoft.NDK)](https://www.nuget.org/packages/KNSoft.NDK) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/KNSoft/KNSoft.NDK/msbuild.yml)](https://github.com/KNSoft/KNSoft.NDK/actions/workflows/msbuild.yml) ![PR Welcome](https://img.shields.io/badge/PR-welcome-0688CB.svg) [![GitHub License](https://img.shields.io/github/license/KNSoft/KNSoft.NDK)](https://github.com/KNSoft/KNSoft.NDK/blob/main/LICENSE) + +[KNSoft.NDK](https://github.com/KNSoft/KNSoft.NDK)提供了原始C/C++定义和引入库供Windows NT开发。 + +## 功能 + +- Windows NT + - 未公开的API声明和类型定义,例如:`Nt/Zw*`、`Ldr*`、`PEB`、`TEB`、`LDR_*`…… + - Windows DLL导出项引入库,例如:`KERNEL32.dll!CreateProcessInternalW`、`ntdll.dll!LdrRegisterDllNotification`…… + - Windows SDK的补充 + - 扩展的宏和定义,例如:`NtCurrentPeb()`、`PEB(64/32)`、`TEB(64/32)`…… +- 规范 + - SMBIOS + - CPUID + - MSVC +- 工具 + - 单元测试框架 + - StrSafe.h(与Windows SDK里的`strsafe.h`不同) + +## 用法 + +[![NuGet Downloads](https://img.shields.io/nuget/dt/KNSoft.NDK)](https://www.nuget.org/packages/KNSoft.NDK) + +### 提要 + +包含[NDK.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/NDK.h)代替(或先于)`Windows.h`即可。 +```C +#include +``` + +NuGet包[KNSoft.NDK](https://www.nuget.org/packages/KNSoft.NDK)包含所有头文件和引入库。 + +### 详细说明 + +下列功能**默认没有启用**,按需引用对应的头文件和库: + +- 规范 + - CPUID: [CPUID.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/Extension/CPUID.h) + - SMBIOS: [SMBIOS.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/Extension/SMBIOS.h) +- Ntdll Hash API (`(A_SHA/MD4/MD5)(Init/Update/Final)`) + - [Ntdll.Hash.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/WinDef/API/Ntdll.Hash.h) + - KNSoft.NDK.Ntdll.Hash.lib (由[KNSoft.NDK.Ntdll.Hash.xml](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.Ntdll.Hash.xml)生成) +- Windows API 引入库补充 + - KNSoft.NDK.WinAPI.lib (由[KNSoft.NDK.WinAPI.xml](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.WinAPI.xml)生成) +- 单元测试框架 + - [UnitTest.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/UnitTest/UnitTest.h) + - [UnitTest.inl](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/UnitTest/UnitTest.inl) +- 安全字符串函数(与Windows SDK里的`strsafe.h`不同) + - [StrSafe.h](https://github.com/KNSoft/KNSoft.NDK/blob/main/Source/Include/KNSoft/NDK/Extension/StrSafe.h) + +下列功能**默认启用**,定义对应宏可进行排除: + +| 宏 | 排除功能 | +| ---- | ---- | +| _KNSOFT_NDK_NO_EXTENSION | 补充或扩展的宏和定义 | +| _KNSOFT_NDK_NO_EXTENSION_MSTOOLCHAIN | Microsoft工具链专有扩展 | + +## 兼容性 + +![PR Welcome](https://img.shields.io/badge/PR-welcome-0688CB.svg) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/KNSoft/KNSoft.NDK/msbuild.yml)](https://github.com/KNSoft/KNSoft.NDK/actions/workflows/msbuild.yml) + +[KNSoft.NDK](https://github.com/KNSoft/KNSoft.NDK)始终跟进最新的Windows NT和规范,目标x86、x64和ARM64平台。 + +**仅支持最新的MSVC生成工具和SDK。** + +> [!CAUTION] +> 处于beta阶段,应小心使用。 + +## 协议 + +[![GitHub License](https://img.shields.io/github/license/KNSoft/KNSoft.NDK)](https://github.com/KNSoft/KNSoft.NDK/blob/main/LICENSE) + +[KNSoft.NDK](https://github.com/KNSoft/KNSoft.NDK)根据[MIT](https://github.com/KNSoft/KNSoft.NDK/blob/main/LICENSE)协议进行许可。 + +合法使用了来自下列公开源的内容: +- Microsoft WDK/DDK/SDK +- Microsoft Public Symbolic Data +- Microsoft Learning +- Microsoft Windows Protocols +- Windows Internals + +和公开项目: +- [winsiderss/phnt](https://github.com/winsiderss/phnt) - [MIT](https://github.com/winsiderss/phnt/blob/master/LICENSE) ([RatinCN/phnt](https://github.com/RatinCN/phnt) fork is used) + +[KNSoft.NDK](https://github.com/KNSoft/KNSoft.NDK)也使用了[KNSoft/Precomp4C](https://github.com/KNSoft/Precomp4C)来生成DLL引入库。 diff --git a/Source/.editorconfig b/Source/.editorconfig new file mode 100644 index 0000000..aff578a --- /dev/null +++ b/Source/.editorconfig @@ -0,0 +1,77 @@ +# Visual Studio generated .editorconfig file with C++ settings. +root = true + +[*.{c,c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}] + +charset = utf-8-bom +indent_style = space +indent_size = 4 +end_of_line = crlf +insert_final_newline = true +max_line_length = 120 + +# Visual C++ Code Style settings + +cpp_generate_documentation_comments = xml + +# Visual C++ Formatting settings + +cpp_indent_braces = false +cpp_indent_multi_line_relative_to = innermost_parenthesis +cpp_indent_within_parentheses = align_to_parenthesis +cpp_indent_preserve_within_parentheses = true +cpp_indent_case_contents = true +cpp_indent_case_labels = true +cpp_indent_case_contents_when_block = false +cpp_indent_lambda_braces_when_parameter = false +cpp_indent_goto_labels = leftmost_column +cpp_indent_preprocessor = leftmost_column +cpp_indent_access_specifiers = false +cpp_indent_namespace_contents = true +cpp_indent_preserve_comments = true +cpp_new_line_before_open_brace_namespace = new_line +cpp_new_line_before_open_brace_type = new_line +cpp_new_line_before_open_brace_function = new_line +cpp_new_line_before_open_brace_block = new_line +cpp_new_line_before_open_brace_lambda = new_line +cpp_new_line_scope_braces_on_separate_lines = true +cpp_new_line_close_brace_same_line_empty_type = true +cpp_new_line_close_brace_same_line_empty_function = true +cpp_new_line_before_catch = false +cpp_new_line_before_else = false +cpp_new_line_before_while_in_do_while = false +cpp_space_before_function_open_parenthesis = remove +cpp_space_within_parameter_list_parentheses = false +cpp_space_between_empty_parameter_list_parentheses = false +cpp_space_after_keywords_in_control_flow_statements = true +cpp_space_within_control_flow_statement_parentheses = false +cpp_space_before_lambda_open_parenthesis = false +cpp_space_within_cast_parentheses = false +cpp_space_after_cast_close_parenthesis = false +cpp_space_within_expression_parentheses = false +cpp_space_before_block_open_brace = true +cpp_space_between_empty_braces = false +cpp_space_before_initializer_list_open_brace = false +cpp_space_within_initializer_list_braces = true +cpp_space_preserve_in_initializer_list = true +cpp_space_before_open_square_bracket = false +cpp_space_within_square_brackets = false +cpp_space_before_empty_square_brackets = false +cpp_space_between_empty_square_brackets = false +cpp_space_group_square_brackets = true +cpp_space_within_lambda_brackets = false +cpp_space_between_empty_lambda_brackets = false +cpp_space_before_comma = false +cpp_space_after_comma = true +cpp_space_remove_around_member_operators = true +cpp_space_before_inheritance_colon = true +cpp_space_before_constructor_colon = true +cpp_space_remove_before_semicolon = true +cpp_space_after_semicolon = true +cpp_space_remove_around_unary_operator = true +cpp_space_around_binary_operator = insert +cpp_space_around_assignment_operator = insert +cpp_space_pointer_reference_alignment = ignore +cpp_space_around_ternary_operator = insert +cpp_use_unreal_engine_macro_formatting = true +cpp_wrap_preserve_blocks = all_one_line_scopes \ No newline at end of file diff --git a/Source/.gitignore b/Source/.gitignore new file mode 100644 index 0000000..bff2e8e --- /dev/null +++ b/Source/.gitignore @@ -0,0 +1,8 @@ +.vs +*.user + +/packages +/OutDir +IntDir + +/*.nupkg \ No newline at end of file diff --git a/Source/Directory.Build.AfterCppDefault.props b/Source/Directory.Build.AfterCppDefault.props new file mode 100644 index 0000000..d56c04b --- /dev/null +++ b/Source/Directory.Build.AfterCppDefault.props @@ -0,0 +1,10 @@ + + + $(DefaultPlatformToolset) + $(SolutionDir)OutDir\$(PlatformTarget)\$(Configuration)\ + IntDir\$(PlatformTarget)\$(Configuration)\ + + + Unicode + + \ No newline at end of file diff --git a/Source/Directory.Build.props b/Source/Directory.Build.props new file mode 100644 index 0000000..d0a5652 --- /dev/null +++ b/Source/Directory.Build.props @@ -0,0 +1,73 @@ + + + + $(MsbuildThisFileDirectory)\Directory.Build.AfterCppDefault.props + + + + + Level3 + stdcpplatest + stdc17 + pch.h + + + + + + + MSB_CONFIGURATIONTYPE_EXE;%(PreprocessorDefinitions) + + + + + MSB_CONFIGURATIONTYPE_DLL;%(PreprocessorDefinitions) + + + + + MSB_CONFIGURATIONTYPE_LIB;%(PreprocessorDefinitions) + + + + + MSB_CONFIGURATIONTYPE_UTILITY;%(PreprocessorDefinitions) + + + + + MSB_CONFIGURATION_NAME="$(ConfigurationName)";%(PreprocessorDefinitions) + MSB_MSBUILD_VERSION="$(MSBuildVersion)";%(PreprocessorDefinitions) + MSB_VCTOOLS_VERSION="$(VCToolsVersion)";%(PreprocessorDefinitions) + MSB_PLATFORM_TOOLSET="$(PlatformToolset)";%(PreprocessorDefinitions) + MSB_PLATFORM_TOOLSET_VERSION="$(PlatformToolsetVersion)";%(PreprocessorDefinitions) + MSB_PLATFORM_TARGET_VERSION="$(PlatformTarget)";%(PreprocessorDefinitions) + MSB_TARGET_PLATFORM_VERSION="$(TargetPlatformVersion)";%(PreprocessorDefinitions) + MSB_TARGET_PLATFORM_DISPLAY_NAME="$(TargetPlatformDisplayName)";%(PreprocessorDefinitions) + + + + + + + MultiThreaded + + + + + MultiThreadedDebug + + + + + + $(MSBuildProjectDirectory)\$(ProjectName).Build.props + + + + + + $([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../')) + + + \ No newline at end of file diff --git a/Source/Include/KNSoft/NDK/3rdParty/phnt b/Source/Include/KNSoft/NDK/3rdParty/phnt new file mode 160000 index 0000000..7748fbe --- /dev/null +++ b/Source/Include/KNSoft/NDK/3rdParty/phnt @@ -0,0 +1 @@ +Subproject commit 7748fbe951adf6edd470362dfcc3e84c78427ca5 diff --git a/Source/Include/KNSoft/NDK/Extension/CPUID.h b/Source/Include/KNSoft/NDK/Extension/CPUID.h new file mode 100644 index 0000000..d46fd36 --- /dev/null +++ b/Source/Include/KNSoft/NDK/Extension/CPUID.h @@ -0,0 +1,301 @@ +#pragma once + +#define CPUID_INTEL_VERSION_INFO_MASK 0xFFF3FF0 // Extended Family ID | Extended Model ID | Processor Type | Family ID | Model +#define CPUID_MAKE_INTEL_VERSION_INFO(ExtendedFamilyId, ExtendedModelId, ProcessorType, FamilyId, Model, SteppingId)\ + (((ExtendedFamilyId & 0b11111111) << 20) |\ + ((ExtendedModelId & 0b1111) << 16) |\ + ((ProcessorType & 0b11) << 12) |\ + ((FamilyId & 0b1111) << 8) |\ + ((Model & 0b1111) << 4) |\ + (SteppingId & 0b1111)) + +typedef union _CPUID_INFO +{ + int Registers[4]; + struct + { + int Eax; + int Ebx; + int Ecx; + int Edx; + }; + + /* F_Leaf_SubLeaf, aka F_EAX_ECX */ + + /* 00-03: Basic CPUID Information */ + struct + { + /* Eax */ + unsigned int MaxInputValue; + /* Ebx, Ecx, Edx */ + unsigned int VendorIdString[3]; + } F00_00; + + struct + { +/* + * Eax: Intel CPU version information + * + * 31 28 27 20 19 16 15 14 13 12 11 8 7 4 3 0 + * +-----+--------------------+-------------------+-----+----------------+-----------+-------+-------------+ + * | | Extended Family ID | Extended Model ID | | Processor Type | Family ID | Model | Stepping ID | + * +-----+--------------------+-------------------+-----+----------------+-----------+-------+-------------+ + * + */ + struct + { + unsigned int SteppingId : 4; + unsigned int Model : 4; + unsigned int FamilyId : 4; + unsigned int ProcessorType : 2; + unsigned int ReservedBits0 : 2; + unsigned int ExtendedModelId : 4; + unsigned int ExtendedFamilyId : 8; + unsigned int ReservedBits1 : 4; + } VersionInfo; + /* Ebx: Additional information */ + struct + { + unsigned int BrandIndex : 8; + unsigned int CLFlushLineSize : 8; + unsigned int MaxNumberOfAddressableId : 8; + unsigned int InitialAPICId : 8; + } AdditionalInfo; + /* Ecx, Edx: Feature information */ + struct + { + /* Ecx */ + struct + { + unsigned int SSE3 : 1; /* 00 SSE3 */ + unsigned int PCLMULQDQ : 1; /* 01 PCLMULQDQ */ + unsigned int DTES64 : 1; /* 02 64-bit DS Area */ + unsigned int MONITOR : 1; /* 03 MONITOR/MWAIT */ + unsigned int DS_CPL : 1; /* 04 CPL Qualified Debug Store */ + unsigned int VMX : 1; /* 05 Virtual Machine Extensions */ + unsigned int SMX : 1; /* 06 Safer Mode Extensions */ + unsigned int EIST : 1; /* 07 Enhanced Intel SpeedStep® technology */ + unsigned int TM2 : 1; /* 08 Thermal Monitor 2 */ + unsigned int SSSE3 : 1; /* 09 SSSE3 */ + unsigned int CNXT_ID : 1; /* 10 L1 Context ID*/ + unsigned int SDBG : 1; /* 11 IA32_DEBUG_INTERFACE MSR */ + unsigned int FMA : 1; /* 12 FMA */ + unsigned int CMPXCHG16B : 1; /* 13 CMPXCHG16B Available */ + unsigned int xTPRUpdateControl : 1; /* 14 xTPR Update Control */ + unsigned int PDCM : 1; /* 15 Perfmon and Debug Capability */ + unsigned int ReservedBits0 : 1; /* 16 Reserved */ + unsigned int PCID : 1; /* 17 Process-context identifiers */ + unsigned int DCA : 1; /* 18 Direct Cache Access */ + unsigned int SSE4_1 : 1; /* 19 SSE4.1*/ + unsigned int SSE4_2 : 1; /* 20 SSE4.2*/ + unsigned int x2APIC : 1; /* 21 x2APIC */ + unsigned int MOVBE : 1; /* 22 MOVBE */ + unsigned int POPCNT : 1; /* 23 POPCNT */ + unsigned int TSC_Deadline : 1; /* 24 TSC deadline */ + unsigned int AESNI : 1; /* 25 AESNI */ + unsigned int XSAVE : 1; /* 26 XSAVE */ + unsigned int OSXSAVE : 1; /* 27 CR4.OSXSAVE */ + unsigned int AVX : 1; /* 28 AVX */ + unsigned int F16C : 1; /* 29 16-bit floating-point conversion */ + unsigned int RDRAND : 1; /* 30 RDRAND */ + unsigned int NotUsedBits0 : 1; /* 31 Always 0 */ + }; + /* Edx */ + struct + { + unsigned int FPU : 1; /* 00 x87 FPU */ + unsigned int VME : 1; /* 01 Virtual 8086 mode enhancements */ + unsigned int DE : 1; /* 02 Debugging Extensions */ + unsigned int PSE : 1; /* 03 Page Size Extension */ + unsigned int TSC : 1; /* 04 Time Stamp Counter */ + unsigned int MSR : 1; /* 05 Model Specific Registers RDMSR and WRMSR Instructions */ + unsigned int PAE : 1; /* 06 Physical Address Extension */ + unsigned int MCE : 1; /* 07 Machine Check Exception */ + unsigned int CX8 : 1; /* 08 CMPXCHG8B Instruction */ + unsigned int APIC : 1; /* 09 APIC On-Chip */ + unsigned int ReservedBits1 : 1; /* 10 Reserved */ + unsigned int SEP : 1; /* 11 SYSENTER and SYSEXIT Instructions */ + unsigned int MTRR : 1; /* 12 Memory Type Range Registers */ + unsigned int PGE : 1; /* 13 Page Global Bit */ + unsigned int MCA : 1; /* 14 Machine Check Architecture */ + unsigned int CMOV : 1; /* 15 Conditional Move Instructions */ + unsigned int PAT : 1; /* 16 Page Attribute Table */ + unsigned int PSE_36 : 1; /* 17 36-Bit Page Size Extension */ + unsigned int PSN : 1; /* 18 Processor Serial Number */ + unsigned int CLFSH : 1; /* 19 CLFLUSH Instruction */ + unsigned int ReservedBits2 : 1; /* 20 Reserved */ + unsigned int DS : 1; /* 21 Debug Store */ + unsigned int ACPI : 1; /* 22 Thermal Monitor and Software Controlled Clock Facilities */ + unsigned int MMX : 1; /* 23 Intel MMX Technology */ + unsigned int FXSR : 1; /* 24 FXSAVE and FXRSTOR Instructions */ + unsigned int SSE : 1; /* 25 SSE */ + unsigned int SSE2 : 1; /* 26 SSE2 */ + unsigned int SS : 1; /* 27 Self Snoop */ + unsigned int HTT : 1; /* 28 Max APIC IDs reserved field is Valid */ + unsigned int TM : 1; /* 29 Thermal Monitor */ + unsigned int ReservedBits3 : 1; /* 30 Reserved */ + unsigned int PBE : 1; /* 31 Pending Break Enable */ + }; + } FeatureInfo; + } F01_00; + + /* 07 Structured Extended Feature Flags Enumeration Leaf */ + struct + { + /* Eax */ + unsigned int MaxInputValue; + /* Ebx, Ecx, Edx: Feature Flags */ + struct + { + /* Ebx */ + struct + { + unsigned int FSGSBASE : 1; /* 00 FSGSBASE */ + unsigned int IA32_TSC_ADJUST : 1; /* 01 IA32_TSC_ADJUST MSR */ + unsigned int SGX : 1; /* 02 Intel® Software Guard Extensions */ + unsigned int BMI1 : 1; /* 03 BMI1 */ + unsigned int HLE : 1; /* 04 HLE */ + unsigned int AVX2 : 1; /* 05 AVX2 */ + unsigned int FDP_EXCPTN_ONLY : 1; /* 06 FDP_EXCPTN_ONLY */ + unsigned int SMEP : 1; /* 07 SMEP */ + unsigned int BMI2 : 1; /* 08 BMI2 */ + unsigned int ERMS : 1; /* 09 Enhanced Fast Strings REP MOVB/STOB */ + unsigned int INVPCID : 1; /* 10 INVPCID */ + unsigned int RTM : 1; /* 11 RTM */ + unsigned int RDT_M : 1; /* 12 Intel® Resource Director Technology (Intel® RDT) Monitoring */ + unsigned int DeprecatesFPUCSDS : 1; /* 13 Deprecates FPU CS and FPU DS */ + unsigned int MPX : 1; /* 14 Intel® Memory Protection Extensions */ + unsigned int RDT_A : 1; /* 15 Intel® Resource Director Technology (Intel® RDT) Allocation */ + unsigned int AVX512F : 1; /* 16 AVX512F */ + unsigned int AVX512DQ : 1; /* 17 AVX512DQ */ + unsigned int RDSEED : 1; /* 18 RDSEED */ + unsigned int ADX : 1; /* 19 ADX */ + unsigned int SMAP : 1; /* 20 Supervisor-Mode Access Prevention */ + unsigned int AVX512_IFMA : 1; /* 21 AVX512_IFMA */ + unsigned int ReservedBits0 : 1; /* 22 Reserved */ + unsigned int CLFLUSHOPT : 1; /* 23 CLFLUSHOPT */ + unsigned int CLWB : 1; /* 24 CLWB */ + unsigned int PT : 1; /* 25 Intel Processor Trace */ + unsigned int AVX512PF : 1; /* 26 AVX512PF */ + unsigned int AVX512ER : 1; /* 27 AVX512ER */ + unsigned int AVX512CD : 1; /* 28 AVX512CD */ + unsigned int SHA : 1; /* 29 SHA */ + unsigned int AVX512BW : 1; /* 30 AVX512BW */ + unsigned int AVX512VL : 1; /* 31 AVX512VL */ + }; + /* Ecx */ + struct + { + unsigned int PREFETCHWT1 : 1; /* 00 PREFETCHWT1 */ + unsigned int AVX512_VBMI : 1; /* 01 AVX512_VBMI */ + unsigned int UMIP : 1; /* 02 User-mode instruction prevention */ + unsigned int PKU : 1; /* 03 Protection keys for user-mode pages */ + unsigned int OSPKE : 1; /* 04 CR4.PKE */ + unsigned int WAITPKG : 1; /* 05 WAITPKG */ + unsigned int AVX512_VBMI2 : 1; /* 06 AVX512_VBMI2 */ + unsigned int CET_SS : 1; /* 07 CET shadow stack */ + unsigned int GFNI : 1; /* 08 GFNI */ + unsigned int VAES : 1; /* 09 VAES */ + unsigned int VPCLMULQDQ : 1; /* 10 VPCLMULQDQ */ + unsigned int AVX512_VNNI : 1; /* 11 AVX512_VNNI */ + unsigned int AVX512_BITALG : 1; /* 12 AVX512_BITALG */ + unsigned int TME_EN : 1; /* 13 TME_EN */ + unsigned int AVX512_VPOPCNTDQ : 1; /* 14 AVX512_VPOPCNTDQ */ + unsigned int ReservedBits1 : 1; /* 15 Reserved */ + unsigned int LA57 : 1; /* 16 57-bit linear addresses and five-level paging */ + unsigned int MAWAU : 5; /* 17-21 57-bit linear addresses and five-level paging */ + unsigned int RDPID : 1; /* 22 RDPID and IA32_TSC_AUX */ + unsigned int KL : 1; /* 23 Key Locker */ + unsigned int ReservedBits2 : 1; /* 24 Reserved */ + unsigned int CLDEMOTE : 1; /* 25 Cache line demote */ + unsigned int ReservedBits3 : 1; /* 26 Reserved */ + unsigned int MOVDIRI : 1; /* 27 MOVDIRI */ + unsigned int MOVDIR64B : 1; /* 28 MOVDIR64B */ + unsigned int ENQCMD : 1; /* 29 Enqueue Stores */ + unsigned int SGX_LC : 1; /* 30 SGX Launch Configuration */ + unsigned int PKS : 1; /* 31 Protection keys for supervisor-mode pages */ + }; + /* Edx */ + struct + { + unsigned int ReservedBits4 : 1; /* 00 Reserved */ + unsigned int SGX_KEYS : 1; /* 01 Attestation Services for Intel® SGX */ + unsigned int AVX512_4VNNIW : 1; /* 02 AVX512_4VNNIW */ + unsigned int AVX512_4FMAPS : 1; /* 03 AVX512_4FMAPS */ + unsigned int FSRM : 1; /* 04 Fast Short REP MOV */ + unsigned int UINTR : 1; /* 05 User interrupts */ + unsigned int ReservedBits5 : 2; /* 06-07 Reserved */ + unsigned int AVX512_VP2INTERSECT : 1; /* 08 AVX512_VP2INTERSECT */ + unsigned int SRBDS_CTRL : 1; /* 09 SRBDS_CTRL */ + unsigned int MD_CLEAR : 1; /* 10 MD_CLEAR */ + unsigned int RTM_ALWAYS_ABORT : 1; /* 11 RTM_ALWAYS_ABORT */ + unsigned int ReservedBits6 : 1; /* 12 Reserved */ + unsigned int RTM_FORCE_ABORT : 1; /* 13 RTM_FORCE_ABORT */ + unsigned int SERIALIZE : 1; /* 14 SERIALIZE */ + unsigned int Hybrid : 1; /* 15 Hybrid */ + unsigned int TSXLDTRK : 1; /* 16 Intel TSX suspend/resume of load address tracking */ + unsigned int ReservedBits7 : 1; /* 17 Reserved */ + unsigned int PCONFIG : 1; /* 18 PCONFIG */ + unsigned int ArchitecturalLBRs : 1; /* 19 Architectural LBRs */ + unsigned int CET_IBT : 1; /* 20 CET indirect branch tracking */ + unsigned int ReservedBits8 : 1; /* 21 Reserved */ + unsigned int AMX_BF16 : 1; /* 22 Tile computational operations on bfloat16 numbers */ + unsigned int AVX512_FP16 : 1; /* 23 AVX512_FP16 */ + unsigned int AMX_TILE : 1; /* 24 Tile architecture */ + unsigned int AMX_INT8 : 1; /* 25 Tile computational operations on 8-bit integers */ + unsigned int Enum_IBRS_IBPB : 1; /* 26 Enumerates for IBRS and IBPB */ + unsigned int Enum_STIBP : 1; /* 27 Enumerates for STIBP */ + unsigned int Enum_L1D_FLUSH : 1; /* 28 Enumerates for L1D_FLUSH */ + unsigned int Enum_ARCH_CAPABILITIES : 1; /* 29 Enumerates for the IA32_ARCH_CAPABILITIES MSR */ + unsigned int Enum_CORE_CAPABILITIES : 1; /* 30 Enumerates for the IA32_CORE_CAPABILITIES MSR */ + unsigned int Enum_SSBD : 1; /* 31 Enumerates for SSBD */ + }; + } FeatureFlags; + } F07_00; + + union + { + /* 0 if the sub-leaf index, 1, is invalid */ + struct + { + unsigned int EaxValidity; + unsigned int EbxValidity; + unsigned int EcxValidity; + unsigned int EdxValidity; + }; + /* Eax, Ebx, Ecx, Edx: Feature Flags */ + struct + { + /* Eax */ + struct + { + unsigned int ReservedBits0 : 4; /* 00-03 Reserved */ + unsigned int AVX_VNNI : 1; /* 04 AVX-VNNI */ + unsigned int AVX512_BF16 : 1; /* 05 AVX512_BF16 */ + unsigned int ReservedBits1 : 4; /* 06-09 Reserved */ + unsigned int FZRM : 1; /* 10 Fast zero-length REP MOVSB */ + unsigned int FSRS : 1; /* 11 Fast short REP STOSB */ + unsigned int FSRCS : 1; /* 12 Fast short REP CMPSB/SCASB */ + unsigned int ReservedBits2 : 9; /* 13-21 Reserved */ + unsigned int HRESET : 1; /* 22 HRESET */ + unsigned int ReservedBits3 : 9; /* 23-31 Reserved */ + }; + /* Ebx */ + struct + { + unsigned int Enum_PPIN : 1; /* 00 Enumerates the presence of the IA32_PPIN and IA32_PPIN_CTL MSRs */ + unsigned int ReservedBits4 : 31; /* 01-31 Reserved */ + }; + /* Ecx */ + unsigned int ReservedBits5; + /* Edx */ + struct + { + unsigned int ReservedBits6 : 18; /* 00-17 Reserved */ + unsigned int CET_SSS : 1; /* 18 CET_SSS */ + unsigned int ReservedBits7 : 13; /* 19-31 Reserved */ + }; + }; + } F07_01; + +} CPUID_INFO, *PCPUID_INFO; diff --git a/Source/Include/KNSoft/NDK/Extension/Extension.h b/Source/Include/KNSoft/NDK/Extension/Extension.h new file mode 100644 index 0000000..ba52911 --- /dev/null +++ b/Source/Include/KNSoft/NDK/Extension/Extension.h @@ -0,0 +1,73 @@ +#pragma once + +#ifdef _KNSOFT_NDK_NO_EXTENSION +#pragma message("KNSoft.NDK: Extension.h is included but _KNSOFT_NDK_NO_EXTENSION is defined.") +#endif + +#include "../NT/MinDef.h" + +// Gets equality of two value after masked +#define IS_EQUAL_MASKED(val1, val2, mask) (!(((val1) ^ (val2)) & (mask))) +// Sets or removes a flag from a combination value +#define COMBINE_FLAGS(val, uflag, bEnable) ((bEnable) ? ((val) | (uflag)) : ((val) & ~(uflag))) +// Test combined flags +#define TEST_FLAGS(val, flags) (((val) & (flags)) == (flags)) + +#pragma region Size in bytes + +#define BYTE_BIT 8UL +#define KB_TO_BYTES(x) ((x) * 1024UL) +#define MB_TO_KB(x) ((x) * 1024UL) +#define MB_TO_BYTES(x) (KB_TO_BYTES(MB_TO_KB(x))) +#define GB_TO_MB(x) ((x) * 1024UL) +#define GB_TO_BYTES(x) (MB_TO_BYTES(GB_TO_MB(x))) +#define TB_TO_GB(x) ((x) * 1024UL) +#define TB_TO_BYTES(x) (GB_TO_BYTES(TB_TO_GB(x))) + +#if defined(_WIN64) +#define SIZE_OF_POINTER 8 +#else +#define SIZE_OF_POINTER 4 +#endif + +#pragma endregion + +#pragma region Limitations + +#define MAX_CLASSNAME_CCH 256 +#define MAX_CIDENTIFIERNAME_CCH 247 +#define MAX_ATOM_CCH 255 +#define MAX_REG_KEYNAME_CCH 255 +#define MAX_REG_VALUENAME_CCH 16383 +#define POINTER_CCH (sizeof(PVOID) * 2 + 1) +#define HEX_RGB_CCH 8 // #RRGGBB + +#pragma endregion + +#pragma region Alignments + +#define CODE_ALIGNMENT 0x10 +#define STRING_ALIGNMENT 0x4 + +#pragma endregion + +#pragma region String + +#define _STR_CCH_LEN(quote) (ARRAYSIZE(quote) - 1) + +#define ASCII_CASE_MASK 0b100000 +#define UNICODE_EOL ((DWORD)0x000A000D) +#define ANSI_EOL ((WORD)0x0A0D) + +#pragma endregion + +#pragma region Any-size array + +#define ANYSIZE_STRUCT_SIZE(structure, field, size) UFIELD_OFFSET(structure, field[size]) + +#define DEFINE_ANYSIZE_STRUCT(varName, baseType, arrayType, arraySize) struct {\ + baseType BaseType;\ + arrayType Array[(arraySize) - 1];\ +} varName + +#pragma endregion diff --git a/Source/Include/KNSoft/NDK/Extension/MSToolChain.h b/Source/Include/KNSoft/NDK/Extension/MSToolChain.h new file mode 100644 index 0000000..3cab340 --- /dev/null +++ b/Source/Include/KNSoft/NDK/Extension/MSToolChain.h @@ -0,0 +1,70 @@ +#pragma once + +#ifdef _KNSOFT_NDK_NO_EXTENSION_MSTOOLCHAIN +#pragma message("KNSoft.NDK: MSToolChain.h is included but _KNSOFT_NDK_NO_EXTENSION_MSTOOLCHAIN is defined.") +#endif + +#include "../NT/MinDef.h" + +#pragma region MSVC and WinSDK + +#if _WIN64 +#define IS_WIN64 TRUE +#else +#define IS_WIN64 FALSE +#endif + +/* Patch C_ASSERT to avoid confusion amount static_assert, _Static_assert, _STATIC_ASSERT and C_ASSERT */ + +#undef C_ASSERT +#define C_ASSERT(expr) static_assert((expr), #expr) + +#define __A2U8(quote) u8##quote +#define _A2U8(quote) __A2U8(quote) + +#define __A2W(quote) L##quote +#define _A2W(quote) __A2W(quote) + +#if _WIN64 +#define MSVC_VARDNAME(x) x +#define MSVC_INCLUDE_VAR(x) __pragma(comment(linker, "/include:"#x)) +#else +#define MSVC_VARDNAME(x) _##x +#define MSVC_INCLUDE_VAR(x) __pragma(comment(linker, "/include:_"#x)) +#endif + +/* + * Initializer support + * See also: + * https://devblogs.microsoft.com/cppblog/new-compiler-warnings-for-dynamic-initialization/ + * https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization + * + * ** FIXME: Not support C++ yet ** + */ + +#ifndef __cplusplus + +// Section 'section-name' is reserved for C++ dynamic initialization. +#pragma warning(error: 5247 5248) + +typedef int(__cdecl* _PIFV)(void); + +#pragma section(".CRT$XINDK", long, read) + +#define MSVC_INITIALIZER(x)\ +int __cdecl x(void);\ +__declspec(allocate(".CRT$XINDK")) _PIFV _KNSoft_NDK_Initializer_User_##x = &x;\ +MSVC_INCLUDE_VAR(_KNSoft_NDK_Initializer_User_##x)\ +int __cdecl x(void) + +#endif + +#pragma endregion + +#pragma region MSBuild + +#define MSB_LIB_PATH(LibName) (MSB_PLATFORMTARGET"/"MSB_CONFIGURATION"/"##LibName) + +/* Other MSB_* are defined in Directory.Build.props */ + +#pragma endregion diff --git a/Source/Include/KNSoft/NDK/Extension/SMBIOS.h b/Source/Include/KNSoft/NDK/Extension/SMBIOS.h new file mode 100644 index 0000000..23d0018 --- /dev/null +++ b/Source/Include/KNSoft/NDK/Extension/SMBIOS.h @@ -0,0 +1,1489 @@ +/* + * KNSoft.NDK SMBIOS.h licensed under the MIT license. + * + * SMBIOS Specification (https://www.dmtf.org/standards/smbios) + * + * V3.7.1 https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.7.1.pdf + */ + +#pragma once + +#include + +typedef unsigned __int64 QWORD, near* PQWORD, far* LPQWORD; + +// nonstandard extension used: zero-sized array in struct/union +#pragma warning(disable: 4200) + +#pragma pack(push, 1) + +typedef enum _SMBIOS_INFORMATION_TYPE +{ + SMBIOSBIOSInformation = 0, + SMBIOSSystemInformation = 1, + SMBIOSBaseboardInformation = 2, + SMBIOSSystemEnclosureOrChassis = 3, + SMBIOSProcessorInformation = 4, + SMBIOSMemoryControllerInformation = 5, /* Obsolete */ + SMBIOSMemoryModuleInformation = 6, /* Obsolete */ + SMBIOSCacheInformation = 7, + SMBIOSPortConnectorInformation = 8, + SMBIOSSystemSlots = 9, + SMBIOSOnBoardDevicesInformation = 10, /* Obsolete */ + SMBIOSOEMStrings = 11, + SMBIOSSystemConfigurationOptions = 12, + SMBIOSBIOSLanguageInformation = 13, + SMBIOSGroupAssociations = 14, + SMBIOSSystemEventLog = 15, + SMBIOSPhysicalMemoryArray = 16, + SMBIOSMemoryDevice = 17, + SMBIOS32BitMemoryErrorInformation = 18, + SMBIOSMemoryArrayMappedAddress = 19, + SMBIOSMemoryDeviceMappedAddress = 20, + SMBIOSBuiltinPointingDevice = 21, + SMBIOSPortableBattery = 22, + SMBIOSSystemReset = 23, + SMBIOSHardwareSecurity = 24, + SMBIOSSystemPowerControls = 25, + SMBIOSVoltageProbe = 26, + SMBIOSCoolingDevice = 27, + SMBIOSTemperatureProbe = 28, + SMBIOSElectricalCurrentProbe = 29, + SMBIOSOutOfBandRemoteAccess = 30, + SMBIOSBootIntegrityServicesEntryPoint = 31, + SMBIOSSystemBootInformation = 32, + SMBIOS64BitMemoryErrorInformation = 33, + SMBIOSManagementDevice = 34, + SMBIOSManagementDeviceComponent = 35, + SMBIOSManagementDeviceThresholdData = 36, + SMBIOSMemoryChannel = 37, + SMBIOSIPMIDeviceInformation = 38, + SMBIOSSystemPowerSupply = 39, + SMBIOSAdditionalInformation = 40, + SMBIOSOnboardDevicesExtendedInformation = 41, + SMBIOSManagementControllerHostInterface = 42, + SMBIOSTPMDevice = 43, + SMBIOSProcessorAdditionalInformation = 44, + SMBIOSFirmwareInventoryInformation = 45, + SMBIOSStringProperty = 46, + SMBIOSInactive = 126, + SMBIOSEndOfTable = 127 +} SMBIOS_INFORMATION_TYPE, *PSMBIOS_INFORMATION_TYPE; + +/* aka RawSMBIOSData */ +typedef struct _SMBIOS_RAWDATA +{ + BYTE Used20CallingMethod; + BYTE SMBIOSMajorVersion; + BYTE SMBIOSMinorVersion; + BYTE DmiRevision; + DWORD Length; + _Field_size_bytes_(Length) BYTE SMBIOSTableData[]; // PSMBIOS_TABLE_HEADER +} SMBIOS_RAWDATA, *PSMBIOS_RAWDATA; + +typedef struct _SMBIOS_TABLE_HEADER +{ + BYTE Type; + BYTE Length; + WORD Handle; +} SMBIOS_TABLE_HEADER, *PSMBIOS_TABLE_HEADER; +C_ASSERT(sizeof(SMBIOS_TABLE_HEADER) == 4); + +typedef struct _SMBIOS_TABLE +{ + SMBIOS_TABLE_HEADER Header; + union + { + struct + { + BYTE Vendor; + BYTE Version; + WORD StartingAddressSegment; + BYTE ReleaseDate; + BYTE ROMSize; + union + { + QWORD Characteristics; + struct + { + QWORD Reserved0 : 1; /* 00 Reserved */ + QWORD Reserved1 : 1; /* 01 Reserved */ + QWORD Unknown0 : 1; /* 02 Unknown */ + QWORD CharacteristicsNotSupported : 1; /* 03 BIOS Characteristics are not supported */ + QWORD ISA : 1; /* 04 ISA is supported */ + QWORD MCA : 1; /* 05 MCA is supported */ + QWORD EISA : 1; /* 06 EISA is supported */ + QWORD PCI : 1; /* 07 PCI is supported */ + QWORD PCCard : 1; /* 08 PC card (PCMCIA) is supported */ + QWORD PNP : 1; /* 09 Plug and Play is supported */ + QWORD APM : 1; /* 10 APM is supported */ + QWORD Upgradeable : 1; /* 11 BIOS is upgradeable (Flash) */ + QWORD ShadowingIsAllowed : 1; /* 12 BIOS shadowing is allowed */ + QWORD VL_VESA : 1; /* 13 VL-VESA is supported */ + QWORD ESCD : 1; /* 14 ESCD support is available */ + QWORD BootFromCD : 1; /* 15 Boot from CD is supported */ + QWORD SelectableBoot : 1; /* 16 Selectable boot is supported */ + QWORD ROMIsSocketed : 1; /* 17 BIOS ROM is socketed (e.g., PLCC or SOP socket) */ + QWORD BootFromPCCard : 1; /* 18 Boot from PC card (PCMCIA) is supported */ + QWORD EDDSpecification : 1; /* 19 EDD specification is supported */ + QWORD FloppyForNEC9800_1Dot2MB : 1; /* 20 Int 13h — Japanese floppy for NEC 9800 1.2 MB (3.5”, 1K bytes/sector, 360 RPM) is supported */ + QWORD FloppyForToshiba_1Dot2MB : 1; /* 21 Int 13h — Japanese floppy for Toshiba 1.2 MB (3.5”, 360 RPM) is supported */ + QWORD Floppy_5Dot25Inch_360KB : 1; /* 22 Int 13h — 5.25” / 360 KB floppy services are supported */ + QWORD Floppy_5Dot25Inch_1Dot2MB : 1; /* 23 Int 13h — 5.25” / 1.2 MB floppy services are supported */ + QWORD Floppy_3Dot5Inch_720KB : 1; /* 24 Int 13h — 3.5” / 720 KB floppy services are supported */ + QWORD Floppy_3Dot5Inch_2Dot88MB : 1; /* 25 Int 13h — 3.5” / 2.88 MB floppy services are supported */ + QWORD PrintScreenService : 1; /* 26 Int 5h, print screen service is supported */ + QWORD _8042KeyboardServices : 1; /* 27 Int 9h, 8042 keyboard services are supported */ + QWORD SerialServices : 1; /* 28 Int 14h, serial services are supported */ + QWORD PrinterServices : 1; /* 29 Int 17h, printer services are supported */ + QWORD CGA_Mono_VideoServices : 1; /* 30 Int 10h, CGA/Mono Video Services are supported */ + QWORD NEC_PC98 : 1; /* 31 NEC PC-98 */ + QWORD ReservedForBIOSVendor : 16; /* 32:47 Reserved for BIOS vendor */ + QWORD ReservedForSystemVendor : 16; /* 48:63 Reserved for system vendor */ + }; + }; + union + { + BYTE CharacteristicsExtensionBytes[2]; + struct + { + struct + { + BYTE ACPI : 1; /* 00 ACPI is supported */ + BYTE USBLegacy : 1; /* 01 USB Legacy is supported */ + BYTE AGP : 1; /* 02 AGP is supported */ + BYTE I2OBoot : 1; /* 03 I2O boot is supported */ + BYTE LS120_SuperDiskBoot : 1; /* 04 LS-120 SuperDisk boot is supported */ + BYTE ATAPI_ZIP_DriveBoot : 1; /* 05 ATAPI ZIP drive boot is supported */ + BYTE _1394Boot : 1; /* 06 1394 boot is supported */ + BYTE SmartBattery : 1; /* 07 Smart battery is supported */ + }; + struct + { + BYTE BIOSBootSpecification : 1; /* 00 BIOS Boot Specification is supported */ + BYTE FunctionKeyInitiatedNetworkServiceBoot : 1; /* 01 Function key-initiated network service boot is supported */ + BYTE EnableTargetedContentDistribution : 1; /* 02 Enable targeted content distribution */ + BYTE UEFISpecification : 1; /* 03 UEFI Specification is supported */ + BYTE VirtualMachine : 1; /* 04 SMBIOS table describes a virtual machine */ + BYTE ManufacturingMode : 1; /* 05 Manufacturing mode is supported */ + BYTE ManufacturingModeEnabled : 1; /* 06 Manufacturing mode is enabled */ + BYTE Reserved : 1; /* 07 Reserved */ + }; + }; + }; + BYTE MajorRelease; + BYTE MinorRelease; + BYTE ECFirmwareMajorRelease; + BYTE ECFirmwareMinorRelease; + union + { + WORD ExtendedROMSize; + struct + { + WORD Size : 14; /* 00:13 Size */ +#define SMBIOS_BIOS_EXTENDEDROMSIZE_UNIT_MB 00b +#define SMBIOS_BIOS_EXTENDEDROMSIZE_UNIT_GB 01b + WORD Unit : 2; /* 14:15 Unit, SMBIOS_BIOS_EXTENDEDROMSIZE_UNIT_* */ + }; + }; + } TYPE_0_BIOS_INFO; + struct + { + BYTE Manufacturer; + BYTE ProductName; + BYTE Version; + BYTE SerialNumber; + BYTE UUID[16]; +#define SMBIOS_SYSTEM_WAKEUPTYPE_RESERVED ((BYTE)00h) +#define SMBIOS_SYSTEM_WAKEUPTYPE_OTHER ((BYTE)01h) +#define SMBIOS_SYSTEM_WAKEUPTYPE_UNKNOW ((BYTE)02h) +#define SMBIOS_SYSTEM_WAKEUPTYPE_APM_TIMER ((BYTE)03h) +#define SMBIOS_SYSTEM_WAKEUPTYPE_MODEM_RING ((BYTE)04h) +#define SMBIOS_SYSTEM_WAKEUPTYPE_LAN_REMOTE ((BYTE)05h) +#define SMBIOS_SYSTEM_WAKEUPTYPE_POWER_SWITCH ((BYTE)06h) +#define SMBIOS_SYSTEM_WAKEUPTYPE_PCI_PME ((BYTE)07h) +#define SMBIOS_SYSTEM_WAKEUPTYPE_AC_POWER_RESTORED ((BYTE)08h) + BYTE WakeUpType; /* SMBIOS_SYSTEM_WAKEUPTYPE_* */ + BYTE SKUNumber; + BYTE Famliy; + } TYPE_1_SYSTEM_INFO; + struct + { + BYTE Manufacturer; + BYTE Product; + BYTE Version; + BYTE SerialNumber; + BYTE AssetTag; + union + { + BYTE FeatureFlags; + struct + { + BYTE HostingBoard : 1; /* 00 The board is a hosting board (for example, a motherboard) */ + BYTE RequiresAuxiliary : 1; /* 01 The board requires at least one daughter board or auxiliary card to function properly */ + BYTE Removable : 1; /* 02 The board is removable */ + BYTE Replaceable : 1; /* 03 The board is replaceable */ + BYTE HotSwappable : 1; /* 04 The board is s hot swappable */ + BYTE Reserved : 3; /* 05:07 Reserved for future definition by this specification */ + }; + }; + BYTE LocationInChassis; + WORD ChassisHandle; +#define SMBIOS_BASEBOARD_TYPE_UNKNOWN ((BYTE)01h) +#define SMBIOS_BASEBOARD_TYPE_OTHER ((BYTE)02h) +#define SMBIOS_BASEBOARD_TYPE_SERVER_BLADE ((BYTE)03h) +#define SMBIOS_BASEBOARD_TYPE_CONNECTIVITY_SWITCH ((BYTE)04h) +#define SMBIOS_BASEBOARD_TYPE_SYSTEM_MANAGEMENT_MODULE ((BYTE)05h) +#define SMBIOS_BASEBOARD_TYPE_PROCESSOR_MODULE ((BYTE)06h) +#define SMBIOS_BASEBOARD_TYPE_IO_MODULE ((BYTE)07h) +#define SMBIOS_BASEBOARD_TYPE_MEMORY_MODULE ((BYTE)08h) +#define SMBIOS_BASEBOARD_TYPE_DAUGHTER_BOARD ((BYTE)09h) +#define SMBIOS_BASEBOARD_TYPE_MOTHERBOARD ((BYTE)0Ah) +#define SMBIOS_BASEBOARD_TYPE_PROCESSOR_MEMORY_MODULE ((BYTE)0Bh) +#define SMBIOS_BASEBOARD_TYPE_PROCESSOR_IO_MODULE ((BYTE)0Ch) +#define SMBIOS_BASEBOARD_TYPE_INTERCONNECT_BOARD ((BYTE)0Dh) + BYTE BoardType; /* SMBIOS_BASEBOARD_TYPE_*/ + BYTE NumberOfContainedObjectHandles; + _Field_size_(NumberOfContainedObjectHandles) WORD ContainedObjectHandles[]; + } TYPE_2_BASEBOARD_INFO; + struct + { + BYTE Manufacturer; + union + { + BYTE Type; + struct + { +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_DESKTOP ((BYTE)03h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_LOW_PROFILE_DESKTOP ((BYTE)04h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_PIZZA_BOX ((BYTE)05h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_MINI_TOWER ((BYTE)06h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_TOWER ((BYTE)07h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_PORTABLE ((BYTE)08h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_LAPTOP ((BYTE)09h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_NOTEBOOK ((BYTE)0Ah) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_HAND_HELD ((BYTE)0Bh) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_DOCKING_STATION ((BYTE)0Ch) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_ALL_IN_ONE ((BYTE)0Dh) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_SUB_NOTEBOOK ((BYTE)0Eh) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_SPACE_SAVING ((BYTE)0Fh) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_LUNCH_BOX ((BYTE)10h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_MAIN_SERVER_CHASSIS ((BYTE)11h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_EXPANSION_CHASSIS ((BYTE)12h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_SUB_CHASSIS ((BYTE)13h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_BUS_EXPANSION_CHASSIS ((BYTE)14h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_PERIPHERAL_CHASSIS ((BYTE)15h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_RAID_CHASSIS ((BYTE)16h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_RACK_MOUNT_CHASSIS ((BYTE)17h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_SEALED_CASE_PC ((BYTE)18h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_MULTI_SYSTEM_CHASSIS ((BYTE)19h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_COMPACT_PCI ((BYTE)1Ah) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_ADVANCED_TCA ((BYTE)1Bh) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_BLADE ((BYTE)1Ch) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_BLADE_ENCLOSURE ((BYTE)1Dh) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_TABLET ((BYTE)1Eh) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_CONVERTIBLE ((BYTE)1Fh) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_DETACHABLE ((BYTE)20h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_IOT_GATEWAY ((BYTE)21h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_EMBEDDED_PC ((BYTE)22h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_MINI_PC ((BYTE)23h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_STICK_PC ((BYTE)24h) + BYTE Value : 7; /* SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_TYPE_* */ + BYTE ChassisLock : 1; /* Chassis lock is present */ + }; + }; + BYTE Version; + BYTE SerialNumber; + BYTE AssetTagNumber; +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_OTHER ((BYTE)01h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_UNKNOWN ((BYTE)02h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_SAFE ((BYTE)03h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_WARNING ((BYTE)04h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_CRITICAL ((BYTE)05h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_NON_RECOVERABLE ((BYTE)06h) + BYTE BootUpState; /* SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_* */ + BYTE PowerSupplyState; /* SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_* */ + BYTE ThermalState; /* SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_STATE_* */ +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_SECURITY_STATE_OTHER ((BYTE)01h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_SECURITY_STATE_UNKNOWN ((BYTE)02h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_SECURITY_STATE_NONE ((BYTE)03h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_SECURITY_STATE_EXTERNAL_INTERFACE_LOCKED_OUT ((BYTE)04h) +#define SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_SECURITY_STATE_EXTERNAL_INTERFACE_ENABLED ((BYTE)05h) + BYTE SecurityStatus; /* SMBIOS_SYSTEM_ENCLOSURE_OR_CHASSIS_SECURITY_STATE_* */ + DWORD OEMDefined; + BYTE Height; + BYTE NumberOfPowerCords; + BYTE ContainedElementCount; + BYTE ContainedElementRecordLength; + _Field_size_bytes_(ContainedElementCount * ContainedElementRecordLength) BYTE ContainedElements[]; + /* BYTE SKUNumber; */ + } TYPE_3_SYSTEM_ENCLOSURE_OR_CHASSIS; + struct + { + BYTE SocketDesignation; +#define SMBIOS_PROCESSOR_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_PROCESSOR_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_PROCESSOR_TYPE_CENTRAL_PROCESSOR ((BYTE)03h) +#define SMBIOS_PROCESSOR_TYPE_MATH_PROCESSOR ((BYTE)04h) +#define SMBIOS_PROCESSOR_TYPE_DSP_PROCESSOR ((BYTE)05h) +#define SMBIOS_PROCESSOR_TYPE_VIDEO_PROCESSOR ((BYTE)06h) + BYTE Type; /* SMBIOS_PROCESSOR_TYPE_* */ + BYTE Family; + BYTE Manufacturer; + QWORD ID; + BYTE Version; + union + { + BYTE Voltage; + struct + { + BYTE Voltage5V : 1; + BYTE Voltage3Dot3V : 1; + BYTE Voltage2Dot9V : 1; + BYTE Reserved0 : 1; + BYTE Reserved1 : 3; + BYTE LegacyMode : 1; /* Should be 0 */ + }; + struct + { + BYTE VoltageTimes10 : 7; + BYTE NotLegacyModeVoltage : 1; /* Should be 1 */ + }; + }; + WORD ExternalClock; + WORD MaxSpeed; + WORD CurrentSpeed; + union + { + BYTE Status; + struct + { +#define SMBIOS_PROCESSOR_CPU_STATUS_UNKNOWN 0h +#define SMBIOS_PROCESSOR_CPU_STATUS_ENABLED 1h +#define SMBIOS_PROCESSOR_CPU_STATUS_DISABLED_BY_USER 2h +#define SMBIOS_PROCESSOR_CPU_STATUS_DISABLED_BY_BIOS 3h +#define SMBIOS_PROCESSOR_CPU_STATUS_IDLE 4h +#define SMBIOS_PROCESSOR_CPU_STATUS_OTHER 7h + BYTE CPUStatus : 3; /* SMBIOS_PROCESSOR_CPU_STATUS_* */ + BYTE Reserved2 : 3; + BYTE CPUSocketPopulated : 1; + BYTE Reserved3 : 1; + }; + }; +#define SMBIOS_PROCESSOR_UPGRADE_OTHER ((BYTE)01h) +#define SMBIOS_PROCESSOR_UPGRADE_UNKNOWN ((BYTE)02h) +#define SMBIOS_PROCESSOR_UPGRADE_DAUGHTER_BOARD ((BYTE)03h) +#define SMBIOS_PROCESSOR_UPGRADE_ZIF_SOCKET ((BYTE)04h) +#define SMBIOS_PROCESSOR_UPGRADE_REPLACEABLE_PIGGY_BACK ((BYTE)05h) +#define SMBIOS_PROCESSOR_UPGRADE_NONE ((BYTE)06h) +#define SMBIOS_PROCESSOR_UPGRADE_LIF_SOCKET ((BYTE)07h) +#define SMBIOS_PROCESSOR_UPGRADE_SLOT_1 ((BYTE)08h) +#define SMBIOS_PROCESSOR_UPGRADE_SLOT_2 ((BYTE)09h) +#define SMBIOS_PROCESSOR_UPGRADE_370_PIN_SOCKET ((BYTE)0Ah) +#define SMBIOS_PROCESSOR_UPGRADE_SLOT_A ((BYTE)0Bh) +#define SMBIOS_PROCESSOR_UPGRADE_SLOT_M ((BYTE)0Ch) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_423 ((BYTE)0Dh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_A ((BYTE)0Eh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_478 ((BYTE)0Fh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_754 ((BYTE)10h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_940 ((BYTE)11h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_939 ((BYTE)12h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_mPGA604 ((BYTE)13h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA771 ((BYTE)14h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA775 ((BYTE)15h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_S1 ((BYTE)16h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_AM2 ((BYTE)17h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_F ((BYTE)18h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1366 ((BYTE)19h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_G34 ((BYTE)1Ah) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_AM3 ((BYTE)1Bh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_C32 ((BYTE)1Ch) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1156 ((BYTE)1Dh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1567 ((BYTE)1Eh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_PGA988A ((BYTE)1Fh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1288 ((BYTE)20h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_rPGA988B ((BYTE)21h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1023 ((BYTE)22h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1224 ((BYTE)23h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1155 ((BYTE)24h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1356 ((BYTE)25h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA2011 ((BYTE)26h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_FS1 ((BYTE)27h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_FS2 ((BYTE)28h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_FM1 ((BYTE)29h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_FM2 ((BYTE)2Ah) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA2011_3 ((BYTE)2Bh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1356_3 ((BYTE)2Ch) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1150 ((BYTE)2Dh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1168 ((BYTE)2Eh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1234 ((BYTE)2Fh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1364 ((BYTE)30h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_AM4 ((BYTE)31h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1151 ((BYTE)32h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1356 ((BYTE)33h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1440 ((BYTE)34h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1515 ((BYTE)35h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA3647_1 ((BYTE)36h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_SP3 ((BYTE)37h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_SP3r2 ((BYTE)38h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA2066 ((BYTE)39h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1392 ((BYTE)3Ah) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1510 ((BYTE)3Bh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1528 ((BYTE)3Ch) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA4189 ((BYTE)3Dh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1200 ((BYTE)3Eh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA4677 ((BYTE)3Fh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1700 ((BYTE)40h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1744 ((BYTE)41h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1781 ((BYTE)42h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1211 ((BYTE)43h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA2422 ((BYTE)44h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA1211 ((BYTE)45h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA2422 ((BYTE)46h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA5773 ((BYTE)47h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA5773 ((BYTE)48h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_AM5 ((BYTE)49h) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_SP5 ((BYTE)4Ah) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_SP6 ((BYTE)4Bh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA883 ((BYTE)4Ch) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA1190 ((BYTE)4Dh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_BGA4129 ((BYTE)4Eh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA4710 ((BYTE)4Fh) +#define SMBIOS_PROCESSOR_UPGRADE_SOCKET_LGA7529 ((BYTE)50h) + BYTE Upgrade; /* SMBIOS_PROCESSOR_UPGRADE_* */ + WORD L1CacheHandle; + WORD L2CacheHandle; + WORD L3CacheHandle; + BYTE SerialNumber; + BYTE AssetTag; + BYTE PartNumber; + BYTE CoreCount; + BYTE CoreEnabled; + BYTE ThreadCount; + union + { + WORD Characteristics; + struct + { + WORD Reserved4 : 1; + WORD Unknown : 1; + WORD _64BitCapable : 1; + WORD MultiCore : 1; + WORD HardwareThread : 1; + WORD ExecuteProtection : 1; + WORD EnhancedVirtualization : 1; + WORD PowerPerformanceControl : 1; + WORD _128BitCapable : 1; + WORD Arm64SoCID : 1; + WORD Reserved5 : 6; + }; + }; + WORD Famliy2; + WORD CoreCount2; + WORD CoreEnabled2; + WORD ThreadCount2; + WORD ThreadEnabled; + } TYPE_4_PROCESSOR_INFO; + struct + { + BYTE SocketDesignation; + union + { + WORD CacheConfiguration; + struct + { + WORD CacheLevel : 3; + WORD CacheSocketed : 1; + WORD Reserved0 : 1; +#define SMBIOS_CACHE_LOCATION_INTERNAL 00b +#define SMBIOS_CACHE_LOCATION_EXTERNAL 01b +#define SMBIOS_CACHE_LOCATION_RESERVED 10b +#define SMBIOS_CACHE_LOCATION_UNKNOWN 11b + WORD Location : 2; /* SMBIOS_CACHE_LOCATION_* */ + WORD Enabled : 1; +#define SMBIOS_CACHE_OPERATIONAL_MODE_WRITE_THROUGH 00b +#define SMBIOS_CACHE_OPERATIONAL_MODE_WRITE_BACK 01b +#define SMBIOS_CACHE_OPERATIONAL_MODE_VARIES_WITH_MEMORY_ADDRESS 10b +#define SMBIOS_CACHE_OPERATIONAL_MODE_UNKNOWN 11b + WORD OperationalMode : 2; /* SMBIOS_CACHE_OPERATIONAL_MODE_* */ + WORD Reserved1 : 6; + }; + }; + union + { + WORD MaximumCacheSize; + struct + { + WORD MaxSizeInGranularity : 15; + WORD MaxSizeGranularity : 1; + }; + }; + union + { + WORD InstalledSize; + struct + { + WORD InstalledSizeInGranularity : 15; + WORD InstalledSizeGranularity : 1; + }; + }; + typedef struct _SMBIOS_CACHE_SRAM_TYPE + { + WORD Other : 1; + WORD Unknown : 1; + WORD NonBurst : 1; + WORD Burst : 1; + WORD PipelineBurst : 1; + WORD Synchronous : 1; + WORD Asynchronous : 1; + WORD Reserved : 9; + } SMBIOS_CACHE_SRAM_TYPE, *PSMBIOS_CACHE_SRAM_TYPE; + C_ASSERT(sizeof(SMBIOS_CACHE_SRAM_TYPE) == sizeof(WORD)); + SMBIOS_CACHE_SRAM_TYPE SupportedSRAMType; + SMBIOS_CACHE_SRAM_TYPE CurrentSRAMType; + BYTE CacheSpeed; +#define SMBIOS_CACHE_ERROR_CORRECTION_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_CACHE_ERROR_CORRECTION_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_CACHE_ERROR_CORRECTION_TYPE_NONE ((BYTE)03h) +#define SMBIOS_CACHE_ERROR_CORRECTION_TYPE_PARITY ((BYTE)04h) +#define SMBIOS_CACHE_ERROR_CORRECTION_TYPE_SINGLE_BIT_ECC ((BYTE)05h) +#define SMBIOS_CACHE_ERROR_CORRECTION_TYPE_MULTI_BIT_ECC ((BYTE)06h) + BYTE ErrorCorrectionType; /* SMBIOS_CACHE_ERROR_CORRECTION_TYPE_* */ +#define SMBIOS_CACHE_SYSTEM_CACHE_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_CACHE_SYSTEM_CACHE_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_CACHE_SYSTEM_CACHE_TYPE_INSTRUCTION ((BYTE)03h) +#define SMBIOS_CACHE_SYSTEM_CACHE_TYPE_DATA ((BYTE)04h) +#define SMBIOS_CACHE_SYSTEM_CACHE_TYPE_UNIFIED ((BYTE)05h) + BYTE SystemCacheType; /* SMBIOS_CACHE_SYSTEM_CACHE_TYPE_* */ +#define SMBIOS_CACHE_ASSOCIATIVITY_OTHER ((BYTE)01h) +#define SMBIOS_CACHE_ASSOCIATIVITY_UNKNOWN ((BYTE)02h) +#define SMBIOS_CACHE_ASSOCIATIVITY_DIRECT_MAPPED ((BYTE)03h) +#define SMBIOS_CACHE_ASSOCIATIVITY_2_WAY_SET_ASSOCIATIVE ((BYTE)04h) +#define SMBIOS_CACHE_ASSOCIATIVITY_4_WAY_SET_ASSOCIATIVE ((BYTE)05h) +#define SMBIOS_CACHE_ASSOCIATIVITY_FULL_ASSOCIATIVE ((BYTE)06h) +#define SMBIOS_CACHE_ASSOCIATIVITY_8_WAY_SET_ASSOCIATIVE ((BYTE)07h) +#define SMBIOS_CACHE_ASSOCIATIVITY_16_WAY_SET_ASSOCIATIVE ((BYTE)08h) +#define SMBIOS_CACHE_ASSOCIATIVITY_12_WAY_SET_ASSOCIATIVE ((BYTE)09h) +#define SMBIOS_CACHE_ASSOCIATIVITY_24_WAY_SET_ASSOCIATIVE ((BYTE)0Ah) +#define SMBIOS_CACHE_ASSOCIATIVITY_32_WAY_SET_ASSOCIATIVE ((BYTE)0Bh) +#define SMBIOS_CACHE_ASSOCIATIVITY_48_WAY_SET_ASSOCIATIVE ((BYTE)0Ch) +#define SMBIOS_CACHE_ASSOCIATIVITY_64_WAY_SET_ASSOCIATIVE ((BYTE)0Dh) +#define SMBIOS_CACHE_ASSOCIATIVITY_20_WAY_SET_ASSOCIATIVE ((BYTE)0Eh) + BYTE Associativity; /* SMBIOS_CACHE_ASSOCIATIVITY_* */ + union + { + DWORD MaximumCacheSize2; + struct + { + DWORD MaxSizeInGranularity2 : 31; + DWORD MaxSizeGranularity2 : 1; + }; + }; + union + { + DWORD InstalledCacheSize2; + struct + { + DWORD InstalledCacheSizeInGranularity2 : 31; + DWORD InstalledCacheSizeGranularity2 : 1; + }; + }; + } TYPE_7_CACHE_INFO; + struct + { + BYTE InternalReferenceDesignator; +#define SMBIOS_PORT_CONNECTOR_TYPE_NONE ((BYTE)00h) +#define SMBIOS_PORT_CONNECTOR_TYPE_CENTRONICS ((BYTE)01h) +#define SMBIOS_PORT_CONNECTOR_TYPE_MINI_CENTRONICS ((BYTE)02h) +#define SMBIOS_PORT_CONNECTOR_TYPE_MINI_PROPRIETARY ((BYTE)03h) +#define SMBIOS_PORT_CONNECTOR_TYPE_DB_25_PIN_MALE ((BYTE)04h) +#define SMBIOS_PORT_CONNECTOR_TYPE_DB_25_PIN_FEMALE ((BYTE)05h) +#define SMBIOS_PORT_CONNECTOR_TYPE_DB_15_PIN_MALE ((BYTE)06h) +#define SMBIOS_PORT_CONNECTOR_TYPE_DB_15_PIN_FEMALE ((BYTE)07h) +#define SMBIOS_PORT_CONNECTOR_TYPE_DB_9_PIN_MALE ((BYTE)08h) +#define SMBIOS_PORT_CONNECTOR_TYPE_DB_9_PIN_FEMALE ((BYTE)09h) +#define SMBIOS_PORT_CONNECTOR_TYPE_RJ_11 ((BYTE)0Ah) +#define SMBIOS_PORT_CONNECTOR_TYPE_RJ_45 ((BYTE)0Bh) +#define SMBIOS_PORT_CONNECTOR_TYPE_50_PIN_MINISCSI ((BYTE)0Ch) +#define SMBIOS_PORT_CONNECTOR_TYPE_MINI_DIN ((BYTE)0Dh) +#define SMBIOS_PORT_CONNECTOR_TYPE_MICRO_DIN ((BYTE)0Eh) +#define SMBIOS_PORT_CONNECTOR_TYPE_PS_2 ((BYTE)0Fh) +#define SMBIOS_PORT_CONNECTOR_TYPE_INFRARED ((BYTE)10h) +#define SMBIOS_PORT_CONNECTOR_TYPE_HP_HIL ((BYTE)11h) +#define SMBIOS_PORT_CONNECTOR_TYPE_ACCESS_BUS ((BYTE)12h) +#define SMBIOS_PORT_CONNECTOR_TYPE_SSA_SCSI ((BYTE)13h) +#define SMBIOS_PORT_CONNECTOR_TYPE_CIRCULAR_DIN_8_MALE ((BYTE)14h) +#define SMBIOS_PORT_CONNECTOR_TYPE_CIRCULAR_DIN_8_FEMALE ((BYTE)15h) +#define SMBIOS_PORT_CONNECTOR_TYPE_ON_BOARD_IDE ((BYTE)16h) +#define SMBIOS_PORT_CONNECTOR_TYPE_ON_BOARD_FLOPPY ((BYTE)17h) +#define SMBIOS_PORT_CONNECTOR_TYPE_9_PIN_DUAL_INLINE ((BYTE)18h) +#define SMBIOS_PORT_CONNECTOR_TYPE_25_PIN_DUAL_INLINE ((BYTE)19h) +#define SMBIOS_PORT_CONNECTOR_TYPE_50_PIN_DUAL_INLINE ((BYTE)1Ah) +#define SMBIOS_PORT_CONNECTOR_TYPE_68_PIN_DUAL_INLINE ((BYTE)1Bh) +#define SMBIOS_PORT_CONNECTOR_TYPE_ON_BOARD_SOUND_INPUT_FROM_CD_ROM ((BYTE)1Ch) +#define SMBIOS_PORT_CONNECTOR_TYPE_MINI_CENTRONICS_TYPE_14 ((BYTE)1Dh) +#define SMBIOS_PORT_CONNECTOR_TYPE_MINI_CENTRONICS_TYPE_26 ((BYTE)1Eh) +#define SMBIOS_PORT_CONNECTOR_TYPE_MINI_JACK ((BYTE)1Fh) +#define SMBIOS_PORT_CONNECTOR_TYPE_BNC ((BYTE)20h) +#define SMBIOS_PORT_CONNECTOR_TYPE_1394 ((BYTE)21h) +#define SMBIOS_PORT_CONNECTOR_TYPE_SAS_SATA_PLUG_RECEPTACLE ((BYTE)22h) +#define SMBIOS_PORT_CONNECTOR_TYPE_USB_TYPE_C_RECEPTACLE ((BYTE)23h) +#define SMBIOS_PORT_CONNECTOR_TYPE_PC_98 ((BYTE)A0h) +#define SMBIOS_PORT_CONNECTOR_TYPE_PC_98HIRESO ((BYTE)A1h) +#define SMBIOS_PORT_CONNECTOR_TYPE_PC_H98 ((BYTE)A2h) +#define SMBIOS_PORT_CONNECTOR_TYPE_PC_98NOTE ((BYTE)A3h) +#define SMBIOS_PORT_CONNECTOR_TYPE_PC_98FULL ((BYTE)A4h) +#define SMBIOS_PORT_CONNECTOR_TYPE_OTHER ((BYTE)FFh) + BYTE InternalConnectorType; /* SMBIOS_PORT_CONNECTOR_TYPE_* */ + BYTE ExternalReferenceDesignator; + BYTE ExternalConnectorType; /* SMBIOS_PORT_CONNECTOR_TYPE_* */ +#define SMBIOS_PORT_TYPE_NONE ((BYTE)00h) +#define SMBIOS_PORT_TYPE_PARALLEL_PORT_XT_AT_COMPATIBLE ((BYTE)01h) +#define SMBIOS_PORT_TYPE_PARALLEL_PORT_PS_2 ((BYTE)02h) +#define SMBIOS_PORT_TYPE_PARALLEL_PORT_ECP ((BYTE)03h) +#define SMBIOS_PORT_TYPE_PARALLEL_PORT_EPP ((BYTE)04h) +#define SMBIOS_PORT_TYPE_PARALLEL_PORT_ECP_EPP ((BYTE)05h) +#define SMBIOS_PORT_TYPE_SERIAL_PORT_XT_AT_COMPATIBLE ((BYTE)06h) +#define SMBIOS_PORT_TYPE_SERIAL_PORT_16450_COMPATIBLE ((BYTE)07h) +#define SMBIOS_PORT_TYPE_SERIAL_PORT_16550_COMPATIBLE ((BYTE)08h) +#define SMBIOS_PORT_TYPE_SERIAL_PORT_16550A_COMPATIBLE ((BYTE)09h) +#define SMBIOS_PORT_TYPE_SCSI_PORT ((BYTE)0Ah) +#define SMBIOS_PORT_TYPE_MIDI_PORT ((BYTE)0Bh) +#define SMBIOS_PORT_TYPE_JOY_STICK_PORT ((BYTE)0Ch) +#define SMBIOS_PORT_TYPE_KEYBOARD_PORT ((BYTE)0Dh) +#define SMBIOS_PORT_TYPE_MOUSE_PORT ((BYTE)0Eh) +#define SMBIOS_PORT_TYPE_SSA_SCSI ((BYTE)0Fh) +#define SMBIOS_PORT_TYPE_USB ((BYTE)10h) +#define SMBIOS_PORT_TYPE_FIRE_WIRE ((BYTE)11h) +#define SMBIOS_PORT_TYPE_PCMCIA_TYPE_1 ((BYTE)12h) +#define SMBIOS_PORT_TYPE_PCMCIA_TYPE_2 ((BYTE)13h) +#define SMBIOS_PORT_TYPE_PCMCIA_TYPE_3 ((BYTE)14h) +#define SMBIOS_PORT_TYPE_CARD_BUS ((BYTE)15h) +#define SMBIOS_PORT_TYPE_ACCESS_BUS_PORT ((BYTE)16h) +#define SMBIOS_PORT_TYPE_SCSI_2 ((BYTE)17h) +#define SMBIOS_PORT_TYPE_SCSI_WIDE ((BYTE)18h) +#define SMBIOS_PORT_TYPE_PC_98 ((BYTE)19h) +#define SMBIOS_PORT_TYPE_PC_98_Hireso ((BYTE)1Ah) +#define SMBIOS_PORT_TYPE_PC_H98 ((BYTE)1Bh) +#define SMBIOS_PORT_TYPE_VIDEO_PORT ((BYTE)1Ch) +#define SMBIOS_PORT_TYPE_AUDIO_PORT ((BYTE)1Dh) +#define SMBIOS_PORT_TYPE_MODEM_PORT ((BYTE)1Eh) +#define SMBIOS_PORT_TYPE_NETWORK_PORT ((BYTE)1Fh) +#define SMBIOS_PORT_TYPE_SATA ((BYTE)20h) +#define SMBIOS_PORT_TYPE_SAS ((BYTE)21h) +#define SMBIOS_PORT_TYPE_MFDP ((BYTE)22h) +#define SMBIOS_PORT_TYPE_THUNDERBOLT ((BYTE)23h) +#define SMBIOS_PORT_TYPE_8251_COMPATIBLE ((BYTE)A0h) +#define SMBIOS_PORT_TYPE_8251_FIFO_COMPATIBLE ((BYTE)A1h) +#define SMBIOS_PORT_TYPE_OTHER ((BYTE)FFh) + BYTE PortType; /* SMBIOS_PORT_TYPE_* */ + } TYPE_8_PORT_CONNECTOR_INFO; + struct + { + BYTE Designation; +#define SMBIOS_SYSTEM_SLOTS_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_ISA ((BYTE)03h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_MCA ((BYTE)04h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_EISA ((BYTE)05h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI ((BYTE)06h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PC_CARD ((BYTE)07h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_VL_VESA ((BYTE)08h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PROPRIETARY ((BYTE)09h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PROCESSOR_CARD_SLOT ((BYTE)0Ah) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PROPRIETARY_MEMORY_CARD_SLOT ((BYTE)0Bh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_IO_RISER_CARD_SLOT ((BYTE)0Ch) +#define SMBIOS_SYSTEM_SLOTS_TYPE_NUBUS ((BYTE)0Dh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_66MHZ_CAPABLE ((BYTE)0Eh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_AGP ((BYTE)0Fh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_AGP_2X ((BYTE)10h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_AGP_4X ((BYTE)11h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_X ((BYTE)12h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_AGP_8X ((BYTE)13h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_1_DP ((BYTE)14h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_1_SD ((BYTE)15h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_2 ((BYTE)16h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_3 ((BYTE)17h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_MXM_TYPE_I ((BYTE)18h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_MXM_TYPE_II ((BYTE)19h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_MXM_TYPE_III_STANDARD ((BYTE)1Ah) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_MXM_TYPE_III_HE ((BYTE)1Bh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_MXM_TYPE_IV ((BYTE)1Ch) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_MXM_3_TYPE_A ((BYTE)1Dh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_M2_SOCKET_MXM_3_TYPE_B ((BYTE)1Eh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_2_SFF_8639 ((BYTE)1Fh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_3_SFF_8639 ((BYTE)20h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_MINI_52_PIN_WITH_BOTTOM_SIDE_KEEP_OUTS ((BYTE)21h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_MINI_52_PIN_WITHOUT_BOTTOM_SIDE_KEEP_OUTS ((BYTE)22h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_MINI_76_PIN ((BYTE)23h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_4_SFF_8639 ((BYTE)24h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_5_SFF_8639 ((BYTE)25h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_OCP_NIC_3_SFF ((BYTE)26h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_OCP_NIC_3_LFF ((BYTE)27h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_OCP_NIC_PRIOR_TO_3 ((BYTE)28h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_CXL_FLEXBUS_1 ((BYTE)30h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PC_98_C20 ((BYTE)A0h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PC_98_C24 ((BYTE)A1h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PC_98_E ((BYTE)A2h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PC_98_LOCAL_BUS ((BYTE)A3h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PC_98_CARD ((BYTE)A4h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS ((BYTE)A5h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_X1 ((BYTE)A6h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_X2 ((BYTE)A7h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_X4 ((BYTE)A8h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_X8 ((BYTE)A9h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_X16 ((BYTE)AAh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_2 ((BYTE)ABh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_2_X1 ((BYTE)ACh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_2_X2 ((BYTE)ADh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_2_X4 ((BYTE)AEh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_2_X8 ((BYTE)AFh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_2_X16 ((BYTE)B0h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_3 ((BYTE)B1h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_3_X1 ((BYTE)B2h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_3_X2 ((BYTE)B3h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_3_X4 ((BYTE)B4h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_3_X8 ((BYTE)B5h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_3_X16 ((BYTE)B6h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_4 ((BYTE)B8h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_4_X1 ((BYTE)B9h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_4_X2 ((BYTE)BAh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_4_X4 ((BYTE)BBh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_4_X8 ((BYTE)BCh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_4_X16 ((BYTE)BDh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_5 ((BYTE)BEh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_5_X1 ((BYTE)BFh) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_5_X2 ((BYTE)C0h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_5_X4 ((BYTE)C1h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_5_X8 ((BYTE)C2h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_5_X16 ((BYTE)C3h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_PCI_EXPRESS_GEN_6_AND_BEYOND ((BYTE)C4h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_EDSFF_E1S_E1L ((BYTE)C5h) +#define SMBIOS_SYSTEM_SLOTS_TYPE_EDSFF_E3S_E3L ((BYTE)C6h) + BYTE Type; /* SMBIOS_SYSTEM_SLOTS_TYPE_* */ +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_OTHER ((BYTE)01h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_UNKNOWN ((BYTE)02h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_8_BIT ((BYTE)03h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_16_BIT ((BYTE)04h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_32_BIT ((BYTE)05h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_64_BIT ((BYTE)06h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_128_BIT ((BYTE)07h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_1X ((BYTE)08h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_2X ((BYTE)09h) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_4X ((BYTE)0Ah) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_8X ((BYTE)0Bh) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_12X ((BYTE)0Ch) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_16X ((BYTE)0Dh) +#define SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_32X ((BYTE)0Eh) + BYTE SlotDataBusWidth; /* SMBIOS_SYSTEM_SLOTS_DATA_BUS_WIDTH_* */ +#define SMBIOS_SYSTEM_SLOTS_CURRENT_USAGE_OTHER ((BYTE)01h) +#define SMBIOS_SYSTEM_SLOTS_CURRENT_USAGE_UNKNOWN ((BYTE)02h) +#define SMBIOS_SYSTEM_SLOTS_CURRENT_USAGE_AVAILABLE ((BYTE)03h) +#define SMBIOS_SYSTEM_SLOTS_CURRENT_USAGE_IN_USE ((BYTE)04h) +#define SMBIOS_SYSTEM_SLOTS_CURRENT_USAGE_UNAVAILABLE ((BYTE)05h) + BYTE CurrentUsage; /* SMBIOS_SYSTEM_SLOTS_CURRENT_USAGE_* */ +#define SMBIOS_SYSTEM_SLOTS_LENGTH_OTHER ((BYTE)01h) +#define SMBIOS_SYSTEM_SLOTS_LENGTH_UNKNOWN ((BYTE)02h) +#define SMBIOS_SYSTEM_SLOTS_LENGTH_SHORT ((BYTE)03h) +#define SMBIOS_SYSTEM_SLOTS_LENGTH_LONG ((BYTE)04h) +#define SMBIOS_SYSTEM_SLOTS_LENGTH_2DOT5_INCH_DRIVE_FORM_FACTOR ((BYTE)05h) +#define SMBIOS_SYSTEM_SLOTS_LENGTH_3DOT5_INCH_DRIVE_FORM_FACTOR ((BYTE)06h) + BYTE Length; /* SMBIOS_SYSTEM_SLOTS_LENGTH_* */ + WORD ID; + union + { + BYTE Characteristics1; + struct + { + BYTE CharacteristicsUnknown : 1; + BYTE Provides5Dot0Volts : 1; + BYTE Provides3Dot3Volts : 1; + BYTE OpeningSharedWithAnother : 1; + BYTE PCCardSupportsPCCard16 : 1; + BYTE PCCardSupportsCardBus : 1; + BYTE PCCardSupportsZoomVideo : 1; + BYTE PCCardSupportsModemRingResume : 1; + }; + }; + union + { + BYTE Characteristics2; + struct + { + BYTE PCISupportsPMESignal : 1; + BYTE SupportsHotPlugDevices : 1; + BYTE PCISupportsSMBusSignal : 1; + BYTE PCIeSupportsBifurcation : 1; + BYTE SupportsAsyncOrSurpriseRemoval : 1; + BYTE FlexbusCXL1Capable : 1; + BYTE FlexbusCXL2Capable : 1; + BYTE FlexbusCXL3Capable : 1; + }; + }; + WORD SegmentGroupNumber; + BYTE BusNumber; + union + { + BYTE DeviceFunctionNumber; + struct + { + BYTE FunctionNumber : 3; + BYTE DeviceNumber : 5; + }; + }; + BYTE DataBusWidth; + BYTE PeerGroupingCount; + _Field_size_bytes_(5 * PeerGroupingCount) BYTE PeerGroups[]; + /* BYTE Information; */ + /* BYTE PhysicalWidth; */ + /* WORD Pitch; */ + /* BYTE Height; */ + } TYPE_9_SYSTEM_SLOTS; + struct + { +#define SMBIOS_ONBOARD_DEVICES_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_VIDEO ((BYTE)03h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_SCSI_CONTROLLER ((BYTE)04h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_ETHERNET ((BYTE)05h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_TOKEN_RING ((BYTE)06h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_SOUND ((BYTE)07h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_PATA_CONTROLLER ((BYTE)08h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_SATA_CONTROLLER ((BYTE)09h) +#define SMBIOS_ONBOARD_DEVICES_TYPE_SAS_CONTROLLER ((BYTE)0Ah) + _Field_size_((Header.Length - sizeof(Header)) / 2) BYTE Type[]; /* SMBIOS_ONBOARD_DEVICES_TYPE_* */ + /* _Field_size_((Header.Length - sizeof(Header)) / 2) BYTE DescriptionString[]; */ + } TYPE_10_OBSOLETE_ON_BOARD_DEVICES_INFO; + struct + { + BYTE Count; + } TYPE_11_OEM_STRINGS; + struct + { + BYTE Count; + } TYPE_12_SYSTEM_CONFIGURATION_OPTIONS; + struct + { + BYTE InstallableLanguages; + union + { + BYTE Flags; + struct + { + BYTE AbbreviatedFormat : 1; + BYTE Reserved0 : 7; + }; + }; + BYTE Reserved1[15]; + BYTE CurrentLanguage; + } TYPE_13_BIOS_LANGUAGE_INFO; + struct + { + BYTE GroupName; + BYTE ItemType1; + WORD ItemHandle1; + /* ItemType2, ItemHandle2, ..., ItemTypeN, ItemHandleN */ + } TYPE_14_GROUP_ASSOCIATIONS; + struct + { +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_OTHER ((BYTE)01h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_UNKNOWN ((BYTE)02h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_SYSTEM_BOARD_OR_MOTHERBOARD ((BYTE)03h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_ISA_ADD_ON_CARD ((BYTE)04h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_EISA_ADD_ON_CARD ((BYTE)05h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_PCI_ADD_ON_CARD ((BYTE)06h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_MCA_ADD_ON_CARD ((BYTE)07h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_PCMCIA_ADD_ON_CARD ((BYTE)08h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_PROPRIETARY_ADD_ON_CARD ((BYTE)09h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_NUBUS ((BYTE)0Ah) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_PC_98_C20_ADD_ON_CARD ((BYTE)A0h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_PC_98_C24_ADD_ON_CARD ((BYTE)A1h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_PC_98_E_ADD_ON_CARD ((BYTE)A2h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_PC_98_LOCAL_BUS_ADD_ON_CARD ((BYTE)A3h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_CXL_ADD_ON_CARD ((BYTE)A4h) + BYTE Location; /* SMBIOS_PHYSICAL_MEMORY_ARRAY_LOCATION_* */ +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_USE_OTHER ((BYTE)01h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_USE_UNKNOWN ((BYTE)02h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_USE_SYSTEM_MEMORY ((BYTE)03h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_USE_VIDEO_MEMORY ((BYTE)04h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_USE_FLASH_MEMORY ((BYTE)05h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_USE_NON_VOLATILE_RAM ((BYTE)06h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_USE_CACHE_MEMORY ((BYTE)07h) + BYTE Use; /* SMBIOS_PHYSICAL_MEMORY_ARRAY_USE_* */ +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_ERROR_CORRECTION_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_ERROR_CORRECTION_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_ERROR_CORRECTION_TYPE_NONE ((BYTE)03h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_ERROR_CORRECTION_TYPE_PARITY ((BYTE)04h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_ERROR_CORRECTION_TYPE_SINGLE_BIT_ECC ((BYTE)05h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_ERROR_CORRECTION_TYPE_MULTI_BIT_ECC ((BYTE)06h) +#define SMBIOS_PHYSICAL_MEMORY_ARRAY_ERROR_CORRECTION_TYPE_CRC ((BYTE)07h) + BYTE ErrorCorrection; /* SMBIOS_PHYSICAL_MEMORY_ARRAY_ERROR_CORRECTION_TYPE_* */ + DWORD MaximumCapacity; + WORD ErrorInformationHandle; + WORD NumberOfMemoryDevices; + QWORD ExtendedMaximumCapacity; + } TYPE_16_PHYSICAL_MEMORY_ARRAY; + struct + { + WORD PhysicalMemoryArrayHandle; + WORD ErrorInformationHandle; + WORD TotalWidth; + WORD DataWidth; + WORD Size; +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_OTHER ((BYTE)01h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_UNKNOWN ((BYTE)02h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_SIMM ((BYTE)03h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_SIP ((BYTE)04h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_CHIP ((BYTE)05h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_DIP ((BYTE)06h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_ZIP ((BYTE)07h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_PROPRIETARY_CARD ((BYTE)08h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_DIMM ((BYTE)09h) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_TSOP ((BYTE)0Ah) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_ROW_OF_CHIPS ((BYTE)0Bh) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_RIMM ((BYTE)0Ch) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_SODIMM ((BYTE)0Dh) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_SRIMM ((BYTE)0Eh) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_FB_DIMM ((BYTE)0Fh) +#define SMBIOS_MEMORY_DEVICE_FORM_FACTOR_DIE ((BYTE)10h) + BYTE FormFactor; /* SMBIOS_MEMORY_DEVICE_FORM_FACTOR_* */ + BYTE DeviceSet; + BYTE DeviceLocator; + BYTE BankLocator; +#define SMBIOS_MEMORY_DEVICE_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_MEMORY_DEVICE_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_MEMORY_DEVICE_TYPE_DRAM ((BYTE)03h) +#define SMBIOS_MEMORY_DEVICE_TYPE_EDRAM ((BYTE)04h) +#define SMBIOS_MEMORY_DEVICE_TYPE_VRAM ((BYTE)05h) +#define SMBIOS_MEMORY_DEVICE_TYPE_SRAM ((BYTE)06h) +#define SMBIOS_MEMORY_DEVICE_TYPE_RAM ((BYTE)07h) +#define SMBIOS_MEMORY_DEVICE_TYPE_ROM ((BYTE)08h) +#define SMBIOS_MEMORY_DEVICE_TYPE_FLASH ((BYTE)09h) +#define SMBIOS_MEMORY_DEVICE_TYPE_EEPROM ((BYTE)0Ah) +#define SMBIOS_MEMORY_DEVICE_TYPE_FEPROM ((BYTE)0Bh) +#define SMBIOS_MEMORY_DEVICE_TYPE_EPROM ((BYTE)0Ch) +#define SMBIOS_MEMORY_DEVICE_TYPE_CDRAM ((BYTE)0Dh) +#define SMBIOS_MEMORY_DEVICE_TYPE_3DRAM ((BYTE)0Eh) +#define SMBIOS_MEMORY_DEVICE_TYPE_SDRAM ((BYTE)0Fh) +#define SMBIOS_MEMORY_DEVICE_TYPE_SGRAM ((BYTE)10h) +#define SMBIOS_MEMORY_DEVICE_TYPE_RDRAM ((BYTE)11h) +#define SMBIOS_MEMORY_DEVICE_TYPE_DDR ((BYTE)12h) +#define SMBIOS_MEMORY_DEVICE_TYPE_DDR2 ((BYTE)13h) +#define SMBIOS_MEMORY_DEVICE_TYPE_DDR2_FB_DIMM ((BYTE)14h) +#define SMBIOS_MEMORY_DEVICE_TYPE_DDR3 ((BYTE)18h) +#define SMBIOS_MEMORY_DEVICE_TYPE_FBD2 ((BYTE)19h) +#define SMBIOS_MEMORY_DEVICE_TYPE_DDR4 ((BYTE)1Ah) +#define SMBIOS_MEMORY_DEVICE_TYPE_LPDDR ((BYTE)1Bh) +#define SMBIOS_MEMORY_DEVICE_TYPE_LPDDR2 ((BYTE)1Ch) +#define SMBIOS_MEMORY_DEVICE_TYPE_LPDDR3 ((BYTE)1Dh) +#define SMBIOS_MEMORY_DEVICE_TYPE_LPDDR4 ((BYTE)1Eh) +#define SMBIOS_MEMORY_DEVICE_TYPE_LOGICAL_NON_VOLATILE_DEVICE ((BYTE)1Fh) +#define SMBIOS_MEMORY_DEVICE_TYPE_HBM ((BYTE)20h) +#define SMBIOS_MEMORY_DEVICE_TYPE_HBM2 ((BYTE)21h) +#define SMBIOS_MEMORY_DEVICE_TYPE_DDR5 ((BYTE)22h) +#define SMBIOS_MEMORY_DEVICE_TYPE_LPDDR5 ((BYTE)23h) +#define SMBIOS_MEMORY_DEVICE_TYPE_HBM3 ((BYTE)24h) + BYTE Type; /* SMBIOS_MEMORY_DEVICE_TYPE_* */ + union + { + WORD TypeDetail; + struct + { + WORD Reserved0 : 1; + WORD TypeOther : 1; + WORD TypeUnknow : 1; + WORD FastPaged : 1; + WORD StaticColumn : 1; + WORD PseudoStatic : 1; + WORD RAMBUS : 1; + WORD Synchronous : 1; + WORD CMOS : 1; + WORD EDO : 1; + WORD WindowDRAM : 1; + WORD CacheDRAM : 1; + WORD NonVolatile : 1; + WORD Registered : 1; + WORD Unbuffered : 1; + WORD LRDIMM : 1; + }; + }; + WORD Speed; + BYTE Manufacturer; + BYTE SerialNumber; + BYTE AssetTag; + BYTE PartNumber; + union + { + BYTE Attributes; + struct + { + BYTE Rank : 4; + BYTE Reserved1 : 4; + }; + }; + DWORD ExtendedSize; + WORD ConfiguredMemorySpeed; + WORD MinimumVoltage; + WORD MaximumVoltage; + WORD ConfiguredVoltage; +#define SMBIOS_MEMORY_DEVICE_TECHNOLOGY_OTHER ((BYTE)01h) +#define SMBIOS_MEMORY_DEVICE_TECHNOLOGY_UNKNOWN ((BYTE)02h) +#define SMBIOS_MEMORY_DEVICE_TECHNOLOGY_DRAM ((BYTE)03h) +#define SMBIOS_MEMORY_DEVICE_TECHNOLOGY_NVDIMM_N ((BYTE)04h) +#define SMBIOS_MEMORY_DEVICE_TECHNOLOGY_NVDIMM_F ((BYTE)05h) +#define SMBIOS_MEMORY_DEVICE_TECHNOLOGY_NVDIMM_P ((BYTE)06h) +#define SMBIOS_MEMORY_DEVICE_TECHNOLOGY_INTEL_OPTANE_PERSISTENT_MEMORY ((BYTE)07h) + BYTE Technology; /* SMBIOS_MEMORY_DEVICE_TECHNOLOGY_* */ + union + { + WORD OperatingModeCapability; + struct + { + WORD Reserved2 : 1; + WORD OperatingModeCapabilityOther : 1; + WORD OperatingModeCapabilityUnknown : 1; + WORD VolatileMemory : 1; + WORD ByteAccessiblePersistentMemory : 1; + WORD BlockAccessiblePersistentMemory : 1; + WORD Reserved3 : 10; + }; + }; + BYTE FirmwareVersion; + WORD ModuleManufacturerID; + WORD ModuleProductID; + WORD SubsystemControllerManufacturerID; + QWORD NonVolatileSize; + QWORD VolatileSize; + QWORD CacheSize; + QWORD LogicalSize; + DWORD ExtendedSpeed; + DWORD ExtendedConfiguredSpeed; + WORD PMIC0ManufacturerID; + WORD PMIC0RevisionNumber; + WORD RCDManufacturerID; + WORD RCDRevisionNumber; + } TYPE_17_MEMORY_DEVICE; + struct + { + DWORD StartingAddress; + DWORD EndingAddress; + WORD Handle; + BYTE PartitionWidth; + QWORD ExtendedStartingAddress; + QWORD ExtendedEndingAddress; + } TYPE_19_MEMORY_ARRAY_MAPPED_ADDRESS; + struct + { + DWORD StartingAddress; + DWORD EndingAddress; + WORD Handle; + WORD MemoryArrayMappedAddressHandle; + BYTE PartitionRowPosition; + BYTE InterleavePosition; + BYTE InterleavedDataDepth; + QWORD ExtendedStartingAddress; + QWORD ExtendedEndingAddress; + } TYPE_20_MEMORY_DEVICE_MAPPED_ADDRESS; + struct + { + union + { + BYTE Capabilities; + struct + { + BYTE Status : 1; +#define SMBIOS_SYSTEM_RESET_BOOT_OPTION_RESERVED 00b +#define SMBIOS_SYSTEM_RESET_BOOT_OPTION_OPERATING_SYSTEM 01b +#define SMBIOS_SYSTEM_RESET_BOOT_OPTION_SYSTEM_UTILITIES 10b +#define SMBIOS_SYSTEM_RESET_BOOT_OPTION_DO_NOT_REBOOT 11b + BYTE BootOption : 2; /* SMBIOS_SYSTEM_RESET_BOOT_OPTION_* */ + BYTE BootOptionOnLimit : 2; /* SMBIOS_SYSTEM_RESET_BOOT_OPTION_* */ + BYTE SystemContainsAWatchdogTimer : 1; + BYTE Reserved : 2; + }; + }; + WORD ResetCount; + WORD ResetLimit; + WORD TimerInterval; + WORD Timeout; + } TYPE_23_SYSTEM_RESET; + struct + { + union + { + BYTE Settings; +#define SMBIOS_HARDWARE_SECURITY_SETTINGS_STATUS_DISABLED 00b +#define SMBIOS_HARDWARE_SECURITY_SETTINGS_STATUS_ENABLED 01b +#define SMBIOS_HARDWARE_SECURITY_SETTINGS_STATUS_NOT_IMPLEMENTED 10b +#define SMBIOS_HARDWARE_SECURITY_SETTINGS_STATUS_UNKNOWN 11b + struct + { + /* SMBIOS_HARDWARE_SECURITY_SETTINGS_STATUS_* */ + BYTE FrontPanelResetStatus : 2; + BYTE AdministratorPasswordStatus : 2; + BYTE KeyboardPasswordStatus : 2; + BYTE PowerOnPasswordStatus : 2; + }; + }; + } TYPE_24_HARDWARE_SECURITY; + struct + { + BYTE NextScheduledPowerOnMonth; + BYTE NextScheduledPowerOnDayOfMonth; + BYTE NextScheduledPowerOnHour; + BYTE NextScheduledPowerOnMinute; + BYTE NextScheduledPowerOnSecond; + } TYPE_25_SYSTEM_POWER_CONTROLS; + struct + { + BYTE Description; + union + { + BYTE LocationAndStatus; + struct + { +#define SMBIOS_VOLTAGE_PROBE_LOCATION_OTHER 00001b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_UNKNOWN 00010b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_PROCESSOR 00011b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_DISK 00100b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_PERIPHERAL_BAY 00101b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_SYSTEM_MANAGEMENT_MODULE 00110b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_MOTHERBOARD 00111b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_MEMORY_MODULE 01000b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_PROCESSOR_MODULE 01001b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_POWER_UNIT 01010b +#define SMBIOS_VOLTAGE_PROBE_LOCATION_ADD_IN_CARD 01011b + BYTE Location : 5; /* SMBIOS_VOLTAGE_PROBE_LOCATION_* */ +#define SMBIOS_VOLTAGE_PROBE_STATUS_OTHER 001b +#define SMBIOS_VOLTAGE_PROBE_STATUS_UNKNOWN 010b +#define SMBIOS_VOLTAGE_PROBE_STATUS_OK 011b +#define SMBIOS_VOLTAGE_PROBE_STATUS_NON_CRITICAL 100b +#define SMBIOS_VOLTAGE_PROBE_STATUS_CRITICAL 101b +#define SMBIOS_VOLTAGE_PROBE_STATUS_NON_RECOVERABLE 110b + BYTE Status : 3; /* SMBIOS_VOLTAGE_PROBE_STATUS_* */ + }; + }; + } TYPE_26_VOLTAGE_PROBE; + struct + { + WORD TemperatureProbeHandle; + union + { + BYTE DeviceTypeAndStatus; + struct + { +#define SMBIOS_COOLING_DEVICE_TYPE_FAN 00011b +#define SMBIOS_COOLING_DEVICE_TYPE_CENTRIFUGAL_BLOWER 00100b +#define SMBIOS_COOLING_DEVICE_TYPE_CHIP_FAN 00101b +#define SMBIOS_COOLING_DEVICE_TYPE_CABINET_FAN 00110b +#define SMBIOS_COOLING_DEVICE_TYPE_POWER_SUPPLY_FAN 00111b +#define SMBIOS_COOLING_DEVICE_TYPE_HEAT_PIPE 01000b +#define SMBIOS_COOLING_DEVICE_TYPE_INTEGRATED_REFRIGERATION 01001b +#define SMBIOS_COOLING_DEVICE_TYPE_ACTIVE_COOLING 10000b +#define SMBIOS_COOLING_DEVICE_TYPE_PASSIVE_COOLING 10001b + BYTE Type : 5; /* SMBIOS_COOLING_DEVICE_TYPE_* */ +#define SMBIOS_COOLING_DEVICE_STATUS_OTHER 001b +#define SMBIOS_COOLING_DEVICE_STATUS_UNKNOWN 010b +#define SMBIOS_COOLING_DEVICE_STATUS_OK 011b +#define SMBIOS_COOLING_DEVICE_STATUS_NON_CRITICAL 100b +#define SMBIOS_COOLING_DEVICE_STATUS_CRITICAL 101b +#define SMBIOS_COOLING_DEVICE_STATUS_NON_RECOVERABLE 110b + BYTE Status : 3; /* SMBIOS_COOLING_DEVICE_STATUS_* */ + }; + }; + BYTE CoolingUnitGroup; + DWORD OEMDefined; + WORD NominalSpeed; + BYTE Description; + } TYPE_27_COOLING_DEVICE; + struct + { + BYTE Description; + union + { + BYTE LocationAndStatus; + struct + { +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_OTHER 00001b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_UNKNOWN 00010b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_PROCESSOR 00011b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_DISK 00100b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_PERIPHERAL_BAY 00101b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_SYSTEM_MANAGEMENT_MODULE 00110b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_MOTHERBOARD 00111b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_MEMORY_MODULE 01000b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_PROCESSOR_MODULE 01001b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_POWER_UNIT 01010b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_ADD_IN_CARD 01011b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_FRONT_PANEL_BOARD 01100b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_BACK_PANEL_BOARD 01101b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_POWER_SYSTEM_BOARD 01110b +#define SMBIOS_TEMPERATURE_PROBE_LOCATION_DRIVE_BACK_PLANE 01111b + BYTE Location : 5; /* SMBIOS_TEMPERATURE_PROBE_LOCATION_* */ +#define SMBIOS_TEMPERATURE_PROBE_STATUS_OTHER 001b +#define SMBIOS_TEMPERATURE_PROBE_STATUS_UNKNOWN 010b +#define SMBIOS_TEMPERATURE_PROBE_STATUS_OK 011b +#define SMBIOS_TEMPERATURE_PROBE_STATUS_NON_CRITICAL 100b +#define SMBIOS_TEMPERATURE_PROBE_STATUS_CRITICAL 101b +#define SMBIOS_TEMPERATURE_PROBE_STATUS_NON_RECOVERABLE 110b + BYTE Status : 3; /* SMBIOS_TEMPERATURE_PROBE_STATUS_* */ + }; + }; + WORD MaximumValue; + WORD MinimumValue; + WORD Resolution; + WORD Tolerance; + WORD Accuracy; + DWORD OEMDefined; + WORD NominalValue; + } TYPE_28_TEMPERATURE_PROBE; + struct + { + BYTE Description; + union + { + BYTE LocationAndStatus; + struct + { +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_OTHER 00001b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_UNKNOWN 00010b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_PROCESSOR 00011b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_DISK 00100b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_PERIPHERAL_BAY 00101b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_SYSTEM_MANAGEMENT_MODULE 00110b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_MOTHERBOARD 00111b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_MEMORY_MODULE 01000b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_PROCESSOR_MODULE 01001b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_POWER_UNIT 01010b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_ADD_IN_CARD 01011b + BYTE Location : 5; /* SMBIOS_ELECTRICAL_CURRENT_PROBE_LOCATION_* */ +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_STATUS_OTHER 001b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_STATUS_UNKNOWN 010b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_STATUS_OK 011b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_STATUS_NON_CRITICAL 100b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_STATUS_CRITICAL 101b +#define SMBIOS_ELECTRICAL_CURRENT_PROBE_STATUS_NON_RECOVERABLE 110b + BYTE Status : 3; /* SMBIOS_ELECTRICAL_CURRENT_PROBE_STATUS_* */ + }; + }; + WORD MaximumValue; + WORD MinimumValue; + WORD Resolution; + WORD Tolerance; + WORD Accuracy; + DWORD OEMDefined; + WORD NominalValue; + } TYPE_29_ELECTRICAL_CURRENT_PROBE; + struct + { + BYTE ManufacturerName; + union + { + BYTE Connections; + struct + { + BYTE InboundConnectionEnabled : 1; + BYTE OutboundConnectionEnabled : 1; + BYTE Reserved : 6; + }; + }; + } TYPE_30_OUT_OF_BAND_REMOTE_ACCESS; + struct + { + BYTE Reserved[6]; + BYTE BootStatus[10]; + } TYPE_32_SYSTEM_BOOT_INFORMATION; + struct + { + BYTE Description; +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_NATIONAL_SEMICONDUCTOR_LM75 ((BYTE)03h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_NATIONAL_SEMICONDUCTOR_LM78 ((BYTE)04h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_NATIONAL_SEMICONDUCTOR_LM79 ((BYTE)05h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_NATIONAL_SEMICONDUCTOR_LM80 ((BYTE)06h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_NATIONAL_SEMICONDUCTOR_LM81 ((BYTE)07h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_ANALOG_DEVICES_ADM9240 ((BYTE)08h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_DALLAS_SEMICONDUCTOR_DS1780 ((BYTE)09h) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_MAXIM_1617 ((BYTE)0Ah) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_GENESYS_GL518SM ((BYTE)0Bh) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_WINBOND_W83781D ((BYTE)0Ch) +#define SMBIOS_MANAGEMENT_DEVICE_TYPE_HOLTEK_HT82H791 ((BYTE)0Dh) + BYTE Type; /* SMBIOS_MANAGEMENT_DEVICE_TYPE_* */ + DWORD Address; +#define SMBIOS_MANAGEMENT_DEVICE_ADDRESS_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_MANAGEMENT_DEVICE_ADDRESS_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_MANAGEMENT_DEVICE_ADDRESS_TYPE_IO_PORT ((BYTE)03h) +#define SMBIOS_MANAGEMENT_DEVICE_ADDRESS_TYPE_MEMORY ((BYTE)04h) +#define SMBIOS_MANAGEMENT_DEVICE_ADDRESS_TYPE_SMBUS ((BYTE)05h) + BYTE AddressType; /* SMBIOS_MANAGEMENT_DEVICE_ADDRESS_TYPE_* */ + } TYPE_34_MANAGEMENT_DEVICE; + struct + { + BYTE Description; + WORD ManagementDeviceHandle; + WORD ComponentHandle; + WORD ThresholdHandle; + } TYPE_35_MANAGEMENT_DEVICE_COMPONENT; + struct + { + BYTE PowerUnitGroup; + BYTE Location; + BYTE DeviceName; + BYTE Manufacturer; + BYTE SerialNumber; + BYTE AssetTagNumber; + BYTE ModelPartNumber; + BYTE RevisionLevel; + WORD MaxPowerCapacity; + union + { + WORD Characteristics; + struct + { + WORD HotReplaceable : 1; + WORD Present : 1; + WORD UnpluggedFromTheWall : 1; +#define SMBIOS_SYSTEM_POWER_SUPPLY_INPUT_VOLTAGE_RANGE_SWITCHING_OTHER 0001b +#define SMBIOS_SYSTEM_POWER_SUPPLY_INPUT_VOLTAGE_RANGE_SWITCHING_UNKNOWN 0010b +#define SMBIOS_SYSTEM_POWER_SUPPLY_INPUT_VOLTAGE_RANGE_SWITCHING_MANUAL 0011b +#define SMBIOS_SYSTEM_POWER_SUPPLY_INPUT_VOLTAGE_RANGE_SWITCHING_AUTO_SWITCH 0100b +#define SMBIOS_SYSTEM_POWER_SUPPLY_INPUT_VOLTAGE_RANGE_SWITCHING_WIDE_RANGE 0101b +#define SMBIOS_SYSTEM_POWER_SUPPLY_INPUT_VOLTAGE_RANGE_SWITCHING_NOT_APPLICABLE 0110b + WORD DMTFInputVoltageRangeSwitching : 4; /* SMBIOS_SYSTEM_POWER_SUPPLY_INPUT_VOLTAGE_RANGE_SWITCHING_* */ +#define SMBIOS_SYSTEM_POWER_SUPPLY_STATUS_OTHER 001b +#define SMBIOS_SYSTEM_POWER_SUPPLY_STATUS_UNKNOWN 010b +#define SMBIOS_SYSTEM_POWER_SUPPLY_STATUS_OK 011b +#define SMBIOS_SYSTEM_POWER_SUPPLY_STATUS_NON_CRITICAL 100b +#define SMBIOS_SYSTEM_POWER_SUPPLY_STATUS_CRITICAL 101b + WORD Status : 3; /* SMBIOS_SYSTEM_POWER_SUPPLY_STATUS_* */ +#define SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_OTHER 0001b +#define SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_UNKNOWN 0010b +#define SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_LINEAR 0011b +#define SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_SWITCHING 0100b +#define SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_BATTERY 0101b +#define SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_UPS 0110b +#define SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_CONVERTER 0111b +#define SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_REGULATOR 1000b + WORD DMTFPowerSupplyType : 4; /* SMBIOS_SYSTEM_POWER_SUPPLY_TYPE_* */ + WORD Reserved : 2; + }; + }; + } TYPE_39_SYSTEM_POWER_SUPPLY; + struct + { + BYTE ReferenceDesignation; + union + { + BYTE Type; + struct + { +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_OTHER ((BYTE)01h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_UNKNOWN ((BYTE)02h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_VIDEO ((BYTE)03h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_SCSI_CONTROLLER ((BYTE)04h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_ETHERNET ((BYTE)05h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_TOKEN_RING ((BYTE)06h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_SOUND ((BYTE)07h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_PATA_CONTROLLER ((BYTE)08h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_SATA_CONTROLLER ((BYTE)09h) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_SAS_CONTROLLER ((BYTE)0Ah) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_WIRELESS_LAN ((BYTE)0Bh) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_BLUETOOTH ((BYTE)0Ch) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_WWAN ((BYTE)0Dh) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_EMMC ((BYTE)0Eh) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_NVME_CONTROLLER ((BYTE)0Fh) +#define SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_UFS_CONTROLLER ((BYTE)10h) + BYTE TypeOfDevice : 7; /* SMBIOS_ONBOARD_DEVICES_EXTENDED_TYPE_* */ + BYTE Status : 1; + }; + }; + BYTE TypeInstance; + WORD SegmentGroupNumber; + BYTE BusNumber; + union + { + BYTE DeviceFunctionNumber; + struct + { + BYTE FunctionNumber : 3; + BYTE DeviceNumber : 5; + }; + }; + } TYPE_41_ONBOARD_DEVICES_EXTENDED_INFORMATION; + struct + { + BYTE VendorID[4]; + BYTE MajorSpecVersion; + BYTE MinorSpecVersion; + DWORD FirmwareVersion1; + DWORD FirmwareVersion2; + BYTE Description; + union + { + QWORD Characteristics; + struct + { + QWORD Reserved0 : 1; + QWORD Reserved1 : 1; + QWORD NotSupported : 1; + QWORD FamilyConfigurableViaFirmwareUpdate : 1; + QWORD FamilyConfigurableViaPlatformSoftwareSupport : 1; + QWORD FamilyConfigurableViaOEMProprietaryMechanism : 1; + QWORD Reserved2 : 58; + }; + }; + DWORD OEMDefined; + } TYPE_43_TPM_DEVICE; + struct + { + WORD ReferencedHandle; + BYTE ProcessorSpecificBlock[]; + } TYPE_44_PROCESSOR_ADDITIONAL_INFO; + struct + { + BYTE ComponentName; + BYTE Version; +#define SMBIOS_FIRMWARE_INVENTORY_VERSION_FORMAT_FREE_FORM ((BYTE)00h) +#define SMBIOS_FIRMWARE_INVENTORY_VERSION_FORMAT_MAJOR_MINOR ((BYTE)01h) +#define SMBIOS_FIRMWARE_INVENTORY_VERSION_FORMAT_HEX_STRING_32 ((BYTE)02h) +#define SMBIOS_FIRMWARE_INVENTORY_VERSION_FORMAT_HEX_STRING_64 ((BYTE)03h) + BYTE VersionFormat; /* SMBIOS_FIRMWARE_INVENTORY_VERSION_FORMAT_* */ + BYTE ID; +#define SMBIOS_FIRMWARE_INVENTORY_ID_FORMAT_FREE_FORM ((BYTE)00h) +#define SMBIOS_FIRMWARE_INVENTORY_ID_FORMAT_UEFI_GUID ((BYTE)01h) + BYTE IDFormat; /* SMBIOS_FIRMWARE_INVENTORY_ID_FORMAT_* */ + BYTE ReleaseDate; + BYTE Manufacturer; + BYTE LowestSupportedFirmwareVersion; /* SMBIOS_FIRMWARE_INVENTORY_VERSION_FORMAT_* */ + QWORD ImageSize; + union + { + WORD Characteristics; + struct + { + WORD Updatable : 1; + WORD WriteProtect : 1; + WORD Reserved : 14; + }; + }; +#define SMBIOS_FIRMWARE_INVENTORY_STATE_OTHER ((BYTE)01h) +#define SMBIOS_FIRMWARE_INVENTORY_STATE_UNKNOWN ((BYTE)02h) +#define SMBIOS_FIRMWARE_INVENTORY_STATE_DISABLED ((BYTE)03h) +#define SMBIOS_FIRMWARE_INVENTORY_STATE_ENABLED ((BYTE)04h) +#define SMBIOS_FIRMWARE_INVENTORY_STATE_ABSENT ((BYTE)05h) +#define SMBIOS_FIRMWARE_INVENTORY_STATE_STANDBY_OFFLINE ((BYTE)06h) +#define SMBIOS_FIRMWARE_INVENTORY_STATE_STANDBY_SPARE ((BYTE)07h) +#define SMBIOS_FIRMWARE_INVENTORY_STATE_UNAVAILABLE_OFFLINE ((BYTE)08h) + BYTE State; /* SMBIOS_FIRMWARE_INVENTORY_STATE_* */ + BYTE NumberOfAssociatedComponents; + _Field_size_(NumberOfAssociatedComponents) WORD AssociatedComponentHandles[]; + } TYPE_45_FIRMWARE_INVENTORY_INFO; + }; +} SMBIOS_TABLE, *PSMBIOS_TABLE; + +#pragma pack(pop) + +#pragma warning(default: 4200) diff --git a/Source/Include/KNSoft/NDK/Extension/StrSafe.h b/Source/Include/KNSoft/NDK/Extension/StrSafe.h new file mode 100644 index 0000000..b3f65f4 --- /dev/null +++ b/Source/Include/KNSoft/NDK/Extension/StrSafe.h @@ -0,0 +1,138 @@ +#pragma once + +#include +#include + +#pragma region String PrintF + +/* + * StrSafe_Cch[V]Printf(A/W) + * + * Return == 0: Error or no data + * Return < BufferCount: Success + * Return >= BufferCount: Truncated, returns required size in character, not including null-terminator + */ + +_Success_( + return > 0 && return < BufferCount +) +__inline +unsigned long +__cdecl +StrSafe_CchVPrintfA( + _Out_writes_opt_(BufferCount) _Always_(_Post_z_) char* const Buffer, + _In_ size_t const BufferCount, + _In_z_ _Printf_format_string_ const char* Format, + va_list ArgList) +{ + int i; + +#pragma warning(disable: 4996) + i = _vsnprintf(Buffer, BufferCount, Format, ArgList); +#pragma warning(default: 4996) + if (i > 0) + { + if (Buffer != NULL && i == BufferCount) + { + Buffer[i - 1] = '\0'; + } + return i; + } else if (i == 0) + { + return 0; + } + +#pragma warning(disable: 4996) + i = _vsnprintf(NULL, 0, Format, ArgList); +#pragma warning(default: 4996) + if (i > 0) + { + if (Buffer != NULL && (size_t)i > BufferCount && BufferCount > 0) + { + Buffer[BufferCount - 1] = '\0'; + } + return i; + } + + return 0; +} + +_Success_( + return > 0 && return < BufferCount +) +__inline +unsigned long +__cdecl +StrSafe_CchVPrintfW( + _Out_writes_opt_(BufferCount) _Always_(_Post_z_) wchar_t* const Buffer, + _In_ size_t const BufferCount, + _In_z_ _Printf_format_string_ const wchar_t* Format, + va_list ArgList) +{ + int i; + +#pragma warning(disable: 4996) + i = _vsnwprintf(Buffer, BufferCount, Format, ArgList); +#pragma warning(default: 4996) + if (i > 0) + { + if (Buffer != NULL && i == BufferCount) + { + Buffer[i - 1] = L'\0'; + } + return i; + } else if (i == 0) + { + return 0; + } + +#pragma warning(disable: 4996) + i = _vsnwprintf(NULL, 0, Format, ArgList); +#pragma warning(default: 4996) + if (i > 0) + { + if (Buffer != NULL && (size_t)i > BufferCount && BufferCount > 0) + { + Buffer[BufferCount - 1] = L'\0'; + } + return i; + } + + return 0; +} + +_Success_( + return > 0 && return < BufferCount +) +__inline +unsigned long +__cdecl +StrSafe_CchPrintfA( + _Out_writes_opt_(BufferCount) _Always_(_Post_z_) char* const Buffer, + _In_ size_t const BufferCount, + _In_z_ _Printf_format_string_ const char* Format, ...) +{ + va_list ArgList; + + va_start(ArgList, Format); + return StrSafe_CchVPrintfA(Buffer, BufferCount, Format, ArgList); +} + +_Success_( + return > 0 && return < BufferCount +) +__inline +unsigned long +__cdecl +StrSafe_CchPrintfW( + _Out_writes_opt_(BufferCount) _Always_(_Post_z_) wchar_t* const Buffer, + _In_ size_t const BufferCount, + _In_z_ _Printf_format_string_ const wchar_t* Format, ...) +{ + va_list ArgList; + + va_start(ArgList, Format); + return StrSafe_CchVPrintfW(Buffer, BufferCount, Format, ArgList); +} + +#pragma endregion diff --git a/Source/Include/KNSoft/NDK/NDK.h b/Source/Include/KNSoft/NDK/NDK.h new file mode 100644 index 0000000..2ad7f04 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NDK.h @@ -0,0 +1,36 @@ +/* + * KNSoft.NDK (https://github.com/KNSoft/KNSoft.NDK) + * Copyright (c) KNSoft.org (https://github.com/KNSoft). All rights reserved. + * Licensed under the MIT license. + */ + +#pragma once + +#include "./NT/NT.h" + +/* Windows.h */ + +#include +#include "./Win32/Def/WinUser.h" +#include "./3rdParty/phnt/winsta.h" + +/* APIs */ + +#include "./Win32/API/Ntdll.h" +#include "./Win32/API/Kernel32.h" +#include "./Win32/API/User32.h" + +/* Additional headers */ + +#include +#include + +/* Enable extensions */ + +#ifndef _KNSOFT_NDK_NO_EXTENSION +#include "Extension/Extension.h" +#endif + +#ifndef _KNSOFT_NDK_NO_EXTENSION_MSTOOLCHAIN +#include "Extension/MSToolChain.h" +#endif diff --git a/Source/Include/KNSoft/NDK/NT/Addendum.h b/Source/Include/KNSoft/NDK/NT/Addendum.h new file mode 100644 index 0000000..243fee2 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Addendum.h @@ -0,0 +1,76 @@ +#pragma once + +#include "./MinDef.h" + +#pragma region Disable Microsoft extension warnings + +// Nonstandard extension used: zero-sized array in struct/union +#pragma warning(disable: 4200) + +#pragma endregion + +#pragma region Windows SDK + +/* wdm.h */ +typedef GUID *PGUID; + +typedef const GUID* PCGUID; + +/* wdm.h */ +typedef LONG KPRIORITY; + +/* wdm.h */ +typedef struct _KSYSTEM_TIME +{ + ULONG LowPart; + LONG High1Time; + LONG High2Time; +} KSYSTEM_TIME, *PKSYSTEM_TIME; + +#pragma region CLIENT_ID[64/32] + +/* wdm.h */ +typedef struct _CLIENT_ID +{ + HANDLE UniqueProcess; + HANDLE UniqueThread; +} CLIENT_ID, *PCLIENT_ID; + +typedef struct _CLIENT_ID64 +{ + VOID* POINTER_64 UniqueProcess; + VOID* POINTER_64 UniqueThread; +} CLIENT_ID64, *PCLIENT_ID64; + +typedef struct _CLIENT_ID32 +{ + VOID* POINTER_32 UniqueProcess; + VOID* POINTER_32 UniqueThread; +} CLIENT_ID32, *PCLIENT_ID32; + +#pragma endregion + +typedef USHORT RTL_ATOM, *PRTL_ATOM; + +#define DECLSPEC_ALLOCATOR __declspec(allocator) +#define DECLSPEC_EXPORT __declspec(dllexport) + +typedef unsigned __int64 QWORD, near* PQWORD, far* LPQWORD; + +// Makes a DWORD value by LOWORD and HIWORD +#define MAKEDWORD(l, h) ((DWORD)(((WORD)(((DWORD_PTR)(l)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(h)) & 0xffff))) << 16)) +#define MAKEQWORD(l, h) ((QWORD)(((DWORD)(((DWORD_PTR)(l)) & 0xffffffff)) | ((QWORD)((DWORD)(((DWORD_PTR)(h)) & 0xffffffff))) << 32)) + +#pragma endregion + +#pragma region MSVC + +EXTERN_C_START +extern IMAGE_DOS_HEADER __ImageBase; +EXTERN_C_END + +#if defined(_DEBUG) && !defined(DBG) +#define DBG 1 +#endif + +#pragma endregion diff --git a/Source/Include/KNSoft/NDK/NT/Dbg.h b/Source/Include/KNSoft/NDK/NT/Dbg.h new file mode 100644 index 0000000..09c14d5 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Dbg.h @@ -0,0 +1,17 @@ +#pragma once + +#include "NT.h" + +EXTERN_C_START + +/* wdm.h */ +#if (NTDDI_VERSION >= NTDDI_WIN2K) +NTSYSAPI +ULONG +__cdecl +DbgPrintReturnControlC( + _In_z_ _Printf_format_string_ PCCH Format, + ...); +#endif + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Ex.h b/Source/Include/KNSoft/NDK/NT/Ex.h new file mode 100644 index 0000000..bc6817b --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Ex.h @@ -0,0 +1,15 @@ +#pragma once + +#include "./MinDef.h" +#include "./Mm.h" + +EXTERN_C_START + +/* wdm.h */ +#if !defined(_KERNEL_MODE) && !defined(_BOOT_ENVIRONMENT) +#define SharedUserData ((KUSER_SHARED_DATA * const)MM_SHARED_USER_DATA_VA) +#endif + +typedef const struct _KUSER_SHARED_DATA* PCKUSER_SHARED_DATA; + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Extension/Runtime.h b/Source/Include/KNSoft/NDK/NT/Extension/Runtime.h new file mode 100644 index 0000000..a3498e0 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Extension/Runtime.h @@ -0,0 +1,105 @@ +#pragma once + +#include "../MinDef.h" + +#pragma region TEB/PEB fast access + +#if defined(_M_X64) + +#define ReadTeb(m) (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(ULONGLONG) ? __readgsqword(UFIELD_OFFSET(TEB, m)) : (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(ULONG) ? __readgsdword(UFIELD_OFFSET(TEB, m)) : (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(USHORT) ? __readgsword(UFIELD_OFFSET(TEB, m)) :\ + __readgsbyte(UFIELD_OFFSET(TEB, m))\ + )\ + )\ +) + +#define WriteTeb(m, val) (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(ULONGLONG) ? __writegsqword(UFIELD_OFFSET(TEB, m), (ULONGLONG)(val)) : (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(ULONG) ? __writegsdword(UFIELD_OFFSET(TEB, m), (ULONG)(val)) : (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(USHORT) ? __writegsword(UFIELD_OFFSET(TEB, m), (USHORT)(val)) :\ + __writegsbyte(UFIELD_OFFSET(TEB, m), (UCHAR)(val))\ + )\ + )\ +) + +#elif defined(_M_IX86) + +#define ReadTeb(m) (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(ULONG) ? __readfsdword(UFIELD_OFFSET(TEB, m)) : (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(USHORT) ? __readfsword(UFIELD_OFFSET(TEB, m)) :\ + __readfsbyte(UFIELD_OFFSET(TEB, m))\ + )\ +) + +#define WriteTeb(m, val) (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(ULONG) ? __writefsdword(UFIELD_OFFSET(TEB, m), (ULONG)(val)) : (\ + RTL_FIELD_SIZE(TEB, m) == sizeof(USHORT) ? __writefsword(UFIELD_OFFSET(TEB, m), (USHORT)(val)) :\ + __writefsbyte(UFIELD_OFFSET(TEB, m), (UCHAR)(val))\ + )\ +) + +#else + +#define ReadTeb(m) (NtCurrentTeb()->m) +#define WriteTeb(m, val) (NtCurrentTeb()->m = (val)) + +#endif + +#pragma endregion + +#pragma region Error codes + +/* Gets or sets the last error */ + +#define NtGetLastError() ((ULONG)ReadTeb(LastErrorValue)) +#define NtSetLastError(Error) WriteTeb(LastErrorValue, Error) + +/* Gets or sets the last status */ + +#define NtGetLastStatus() ((NTSTATUS)(ReadTeb(LastStatusValue))) +#define NtSetLastStatus(Status) WriteTeb(LastStatusValue, Status) + +/* + * Error code conversion (NOT translation) Win32 Error/NTSTATUS/HRESULT + * HRESULT_FROM_WIN32 / NTSTATUS_FROM_WIN32 / HRESULT_FROM_NT + */ + +#pragma endregion + +#pragma region Pseudo Handles + +#define NtCurrentProcessToken() ((HANDLE)(LONG_PTR)-4) +#define ZwCurrentProcessToken() NtCurrentProcessToken() +#define NtCurrentThreadToken() ((HANDLE)(LONG_PTR)-5) +#define ZwCurrentThreadToken() NtCurrentThreadToken() +#define NtCurrentThreadEffectiveToken() ((HANDLE)(LONG_PTR)-6) +#define ZwCurrentThreadEffectiveToken() NtCurrentThreadEffectiveToken() + +#pragma endregion + +#pragma region Current runtime information + +#define NtGetCurrentProcessId() ((HANDLE)ReadTeb(ClientId.UniqueProcess)) +#define NtGetCurrentThreadId() ((HANDLE)ReadTeb(ClientId.UniqueThread)) +#define NtGetCurrentDirectory() ((PCURDIR)&NtCurrentPeb()->ProcessParameters->CurrentDirectory) +#define NtGetCurrentImageBase() (NtCurrentPeb()->ImageBaseAddress) +#define NtGetNtdllBase() (CONTAINING_RECORD(NtCurrentPeb()->Ldr->InInitializationOrderModuleList.Flink, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList)->DllBase) +#define NtGetProcessHeap() (NtCurrentPeb()->ProcessHeap) + +#pragma endregion + +#pragma region Context + +#if defined(_M_IX86) +#define CONTEXT_PC Eip +#elif defined(_M_X64) +#define CONTEXT_PC Rip +#elif defined(_M_ARM64) +#define CONTEXT_PC Pc +#endif + +#pragma endregion + +#define CPU_CACHE_LINE_SIZE 64 diff --git a/Source/Include/KNSoft/NDK/NT/Extension/Security.h b/Source/Include/KNSoft/NDK/NT/Extension/Security.h new file mode 100644 index 0000000..6fe7b64 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Extension/Security.h @@ -0,0 +1,39 @@ +#pragma once + +#include "../MinDef.h" +#include "../../Extension/Extension.h" + +/* Well-known SIDs */ + +typedef DEFINE_ANYSIZE_STRUCT(SID_2, SID, DWORD, 2); +typedef DEFINE_ANYSIZE_STRUCT(SID_3, SID, DWORD, 3); +typedef DEFINE_ANYSIZE_STRUCT(SID_4, SID, DWORD, 4); +typedef DEFINE_ANYSIZE_STRUCT(SID_5, SID, DWORD, 5); +typedef DEFINE_ANYSIZE_STRUCT(SID_6, SID, DWORD, 6); +typedef DEFINE_ANYSIZE_STRUCT(SID_7, SID, DWORD, 7); + +/* SeExport used */ +#define SID_EVERYONE { SID_REVISION, 1, SECURITY_WORLD_SID_AUTHORITY, { SECURITY_WORLD_RID } } +#define SID_SYSTEM { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_LOCAL_SYSTEM_RID } } +#define SID_ADMINS { { SID_REVISION, 2, SECURITY_NT_AUTHORITY, { SECURITY_BUILTIN_DOMAIN_RID } }, DOMAIN_ALIAS_RID_ADMINS } +#define SID_USERS { { SID_REVISION, 2, SECURITY_NT_AUTHORITY, { SECURITY_BUILTIN_DOMAIN_RID } }, DOMAIN_ALIAS_RID_USERS } +#define SID_AUTHENTICATED_USERS { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_AUTHENTICATED_USER_RID } } +#define SID_LOCAL_SERVICE { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_LOCAL_SERVICE_RID } } +#define SID_NETWORK_SERVICE { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_NETWORK_SERVICE_RID } } +#define SID_TRUSTED_INSTALLER { SID_REVISION, SECURITY_SERVICE_ID_RID_COUNT, SECURITY_NT_AUTHORITY, { SECURITY_SERVICE_ID_BASE_RID }, SECURITY_TRUSTED_INSTALLER_RID1, SECURITY_TRUSTED_INSTALLER_RID2, SECURITY_TRUSTED_INSTALLER_RID3, SECURITY_TRUSTED_INSTALLER_RID4, SECURITY_TRUSTED_INSTALLER_RID5 } +#define SID_LOCAL { SID_REVISION, 1, SECURITY_LOCAL_SID_AUTHORITY, { SECURITY_LOCAL_RID } } +#define SID_INTERACTIVE { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_INTERACTIVE_RID } } +#define SID_MANDATORY_UNTRUSTED { SID_REVISION, 1, SECURITY_MANDATORY_LABEL_AUTHORITY, { SECURITY_MANDATORY_UNTRUSTED_RID } } +#define SID_MANDATORY_LOW { SID_REVISION, 1, SECURITY_MANDATORY_LABEL_AUTHORITY, { SECURITY_MANDATORY_LOW_RID } } +#define SID_MANDATORY_MEDIUM { SID_REVISION, 1, SECURITY_MANDATORY_LABEL_AUTHORITY, { SECURITY_MANDATORY_MEDIUM_RID } } +#define SID_MANDATORY_HIGH { SID_REVISION, 1, SECURITY_MANDATORY_LABEL_AUTHORITY, { SECURITY_MANDATORY_HIGH_RID } } +#define SID_MANDATORY_SYSTEM { SID_REVISION, 1, SECURITY_MANDATORY_LABEL_AUTHORITY, { SECURITY_MANDATORY_SYSTEM_RID } } + +/* Addendum */ +#define SID_LOCAL_ACCOUNT { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_LOCAL_ACCOUNT_RID } } +#define SID_LOCAL_ACCOUNT_AND_ADMIN { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_LOCAL_ACCOUNT_AND_ADMIN_RID } } +#define SID_LOCAL_LOGON { SID_REVISION, 1, SECURITY_LOCAL_SID_AUTHORITY, { SECURITY_LOCAL_LOGON_RID } } +#define SID_NTLM { {SID_REVISION, SECURITY_PACKAGE_RID_COUNT, SECURITY_NT_AUTHORITY, { SECURITY_PACKAGE_BASE_RID }}, SECURITY_PACKAGE_NTLM_RID } +#define SID_THIS_ORGANIZATION { SID_REVISION, 1, SECURITY_NT_AUTHORITY, { SECURITY_THIS_ORGANIZATION_RID } } +#define SID_MANDATORY_MEDIUM_PLUS { SID_REVISION, 1, SECURITY_MANDATORY_LABEL_AUTHORITY, { SECURITY_MANDATORY_MEDIUM_PLUS_RID } } +#define SID_MANDATORY_PROTECTED_PROCESS { SID_REVISION, 1, SECURITY_MANDATORY_LABEL_AUTHORITY, { SECURITY_MANDATORY_PROTECTED_PROCESS_RID } } diff --git a/Source/Include/KNSoft/NDK/NT/Io.h b/Source/Include/KNSoft/NDK/NT/Io.h new file mode 100644 index 0000000..24e6af6 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Io.h @@ -0,0 +1,1629 @@ +#pragma once + +#include "./MinDef.h" + +EXTERN_C_START + +#pragma region Reparse Tag + +#define IO_REPARSE_TAG_DRIVE_EXTENDER (0x80000005L) +#define IO_REPARSE_TAG_FILTER_MANAGER (0x8000000BL) +#define IO_REPARSE_TAG_IIS_CACHE (0xA0000010L) +#define IO_REPARSE_TAG_APPXSTRM (0xC0000014L) +#define IO_REPARSE_TAG_DFM (0x80000016L) +#define IO_REPARSE_TAG_LX_SYMLINK (0xA000001DL) +#define IO_REPARSE_TAG_LX_FIFO (0x80000024L) +#define IO_REPARSE_TAG_LX_CHR (0x80000025L) +#define IO_REPARSE_TAG_LX_BLK (0x80000026L) + +/////////////////////////////////////////////////////////////////////////////// +// +// Non-Microsoft tags for reparse points +// +/////////////////////////////////////////////////////////////////////////////// + +// +// Tag allocated to CONGRUENT, May 2000. Used by IFSTEST +// + +#define IO_REPARSE_TAG_IFSTEST_CONGRUENT (0x00000009L) + +// +// Tag allocated to Moonwalk Universal for HSM +// GUID: 257ABE42-5A28-4C8C-AC46-8FEA5619F18F +// + +#define IO_REPARSE_TAG_MOONWALK_HSM (0x0000000AL) + +// +// Tag allocated to Tsinghua University for Research purposes +// No released products should use this tag +// GUID: b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2 +// + +#define IO_REPARSE_TAG_TSINGHUA_UNIVERSITY_RESEARCH (0x0000000BL) + +// +// Tag allocated to ARKIVIO for HSM +// + +#define IO_REPARSE_TAG_ARKIVIO (0x0000000CL) + +// +// Tag allocated to SOLUTIONSOFT for name surrogate +// + +#define IO_REPARSE_TAG_SOLUTIONSOFT (0x2000000DL) + +// +// Tag allocated to COMMVAULT for HSM +// + +#define IO_REPARSE_TAG_COMMVAULT (0x0000000EL) + +// +// Tag allocated to Overtone Software for HSM +// + +#define IO_REPARSE_TAG_OVERTONE (0x0000000FL) + +// +// Tag allocated to Symantec (formerly to KVS Inc) for HSM +// GUID: A49F7BF6-77CA-493c-A0AA-18DBB28D1098 +// + +#define IO_REPARSE_TAG_SYMANTEC_HSM2 (0x00000010L) + +// +// Tag allocated to Enigma Data for HSM +// + +#define IO_REPARSE_TAG_ENIGMA_HSM (0x00000011L) + +// +// Tag allocated to Symantec for HSM +// GUID: B99F4235-CF1C-48dd-9E6C-459FA289F8C7 +// + +#define IO_REPARSE_TAG_SYMANTEC_HSM (0x00000012L) + +// +// Tag allocated to INTERCOPE for HSM +// GUID: F204BE2D-AEEB-4728-A31C-C7F4E9BEA758} +// + +#define IO_REPARSE_TAG_INTERCOPE_HSM (0x00000013L) + +// +// Tag allocated to KOM Networks for HSM +// + +#define IO_REPARSE_TAG_KOM_NETWORKS_HSM (0x00000014L) + +// +// Tag allocated to MEMORY_TECH for HSM +// GUID: E51BA456-046C-43ea-AEC7-DC1A87E1FD49 +// + +#define IO_REPARSE_TAG_MEMORY_TECH_HSM (0x00000015L) + +// +// Tag allocated to BridgeHead Software for HSM +// GUID: EBAFF6E3-F21D-4496-8342-58144B3D2BD0 +// + +#define IO_REPARSE_TAG_BRIDGEHEAD_HSM (0x00000016L) + +// +// Tag allocated to OSR for samples reparse point filter +// GUID: 3740c860-b19b-11d9-9669-0800200c9a66 +// + +#define IO_REPARSE_TAG_OSR_SAMPLE (0x20000017L) + +// +// Tag allocated to Global 360 for HSM +// GUID: C4B51F66-7F00-4c55-9441-8A1B159F209B +// + +#define IO_REPARSE_TAG_GLOBAL360_HSM (0x00000018L) + +// +// Tag allocated to Altiris for HSM +// GUID: fc1047eb-fb2d-45f2-a2f4-a71c1032fa2dB +// + +#define IO_REPARSE_TAG_ALTIRIS_HSM (0x00000019L) + +// +// Tag allocated to Hermes for HSM +// GUID: 437E0FD5-FCB4-42fe-877A-C785DA662AC2 +// + +#define IO_REPARSE_TAG_HERMES_HSM (0x0000001AL) + +// +// Tag allocated to PointSoft for HSM +// GUID: 547BC7FD-9604-4deb-AE07-B6514DF5FBC6 +// + +#define IO_REPARSE_TAG_POINTSOFT_HSM (0x0000001BL) + +// +// Tag allocated to GRAU Data Storage for HSM +// GUID: 6662D310-5653-4D10-8C31-F8E166D1A1BD +// + +#define IO_REPARSE_TAG_GRAU_DATASTORAGE_HSM (0x0000001CL) + +// +// Tag allocated to CommVault for HSM +// GUID: cc38adf3-c583-4efa-b183-72c1671941de +// + +#define IO_REPARSE_TAG_COMMVAULT_HSM (0x0000001DL) + + +// +// Tag allocated to Data Storage Group for single instance storage +// GUID: C1182673-0562-447a-8E40-4F0549FDF817 +// + +#define IO_REPARSE_TAG_DATASTOR_SIS (0x0000001EL) + + +// +// Tag allocated to Enterprise Data Solutions, Inc. for HSM +// GUID: EB63DF9D-8874-41cd-999A-A197542CDAFC +// + +#define IO_REPARSE_TAG_EDSI_HSM (0x0000001FL) + + +// +// Tag allocated to HP StorageWorks Reference Information Manager for Files (HSM) +// GUID: 3B0F6B23-0C2E-4281-9C19-C6AEEBC88CD8 +// + +#define IO_REPARSE_TAG_HP_HSM (0x00000020L) + + +// +// Tag allocated to SER Beteiligung Solutions Deutschland GmbH (HSM) +// GUID: 55B673F0-978E-41c5-9ADB-AF99640BE90E +// + +#define IO_REPARSE_TAG_SER_HSM (0x00000021L) + + +// +// Tag allocated to Double-Take Software (formerly NSI Software, Inc.) for HSM +// GUID: f7cb0ce8-453a-4ae1-9c56-db41b55f6ed4 +// + +#define IO_REPARSE_TAG_DOUBLE_TAKE_HSM (0x00000022L) + + +// +// Tag allocated to Beijing Wisdata Systems CO, LTD for HSM +// GUID: d546500a-2aeb-45f6-9482-f4b1799c3177 +// + +#define IO_REPARSE_TAG_WISDATA_HSM (0x00000023L) + + +// +// Tag allocated to Mimosa Systems Inc for HSM +// GUID: 8ddd4144-1a22-404b-8a5a-fcd91c6ee9f3 +// + +#define IO_REPARSE_TAG_MIMOSA_HSM (0x00000024L) + + +// +// Tag allocated to H&S Heilig und Schubert Software AG for HSM +// GUID: 77CA30C0-E5EC-43df-9E44-A4910378E284 +// + +#define IO_REPARSE_TAG_HSAG_HSM (0x00000025L) + + +// +// Tag allocated to Atempo Inc. (Atempo Digital Archive) for HSM +// GUID: 9B64518A-D6A4-495f-8D01-392F38862F0C +// + +#define IO_REPARSE_TAG_ADA_HSM (0x00000026L) + + +// +// Tag allocated to Autonomy Corporation for HSM +// GUID: EB112A57-10FC-4b42-B590-A61897FDC432 +// + +#define IO_REPARSE_TAG_AUTN_HSM (0x00000027L) + + +// +// Tag allocated to Nexsan for HSM +// GUID: d35eba9a-e722-445d-865f-dde1120acf16 +// + +#define IO_REPARSE_TAG_NEXSAN_HSM (0x00000028L) + + +// +// Tag allocated to Double-Take for SIS +// GUID: BDA506C2-F74D-4495-9A8D-44FD8D5B4F42 +// + +#define IO_REPARSE_TAG_DOUBLE_TAKE_SIS (0x00000029L) + + +// +// Tag allocated to Sony for HSM +// GUID: E95032E4-FD81-4e15-A8E2-A1F078061C4E +// + +#define IO_REPARSE_TAG_SONY_HSM (0x0000002AL) + + +// +// Tag allocated to Eltan Comm for HSM +// GUID: E1596D9F-44D8-43f4-A2D6-E9FE8D3E28FB +// + +#define IO_REPARSE_TAG_ELTAN_HSM (0x0000002BL) + + +// +// Tag allocated to Utixo LLC for HSM +// GUID: 5401F960-2F95-46D0-BBA6-052929FE2C32 +// + +#define IO_REPARSE_TAG_UTIXO_HSM (0x0000002CL) + + +// +// Tag allocated to Quest Software for HSM +// GUID: D546500A-2AEB-45F6-9482-F4B1799C3177 +// + +#define IO_REPARSE_TAG_QUEST_HSM (0x0000002DL) + + +// +// Tag allocated to DataGlobal GmbH for HSM +// GUID: 7A09CA83-B7B1-4614-ADFD-0BD5F4F989C9 +// + +#define IO_REPARSE_TAG_DATAGLOBAL_HSM (0x0000002EL) + + +// +// Tag allocated to Qi Tech LLC for HSM +// GUID: C8110B39-A4CE-432E-B58A-FBEAD296DF03 +// + +#define IO_REPARSE_TAG_QI_TECH_HSM (0x2000002FL) + +// +// Tag allocated to DataFirst Corporation for HSM +// GUID: E0E40591-6434-479f-94AC-DECF6DAEFB5C +// + +#define IO_REPARSE_TAG_DATAFIRST_HSM (0x00000030L) + +// +// Tag allocated to C2C Systems for HSM +// GUID: 6F2F829C-36AE-4E88-A3B6-E2C24377EA1C +// + +#define IO_REPARSE_TAG_C2CSYSTEMS_HSM (0x00000031L) + +// +// Tag allocated to Waterford Technologies for deduplication +// GUID: 0AF8B999-B8E8-408b-805F-5448E68F9274 +// + +#define IO_REPARSE_TAG_WATERFORD (0x00000032L) + +// +// Tag allocated to Riverbed Technology for HSM +// GUID: 3336274-255B-4038-9D39-14B0EC3F8256 +// + +#define IO_REPARSE_TAG_RIVERBED_HSM (0x00000033L) + +// +// Tag allocated to Caringo, Inc. for HSM +// GUID: B92426FA-D35F-48DB-A452-8FD557A23353 +// + +#define IO_REPARSE_TAG_CARINGO_HSM (0x00000034L) + +// +// Tag allocated to MaxiScale, Inc. for HSM +// GUID: 643B4714-BA13-427b-B771-C5BFDE787BB7 +// + +#define IO_REPARSE_TAG_MAXISCALE_HSM (0x20000035L) + +// +// Tag allocated to Citrix Systems for profile management +// GUID: B9150EDE-5845-4818-841B-5BCBB3B848E3 +// + +#define IO_REPARSE_TAG_CITRIX_PM (0x00000036L) + +// +// Tag allocated to OpenAFS for DFS +// GUID: EF21A155-5C92-4470-AB3B-370403D96369 +// + +#define IO_REPARSE_TAG_OPENAFS_DFS (0x00000037L) + +// +// Tag allocated to ZL Technologies Inc for HSM +// GUID: A521FE7A-EB10-4148-BAC7-264359827B7E +// + +#define IO_REPARSE_TAG_ZLTI_HSM (0x00000038L) + +// +// Tag allocated to EMC Corporation for HSM +// GUID: 119EA2B9-8979-48b9-B4CE-5082AF2D81E5 +// + +#define IO_REPARSE_TAG_EMC_HSM (0x00000039L) + +// +// Tag allocated to VMware for profile management +// GUID: 6D020A57-C9BB-4DA4-A43F-49686D8D5E77 +// + +#define IO_REPARSE_TAG_VMWARE_PM (0x0000003AL) + +// +// Tag allocated to Arco Computer Products for backup +// GUID: C933F72B-A64D-44d9-8CD9-F339D12390CC +// + +#define IO_REPARSE_TAG_ARCO_BACKUP (0x0000003BL) + +// +// Tag allocated to Carroll-Net for HSM +// GUID: 805EB191-564B-415a-A78C-9ED0AF8E02FF +// + +#define IO_REPARSE_TAG_CARROLL_HSM (0x0000003CL) + +// +// Tag allocated to ComTrade for HSM +// GUID: D546500A-2AEB-45F6-9482-F4B1799C3177 +// + +#define IO_REPARSE_TAG_COMTRADE_HSM (0x0000003DL) + +// +// Tag allocated to EaseVault for HSM +// GUID: BBA65D6F-F8A0-48CC-B748-DBD5FFFCCFB1 +// + +#define IO_REPARSE_TAG_EASEVAULT_HSM (0x0000003EL) + +// +// Tag allocated to Hitachi Data Systems for HSM +// GUID: DC095FD2-AC3C-46BA-9E58-DD182BE86AF4 +// + +#define IO_REPARSE_TAG_HDS_HSM (0x0000003FL) + +// +// Tag allocated to Maginatics for network redirector +// GUID: 1907AE87-388D-4854-AF63-B585A619DF28 +// + +#define IO_REPARSE_TAG_MAGINATICS_RDR (0x00000040L) + +// +// Tag allocated to Google for HSM +// GUID: 40550C94-68DB-4726-9C62-47BB88577BD0 +// + +#define IO_REPARSE_TAG_GOOGLE_HSM (0x00000041L) + +// +// Tag allocated to Quaddra for HSM +// GUID: 491D6619-20C3-4BFA-AF98-4EA2A7F53F1D +// + +#define IO_REPARSE_TAG_QUADDRA_HSM (0x00000042L) + +// +// Tag allocated to HP for backup +// GUID: 0c5ed442-4928-473e-970e-5389ff2b4328 +// + +#define IO_REPARSE_TAG_HP_BACKUP (0x00000043L) + +// +// Tag allocated to DropBox for HSM +// GUID: C5BB0F16-68E9-4456-B6B9-5F5EE5F89965 +// + +#define IO_REPARSE_TAG_DROPBOX_HSM (0x00000044L) + +// +// Tag allocated to Adobe for HSM +// GUID: 48F5DB1C-ED3C-44F7-8EBA-3623C09D6179 +// + +#define IO_REPARSE_TAG_ADOBE_HSM (0x00000045L) + +// +// Tag allocated to HP for HPE Data Protector HSM +// GUID: 3370DFC4-DCED-4DEB-AD0C-9A2416B3198B +// + +#define IO_REPARSE_TAG_HP_DATA_PROTECT (0x00000046L) + +// +// Tag allocated to Activision for HSM +// GUID: 18CC35B3-5DFF-408E-B42E-9FA6731BC506 +// + +#define IO_REPARSE_TAG_ACTIVISION_HSM (0x00000047L) + +// +// Tag allocated to Hitachi for HSM +// GUID: DFFD30B6-6CC0-46A8-94C2-AAE32C9B16D1 +// + +#define IO_REPARSE_TAG_HDS_HCP_HSM (0x00000048L) + +// +// Tag allocated to AuriStor File System +// GUID: AFBD291F-3DF8-46BA-BE87-47A632714BB7 +// + +#define IO_REPARSE_TAG_AURISTOR_FS (0x00000049L) + +// +// Tag allocated to ItStation for restore +// GUID: C33A7A21-6142-4860-9AAA-0008F1064616 +// + +#define IO_REPARSE_TAG_ITSTATION (0x0000004AL) + +// +// Tag allocated to Spharsoft for dedup +// GUID: 2AB7C758-E6AA-43FB-9194-80A436E22F26 +// + +#define IO_REPARSE_TAG_SPHARSOFT (0x0000004BL) + +// +// Tag allocated to AlertBoot for encryption +// GUID: 80050DB9-52D3-4742-B28B-3918177242D5 +// + +#define IO_REPARSE_TAG_ALERTBOOT (0x2000004CL) + +// +// Tag allocated to mTalos for monitoring +// GUID: C51BB90B-77D2-43B9-8E88-CC5745E977FF +// + +#define IO_REPARSE_TAG_MTALOS (0x0000004DL) + +// +// Tag allocated to CTERA for HSM +// GUID: A0431A3B-7789-485C-8638-FCA288FDBA71 +// + +#define IO_REPARSE_TAG_CTERA_HSM (0x0000004EL) + +// +// Tag allocated to Nippon Techno Lab for HSM +// GUID: 8E5C2A8D-7344-4923-A741-2E9EFF128126 +// + +#define IO_REPARSE_TAG_NIPPON_HSM (0x0000004FL) + +// +// Tag allocated to Redstor for HSM +// GUID: E6636830-4534-4FA2-9D4F-DDD22818EDCC +// + +#define IO_REPARSE_TAG_REDSTOR_HSM (0x00000050L) + +// +// Tag allocated to NeuShield for monitoring +// GUID: 585414E1-6E0E-46B6-8838-ED837173F590 +// + +#define IO_REPARSE_TAG_NEUSHIELD (0x00000051L) + +// +// Tag allocated to DOR for HSM +// GUID: 51A0CF2A-5221-4093-9025-06D80C2AA122 +// + +#define IO_REPARSE_TAG_DOR_HSM (0x00000052L) + +// +// Tag allocated to StorageCraft Technology for backup +// GUID: 5E2913DA-EAEE-47CB-B866-EDDCAEB3EBC3 +// + +#define IO_REPARSE_TAG_SHX_BACKUP (0x00000053L) + +// +// Tag allocated to NVIDIA Corporation for union file system +// GUID: E2700D02-2ABA-4629-805D-956A381244A5 +// + +#define IO_REPARSE_TAG_NVIDIA_UNIONFS (0x20000054L) + +// +// Tag allocated to HubStor for HSM +// GUID: 9492F18B-303F-4394-9804-8ED21710CA8C +// + +#define IO_REPARSE_TAG_HUBSTOR_HSM (0x00000055L) + +// +// Tag allocated to iManage for HSM +// GUID: 7C334C3C-0C03-4659-93D8-EBCF627BC3F1 +// + +#define IO_REPARSE_TAG_IMANAGE_HSM (0x20000056L) + +// +// Tag allocated to EaseFilter Technologies Limited for HSM +// GUID: 8015B12A-A78F-4645-B999-7ED7978B51F1 +// + +#define IO_REPARSE_TAG_EASEFILTER_HSM (0x00000057L) + +// +// Tag allocated to Peer Software Inc. Limited for HSM +// GUID: A9DFF133-08B0-4005-9E6B-D9C8876942F4 +// + +#define IO_REPARSE_TAG_PEER_GFS (0x00000058L) + +// +// Tag allocated to Amazon Web Services Inc. This is for use +// in the AWS AppStream Product. +// GUID: 0485DEC0-0A06-4352-892A-FDEFA63BFDD8 +// + +#define IO_REPARSE_TAG_AMZN_APPSTREAM (0x00000059L) + + +// +// Tag allocated to Acronis for HSM +// +// GUID: A8EA81D5-7F25-42AC-B20D-F0EEB15B1F82} +// +#define IO_REPARSE_TAG_ACRONIS_HSM_0 (0x00000060L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 8FCBC190-0ACE-477A-B08C-577548E9BB22 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_1 (0x00000061L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 1ABBD355-7E88-4D0B-AFBD-6BF3FF3F65E5 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_2 (0x00000062L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: EE4F962D-25D6-4F69-BEE1-DC952D853305 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_3 (0x00000063L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 4AAB412F-BF9E-460C-9292-31DE5A3F9D08 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_4 (0x00000064L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 67D29104-E971-477D-8BA5-E077E2D17472 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_5 (0x00000065L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 6EFAE00E-9C04-4767-B30A-C9DDE120E7DE +// +#define IO_REPARSE_TAG_ACRONIS_HSM_6 (0x00000066L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 7D66C79F-7E5C-4265-BEC8-E7F916A31C97 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_7 (0x00000067L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 43055DA8-8B12-436C-B8CC-01505809247A +// +#define IO_REPARSE_TAG_ACRONIS_HSM_8 (0x00000068L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 8DCA3C54-234F-41CA-9BB7-0886C1F1AC94 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_9 (0x00000069L) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 76B16F29-AA91-4442-B36F-301C57037B5D +// +#define IO_REPARSE_TAG_ACRONIS_HSM_A (0x0000006AL) + +// +// Tag allocated to Acronis for HSM +// +// GUID: CE206456-FC1A-4841-8527-7BDADBDD8A0B +// +#define IO_REPARSE_TAG_ACRONIS_HSM_B (0x0000006BL) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 9CEC8C4B-DAD0-4C2A-BC7B-D1C818A3E9E8 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_C (0x0000006CL) + +// +// Tag allocated to Acronis for HSM +// +// GUID: C25CB784-3C8B-48DF-B14B-D2A87C441183 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_D (0x0000006DL) + +// +// Tag allocated to Acronis for HSM +// +// GUID: C74393B8-3025-467E-BF75-1E9771CC2BDA +// +#define IO_REPARSE_TAG_ACRONIS_HSM_E (0x0000006EL) + +// +// Tag allocated to Acronis for HSM +// +// GUID: 8B72233F-3B15-4496-B1AA-B3E7C5FD3485 +// +#define IO_REPARSE_TAG_ACRONIS_HSM_F (0x0000006FL) + +#pragma endregion ntifs.h + +#pragma region Link Tracking Information + +// +// The following three FSCTLs are placed in this file to facilitate sharing +// between the redirector and the IO subsystem +// +// This FSCTL is used to garner the link tracking information for a file. +// The data structures used for retrieving the information are +// LINK_TRACKING_INFORMATION defined further down in this file. +// + +#define FSCTL_LMR_GET_LINK_TRACKING_INFORMATION CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,58,METHOD_BUFFERED,FILE_ANY_ACCESS) + +// +// This FSCTL is used to update the link tracking information on a server for +// an intra machine/ inter volume move on that server +// + +#define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,59,METHOD_BUFFERED,FILE_ANY_ACCESS) + +// +// The following IOCTL is used in link tracking implementation. It determines if the +// two file objects passed in are on the same server. This IOCTL is available in +// kernel mode only since it accepts FILE_OBJECT as parameters +// + +#define IOCTL_LMR_ARE_FILE_OBJECTS_ON_SAME_SERVER CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,60,METHOD_BUFFERED,FILE_ANY_ACCESS) + +// +// Control structure for FSCTL_LMR_GET_LINK_TRACKING_INFORMATION +// + +// +// For links on DFS volumes the volume id and machine id are returned for +// link tracking +// +typedef enum _LINK_TRACKING_INFORMATION_TYPE +{ + NtfsLinkTrackingInformation, + DfsLinkTrackingInformation +} LINK_TRACKING_INFORMATION_TYPE, *PLINK_TRACKING_INFORMATION_TYPE; + +typedef struct _LINK_TRACKING_INFORMATION +{ + LINK_TRACKING_INFORMATION_TYPE Type; + UCHAR VolumeId[16]; +} LINK_TRACKING_INFORMATION, *PLINK_TRACKING_INFORMATION; + +// +// Control structure for FSCTL_LMR_SET_LINK_TRACKING_INFORMATION +// +typedef struct _REMOTE_LINK_TRACKING_INFORMATION_ +{ + PVOID TargetFileObject; + ULONG TargetLinkTrackingInformationLength; + UCHAR TargetLinkTrackingInformationBuffer[1]; +} REMOTE_LINK_TRACKING_INFORMATION, *PREMOTE_LINK_TRACKING_INFORMATION; + +#pragma endregion ntifs.h + +#pragma region FSCTLs + +/* FSCTL_QUERY_EXTENT_READ_CACHE_INFO ntifs.h */ + +#if (_WIN32_WINNT >= _WIN32_WINNT_THRESHOLD) + +typedef struct _VCN_RANGE_INPUT_BUFFER +{ + LARGE_INTEGER StartingVcn; + LARGE_INTEGER ClusterCount; +} VCN_RANGE_INPUT_BUFFER, *PVCN_RANGE_INPUT_BUFFER; + +typedef struct _EXTENT_READ_CACHE_INFO_BUFFER +{ + LARGE_INTEGER AllocatedCache; + LARGE_INTEGER PopulatedCache; + LARGE_INTEGER InErrorCache; +} EXTENT_READ_CACHE_INFO_BUFFER, *PEXTENT_READ_CACHE_INFO_BUFFER; + +#endif /* _WIN32_WINNT >= _WIN32_WINNT_THRESHOLD */ + +/* FSCTL_QUERY_REFS_VOLUME_COUNTER_INFO ntifs.h */ + +#if (_WIN32_WINNT >= _WIN32_WINNT_THRESHOLD) + +typedef struct _REFS_VOLUME_COUNTER_INFO_INPUT_BUFFER +{ + BOOLEAN ResetCounters; +} REFS_VOLUME_COUNTER_INFO_INPUT_BUFFER, *PREFS_VOLUME_COUNTER_INFO_INPUT_BUFFER; + +typedef struct _VOLUME_REFS_INFO_BUFFER +{ + // + // These values will not be affected at reset + // + LARGE_INTEGER CacheSizeInBytes; + LARGE_INTEGER AllocatedCacheInBytes; + LARGE_INTEGER PopulatedCacheInBytes; + LARGE_INTEGER InErrorCacheInBytes; + LARGE_INTEGER MemoryUsedForCacheMetadata; + ULONG CacheLineSize; + LONG CacheTransactionsOutstanding; + LONG CacheLinesFree; + LONG CacheLinesInError; + + // + // These values will be affected at reset + // + LARGE_INTEGER CacheHitsInBytes; + LARGE_INTEGER CacheMissesInBytes; + LARGE_INTEGER CachePopulationUpdatesInBytes; + LARGE_INTEGER CacheWriteThroughUpdatesInBytes; + LARGE_INTEGER CacheInvalidationsInBytes; + LARGE_INTEGER CacheOverReadsInBytes; + LARGE_INTEGER MetadataWrittenBytes; + + LONG CacheHitCounter; + LONG CacheMissCounter; + LONG CacheLineAllocationCounter; + LONG CacheInvalidationsCounter; + LONG CachePopulationUpdatesCounter; + LONG CacheWriteThroughUpdatesCounter; + LONG MaxCacheTransactionsOutstanding; + +// LONG TimeRequiredForCacheHitIn100us; +// LONG TimeRequiredForCacheMissIn100us; + + LONGLONG DataWritesReallocationCount; + LONGLONG DataInPlaceWriteCount; + LONGLONG MetadataAllocationsFastTierCount; + LONGLONG MetadataAllocationsSlowTierCount; + LONGLONG DataAllocationsFastTierCount; + LONGLONG DataAllocationsSlowTierCount; + + LONGLONG DestagesSlowTierToFastTier; + LONGLONG DestagesFastTierToSlowTier; + LONG SlowTierDataFillRatio; + LONG FastTierDataFillRatio; + LONG SlowTierMetadataFillRatio; + LONG FastTierMetadataFillRatio; + + LONGLONG SlowToFastDestageReadLatency; + LONG SlowToFastDestageReadLatencyBase; + + LONGLONG SlowToFastDestageWriteLatency; + LONG SlowToFastDestageWriteLatencyBase; + + LONGLONG FastToSlowDestageReadLatency; + LONG FastToSlowDestageReadLatencyBase; + + LONGLONG FastToSlowDestageWriteLatency; + LONG FastToSlowDestageWriteLatencyBase; + + LONGLONG SlowTierContainerFillRatio; + LONG SlowTierContainerFillRatioBase; + + LONGLONG FastTierContainerFillRatio; + LONG FastTierContainerFillRatioBase; + + LONG Unused1; + LONG Unused2; + LONG Unused3; + LONG Unused4; + + LONGLONG TreeUpdateCount; + LONGLONG CheckpointCount; + LONGLONG LogWriteCount; + LONG LogFillRatio; + + LONG ReadCacheInvalidationsForOverwrite; + LONG ReadCacheInvalidationsForReuse; + LONG ReadCacheInvalidationsGeneral; + + LONG ReadCacheChecksOnMount; + LONG ReadCacheIssuesOnMount; + + LONGLONG TrimLatency; + LONG TrimLatencyBase; + + LONGLONG DataCompactionCount; + + LONGLONG CompactionReadLatency; + LONG CompactionReadLatencyBase; + + LONGLONG CompactionWriteLatency; + LONG CompactionWriteLatencyBase; + + LARGE_INTEGER DataInPlaceWriteClusterCount; + + LONG CompactionFailedDueToIneligibleContainer; + LONG CompactionFailedDueToMaxFragmentation; + + LONGLONG CompactedContainerFillRatio; + LONG CompactedContainerFillRatioBase; + + LONG ContainerMoveRetryCount; + LONG ContainerMoveFailedDueToIneligibleContainer; + + LONG CompactionFailureCount; + LONG ContainerMoveFailureCount; + + LARGE_INTEGER NumberOfDirtyMetadataPages; + LONG NumberOfDirtyTableListEntries; + LONG NumberOfDeleteQueueEntries; + + LONG MAAFilteredViewSize; + LONG MAAFilteredViewInsertions; + LONG MAAFilteredViewDeletions; + LONG MAAFilteredViewCollisions; + LONG MAAFilteredViewPurges; + LONGLONG MAARegionsVisitedPerAllocationSum; + LONG MAARegionsVisitedPerAllocationBase; + LONG MAAMaxRegionsVisitedPerAllocation; + + LONGLONG TreeUpdateLatencyExclusive; + LONGLONG TreeUpdateLatencyTotal; + LONG TreeUpdateLatencyBase; + + LONGLONG CheckpointLatencyTreeUpdateExclusive; + LONGLONG CheckpointLatencyTreeUpdateTotal; + LONG CheckpointLatencyTreeUpdateBase; + LONGLONG CheckpointLatencyTotal; + LONG CheckpointLatencyTotalBase; + +} VOLUME_REFS_INFO_BUFFER, *PVOLUME_REFS_INFO_BUFFER; + +#endif /* _WIN32_WINNT >= _WIN32_WINNT_THRESHOLD */ + +/* FSCTL_QUERY_DIRECT_ACCESS_EXTENTS ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_TH2) + +typedef struct _QUERY_DIRECT_ACCESS_EXTENTS +{ + LONGLONG FileOffset; + LONGLONG Length; + ULONG Flags; + ULONG Reserved; +} QUERY_DIRECT_ACCESS_EXTENTS, *PQUERY_DIRECT_ACCESS_EXTENTS; + +#define QUERY_DIRECT_ACCESS_IMAGE_EXTENTS 0x00000001 +#define QUERY_DIRECT_ACCESS_DATA_EXTENTS 0x00000002 + +#endif /* NTDDI_VERSION >= NTDDI_WIN10_TH2 */ + +/* FSCTL_GHOST_FILE_EXTENTS ntifs.h */ + +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10_TH2) +typedef struct _FSCTL_GHOST_FILE_EXTENTS_INPUT_BUFFER +{ + LARGE_INTEGER FileOffset; + LARGE_INTEGER ByteCount; + + GUID RecallOwnerGuid; + + ULONG RecallMetadataBufferSize; + UCHAR RecallMetadataBuffer[ANYSIZE_ARRAY]; +} FSCTL_GHOST_FILE_EXTENTS_INPUT_BUFFER, *PFSCTL_GHOST_FILE_EXTENTS_INPUT_BUFFER; +#endif // #if (_WIN32_WINNT >= _WIN32_WINNT_WIN10_TH2) + +/* FSCTL_QUERY_GHOSTED_FILE_EXTENTS ntifs.h */ + +typedef struct _FSCTL_QUERY_GHOSTED_FILE_EXTENTS_INPUT_RANGE +{ + LARGE_INTEGER FileOffset; + LARGE_INTEGER ByteCount; +} FSCTL_QUERY_GHOSTED_FILE_EXTENTS_INPUT_RANGE, *PFSCTL_QUERY_GHOSTED_FILE_EXTENTS_INPUT_RANGE; + +typedef struct _GHOSTED_FILE_EXTENT +{ + LARGE_INTEGER FileOffset; + LARGE_INTEGER ByteCount; + + GUID RecallOwnerGuid; + ULONG NextEntryOffset; + ULONG RecallMetadataBufferSize; + UCHAR RecallMetadataBuffer[ANYSIZE_ARRAY]; +} GHOSTED_FILE_EXTENT, *PGHOSTED_FILE_EXTENT; + +typedef struct _FSCTL_QUERY_GHOSTED_FILE_EXTENTS_OUTPUT +{ + ULONG ExtentCount; + ULONG TotalExtentCount; + UCHAR Extents[ANYSIZE_ARRAY]; +} FSCTL_QUERY_GHOSTED_FILE_EXTENTS_OUTPUT, *PFSCTL_QUERY_GHOSTED_FILE_EXTENTS_OUTPUT; + +#define GHOSTED_FILE_EXTENTS_OUTPUT_SIZE(Count, MaxRecallMetadataBufferSize) \ + FIELD_OFFSET(FSCTL_QUERY_GHOSTED_FILE_EXTENTS_OUTPUT, Extents) + \ + ALIGN_UP((FIELD_OFFSET(GHOSTED_FILE_EXTENT, RecallMetadataBuffer) + \ + MaxRecallMetadataBufferSize), \ + 8) * \ + (Count) + +/* FSCTL_UNMAP_SPACE ntifs.h */ + +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10_TH2) + +typedef struct _FSCTL_UNMAP_SPACE_INPUT_BUFFER +{ + LARGE_INTEGER BytesToUnmap; +} FSCTL_UNMAP_SPACE_INPUT_BUFFER, *PFSCTL_UNMAP_SPACE_INPUT_BUFFER; + +typedef struct _FSCTL_UNMAP_SPACE_OUTPUT +{ + LARGE_INTEGER BytesUnmapped; +} FSCTL_UNMAP_SPACE_OUTPUT, *PFSCTL_UNMAP_SPACE_OUTPUT; + +#endif // #if (_WIN32_WINNT >= _WIN32_WINNT_WIN10_TH2) + +/* FSCTL_QUERY_VOLUME_NUMA_INFO ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_RS2) + +typedef struct _FSCTL_QUERY_VOLUME_NUMA_INFO_OUTPUT +{ + ULONG NumaNode; +} FSCTL_QUERY_VOLUME_NUMA_INFO_OUTPUT, *PFSCTL_QUERY_VOLUME_NUMA_INFO_OUTPUT; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN10_RS2) + +/* FSCTL_REFS_DEALLOCATE_RANGES ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_RS2) + +typedef struct _REFS_DEALLOCATE_RANGES_RANGE +{ + ULONGLONG StartOfRange; + ULONGLONG CountOfRange; +} REFS_DEALLOCATE_RANGES_RANGE, *PREFS_DEALLOCATE_RANGES_RANGE; + +typedef struct _REFS_DEALLOCATE_RANGES_INPUT_BUFFER +{ + ULONG RangeCount; + REFS_DEALLOCATE_RANGES_RANGE Ranges[ANYSIZE_ARRAY]; +} REFS_DEALLOCATE_RANGES_INPUT_BUFFER, *PREFS_DEALLOCATE_RANGES_INPUT_BUFFER; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN10_RS2) + +/* FSCTL_REFS_DEALLOCATE_RANGES_EX ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_FE) + +typedef enum _REFS_DEALLOCATE_RANGES_ALLOCATOR +{ + REFS_DEALLOCATE_RANGES_ALLOCATOR_NONE = 0, + REFS_DEALLOCATE_RANGES_ALLOCATOR_SAA = 1, + REFS_DEALLOCATE_RANGES_ALLOCATOR_CAA = 2, + REFS_DEALLOCATE_RANGES_ALLOCATOR_MAA = 3, +} REFS_DEALLOCATE_RANGES_ALLOCATOR, *PREFS_DEALLOCATE_RANGES_ALLOCATOR; + +typedef struct _REFS_DEALLOCATE_RANGES_INPUT_BUFFER_EX +{ + ULONG RangeCount; + REFS_DEALLOCATE_RANGES_ALLOCATOR Allocator; + LONGLONG StreamReserveUpdateCount; + ULONG OffsetToRanges; + ULONG OffsetToLeakCounts; + ULONGLONG Reserved[2]; +} REFS_DEALLOCATE_RANGES_INPUT_BUFFER_EX, *PREFS_DEALLOCATE_RANGES_INPUT_BUFFER_EX; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN10_FE) + +/* FSCTL_REFS_REMOVE_HARDLINK_BACKPOINTER ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_MN) + +typedef struct _REFS_REMOVE_HARDLINK_BACKPOINTER +{ + ULONGLONG ParentDirectory; + ULONGLONG Reserved; + WCHAR FileName[1]; +} REFS_REMOVE_HARDLINK_BACKPOINTER, *PREFS_REMOVE_HARDLINK_BACKPOINTER; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN10_MN) + +/* FSCTL_REFS_STREAM_SNAPSHOT_MANAGEMENT ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_FE) + +enum _REFS_STREAM_EXTENT_PROPERTIES +{ + REFS_STREAM_EXTENT_PROPERTY_VALID = 0x0010, + REFS_STREAM_EXTENT_PROPERTY_STREAM_RESERVED = 0x0020, + REFS_STREAM_EXTENT_PROPERTY_CRC32 = 0x0080, + REFS_STREAM_EXTENT_PROPERTY_CRC64 = 0x0100, + REFS_STREAM_EXTENT_PROPERTY_GHOSTED = 0x0200, + REFS_STREAM_EXTENT_PROPERTY_READONLY = 0x0400, + REFS_STREAM_EXTENT_PROPERTY_SPARSE = 0x0008, +}; +typedef USHORT REFS_STREAM_EXTENT_PROPERTIES; +typedef REFS_STREAM_EXTENT_PROPERTIES* PREFS_STREAM_EXTENT_PROPERTIES; + +typedef struct _REFS_STREAM_EXTENT +{ + LONGLONG Vcn; + LONGLONG Lcn; + LONGLONG Length; + REFS_STREAM_EXTENT_PROPERTIES Properties; // enum _REFS_STREAM_EXTENT_PROPERTIES +} REFS_STREAM_EXTENT, *PREFS_STREAM_EXTENT; + +typedef enum _REFS_STREAM_SNAPSHOT_OPERATION +{ + REFS_STREAM_SNAPSHOT_OPERATION_INVALID = 0, + REFS_STREAM_SNAPSHOT_OPERATION_CREATE = 1, + REFS_STREAM_SNAPSHOT_OPERATION_LIST = 2, + REFS_STREAM_SNAPSHOT_OPERATION_QUERY_DELTAS = 3, + REFS_STREAM_SNAPSHOT_OPERATION_REVERT = 4, + REFS_STREAM_SNAPSHOT_OPERATION_SET_SHADOW_BTREE = 5, + REFS_STREAM_SNAPSHOT_OPERATION_CLEAR_SHADOW_BTREE = 6, + REFS_STREAM_SNAPSHOT_OPERATION_MAX = REFS_STREAM_SNAPSHOT_OPERATION_CLEAR_SHADOW_BTREE, +} REFS_STREAM_SNAPSHOT_OPERATION, *PREFS_STREAM_SNAPSHOT_OPERATION; + +typedef struct _REFS_STREAM_SNAPSHOT_MANAGEMENT_INPUT_BUFFER +{ + REFS_STREAM_SNAPSHOT_OPERATION Operation; + USHORT SnapshotNameLength; + USHORT OperationInputBufferLength; + ULONGLONG Reserved[2]; + USHORT NameAndInputBuffer[ANYSIZE_ARRAY]; +} REFS_STREAM_SNAPSHOT_MANAGEMENT_INPUT_BUFFER, *PREFS_STREAM_SNAPSHOT_MANAGEMENT_INPUT_BUFFER; + +typedef struct _REFS_STREAM_SNAPSHOT_LIST_OUTPUT_BUFFER_ENTRY +{ + ULONG NextEntryOffset; + USHORT SnapshotNameLength; + ULONGLONG SnapshotCreationTime; + ULONGLONG StreamSize; + ULONGLONG StreamAllocationSize; + ULONGLONG Reserved[2]; + WCHAR SnapshotName[ANYSIZE_ARRAY]; +} REFS_STREAM_SNAPSHOT_LIST_OUTPUT_BUFFER_ENTRY, *PREFS_STREAM_SNAPSHOT_LIST_OUTPUT_BUFFER_ENTRY; + +typedef struct _REFS_STREAM_SNAPSHOT_LIST_OUTPUT_BUFFER +{ + ULONG EntryCount; + ULONG BufferSizeRequiredForQuery; + ULONG Reserved[2]; + REFS_STREAM_SNAPSHOT_LIST_OUTPUT_BUFFER_ENTRY Entries[ANYSIZE_ARRAY]; +} REFS_STREAM_SNAPSHOT_LIST_OUTPUT_BUFFER, *PREFS_STREAM_SNAPSHOT_LIST_OUTPUT_BUFFER; + +typedef struct _REFS_STREAM_SNAPSHOT_QUERY_DELTAS_INPUT_BUFFER +{ + LONGLONG StartingVcn; + ULONG Flags; + ULONG Reserved; +} REFS_STREAM_SNAPSHOT_QUERY_DELTAS_INPUT_BUFFER, *PREFS_STREAM_SNAPSHOT_QUERY_DELTAS_INPUT_BUFFER; + +typedef struct _REFS_STREAM_SNAPSHOT_QUERY_DELTAS_OUTPUT_BUFFER +{ + ULONG ExtentCount; + ULONG Reserved[2]; + REFS_STREAM_EXTENT Extents[ANYSIZE_ARRAY]; +} REFS_STREAM_SNAPSHOT_QUERY_DELTAS_OUTPUT_BUFFER, *PREFS_STREAM_SNAPSHOT_QUERY_DELTAS_OUTPUT_BUFFER; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN10_FE) + +/* FSCTL_DUPLICATE_CLUSTER ntifs.h */ +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) +typedef struct _DUPLICATE_CLUSTER_DATA +{ + + LONGLONG SourceLcn; + LONGLONG TargetLcn; + LARGE_INTEGER TargetFileOffset; + ULONG DuplicationLimit; + ULONG Reserved; + +} DUPLICATE_CLUSTER_DATA, *PDUPLICATE_CLUSTER_DATA; +#endif (NTDDI_VERSION >= NTDDI_WIN10_NI) + +/* FSCTL_QUERY_LCN_WEAK_REFERENCE_STATE ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +enum _LCN_WEAK_REFERENCE_STATE +{ + + LCN_WEAK_REFERENCE_VALID = 0x00000001, + LCN_WEAK_REFERENCE_BROKEN = 0x00000002, + LCN_CHECKSUM_VALID = 0x00000004, + LCN_IS_VALID = 0x00000008, + LCN_IS_STREAM_RESERVED = 0x00000010, + LCN_IS_READ_ONLY = 0x00000020 +}; +typedef ULONG LCN_WEAK_REFERENCE_STATE; +typedef LCN_WEAK_REFERENCE_STATE *PLCN_WEAK_REFERENCE_STATE; + +typedef struct _LCN_WEAK_REFERENCE_BUFFER +{ + // + // The LCN here acts as a token to reference the weak reference on a given + // file system cluster. It doesn't mean much else to an application. + // + LONGLONG Lcn; + LONGLONG LengthInClusters; + ULONG ReferenceCount; + LCN_WEAK_REFERENCE_STATE State; // enum _LCN_WEAK_REFERENCE_STATE +} LCN_WEAK_REFERENCE_BUFFER, *PLCN_WEAK_REFERENCE_BUFFER; + +#endif (NTDDI_VERSION >= NTDDI_WIN10_NI) + +/* FSCTL_CREATE_LCN_WEAK_REFERENCE ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +typedef ULONG LCN_WEAK_REFERENCE_CREATE_FLAGS; +typedef LCN_WEAK_REFERENCE_CREATE_FLAGS *PLCN_WEAK_REFERENCE_CREATE_FLAGS; + +typedef struct _LCN_WEAK_REFERENCE_CREATE_INPUT_BUFFER +{ + LONGLONG Offset; + LONGLONG Length; + ULONG Flags; + ULONG Reserved; +} LCN_WEAK_REFERENCE_CREATE_INPUT_BUFFER, *PLCN_WEAK_REFERENCE_CREATE_INPUT_BUFFER; + +typedef struct _LCN_WEAK_REFERENCE_VCN_MAPPING +{ + LONGLONG Vcn; + LONGLONG Lcn; + LONGLONG CountOfRange; +} LCN_WEAK_REFERENCE_VCN_MAPPING, *PLCN_WEAK_REFERENCE_VCN_MAPPING; + +typedef struct _LCN_WEAK_REFERENCE_CREATE_OUTPUT_BUFFER +{ + ULONG MappingCount; + LCN_WEAK_REFERENCE_VCN_MAPPING VcnLcnMappings[ANYSIZE_ARRAY]; +} LCN_WEAK_REFERENCE_CREATE_OUTPUT_BUFFER, *PLCN_WEAK_REFERENCE_CREATE_OUTPUT_BUFFER; + +#endif (NTDDI_VERSION >= NTDDI_WIN10_NI) + +/* FSCTL_CLEAR_LCN_WEAK_REFERENCE ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +typedef struct _LCN_WEAK_REFERENCE_RANGE +{ + LONGLONG StartOfRange; + LONGLONG CountOfRange; +} LCN_WEAK_REFERENCE_RANGE, *PLCN_WEAK_REFERENCE_RANGE; + +typedef struct _LCN_WEAK_REFERENCE_CLEAR_INPUT_BUFFER +{ + ULONG RangeCount; + LCN_WEAK_REFERENCE_RANGE Ranges[ANYSIZE_ARRAY]; +} LCN_WEAK_REFERENCE_CLEAR_INPUT_BUFFER, *PLCN_WEAK_REFERENCE_CLEAR_INPUT_BUFFER; + +#endif // (NTDDI_VERSION >= NTDDI_WIN10_NI) + +/* FSCTL_REFS_SET_VOLUME_DEDUP_INFO ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +#define REFS_VOLUME_DEDUP_INFO_INPUT_BUFFER_VERSION_V1 1 +#define REFS_VOLUME_DEDUP_INFO_INPUT_BUFFER_VERSION 2 + +typedef struct _REFS_VOLUME_DEDUP_INFO_INPUT_BUFFER +{ + ULONG Version; + + BOOLEAN SetDedupState; + BOOLEAN Enable; + + BOOLEAN SetWeakRefState; + BOOLEAN EnableWeakRef; + + BOOLEAN SetDirtyRangeTrackingState; + BOOLEAN EnableDirtyRangeTracking; + + BOOLEAN SetWeakRefInconsistentState; + BOOLEAN SetWeakRefInconsistent; +} REFS_VOLUME_DEDUP_INFO_INPUT_BUFFER, *PREFS_VOLUME_DEDUP_INFO_INPUT_BUFFER; + +#endif // (NTDDI_VERSION >= NTDDI_WIN10_NI) + +/* FSCTL_REFS_QUERY_VOLUME_DEDUP_INFO */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +#define REFS_VOLUME_DEDUP_INFO_OUTPUT_BUFFER_VERSION_V1 1 +#define REFS_VOLUME_DEDUP_INFO_OUTPUT_BUFFER_VERSION 2 + +typedef struct _REFS_VOLUME_DEDUP_INFO_OUTPUT_BUFFER +{ + ULONG Version; + BOOLEAN Enabled; + BOOLEAN EnabledWeakRef; + BOOLEAN EnabledDirtyRangeTracking; + BOOLEAN WeakRefInconsistent; + BOOLEAN IsClustered; + ULONG VolumeIdHash; + GUID VolumeGuid; + GUID VolumeUniqueGuid; +} REFS_VOLUME_DEDUP_INFO_OUTPUT_BUFFER, *PREFS_VOLUME_DEDUP_INFO_OUTPUT_BUFFER; + +#endif // (NTDDI_VERSION >= NTDDI_WIN10_NI) + +/* FSCTL_REFS_QUERY_VOLUME_TOTAL_SHARED_LCNS ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +#define REFS_QUERY_VOLUME_TOTAL_SHARED_LCNS_OUTPUT_BUFFER_VERSION 1 + +typedef struct _REFS_QUERY_VOLUME_TOTAL_SHARED_LCNS_OUTPUT_BUFFER +{ + ULONG Version; + ULONGLONG TotalSharedLcns; +} REFS_QUERY_VOLUME_TOTAL_SHARED_LCNS_OUTPUT_BUFFER, *PREFS_QUERY_VOLUME_TOTAL_SHARED_LCNS_OUTPUT_BUFFER; + +#endif // (NTDDI_VERSION >= NTDDI_WIN10_NI) + +#if (NTDDI_VERSION >= NTDDI_WIN10_FE) +typedef struct _SET_CACHED_RUNS_STATE_INPUT_BUFFER +{ + BOOLEAN Enable; +} SET_CACHED_RUNS_STATE_INPUT_BUFFER, *PSET_CACHED_RUNS_STATE_INPUT_BUFFER; +#endif + +/* FSCTL_REFS_SET_VOLUME_COMPRESSION_INFO ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +typedef enum _REFS_COMPRESSION_FORMATS +{ + REFS_COMPRESSION_FORMAT_UNCHANGED = 0, + REFS_COMPRESSION_FORMAT_UNKNOWN = 1, + REFS_COMPRESSION_FORMAT_UNCOMPRESSED = 2, + REFS_COMPRESSION_FORMAT_LZ4 = 3, + REFS_COMPRESSION_FORMAT_ZSTD = 4, +} REFS_COMPRESSION_FORMATS, *PREFS_COMPRESSION_FORMATS; + +typedef enum _REFS_SET_VOLUME_COMPRESSION_INFO_FLAGS +{ + REFS_SET_VOLUME_COMPRESSION_INFO_FLAG_START_COMPRESSION = 0x00000001, + REFS_SET_VOLUME_COMPRESSION_INFO_FLAG_STOP_COMPRESSION = 0x00000002, + REFS_SET_VOLUME_COMPRESSION_INFO_FLAG_GC_ONLY = 0x00000004, +#if (NTDDI_VERSION >= NTDDI_WIN10_GE) + REFS_SET_VOLUME_COMPRESSION_INFO_FLAG_ENABLE_COMPRESSION = 0x00000008, + REFS_SET_VOLUME_COMPRESSION_INFO_FLAG_DISABLE_COMPRESSION = 0x00000010, +#endif + REFS_SET_VOLUME_COMPRESSION_INFO_FLAG_MAX = 0x00000010, +} REFS_SET_VOLUME_COMPRESSION_INFO_FLAGS, *PREFS_SET_VOLUME_COMPRESSION_INFO_FLAGS; + +#define REFS_SET_VOLUME_COMPRESSION_INFO_INPUT_BUFFER_VERSION 1 + +typedef struct _REFS_SET_VOLUME_COMPRESSION_INFO_INPUT_BUFFER +{ + ULONG Version; + + // + // The compression format for the volume. If this value is + // REFS_COMPRESSION_FORMAT_UNCHANGED then no compression + // parameters on the volume are changed. + // + REFS_COMPRESSION_FORMATS CompressionFormat; + + // + // The compression level to use for the selected compression + // format. This is compression format dependant. + // + SHORT CompressionLevel; + + // + // The compression chunk size in bytes. Multiple of the volumes + // cluster size and power of two. + // + ULONG CompressionChunkSizeBytes; + + // + // REFS_SET_VOLUME_COMPRESSION_INFO_FLAGS + // + ULONG Flags; + + // + // Tuning parameters for compression, recompression, and decompression. + // + ULONG CompressionTuning; + ULONG RecompressionTuning; + ULONG DecompressionTuning; + + // + // Reserved for future implementations. Zeroed. + // + ULONG Reserved[6]; +} REFS_SET_VOLUME_COMPRESSION_INFO_INPUT_BUFFER, *PREFS_SET_VOLUME_COMPRESSION_INFO_INPUT_BUFFER; + +#endif // (NTDDI_VERSION >= NTDDI_WIN10_NI) + +/* FSCTL_REFS_QUERY_VOLUME_COMPRESSION_INFO ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +typedef enum _REFS_QUERY_VOLUME_COMPRESSION_INFO_FLAGS +{ + REFS_QUERY_VOLUME_COMPRESSION_INFO_FLAGS_RUNNING = 0x00000001, + REFS_QUERY_VOLUME_COMPRESSION_INFO_FLAGS_STOPPED = 0x00000002 +} REFS_QUERY_VOLUME_COMPRESSION_INFO_FLAGS, *PREFS_QUERY_VOLUME_COMPRESSION_INFO_FLAGS; + +#define REFS_QUERY_VOLUME_COMPRESSION_INFO_OUTPUT_BUFFER_VERSION 1 + +typedef struct _REFS_QUERY_VOLUME_COMPRESSION_INFO_OUTPUT_BUFFER +{ + ULONG Version; + + // + // The default compression format for the volume. + // + REFS_COMPRESSION_FORMATS DefaultCompressionFormat; + + // + // The default compression level for the volume. + // + SHORT DefaultCompressionLevel; + + // + // The default compression chunk size in bytes for the volume. + // + ULONG DefaultCompressionChunkSizeBytes; + + // + // The volume cluster size in bytes. + // + ULONG VolumeClusterSizeBytes; + + // + // The total number of clusters on the volume. + // + ULONGLONG TotalVolumeClusters; + + // + // The total number of committed allocated clusters on the volume. + // + ULONGLONG TotalAllocatedClusters; + + // + // The total number of allocated clusters on the volume that + // are compressible. + // + ULONGLONG TotalCompressibleClustersAllocated; + + // + // The total number of compressible clusters that are still + // referenced in the namespace. This is always less or equal than + // TotalCompressibleClusters, and the delta of the two yields + // the total number of clusters that can be reclaimed by + // recompressing the volume. + // + ULONGLONG TotalCompressibleClustersInUse; + + // + // The total number of compressed clusters allocated on the volume. + // + ULONGLONG TotalCompressedClusters; + + // + // REFS_QUERY_VOLUME_COMPRESSION_INFO_FLAGS + // + ULONG Flags; + + // + // The tuning parameters as stored on the volume. + // + ULONG CompressionTuning; + ULONG RecompressionTuning; + ULONG DecompressionTuning; + + // + // The last status code reported by volume compression. + // + NTSTATUS LastCompressionStatus; + + // + // Reserved for future implementations. Filled with zeroes. + // + ULONG Reserved[8]; +} REFS_QUERY_VOLUME_COMPRESSION_INFO_OUTPUT_BUFFER, *PREFS_QUERY_VOLUME_COMPRESSION_INFO_OUTPUT_BUFFER; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN10_NI) + +/* FSCTL_REFS_SET_VOLUME_IO_METRICS_INFO ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN11_ZN) + +#define REFS_SET_VOLUME_IO_METRICS_INFO_INPUT_BUFFER_VERSION 1 + +typedef struct _REFS_SET_VOLUME_IO_METRICS_INFO_INPUT_BUFFER +{ + ULONG Version; + + ULONG GlobalSecondsToTrack; + ULONG MetricsPeriodicitySeconds; + ULONG MetricsGenerationsPerContainer; + + ULONG Reserved[8]; +} REFS_SET_VOLUME_IO_METRICS_INFO_INPUT_BUFFER, *PREFS_SET_VOLUME_IO_METRICS_INFO_INPUT_BUFFER; + +#endif + +/* FSCTL_REFS_QUERY_VOLUME_IO_METRICS_INFO ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN11_ZN) + +#define REFS_QUERY_VOLUME_IO_METRICS_INFO_INPUT_BUFFER_VERSION 1 +#define REFS_QUERY_VOLUME_IO_METRICS_INFO_OUTPUT_BUFFER_VERSION 1 + +typedef enum _REFS_QUERY_VOLUME_IO_METRICS_INFO_QUERY_TYPE +{ + REFS_QUERY_VOLUME_IO_METRICS_INFO_QUERY_TYPE_PARAMETERS = 1, + REFS_QUERY_VOLUME_IO_METRICS_INFO_QUERY_TYPE_METRICS_DATA = 2, +} REFS_QUERY_VOLUME_IO_METRICS_INFO_QUERY_TYPE, *PREFS_QUERY_VOLUME_IO_METRICS_INFO_QUERY_TYPE; + +typedef struct _REFS_QUERY_VOLUME_IO_METRICS_INFO_INPUT_BUFFER +{ + ULONG Version; + REFS_QUERY_VOLUME_IO_METRICS_INFO_QUERY_TYPE QueryType; + ULONG Reserved[6]; + union + { + ULONGLONG UnusedAlign; + struct + { + ULONG Reserved[6]; + } Parameters; + struct + { + ULONGLONG ResumeKeyBlob[2]; + ULONG Reserved[6]; + } MetricsData; + }; +} REFS_QUERY_VOLUME_IO_METRICS_INFO_INPUT_BUFFER, *PREFS_QUERY_VOLUME_IO_METRICS_INFO_INPUT_BUFFER; + +typedef struct _REFS_QUERY_VOLUME_IO_METRICS_METRICS_DATA +{ + ULONGLONG PlaceHolder; +} REFS_QUERY_VOLUME_IO_METRICS_METRICS_DATA, *PREFS_QUERY_VOLUME_IO_METRICS_METRICS_DATA; + +typedef struct _REFS_QUERY_VOLUME_IO_METRICS_INFO_OUTPUT_BUFFER +{ + ULONG Version; + REFS_QUERY_VOLUME_IO_METRICS_INFO_QUERY_TYPE QueryType; + ULONG Reserved[6]; + union + { + ULONGLONG UnusedAlign; + struct + { + ULONG GlobalSecondsToTrack; + ULONG MetricsPeriodicitySeconds; + ULONG MetricsGenerationsPerContainer; + ULONG Reserved[6]; + } Parameters; + struct + { + ULONG EntryCount; + ULONGLONG ResumeKeyBlob[2]; + ULONG Reserved[6]; + REFS_QUERY_VOLUME_IO_METRICS_METRICS_DATA Metrics[ANYSIZE_ARRAY]; + } MetricsData; + }; +} REFS_QUERY_VOLUME_IO_METRICS_INFO_OUTPUT_BUFFER, *PREFS_QUERY_VOLUME_IO_METRICS_INFO_OUTPUT_BUFFER; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN11_ZN) + +/* FSCTL_REFS_SET_ROLLBACK_PROTECTION_INFO ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN11_GE) + +#define REFS_SET_ROLLBACK_PROTECTION_INFO_INPUT_BUFFER_VERSION 1 + +typedef struct _REFS_SET_ROLLBACK_PROTECTION_INFO_INPUT_BUFFER +{ + ULONG Version; + BOOLEAN FailMountOnMismatch; + ULONG CustomPayloadLength; + ULONG CustomPayloadOffset; +} REFS_SET_ROLLBACK_PROTECTION_INFO_INPUT_BUFFER, *PREFS_SET_ROLLBACK_PROTECTION_INFO_INPUT_BUFFER; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN11_GE) + +/* FSCTL_REFS_QUERY_ROLLBACK_PROTECTION_INFO ntifs.h */ + +#if (NTDDI_VERSION >= NTDDI_WIN11_GE) + +#define REFS_QUERY_ROLLBACK_PROTECTION_INFO_OUTPUT_BUFFER_VERSION 1 + +typedef struct _REFS_QUERY_ROLLBACK_PROTECTION_INFO_OUTPUT_BUFFER +{ + ULONG Version; + GUID VolumeGuid; + GUID RollbackProtectionGuid; + BOOLEAN FailMountOnMismatch; + ULONGLONG FrozenVirtualClock; + ULONGLONG CurrentVirtualClock; + USHORT ChecksumType; + ULONG ChecksumLength; + ULONG ChecksumOffset; + ULONG CustomPayloadLength; + ULONG CustomPayloadOffset; +} REFS_QUERY_ROLLBACK_PROTECTION_INFO_OUTPUT_BUFFER, *PREFS_QUERY_ROLLBACK_PROTECTION_INFO_OUTPUT_BUFFER; + +#endif // #if (NTDDI_VERSION >= NTDDI_WIN11_GE) + +/* IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES ntifs.h */ + +#define VOLSNAPCONTROLTYPE 0x00000053 // 'S' +#define IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES CTL_CODE(VOLSNAPCONTROLTYPE, 0, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) + +#pragma endregion + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Ke.h b/Source/Include/KNSoft/NDK/NT/Ke.h new file mode 100644 index 0000000..efe5555 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Ke.h @@ -0,0 +1,25 @@ +#pragma once + +#include "./MinDef.h" + +EXTERN_C_START + +/* wdm.h */ + +#define LOW_PRIORITY 0 // Lowest thread priority level +#define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level +#define HIGH_PRIORITY 31 // Highest thread priority level +#define MAXIMUM_PRIORITY 32 // Number of thread priority levels + +#define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects + +#define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended + +/* wdm.h */ +typedef enum _KINTERRUPT_MODE +{ + LevelSensitive, + Latched +} KINTERRUPT_MODE; + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Macro.h b/Source/Include/KNSoft/NDK/NT/Macro.h new file mode 100644 index 0000000..81637a1 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Macro.h @@ -0,0 +1,161 @@ +#pragma once + +#include "MinDef.h" +#include "./Mm.h" + +#pragma region Assertion + +#if defined(_PREFAST_) +#define NT_ANALYSIS_ASSUME(_exp) _Analysis_assume_(_exp) +#else +#if DBG +#define NT_ANALYSIS_ASSUME(_exp) ((void) 0) +#else +#define NT_ANALYSIS_ASSUME(_exp) __noop(_exp) +#endif +#endif + +#define NT_ASSERT_ACTION(_exp) \ + ((!(_exp)) ? \ + (__annotation(L"Debug", L"AssertFail", L## #_exp), \ + DbgRaiseAssertionFailure(), FALSE) : \ + TRUE) + +#define NT_ASSERTMSG_ACTION(_msg, _exp) \ + ((!(_exp)) ? \ + (__annotation(L"Debug", L"AssertFail", L##_msg), \ + DbgRaiseAssertionFailure(), FALSE) : \ + TRUE) + +#define NT_ASSERTMSGW_ACTION(_msg, _exp) \ + ((!(_exp)) ? \ + (__annotation(L"Debug", L"AssertFail", _msg), \ + DbgRaiseAssertionFailure(), FALSE) : \ + TRUE) + +#if DBG + +#define NT_ASSERT_ASSUME(_exp) \ + (NT_ANALYSIS_ASSUME(_exp), NT_ASSERT_ACTION(_exp)) +#define NT_ASSERTMSG_ASSUME(_msg, _exp) \ + (NT_ANALYSIS_ASSUME(_exp), NT_ASSERTMSG_ACTION(_msg, _exp)) +#define NT_ASSERTMSGW_ASSUME(_msg, _exp) \ + (NT_ANALYSIS_ASSUME(_exp), NT_ASSERTMSGW_ACTION(_msg, _exp)) + +#define NT_ASSERT_NOASSUME NT_ASSERT_ASSUME +#define NT_ASSERTMSG_NOASSUME NT_ASSERTMSG_ASSUME +#define NT_ASSERTMSGW_NOASSUME NT_ASSERTMSGW_ASSUME + +#define NT_VERIFY NT_ASSERT +#define NT_VERIFYMSG NT_ASSERTMSG +#define NT_VERIFYMSGW NT_ASSERTMSGW + +#else // DBG + +#define NT_ASSERT_ASSUME(_exp) (NT_ANALYSIS_ASSUME(_exp), 0) +#define NT_ASSERTMSG_ASSUME(_msg, _exp) (NT_ANALYSIS_ASSUME(_exp), 0) +#define NT_ASSERTMSGW_ASSUME(_msg, _exp) (NT_ANALYSIS_ASSUME(_exp), 0) + +#define NT_ASSERT_NOASSUME(_exp) ((void) 0) +#define NT_ASSERTMSG_NOASSUME(_msg, _exp) ((void) 0) +#define NT_ASSERTMSGW_NOASSUME(_msg, _exp) ((void) 0) + +#define NT_VERIFY(_exp) (NT_ANALYSIS_ASSUME(_exp), ((_exp) ? TRUE : FALSE)) +#define NT_VERIFYMSG(_msg, _exp ) (NT_ANALYSIS_ASSUME(_exp), ((_exp) ? TRUE : FALSE)) +#define NT_VERIFYMSGW(_msg, _exp) (NT_ANALYSIS_ASSUME(_exp), ((_exp) ? TRUE : FALSE)) + +#endif // DBG + +#define NT_FRE_ASSERT(_exp) (NT_ANALYSIS_ASSUME(_exp), NT_ASSERT_ACTION(_exp)) +#define NT_FRE_ASSERTMSG(_msg, _exp) (NT_ANALYSIS_ASSUME(_exp), NT_ASSERTMSG_ACTION(_msg, _exp)) +#define NT_FRE_ASSERTMSGW(_msg, _exp) (NT_ANALYSIS_ASSUME(_exp), NT_ASSERTMSGW_ACTION(_msg, _exp)) + +#ifdef NT_ASSERT_ALWAYS_ASSUMES +#define NT_ASSERT NT_ASSERT_ASSUME +#define NT_ASSERTMSG NT_ASSERTMSG_ASSUME +#define NT_ASSERTMSGW NT_ASSERTMSGW_ASSUME +#else +#define NT_ASSERT NT_ASSERT_NOASSUME +#define NT_ASSERTMSG NT_ASSERTMSG_NOASSUME +#define NT_ASSERTMSGW NT_ASSERTMSGW_NOASSUME +#endif + +#pragma endregion wdm.h + +#pragma region Align & Round + +#undef ALIGN_DOWN_BY +#undef ALIGN_UP_BY +#undef ALIGN_DOWN_POINTER_BY +#undef ALIGN_UP_POINTER_BY +#undef ALIGN_DOWN +#undef ALIGN_UP +#undef ALIGN_DOWN_POINTER +#undef ALIGN_UP_POINTER + +#define ALIGN_DOWN_BY(length, alignment) \ + ((ULONG_PTR)(length) & ~((ULONG_PTR)(alignment) - 1)) + +#define ALIGN_UP_BY(length, alignment) \ + (ALIGN_DOWN_BY(((ULONG_PTR)(length) + (alignment) - 1), alignment)) + +#define ALIGN_DOWN_POINTER_BY(address, alignment) \ + ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)(alignment) - 1))) + +#define ALIGN_UP_POINTER_BY(address, alignment) \ + (ALIGN_DOWN_POINTER_BY(((ULONG_PTR)(address) + (alignment) - 1), alignment)) + +#define ALIGN_DOWN(length, type) \ + ALIGN_DOWN_BY(length, sizeof(type)) + +#define ALIGN_UP(length, type) \ + ALIGN_UP_BY(length, sizeof(type)) + +#define ALIGN_DOWN_POINTER(address, type) \ + ALIGN_DOWN_POINTER_BY(address, sizeof(type)) + +#define ALIGN_UP_POINTER(address, type) \ + ALIGN_UP_POINTER_BY(address, sizeof(type)) + +#define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) +#define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0)) +#define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1))) +#define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1))) +#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) ((BYTE_OFFSET (Va) + ((SIZE_T) (Size)) + (PAGE_SIZE - 1)) >> PAGE_SHIFT) + +#pragma endregion wdm.h + +#pragma region + +#define Add2Ptr(P,I) ((PVOID)((PUCHAR)(P) + (I))) +#define PtrOffset(B,O) ((ULONG)((ULONG_PTR)(O) - (ULONG_PTR)(B))) + +#define ROUND_TO_SIZE(_length, _alignment) \ + ((((ULONG_PTR)(_length)) + ((_alignment)-1)) & ~(ULONG_PTR)((_alignment) - 1)) + +#define IS_ALIGNED(_pointer, _alignment) \ + ((((ULONG_PTR)(_pointer)) & ((_alignment) - 1)) == 0) + +#pragma endregion fltKernel.h + +#pragma region + +#ifndef FIELD_SIZE +#define FIELD_SIZE(type, field) (sizeof(((type *)0)->field)) +#endif + +#if defined (_WIN64) +#define BitScanReverseSizeT BitScanReverse64 +#define BitScanForwardSizeT BitScanForward64 +#else +#define BitScanReverseSizeT BitScanReverse +#define BitScanForwardSizeT BitScanForward +#endif + +#if DBG +#define IF_DEBUG if (TRUE) +#else +#define IF_DEBUG if (FALSE) +#endif + +#pragma endregion wdm.h diff --git a/Source/Include/KNSoft/NDK/NT/MinDef.h b/Source/Include/KNSoft/NDK/NT/MinDef.h new file mode 100644 index 0000000..ea934e7 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/MinDef.h @@ -0,0 +1,17 @@ +/* Supersede minwindef.h and include ntstatus.h */ + +#pragma once + +#include "./Private/TargetArch.h" + +#include "./Private/Winnt_Around.h" +#include +#include "./Private/Winnt_Around.h" + +#include "./Private/Ntdef_Around.h" +#include +#include "./Private/Ntdef_Around.h" + +#include + +#include "./Macro.h" diff --git a/Source/Include/KNSoft/NDK/NT/Mm.h b/Source/Include/KNSoft/NDK/NT/Mm.h new file mode 100644 index 0000000..744115d --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Mm.h @@ -0,0 +1,47 @@ +#pragma once + +#include "./MinDef.h" + +/* ntddk.h */ +#define MM_LOWEST_USER_ADDRESS ((PVOID)(LONG_PTR)0x10000) + +/* wdm.h */ +#define PAGE_SIZE 0x1000 +#define PAGE_SHIFT 12L + +/* WDK/KNSoft.NDK */ +#define MM_SHARED_USER_DATA_VA 0x7FFE0000 + +#define MM_ALLOCATION_GRANULARITY 0x10000 + +#if defined(_WIN64) +#define MM_HIGHEST_USER_ADDRESS ((PVOID)0x000007FFFFFEFFFFULL) +#else +#define MM_HIGHEST_USER_ADDRESS ((PVOID)0x7FFEFFFFUL) +#endif + +#pragma region ASLR + +/* + * ASLR initialization constants, see: + * "Image randomization." Microsoft Windows Internals + * ntoskrnl.exe!MiInitializeRelocations + */ + +#if defined(_WIN64) + +/* [0x00007FF7FFFF0000 ... 0x00007FFFFFFF0000], 32G */ + +#define MI_ASLR_BITMAP_SIZE 0x10000 +#define MI_ASLR_HIGHEST_SYSTEM_RANGE_ADDRESS ((PVOID)0x00007FFFFFFF0000ULL) + +#else + +/* [0x50000000 ... 0x78000000], 640M */ + +#define MI_ASLR_BITMAP_SIZE 0x500 +#define MI_ASLR_HIGHEST_SYSTEM_RANGE_ADDRESS ((PVOID)0x78000000UL) + +#endif + +#pragma endregion KNSoft.NDK diff --git a/Source/Include/KNSoft/NDK/NT/NT.h b/Source/Include/KNSoft/NDK/NT/NT.h new file mode 100644 index 0000000..e7dac1d --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/NT.h @@ -0,0 +1,100 @@ +#pragma once + +#define _DEFINED__WNF_STATE_NAME + +#ifndef _KNSOFT_NDK_NO_EXTENSION +#include "./Extension/Runtime.h" +#include "./Extension/Security.h" +#endif + +#include "./MinDef.h" +#include "./Macro.h" +#include "./Addendum.h" + +#include +#include +#include +#include + +#pragma region phnt + +#ifndef PHNT_MODE +#if defined(_KERNEL_MODE) +#define PHNT_MODE PHNT_MODE_KERNEL +#else +#define PHNT_MODE PHNT_MODE_USER +#endif +#endif + +#ifndef PHNT_VERSION +#if (NTDDI_VERSION < NTDDI_WINXP) +#define PHNT_VERSION PHNT_WIN2K +#elif (NTDDI_VERSION < NTDDI_WS03) +#define PHNT_VERSION PHNT_WINXP +#elif (NTDDI_VERSION < NTDDI_WIN6) +#define PHNT_VERSION PHNT_WS03 +#elif (NTDDI_VERSION < NTDDI_WIN7) +#define PHNT_VERSION PHNT_VISTA +#elif (NTDDI_VERSION < NTDDI_WIN8) +#define PHNT_VERSION PHNT_WIN7 +#elif (NTDDI_VERSION < NTDDI_WINBLUE) +#define PHNT_VERSION PHNT_WIN8 +#elif (NTDDI_VERSION < NTDDI_WINTHRESHOLD) +#define PHNT_VERSION PHNT_WINBLUE +#elif (NTDDI_VERSION < NTDDI_WIN10_TH2) +#define PHNT_VERSION PHNT_THRESHOLD +#elif (NTDDI_VERSION < NTDDI_WIN10_RS1) +#define PHNT_VERSION PHNT_THRESHOLD2 +#elif (NTDDI_VERSION < NTDDI_WIN10_RS2) +#define PHNT_VERSION PHNT_REDSTONE +#elif (NTDDI_VERSION < NTDDI_WIN10_RS3) +#define PHNT_VERSION PHNT_REDSTONE2 +#elif (NTDDI_VERSION < NTDDI_WIN10_RS4) +#define PHNT_VERSION PHNT_REDSTONE3 +#elif (NTDDI_VERSION < NTDDI_WIN10_RS5) +#define PHNT_VERSION PHNT_REDSTONE4 +#elif (NTDDI_VERSION < NTDDI_WIN10_19H1) +#define PHNT_VERSION PHNT_REDSTONE5 +#elif (NTDDI_VERSION < NTDDI_WIN10_VB) +#define PHNT_VERSION PHNT_19H1 +#elif (NTDDI_VERSION < NTDDI_WIN10_MN) +#define PHNT_VERSION PHNT_19H2 +#elif (NTDDI_VERSION < NTDDI_WIN10_FE) +#define PHNT_VERSION PHNT_20H1 +#elif (NTDDI_VERSION < NTDDI_WIN10_CO) +#define PHNT_VERSION PHNT_20H2 +#elif (NTDDI_VERSION < NTDDI_WIN10_NI) +#define PHNT_VERSION PHNT_21H1 +#elif (NTDDI_VERSION < NTDDI_WIN10_CU) +#define PHNT_VERSION PHNT_WIN10_21H2 +#elif (NTDDI_VERSION < NTDDI_WIN11_ZN) +#define PHNT_VERSION PHNT_WIN10_22H2 +#elif (NTDDI_VERSION < NTDDI_WIN11_GA) +#define PHNT_VERSION PHNT_WIN11_22H2 +#elif (NTDDI_VERSION < NTDDI_WIN11_GE) +#define PHNT_VERSION PHNT_WIN11_23H2 +#else +#define PHNT_VERSION PHNT_WIN11_24H2 +#endif +#endif + +#include "../3rdParty/phnt/phnt.h" + +#undef RTL_SOFT_ASSERT +#undef RTL_SOFT_ASSERTMSG + +#pragma endregion + +#pragma region KNSoft.NDK + +#include "./Dbg.h" +#include "./Ex.h" +#include "./Io.h" +#include "./Ke.h" +#include "./Mm.h" +#include "./Ob.h" +#include "./Se.h" +#include "./Rtl/Rtl.h" +#include "./Wow/Wow.h" + +#pragma endregion diff --git a/Source/Include/KNSoft/NDK/NT/Ob.h b/Source/Include/KNSoft/NDK/NT/Ob.h new file mode 100644 index 0000000..33cde2b --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Ob.h @@ -0,0 +1,9 @@ +#pragma once + +#include "./MinDef.h" + +EXTERN_C_START + +#define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\') + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Private/Ntdef_Around.h b/Source/Include/KNSoft/NDK/NT/Private/Ntdef_Around.h new file mode 100644 index 0000000..f845d89 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Private/Ntdef_Around.h @@ -0,0 +1,109 @@ +/* Include this file before and after ntdef.h if winnt.h is already included */ + +#ifndef _NTDEF_ + +#undef LANGIDFROMLCID +#undef MAKELANGID +#undef MAKELCID +#undef MAKESORTLCID +#undef MAX_NATURAL_ALIGNMENT +#undef PRIMARYLANGID +#undef SUBLANGID +#undef PROBE_ALIGNMENT +#undef PROBE_ALIGNMENT32 +#undef SORTIDFROMLCID +#undef SORTVERSIONFROMLCID +#undef UNICODE_STRING_MAX_BYTES + +#define _LIST_ENTRY _MS_LIST_ENTRY +#define LIST_ENTRY MS_LIST_ENTRY +#define PLIST_ENTRY PMS_LIST_ENTRY +#define PRLIST_ENTRY PRMS_LIST_ENTRY +#define LIST_ENTRY32 MS_LIST_ENTRY32 +#define PLIST_ENTRY32 PMS_LIST_ENTRY32 +#define LIST_ENTRY64 MS_LIST_ENTRY64 +#define PLIST_ENTRY64 PMS_LIST_ENTRY64 +#define _SINGLE_LIST_ENTRY _MS_SINGLE_LIST_ENTRY +#define SINGLE_LIST_ENTRY MS_SINGLE_LIST_ENTRY +#define PSINGLE_LIST_ENTRY PMS_SINGLE_LIST_ENTRY +#define _LARGE_INTEGER _MS_LARGE_INTEGER +#define LARGE_INTEGER MS_LARGE_INTEGER +#define PLARGE_INTEGER PMS_LARGE_INTEGER +#define _ULARGE_INTEGER _MS_ULARGE_INTEGER +#define ULARGE_INTEGER MS_ULARGE_INTEGER +#define PULARGE_INTEGER PMS_ULARGE_INTEGER +#define _LUID _MS_LUID +#define LUID MS_LUID +#define PLUID PMS_LUID +#define _FLOAT128 _MS_FLOAT128 +#define FLOAT128 MS_FLOAT128 +#define PFLOAT128 PMS_FLOAT128 +#define _PROCESSOR_NUMBER _MS_PROCESSOR_NUMBER +#define PROCESSOR_NUMBER MS_PROCESSOR_NUMBER +#define PPROCESSOR_NUMBER PMS_PROCESSOR_NUMBER +#define _GROUP_AFFINITY _MS_GROUP_AFFINITY +#define GROUP_AFFINITY MS_GROUP_AFFINITY +#define PGROUP_AFFINITY PMS_GROUP_AFFINITY +#define _GROUP_AFFINITY32 _MS_GROUP_AFFINITY32 +#define GROUP_AFFINITY32 MS_GROUP_AFFINITY32 +#define PGROUP_AFFINITY32 PMS_GROUP_AFFINITY32 +#define _GROUP_AFFINITY64 _MS_GROUP_AFFINITY64 +#define GROUP_AFFINITY64 MS_GROUP_AFFINITY64 +#define PGROUP_AFFINITY64 PMS_GROUP_AFFINITY64 + +#if defined(_M_IX86) +#define Int64ShllMod32 MS_Int64ShllMod32 +#define Int64ShraMod32 MS_Int64ShraMod32 +#define Int64ShrlMod32 MS_Int64ShrlMod32 +#endif + +#define _ENUM_FLAG_SIZED_INTEGER _MS_ENUM_FLAG_SIZED_INTEGER +#define _ENUM_FLAG_INTEGER_FOR_SIZE _MS_ENUM_FLAG_INTEGER_FOR_SIZE + +#else + +#undef _ENUM_FLAG_SIZED_INTEGER +#undef _ENUM_FLAG_INTEGER_FOR_SIZE + +#undef Int64ShllMod32 +#undef Int64ShraMod32 +#undef Int64ShrlMod32 + +#undef _LIST_ENTRY +#undef LIST_ENTRY +#undef PLIST_ENTRY +#undef PRLIST_ENTRY +#undef LIST_ENTRY32 +#undef PLIST_ENTRY32 +#undef LIST_ENTRY64 +#undef PLIST_ENTRY64 +#undef _SINGLE_LIST_ENTRY +#undef SINGLE_LIST_ENTRY +#undef PSINGLE_LIST_ENTRY + +#undef _LARGE_INTEGER +#undef LARGE_INTEGER +#undef PLARGE_INTEGER +#undef _ULARGE_INTEGER +#undef ULARGE_INTEGER +#undef PULARGE_INTEGER +#undef _LUID +#undef LUID +#undef PLUID +#undef _FLOAT128 +#undef FLOAT128 +#undef PFLOAT128 +#undef _PROCESSOR_NUMBER +#undef PROCESSOR_NUMBER +#undef PPROCESSOR_NUMBER +#undef _GROUP_AFFINITY +#undef GROUP_AFFINITY +#undef PGROUP_AFFINITY +#undef _GROUP_AFFINITY32 +#undef GROUP_AFFINITY32 +#undef PGROUP_AFFINITY32 +#undef _GROUP_AFFINITY64 +#undef GROUP_AFFINITY64 +#undef PGROUP_AFFINITY64 + +#endif diff --git a/Source/Include/KNSoft/NDK/NT/Private/TargetArch.h b/Source/Include/KNSoft/NDK/NT/Private/TargetArch.h new file mode 100644 index 0000000..0356364 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Private/TargetArch.h @@ -0,0 +1,46 @@ +/* Patches #error "No Target Architecture" in ntdef.h and winnt.h */ + +#pragma once + +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && !defined(_ARM64EC_) && defined(_M_IX86) +#define _X86_ +#if !defined(_CHPE_X86_ARM64_) && defined(_M_HYBRID) +#define _CHPE_X86_ARM64_ +#endif +#endif + +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && (defined(_M_AMD64) || defined(_M_ARM64EC)) +#define _AMD64_ +#endif + +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && !defined(_ARM64EC_) && defined(_M_ARM) +#define _ARM_ +#endif + +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && !defined(_ARM64EC_) && defined(_M_ARM64) +#define _ARM64_ +#endif + +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_ARM_) && !defined(_ARM64_) && !defined(_ARM64EC_) && defined(_M_ARM64EC) +#define _ARM64EC_ +#endif + +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && !defined(_ARM64EC_) && defined(_M_M68K) +#define _68K_ +#endif + +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && !defined(_ARM64EC_) && defined(_M_MPPC) +#define _MPPC_ +#endif + +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && !defined(_ARM64EC_) && defined(_M_IA64) +#if !defined(_IA64_) +#define _IA64_ +#endif /* !_IA64_ */ +#endif + +#ifndef _MAC +#if defined(_68K_) || defined(_MPPC_) +#define _MAC +#endif +#endif diff --git a/Source/Include/KNSoft/NDK/NT/Private/Winnt_Around.h b/Source/Include/KNSoft/NDK/NT/Private/Winnt_Around.h new file mode 100644 index 0000000..752fcaf --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Private/Winnt_Around.h @@ -0,0 +1,16 @@ +/* Include this file before and after winnt.h */ + +#ifndef _WINNT_ + +#define WIN32_NO_STATUS + +#define PSID MS_PSID + +#else + +#undef WIN32_NO_STATUS + +#undef PSID +typedef SID* PSID; + +#endif diff --git a/Source/Include/KNSoft/NDK/NT/Rtl/Assertion.h b/Source/Include/KNSoft/NDK/NT/Rtl/Assertion.h new file mode 100644 index 0000000..c091dea --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Rtl/Assertion.h @@ -0,0 +1,47 @@ +#pragma once + +#include "../NT.h" + +EXTERN_C_START + +#pragma region Assert + +#if DBG + +#define ASSERT( exp ) \ + ((!(exp)) ? \ + (RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ),FALSE) : \ + TRUE) +#define ASSERTMSG( msg, exp ) \ + ((!(exp)) ? \ + (RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, (PSTR)msg ),FALSE) : \ + TRUE) +#define RTL_SOFT_ASSERT(_exp) \ + ((!(_exp)) ? \ + (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \ + TRUE) +#define RTL_SOFT_ASSERTMSG(_msg, _exp) \ + ((!(_exp)) ? \ + (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \ + TRUE) +#define RTL_VERIFY ASSERT +#define RTL_VERIFYMSG ASSERTMSG +#define RTL_SOFT_VERIFY RTL_SOFT_ASSERT +#define RTL_SOFT_VERIFYMSG RTL_SOFT_ASSERTMSG + +#else + +#define ASSERT(exp) ((void) 0) +#define ASSERTMSG(msg, exp) ((void) 0) +#define RTL_SOFT_ASSERT(_exp) ((void) 0) +#define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0) +#define RTL_VERIFY(exp) ((exp) ? TRUE : FALSE) +#define RTL_VERIFYMSG(msg, exp) ((exp) ? TRUE : FALSE) +#define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE) +#define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE) + +#endif // DBG + +#pragma endregion wdm.h + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Rtl/Memory.h b/Source/Include/KNSoft/NDK/NT/Rtl/Memory.h new file mode 100644 index 0000000..c48adbe --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Rtl/Memory.h @@ -0,0 +1,40 @@ +#pragma once + +#include "../MinDef.h" + +EXTERN_C_START + +#pragma region + +#define RtlCopyBytes RtlCopyMemory +#define RtlZeroBytes RtlZeroMemory +#define RtlFillBytes RtlFillMemory + +#if defined(_M_AMD64) || defined(_M_ARM64) + +NTSYSAPI +VOID +NTAPI +RtlCopyMemoryNonTemporal( + _Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, + _In_reads_bytes_(Length) CONST VOID UNALIGNED *Source, + _In_ SIZE_T Length); + +NTSYSAPI +VOID +NTAPI +RtlFillMemoryNonTemporal( + _Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, + _In_ SIZE_T Length, + _In_ CONST UCHAR Value); + +#else + +#define RtlCopyMemoryNonTemporal RtlCopyMemory +#define RtlFillMemoryNonTemporal RtlFillMemory + +#endif + +#pragma endregion wdm.h + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Rtl/Rtl.h b/Source/Include/KNSoft/NDK/NT/Rtl/Rtl.h new file mode 100644 index 0000000..e58da9e --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Rtl/Rtl.h @@ -0,0 +1,4 @@ +#pragma once + +#include "./Assertion.h" +#include "./Memory.h" diff --git a/Source/Include/KNSoft/NDK/NT/Se.h b/Source/Include/KNSoft/NDK/NT/Se.h new file mode 100644 index 0000000..6cff5c8 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Se.h @@ -0,0 +1,165 @@ +#pragma once + +#include "./MinDef.h" + +EXTERN_C_START + +/* ntifs.h */ +#define SeLengthSid( Sid ) (8 + (4 * ((SID*)Sid)->SubAuthorityCount)) + +/* ntifs.h */ +typedef struct _SE_EXPORTS +{ + // + // Privilege values + // + LUID SeCreateTokenPrivilege; + LUID SeAssignPrimaryTokenPrivilege; + LUID SeLockMemoryPrivilege; + LUID SeIncreaseQuotaPrivilege; + LUID SeUnsolicitedInputPrivilege; + LUID SeTcbPrivilege; + LUID SeSecurityPrivilege; + LUID SeTakeOwnershipPrivilege; + LUID SeLoadDriverPrivilege; + LUID SeCreatePagefilePrivilege; + LUID SeIncreaseBasePriorityPrivilege; + LUID SeSystemProfilePrivilege; + LUID SeSystemtimePrivilege; + LUID SeProfileSingleProcessPrivilege; + LUID SeCreatePermanentPrivilege; + LUID SeBackupPrivilege; + LUID SeRestorePrivilege; + LUID SeShutdownPrivilege; + LUID SeDebugPrivilege; + LUID SeAuditPrivilege; + LUID SeSystemEnvironmentPrivilege; + LUID SeChangeNotifyPrivilege; + LUID SeRemoteShutdownPrivilege; + + // + // Universally defined Sids + // + PSID SeNullSid; + PSID SeWorldSid; + PSID SeLocalSid; + PSID SeCreatorOwnerSid; + PSID SeCreatorGroupSid; + + // + // Nt defined Sids + // + PSID SeNtAuthoritySid; + PSID SeDialupSid; + PSID SeNetworkSid; + PSID SeBatchSid; + PSID SeInteractiveSid; + PSID SeLocalSystemSid; + PSID SeAliasAdminsSid; + PSID SeAliasUsersSid; + PSID SeAliasGuestsSid; + PSID SeAliasPowerUsersSid; + PSID SeAliasAccountOpsSid; + PSID SeAliasSystemOpsSid; + PSID SeAliasPrintOpsSid; + PSID SeAliasBackupOpsSid; + + // + // New Sids defined for NT5 + // + PSID SeAuthenticatedUsersSid; + PSID SeRestrictedSid; + PSID SeAnonymousLogonSid; + + // + // New Privileges defined for NT5 + // + LUID SeUndockPrivilege; + LUID SeSyncAgentPrivilege; + LUID SeEnableDelegationPrivilege; + + // + // New Sids defined for post-Windows 2000 + // + PSID SeLocalServiceSid; + PSID SeNetworkServiceSid; + + // + // New Privileges defined for post-Windows 2000 + // + LUID SeManageVolumePrivilege; + LUID SeImpersonatePrivilege; + LUID SeCreateGlobalPrivilege; + + // + // New Privileges defined for post Windows Server 2003 + // + LUID SeTrustedCredManAccessPrivilege; + LUID SeRelabelPrivilege; + LUID SeIncreaseWorkingSetPrivilege; + LUID SeTimeZonePrivilege; + LUID SeCreateSymbolicLinkPrivilege; + + // + // New Sids defined for post Windows Server 2003 + // + PSID SeIUserSid; + + // + // Mandatory Sids, ordered lowest to highest. + // + PSID SeUntrustedMandatorySid; + PSID SeLowMandatorySid; + PSID SeMediumMandatorySid; + PSID SeHighMandatorySid; + PSID SeSystemMandatorySid; + PSID SeOwnerRightsSid; + + // + // Package/Capability Sids. + // + PSID SeAllAppPackagesSid; + PSID SeUserModeDriversSid; + + // + // Process Trust Sids. + // + PSID SeProcTrustWinTcbSid; + + // + // Trusted Installer SID. + // + PSID SeTrustedInstallerSid; + + // + // New Privileges defined for Windows 10 + // + LUID SeDelegateSessionUserImpersonatePrivilege; + + // + // App Silo SID + // + PSID SeAppSiloSid; + + // + // App Silo Volume Root Minimal Capability SID + // + PSID SeAppSiloVolumeRootMinimalCapabilitySid; + + // + // App Silo Users Minimal Capability SID + // + PSID SeAppSiloProfilesRootMinimalCapabilitySid; + + // + // App Silo Prompt Access Capability SID + // + PSID SeAppSiloPromptForAccessCapabilitySid; + + // + // App Silo Access To Publisher Directory Capability SID + // + PSID SeAppSiloAccessToPublisherDirectoryCapabilitySid; +} SE_EXPORTS, *PSE_EXPORTS; + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Wow/Io.h b/Source/Include/KNSoft/NDK/NT/Wow/Io.h new file mode 100644 index 0000000..1d7e959 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Wow/Io.h @@ -0,0 +1,51 @@ +#pragma once + +#include "../MinDef.h" + +EXTERN_C_START + +#pragma region IO_STATUS_BLOCK[64/32] + +#if defined(_WIN64) + +typedef IO_STATUS_BLOCK IO_STATUS_BLOCK64; +#define Iosb64ToIosb(_iosb, _iosb64) { \ + (_iosb) = (_iosb64); \ +} +#define IosbToIosb64(_iosb64, _iosb) { \ + (_iosb64) = (_iosb); \ +} + +#else + +typedef struct _IO_STATUS_BLOCK64 +{ + union + { + NTSTATUS Status; + PVOID64 Pointer; + } DUMMYUNIONNAME; + ULONG64 Information; +} IO_STATUS_BLOCK64; + +#define Iosb64ToIosb(_iosb, _iosb64) { \ + (_iosb).Pointer = Ptr64ToPtr( (_iosb64).Pointer ); \ + (_iosb).Information = (ULONG_PTR)(_iosb64).Information; \ +} +#define IosbToIosb64(_iosb64, _iosb) { \ + (_iosb64).Pointer = PtrToPtr64( (_iosb).Pointer ); \ + (_iosb64).Information = (ULONG64)(_iosb).Information; \ +} + +#endif + +typedef IO_STATUS_BLOCK64 *PIO_STATUS_BLOCK64; +typedef struct _IO_STATUS_BLOCK32 +{ + NTSTATUS Status; + ULONG Information; +} IO_STATUS_BLOCK32, *PIO_STATUS_BLOCK32; + +#pragma endregion wdm.h + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Wow/Ldr.h b/Source/Include/KNSoft/NDK/NT/Wow/Ldr.h new file mode 100644 index 0000000..de20d10 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Wow/Ldr.h @@ -0,0 +1,110 @@ +#pragma once + +#include "../NT.h" + +EXTERN_C_START + +typedef struct _LDR_SERVICE_TAG_RECORD64 LDR_SERVICE_TAG_RECORD64, *PLDR_SERVICE_TAG_RECORD64; +struct _LDR_SERVICE_TAG_RECORD64 +{ + LDR_SERVICE_TAG_RECORD64* POINTER_64 Next; + ULONG ServiceTag; +}; + +typedef struct _LDRP_CSLIST64 +{ + SINGLE_LIST_ENTRY64* POINTER_64 Tail; +} LDRP_CSLIST64, *PLDRP_CSLIST64; + +typedef struct _LDR_DDAG_NODE64 +{ + LIST_ENTRY64 Modules; + LDR_SERVICE_TAG_RECORD64* POINTER_64 ServiceTagList; + ULONG LoadCount; + ULONG LoadWhileUnloadingCount; + ULONG LowestLink; + union + { + LDRP_CSLIST64 Dependencies; + SINGLE_LIST_ENTRY64 RemovalLink; + }; + LDRP_CSLIST64 IncomingDependencies; + LDR_DDAG_STATE State; + SINGLE_LIST_ENTRY64 CondenseLink; + ULONG PreorderNumber; +} LDR_DDAG_NODE64, *PLDR_DDAG_NODE64; + +typedef struct _LDR_DATA_TABLE_ENTRY64 +{ + LIST_ENTRY64 InLoadOrderModuleList; + LIST_ENTRY64 InMemoryOrderModuleList; + LIST_ENTRY64 InInitializationOrderModuleList; + VOID* POINTER_64 DllBase; + VOID* POINTER_64 EntryPoint; + ULONG SizeOfImage; + UNICODE_STRING64 FullDllName; + UNICODE_STRING64 BaseDllName; + union + { + UCHAR FlagGroup[4]; + ULONG Flags; + struct + { + ULONG PackagedBinary : 1; + ULONG MarkedForRemoval : 1; + ULONG ImageDll : 1; + ULONG LoadNotificationsSent : 1; + ULONG TelemetryEntryProcessed : 1; + ULONG ProcessStaticImport : 1; + ULONG InLegacyLists : 1; + ULONG InIndexes : 1; + ULONG ShimDll : 1; + ULONG InExceptionTable : 1; + ULONG ReservedFlags1 : 2; + ULONG LoadInProgress : 1; + ULONG LoadConfigProcessed : 1; + ULONG EntryProcessed : 1; + ULONG ProtectDelayLoad : 1; + ULONG ReservedFlags3 : 2; + ULONG DontCallForThreads : 1; + ULONG ProcessAttachCalled : 1; + ULONG ProcessAttachFailed : 1; + ULONG CorDeferredValidate : 1; + ULONG CorImage : 1; + ULONG DontRelocate : 1; + ULONG CorILOnly : 1; + ULONG ChpeImage : 1; + ULONG ChpeEmulatorImage : 1; + ULONG ReservedFlags5 : 1; + ULONG Redirected : 1; + ULONG ReservedFlags6 : 2; + ULONG CompatDatabaseProcessed : 1; + }; + }; + USHORT ObsoleteLoadCount; + USHORT TlsIndex; + LIST_ENTRY64 HashLinks; + ULONG TimeDateStamp; + ACTIVATION_CONTEXT64* POINTER_64 EntryPointActivationContext; + VOID* POINTER_64 Lock; + LDR_DDAG_NODE64* POINTER_64 DdagNode; + LIST_ENTRY64 NodeModuleLink; + struct LDRP_LOAD_CONTEXT* POINTER_64 LoadContext; + VOID* POINTER_64 ParentDllBase; + VOID* POINTER_64 SwitchBackContext; + RTL_BALANCED_NODE64 BaseAddressIndexNode; + RTL_BALANCED_NODE64 MappingInfoIndexNode; + ULONGLONG OriginalBase; + LARGE_INTEGER LoadTime; + ULONG BaseNameHashValue; + LDR_DLL_LOAD_REASON LoadReason; + ULONG ImplicitPathOptions; + ULONG ReferenceCount; + ULONG DependentLoadFlags; + UCHAR SigningLevel; + ULONG CheckSum; + VOID* POINTER_64 ActivePatchImageBase; + LDR_HOT_PATCH_STATE HotPatchState; +} LDR_DATA_TABLE_ENTRY64, *PLDR_DATA_TABLE_ENTRY64; + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Wow/Rtl.h b/Source/Include/KNSoft/NDK/NT/Wow/Rtl.h new file mode 100644 index 0000000..1cd505d --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Wow/Rtl.h @@ -0,0 +1,109 @@ +#pragma once + +#include "../MinDef.h" + +EXTERN_C_START + +typedef struct _SINGLE_LIST_ENTRY64 SINGLE_LIST_ENTRY64, *PSINGLE_LIST_ENTRY64; +struct _SINGLE_LIST_ENTRY64 +{ + SINGLE_LIST_ENTRY64* POINTER_64 Next; +}; + +#pragma region RTL_BITMAP[64/32] + +typedef struct _RTL_BITMAP64 +{ + ULONG SizeOfBitMap; + ULONG* POINTER_64 Buffer; +} RTL_BITMAP64, *PRTL_BITMAP64; + +typedef struct _RTL_BITMAP32 +{ + ULONG SizeOfBitMap; + ULONG* POINTER_32 Buffer; +} RTL_BITMAP32, *PRTL_BITMAP32; + +#pragma endregion + +#pragma region RTL_CRITICAL_SECTION[_DEBUG](64/32) + +typedef struct _RTL_CRITICAL_SECTION64 RTL_CRITICAL_SECTION64, *PRTL_CRITICAL_SECTION64; +typedef struct _RTL_CRITICAL_SECTION32 RTL_CRITICAL_SECTION32, *PRTL_CRITICAL_SECTION32; + +typedef struct _RTL_CRITICAL_SECTION_DEBUG64 +{ + WORD Type; + WORD CreatorBackTraceIndex; + RTL_CRITICAL_SECTION64* POINTER_64 CriticalSection; + LIST_ENTRY64 ProcessLocksList; + DWORD EntryCount; + DWORD ContentionCount; + DWORD Flags; + WORD CreatorBackTraceIndexHigh; + WORD Identifier; +} RTL_CRITICAL_SECTION_DEBUG64, *PRTL_CRITICAL_SECTION_DEBUG64, RTL_RESOURCE_DEBUG64, *PRTL_RESOURCE_DEBUG64; + +typedef struct _RTL_CRITICAL_SECTION_DEBUG32 +{ + WORD Type; + WORD CreatorBackTraceIndex; + RTL_CRITICAL_SECTION32* POINTER_32 CriticalSection; + LIST_ENTRY32 ProcessLocksList; + DWORD EntryCount; + DWORD ContentionCount; + DWORD Flags; + WORD CreatorBackTraceIndexHigh; + WORD Identifier; +} RTL_CRITICAL_SECTION_DEBUG32, *PRTL_CRITICAL_SECTION_DEBUG32, RTL_RESOURCE_DEBUG32, *PRTL_RESOURCE_DEBUG32; + +struct _RTL_CRITICAL_SECTION64 +{ + RTL_CRITICAL_SECTION_DEBUG64* POINTER_64 DebugInfo; + LONG LockCount; + LONG RecursionCount; + VOID* POINTER_64 OwningThread; + VOID* POINTER_64 LockSemaphore; + ULONGLONG SpinCount; +}; + +struct _RTL_CRITICAL_SECTION32 +{ + RTL_CRITICAL_SECTION_DEBUG32* POINTER_32 DebugInfo; + LONG LockCount; + LONG RecursionCount; + VOID* POINTER_32 OwningThread; + VOID* POINTER_32 LockSemaphore; + ULONG SpinCount; +}; + +#pragma endregion + +#pragma region RTL_BALANCED_NODE(64/32) + +typedef struct _RTL_BALANCED_NODE64 RTL_BALANCED_NODE64, *PRTL_BALANCED_NODE64; +struct _RTL_BALANCED_NODE64 +{ + union + { + RTL_BALANCED_NODE64* POINTER_64 Children[2]; + struct + { + RTL_BALANCED_NODE64* POINTER_64 Left; + RTL_BALANCED_NODE64* POINTER_64 Right; + } DUMMYSTRUCTNAME; + } DUMMYUNIONNAME; + +#define RTL_BALANCED_NODE_RESERVED_PARENT_MASK 3 + + union + { + UCHAR Red : 1; + UCHAR Balance : 2; + ULONGLONG ParentValue; + } DUMMYUNIONNAME2; +}; + +#pragma endregion + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Wow/Sxs.h b/Source/Include/KNSoft/NDK/NT/Wow/Sxs.h new file mode 100644 index 0000000..33bef64 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Wow/Sxs.h @@ -0,0 +1,112 @@ +#pragma once + +#include "../NT.h" + +EXTERN_C_START + +#pragma region ASSEMBLY_STORAGE_MAP_ENTRY[64/32] + +typedef struct _ASSEMBLY_STORAGE_MAP_ENTRY64 +{ + ULONG Flags; + UNICODE_STRING64 DosPath; + VOID* POINTER_64 Handle; +} ASSEMBLY_STORAGE_MAP_ENTRY64, *PASSEMBLY_STORAGE_MAP_ENTRY64; + +typedef struct _ASSEMBLY_STORAGE_MAP_ENTRY32 +{ + ULONG Flags; + UNICODE_STRING32 DosPath; + VOID* POINTER_32 Handle; +} ASSEMBLY_STORAGE_MAP_ENTRY32, *PASSEMBLY_STORAGE_MAP_ENTRY32; + +#pragma endregion + +#pragma region ASSEMBLY_STORAGE_MAP[64/32] + +typedef struct _ASSEMBLY_STORAGE_MAP64 +{ + ULONG Flags; + ULONG AssemblyCount; + ASSEMBLY_STORAGE_MAP_ENTRY64* POINTER_64* AssemblyArray; +} ASSEMBLY_STORAGE_MAP64, *PASSEMBLY_STORAGE_MAP64; + +typedef struct _ASSEMBLY_STORAGE_MAP32 +{ + ULONG Flags; + ULONG AssemblyCount; + ASSEMBLY_STORAGE_MAP_ENTRY32* POINTER_32* AssemblyArray; +} ASSEMBLY_STORAGE_MAP32, *PASSEMBLY_STORAGE_MAP32; + +#pragma endregion + +#pragma region ACTIVATION_CONTEXT[64/32] + +typedef struct _ACTIVATION_CONTEXT64 +{ + LONG RefCount; + ULONG Flags; + ACTIVATION_CONTEXT_DATA* POINTER_64 ActivationContextData; + VOID* POINTER_64 NotificationRoutine; // PACTIVATION_CONTEXT_NOTIFY_ROUTINE + VOID* POINTER_64 NotificationContext; + ULONG SentNotifications[8]; + ULONG DisabledNotifications[8]; + ASSEMBLY_STORAGE_MAP64 StorageMap; + ASSEMBLY_STORAGE_MAP_ENTRY64* POINTER_64 InlineStorageMapEntries[32]; +} ACTIVATION_CONTEXT64, *PACTIVATION_CONTEXT64; + +typedef struct _ACTIVATION_CONTEXT32 +{ + LONG RefCount; + ULONG Flags; + ACTIVATION_CONTEXT_DATA* POINTER_32 ActivationContextData; + VOID* POINTER_32 NotificationRoutine; // PACTIVATION_CONTEXT_NOTIFY_ROUTINE + VOID* POINTER_32 NotificationContext; + ULONG SentNotifications[8]; + ULONG DisabledNotifications[8]; + ASSEMBLY_STORAGE_MAP32 StorageMap; + ASSEMBLY_STORAGE_MAP_ENTRY32* POINTER_32 InlineStorageMapEntries[32]; +} ACTIVATION_CONTEXT32, *PACTIVATION_CONTEXT32; + +#pragma region [RTL_]ACTIVATION_CONTEXT_STACK[_FRAME][64/32] + +typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME64 RTL_ACTIVATION_CONTEXT_STACK_FRAME64, *PRTL_ACTIVATION_CONTEXT_STACK_FRAME64; +typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME32 RTL_ACTIVATION_CONTEXT_STACK_FRAME32, *PRTL_ACTIVATION_CONTEXT_STACK_FRAME32; + +struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME64 +{ + RTL_ACTIVATION_CONTEXT_STACK_FRAME64* POINTER_64 Previous; + ACTIVATION_CONTEXT64* POINTER_64 ActivationContext; + ULONG Flags; +}; + +struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME32 +{ + RTL_ACTIVATION_CONTEXT_STACK_FRAME32* POINTER_32 Previous; + ACTIVATION_CONTEXT32* POINTER_32 ActivationContext; + ULONG Flags; +}; + +typedef struct _ACTIVATION_CONTEXT_STACK64 +{ + RTL_ACTIVATION_CONTEXT_STACK_FRAME64* POINTER_64 ActiveFrame; + LIST_ENTRY64 FrameListCache; + ULONG Flags; + ULONG NextCookieSequenceNumber; + ULONG StackId; +} ACTIVATION_CONTEXT_STACK64, *PACTIVATION_CONTEXT_STACK64; + +typedef struct _ACTIVATION_CONTEXT_STACK32 +{ + RTL_ACTIVATION_CONTEXT_STACK_FRAME32* POINTER_32 ActiveFrame; + LIST_ENTRY32 FrameListCache; + ULONG Flags; + ULONG NextCookieSequenceNumber; + ULONG StackId; +} ACTIVATION_CONTEXT_STACK32, *PACTIVATION_CONTEXT_STACK32; + +#pragma endregion + +#pragma endregion + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/NT/Wow/Wow.h b/Source/Include/KNSoft/NDK/NT/Wow/Wow.h new file mode 100644 index 0000000..98341e2 --- /dev/null +++ b/Source/Include/KNSoft/NDK/NT/Wow/Wow.h @@ -0,0 +1,65 @@ +#pragma once + +#include "../NT.h" +#include "./Rtl.h" +#include "./Io.h" +#include "./Sxs.h" +#include "./Ldr.h" + +EXTERN_C_START + +/* Caution: Exported from Wow Ntdll.dll only!!! */ + +_Must_inspect_result_ +__drv_allocatesMem(Mem) +NTSYSCALLAPI +NTSTATUS +NTAPI +NtWow64AllocateVirtualMemory64( + _In_ HANDLE ProcessHandle, + _Inout_ _At_(*BaseAddress, + _Readable_bytes_(*RegionSize) + _Writable_bytes_(*RegionSize) + _Post_readable_byte_size_(*RegionSize)) PULONGLONG BaseAddress, + _In_ ULONGLONG ZeroBits, + _Inout_ PULONGLONG RegionSize, + _In_ ULONG AllocationType, + _In_ ULONG Protect); + +NTSYSAPI +NTSTATUS +NTAPI +NtWow64QueryInformationProcess64( + _In_ HANDLE ProcessHandle, + _In_ PROCESSINFOCLASS ProcessInformationClass, + _Out_writes_bytes_to_(ProcessInformationLength, *ReturnLength) PVOID ProcessInformation, + _In_ ULONG ProcessInformationLength, + _Out_opt_ PULONG ReturnLength); + +NTSYSAPI +NTSTATUS +NTAPI +NtWow64ReadVirtualMemory64( + _In_ HANDLE ProcessHandle, + _In_ ULONGLONG BaseAddress, + _Out_ PVOID Buffer, + _In_ ULONGLONG NumberOfBytesToRead, + _Out_opt_ PULONGLONG NumberOfBytesRead); + +NTSYSAPI +NTSTATUS +NTAPI +NtWow64WriteVirtualMemory64( + _In_ HANDLE ProcessHandle, + _In_ ULONGLONG BaseAddress, + _In_ PVOID Buffer, + _In_ ULONGLONG NumberOfBytesToWrite, + _Out_opt_ ULONGLONG NumberOfBytesWritten); + +NTSYSCALLAPI +BOOLEAN +NTAPI +NtWow64IsProcessorFeaturePresent( + _In_ ULONG ProcessorFeature); + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/UnitTest/UnitTest.h b/Source/Include/KNSoft/NDK/UnitTest/UnitTest.h new file mode 100644 index 0000000..e6a4243 --- /dev/null +++ b/Source/Include/KNSoft/NDK/UnitTest/UnitTest.h @@ -0,0 +1,134 @@ +/* + * KNSoft.NDK.UnitTest - Lite weight unit test framework + * Copyright (c) KNSoft.org (https://github.com/KNSoft). All rights reserved. + * Licensed under the MIT license. + */ + +#pragma once + +#include + +EXTERN_C_START + +typedef struct _UNITTEST_RESULT +{ + ULONG Pass; + ULONG Fail; + ULONG Skip; + ULONGLONG Elapsed; // in μs (us, microsecond) +} UNITTEST_RESULT, *PUNITTEST_RESULT; + +typedef +_Function_class_(FN_UNITTEST_PROC) +VOID +NTAPI +FN_UNITTEST_PROC( + UNITTEST_RESULT* Result, + _In_ INT ArgC, + _In_reads_(ArgC) _Pre_z_ PCWSTR* ArgV); + +typedef struct _UNITTEST_ENTRY +{ + FN_UNITTEST_PROC* Proc; + UNICODE_STRING Name; +} UNITTEST_ENTRY, *PUNITTEST_ENTRY; +typedef const UNITTEST_ENTRY *PCUNITTEST_ENTRY; + +typedef +_Function_class_(FN_UNITTEST_ENUM_PROC) +BOOL +CALLBACK +FN_UNITTEST_ENUM_PROC( + _In_ PCUNITTEST_ENTRY Entry, + _In_opt_ PVOID Context); + +BOOL +NTAPI +UnitTest_EnumEntries( + _In_ __callback FN_UNITTEST_ENUM_PROC* Callback, + _In_opt_ PVOID Context); + +_Ret_maybenull_ +_Must_inspect_result_ +PCUNITTEST_ENTRY +NTAPI +UnitTest_FindEntry( + _In_z_ PCWSTR Name); + +VOID +NTAPI +UnitTest_RunEntry( + _In_ PCUNITTEST_ENTRY Entry, + _Out_ PUNITTEST_RESULT Result, + _In_ INT ArgC, + _In_reads_(ArgC) _Pre_z_ PCWSTR* ArgV); + +ULONG +NTAPI +UnitTest_RunAll( + _Out_ PUNITTEST_RESULT Result); + +_Success_(return != FALSE) +BOOL +NTAPI +UnitTest_Run( + _In_z_ PCWSTR Name, + _Out_ PUNITTEST_RESULT Result, + _In_ INT ArgC, + _In_reads_(ArgC) _Pre_z_ PCWSTR* ArgV); + +_Success_(return == 0) +INT +NTAPI +UnitTest_Main( + _In_ int argc, + _In_reads_(argc) _Pre_z_ wchar_t** argv); + +/* Print string to stdout */ +VOID +NTAPI +UnitTest_PrintEx( + _In_reads_bytes_(TextSize) PCCH Text, + _In_ ULONG TextSize); + +#define UnitTest_Print(Text) UnitTest_PrintEx(Text, sizeof(Text)) + +/* Format string and print to stdout */ +VOID +__cdecl +UnitTest_PrintF( + _In_z_ _Printf_format_string_ PCSTR Format, + ...); + +/* Format string and output to both of stdout and debugger */ +VOID +__cdecl +UnitTest_FormatMessage( + _In_z_ _Printf_format_string_ PCSTR Format, + ...); + +#define TEST_PARAMETER_RESULT _KNSoft_NDK_UnitTest_Result +#define TEST_PARAMETER_ARGC _KNSoft_NDK_UnitTest_ArgC +#define TEST_PARAMETER_ARGV _KNSoft_NDK_UnitTest_ArgV + +/* Define a test */ +#define TEST_FUNC(Name) EXTERN_C VOID NTAPI Name(UNITTEST_RESULT* TEST_PARAMETER_RESULT, _In_ INT TEST_PARAMETER_ARGC, _In_reads_(TEST_PARAMETER_ARGC) _Pre_z_ PCWSTR* TEST_PARAMETER_ARGV) +#define TEST_DECL_FUNC(Name) EXTERN_C FN_UNITTEST_PROC Name +#define TEST_DECL_ENTRY(Name) { Name, RTL_CONSTANT_STRING(L###Name) } + +/* Global test list */ +EXTERN_C CONST UNITTEST_ENTRY UnitTestList[]; + +/* Increase count of test result, parameter can be Pass/Fail/Skip */ +#define TEST_RESULT(r) (TEST_PARAMETER_RESULT->r++) + +/* Pass if Expr is True, or fail and print assertion otherwise */ +#define TEST_OK(Expr) (Expr ? TEST_RESULT(Pass) : (TEST_RESULT(Fail), UnitTest_FormatMessage("%hs (Line %d) Assertion failed: %hs\n", __FILE__, __LINE__, #Expr))) + +/* Skip and print message */ +#define TEST_SKIP(Format, ...) (TEST_RESULT(Skip), UnitTest_FormatMessage("%hs (Line %d) Skipped: "Format"\n", __FILE__, __LINE__, ##__VA_ARGS__)) + +/* Fail and print message */ +#define TEST_FAIL(Format, ...) (TEST_RESULT(Fail), UnitTest_FormatMessage("%hs (Line %d) Failed: "Format"\n", __FILE__, __LINE__, ##__VA_ARGS__)) + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/UnitTest/UnitTest.inl b/Source/Include/KNSoft/NDK/UnitTest/UnitTest.inl new file mode 100644 index 0000000..12e83ce --- /dev/null +++ b/Source/Include/KNSoft/NDK/UnitTest/UnitTest.inl @@ -0,0 +1,344 @@ +#pragma once + +#include "./UnitTest.h" + +#include "../NT/NT.h" +#include "../Extension/StrSafe.h" + +#pragma region Prints + +static +VOID +UnitTest_PrintTitle(VOID) +{ + UnitTest_Print("====================================================================================================\n" + "KNSoft.NDK.UnitTest\n\n" + " Lite-weight Unit Test Framework from KNSoft.NDK (https://github.com/KNSoft/KNSoft.NDK)\n" + "====================================================================================================\n\n"); +} + +static +VOID +UnitTest_PrintUsage(VOID) +{ + UnitTest_Print("Usage: Test_Program [-Run | -List] [TestName] [Parameters]\n\n" + "e.g.,\n\n" + " Test_Program -List\n" + " List all tests.\n\n" + " Test_Program -Run\n" + " Run all tests.\n\n" + " Test_Program -Run TestName -Switch1 -Switch2\n" + " Run the test that named TestName with two input parameters.\n\n" + "Exit with the count of failed tests, or 0 if no test failed.\n\n"); +} + +static +VOID +UnitTest_PrintList(VOID) +{ + PCUNITTEST_ENTRY Entry; + BOOL HasEntry = FALSE; + + UnitTest_Print("Test list:\n"); + + for (Entry = UnitTestList; Entry->Name.Buffer != NULL; Entry++) + { + UnitTest_PrintF(" %wZ\n", &Entry->Name); + HasEntry = TRUE; + } + if (!HasEntry) + { + UnitTest_Print(" (Empty)\n"); + } + + UnitTest_Print("\n"); +} + +#pragma endregion + +#pragma region Entry API + +BOOL +NTAPI +UnitTest_EnumEntries( + _In_ __callback FN_UNITTEST_ENUM_PROC* Callback, + _In_opt_ PVOID Context) +{ + PCUNITTEST_ENTRY Entry; + BOOL Ret; + + for (Entry = UnitTestList; Entry->Name.Buffer != NULL; Entry++) + { + Ret = Callback(Entry, Context); + if (!Ret) + { + return Ret; + } + } + + return TRUE; +} + +_Ret_maybenull_ +_Must_inspect_result_ +PCUNITTEST_ENTRY +NTAPI +UnitTest_FindEntry( + _In_z_ PCWSTR Name) +{ + PCUNITTEST_ENTRY Entry; + UNICODE_STRING NameString; + + RtlInitUnicodeString(&NameString, Name); + + for (Entry = UnitTestList; Entry->Name.Buffer != NULL; Entry++) + { + if (RtlEqualUnicodeString((PUNICODE_STRING)&Entry->Name, &NameString, FALSE)) + { + return Entry; + } + } + + return NULL; +} + +#pragma endregion + +#pragma region Execute API + +VOID +NTAPI +UnitTest_RunEntry( + _In_ PCUNITTEST_ENTRY Entry, + _Out_ PUNITTEST_RESULT Result, + _In_ INT ArgC, + _In_reads_(ArgC) _Pre_z_ PCWSTR* ArgV) +{ + LARGE_INTEGER PrefCounter1, PrefCounter2, PrefFreq; + ULONGLONG ElapsedMicroseconds; + + UnitTest_FormatMessage(">>>> Running unit test: %wZ\n", &Entry->Name); + RtlZeroMemory(Result, sizeof(*Result)); + + /* NtQueryPerformanceCounter writes frequency after counter */ + NtQueryPerformanceCounter(&PrefCounter1, NULL); + Entry->Proc(Result, ArgC, ArgV); + NtQueryPerformanceCounter(&PrefCounter2, &PrefFreq); + + /* Convert to microseconds before dividing for avoiding loss-of-precision */ + ElapsedMicroseconds = (ULONGLONG)PrefCounter2.QuadPart - (ULONGLONG)PrefCounter1.QuadPart; + ElapsedMicroseconds *= 1000000; + ElapsedMicroseconds = (ULONGLONG)((ElapsedMicroseconds / (DOUBLE)PrefFreq.QuadPart) + (DOUBLE)0.5); + Result->Elapsed = ElapsedMicroseconds; + UnitTest_FormatMessage("<<<< Result: %lu tests executed (%lu passed, %lu failed, %lu skipped) in %llu ms (%llu μs)\n\n", + Result->Pass + Result->Fail + Result->Skip, + Result->Pass, + Result->Fail, + Result->Skip, + (ULONGLONG)((ElapsedMicroseconds / 1000.0F) + 0.5F), + Result->Elapsed); +} + +ULONG +NTAPI +UnitTest_RunAll( + _Out_ PUNITTEST_RESULT Result) +{ + ULONG Ret = 0; + PCUNITTEST_ENTRY Entry; + UNITTEST_RESULT EntryResult; + + RtlZeroMemory(Result, sizeof(*Result)); + + for (Entry = UnitTestList; Entry->Name.Buffer != NULL; Entry++) + { + UnitTest_RunEntry(Entry, &EntryResult, 0, NULL); + Result->Pass += EntryResult.Pass; + Result->Fail += EntryResult.Fail; + Result->Skip += EntryResult.Skip; + Result->Elapsed += EntryResult.Elapsed; + Ret++; + } + + if (Ret > 0) + { + UnitTest_FormatMessage("Totally %lu test entries ran, %lu tests executed (%lu passed, %lu failed, %lu skipped) in %llu ms\n", + Ret, + Result->Pass + Result->Fail + Result->Skip, + Result->Pass, + Result->Fail, + Result->Skip, + (ULONGLONG)((Result->Elapsed / 1000.0F) + 0.5F)); + } + return Ret; +} + +_Success_(return != FALSE) +BOOL +NTAPI +UnitTest_Run( + _In_z_ PCWSTR Name, + _Out_ PUNITTEST_RESULT Result, + _In_ INT ArgC, + _In_reads_(ArgC) _Pre_z_ PCWSTR * ArgV) +{ + PCUNITTEST_ENTRY Entry = UnitTest_FindEntry(Name); + + if (Entry == NULL) + { + return FALSE; + } + + UnitTest_RunEntry(Entry, Result, ArgC, ArgV); + return TRUE; +} + +_Success_(return == 0) +INT +NTAPI +UnitTest_Main( + _In_ int argc, + _In_reads_(argc) _Pre_z_ wchar_t** argv) +{ + UNITTEST_RESULT Result; + PCUNITTEST_ENTRY Entry; + + UnitTest_PrintTitle(); + if (argc > 1) + { + if (_wcsicmp(argv[1], L"-List") == 0) + { + UnitTest_PrintList(); + return 0; + } else if (_wcsicmp(argv[1], L"-Run") == 0) + { + if (argc == 2) + { + if (UnitTest_RunAll(&Result) == 0) + { + UnitTest_Print("No test entry found\n\n"); + return (INT)STATUS_NOT_FOUND; + } + return Result.Fail; + } else if (argc >= 3) + { + Entry = UnitTest_FindEntry(argv[2]); + if (Entry == NULL) + { + UnitTest_PrintF("Test \"%ls\" not found\n\n", argv[2]); + UnitTest_PrintList(); + return (INT)STATUS_NOT_FOUND; + } + UnitTest_RunEntry(Entry, &Result, argc - 3, (PCWSTR*)(argv + 3)); + return Result.Fail; + } + } + } + + UnitTest_Print("Invalid parameter\n\n"); + UnitTest_PrintUsage(); + return (INT)STATUS_INVALID_PARAMETER; +} + +#pragma endregion + +#pragma region Utils + +static +VOID +__cdecl +UnitTest_PrintFV( + _In_z_ _Printf_format_string_ PCSTR Format, + _In_ va_list ArgList) +{ + CHAR sz[512 + 1]; // Same limitation as DbgPrint + ULONG u, uNew; + HANDLE hStdOut; + PSTR psz; + IO_STATUS_BLOCK IoStatusBlock; + + /* Write standard output if exists */ + hStdOut = NtCurrentPeb()->ProcessParameters->StandardOutput; + if (hStdOut == NULL) + { + return; + } + + /* Format string */ + u = StrSafe_CchVPrintfA(sz, ARRAYSIZE(sz), Format, ArgList); + if (u == 0) + { + return; + } + + /* Allocate buffer if sz too small */ + if (u >= ARRAYSIZE(sz)) + { + psz = (PSTR)RtlAllocateHeap(NtGetProcessHeap(), 0, (SIZE_T)u + 1); + if (psz != NULL) + { + uNew = StrSafe_CchVPrintfA(psz, (SIZE_T)u + 1, Format, ArgList); + if (uNew > 0 && uNew < u) + { + u = uNew; + goto _Print_Stdout; + } + RtlFreeHeap(NtGetProcessHeap(), 0, psz); + } + + /* New allocated buffer unavailable, fallback to sz (truncated) */ + u = ARRAYSIZE(sz) - 1; + } + + psz = sz; + +_Print_Stdout: + NtWriteFile(hStdOut, NULL, NULL, NULL, &IoStatusBlock, psz, u, NULL, NULL); + if (psz != sz) + { + RtlFreeHeap(NtGetProcessHeap(), 0, psz); + } +} + +VOID +NTAPI +UnitTest_PrintEx( + _In_reads_bytes_(TextSize) PCCH Text, + _In_ ULONG TextSize) +{ + HANDLE StdOutHandle; + IO_STATUS_BLOCK IoStatusBlock; + + StdOutHandle = NtCurrentPeb()->ProcessParameters->StandardOutput; + if (StdOutHandle != NULL) + { + NtWriteFile(StdOutHandle, NULL, NULL, NULL, &IoStatusBlock, (PVOID)Text, TextSize, NULL, NULL); + } +} + +VOID +__cdecl +UnitTest_PrintF( + _In_z_ _Printf_format_string_ PCSTR Format, + ...) +{ + va_list ArgList; + + va_start(ArgList, Format); + UnitTest_PrintFV(Format, ArgList); +} + +VOID +__cdecl +UnitTest_FormatMessage( + _In_z_ _Printf_format_string_ PCSTR Format, + ...) +{ + va_list ArgList; + + va_start(ArgList, Format); + vDbgPrintEx(MAXULONG, DPFLTR_ERROR_LEVEL, Format, ArgList); + UnitTest_PrintFV(Format, ArgList); +} + +#pragma endregion diff --git a/Source/Include/KNSoft/NDK/Win32/API/Kernel32.h b/Source/Include/KNSoft/NDK/Win32/API/Kernel32.h new file mode 100644 index 0000000..9cd13da --- /dev/null +++ b/Source/Include/KNSoft/NDK/Win32/API/Kernel32.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../../NT/MinDef.h" + +#include + +EXTERN_C_START + +WINBASEAPI +BOOL +WINAPI +CreateProcessInternalW( + _In_opt_ HANDLE hToken, + _In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _Out_opt_ PHANDLE hNewToken); + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/Win32/API/Ntdll.Hash.h b/Source/Include/KNSoft/NDK/Win32/API/Ntdll.Hash.h new file mode 100644 index 0000000..5ead23c --- /dev/null +++ b/Source/Include/KNSoft/NDK/Win32/API/Ntdll.Hash.h @@ -0,0 +1,101 @@ +#pragma once + +#include "../../NT/MinDef.h" + +EXTERN_C_START + +typedef struct _A_SHA_CTX +{ + UCHAR Buffer[64]; + ULONG State[5]; + ULONG Count[2]; +} A_SHA_CTX, *PA_SHA_CTX; + +#define A_SHA_DIGEST_LEN 20 + +typedef struct _MD5_CTX +{ + ULONG Count[2]; + ULONG State[4]; + UCHAR Buffer[64]; + UCHAR Hash[16]; +} MD5_CTX, *PMD5_CTX; + +#define MD5_DIGEST_LEN 16 + +typedef struct _MD4_CTX +{ + ULONG State[4]; + ULONG Count[2]; + UCHAR Buffer[64]; + UCHAR Hash[16]; +} MD4_CTX, *PMD4_CTX; + +#define MD4_DIGEST_LEN 16 + +#ifndef RSA32API +#define RSA32API __stdcall +#endif + +NTSYSAPI +VOID +RSA32API +A_SHAInit( + _Out_ PA_SHA_CTX Context); + +NTSYSAPI +VOID +RSA32API +A_SHAUpdate( + _Inout_ PA_SHA_CTX Context, + _In_reads_(BufferSize) PUCHAR Buffer, + _In_ ULONG BufferSize); + +NTSYSAPI +VOID +RSA32API +A_SHAFinal( + _Inout_ PA_SHA_CTX Context, + _Out_ PUCHAR Result); + +NTSYSAPI +VOID +RSA32API +MD5Init( + _Out_ PMD5_CTX Context); + +NTSYSAPI +VOID +RSA32API +MD5Update( + _Inout_ PMD5_CTX Context, + _In_reads_(BufferSize) PUCHAR Buffer, + _In_ ULONG BufferSize); + +NTSYSAPI +VOID +RSA32API +MD5Final( + _Inout_ PMD5_CTX Context); + +NTSYSAPI +VOID +RSA32API +MD4Init( + _Out_ PMD4_CTX Context); + +NTSYSAPI +VOID +RSA32API +MD4Update( + _Inout_ PMD4_CTX Context, + _In_reads_(BufferSize) PUCHAR Buffer, + _In_ ULONG BufferSize); + +NTSYSAPI +VOID +RSA32API +MD4Final( + _Inout_ PMD4_CTX Context); + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/Win32/API/Ntdll.h b/Source/Include/KNSoft/NDK/Win32/API/Ntdll.h new file mode 100644 index 0000000..69c7c4e --- /dev/null +++ b/Source/Include/KNSoft/NDK/Win32/API/Ntdll.h @@ -0,0 +1,17 @@ +#pragma once + +#include "../../NT/MinDef.h" + +EXTERN_C_START + +#pragma region Csrss + +/* KNSoft.NDK */ +NTSYSAPI +HANDLE +NTAPI +CsrGetProcessId(VOID); + +#pragma endregion + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/Win32/API/User32.h b/Source/Include/KNSoft/NDK/Win32/API/User32.h new file mode 100644 index 0000000..139868f --- /dev/null +++ b/Source/Include/KNSoft/NDK/Win32/API/User32.h @@ -0,0 +1,39 @@ +#pragma once + +#include "../../NT/MinDef.h" + +#include + +EXTERN_C_START + +WINUSERAPI +INT +WINAPI +MessageBoxTimeoutA( + _In_opt_ HWND hWnd, + _In_opt_ LPCSTR lpText, + _In_opt_ LPCSTR lpCaption, + _In_ UINT uType, + _In_ WORD wLanguageId, + _In_ DWORD dwMilliseconds); + +WINUSERAPI +INT +WINAPI +MessageBoxTimeoutW( + _In_opt_ HWND hWnd, + _In_opt_ LPCWSTR lpText, + _In_opt_ LPCWSTR lpCaption, + _In_ UINT uType, + _In_ WORD wLanguageId, + _In_ DWORD dwMilliseconds); + +WINUSERAPI +BOOL +WINAPI +EndTask( + HWND hWnd, + BOOL fShutDown, + BOOL fForce); + +EXTERN_C_END diff --git a/Source/Include/KNSoft/NDK/Win32/Def/CommCtrl.h b/Source/Include/KNSoft/NDK/Win32/Def/CommCtrl.h new file mode 100644 index 0000000..613be3c --- /dev/null +++ b/Source/Include/KNSoft/NDK/Win32/Def/CommCtrl.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + +#pragma region Patches C26454 warning + +#undef NM_FIRST +#define NM_FIRST 0x100000000 + +#undef TCN_FIRST +#define TCN_FIRST 0xFFFFFDDA + +#undef TVN_FIRST +#define TVN_FIRST 0xFFFFFE70 + +#undef LVN_FIRST +#define LVN_FIRST 0xFFFFFF9C + +#pragma endregion diff --git a/Source/Include/KNSoft/NDK/Win32/Def/WinUser.h b/Source/Include/KNSoft/NDK/Win32/Def/WinUser.h new file mode 100644 index 0000000..af4f699 --- /dev/null +++ b/Source/Include/KNSoft/NDK/Win32/Def/WinUser.h @@ -0,0 +1,5 @@ +#pragma once + +#ifndef WM_COPYGLOBALDATA +#define WM_COPYGLOBALDATA 0x49 +#endif diff --git a/Source/KNSoft.NDK.nuspec b/Source/KNSoft.NDK.nuspec new file mode 100644 index 0000000..851dff7 --- /dev/null +++ b/Source/KNSoft.NDK.nuspec @@ -0,0 +1,26 @@ + + + + KNSoft.NDK + 1.1.0-beta + KNSoft.NDK + KNSoft + https://github.com/KNSoft/KNSoft.NDK + true + MIT + https://licenses.nuget.org/MIT + README.md + KNSoft.NDK provides native C/C++ definitions and import libraries for Windows NT development. + native Windows Utility Runtime + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/KNSoft.NDK.sln b/Source/KNSoft.NDK.sln new file mode 100644 index 0000000..ec44381 --- /dev/null +++ b/Source/KNSoft.NDK.sln @@ -0,0 +1,54 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35122.118 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KNSoft.NDK", "KNSoft.NDK\KNSoft.NDK.vcxproj", "{1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test\Test.vcxproj", "{E4BBF3A5-9277-48A9-94E6-3F15F740655D}" + ProjectSection(ProjectDependencies) = postProject + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991} = {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Debug|ARM64.ActiveCfg = Release|ARM64 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Debug|ARM64.Build.0 = Release|ARM64 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Debug|x64.ActiveCfg = Release|x64 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Debug|x64.Build.0 = Release|x64 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Debug|x86.ActiveCfg = Release|Win32 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Debug|x86.Build.0 = Release|Win32 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Release|ARM64.ActiveCfg = Release|ARM64 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Release|ARM64.Build.0 = Release|ARM64 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Release|x64.ActiveCfg = Release|x64 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Release|x64.Build.0 = Release|x64 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Release|x86.ActiveCfg = Release|Win32 + {1A6001A4-2E81-4CFB-86F3-E1FE1B4A5991}.Release|x86.Build.0 = Release|Win32 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Debug|ARM64.Build.0 = Debug|ARM64 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Debug|x64.ActiveCfg = Debug|x64 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Debug|x64.Build.0 = Debug|x64 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Debug|x86.ActiveCfg = Debug|Win32 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Debug|x86.Build.0 = Debug|Win32 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Release|ARM64.ActiveCfg = Release|ARM64 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Release|ARM64.Build.0 = Release|ARM64 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Release|x64.ActiveCfg = Release|x64 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Release|x64.Build.0 = Release|x64 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Release|x86.ActiveCfg = Release|Win32 + {E4BBF3A5-9277-48A9-94E6-3F15F740655D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {55CC86D7-4495-4801-B194-094F927EEF7D} + EndGlobalSection +EndGlobal diff --git a/Source/KNSoft.NDK.targets b/Source/KNSoft.NDK.targets new file mode 100644 index 0000000..202c623 --- /dev/null +++ b/Source/KNSoft.NDK.targets @@ -0,0 +1,12 @@ + + + + $(MSBuildThisFileDirectory)Include;$(MSBuildThisFileDirectory)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + $(MSBuildThisFileDirectory)Lib\$(PlatformTarget);$(LibraryPath) + + + + ntdll.lib;%(AdditionalDependencies) + + + diff --git a/Source/KNSoft.NDK/KNSoft.NDK.vcxproj b/Source/KNSoft.NDK/KNSoft.NDK.vcxproj new file mode 100644 index 0000000..24e7397 --- /dev/null +++ b/Source/KNSoft.NDK/KNSoft.NDK.vcxproj @@ -0,0 +1,209 @@ + + + + + + Release + ARM64 + + + Release + Win32 + + + Release + x64 + + + + 17.0 + Win32Proj + {1a6001a4-2e81-4cfb-86f3-e1fe1b4a5991} + KNSoft.NDK + 10.0 + KNSoft.NDK + + + + false + true + Utility + + + false + true + Utility + + + false + true + Utility + + + + + + + + + + + + + + + + + + $(SolutionDir)OutDir\$(PlatformTarget)\ + IntDir\$(PlatformTarget)\ + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + + + $(SolutionDir)OutDir\$(PlatformTarget)\ + IntDir\$(PlatformTarget)\ + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + + + $(SolutionDir)OutDir\$(PlatformTarget)\ + IntDir\$(PlatformTarget)\ + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/Source/KNSoft.NDK/KNSoft.NDK.vcxproj.filters b/Source/KNSoft.NDK/KNSoft.NDK.vcxproj.filters new file mode 100644 index 0000000..cce2ccc --- /dev/null +++ b/Source/KNSoft.NDK/KNSoft.NDK.vcxproj.filters @@ -0,0 +1,259 @@ + + + + + {0824e6bd-fba8-4ba1-a245-1c0743fc1404} + + + {3769bb18-ab05-4c44-8684-2ff9124963ae} + + + {2e85c850-9b91-4075-b52c-19c59f8872c0} + + + {347e9f2f-faac-4fa8-b572-16ecdf28ed59} + + + {9f7bef88-765d-47ea-93a4-dbd29859e6e3} + + + {b8cf96b3-56aa-4366-920a-77b5f9d68ee9} + + + {a8b5d84e-895c-4b3c-843e-85298108c298} + + + {a68ed197-518e-4f67-a03c-8742d02e2142} + + + {37cee708-6068-468d-b93e-989878d2d90f} + + + {ab2e801f-dc73-49d5-aa69-4475da07fe27} + + + {fb4a9d12-d5de-4a28-872e-91496ea7d1f6} + + + {cb41731f-a75f-4920-a2de-db9cc44fd75b} + + + + + + NT + + + NT + + + NT + + + NT\Private + + + NT\Private + + + NT\Private + + + Extension + + + Extension + + + Extension + + + Extension + + + Extension + + + Win32\Def + + + Win32\Def + + + Win32\API + + + Win32\API + + + Win32\API + + + Win32\API + + + UnitTest + + + NT\Rtl + + + NT\Rtl + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + 3rdParty\phnt + + + NT\Wow + + + NT\Wow + + + NT\Wow + + + NT\Wow + + + NT\Wow + + + NT\Extension + + + NT\Extension + + + NT + + + NT + + + NT + + + NT + + + NT + + + NT + + + NT + + + NT + + + NT\Rtl + + + + + + UnitTest + + + + + Win32\API + + + Win32\API + + + \ No newline at end of file diff --git a/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.Ntdll.Hash.xml b/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.Ntdll.Hash.xml new file mode 100644 index 0000000..da624ad --- /dev/null +++ b/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.Ntdll.Hash.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.WinAPI.xml b/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.WinAPI.xml new file mode 100644 index 0000000..33adc51 --- /dev/null +++ b/Source/KNSoft.NDK/WinAPI/KNSoft.NDK.WinAPI.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/KNSoft.NDK/packages.config b/Source/KNSoft.NDK/packages.config new file mode 100644 index 0000000..196bfb0 --- /dev/null +++ b/Source/KNSoft.NDK/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Source/Test/Extension/MSToolChain.c b/Source/Test/Extension/MSToolChain.c new file mode 100644 index 0000000..5930b03 --- /dev/null +++ b/Source/Test/Extension/MSToolChain.c @@ -0,0 +1,28 @@ +/* + * Test for the MSToolChain.h + */ + +#include "../Test.h" + +static volatile LONG g_lInit = 0; + +static +MSVC_INITIALIZER(Init1) +{ + InterlockedAdd(&g_lInit, 234); + return 0; +} + +static +MSVC_INITIALIZER(Init2) +{ + InterlockedAdd(&g_lInit, 432); + return 0; +} + +TEST_FUNC(MSToolChain) +{ + TEST_OK(g_lInit == 666); +} + +C_ASSERT(TRUE); diff --git a/Source/Test/Main.c b/Source/Test/Main.c new file mode 100644 index 0000000..596cee2 --- /dev/null +++ b/Source/Test/Main.c @@ -0,0 +1,30 @@ +#include +#include + +TEST_DECL_FUNC(UnitTestFramework); +TEST_DECL_FUNC(MSToolChain); +TEST_DECL_FUNC(PebLdrStruct); +TEST_DECL_FUNC(PebStruct); +TEST_DECL_FUNC(TebStruct); +TEST_DECL_FUNC(KUSDStruct); +TEST_DECL_FUNC(StrSafeFunc); + +CONST UNITTEST_ENTRY UnitTestList[] = { + TEST_DECL_ENTRY(UnitTestFramework), + TEST_DECL_ENTRY(MSToolChain), + TEST_DECL_ENTRY(PebLdrStruct), + TEST_DECL_ENTRY(PebStruct), + TEST_DECL_ENTRY(TebStruct), + TEST_DECL_ENTRY(KUSDStruct), + TEST_DECL_ENTRY(StrSafeFunc), + { 0 } +}; + +int +_cdecl +wmain( + _In_ int argc, + _In_reads_(argc) _Pre_z_ wchar_t** argv) +{ + return UnitTest_Main(argc, argv); +} diff --git a/Source/Test/NT/PebLdr.c b/Source/Test/NT/PebLdr.c new file mode 100644 index 0000000..c2c5f1a --- /dev/null +++ b/Source/Test/NT/PebLdr.c @@ -0,0 +1,35 @@ +/* + * Test for the PEB_LDR_DATA structure definitions + */ + +#include "../Test.h" + +TEST_FUNC(PebLdrStruct) +{ + PPEB_LDR_DATA Ldr = NtCurrentPeb()->Ldr; + PLDR_DATA_TABLE_ENTRY NtdllLdrEntry; + PIMAGE_NT_HEADERS NtdllHeader; + BOOL NtdllBaseValid; + + TEST_OK(CONTAINING_RECORD(Ldr->InLoadOrderModuleList.Flink, + LDR_DATA_TABLE_ENTRY, + InLoadOrderModuleList)->DllBase == GetModuleHandleW(NULL)); + + NtdllLdrEntry = CONTAINING_RECORD(Ldr->InInitializationOrderModuleList.Flink, + LDR_DATA_TABLE_ENTRY, + InInitializationOrderModuleList); + TEST_OK(NtdllLdrEntry->EntryPoint == NULL); + + NtdllBaseValid = NtdllLdrEntry->DllBase != NULL && NtdllLdrEntry->DllBase == GetModuleHandleW(L"ntdll.dll"); + TEST_OK(NtdllBaseValid); + if (NtdllBaseValid) + { + NtdllHeader = Add2Ptr(NtdllLdrEntry->DllBase, ((PIMAGE_DOS_HEADER)(NtdllLdrEntry->DllBase))->e_lfanew); + TEST_OK(NtdllLdrEntry->SizeOfImage == NtdllHeader->OptionalHeader.SizeOfImage); + TEST_OK(NtdllLdrEntry->CheckSum == NtdllHeader->OptionalHeader.CheckSum); + TEST_OK(NtdllLdrEntry->TimeDateStamp == NtdllHeader->FileHeader.TimeDateStamp); + } else + { + TEST_SKIP("NtdllBaseValid is FALSE, skip some field tests about PE image\n"); + } +} diff --git a/Source/Test/NT/PebTebKUSD.c b/Source/Test/NT/PebTebKUSD.c new file mode 100644 index 0000000..77aad19 --- /dev/null +++ b/Source/Test/NT/PebTebKUSD.c @@ -0,0 +1,90 @@ +/* + * Test for the KNSoft.NDK PEB/TEB/KUSER_SHARED_DATA structure definitions + */ + +#include "../Test.h" + +TEST_FUNC(PebStruct) +{ + NTSTATUS Status; + PPEB Peb = NtCurrentPeb(); + + PROCESS_BASIC_INFORMATION PBI; + Status = NtQueryInformationProcess(NtCurrentProcess(), + ProcessBasicInformation, + &PBI, + sizeof(PBI), + NULL); + if (NT_SUCCESS(Status)) + { + TEST_OK(Peb == PBI.PebBaseAddress); + } else + { + TEST_SKIP("NtQueryInformationProcess failed with 0x%08lX, skip test for Peb\n", Status); + } + + TEST_OK(Peb->ImageBaseAddress == &__ImageBase); + TEST_OK(Peb->ProcessHeap == GetProcessHeap()); + + PIMAGE_NT_HEADERS pNtHeader = Add2Ptr(&__ImageBase, __ImageBase.e_lfanew); + TEST_OK(Peb->ImageSubsystemMajorVersion == (ULONG)pNtHeader->OptionalHeader.MajorSubsystemVersion); + TEST_OK(Peb->ImageSubsystemMinorVersion == (ULONG)pNtHeader->OptionalHeader.MinorSubsystemVersion); + + PROCESS_SESSION_INFORMATION PSI; + Status = NtQueryInformationProcess(NtCurrentProcess(), + ProcessSessionInformation, + &PSI, + sizeof(PSI), + NULL); + if (NT_SUCCESS(Status)) + { + TEST_OK(Peb->SessionId == PSI.SessionId); + } else + { + TEST_SKIP("NtQueryInformationProcess failed with 0x%08lX, skip test for Peb->SessionId\n", Status); + } +} + +TEST_FUNC(TebStruct) +{ + PTEB Teb = NtCurrentTeb(); + + TEST_OK(Teb->ProcessEnvironmentBlock == NtCurrentPeb()); + TEST_OK((ULONG_PTR)Teb->ClientId.UniqueProcess == (ULONG_PTR)GetCurrentProcessId()); + TEST_OK((ULONG_PTR)Teb->ClientId.UniqueThread == (ULONG_PTR)GetCurrentThreadId()); + + Teb->LastErrorValue = ERROR_BAD_FILE_TYPE; + TEST_OK(GetLastError() == ERROR_BAD_FILE_TYPE); + SetLastError(ERROR_INVALID_EA_NAME); + TEST_OK(Teb->LastErrorValue == ERROR_INVALID_EA_NAME); + + Teb->LastStatusValue = STATUS_NOT_IMPLEMENTED; + TEST_OK(RtlGetLastNtStatus() == STATUS_NOT_IMPLEMENTED); + RtlNtStatusToDosError(STATUS_DYNAMIC_CODE_BLOCKED); + TEST_OK(Teb->LastStatusValue == STATUS_DYNAMIC_CODE_BLOCKED); + + TEST_OK(Teb->CurrentLocale == GetThreadLocale()); + TEST_OK(Teb->HardErrorMode == GetThreadErrorMode()); +} + +TEST_FUNC(KUSDStruct) +{ + PCKUSER_SHARED_DATA KUSD = SharedUserData; + TIME_ZONE_INFORMATION TimeZoneInfo; + WCHAR NtSystemRoot[MAX_PATH]; + SYSTEM_INFO SystemInfo; + + DWORD TimeZoneId = GetTimeZoneInformation(&TimeZoneInfo); + TEST_OK(KUSD->TimeZoneId == TimeZoneId); + + if (GetWindowsDirectoryW(NtSystemRoot, ARRAYSIZE(NtSystemRoot)) > 0) + { + TEST_OK(_wcsicmp(KUSD->NtSystemRoot, NtSystemRoot) == 0); + } else + { + TEST_SKIP("GetWindowsDirectoryW failed with 0x%08lX, skip test for KUSD->NtSystemRoot\n", GetLastError()); + } + + GetNativeSystemInfo(&SystemInfo); + TEST_OK(KUSD->NativeProcessorArchitecture == SystemInfo.wProcessorArchitecture); +} diff --git a/Source/Test/StrSafe.c b/Source/Test/StrSafe.c new file mode 100644 index 0000000..eb1b925 --- /dev/null +++ b/Source/Test/StrSafe.c @@ -0,0 +1,36 @@ +/* + * Test for the StrSafe.h + */ + +#include "Test.h" + +#include + +#define DEFINE_TEST_STRING(Name, String)\ +static const char Name##_A[] = String;\ +static const wchar_t Name##_W[] = _A2W(String); + +DEFINE_TEST_STRING(TEST_STRING1, "KNSoft.NDK StrSafe.h Test String"); +DEFINE_TEST_STRING(TEST_STRING1_PART1, "KNSoft.NDK StrSafe.h Test"); + +TEST_FUNC(StrSafeFunc) +{ + char szTempA[_countof(TEST_STRING1_A)]; + wchar_t szTempW[_countof(TEST_STRING1_W)]; + + TEST_OK(StrSafe_CchPrintfA(NULL, 0, "%hs", TEST_STRING1_A) == _STR_CCH_LEN(TEST_STRING1_A)); + TEST_OK(StrSafe_CchPrintfA(szTempA, ARRAYSIZE(szTempA), "%hs", TEST_STRING1_A) == _STR_CCH_LEN(TEST_STRING1_A)); + TEST_OK(strcmp(szTempA, TEST_STRING1_A) == 0); + TEST_OK(StrSafe_CchPrintfW(NULL, 0, L"%ls", TEST_STRING1_W) == _STR_CCH_LEN(TEST_STRING1_W)); + TEST_OK(StrSafe_CchPrintfW(szTempW, ARRAYSIZE(szTempW), L"%ls", TEST_STRING1_W) == _STR_CCH_LEN(TEST_STRING1_W)); + TEST_OK(wcscmp(szTempW, TEST_STRING1_W) == 0); + + TEST_OK(StrSafe_CchPrintfA(szTempA, ARRAYSIZE(szTempA), "%hs", TEST_STRING1_PART1_A) == _STR_CCH_LEN(TEST_STRING1_PART1_A)); + TEST_OK(strcmp(szTempA, TEST_STRING1_PART1_A) == 0); + TEST_OK(StrSafe_CchPrintfA(szTempA, ARRAYSIZE(szTempA), "%hs$", TEST_STRING1_A) == _STR_CCH_LEN(TEST_STRING1_A) + 1); + TEST_OK(strcmp(szTempA, TEST_STRING1_A) == 0); + TEST_OK(StrSafe_CchPrintfW(szTempW, ARRAYSIZE(szTempW), L"%ls", TEST_STRING1_PART1_W) == _STR_CCH_LEN(TEST_STRING1_PART1_W)); + TEST_OK(wcscmp(szTempW, TEST_STRING1_PART1_W) == 0); + TEST_OK(StrSafe_CchPrintfW(szTempW, ARRAYSIZE(szTempW), L"%ls$", TEST_STRING1_W) == _STR_CCH_LEN(TEST_STRING1_W) + 1); + TEST_OK(wcscmp(szTempW, TEST_STRING1_W) == 0); +} diff --git a/Source/Test/Test.h b/Source/Test/Test.h new file mode 100644 index 0000000..a4aefaa --- /dev/null +++ b/Source/Test/Test.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include +#include + +#pragma comment(lib, "KNSoft.NDK.Ntdll.Hash.lib") +#pragma comment(lib, "KNSoft.NDK.WinAPI.lib") diff --git a/Source/Test/Test.vcxproj b/Source/Test/Test.vcxproj new file mode 100644 index 0000000..ba8e093 --- /dev/null +++ b/Source/Test/Test.vcxproj @@ -0,0 +1,198 @@ + + + + + Debug + ARM64 + + + Debug + Win32 + + + Release + ARM64 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {e4bbf3a5-9277-48a9-94e6-3f15f740655d} + Test + 10.0.22621.0 + + + + Application + true + + + Application + false + true + + + Application + true + + + Application + true + + + Application + false + true + + + Application + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + $(OutDir)../;$(LibraryPath) + + + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + $(OutDir)../;$(LibraryPath) + + + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + $(OutDir)../;$(LibraryPath) + + + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + $(OutDir)../;$(LibraryPath) + + + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + $(OutDir)../;$(LibraryPath) + + + $(SolutionDir)Include;$(SolutionDir)Include\KNSoft\NDK\3rdParty\phnt;$(IncludePath) + $(OutDir)../;$(LibraryPath) + + + + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + ntdll.lib;%(AdditionalDependencies) + + + + + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + ntdll.lib;%(AdditionalDependencies) + + + + + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + ntdll.lib;%(AdditionalDependencies) + + + + + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + ntdll.lib;%(AdditionalDependencies) + + + + + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + ntdll.lib;%(AdditionalDependencies) + + + + + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + ntdll.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Test/Test.vcxproj.filters b/Source/Test/Test.vcxproj.filters new file mode 100644 index 0000000..14e97b8 --- /dev/null +++ b/Source/Test/Test.vcxproj.filters @@ -0,0 +1,28 @@ + + + + + + + NT + + + + NT + + + Extension + + + + + + + + {62d5419b-ca75-423e-b61b-b51ebb1a1c18} + + + {465796cb-eade-41ce-a5d4-197bee582c40} + + + \ No newline at end of file diff --git a/Source/Test/UnitTestFramework.c b/Source/Test/UnitTestFramework.c new file mode 100644 index 0000000..cd84cc8 --- /dev/null +++ b/Source/Test/UnitTestFramework.c @@ -0,0 +1,39 @@ +/* + * Test for the KNSoft.NDK.UnitTest unit test framework itself + */ + +#include "Test.h" + +TEST_FUNC(UnitTestFramework) +{ + UNITTEST_RESULT Result; + + UnitTest_Print("The following tests verify the unit test framework itself, so fail and skip outputs are expected\n"); + + /* Totally 5 pass, 6 fail, 3 skip */ + TEST_OK(TRUE); + TEST_OK(1 == 1); + TEST_OK(1 != 2); + TEST_RESULT(Pass); + TEST_RESULT(Pass); + + TEST_OK(FALSE); + TEST_OK(1 != 1); + TEST_OK(1 == 2); + TEST_RESULT(Fail); + TEST_FAIL("Fail"); + TEST_FAIL(); + + TEST_SKIP("Skip"); + TEST_SKIP(); + TEST_RESULT(Skip); + + /* Move the result to local and verify */ + C_ASSERT(sizeof(Result) == sizeof(*TEST_PARAMETER_RESULT)); + RtlCopyMemory(&Result, TEST_PARAMETER_RESULT, sizeof(Result)); + RtlZeroMemory(TEST_PARAMETER_RESULT, sizeof(*TEST_PARAMETER_RESULT)); + + TEST_OK(Result.Pass == 5); + TEST_OK(Result.Fail == 6); + TEST_OK(Result.Skip == 3); +}