r0遍历系统进程方法总结

方法1: ZwQuerySystemInformation

这个方法网上一搜一大堆,不举例了

方法2:暴力枚举PID枚举进程,代码:

NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObj, PUNICODE_STRING pRegStr)
{

	pDriverObj->DriverUnload = MyUnload;

	DbgPrint("DriverEntry...\n");

	//1.暴力枚举PID,枚举进程
	for (ULONG i = 0; i < 65535; i += 4)
	{
		SearchProcessPID(i);
	}
	return STATUS_SUCCESS;
}
//暴力枚举PID,枚举进程
NTSTATUS SearchProcessPID(ULONG pid)
{
	NTSTATUS status = STATUS_SUCCESS;
	PEPROCESS process = NULL;
	PUCHAR processName;
	status = PsLookupProcessByProcessId((HANDLE)pid, &process);
	processName = ExAllocatePool(NonPagedPool, sizeof(process));
	if (NT_SUCCESS(status))
	{
		processName = PsGetProcessImageFileName(process);
		DbgPrint("PID:%d,processName:%s\n", pid, processName);
	}
	

方法3和方法1原理相同,枚举eprocess结构体的ActiveProcessLinks链表实现,代码如下

//通过EPROCESS枚举进程
NTSTATUS SearchProcessEPROCESS()
{
	PEPROCESS process=NULL,firstProcess=NULL;
	NTSTATUS status = STATUS_SUCCESS;
	PLIST_ENTRY plist;
	process = firstProcess = PsGetCurrentProcess();
	do
	{
		PUCHAR ProcessNmae = NULL;
		ProcessNmae = PsGetProcessImageFileName(process);
		DbgPrint("PID:%d,ProcessName:%s\n", (HANDLE)PsGetProcessId(process), ProcessNmae);
		plist = (PLIST_ENTRY)((ULONG)process + ACTIVE_PROCESS_LINK);
		process = (PEPROCESS)((ULONG)plist->Flink - ACTIVE_PROCESS_LINK);
		if (process == firstProcess)
		{
			break;
		}
	} while (process != NULL);

	return status;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值