ZwQuerySystemInformation 查看系统进程信息

ZwQuerySystemInformation 查看系统进程信息



  1. #include <ntddk.h>
  2. typedef enum _SYSTEM_INFORMATION_CLASS {
  3. SystemBasicInformation,
  4. SystemProcessorInformation,
  5. SystemPerformanceInformation,
  6. SystemTimeOfDayInformation,
  7. SystemPathInformation,
  8. SystemProcessInformation, //5
  9. SystemCallCountInformation,
  10. SystemDeviceInformation,
  11. SystemProcessorPerformanceInformation,
  12. SystemFlagsInformation,
  13. SystemCallTimeInformation,
  14. SystemModuleInformation,
  15. SystemLocksInformation,
  16. SystemStackTraceInformation,
  17. SystemPagedPoolInformation,
  18. SystemNonPagedPoolInformation,
  19. SystemHandleInformation,
  20. SystemObjectInformation,
  21. SystemPageFileInformation,
  22. SystemVdmInstemulInformation,
  23. SystemVdmBopInformation,
  24. SystemFileCacheInformation,
  25. SystemPoolTagInformation,
  26. SystemInterruptInformation,
  27. SystemDpcBehaviorInformation,
  28. SystemFullMemoryInformation,
  29. SystemLoadGdiDriverInformation,
  30. SystemUnloadGdiDriverInformation,
  31. SystemTimeAdjustmentInformation,
  32. SystemSummaryMemoryInformation,
  33. SystemNextEventIdInformation,
  34. SystemEventIdsInformation,
  35. SystemCrashDumpInformation,
  36. SystemExceptionInformation,
  37. SystemCrashDumpStateInformation,
  38. SystemKernelDebuggerInformation,
  39. SystemContextSwitchInformation,
  40. SystemRegistryQuotaInformation,
  41. SystemExtendServiceTableInformation,
  42. SystemPrioritySeperation,
  43. SystemPlugPlayBusInformation,
  44. SystemDockInformation,
  45. SystemPowerInformation2,
  46. SystemProcessorSpeedInformation,
  47. SystemCurrentTimeZoneInformation,
  48. SystemLookasideInformation
  49. } SYSTEM_INFORMATION_CLASS, *PSYSTEM_INFORMATION_CLASS;
  50. typedef struct _SYSTEM_THREAD_INFORMATION {
  51. LARGE_INTEGER KernelTime;
  52. LARGE_INTEGER UserTime;
  53. LARGE_INTEGER CreateTime;
  54. ULONG WaitTime;
  55. PVOID StartAddress;
  56. CLIENT_ID ClientId;
  57. KPRIORITY Priority;
  58. LONG BasePriority;
  59. ULONG ContextSwitchCount;
  60. ULONG State;
  61. KWAIT_REASON WaitReason;
  62. }SYSTEM_THREAD_INFORMATION, *PSYSTEM_THREAD_INFORMATION;
  63. typedef struct _SYSTEM_PROCESS_INFORMATION {
  64. ULONG NextEntryOffset;
  65. ULONG NumberOfThreads;
  66. LARGE_INTEGER Reserved[3];
  67. LARGE_INTEGER CreateTime;
  68. LARGE_INTEGER UserTime;
  69. LARGE_INTEGER KernelTime;
  70. UNICODE_STRING ImageName;
  71. KPRIORITY BasePriority;
  72. HANDLE ProcessId;
  73. HANDLE InheritedFromProcessId;
  74. ULONG HandleCount;
  75. ULONG Reserved2[2];
  76. ULONG PrivatePageCount;
  77. VM_COUNTERS VirtualMemoryCounters;
  78. IO_COUNTERS IoCounters;
  79. SYSTEM_THREAD_INFORMATION Threads[0];
  80. } SYSTEM_PROCESS_INFORMATION, *PSYSTEM_PROCESS_INFORMATION;
  81. //不加extern "C" 一直报link错误
  82. extern "C" NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(
  83. IN ULONG SystemInformationClass,
  84. IN PVOID SystemInformation,
  85. IN ULONG SystemInformationLength,
  86. OUT PULONG ReturnLength);
  87. VOID Unload(
  88. __in struct _DRIVER_OBJECT *DriverObject
  89. )
  90. {
  91. KdPrint(("unload ....."));
  92. }
  93. NTSTATUS Ring0EnumProcess()
  94. {
  95. ULONG cbBuffer = 0x8000; //32k
  96. PVOID pSystemInfo;
  97. NTSTATUS status;
  98. PSYSTEM_PROCESS_INFORMATION pInfo;
  99. //为查找进程分配足够的空间
  100. do
  101. {
  102. pSystemInfo = ExAllocatePool(NonPagedPool, cbBuffer);
  103. if (pSystemInfo == NULL) //申请空间失败,返回
  104. {
  105. return 1;
  106. }
  107. status = ZwQuerySystemInformation(SystemProcessInformation, pSystemInfo, cbBuffer, NULL );
  108. if (status == STATUS_INFO_LENGTH_MISMATCH) //空间不足
  109. {
  110. ExFreePool(pSystemInfo);
  111. cbBuffer *= 2;
  112. }
  113. else if(!NT_SUCCESS(status))
  114. {
  115. ExFreePool(pSystemInfo);
  116. return 1;
  117. }
  118. } while(status == STATUS_INFO_LENGTH_MISMATCH); //如果是空间不足,就一直循环
  119. pInfo = (PSYSTEM_PROCESS_INFORMATION)pSystemInfo; //把得到的信息放到pInfo中
  120. for (;;)
  121. {
  122. LPWSTR pszProcessName = pInfo->ImageName.Buffer;
  123. if (pszProcessName == NULL)
  124. {
  125. pszProcessName = L"NULL";
  126. }
  127. KdPrint(("PID:%d, process name:%S\n", pInfo->ProcessId, pszProcessName));
  128. if (pInfo->NextEntryOffset == 0) //==0,说明到达进程链的尾部了
  129. {
  130. break;
  131. }
  132. pInfo = (PSYSTEM_PROCESS_INFORMATION)(((PUCHAR)pInfo) + pInfo->NextEntryOffset); //遍历
  133. }
  134. return STATUS_SUCCESS;
  135. }
  136. NTSTATUS DriverEntry(
  137. __in PDRIVER_OBJECT DriverObject,
  138. __in PUNICODE_STRING RegistryPath
  139. )
  140. {
  141. DriverObject->DriverUnload = Unload;
  142. Ring0EnumProcess();
  143. return STATUS_SUCCESS;
  144. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值