Windows内核遍历驱动模块源码分析
要获取windows 内核中所有驱动模块信息,调用 系统服务函数 NtQuerySystemInformation,参数SystemInformationClass 传入SystemModuleInformation.
NtQuerySystemInformation申明如下:
- //
- // System Information Classes.
- //
- typedef enum _SYSTEM_INFORMATION_CLASS {
- SystemBasicInformation,
- SystemProcessorInformation, // obsolete...delete
- SystemPerformanceInformation,
- SystemTimeOfDayInformation,
- SystemPathInformation,
- SystemProcessInformation, //系统进程信息
- SystemCallCountInformation,
- SystemDeviceInformation,
- SystemProcessorPerformanceInformation,
- SystemFlagsInformation,
- SystemCallTimeInformation,
- SystemModuleInformation, //系统模块
- SystemLocksInformation,
- SystemStackTraceInformation,
- SystemPagedPoolInformation,
- SystemNonPagedPoolInformation,
- SystemHandleInformation,
- SystemObjectInformation,
- SystemPageFileInformation,
- SystemVdmInstemulInformation,
- SystemVdmBopInformation,
- SystemFileCacheInformation,
- SystemPoolTagInformation,
- SystemInterruptInformation,
- SystemDpcBehaviorInformation,
- SystemFullMemoryInformation,
- SystemLoadGdiDriverInformation,
- SystemUnloadGdiDriverInformation,
- SystemTimeAdjustmentInformation,
- SystemSummaryMemoryInformation,
- SystemMirrorMemoryInformation,
- SystemPerformanceTraceInformation,
- SystemObsolete0,
- SystemExceptionInformation,
- SystemCrashDumpStateInformation,
- SystemKernelDebuggerInformation,
- SystemContextSwitchInformation,
- SystemRegistryQuotaInformation,
- SystemExtendServiceTableInformation,
- SystemPrioritySeperation,
- SystemVerifierAddDriverInformation,
- SystemVerifierRemoveDriverInformation,
- SystemProcessorIdleInformation,
- SystemLegacyDriverInformation,
- SystemCurrentTimeZoneInformation,
- SystemLookasideInformation,
- SystemTimeSlipNotification,
- SystemSessionCreate,
- SystemSessionDetach,
- SystemSessionInformation,
- SystemRangeStartInformation,
- SystemVerifierInformation,
- SystemVerifierThunkExtend,
- SystemSessionProcessInformation,
- SystemLoadGdiDriverInSystemSpace,
- SystemNumaProcessorMap,
- SystemPrefetcherInformation,
- SystemExtendedProcessInformation,
- SystemRecommendedSharedDataAlignment,
- SystemComPlusPackage,
- SystemNumaAvailableMemory,
- SystemProcessorPowerInformation,
- SystemEmulationBasicInformation,
- SystemEmulationProcessorInformation,
- SystemExtendedHandleInformation,
- SystemLostDelayedWriteInformation,
- SystemBigPoolInformation,
- SystemSessionPoolTagInformation,
- SystemSessionMappedViewInformation,
- SystemHotpatchInformation,
- SystemObjectSecurityMode,
- SystemWatchdogTimerHandler,
- SystemWatchdogTimerInformation,
- SystemLogicalProcessorInformation,
- SystemWow64SharedInformation,
- SystemRegisterFirmwareTableInformationHandler,
- SystemFirmwareTableInformation,
- SystemModuleInformationEx,
- SystemVerifierTriageInformation,
- SystemSuperfetchInformation,
- SystemMemoryListInformation,
- SystemFileCacheInformationEx,
- MaxSystemInfoClass // MaxSystemInfoClass should always be the last enum
- } SYSTEM_INFORMATION_CLASS;

- //
- // System Information Classes.
- //
- typedef enum _SYSTEM_INFORMATION_CLASS {
- SystemBasicInformation,
- SystemProcessorInformation, // obsolete...delete
- SystemPerformanceInformation,
- SystemTimeOfDayInformation,
- SystemPathInformation,
- SystemProcessInformation, //系统进程信息
- SystemCallCountInformation,
- SystemDeviceInformation,
- SystemProcessorPerformanceInformation,
- SystemFlagsInformation,
- SystemCallTimeInformation,
- SystemModuleInformation, //系统模块
- SystemLocksInformation,
- SystemStackTraceInformation,
- SystemPagedPoolInformation,
- SystemNonPagedPoolInformation,
- SystemHandleInformation,
- SystemObjectInformation,
- SystemPageFileInformation,
- SystemVdmInstemulInformation,
- SystemVdmBopInformation,
- SystemFileCacheInformation,
- SystemPoolTagInformation,
- SystemInterruptInformation,
- SystemDpcBehaviorInformation,
- SystemFullMemoryInformation,
- SystemLoadGdiDriverInformation,
- SystemUnloadGdiDriverInformation,
- SystemTimeAdjustmentInformation,
- SystemSummaryMemoryInformation,
- SystemMirrorMemoryInformation,
- SystemPerformanceTraceInformation,
- SystemObsolete0,
- SystemExceptionInformation,
- SystemCrashDumpStateInformation,
- SystemKernelDebuggerInformation,
- SystemContextSwitchInformation,
- SystemRegistryQuotaInformation,
- SystemExtendServiceTableInformation,
- SystemPrioritySeperation,
- SystemVerifierAddDriverInformation,
- SystemVerifierRemoveDriverInformation,
- SystemProcessorIdleInformation,
- SystemLegacyDriverInformation,
- SystemCurrentTimeZoneInformation,
- SystemLookasideInformation,
- SystemTimeSlipNotification,
- SystemSessionCreate,
- SystemSessionDetach,
- SystemSessionInformation,
- SystemRangeStartInformation,
- SystemVerifierInformation,
- SystemVerifierThunkExtend,
- SystemSessionProcessInformation,
- SystemLoadGdiDriverInSystemSpace,
- SystemNumaProcessorMap,
- SystemPrefetcherInformation,
- SystemExtendedProcessInformation,
- SystemRecommendedSharedDataAlignment,
- SystemComPlusPackage,
- SystemNumaAvailableMemory,
- SystemProcessorPowerInformation,
- SystemEmulationBasicInformation,
- SystemEmulationProcessorInformation,
- SystemExtendedHandleInformation,
- SystemLostDelayedWriteInformation,
- SystemBigPoolInformation,
- SystemSessionPoolTagInformation,
- SystemSessionMappedViewInformation,
- SystemHotpatchInformation,
- SystemObjectSecurityMode,
- SystemWatchdogTimerHandler,
- SystemWatchdogTimerInformation,
- SystemLogicalProcessorInformation,
- SystemWow64SharedInformation,
- SystemRegisterFirmwareTableInformationHandler,
- SystemFirmwareTableInformation,
- SystemModuleInformationEx,
- SystemVerifierTriageInformation,
- SystemSuperfetchInformation,
- SystemMemoryListInformation,
- SystemFileCacheInformationEx,
- MaxSystemInfoClass // MaxSystemInfoClass should always be the last enum
- } SYSTEM_INFORMATION_CLASS;
- NTSTATUS
- NtQuerySystemInformation (
- IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
- OUT PVOID SystemInformation,
- IN ULONG SystemInformationLength,
- OUT PULONG ReturnLength OPTIONAL
- )

- NTSTATUS
- NtQuerySystemInformation (
- IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
- OUT PVOID SystemInformation,
- IN ULONG SystemInformationLength,
- OUT PULONG ReturnLength OPTIONAL
- )
根据泄漏出的widows 2000 部分源代码,NtQuerySystemInformation 有关 SystemModuleInformation的实现部分如下:
- case SystemModuleInformation:
- KeEnterCriticalRegion();
- ExAcquireResourceExclusive( &PsLoadedModuleResource, TRUE );
- ReleaseModuleResoure = TRUE;
- Status = ExpQueryModuleInformation( &PsLoadedModuleList,
- &MmLoadedUserImageList,
- (PRTL_PROCESS_MODULES)SystemInformation,
- SystemInformationLength,
- ReturnLength
- );
- ExReleaseResource (&PsLoadedModuleResource);
- ReleaseModuleResoure = FALSE;
- KeLeaveCriticalRegion();
- break;

- case SystemModuleInformation:
- KeEnterCriticalRegion();
- ExAcquireResourceExclusive( &PsLoadedModuleResource, TRUE );
- ReleaseModuleResoure = TRUE;
- Status = ExpQueryModuleInformation( &PsLoadedModuleList,
- &MmLoadedUserImageList,
- (PRTL_PROCESS_MODULES)SystemInformation,
- SystemInformationLength,
- ReturnLength
- );
- ExReleaseResource (&PsLoadedModuleResource);
- ReleaseModuleResoure = FALSE;
- KeLeaveCriticalRegion();
- break;
在Windows内核实现中,存在两个存储系统加载模块的两个链表,分别是PsLoadedModuleList和 MmLoadedUserImageList,两个全局变量 申明如下:
- LIST_ENTRY PsLoadedModuleList;//驱动模块列表
- LIST_ENTRY MmLoadedUserImageList;//应用程序映像列表

- LIST_ENTRY PsLoadedModuleList;//驱动模块列表
- LIST_ENTRY MmLoadedUserImageList;//应用程序映像列表
Windows就是通过这两个链表将代表系统模块的_LDR_DATA_ENTRY结构链接在一起。
_LDR_DATA_ENTRY结构体中有3个 _LIST_ENTRY,系统根据不同排列顺序串连系统中所加载的所有模块,情况就相当明显了,只要遍历任何一个双向链表,即可获得加载的模块信息。
在Windows 内核中,表示每个模块的数据结构是_LDR_DATA_TABLE_ENTRY,其结构申明为:
- kd> dt _LDR_DATA_TABLE_ENTRY
- nt!_LDR_DATA_TABLE_ENTRY
- +0x000 InLoadOrderLinks : _LIST_ENTRY
- +0x008 InMemoryOrderLinks : _LIST_ENTRY
- +0x010 InInitializationOrderLinks : _LIST_ENTRY
- +0x018 DllBase : Ptr32 Void
- +0x01c EntryPoint : Ptr32 Void
- +0x020 SizeOfImage : Uint4B
- +0x024 FullDllName : _UNICODE_STRING
- +0x02c BaseDllName : _UNICODE_STRING
- +0x034 Flags : Uint4B
- +0x038 LoadCount : Uint2B
- +0x03a TlsIndex : Uint2B
- +0x03c HashLinks : _LIST_ENTRY
- +0x03c SectionPointer : Ptr32 Void
- +0x040 CheckSum : Uint4B
- +0x044 TimeDateStamp : Uint4B
- +0x044 LoadedImports : Ptr32 Void
- +0x048 EntryPointActivationContext : Ptr32 Void
- +0x04c PatchInformation : Ptr32 Void

- kd> dt _LDR_DATA_TABLE_ENTRY
- nt!_LDR_DATA_TABLE_ENTRY
- +0x000 InLoadOrderLinks : _LIST_ENTRY
- +0x008 InMemoryOrderLinks : _LIST_ENTRY
- +0x010 InInitializationOrderLinks : _LIST_ENTRY
- +0x018 DllBase : Ptr32 Void
- +0x01c EntryPoint : Ptr32 Void
- +0x020 SizeOfImage : Uint4B
- +0x024 FullDllName : _UNICODE_STRING
- +0x02c BaseDllName : _UNICODE_STRING
- +0x034 Flags : Uint4B
- +0x038 LoadCount : Uint2B
- +0x03a TlsIndex : Uint2B
- +0x03c HashLinks : _LIST_ENTRY
- +0x03c SectionPointer : Ptr32 Void
- +0x040 CheckSum : Uint4B
- +0x044 TimeDateStamp : Uint4B
- +0x044 LoadedImports : Ptr32 Void
- +0x048 EntryPointActivationContext : Ptr32 Void
- +0x04c PatchInformation : Ptr32 Void
jpg改rar
Windows内核遍历驱动模块源码分析的更多相关文章
- Linux 内核调度器源码分析 - 初始化
导语 上篇系列文 混部之殇-论云原生资源隔离技术之CPU隔离(一) 介绍了云原生混部场景中CPU资源隔离核心技术:内核调度器,本系列文章<Linux内核调度器源码分析>将从源码的角度剖析内 ...
- 鸿蒙轻内核M核源码分析:LibC实现之Musl LibC
摘要:本文学习了LiteOS-M内核Musl LibC的实现,特别是文件系统和内存分配释放部分. 本文分享自华为云社区<鸿蒙轻内核M核源码分析系列十九 Musl LibC>,作者:zhus ...
- HashSet 添加/遍历元素源码分析
HashSet 类图 HashSet 简单说明 HashSet 实现了 Set 接口 HashSet 底层实际上是由 HashMap 实现的 public HashSet() { map = new ...
- 面经手册 · 第4篇《HashMap数据插入、查找、删除、遍历,源码分析》
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 在上一章节我们讲解并用数据验证了,HashMap中的,散列表的实现.扰动函数.负载因 ...
- ARMv8 Linux内核head.S源码分析
ARMv8Linux内核head.S主要工作内容: 1. 从el2特权级退回到el1 2. 确认处理器类型 3. 计算内核镜像的起始物理地址及物理地址与虚拟地址之间的偏移 4. 验证设备树的地址是否有 ...
- 鸿蒙轻内核源码分析:文件系统FatFS
摘要:本文为大家介绍FatFS文件系统结构体的结构体和全局变量,并分析FatFS文件操作接口. 本文分享自华为云社区<鸿蒙轻内核M核源码分析系列二一 03 文件系统FatFS>,作者:zh ...
- 鸿蒙轻内核源码分析:文件系统LittleFS
摘要:本文先介绍下LFS文件系统结构体的结构体和全局变量,然后分析下LFS文件操作接口. 本文分享自华为云社区<# 鸿蒙轻内核M核源码分析系列二一 02 文件系统LittleFS>,作者: ...
- 鸿蒙内核源码分析(字符设备篇) | 字节为单位读写的设备 | 百篇博客分析OpenHarmony源码 | v67.01
百篇博客系列篇.本篇为: v67.xx 鸿蒙内核源码分析(字符设备篇) | 字节为单位读写的设备 | 51.c.h.o 文件系统相关篇为: v62.xx 鸿蒙内核源码分析(文件概念篇) | 为什么说一 ...
- 鸿蒙内核源码分析(GN应用篇) | GN语法及在鸿蒙的使用 | 百篇博客分析OpenHarmony源码 | v60.01
百篇博客系列篇.本篇为: v60.xx 鸿蒙内核源码分析(gn应用篇) | gn语法及在鸿蒙的使用 | 51.c.h.o 编译构建相关篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙 ...
随机推荐
- MySQL连表操作之一对多
引入 当我们在数据库中创建表的时候,有可能某些列中值内容量很大,而且重复. 例子:创建一个学生表,按学校年纪班级分,表的内容大致如下: id name partment 1 xxx x学校x年级x班级 ...
- Photon服务器进阶&一个新游戏的出产(三)
下面或许该介绍介绍我用Photon写的一个4人联机麻将了~ 上图
- 通过jquery的serializearray处理表单数据成json格式,并提交到后台处理
var params = $("#myform").serializeArray(); var values = {}; for (var item in params) { va ...
- sobel算子的一些细节
1. 形式 Gy 上下颠倒的 (*A表示卷积图像,忽略先): 看得出来,sobel算子感觉并不统一,特别是方向,我们知道matlab的图像格式是,x轴从左到右,y轴从上到下,原点在左上角. 所以,第二 ...
- C++ ## ... 实用
关于...的使用...在C宏中称为Variadic Macro,也就是变参宏.比如:#define myprintf(templt,...)fprintf(stderr,templt,__VA_ARG ...
- ab 轻量的压测工具
阅读:http://www.cnblogs.com/luminji/archive/2011/09/02/2163525.html
- ETL简介
1.ETL的定义 ETL分别是“Extract”.“ Transform” .“Load”三个单词的首字母缩写也就是“抽取”.“转换”.“装载”,但我们日常往往简称其为数据抽取. ETL是BI/DW( ...
- LYDSY模拟赛day2 Divisors
/* 注意分解质因数,如果i是,那么n/i也是,这样就可以解决分解质因数的时间问题了 当 k ≥ 1 时,只有这些数的约数才会对答案产生贡献. 求出 m 个数的所有不超过 n 的约数,去重后统计即可. ...
- WSDL2java简单使用
一.使用工具WSDL2java把接口转为本地可调用的.java文件 工具的目录结构: 设置WSDL2Java(URL).bat中的参数 set Axis_Lib=.\lib set Java_Cmd= ...
- Linux进程间通信(八):流套接字 socket()、bind()、listen()、accept()、connect()、read()、write()、close()
前面说到的进程间的通信,所通信的进程都是在同一台计算机上的,而使用socket进行通信的进程可以是同一台计算机的进程,也是可以是通过网络连接起来的不同计算机上的进程.通常我们使用socket进行网络编 ...