Win Kernel 链表

API

  1. 初始化:InitializeListHead
  2. 插入: InsertHeadListInsertTailList
  3. 删除: RemoveHeadListRemoveTailList

list.h

1
2
3
4
5
6
7
#pragma once
#include <wdm.h>

typedef struct UserList {
LIST_ENTRY ListEntry;
UNICODE_STRING UserName;
}UserList, * PUserList;

Driver.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <wdm.h>
#include "list.h"

VOID DriverUnload(PDRIVER_OBJECT driverObject)
{

}

NTSTATUS DriverEntry(PDRIVER_OBJECT driverObject, PUNICODE_STRING registryPath)
{
DbgPrint("[TEST] Run\n");
DbgBreakPoint();
driverObject->DriverUnload = DriverUnload;
UserList userListHead = { 0 };
RtlInitUnicodeString(&userListHead.UserName, L"Zhangsan");
UserList userListNodeA = { 0 };
RtlInitUnicodeString(&userListNodeA.UserName, L"Lisi");
UserList userListNodeB = { 0 };
RtlInitUnicodeString(&userListNodeB.UserName, L"Wangwu");
InitializeListHead(&userListHead.ListEntry);
InsertTailList(&userListHead.ListEntry, &userListNodeA.ListEntry);
InsertTailList(&userListHead.ListEntry, &userListNodeB.ListEntry);
PLIST_ENTRY pListEntry = &userListHead.ListEntry;
do
{
PUserList tmp = pListEntry;
DbgPrint("[TEST] Name: %wZ\n", tmp->UserName);
pListEntry = pListEntry->Flink;
} while (pListEntry != &userListHead.ListEntry);
}