Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
Test_ProcessImages.cpp File Reference
#include "gtest/gtest.h"
#include "process_images.h"

Go to the source code of this file.

Functions

 TEST (ProcessImages, ImageIsKnownAfterTheProcessExits)
 TEST (ProcessImages, SystemRootPathsBecomeWin32Paths)
 TEST (ProcessImages, ReusedPidResolvesByEventTime)
 TEST (ProcessImages, SmallClockDifferenceStillMatches)
 TEST (ProcessImages, UnknownProcessIsEmpty)
 TEST (ProcessImages, ResolveNamesProcessesWithoutAnImageFile)
 TEST (ProcessImages, ResolveFallsBackToWindowsForRunningProcesses)

Function Documentation

◆ TEST() [1/7]

TEST ( ProcessImages ,
ImageIsKnownAfterTheProcessExits  )

Definition at line 15 of file Test_ProcessImages.cpp.

15 {
16 RecordProcessStart(900001, R"(\??\C:\Tests\Test_NtWriteVirtualMemoryx64.exe)", At(0));
17 RecordProcessExit(900001);
18 // A hook event from just before the exit, delivered after it
19 EXPECT_EQ(LookupProcessImage(900001, At(0.5)), R"(C:\Tests\Test_NtWriteVirtualMemoryx64.exe)");
20}
void RecordProcessExit(DWORD processId)
Records a process exit (ProcessTerminated). Its entry is forgotten a minute later.
void RecordProcessStart(DWORD processId, const std::string &image, const FILETIME &time)
Records a process start (ProcessCreated).
std::string LookupProcessImage(DWORD processId, const FILETIME &time)
The image of the process that had processId at the given time, from the recorded starts....

References LookupProcessImage(), RecordProcessExit(), and RecordProcessStart().

◆ TEST() [2/7]

TEST ( ProcessImages ,
ResolveFallsBackToWindowsForRunningProcesses  )

Definition at line 53 of file Test_ProcessImages.cpp.

53 {
54 // This process started before anything recorded it
55 std::string image = ResolveProcessImage(GetCurrentProcessId(), At(0));
56 EXPECT_NE(image.find("Test_Service.exe"), std::string::npos) << image;
57}
std::string ResolveProcessImage(DWORD processId, const FILETIME &time)
LookupProcessImage, falling back to asking Windows (QueryFullProcessImageName) for processes the serv...

References ResolveProcessImage().

◆ TEST() [3/7]

TEST ( ProcessImages ,
ResolveNamesProcessesWithoutAnImageFile  )

Definition at line 48 of file Test_ProcessImages.cpp.

48 {
49 // QueryFullProcessImageName fails for these; kernel registry and file activity is charged to System
50 EXPECT_EQ(ResolveProcessImage(4, At(0)), "System");
51}

References ResolveProcessImage().

◆ TEST() [4/7]

TEST ( ProcessImages ,
ReusedPidResolvesByEventTime  )

Definition at line 29 of file Test_ProcessImages.cpp.

29 {
30 RecordProcessStart(900003, R"(C:\old.exe)", At(0));
31 RecordProcessExit(900003);
32 RecordProcessStart(900003, R"(C:\new.exe)", At(10));
33 EXPECT_EQ(LookupProcessImage(900003, At(5)), R"(C:\old.exe)"); // late event from the old process
34 EXPECT_EQ(LookupProcessImage(900003, At(11)), R"(C:\new.exe)");
35}

References LookupProcessImage(), RecordProcessExit(), and RecordProcessStart().

◆ TEST() [5/7]

TEST ( ProcessImages ,
SmallClockDifferenceStillMatches  )

Definition at line 37 of file Test_ProcessImages.cpp.

37 {
38 // The hook's timestamp can read slightly earlier than the kernel's creation time
39 RecordProcessStart(900004, R"(C:\a.exe)", At(5));
40 EXPECT_EQ(LookupProcessImage(900004, At(4.5)), R"(C:\a.exe)");
41 EXPECT_EQ(LookupProcessImage(900004, At(2)), "");
42}

References LookupProcessImage(), and RecordProcessStart().

◆ TEST() [6/7]

TEST ( ProcessImages ,
SystemRootPathsBecomeWin32Paths  )

Definition at line 22 of file Test_ProcessImages.cpp.

22 {
23 RecordProcessStart(900002, R"(\SystemRoot\System32\Conhost.exe)", At(0));
24 char windows[MAX_PATH];
25 UINT length = GetWindowsDirectoryA(windows, MAX_PATH);
26 EXPECT_EQ(LookupProcessImage(900002, At(1)), std::string(windows, length) + R"(\System32\Conhost.exe)");
27}
#define MAX_PATH
Definition callbacks.h:7

References LookupProcessImage(), MAX_PATH, and RecordProcessStart().

◆ TEST() [7/7]

TEST ( ProcessImages ,
UnknownProcessIsEmpty  )

Definition at line 44 of file Test_ProcessImages.cpp.

44 {
45 EXPECT_EQ(LookupProcessImage(900005, At(0)), "");
46}

References LookupProcessImage().