Skip to content
API Documentation
BastionGuard™
DelayedScanQueue Class Reference

Classes

struct  Item

Public Member Functions

 DelayedScanQueue (YaraEngine &y)
void enqueue (const std::string &path, int delay_ms=30000)
void run ()
void stop ()

Private Attributes

YaraEngine & yara
std::mutex mtx
std::vector< Item > queue
std::atomic< bool > active {true}

Detailed Description

Definition at line 858 of file BastionGuard-ransomware-realtime.cpp.

Constructor & Destructor Documentation

◆ DelayedScanQueue()

DelayedScanQueue::DelayedScanQueue ( YaraEngine & y)
inline

Definition at line 872 of file BastionGuard-ransomware-realtime.cpp.

References yara.

Member Function Documentation

◆ enqueue()

void DelayedScanQueue::enqueue ( const std::string & path,
int delay_ms = 30000 )
inline

Definition at line 874 of file BastionGuard-ransomware-realtime.cpp.

875 {
876 std::lock_guard<std::mutex> lock(mtx);
877 queue.push_back({
878 path,
879 std::chrono::steady_clock::now() + std::chrono::milliseconds(delay_ms)
880 });
881 log_msg(_("DelayedScanQueue: aggiunto ") + path);
882 }
#define _(s)
void log_msg(const std::string &msg)

References _, log_msg(), mtx, and queue.

Referenced by InotifyEngine::run().

◆ run()

void DelayedScanQueue::run ( )
inline

Definition at line 884 of file BastionGuard-ransomware-realtime.cpp.

885 {
886 log_msg(_("DelayedScanQueue: thread avviato"));
887
888 while (active) {
889 auto now = std::chrono::steady_clock::now();
890 std::vector<std::string> to_scan;
891
892 {
893 std::lock_guard<std::mutex> lock(mtx);
894 auto it = queue.begin();
895 while (it != queue.end()) {
896 if (it->when <= now) {
897 to_scan.push_back(it->path);
898 it = queue.erase(it);
899 } else {
900 ++it;
901 }
902 }
903 }
904
905 for (const auto& p : to_scan) {
906 log_msg(_("DelayedScanQueue: SCANSIONE RITARDATA → ") + p);
907 yara.scan_file(p);
908 }
909
910 std::this_thread::sleep_for(std::chrono::milliseconds(500));
911 }
912
913 log_msg(_("DelayedScanQueue: thread terminato"));
914 }
bool scan_file(const std::string &path)

References _, active, log_msg(), mtx, queue, YaraEngine::scan_file(), and yara.

Referenced by main().

◆ stop()

void DelayedScanQueue::stop ( )
inline

Definition at line 916 of file BastionGuard-ransomware-realtime.cpp.

917 {
918 active = false;
919 }

References active.

Referenced by main().

Member Data Documentation

◆ active

std::atomic<bool> DelayedScanQueue::active {true}
private

Definition at line 869 of file BastionGuard-ransomware-realtime.cpp.

Referenced by run(), and stop().

◆ mtx

std::mutex DelayedScanQueue::mtx
private

Definition at line 867 of file BastionGuard-ransomware-realtime.cpp.

Referenced by enqueue(), and run().

◆ queue

std::vector<Item> DelayedScanQueue::queue
private

Definition at line 868 of file BastionGuard-ransomware-realtime.cpp.

Referenced by enqueue(), and run().

◆ yara

YaraEngine& DelayedScanQueue::yara
private

Definition at line 860 of file BastionGuard-ransomware-realtime.cpp.

Referenced by DelayedScanQueue(), and run().


The documentation for this class was generated from the following file: