阅读:1055回复:3
通用Hook函数方法检测进程的问题
我刚开始学写驱动程序,需要在驱动中获得系统的进程列表,并传回给应用程序。
我现在的做法是HOOK函数ZwQuerySystemInformation,在自己的Hook函数中调用原函数后,遍历所有系统进程并分配空间,将进程信息存入动态链表。但是这样会导致内核崩溃,是什么原因呢?是不是这样会改变堆栈里面的值呢? 正确的做法应该是什么呢? 附部分源代码: typedef struct _procinfo { ULONG ProcessId; UNICODE_STRING ProcessName; struct _procinfo * Next; }PROCINFO,*PPROCINFO; NTSTATUS NewZwQuerySystemInformation( IN ULONG SystemInformationClass, IN OUT PVOID SystemInformation, IN ULONG SystemInformaitonLength, OUT PULONG ReturnLength OPTIONAL) { NTSTATUS NtStatus; PSYSTEM_PROCESSES ProcCur = NULL; PSYSTEM_PROCESSES ProcPre = NULL; PPROCINFO pNewPI = NULL; if(SystemInformationClass == 5) { DbgPrint(\"ZwQuerySystemInformation for Process/Thead\\n\"); } NtStatus = (OldZwQuerySystemInformation)(SystemInformationClass, SystemInformation, SystemInformaitonLength, ReturnLength); if(NT_SUCCESS(NtStatus) && SystemInformationClass == 5) { ProcCur = (PSYSTEM_PROCESSES)SystemInformation; pCurrentPI = pFirstPI; while(ProcCur != NULL) { pCurrentNK = pFirstNK; pNewPI = ExAllocatePool(NonPagedPool,sizeof(PROCINFO)); if(pNewPI != NULL) { if(pFirstPI == NULL) { pFirstPI = pNewPI; pCurrentPI = pNewPI; } else { pCurrentPI->Next = pNewPI; pCurrentPI = pNewPI; } pCurrentPI->ProcessId = ProcCur->ProcessId; RtlCopyUnicodeString(&pCurrentPI->ProcessName, &ProcCur->ProcessName); pCurrentPI->Next = NULL; NumProcInfo++; } ProcPre = ProcCur; if(ProcCur->NextEntryDelta != 0) { ProcCur = (PSYSTEM_PROCESSES)((PTSTR)ProcCur + ProcCur->NextEntryDelta); } else { ProcCur = NULL; } } } return NtStatus; } |
|
沙发#
发布于:2005-05-16 09:18
我现在已经变得很Lazy,传上来你的工程,调好还给你
|
|
|
板凳#
发布于:2005-05-17 10:19
我现在已经变得很Lazy,传上来你的工程,调好还给你 那麻烦把ms的os代码调好发我一份 :D |
|
|
地板#
发布于:2005-05-17 16:22
[quote]我现在已经变得很Lazy,传上来你的工程,调好还给你 那麻烦把ms的os代码调好发我一份 :D [/quote] 这好办,不过事先声明,偶只会调longhorn的,不会nt4 win2k的 :D |
|
|