1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| VOID ProcessNotify(HANDLE pid, HANDLE pid2, BOOLEAN value) { UNREFERENCED_PARAMETER(pid); if (value) { DbgPrint("Process Created %d\n", pid2); PEPROCESS CurrentProc = NULL; PsLookupProcessByProcessId(pid2, &CurrentProc); if (!CurrentProc) { return; }
pMyProcess PMyProcess = ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(MyProcess),'cpym'); if (PMyProcess) { RtlZeroMemory(PMyProcess, sizeof(MyProcess)); PMyProcess->pid = pid2; PMyProcess->pEprocessObj = CurrentProc; PMyProcess->ProcessName = PsGetProcessImageFileName(CurrentProc); KIRQL irql = 0; KeAcquireSpinLock(&kSpinLock, &irql); InsertTailList(&listhead, &(PMyProcess->list)); KeReleaseSpinLock(&kSpinLock, irql); } PUCHAR processname = PsGetProcessImageFileName(CurrentProc); DbgPrint("Process Name %s\n", processname);
}
return; }
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) {
InitializeListHead(&listhead); PsSetCreateProcessNotifyRoutine(ProcessNotify, FALSE);
return Status; }
VOID DriverUnload(PDRIVER_OBJECT DriverObject) { UNREFERENCED_PARAMETER(DriverObject); DbgPrint("Driver Stopping -> %wZ\n", &DriverObject->DriverName); DbgPrint("Device Stopping\n"); if (DriverObject->DeviceObject) { IoDeleteDevice(DriverObject->DeviceObject);
UNICODE_STRING symname = { 0 }; RtlInitUnicodeString(&symname, SYM_NAME); IoDeleteSymbolicLink(&symname); } PsSetCreateProcessNotifyRoutine(ProcessNotify, TRUE);
PLIST_ENTRY temp = NULL; pMyProcess tempMy = NULL; while (listhead.Blink != &listhead) { temp = RemoveTailList(&listhead); tempMy = CONTAINING_RECORD(temp, MyProcess, list);
DbgPrint("link -- name: %s -- pid: %d -- obj: %p\n", tempMy->ProcessName, tempMy->pid, tempMy->pEprocessObj); ExFreePool(temp); }
}
|