本来想通过链表枚举的,但是想想还是慢慢来,所以就只用这个函数。貌似任务管理器就是通过这个函数枚举进程的,俺心血来潮,也写了一个.不过用DeBugView却没有任何输出,调式了半天也木结果,挺郁闷滴,达达们帮忙看看.
.386
.model flat, stdcall
option casemap:none
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include w2k\ntdll.inc
include w2k\ntddk.inc
includelib ntdll.lib
include Strings.mac
include common.inc
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.data
ProcessCount dd 0
.data?
processinfo db 10000H dup(?)
Pprocessinfo dd ?
ReturnLength dd ?
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.code
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; DriverEntry
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
invoke DbgPrint, $CTA0("\n代码入口\n")
invoke ZwQuerySystemInformation,NT_PROCESSTHREAD_INFO,addr Pprocessinfo,50000H,offset ReturnLength
.if eax == STATUS_SUCCESS
invoke DbgPrint, $CTA0("Get Original Data Success\n")
mov edi,Pprocessinfo;保存到edi
assume edi: ptr SYSTEMPROCESSES;对应结构
.while [edi].NextEntryDelta!=0
invoke DbgPrint, $CTA0("ID=%d ProcessName=%ws\n"),[edi].ProcessId,[edi].ProcessName.Buffer
add edi,[edi].NextEntryDelta;恢复堆栈
inc ProcessCount;这里每循环一次其值就多一次,纪录进程个数
.endw
assume edi:nothing
invoke DbgPrint, $CTA0("\n一共枚举到 %d 个进程\n"),ProcessCount
.elseif
invoke DbgPrint, $CTA0("\nZwQuerySystemInformation函数调用失败\n")
.endif
invoke DbgPrint, $CTA0("\n执行完毕退出\n")
mov eax, STATUS_DEVICE_CONFIGURATION_ERROR
ret
DriverEntry endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end DriverEntry
common.inc:
NT_PROCESSTHREAD_INFO equ 5
STATUS_SUCCESS equ 0
SYSTEMTHREADS STRUCT
KernelTime db 8 dup(?)
UserTime db 8 dup(?)
CreateTime db 8 dup(?)
WaitTime ULONG ?
StartAddress PVOID ?
ClientIs DWORD ?
Priority DWORD ?
BasePriority DWORD ?
ContextSwitchCount ULONG ?
ThreadState ULONG ?
WaitReason DWORD ?
SYSTEMTHREADS ENDS
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SYSTEMPROCESSES struct
NextEntryDelta ULONG ?
ThreadCount ULONG ?
Reserved1 dd 6 DUP(?)
CreateTime db 8 dup(?)
UserTime db 8 dup(?)
KernelTime db 8 dup(?)
ProcessName UNICODE_STRING <>
BasePriority DWORD ? ;变量类型KPRIORITY
ProcessId ULONG ?
InheritedFromProcessId ULONG ?
HandleCount ULONG ?
Reserved2 ULONG 2 DUP(?)
VmCounters DWORD ? ;VM_COUNTERS
IoCounters DWORD ? ;IO_COUNTERS
Threads SYSTEMTHREADS <>
SYSTEMPROCESSES ends
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
UNICODE_STRING STRUCT
_Length WORD ? ; len of string in bytes (not dbs)
MaximumLength WORD ? ; len of Buffer in bytes (not dbs)
Buffer PWSTR ? ; pointer to string
UNICODE_STRING ENDS
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!