1#include <grpcpp/grpcpp.h>
2#include "panoptes.grpc.pb.h"
3#include "panoptes.pb.h"
9namespace fs = std::filesystem;
17std::unique_ptr<PanoptesService::Stub>
stub;
22#define PANOPTES_REG_ROOT HKEY_CURRENT_USER
24#define PANOPTES_REG_ROOT HKEY_LOCAL_MACHINE
33 DWORD dwType = REG_DWORD;
34 DWORD dwSize =
sizeof(DWORD);
37 LONG lResult = RegOpenKeyExA(
45 if (lResult != ERROR_SUCCESS) {
46 std::cerr <<
"Error opening registry key. Error code: " << lResult << std::endl;
51 lResult = RegQueryValueExA(
56 reinterpret_cast<LPBYTE
>(&portValue),
62 if (lResult != ERROR_SUCCESS) {
63 std::cerr <<
"Error reading registry value. Error code: " << lResult << std::endl;
67 if (dwType != REG_DWORD) {
68 std::cerr <<
"Unexpected value type in registry." << std::endl;
92 std::cerr <<
"Failed to get registry port value." << std::endl;
95 std::string server_url =
"localhost:" + std::to_string(portValue);
99 std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(server_url,
100 grpc::InsecureChannelCredentials());
102 stub = PanoptesService::NewStub(channel);
104 grpc::ClientContext context;
105 HealthCheckRequest request;
106 HealthCheckResponse response;
107 request.set_ping(
true);
110 grpc::Status status =
stub->HealthCheck(&context, request, &response);
125 HMODULE extensibility = LoadLibraryA(dllFile.c_str());
126 if (extensibility == NULL) {
127 DWORD error = GetLastError();
157 for (
int attempt = 0; attempt < maxAttempts; ++attempt) {
162 if (attempt < maxAttempts - 1) {
163 int sleep_duration_ms = baseSleep * std::pow(multiplier, attempt);
164 std::cout <<
"Sleeping for " << sleep_duration_ms <<
" ms" << std::endl;
165 std::this_thread::sleep_for(std::chrono::milliseconds(sleep_duration_ms));
178int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
188 DWORD length = GetModuleFileNameA(NULL, modulePath,
MAX_PATH);
189 if (length != 0 && length !=
MAX_PATH) {
190 std::string containerDir(modulePath, length);
191 SetCurrentDirectoryA(containerDir.substr(0, containerDir.find_last_of(
"\\/")).c_str());
194 std::string dllPath(__argv[1]);
196 printf(
"Error Loading Extensibility");
200 HANDLE grpcServerThread = CreateThread(
209 if (grpcServerThread == NULL ||
BindPort == 0)
211 std::cout <<
"Error creating thread: " << GetLastError() << std::endl;
218 std::cout <<
"Error Binding to service: " << GetLastError() << std::endl;
223 HANDLE healthCheckThread = CreateThread(
232 if (healthCheckThread == NULL ||
BindPort == 0)
234 std::cout <<
"Error creating thread: " << GetLastError() << std::endl;
240 HANDLE messageQueueThread = CreateThread(
249 if (healthCheckThread == NULL ||
BindPort == 0)
251 std::cout <<
"Error creating thread: " << GetLastError() << std::endl;
bool(* PanoEntryPtr)(PeScan *)
std::unique_ptr< PanoptesService::Stub > stub
#define PANOPTES_REG_ROOT
void HealthCheck()
The HealthCheck function is a thread that checks the health of the Panoptes main service.
ExtensibilityCore::PanoBindPtr PanoBind
void MessageQueueThread()
The MessageQueueThread function is a thread that dequeues messages from the message queue and process...
bool GetRegistryPortValue(DWORD &portValue)
Get the gRPC port value from the registry.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
The WinMain function is the entry point for the container.
std::atomic_bool isConnected
bool BindToServiceWithRetry(int containerPort, int maxAttempts, int baseSleep, double multiplier)
The BindToServiceWithRetry function is a function that binds to the Panoptes main service with a retr...
ExtensibilityCore::PanoEntryPtr PanoEntry
bool LoadExtensibility(std::string dllFile)
The LoadExtensibility function is a function that loads the extensibility DLL.
ExtensibilityCore::PanoUnbindPtr PanoUnbind
VOID RunContainerServer(LPVOID ContainerPort)
The RunContainerServer function is a function that runs the container server.
PeMessageQueue * message_queue_pe_
The information about the file to be scanned that passed between the container, extensibility and the...