要获取windows 内核中所有驱动模块信息,调用 系统服务函数 NtQuerySystemInformation,参数SystemInformationClass 传入SystemModuleInformation.

NtQuerySystemInformation申明如下:

  1. //
  2. // System Information Classes.
  3. //
  4. typedef enum _SYSTEM_INFORMATION_CLASS {
  5. SystemBasicInformation,
  6. SystemProcessorInformation,              // obsolete...delete
  7. SystemPerformanceInformation,
  8. SystemTimeOfDayInformation,
  9. SystemPathInformation,
  10. SystemProcessInformation,                //系统进程信息
  11. SystemCallCountInformation,
  12. SystemDeviceInformation,
  13. SystemProcessorPerformanceInformation,
  14. SystemFlagsInformation,
  15. SystemCallTimeInformation,
  16. SystemModuleInformation,     //系统模块
  17. SystemLocksInformation,
  18. SystemStackTraceInformation,
  19. SystemPagedPoolInformation,
  20. SystemNonPagedPoolInformation,
  21. SystemHandleInformation,
  22. SystemObjectInformation,
  23. SystemPageFileInformation,
  24. SystemVdmInstemulInformation,
  25. SystemVdmBopInformation,
  26. SystemFileCacheInformation,
  27. SystemPoolTagInformation,
  28. SystemInterruptInformation,
  29. SystemDpcBehaviorInformation,
  30. SystemFullMemoryInformation,
  31. SystemLoadGdiDriverInformation,
  32. SystemUnloadGdiDriverInformation,
  33. SystemTimeAdjustmentInformation,
  34. SystemSummaryMemoryInformation,
  35. SystemMirrorMemoryInformation,
  36. SystemPerformanceTraceInformation,
  37. SystemObsolete0,
  38. SystemExceptionInformation,
  39. SystemCrashDumpStateInformation,
  40. SystemKernelDebuggerInformation,
  41. SystemContextSwitchInformation,
  42. SystemRegistryQuotaInformation,
  43. SystemExtendServiceTableInformation,
  44. SystemPrioritySeperation,
  45. SystemVerifierAddDriverInformation,
  46. SystemVerifierRemoveDriverInformation,
  47. SystemProcessorIdleInformation,
  48. SystemLegacyDriverInformation,
  49. SystemCurrentTimeZoneInformation,
  50. SystemLookasideInformation,
  51. SystemTimeSlipNotification,
  52. SystemSessionCreate,
  53. SystemSessionDetach,
  54. SystemSessionInformation,
  55. SystemRangeStartInformation,
  56. SystemVerifierInformation,
  57. SystemVerifierThunkExtend,
  58. SystemSessionProcessInformation,
  59. SystemLoadGdiDriverInSystemSpace,
  60. SystemNumaProcessorMap,
  61. SystemPrefetcherInformation,
  62. SystemExtendedProcessInformation,
  63. SystemRecommendedSharedDataAlignment,
  64. SystemComPlusPackage,
  65. SystemNumaAvailableMemory,
  66. SystemProcessorPowerInformation,
  67. SystemEmulationBasicInformation,
  68. SystemEmulationProcessorInformation,
  69. SystemExtendedHandleInformation,
  70. SystemLostDelayedWriteInformation,
  71. SystemBigPoolInformation,
  72. SystemSessionPoolTagInformation,
  73. SystemSessionMappedViewInformation,
  74. SystemHotpatchInformation,
  75. SystemObjectSecurityMode,
  76. SystemWatchdogTimerHandler,
  77. SystemWatchdogTimerInformation,
  78. SystemLogicalProcessorInformation,
  79. SystemWow64SharedInformation,
  80. SystemRegisterFirmwareTableInformationHandler,
  81. SystemFirmwareTableInformation,
  82. SystemModuleInformationEx,
  83. SystemVerifierTriageInformation,
  84. SystemSuperfetchInformation,
  85. SystemMemoryListInformation,
  86. SystemFileCacheInformationEx,
  87. MaxSystemInfoClass   // MaxSystemInfoClass should always be the last enum
  88. } 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;
  1. NTSTATUS
  2. NtQuerySystemInformation (
  3. IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
  4. OUT PVOID SystemInformation,
  5. IN ULONG SystemInformationLength,
  6. OUT PULONG ReturnLength OPTIONAL
  7. )
NTSTATUS
NtQuerySystemInformation (
IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
OUT PVOID SystemInformation,
IN ULONG SystemInformationLength,
OUT PULONG ReturnLength OPTIONAL
)

根据泄漏出的widows 2000 部分源代码,NtQuerySystemInformation 有关 SystemModuleInformation的实现部分如下:

  1. case SystemModuleInformation:
  2. KeEnterCriticalRegion();
  3. ExAcquireResourceExclusive( &PsLoadedModuleResource, TRUE );
  4. ReleaseModuleResoure = TRUE;
  5. Status = ExpQueryModuleInformation( &PsLoadedModuleList,
  6. &MmLoadedUserImageList,
  7. (PRTL_PROCESS_MODULES)SystemInformation,
  8. SystemInformationLength,
  9. ReturnLength
  10. );
  11. ExReleaseResource (&PsLoadedModuleResource);
  12. ReleaseModuleResoure = FALSE;
  13. KeLeaveCriticalRegion();
  14. 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,两个全局变量 申明如下:

  1. LIST_ENTRY PsLoadedModuleList;//驱动模块列表
  2. LIST_ENTRY MmLoadedUserImageList;//应用程序映像列表
LIST_ENTRY PsLoadedModuleList;//驱动模块列表
LIST_ENTRY MmLoadedUserImageList;//应用程序映像列表

Windows就是通过这两个链表将代表系统模块的_LDR_DATA_ENTRY结构链接在一起。

_LDR_DATA_ENTRY结构体中有3个 _LIST_ENTRY,系统根据不同排列顺序串连系统中所加载的所有模块,情况就相当明显了,只要遍历任何一个双向链表,即可获得加载的模块信息。

在Windows 内核中,表示每个模块的数据结构是_LDR_DATA_TABLE_ENTRY,其结构申明为:

  1. kd> dt _LDR_DATA_TABLE_ENTRY
  2. nt!_LDR_DATA_TABLE_ENTRY
  3. +0x000 InLoadOrderLinks : _LIST_ENTRY
  4. +0x008 InMemoryOrderLinks : _LIST_ENTRY
  5. +0x010 InInitializationOrderLinks : _LIST_ENTRY
  6. +0x018 DllBase          : Ptr32 Void
  7. +0x01c EntryPoint       : Ptr32 Void
  8. +0x020 SizeOfImage      : Uint4B
  9. +0x024 FullDllName      : _UNICODE_STRING
  10. +0x02c BaseDllName      : _UNICODE_STRING
  11. +0x034 Flags            : Uint4B
  12. +0x038 LoadCount        : Uint2B
  13. +0x03a TlsIndex         : Uint2B
  14. +0x03c HashLinks        : _LIST_ENTRY
  15. +0x03c SectionPointer   : Ptr32 Void
  16. +0x040 CheckSum         : Uint4B
  17. +0x044 TimeDateStamp    : Uint4B
  18. +0x044 LoadedImports    : Ptr32 Void
  19. +0x048 EntryPointActivationContext : Ptr32 Void
  20. +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内核遍历驱动模块源码分析的更多相关文章

  1. Linux 内核调度器源码分析 - 初始化

    导语 上篇系列文 混部之殇-论云原生资源隔离技术之CPU隔离(一) 介绍了云原生混部场景中CPU资源隔离核心技术:内核调度器,本系列文章<Linux内核调度器源码分析>将从源码的角度剖析内 ...

  2. 鸿蒙轻内核M核源码分析:LibC实现之Musl LibC

    摘要:本文学习了LiteOS-M内核Musl LibC的实现,特别是文件系统和内存分配释放部分. 本文分享自华为云社区<鸿蒙轻内核M核源码分析系列十九 Musl LibC>,作者:zhus ...

  3. HashSet 添加/遍历元素源码分析

    HashSet 类图 HashSet 简单说明 HashSet 实现了 Set 接口 HashSet 底层实际上是由 HashMap 实现的 public HashSet() { map = new ...

  4. 面经手册 · 第4篇《HashMap数据插入、查找、删除、遍历,源码分析》

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 在上一章节我们讲解并用数据验证了,HashMap中的,散列表的实现.扰动函数.负载因 ...

  5. ARMv8 Linux内核head.S源码分析

    ARMv8Linux内核head.S主要工作内容: 1. 从el2特权级退回到el1 2. 确认处理器类型 3. 计算内核镜像的起始物理地址及物理地址与虚拟地址之间的偏移 4. 验证设备树的地址是否有 ...

  6. 鸿蒙轻内核源码分析:文件系统FatFS

    摘要:本文为大家介绍FatFS文件系统结构体的结构体和全局变量,并分析FatFS文件操作接口. 本文分享自华为云社区<鸿蒙轻内核M核源码分析系列二一 03 文件系统FatFS>,作者:zh ...

  7. 鸿蒙轻内核源码分析:文件系统LittleFS

    摘要:本文先介绍下LFS文件系统结构体的结构体和全局变量,然后分析下LFS文件操作接口. 本文分享自华为云社区<# 鸿蒙轻内核M核源码分析系列二一 02 文件系统LittleFS>,作者: ...

  8. 鸿蒙内核源码分析(字符设备篇) | 字节为单位读写的设备 | 百篇博客分析OpenHarmony源码 | v67.01

    百篇博客系列篇.本篇为: v67.xx 鸿蒙内核源码分析(字符设备篇) | 字节为单位读写的设备 | 51.c.h.o 文件系统相关篇为: v62.xx 鸿蒙内核源码分析(文件概念篇) | 为什么说一 ...

  9. 鸿蒙内核源码分析(GN应用篇) | GN语法及在鸿蒙的使用 | 百篇博客分析OpenHarmony源码 | v60.01

    百篇博客系列篇.本篇为: v60.xx 鸿蒙内核源码分析(gn应用篇) | gn语法及在鸿蒙的使用 | 51.c.h.o 编译构建相关篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙 ...

随机推荐

  1. a版本冲刺第十天

    队名:Aruba   队员: 黄辉昌 李陈辉 林炳锋 鄢继仁 张秀锋 章  鼎 408: 十天体会:完成冲刺很开心,大家一起为同一件事情努力的感觉还是很不错的,众人拾柴火焰高,而且冲刺的时候会有一种压 ...

  2. Resharper的使用

    一:Reshaper是什么 即便是那些整天攻击 .NET 和 C# 的人,也常常不得不承认 Visual Studio 确实是个够强大的 IDE,除非他认为更少的 IDE 功能和命令行调试才是更强大的 ...

  3. Excel 转Latex 及tex表格的处理 总结

    Excel 转LaTex表格 与TeX表格的处理 总结   工具使用:一个Latex表格输入神器--Excel2Tex插件的安装过程. 首先下载插件:http://www.ctan.org/tex-a ...

  4. java中volatile关键字的含义

    在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...

  5. rqnoj378 约会计划

    题目描述 cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而,最关键的是,cc能够很好的调解各各妹妹间的关系.mm之间的关系及其复杂,cc必须严格 ...

  6. Navigation Bar options for Android (based on photosomething project)

    1, Tab控件即标签页,可以在一页中切换显示n页内容,要使用此效果,需要用到TabHost和Tabwidget类.(过时了?) Tab控件具有两种实现过程,一是在同一个Activity中切换显示不同 ...

  7. Rails的三种环境----开发环境,生产环境和测试环境

    Rails 的三个环境 Rails 的应用程序预设提供了三种不同的执行模式: development environment 开发模式,用在你的开发的时候 test environment 测试模式, ...

  8. maven项目常见问题

    问题1:Maven项目,右键-update project后报错如下的解决办法: 1).DescriptionResourcePathLocationType Java compiler level ...

  9. PHP header函数使用大全

    PHP header函数大全 header('Content-Type: text/html; charset=utf-8'); header('Location: http://52php.cnbl ...

  10. PHP中类的继承和构造函数的继承

    PHP4.x 版本: PHP 4.x 的构造函数名与类名相同. 子类的构造函数名与子类名相同(废话). 在子类里父类的构造函数不会自动执行. 要在子类里执行父类的构造函数,必须执行类似以下语句: $t ...