https://cloud.tencent.com/developer/article/1875879
#include <ntddk.h>
typedef struct _TestListEntry {
ULONG m_ulDataA;
ULONG m_ulDataB;
LIST_ENTRY m_ListEntry;
ULONG m_ulDataC;
ULONG m_ulDataD;
}TestListEntry,*PTestListEntry;
VOID Unload(IN PDRIVER_OBJECT DriverObject) {
if (DriverObject!=NULL)
{
KdPrint(("driver unload \r\n"));
DbgPrint("hello kernel currentProcessId = 0x%p\n", PsGetCurrentProcessId());
}
return;
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegisteryPath) {
DriverObject->DriverUnload = Unload;
KdBreakPoint();
//link list;
LIST_ENTRY ListHeader = { 0 };
InitializeListHead(&ListHeader);
TestListEntry EntryA = { 0 };
EntryA.m_ulDataA = 'A';
TestListEntry EntryB = { 0 };
EntryB.m_ulDataA = 'B';
TestListEntry EntryC = { 0 };
EntryC.m_ulDataA = 'C';
InsertHeadList(&ListHeader,&EntryB.m_ListEntry);
InsertHeadList(&ListHeader, &EntryA.m_ListEntry);
InsertTailList(&ListHeader, &EntryC.m_ListEntry);
//Heander->A->B->C
//遍历
//flink 从前往后
DbgPrint("FLINK BROSWER\n");
PLIST_ENTRY pListEnrty = NULL;
pListEnrty = ListHeader.Flink;
while (pListEnrty!=&ListHeader)
{
PTestListEntry pTestEnrty = CONTAINING_RECORD(pListEnrty, TestListEntry, m_ListEntry);
DbgPrint("listPtr = %p,Enrty = %p,Tag = %c\n",pListEnrty,pTestEnrty,(CHAR)pTestEnrty->m_ulDataA);
pListEnrty = pListEnrty->Flink;
}
//blink 从后往前
DbgPrint("remove node\n");
//
//RemoveHeadList();
//RemoveTailList();
//RemoveEntryList();
//IsListEmpty();
return STATUS_SUCCESS;
}