#include <ntddk.h> #define MEM_TAG 'jklk' typedef struct { LIST_ENTRY List_entry; ULONG Data; }MY_LIST,*PMY_LIST; LIST_ENTRY My_listHead;//声明一个结构 void Unload(IN PDRIVER_OBJECT DriverObject) { KdPrint(("驱动卸载成功!\n")); } VOID Listinit() { InitializeListHead(&My_listHead);//初始化 } NTSTATUS MyAppendData(ULONG AppendValue) { PMY_LIST my_AppendList=(PMY_LIST)ExAllocatePoolWithTag(PagedPool,sizeof(MY_LIST), MEM_TAG); if(my_AppendList==NULL) { KdPrint(("分配空间失败\n")); return -1; } else { KdPrint(("分配空间成功\n")); } my_AppendList->Data=AppendValue; InsertHeadList(&My_listHead,(PLIST_ENTRY)my_AppendList); ExFreePool(my_AppendList); return STATUS_SUCCESS; } void ShowList() { PLIST_ENTRY p=NULL; PMY_LIST elem; KdPrint(("Show List start\n")); for( p=My_listHead.Flink;p!=My_listHead.Flink;p=p->Flink) { elem=CONTAINING_RECORD(My_listHead.Flink,MY_LIST,List_entry); KdPrint(("Value Is%x \n",elem->Data)); } } NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegPath) { ULONG value; value=0; KdPrint(("驱动加载成功!\n")); Listinit(); for(value=0;value<10;value++) MyAppendData(value); ShowList(); DriverObject->DriverUnload=Unload; return STATUS_SUCCESS; }
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课