4 releases

0.1.3 Mar 8, 2024
0.1.2 Oct 16, 2022
0.1.1 Jan 19, 2022
0.1.0 Jan 19, 2022

#372 in Hardware support

36 downloads per month

Custom license

5KB

Rust crates.io docs.rs

kernel-log-rs

A minimalistic logger for Windows Kernel Drivers.

Usage

#![no_std]

use kernel_log::KernelLogger;

#[no_mangle]
pub extern "system" fn DriverEntry(_: PDRIVER_OBJECT, _: u64) -> NTSTATUS {
    KernelLogger::init(LevelFilter::Info).expect("Failed to initialize logger");

    log::warn!("This is an example message.")
}

lib.rs:

Implements the print!, println! and dbg! macros so they can be used in the kernel without the use of an allocator.

By default the macros are prefixed with kernel_. If you want to remove the prefix, you can enable the std_name feature.

Usage

Exactly as you'd use the original macros from the standard library.

#![no_std]

// ...

kernel_dbg!(2 + 2);
kernel_print!("{} + {} = {}\n", 2, 2, 2 + 2);
kernel_println!("{} + {} = {}", 2, 2, 2 + 2);

Features

  • std_name: Allows you to use the macros without the kernel_ prefix.
  • format: Uses the format! macro instead of the core::fmt::Write trait to convert the passed data into a string. This crate provides a simple wrapper for logging with the DbgPrint function. The logs won't be included in the final binary which helps to harden reverse engineering.

Dependencies

~0.7–1MB
~24K SLoC