Skip to content
API Documentation
BastionGuard™
AntiRansomwarePage.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21#pragma once
22#include <gtkmm.h>
23#include <giomm.h>
24#include <filesystem>
25#include <string>
26#include <vector>
27#include <yara.h>
28#include <thread>
29#include <atomic>
30
31#include "LifetimeGuard.hpp"
32
33class AntiRansomwarePage : public Gtk::Box {
34public:
35 AntiRansomwarePage(Gtk::Window& parent);
36 virtual ~AntiRansomwarePage();
37
38 std::string selectedPath;
39
40 void sendAlert(const std::string& file, const std::string& ruleName);
41 void appendLog(const Glib::ustring& text);
42
43private:
44
45 Gtk::Window& parentWindow;
46
47 Gtk::Box buttonBox{Gtk::Orientation::HORIZONTAL, 8};
48 Gtk::Button btnStart{"Avvia protezione"};
49 Gtk::Button btnStop{"Ferma protezione"};
50 Gtk::Button btnChooseFile{"Scegli file"};
51 Gtk::Button btnChooseFolder{"Scegli cartella"};
52 Gtk::Button btnScan{"Scansiona"};
53 Gtk::Button btnTest{"Test alert"};
54
55 Gtk::TextView textView;
56 Glib::RefPtr<Gtk::TextBuffer> textBuffer;
57
58 bool daemonRunning = false;
59
60
61 YR_COMPILER* yaraCompiler = nullptr;
62 YR_RULES* yaraRules = nullptr;
63
64 void loadYaraRules();
65 void runYaraOnPath(const std::string& path);
66 void scanDirectoryRecursively(const std::string& path);
67
68
71 void onChooseFile();
72 void onChooseFolder();
73 void onManualScan();
74 void onTestAlert();
75
76
77 std::thread logThread;
78 std::atomic<bool> logThreadRunning{false};
79
80 // Alive flag: proteggere signal_idle.connect_once che possono
81 // eseguirsi dopo la distruzione della pagina.
83
85 void processLogLine(const std::string& line);
86};
BastionGuard::AliveFlag alive_
Glib::RefPtr< Gtk::TextBuffer > textBuffer
void appendLog(const Glib::ustring &text)
std::atomic< bool > logThreadRunning
void sendAlert(const std::string &file, const std::string &ruleName)
AntiRansomwarePage(Gtk::Window &parent)
void runYaraOnPath(const std::string &path)
void processLogLine(const std::string &line)
void scanDirectoryRecursively(const std::string &path)
std::shared_ptr< std::atomic< bool > > AliveFlag
AliveFlag make_alive_flag()