5#include "absl/flags/flag.h"
6#include "absl/flags/parse.h"
8ABSL_FLAG(
bool, install,
false,
"Install Panoptes Kernel Driver, Service, and Context Menu");
9ABSL_FLAG(
bool, uninstall,
false,
"Uninstall Panoptes");
17 DWORD fileAttributes = GetFileAttributesA(filePath.c_str());
18 return (fileAttributes != INVALID_FILE_ATTRIBUTES &&
19 !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
28 SC_HANDLE scm = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
33 SC_HANDLE service = OpenServiceA(scm, serviceName.c_str(), SERVICE_QUERY_STATUS);
35 if (service == NULL) {
36 DWORD error = GetLastError();
37 CloseServiceHandle(scm);
38 return (error != ERROR_SERVICE_DOES_NOT_EXIST);
41 CloseServiceHandle(service);
42 CloseServiceHandle(scm);
51 InstallHinfSection(NULL, NULL, L
"DefaultInstall 132 C:\\Program Files\\Panoptes\\driver\\Panoptes.inf", 0);
59 HKEY hKey, hCommandKey;
60 std::string subKey =
"*\\shell\\Panoptes";
62 LONG
result = RegCreateKeyExA(
67 REG_OPTION_NON_VOLATILE,
74 if (
result == ERROR_SUCCESS) {
75 std::string rootDefaultValue =
"Scan with Panoptes";
81 reinterpret_cast<const BYTE*
>(rootDefaultValue.c_str()),
82 static_cast<DWORD>((rootDefaultValue.length() + 1) *
sizeof(
wchar_t))
84 if (
result != ERROR_SUCCESS) {
90 std::string iconValue =
"C:\\Program Files\\Panoptes\\tools\\PanoptesScan.exe";
96 reinterpret_cast<const BYTE*
>(iconValue.c_str()),
97 static_cast<DWORD>((iconValue.length() + 1) *
sizeof(
wchar_t))
100 if (
result == ERROR_SUCCESS) {
107 REG_OPTION_NON_VOLATILE,
114 if (
result == ERROR_SUCCESS) {
116 std::string commandValue =
"\"C:\\Program Files\\Panoptes\\tools\\PanoptesScan.exe\" \"%1\"";
122 reinterpret_cast<const BYTE*
>(commandValue.c_str()),
123 static_cast<DWORD>((commandValue.length() + 1) *
sizeof(
wchar_t))
126 RegCloseKey(hCommandKey);
143 WIN32_FIND_DATAA findFileData;
145 strcpy_s(searchPath, databasePath.c_str());
146 strcat_s(searchPath,
"\\*");
148 HANDLE hFind = FindFirstFileA(searchPath, &findFileData);
149 if (hFind == INVALID_HANDLE_VALUE) {
154 if (strcmp(findFileData.cFileName,
".") != 0 &&
155 strcmp(findFileData.cFileName,
"..") != 0) {
156 std::string filePath = databasePath +
"\\" + findFileData.cFileName;
158 if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
162 DeleteFileA(filePath.c_str());
165 }
while (FindNextFileA(hFind, &findFileData) != 0);
167 if (RemoveDirectoryA(databasePath.c_str())) {
171 printf(
"Error attempting to delete database file: %d\n", GetLastError());
181 std::string subKey =
"*\\shell\\Panoptes";
183 LONG
result = RegDeleteTreeA(
197 SC_HANDLE scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
202 SC_HANDLE service = OpenServiceA(scm, serviceName.c_str(), DELETE);
203 if (service == NULL) {
204 CloseServiceHandle(scm);
210 CloseServiceHandle(service);
211 CloseServiceHandle(scm);
215 CloseServiceHandle(service);
216 CloseServiceHandle(scm);
226 if (DeleteFileA(filePath.c_str())) {
230 DWORD error = GetLastError();
231 if (error == ERROR_FILE_NOT_FOUND) {
248 printf(
"Adding new context menu item\n");
250 printf(
"successfully added new context menu item\n");
252 printf(
"Attempting to install driver");
254 printf(
"Successfully installed driver");
256 if (!
FileExists(
"C:\\Windows\\System32\\drivers\\Panoptes\\Panoptes.sys"))
284 std::string driverPath =
"C:\\Windows\\System32\\drivers\\Panoptes\\Panoptes.sys";
309int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow) {
310 std::string infPath =
"C:\\Program Files\\Panoptes\\driver\\Panoptes.inf";
311 absl::ParseCommandLine(__argc, __argv);
313 if (absl::GetFlag(FLAGS_install) ==
true && absl::GetFlag(FLAGS_uninstall) ==
true) {
314 MessageBoxA(NULL,
"Can not specify `install` and `uninstall` flags",
"Panoptes EDR", 1);
316 else if (absl::GetFlag(FLAGS_uninstall) ==
true) {
318 MessageBoxA(NULL,
"Driver uninstalled successfully.",
"Panoptes EDR Uninstall", 0);
321 MessageBoxA(NULL,
"Failed to uninstall driver.",
"Panoptes EDR Uninstall", 1);
324 else if (absl::GetFlag(FLAGS_install)) {
326 MessageBoxA(NULL,
"Driver installed successfully.",
"Panoptes EDR Installer", 0);
329 MessageBoxA(NULL,
"Failed to install driver.",
"Panoptes EDR Installer", 1);
333 MessageBoxA(NULL,
"No arguments provided.",
"Panoptes EDR", 1);
bool DeleteDatabase(std::string databasePath)
Deletes the rocksdb database file.
bool FileExists(const std::string &filePath)
Checks if a file exists.
BOOL UninstallPanoptes()
Uninstalls the Panoptes driver, service, and removes the context menu item.
bool ServiceExists(const std::string &serviceName)
Checks if a service exists.
bool DeletePanoptesDriver(const std::string &filePath)
Deletes the Panoptes driver file.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
The main function for the Panoptes Setup program.
bool DeletePanoptesService(const std::string &serviceName)
Deletes the Panoptes service.
BOOL InstallPanoptes(std::string infPath)
Installs the Panoptes driver, service, and adds the context menu item.
LONG NewContextMenuItem()
Creates a new context menu item called "Scan with Panoptes" that uses the PanoptesScan....
LONG DeleteContextMenuItem()
Deletes the context menu item called "Scan with Panoptes".
ABSL_FLAG(bool, install, false, "Install Panoptes Kernel Driver, Service, and Context Menu")
VOID InstallDriverFile(std::string infPath)
Installs the driver file.