9#include <nlohmann/json.hpp>
13#include <condition_variable>
18#include <unordered_map>
24#define PANO_PENDING_EVENT_REQUESTS 4
30#define PANO_WRITE_SETTLE_MS 2000
31#define PANO_WRITE_MAX_WINDOW_MS 30000
32#define PANO_WRITE_POLL_MS 500
40static HANDLE g_Device = INVALID_HANDLE_VALUE;
41static HANDLE g_CompletionPort = NULL;
43static std::thread g_ReaderThread;
44static std::thread g_ScanThread;
45static std::atomic<bool> g_Stopping =
false;
60static std::mutex g_WrittenFilesLock;
61static std::unordered_map<std::string, PANO_WRITTEN_FILE> g_WrittenFiles;
65static std::mutex g_PendingScansLock;
66static std::vector<std::string> g_PendingScans;
73#define PANO_MAX_ECHO_BUFFER (4 * 1024 * 1024)
74static std::mutex g_EchoLock;
75static std::condition_variable g_EchoReady;
76static std::string g_EchoBuffer;
77static UINT64 g_EchoSkipped = 0;
78static bool g_EchoStopping =
false;
79static std::thread g_EchoThread;
83static std::vector<std::pair<std::wstring, std::wstring>> g_DeviceMap;
87static std::vector<std::string> g_LogExclusions;
89static bool IsLogExcluded(
const std::string &path)
94#pragma region Path Conversion
96static void BuildDeviceMap()
99 WCHAR drive[] = L
"A:";
101 for (WCHAR letter = L
'A'; letter <= L
'Z'; letter++)
104 if (QueryDosDeviceW(drive, target,
MAX_PATH) != 0)
106 g_DeviceMap.emplace_back(target, drive);
113static std::wstring ToDosPath(
const std::wstring &ntPath)
115 for (
const auto &[device, drive] : g_DeviceMap)
117 if (ntPath.size() > device.size() &&
118 ntPath[device.size()] == L
'\\' &&
119 _wcsnicmp(ntPath.c_str(), device.c_str(), device.size()) == 0)
121 return drive + ntPath.substr(device.size());
125 const std::wstring mupPrefix = L
"\\Device\\Mup\\";
126 if (_wcsnicmp(ntPath.c_str(), mupPrefix.c_str(), mupPrefix.size()) == 0)
128 return L
"\\\\" + ntPath.substr(mupPrefix.size());
137static std::wstring ToPipeOrMailslotPath(
const std::wstring &ntPath)
139 static const std::pair<std::wstring, std::wstring> prefixes[] = {
140 {L
"\\Device\\NamedPipe\\", L
"\\\\.\\pipe\\"},
141 {L
"\\Device\\Mailslot\\", L
"\\\\.\\mailslot\\"},
143 for (
const auto &[device, display] : prefixes)
145 if (_wcsnicmp(ntPath.c_str(), device.c_str(), device.size()) == 0)
147 return display + ntPath.substr(device.size());
155#pragma region Event Handling
157static const char *EventTypeName(UINT32 type)
162 return "FileCreated";
166 return "FileOverwritten";
168 return "FileSuperseded";
172 return "NamedPipeCreate";
174 return "NamedPipeOpen";
176 return "MailslotCreate";
178 return "MailslotOpen";
180 return "FileDeleted";
182 return "FileRenamed";
184 return "ProcessCreated";
186 return "ProcessTerminated";
188 return "FileModified";
190 return "FileSecurityChanged";
192 return "FileExtendedAttributesChanged";
194 return "RegistrySetValue";
196 return "RegistrySaveKey";
198 return "RegistrySetKeySecurity";
200 return "RegistryDeleteKey";
202 return "RegistryCreateKey";
204 return "RegistryLoadKey";
206 return "RegistryReplaceKey";
208 return "RegistryRenameKey";
210 return "RegistryQueryValue";
216static FILETIME ToFileTime(INT64 timestamp)
219 fileTime.dwLowDateTime = (DWORD)(timestamp & 0xFFFFFFFF);
220 fileTime.dwHighDateTime = (DWORD)(timestamp >> 32);
227static void LogEvent(nlohmann::ordered_json &event,
const FILETIME &time)
229 [[maybe_unused]] std::string line =
RecordEvent(event, time);
233 std::lock_guard<std::mutex> lock(g_EchoLock);
234 if (g_EchoBuffer.size() + line.size() <= PANO_MAX_ECHO_BUFFER)
236 g_EchoBuffer += line;
243 g_EchoReady.notify_one();
248static void ConsoleEchoThread()
254 bool stopping =
false;
256 std::unique_lock<std::mutex> lock(g_EchoLock);
257 g_EchoReady.wait(lock, [] {
return !g_EchoBuffer.empty() || g_EchoStopping; });
258 batch.swap(g_EchoBuffer);
259 skipped = g_EchoSkipped;
261 stopping = g_EchoStopping;
266 std::cout.write(batch.data(), batch.size());
271 std::cout <<
"[console echo fell behind: " << skipped <<
" events not shown here; they are in the log file]\n";
285static bool IsPortableExecutable(
const std::string &path)
287 HANDLE file = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
288 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
289 if (file == INVALID_HANDLE_VALUE)
295 IMAGE_DOS_HEADER dosHeader;
297 if (ReadFile(file, &dosHeader,
sizeof(dosHeader), &bytesRead, NULL) &&
298 bytesRead ==
sizeof(dosHeader) &&
299 dosHeader.e_magic == IMAGE_DOS_SIGNATURE &&
300 dosHeader.e_lfanew > 0)
303 LARGE_INTEGER offset;
304 offset.QuadPart = dosHeader.e_lfanew;
305 if (SetFilePointerEx(file, offset, NULL, FILE_BEGIN) &&
306 ReadFile(file, &signature,
sizeof(signature), &bytesRead, NULL) &&
307 bytesRead ==
sizeof(signature))
309 isPe = (signature == IMAGE_NT_SIGNATURE);
319static bool IsScanCandidate(
const std::string &path)
321 DWORD attributes = GetFileAttributesA(path.c_str());
322 if (attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY))
326 return IsPortableExecutable(path);
330static void QueueFileScan(
const std::string &path)
332 if (IsScanCandidate(path))
339static void RequestFileScan(
const std::string &path)
341 std::lock_guard<std::mutex> lock(g_PendingScansLock);
342 g_PendingScans.push_back(path);
347static nlohmann::json SecurityInformationNames(UINT32 securityInformation)
349 static const std::pair<UINT32, const char *> names[] = {
350 {OWNER_SECURITY_INFORMATION,
"Owner"},
351 {GROUP_SECURITY_INFORMATION,
"Group"},
352 {DACL_SECURITY_INFORMATION,
"Dacl"},
353 {SACL_SECURITY_INFORMATION,
"Sacl"},
354 {LABEL_SECURITY_INFORMATION,
"Label"},
355 {ATTRIBUTE_SECURITY_INFORMATION,
"Attribute"},
356 {SCOPE_SECURITY_INFORMATION,
"Scope"},
357 {PROCESS_TRUST_LABEL_SECURITY_INFORMATION,
"ProcessTrustLabel"},
358 {BACKUP_SECURITY_INFORMATION,
"Backup"},
359 {PROTECTED_DACL_SECURITY_INFORMATION,
"ProtectedDacl"},
360 {PROTECTED_SACL_SECURITY_INFORMATION,
"ProtectedSacl"},
361 {UNPROTECTED_DACL_SECURITY_INFORMATION,
"UnprotectedDacl"},
362 {UNPROTECTED_SACL_SECURITY_INFORMATION,
"UnprotectedSacl"},
365 nlohmann::json result = nlohmann::json::array();
366 UINT32 remaining = securityInformation;
367 for (
const auto &[bit, name] : names)
369 if (securityInformation & bit)
371 result.push_back(name);
378 sprintf_s(hex,
"0x%X", remaining);
379 result.push_back(hex);
389 if (data->
ProcessId == GetCurrentProcessId())
395 std::wstring dosPath = ToDosPath(ntPath);
396 std::string path =
ToString(dosPath.empty() ? ToPipeOrMailslotPath(ntPath) : dosPath);
400 FILETIME reportTime = ToFileTime(header->
Timestamp);
403 nlohmann::ordered_json event;
404 event[
"Event"] = EventTypeName(header->
Type);
407 event[
"Path"] = path;
408 event[
"Writes"] = data->
Writes;
409 event[
"Bytes"] = data->
Bytes;
414 event[
"StillOpen"] =
true;
418 event[
"NameTruncated"] =
true;
420 if (!IsLogExcluded(path))
422 LogEvent(event, reportTime);
426 if (!stillOpen && !dosPath.empty())
428 RequestFileScan(path);
435 if (data->
ProcessId == GetCurrentProcessId())
447 std::wstring dosPath = ToDosPath(ntPath);
448 std::string path =
ToString(dosPath.empty() ? ToPipeOrMailslotPath(ntPath) : dosPath);
450 FILETIME timestamp = ToFileTime(header->
Timestamp);
460 ULONGLONG now = GetTickCount64();
461 std::lock_guard<std::mutex> lock(g_WrittenFilesLock);
462 auto [it, inserted] = g_WrittenFiles.try_emplace(path);
480 nlohmann::ordered_json event;
481 event[
"Event"] = EventTypeName(header->
Type);
485 event[
"Path"] = path;
489 event[
"Oplocked"] =
true;
493 event[
"NameTruncated"] =
true;
497 event[
"DeleteOnClose"] =
true;
502 event[
"Changed"] = SecurityInformationNames(data->
Length);
506 event[
"Bytes"] = data->
Length;
508 if (!IsLogExcluded(path))
510 LogEvent(event, timestamp);
515 switch (header->
Type)
520 if (!dosPath.empty())
522 RequestFileScan(path);
530 if (data->
ProcessId == GetCurrentProcessId())
537 std::wstring dosSource = ToDosPath(ntSource);
538 std::wstring dosDestination = ToDosPath(ntDestination);
539 std::string source =
ToString(dosSource.empty() ? ntSource : dosSource);
540 std::string destination =
ToString(dosDestination.empty() ? ntDestination : dosDestination);
542 nlohmann::ordered_json event;
543 event[
"Event"] = EventTypeName(header->
Type);
547 event[
"Path"] = source;
548 event[
"NewPath"] = destination;
552 event[
"ReplaceExisting"] =
true;
556 event[
"NameTruncated"] =
true;
561 if (!(IsLogExcluded(source) && IsLogExcluded(destination)))
563 LogEvent(event, ToFileTime(header->
Timestamp));
566 if (dosDestination.empty())
573 bool hasPendingWrites =
false;
575 std::lock_guard<std::mutex> lock(g_WrittenFilesLock);
576 auto pending = g_WrittenFiles.find(source);
577 if (pending != g_WrittenFiles.end())
580 g_WrittenFiles.erase(pending);
583 auto [it, inserted] = g_WrittenFiles.try_emplace(destination, file);
601 hasPendingWrites =
true;
606 if (!hasPendingWrites)
608 RequestFileScan(destination);
614static std::wstring ToRegistryDisplayPath(
const std::wstring &kernelPath)
616 static const std::pair<std::wstring, std::wstring> roots[] = {
617 {L
"\\REGISTRY\\MACHINE", L
"HKLM"},
618 {L
"\\REGISTRY\\USER", L
"HKU"},
620 for (
const auto &[root, display] : roots)
622 if (_wcsnicmp(kernelPath.c_str(), root.c_str(), root.size()) == 0 &&
623 (kernelPath.size() == root.size() || kernelPath[root.size()] == L
'\\'))
625 return display + kernelPath.substr(root.size());
633static std::string ToRegistryFilePath(
const std::wstring &path)
635 static const std::wstring dosDevicePrefixes[] = {L
"\\??\\", L
"\\DosDevices\\"};
636 for (
const auto &prefix : dosDevicePrefixes)
638 if (_wcsnicmp(path.c_str(), prefix.c_str(), prefix.size()) == 0)
640 return ToString(path.substr(prefix.size()));
644 std::wstring dosPath = ToDosPath(path);
645 return ToString(dosPath.empty() ? path : dosPath);
648static const char *RegistryValueTypeName(UINT32 type)
657 return "REG_EXPAND_SZ";
662 case REG_DWORD_BIG_ENDIAN:
663 return "REG_DWORD_BIG_ENDIAN";
667 return "REG_MULTI_SZ";
677static std::string RegistryValueHex(
const BYTE *data, UINT32 length)
679 static const char digits[] =
"0123456789ABCDEF";
681 hex.reserve(length * 2);
682 for (UINT32 i = 0; i < length; i++)
684 hex += digits[data[i] >> 4];
685 hex += digits[data[i] & 0xF];
692static nlohmann::json RegistryValueData(UINT32 type,
const BYTE *data, UINT32 length)
694 auto readString = [](
const BYTE *bytes, UINT32 byteLength) {
695 std::wstring text(byteLength /
sizeof(WCHAR), L
'\0');
696 memcpy(text.data(), bytes, text.size() *
sizeof(WCHAR));
706 std::wstring text = readString(data, length);
707 text.erase(std::find(text.begin(), text.end(), L
'\0'), text.end());
712 std::wstring text = readString(data, length);
713 nlohmann::json strings = nlohmann::json::array();
715 while (start < text.size())
717 size_t end = text.find(L
'\0', start);
722 if (end == std::wstring::npos)
726 strings.push_back(
ToString(text.substr(start, end - start)));
732 if (length >=
sizeof(UINT32))
735 memcpy(&value, data,
sizeof(value));
740 if (length >=
sizeof(UINT64))
743 memcpy(&value, data,
sizeof(value));
753 if (data->
ProcessId == GetCurrentProcessId())
761 std::string key =
ToString(ToRegistryDisplayPath(keyName));
763 nlohmann::ordered_json event;
764 event[
"Event"] = EventTypeName(header->
Type);
772 switch (header->
Type)
777 event[
"ValueName"] =
ToString(secondName);
778 const char *typeName = RegistryValueTypeName(data->
Detail);
779 if (typeName !=
nullptr)
781 event[
"Type"] = typeName;
785 event[
"Type"] = data->
Detail;
788 nlohmann::json decoded = RegistryValueData(data->
Detail, valueData, data->
DataLength);
789 if (!decoded.is_null())
791 event[
"Data"] = std::move(decoded);
793 event[
"DataHex"] = RegistryValueHex(valueData, data->
DataLength);
796 event[
"DataTruncated"] =
true;
801 event[
"Path"] = ToRegistryFilePath(secondName);
802 event[
"Format"] = data->
Detail;
805 event[
"Changed"] = SecurityInformationNames(data->
Detail);
808 event[
"Path"] = ToRegistryFilePath(secondName);
809 event[
"LoadFlags"] = data->
Detail;
814 std::wstring oldFile(data->
DataLength /
sizeof(WCHAR), L
'\0');
815 memcpy(oldFile.data(), valueData, oldFile.size() *
sizeof(WCHAR));
816 event[
"Path"] = ToRegistryFilePath(secondName);
817 event[
"OldPath"] = ToRegistryFilePath(oldFile);
820 event[
"OldPathTruncated"] =
true;
825 event[
"NewKey"] =
ToString(ToRegistryDisplayPath(secondName));
828 event[
"ValueName"] =
ToString(secondName);
829 event[
"InformationClass"] = data->
Detail;
836 event[
"KernelMode"] =
true;
840 event[
"NameTruncated"] =
true;
844 event[
"Incomplete"] =
true;
849 bool excluded = IsLogExcluded(key);
852 excluded = IsLogExcluded(event[
"NewKey"].get<std::string>());
856 LogEvent(event, ToFileTime(header->
Timestamp));
862 nlohmann::ordered_json event;
863 event[
"Event"] = EventTypeName(header->
Type);
870 std::wstring dosPath = ToDosPath(ntPath);
876 event[
"Image"] =
ToString(dosPath.empty() ? ntPath : dosPath);
877 event[
"CommandLine"] =
ToString(commandLine);
880 event[
"NameTruncated"] =
true;
884 event[
"CommandLineTruncated"] =
true;
896 LogEvent(event, ToFileTime(header->
Timestamp));
899static void HandleEvent(
const BYTE *buffer, DWORD bytes)
918 nlohmann::ordered_json event;
919 event[
"Event"] =
"EventsDropped";
920 event[
"Reason"] =
"NoService";
926 nlohmann::ordered_json event;
927 event[
"Event"] =
"EventsDropped";
928 event[
"Reason"] =
"QueueFull";
929 event[
"Count"] = header->
Dropped;
933 if (EventTypeName(header->
Type) ==
nullptr)
955 HandleRenameEvent(header, rename);
973 HandleProcessEvent(header, process);
992 HandleRegistryEvent(header, registry);
1009 HandleFileModifiedEvent(header, modified);
1025 HandleFileEvent(header, data);
1030#pragma region Threads
1034 ZeroMemory(&request->
Overlapped,
sizeof(OVERLAPPED));
1035 BOOL ok = DeviceIoControl(
1046 return ok || GetLastError() == ERROR_IO_PENDING;
1049static void EventReaderThread()
1051 int outstanding = 0;
1052 for (
auto &request : g_Requests)
1054 if (IssueEventRequest(&request))
1060 while (outstanding > 0)
1064 LPOVERLAPPED overlapped = NULL;
1065 BOOL ok = GetQueuedCompletionStatus(g_CompletionPort, &bytes, &key, &overlapped, INFINITE);
1066 if (overlapped == NULL)
1077 HandleEvent(request->
Buffer, bytes);
1081 DWORD error = GetLastError();
1082 if (error != ERROR_OPERATION_ABORTED)
1084 std::cerr <<
"Driver event request failed. Error code: " << error << std::endl;
1088 if (!g_Stopping && IssueEventRequest(request))
1098static void WrittenFileScanThread()
1104 std::vector<std::string> requested;
1106 std::lock_guard<std::mutex> lock(g_PendingScansLock);
1107 requested.swap(g_PendingScans);
1110 std::sort(requested.begin(), requested.end());
1111 requested.erase(std::unique(requested.begin(), requested.end()), requested.end());
1112 for (
const auto &path : requested)
1114 QueueFileScan(path);
1117 std::vector<std::pair<std::string, PANO_WRITTEN_FILE>> ready;
1118 ULONGLONG now = GetTickCount64();
1120 std::lock_guard<std::mutex> lock(g_WrittenFilesLock);
1121 for (
auto it = g_WrittenFiles.begin(); it != g_WrittenFiles.end();)
1127 ready.emplace_back(it->first, file);
1128 it = g_WrittenFiles.erase(it);
1137 for (
const auto &[path, file] : ready)
1139 nlohmann::ordered_json event;
1140 event[
"Event"] =
"FileModified";
1143 event[
"Path"] = path;
1144 event[
"Writes"] = file.
Writes;
1145 event[
"Bytes"] = file.
Bytes;
1150 if (!IsLogExcluded(path))
1159 QueueFileScan(path);
1173 g_Device = CreateFileW(
1176 FILE_SHARE_READ | FILE_SHARE_WRITE,
1179 FILE_FLAG_OVERLAPPED,
1181 if (g_Device == INVALID_HANDLE_VALUE)
1183 DWORD error = GetLastError();
1184 std::cerr <<
"Failed to open the Panoptes driver device. Error code: " << error << std::endl;
1188 g_CompletionPort = CreateIoCompletionPort(g_Device, NULL, 0, 1);
1189 if (g_CompletionPort == NULL)
1191 CloseHandle(g_Device);
1192 g_Device = INVALID_HANDLE_VALUE;
1198 g_EchoStopping =
false;
1199 g_EchoThread = std::thread(ConsoleEchoThread);
1201 g_ReaderThread = std::thread(EventReaderThread);
1202 g_ScanThread = std::thread(WrittenFileScanThread);
1208 if (g_Device == INVALID_HANDLE_VALUE)
1216 CancelIoEx(g_Device, NULL);
1218 if (g_ReaderThread.joinable())
1220 g_ReaderThread.join();
1222 if (g_ScanThread.joinable())
1224 g_ScanThread.join();
1228 std::lock_guard<std::mutex> lock(g_PendingScansLock);
1229 g_PendingScans.clear();
1235 std::lock_guard<std::mutex> lock(g_EchoLock);
1236 g_EchoStopping =
true;
1238 g_EchoReady.notify_one();
1239 if (g_EchoThread.joinable())
1241 g_EchoThread.join();
1245 CloseHandle(g_CompletionPort);
1246 CloseHandle(g_Device);
1247 g_CompletionPort = NULL;
1248 g_Device = INVALID_HANDLE_VALUE;
static bool IsPathInList(const std::vector< std::string > &patterns, const std::string &path)
Check whether a path matches any pattern in an exclusion list. A pattern with no wildcard matches eve...
std::vector< std::string > m_logExclusions
Path patterns whose driver events are not logged (see IsPathInList). Files matching them are still sc...
std::string RecordEvent(nlohmann::ordered_json &event, const FILETIME &time)
Gives event the next sequence number (appended as "Seq"), writes it to pano.log and queues it for eve...
FILETIME CurrentFileTime()
The current time as a FILETIME, for events that carry no timestamp of their own.
struct _PANO_EVENT_REQUEST PANO_EVENT_REQUEST
#define PANO_WRITE_MAX_WINDOW_MS
#define PANO_PENDING_EVENT_REQUESTS
#define PANO_WRITE_SETTLE_MS
struct _PANO_EVENT_REQUEST * PPANO_EVENT_REQUEST
struct _PANO_WRITTEN_FILE PANO_WRITTEN_FILE
#define PANO_WRITE_POLL_MS
ERRORCODE StartDriverEvents(const Configuration *configuration)
Opens the Panoptes driver device and starts the threads that read events from it (IOCTL_PANOPTES_GET_...
void StopDriverEvents()
Cancels the pending event requests and stops the reader threads.
void SelfQueuePeScan(std::string pePath, std::string fileHash)
#define PANO_FLAG_OPLOCKED
#define PANO_FLAG_HANDLE_STILL_OPEN
PANO_EVENT_FILE_MODIFIED: sent while the handle is still open and writing, so the file may not be com...
#define PANO_FLAG_KERNEL_MODE_CALLER
Registry events: the operation came from kernel mode (a driver or the system) rather than from a user...
#define PANO_FLAG_CAPTURE_FAILED
Registry events: a name or the data could not be read, so the event is incomplete....
struct _PANO_RENAME_EVENT_DATA PANO_RENAME_EVENT_DATA
The data for PANO_EVENT_FILE_RENAME.
struct _PANO_EVENT_HEADER PANO_EVENT_HEADER
The header at the start of every IOCTL_PANOPTES_GET_EVENT response.
@ PANO_EVENT_REGISTRY_SET_KEY_SECURITY
A registry key's security descriptor is about to be changed (a PANO_REGISTRY_EVENT_DATA)....
@ PANO_EVENT_FILE_RENAME
A file was renamed or moved (a PANO_RENAME_EVENT_DATA).
@ PANO_EVENT_MAILSLOT_CREATE
A server created a mailslot (CreateMailslot).
@ PANO_EVENT_NAMED_PIPE_CREATE
A server created a named pipe, or another instance of one (CreateNamedPipe).
@ PANO_EVENT_FILE_MODIFIED
A handle that wrote to a file was closed (a PANO_FILE_MODIFIED_EVENT_DATA). One event covers every wr...
@ PANO_EVENT_MAILSLOT_OPEN
A client opened a mailslot to write to it (CreateFile on \.\mailslot...).
@ PANO_EVENT_REGISTRY_SAVE_KEY
A registry key is about to be saved to a file, e.g. reg save HKLM\SAM (a PANO_REGISTRY_EVENT_DATA)....
@ PANO_EVENT_FILE_SUPERSEDED
@ PANO_EVENT_REGISTRY_REPLACE_KEY
A key's hive file was replaced, taking effect at the next boot, e.g. reg replace (a PANO_REGISTRY_EVE...
@ PANO_EVENT_FILE_EA_CHANGED
A file's extended attributes were written (a PANO_FILE_EVENT_DATA). Length holds the size of the EA b...
@ PANO_EVENT_NAMED_PIPE_OPEN
A client connected to a named pipe (CreateFile on \.\pipe...).
@ PANO_EVENT_REGISTRY_RENAME_KEY
A registry key was renamed (a PANO_REGISTRY_EVENT_DATA). The key name is the old full name and Second...
@ PANO_EVENT_REGISTRY_SET_VALUE
A registry value is about to be written (a PANO_REGISTRY_EVENT_DATA). SecondName is the value name,...
@ PANO_EVENT_FILE_OVERWRITTEN
@ PANO_EVENT_REGISTRY_CREATE_KEY
A new registry key was created (a PANO_REGISTRY_EVENT_DATA with only the key name)....
@ PANO_EVENT_FILE_CREATED
@ PANO_EVENT_FILE_SECURITY_CHANGED
A file's security descriptor was changed (a PANO_FILE_EVENT_DATA). Length holds the SECURITY_INFORMAT...
@ PANO_EVENT_PROCESS_TERMINATED
A process exited (a PANO_PROCESS_EVENT_DATA with only ProcessId set).
@ PANO_EVENT_FILE_OPENED
No longer reported: opens of existing files are too frequent and filled the queue....
@ PANO_EVENT_PROCESS_CREATED
A process was created (a PANO_PROCESS_EVENT_DATA).
@ PANO_EVENT_REGISTRY_LOAD_KEY
A hive file was loaded into the registry, e.g. reg load (a PANO_REGISTRY_EVENT_DATA)....
@ PANO_EVENT_REGISTRY_DELETE_KEY
A registry key is about to be deleted (a PANO_REGISTRY_EVENT_DATA with only the key name)....
@ PANO_EVENT_REGISTRY_QUERY_VALUE
A value was read from a key holding credentials (under HKLM\SAM or HKLM\SECURITY) (a PANO_REGISTRY_EV...
@ PANO_EVENT_FILE_DELETE
A file was marked for deletion (a PANO_FILE_EVENT_DATA). The delete happens when the last handle clos...
struct _PANO_REGISTRY_EVENT_DATA PANO_REGISTRY_EVENT_DATA
The data for PANO_EVENT_REGISTRY_* events.
#define PANO_FLAG_COMMAND_LINE_TRUNCATED
PANO_EVENT_PROCESS_CREATED: the command line was truncated to fit the event.
#define PANO_FLAG_REPLACE_EXISTING
PANO_EVENT_FILE_RENAME: the rename replaced an existing file at the destination.
#define PANO_FLAG_NAME_TRUNCATED
#define PANO_MAX_EVENT_SIZE
The output buffer size the service passes with IOCTL_PANOPTES_GET_EVENT. The driver never returns an ...
#define PANOPTES_USER_DEVICE_PATH
struct _PANO_FILE_EVENT_DATA PANO_FILE_EVENT_DATA
The data for file, named pipe and mailslot events.
struct _PANO_PROCESS_EVENT_DATA PANO_PROCESS_EVENT_DATA
The data for PANO_EVENT_PROCESS_CREATED and PANO_EVENT_PROCESS_TERMINATED.
struct _PANO_FILE_MODIFIED_EVENT_DATA PANO_FILE_MODIFIED_EVENT_DATA
The data for PANO_EVENT_FILE_MODIFIED.
#define PANO_FLAG_DELETE_ON_CLOSE
PANO_EVENT_FILE_DELETE: the file was opened with FILE_DELETE_ON_CLOSE rather than having its delete d...
#define PANO_FLAG_DATA_TRUNCATED
PANO_EVENT_REGISTRY_SET_VALUE / _REPLACE_KEY: Data holds only the first PANO_MAX_REGISTRY_DATA_SIZE b...
#define IOCTL_PANOPTES_GET_EVENT
Waits for and returns the next event from the driver.
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 ResolveProcessImage(DWORD processId, const FILETIME &time)
LookupProcessImage, falling back to asking Windows (QueryFullProcessImageName) for processes the serv...
BYTE Buffer[PANO_MAX_EVENT_SIZE]
UINT32 Length
Length of the write, PANO_EVENT_FILE_WRITE only.
UINT32 NameLength
Length of FileName in WCHARs. FileName is not null terminated.
UINT32 Flags
PANO_FLAG_* values.
UINT64 ProcessId
The process and thread of the most recent write.
UINT32 NameLength
Length of FileName in WCHARs. FileName is not null terminated. It is the file's name when the event w...
INT64 FirstWriteTime
When the first of those writes happened, in FILETIME units (UTC).
UINT32 Flags
PANO_FLAG_* values.
UINT64 Bytes
Bytes written by those writes.
UINT64 Writes
Number of writes through the handle covered by this event.
UINT32 Flags
PANO_FLAG_* values. PANO_FLAG_NAME_TRUNCATED refers to the image name and PANO_FLAG_COMMAND_LINE_TRUN...
WCHAR Strings[1]
The image name immediately followed by the command line. Neither is null terminated.
UINT32 CommandLineLength
Length of the command line in WCHARs. PANO_EVENT_PROCESS_CREATED only.
UINT32 ImageNameLength
Length of the image name in WCHARs. PANO_EVENT_PROCESS_CREATED only.
UINT64 ParentProcessId
PANO_EVENT_PROCESS_CREATED only.
UINT64 CreatingProcessId
The process that created the new process, which can differ from the parent. PANO_EVENT_PROCESS_CREATE...
UINT64 CreatingThreadId
The thread that created the new process. PANO_EVENT_PROCESS_CREATED only.
WCHAR Strings[1]
The key name, then the second name (neither null terminated), then DataLength bytes of data....
UINT32 KeyNameLength
Length of the key's full name (\REGISTRY\MACHINE...) in WCHARs.
UINT32 Detail
Per event type: the REG_* value type (SET_VALUE), the REG_*_FORMAT (SAVE_KEY), the SECURITY_INFORMATI...
UINT32 DataSize
The full size of Data in bytes before it was cut to fit: the value's data (SET_VALUE) or the old hive...
UINT32 Flags
PANO_FLAG_* values.
UINT32 SecondNameLength
Length of the second name in WCHARs: the value name (SET_VALUE, QUERY_VALUE), the file (SAVE_KEY,...
UINT32 DataLength
Bytes in Data, at most PANO_MAX_REGISTRY_DATA_SIZE. SET_VALUE and REPLACE_KEY only.
WCHAR Names[1]
The original name immediately followed by the new name. Neither is null terminated.
UINT32 Flags
PANO_FLAG_* values.
UINT32 SourceNameLength
Length of the original name in WCHARs.
UINT32 DestinationNameLength
Length of the new name in WCHARs.
std::string FormatSystemTime(const FILETIME &ft)
The log's Time format: "2026/11/15 21:05:48.123", in the FILETIME's zone (UTC).
std::string ToString(const std::wstring &wstr)