• Stars
    star
    178
  • Rank 214,044 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 3 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C# Kernel Mode Driver example using NativeAOT

KernelSharp

This is an example of how to use NativeAOT to compile C# code to a Windows Kernel Mode driver. This repository contains parts of https://github.com/ZeroLP/ZeroKernel.

If you want to see an example of a full memory R/W Driver using this, check out my repo https://github.com/VollRagm/KernelBypassSharp.

Compiling

Open the build.bat and fix the file paths. ILCPATH is located at C:\Users\username\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-alpha.1.21430.2\tools, ntoskrnl.lib is located in the WDK install path. Run x64 Native Tools Command Prompt for VS 2019, cd into the project directory and run build.bat. You can load the driver or map it with kdmapper.

Creating a project

Follow the Quick start guide to create a new native project. After that simply edit the project file itself and add all properties from the project in this repository. After including WDK.cs and the Runtime folder in your project you will be able to compile it.

Features

  • Call any kernel export
  • Convert C# strings to multibyte characters
  • Reading cr3

Limitations

  • No support for variadic arguments
  • No managed multibyte character string type, conversion is required
  • The native compiler misplaces globally declared strings wrongly, causing a bluescreen when referenced