mrexodia/phnt-single-header

GitHub: mrexodia/phnt-single-header

将 System Informer 的 phnt Windows 原生 API 库整合为单头文件形式,大幅简化底层开发集成流程。

Stars: 241 | Forks: 18

# phnt-single-header 本仓库自动生成 [System Informer](https://github.com/winsiderss/systeminformer) 的 [phnt](https://github.com/winsiderss/systeminformer/tree/master/phnt) 库的单头文件版本。创建本仓库是因为原始库拆分为许多头文件,集成到你的项目中可能比较繁琐。 ## 用法 这是一个使用 phnt 的简单示例 ``` #define PHNT_VERSION PHNT_WIN11 #include "phnt.h" // Instead of Windows.h // Imports for ntdll.dll #pragma comment(lib, "ntdll.lib") static char message[] = "Hello, phnt!\r\n"; int main() { IO_STATUS_BLOCK IoStatusBlock = { 0, 0 }; NtWriteFile( NtCurrentPeb()->ProcessParameters->StandardOutput, NULL, NULL, NULL, &IoStatusBlock, message, strlen(message) - 1, NULL, NULL ); return 0; } ``` ## 下载 [`phnt.h`](https://github.com/mrexodia/phnt-single-header/releases/latest/download/phnt.h)([最新发布版](https://github.com/mrexodia/phnt-single-header/releases/latest)的直接链接)。 ## CMake 要在 CMake 中快速使用此库,请使用 [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html): ``` cmake_minimum_required(VERSION 3.24) cmake_policy(SET CMP0135 NEW) project(phnt-example) include(FetchContent) set(phnt_TAG "v1.4-ed73b907") message(STATUS "Fetching phnt (${phnt_TAG})...") FetchContent_Declare(phnt URL "https://github.com/mrexodia/phnt-single-header/releases/download/${phnt_TAG}/phnt.zip" URL_HASH "SHA256=a41def8d91204dc8c1d322a9d20b5fa107f99138ed0ad8bf52d6353137000dd5" ) FetchContent_MakeAvailable(phnt) add_executable(example main.cpp) target_link_libraries(example PRIVATE phnt::phnt) ``` 除了使用 `FetchContent`,你也可以将 [`phnt.zip`](https://github.com/mrexodia/phnt-single-header/releases/latest/download/phnt.zip) 解压到项目的 `third_party/phnt` 目录中,然后执行: ``` add_subdirectory(third_party/phnt) ``` 目标 `phnt::phnt` 也会链接到 `ntdll.lib`。如果你想避免这种情况,可以改为链接 `phnt::headers`。 _注意_:`phnt.zip` 中的 CMake 项目也可以作为 CMake 包使用。在配置并安装它之后,你可以执行 `find_package(phnt REQUIRED)`,一切应该都能开箱即用。 ## 旧版 SDK 要将 phnt 与旧版 SDK 配合使用,请将 `PHNT_VERSION` 更改为以下值之一: ``` #define PHNT_VERSION PHNT_WIN2K #define PHNT_VERSION PHNT_WINXP #define PHNT_VERSION PHNT_WS03 #define PHNT_VERSION PHNT_VISTA #define PHNT_VERSION PHNT_WIN7 #define PHNT_VERSION PHNT_WIN8 #define PHNT_VERSION PHNT_WINBLUE #define PHNT_VERSION PHNT_THRESHOLD #define PHNT_VERSION PHNT_THRESHOLD2 #define PHNT_VERSION PHNT_REDSTONE #define PHNT_VERSION PHNT_REDSTONE2 #define PHNT_VERSION PHNT_REDSTONE3 #define PHNT_VERSION PHNT_REDSTONE4 #define PHNT_VERSION PHNT_REDSTONE5 #define PHNT_VERSION PHNT_19H1 #define PHNT_VERSION PHNT_19H2 #define PHNT_VERSION PHNT_20H1 #define PHNT_VERSION PHNT_20H2 #define PHNT_VERSION PHNT_21H1 #define PHNT_VERSION PHNT_WIN10_21H2 #define PHNT_VERSION PHNT_WIN10_22H2 #define PHNT_VERSION PHNT_WIN11 #define PHNT_VERSION PHNT_WIN11_22H2 ```
标签:Awesome列表, Bash脚本, C/C++, CMake, Native API, NTDLL, PHNT, System Informer, UML, Windows API, Windows NT, Windows 内核编程, Windows 内部机制, 事务性I/O, 云资产清单, 单头文件库, 底层开发, 系统编程, 网络安全监控, 逆向工程, 驱动开发