1. kd> dt _driver_object
  2. ntdll!_DRIVER_OBJECT
  3. +0x000 Type : Int2B
  4. +0x002 Size : Int2B
  5. +0x004 DeviceObject : Ptr32 _DEVICE_OBJECT
  6. +0x008 Flags : Uint4B
  7. +0x00c DriverStart : Ptr32 Void
  8. +0x010 DriverSize : Uint4B
  9. +0x014 DriverSection : Ptr32 Void
  10. +0x018 DriverExtension : Ptr32 _DRIVER_EXTENSION
  11. +0x01c DriverName : _UNICODE_STRING
  12. +0x024 HardwareDatabase : Ptr32 _UNICODE_STRING
  13. +0x028 FastIoDispatch : Ptr32 _FAST_IO_DISPATCH
  14. +0x02c DriverInit : Ptr32 long
  15. +0x030 DriverStartIo : Ptr32 void
  16. +0x034 DriverUnload : Ptr32 void
  17. +0x038 MajorFunction : [28] Ptr32 long
  18. +0x014 DriverSection : Ptr32 Void
  19. 类似3peb

list module

  1. #include <ntifs.h>
  2. //0x78 bytes (sizeof)
  3. typedef struct _KLDR_DATA_TABLE_ENTRY32 {
  4. LIST_ENTRY32 InLoadOrderLinks;
  5. ULONG __Undefined1;
  6. ULONG __Undefined2;
  7. ULONG __Undefined3;
  8. ULONG NonPagedDebugInfo;
  9. ULONG DllBase;
  10. ULONG EntryPoint;
  11. ULONG SizeOfImage;
  12. UNICODE_STRING32 FullDllName;
  13. UNICODE_STRING32 BaseDllName;
  14. ULONG Flags;
  15. USHORT LoadCount;
  16. USHORT __Undefined5;
  17. ULONG __Undefined6;
  18. ULONG CheckSum;
  19. ULONG TimeDateStamp;
  20. //
  21. // NOTE : Do not grow this structure at the dump files used a packed
  22. // array of these structures.
  23. //
  24. } KLDR_DATA_TABLE_ENTRY32, * PKLDR_DATA_TABLE_ENTRY32;
  25. VOID Unload(PDRIVER_OBJECT DriverObject) {
  26. KdPrint(("driver unloaded\r\n"));
  27. }
  28. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegisteryPath) {
  29. NTSTATUS status;
  30. DriverObject->DriverUnload = Unload;
  31. DbgBreakPoint();
  32. PKLDR_DATA_TABLE_ENTRY32 ldr = (PKLDR_DATA_TABLE_ENTRY32)DriverObject->DriverSection;
  33. PKLDR_DATA_TABLE_ENTRY32 pre = (PKLDR_DATA_TABLE_ENTRY32)ldr->InLoadOrderLinks.Flink;
  34. PKLDR_DATA_TABLE_ENTRY32 next = (PKLDR_DATA_TABLE_ENTRY32)pre->InLoadOrderLinks.Flink;
  35. int count = 0;
  36. while(next!=pre)
  37. {
  38. DbgPrintEx(77, 0, "[db]:%d driver name = %wZ\r\n", count++, &next->FullDllName);
  39. next = (PKLDR_DATA_TABLE_ENTRY32)next->InLoadOrderLinks.Flink;
  40. }
  41. DbgBreakPoint();
  42. return STATUS_SUCCESS;
  43. }

hide

  1. #include <ntifs.h>
  2. //0x78 bytes (sizeof)
  3. typedef struct _KLDR_DATA_TABLE_ENTRY {
  4. LIST_ENTRY InLoadOrderLinks;
  5. ULONG __Undefined1;
  6. ULONG __Undefined2;
  7. ULONG __Undefined3;
  8. ULONG NonPagedDebugInfo;
  9. ULONG DllBase;
  10. ULONG EntryPoint;
  11. ULONG SizeOfImage;
  12. UNICODE_STRING FullDllName;
  13. UNICODE_STRING BaseDllName;
  14. ULONG Flags;
  15. USHORT LoadCount;
  16. USHORT __Undefined5;
  17. ULONG __Undefined6;
  18. ULONG CheckSum;
  19. ULONG TimeDateStamp;
  20. //
  21. // NOTE : Do not grow this structure at the dump files used a packed
  22. // array of these structures.
  23. //
  24. } KLDR_DATA_TABLE_ENTRY, * PKLDR_DATA_TABLE_ENTRY;
  25. NTKERNELAPI
  26. NTSTATUS
  27. ObReferenceObjectByName(
  28. __in PUNICODE_STRING ObjectName,
  29. __in ULONG Attributes,
  30. __in_opt PACCESS_STATE AccessState,
  31. __in_opt ACCESS_MASK DesiredAccess,
  32. __in POBJECT_TYPE ObjectType,
  33. __in KPROCESSOR_MODE AccessMode,
  34. __inout_opt PVOID ParseContext,
  35. __out PVOID* Object
  36. );
  37. VOID Unload(PDRIVER_OBJECT DriverObject) {
  38. KdPrint(("driver unloaded\r\n"));
  39. }
  40. extern POBJECT_TYPE * IoDriverObjectType;
  41. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegisteryPath) {
  42. NTSTATUS status;
  43. DriverObject->DriverUnload = Unload;
  44. DbgBreakPoint();
  45. PKLDR_DATA_TABLE_ENTRY ldr = (PKLDR_DATA_TABLE_ENTRY)DriverObject->DriverSection;
  46. PKLDR_DATA_TABLE_ENTRY pre = (PKLDR_DATA_TABLE_ENTRY)ldr->InLoadOrderLinks.Flink;
  47. PKLDR_DATA_TABLE_ENTRY next = (PKLDR_DATA_TABLE_ENTRY)pre->InLoadOrderLinks.Flink;
  48. int count = 0;
  49. UNICODE_STRING driverName1 = RTL_CONSTANT_STRING(L"helloDriver.sys");
  50. UNICODE_STRING driverName = RTL_CONSTANT_STRING(L"\\driver\\helloDriver.sys");
  51. while(next!=pre)
  52. {
  53. DbgPrintEx(77, 0, "[db]:%d driver name = %wZ\r\n", count++, &next->FullDllName);
  54. if (RtlEqualUnicodeString(&next->BaseDllName,&driverName,TRUE))
  55. {
  56. DbgPrintEx(77, 0, "driver remove %wZ\r\n", &next->FullDllName);
  57. PDRIVER_OBJECT pDriver = NULL;
  58. status = ObReferenceObjectByName(&driverName1, FILE_ALL_ACCESS, 0, 0, *IoDriverObjectType, KernelMode, NULL, &pDriver);
  59. pDriver->DriverSection = ldr->InLoadOrderLinks.Flink;
  60. RemoveEntryList(&next->InLoadOrderLinks);
  61. if (NT_SUCCESS(status))
  62. {
  63. pDriver->DriverInit = NULL;
  64. pDriver->Type = 0;
  65. }
  66. ObDereferenceObject(pDriver);
  67. break;
  68. }
  69. next = (PKLDR_DATA_TABLE_ENTRY)next->InLoadOrderLinks.Flink;
  70. }
  71. DbgBreakPoint();
  72. return STATUS_SUCCESS;
  73. }