Musa.Veil

repository·main·Indexed 18 days ago

https://github.com/mirokaku/musa.veil

A collection of Native API definitions for Windows providing access to undocumented internal APIs from ntoskrnl.exe, ntdll.dll, and kernelbase.dll. Designed for both user-mode and kernel-mode development, it is compatible with the Windows SDK and supports installation via NuGet, CMake FetchContent, or manual inclusion.

Tokens
2K
Snippets
8
Records
10
Agent score
63%

What's inside Musa.Veil

  1. Overview of Musa.Veil

    main

    Musa.Veil is a collection of native Windows API definitions. It provides access to undocumented APIs from ntoskrnl.exe, ntdll.dll, and kernelbase.dll.

    Key features:

    • Supports both kernel mode and user mode.
    • Compatible with /W4 and /WX compilation options.
    • Adapted for the Windows SDK.
    • API availability is managed via Windows SDK version macros.
  2. Install Musa.Veil via CMake FetchContent

    main

    You can include Musa.Veil in your CMake project using FetchContent. After making the content available, you must define an INTERFACE library to handle the include directories and then link it to your target.

    include(FetchContent)
    
    FetchContent_Declare(
        Musa.Veil
        GIT_REPOSITORY https://github.com/MiroKaku/Musa.Veil.git
        GIT_TAG main
        GIT_SHALLOW TRUE
    )
    FetchContent_MakeAvailable(Musa.Veil)
    
    add_library(Musa.Veil INTERFACE)
    target_include_directories(Musa.Veil INTERFACE "${musa.veil_SOURCE_DIR}")
    
    # Link to your target
    target_link_libraries(YourTarget PRIVATE Musa.Veil)
  3. Install Musa.Veil via NuGet

    main

    The recommended way to integrate Musa.Veil into a Windows project is via NuGet. You can either use the Visual Studio NuGet Package Manager UI or manually edit your .vcxproj file if you are using the Mile.Project.Windows template.

    <ItemGroup>
      <PackageReference Include="Musa.Veil">
        <!-- Expected version -->
        <Version>1.0.0</Version>
      </PackageReference>
    </ItemGroup>
  4. Use separate namespaces in Musa.Veil

    main

    To avoid polluting the global namespace, define the VEIL_USE_SEPARATE_NAMESPACE macro. When doing so, ensure that Veil.h is included before any other headers.

    // Define this macro to avoid polluting the global namespace
    #define VEIL_USE_SEPARATE_NAMESPACE
    
    // Ensure Veil.h is included before other headers
    #include "Veil.h"
  5. Configure Musa.Veil namespaces and headers

    main

    To use Musa.Veil in your C code, include Veil.h. If you prefer to avoid global namespace pollution, define the VEIL_USE_SEPARATE_NAMESPACE macro before including the header. Note that Veil.h must be included before any other headers.

    // If you want to use a separate namespace, define the following macro.
    #define VEIL_USE_SEPARATE_NAMESPACE
    
    // Include Veil.h before any other headers
    #include "Veil.h"
  6. Install Musa.Veil via NuGet (Recommended)

    main

    The easiest way to use Musa.Veil is through NuGet.

    1. Right-click your project in your IDE and select "Manage NuGet Packages".
    2. Search for Musa.Veil.
    3. Select the version compatible with your project and click "Install".

    If you are using the Mile.Project.Windows project template, you can add the package directly to your .vcxproj file:

    <ItemGroup>
      <PackageReference Include="Musa.Veil">
        <!-- Desired Version -->
        <Version>1.0.0</Version>
      </PackageReference>
    </ItemGroup>
  7. Generate 32-bit import libraries (.lib) for ci.dll

    main

    Generating a 32-bit import library is more complex because 32-bit functions use name decoration (e.g., CiFreePolicyInfo@4) based on argument byte sums, while ci.dll exports functions in their non-decorated shape. To bridge this, you must provide an object file containing function stubs that mimic the expected signatures.

    1. Extract exports and create a .def file as you would for 64-bit.
    2. Create a C++ stub file: Implement the functions with the correct signatures but dummy bodies (e.g., returning nullptr).
    3. Compile the stub to an .obj file: Use cl with appropriate kernel and CRT include paths.
    4. Generate the .lib file: Use the lib utility, including the newly created .obj file.
    // Example stub in CI.Stub.cpp
    _IRQL_requires_max_(PASSIVE_LEVEL)
    PVOID
    NTAPI
    CiFreePolicyInfo(
        _In_ MINCRYPT_POLICY_INFO* PolicyInfo
    )
    {
        UNREFERENCED_PARAMETER(PolicyInfo);
        return nullptr;
    }
    # Compile the stub
    SET KM_IncludePath="C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\km"
    SET CRT_IncludePath="C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\km\crt"
    SET KIT_SHARED_IncludePath="C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared"
    
    cl CI.Stub.cpp /c /kernel /Zc:wchar_t /I%KM_IncludePath% /I%CRT_IncludePath% /I%KIT_SHARED_IncludePath% /D _X86_=1 /D i386=1 /DSTD_CALL /D_MINCRYPT_LIB
    
    # Generate the .lib file using the OBJ
    lib /def:CI.def /machine:x86 /out:ci.lib CI.Stub.obj
  8. Generate x64/AMD64 import libraries (.lib) for ci.dll

    main

    Since a pre-built ci.lib is not provided, you must generate one manually to link against ci.dll in 64-bit environments.

    1. Extract exported functions: Use the dumpbin utility to identify the functions exported by the DLL.
    2. Create a .def file: Define the library name and the list of exported functions. Use the @n NONAME syntax if necessary.
    3. Generate the .lib file: Use the lib utility specifying the correct machine architecture.
    # 1. Get exported functions
    dumpbin /EXPORTS c:\windows\system32\ci.dll
    
    # 2. Create CI.def (example content)
    # LIBRARY ci.dll
    # EXPORTS
    #     CiValidateFileAsImageType       @1  NONAME
    #     ...
    
    # 3. Generate the .lib file
    lib /def:CI.def /machine:x64 /out:ci.lib
    # OR for AMD64
    lib /def:CI.def /machine:AMD64 /out:ci.lib
  9. Configure Musa.Veil include paths via MSBuild

    main

    When using Musa.Veil via NuGet in an MSBuild-based project (such as C++ projects in Visual Studio), the Musa.Veil.Config.props file automatically manages the include paths. It defines the Musa_Veil_Include property pointing to the library's include directory and appends this directory to your project's IncludePath property. This ensures that headers from the Musa.Veil repository are available to your compiler without manual path configuration.

    <!-- The following properties are managed by Musa.Veil.Config.props -->
    <Musa_Veil_Include>$(Musa_Veil_Root)\include</Musa_Veil_Include>
    <IncludePath>$(Musa_Veil_Include);$(IncludePath)</IncludePath>