Jump to content
Tuts 4 You

Kernel Mode VS User Mode


Aldhard Oswine

Recommended Posts

Aldhard Oswine

I think I've not seen a kernel-mode code.


What is the difference between a user-mode program and kernel-mode program at code level?

int main(){
	puts("HW");
}

It's simple user-mode code/program, is there something similar for kernel-mode code/program?

What is a difference between writing user-mode and kernel-mode program? Are there same APIs, etc.

Link to comment
16 hours ago, Aldhard Oswine said:

I think I've not seen a kernel-mode code.


What is the difference between a user-mode program and kernel-mode program at code level?


int main(){
	puts("HW");
}

It's simple user-mode code/program, is there something similar for kernel-mode code/program?

What is a difference between writing user-mode and kernel-mode program? Are there same APIs, etc.

 

Example Universal Windows Driver Code using Kernel-Mode Driver Framework (KMDF) :

[QUOTE]
#include <ntddk.h>
#include <wdf.h>
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;

NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT  DriverObject, _In_ PUNICODE_STRING RegistryPath)
{
    NTSTATUS status;
    WDF_DRIVER_CONFIG config;

    KdPrintEx(( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n" ));
    WDF_DRIVER_CONFIG_INIT(&config, KmdfHelloWorldEvtDeviceAdd);
    status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
    return status;
}

NTSTATUS KmdfHelloWorldEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit)
{
    NTSTATUS status;
    WDFDEVICE hDevice;
    UNREFERENCED_PARAMETER(Driver);

    KdPrintEx(( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n" ));
    status = WdfDeviceCreate(&DeviceInit, WDF_NO_OBJECT_ATTRIBUTES, &hDevice);
    return status;
}

[/QUOTE]

Full and related articles here .

 

EDIT :

@Aldhard Oswine :

You can also download the detailed but EASY TO FOLLOW guide discussing the creation of Windows Drivers here .

I have also attached the PDF to this post  so that anyone can access here in future even if that link goes offline .

See specifically from page 14 onwards and also have a look at page 42 and a few pages after that ...Hope these will help you.

Cheers :)

 

 

 

Getting started with Windows drivers - OFFICIAL PDF - April 2017 - VERY IMP.pdf

Edited by Techlord
Added OFFICIAL Microsoft PDF Link
  • Like 3
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...