1#include <grpcpp/grpcpp.h>
2#include "panoptes.grpc.pb.h"
3#include "panoptes.pb.h"
9namespace fs = std::filesystem;
18std::unique_ptr<PanoptesService::Stub>
stub;
27 DWORD dwType = REG_DWORD;
31 LONG lResult = RegOpenKeyExA(
39 if (lResult != ERROR_SUCCESS) {
40 std::cerr <<
"Error opening registry key. Error code: " << lResult << std::endl;
45 lResult = RegQueryValueExA(
50 reinterpret_cast<LPBYTE
>(&portValue),
56 if (lResult != ERROR_SUCCESS) {
57 std::cerr <<
"Error reading registry value. Error code: " << lResult << std::endl;
61 if (dwType != REG_DWORD) {
62 std::cerr <<
"Unexpected value type in registry." << std::endl;
86 std::cerr <<
"Failed to get registry port value." << std::endl;
89 std::string server_url =
"localhost:" + std::to_string(portValue);
93 std::shared_ptr<grpc::Channel> channel = grpc::CreateChannel(server_url,
94 grpc::InsecureChannelCredentials());
96 stub = PanoptesService::NewStub(channel);
98 grpc::ClientContext context;
99 HealthCheckRequest request;
100 HealthCheckResponse response;
101 request.set_ping(
true);
104 grpc::Status status =
stub->HealthCheck(&context, request, &response);
119 HMODULE extensibility = LoadLibraryA(dllFile.c_str());
120 if (extensibility == NULL) {
121 DWORD error = GetLastError();
151 for (
int attempt = 0; attempt < maxAttempts; ++attempt) {
156 if (attempt < maxAttempts - 1) {
157 int sleep_duration_ms = baseSleep * std::pow(multiplier, attempt);
158 std::cout <<
"Sleeping for " << sleep_duration_ms <<
" ms" << std::endl;
159 std::this_thread::sleep_for(std::chrono::milliseconds(sleep_duration_ms));
172int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
179 std::string dllPath(__argv[1]);
181 printf(
"Error Loading Extensibility");
185 HANDLE grpcServerThread = CreateThread(
194 if (grpcServerThread == NULL ||
BindPort == 0)
196 std::cout <<
"Error creating thread: " << GetLastError() << std::endl;
203 std::cout <<
"Error Binding to service: " << GetLastError() << std::endl;
208 HANDLE healthCheckThread = CreateThread(
217 if (healthCheckThread == NULL ||
BindPort == 0)
219 std::cout <<
"Error creating thread: " << GetLastError() << std::endl;
225 HANDLE messageQueueThread = CreateThread(
234 if (healthCheckThread == NULL ||
BindPort == 0)
236 std::cout <<
"Error creating thread: " << GetLastError() << std::endl;
bool(* PanoEntryPtr)(PeScan *, MemScan *)
PeScan dequeue()
The dequeue function dequeues a PeScan messages from the queue.
std::unique_ptr< PanoptesService::Stub > stub
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.
MemoryMessageQueue * message_queue_mem_
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
PeMessageQueue * message_queue_pe_
VOID RunContainerServer(LPVOID ContainerPort)
The RunContainerServer function is a function that runs the container server.
The information about the file to be scanned that passed between the container, extensibility and the...