MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / OnProcessNotify

Function OnProcessNotify

KernelLibrary/SysMon.cpp:41–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41void OnProcessNotify(_Inout_ PEPROCESS Process, _In_ HANDLE ProcessId, _Inout_opt_ PPS_CREATE_NOTIFY_INFO CreateInfo) {
42 //UNREFERENCED_PARAMETER(Process);
43
44 if (CreateInfo) {
45 // process create
46 USHORT allocSize = sizeof(FullItem<ProcessCreateInfo>);
47 USHORT commandLineSize = 0;
48 if (CreateInfo->CommandLine) {
49 commandLineSize = CreateInfo->CommandLine->Length;
50 allocSize += commandLineSize;
51 }
52 auto info = (FullItem<ProcessCreateInfo>*)ExAllocatePoolWithTag(PagedPool, allocSize, SYSMON_TAG);
53 if (info == nullptr) {
54 KdPrint((SYSMON_PREFIX "failed allocation\n"));
55 return;
56 }
57
58 auto& item = info->Data;
59 //KeQuerySystemTimePrecise(&item.Time);// Available starting with Windows 8.
60 item.Type = ItemType::ProcessCreate;
61 item.Size = sizeof(ProcessCreateInfo) + commandLineSize;
62 item.ProcessId = HandleToUlong(ProcessId);
63 item.ParentProcessId = HandleToUlong(CreateInfo->ParentProcessId);
64
65 if (commandLineSize > 0) {
66 ::memcpy((UCHAR*)&item + sizeof(item), CreateInfo->CommandLine->Buffer,
67 commandLineSize);
68 item.CommandLineLength = commandLineSize / sizeof(WCHAR);
69 item.CommandLineOffset = sizeof(item);
70 }
71 else {
72 item.CommandLineLength = 0;
73 }
74 PushItem(&info->Entry);
75
76 KdPrint(("[Library] %s [%ld] ��������%wZ\n", GetProcessNameByProcessId(CreateInfo->ParentProcessId),
77 CreateInfo->ParentProcessId, CreateInfo->ImageFileName));
78 PUCHAR name = PsGetProcessImageFileName(Process);
79 if (!_stricmp(reinterpret_cast<const char*>(name), "calc.exe")) {
80 KdPrint(("��ֹ��������������"));
81 CreateInfo->CreationStatus = STATUS_UNSUCCESSFUL;// ����ʧ��
82 }
83 }
84 else {
85 // process exit
86 auto info = (FullItem<ProcessExitInfo>*)ExAllocatePoolWithTag(PagedPool,
87 sizeof(FullItem<ProcessExitInfo>), SYSMON_TAG);
88 if (info == nullptr) {
89 KdPrint((SYSMON_PREFIX "failed allocation\n"));
90 return;
91 }
92
93 auto& item = info->Data;
94 //KeQuerySystemTimePrecise(&item.Time);
95 item.Type = ItemType::ProcessExit;
96 item.ProcessId = HandleToULong(ProcessId);
97 item.Size = sizeof(ProcessExitInfo);
98

Callers

nothing calls this directly

Calls 2

PushItemFunction · 0.85

Tested by

no test coverage detected