Add a process to the linked-list of process history objects. This function attempts to add a history object regardless of failures. @param ProcessId - The process ID of the process to add. @param CreateInfo - Information about the process being created. */
| 187 | @param CreateInfo - Information about the process being created. |
| 188 | */ |
| 189 | VOID |
| 190 | ImageHistoryFilter::AddProcessToHistory ( |
| 191 | _In_ HANDLE ProcessId, |
| 192 | _In_ PPS_CREATE_NOTIFY_INFO CreateInfo |
| 193 | ) |
| 194 | { |
| 195 | NTSTATUS status; |
| 196 | PPROCESS_HISTORY_ENTRY newProcessHistory; |
| 197 | LARGE_INTEGER systemTime; |
| 198 | LARGE_INTEGER localSystemTime; |
| 199 | BOOLEAN processHistoryLockHeld; |
| 200 | |
| 201 | processHistoryLockHeld = FALSE; |
| 202 | status = STATUS_SUCCESS; |
| 203 | |
| 204 | if (ImageHistoryFilter::destroying) |
| 205 | { |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | newProcessHistory = RCAST<PPROCESS_HISTORY_ENTRY>(ExAllocatePoolWithTag(PagedPool, sizeof(PROCESS_HISTORY_ENTRY), PROCESS_HISTORY_TAG)); |
| 210 | if (newProcessHistory == NULL) |
| 211 | { |
| 212 | DBGPRINT("ImageHistoryFilter!AddProcessToHistory: Failed to allocate space for the process history."); |
| 213 | status = STATUS_NO_MEMORY; |
| 214 | goto Exit; |
| 215 | } |
| 216 | |
| 217 | memset(newProcessHistory, 0, sizeof(PROCESS_HISTORY_ENTRY)); |
| 218 | |
| 219 | // |
| 220 | // Basic fields. |
| 221 | // |
| 222 | newProcessHistory->ProcessId = ProcessId; |
| 223 | newProcessHistory->ParentId = CreateInfo->ParentProcessId; |
| 224 | newProcessHistory->CallerId = PsGetCurrentProcessId(); |
| 225 | newProcessHistory->ProcessTerminated = FALSE; |
| 226 | newProcessHistory->ImageLoadHistorySize = 0; |
| 227 | KeQuerySystemTime(&systemTime); |
| 228 | ExSystemTimeToLocalTime(&systemTime, &localSystemTime); |
| 229 | newProcessHistory->EpochExecutionTime = localSystemTime.QuadPart / TICKSPERSEC - SECS_1601_TO_1970; |
| 230 | // |
| 231 | // Image file name fields. |
| 232 | // |
| 233 | |
| 234 | |
| 235 | // |
| 236 | // Allocate the necessary space. |
| 237 | // |
| 238 | newProcessHistory->ProcessImageFileName = RCAST<PUNICODE_STRING>(ExAllocatePoolWithTag(PagedPool, sizeof(UNICODE_STRING) + CreateInfo->ImageFileName->Length, IMAGE_NAME_TAG)); |
| 239 | if (newProcessHistory->ProcessImageFileName == NULL) |
| 240 | { |
| 241 | DBGPRINT("ImageHistoryFilter!AddProcessToHistory: Failed to allocate space for process ImageFileName."); |
| 242 | goto Exit; |
| 243 | } |
| 244 | |
| 245 | newProcessHistory->ProcessImageFileName->Buffer = RCAST<PWCH>(RCAST<ULONG_PTR>(newProcessHistory->ProcessImageFileName) + sizeof(UNICODE_STRING)); |
| 246 | newProcessHistory->ProcessImageFileName->Length = CreateInfo->ImageFileName->Length; |
nothing calls this directly
no test coverage detected