Skip to content
API Documentation
BastionGuard™
ScanPage.cpp File Reference

Go to the source code of this file.

Functions

static int64_t nowMs ()
static bool ends_with (const std::string &s, const std::string &suf)
static bool isBuildArtifactExt (const std::string &path)
static bool isInBuildDir (const std::string &path)
static std::string normalizePath (std::string p)
static std::string trim (const std::string &s)
std::string getConfigPath ()
std::uintmax_t safeSize (const std::string &p) noexcept

Variables

std::string globalMalwareBazaarApiKey
static std::unordered_set< std::string > recentlyScanned
static std::atomic< int > g_recentEventCount {0}
static std::atomic< int64_t > g_burstWindowStartMs {0}
static std::atomic< int64_t > g_throttleUntilMs {0}
static constexpr int kBurstWindowMs = 2000
static constexpr int kBurstThreshold = 20
static constexpr int64_t kThrottleHoldMs = 5000
static std::atomic< int > activeCloudChecks {0}

Function Documentation

◆ ends_with()

bool ends_with ( const std::string & s,
const std::string & suf )
static

Definition at line 71 of file ScanPage.cpp.

71 {
72 return s.size() >= suf.size() &&
73 s.compare(s.size() - suf.size(), suf.size(), suf) == 0;
74}

References ends_with().

Referenced by ends_with(), ScanPage::handleInotifyFileEvent(), and isBuildArtifactExt().

◆ getConfigPath()

std::string getConfigPath ( )

Definition at line 310 of file ScanPage.cpp.

310 {
311 return Glib::get_home_dir() + "/.local/share/BastionGuard/config.json";
312}

References getConfigPath().

Referenced by getConfigPath(), ScanPage::loadConfig(), and ScanPage::saveConfig().

◆ isBuildArtifactExt()

bool isBuildArtifactExt ( const std::string & path)
static

Definition at line 79 of file ScanPage.cpp.

79 {
80 static const char* exts[] = {
81 ".o", ".obj", ".a", ".lo", ".la", ".pyc", ".pyo",
82 ".class", ".d", ".gch", ".pch", ".mod", ".swp", ".swo",
83 ".rlib", ".rmeta", ".tmp", ".bc", ".ll"
84 };
85 for (auto* e : exts) {
86 if (ends_with(path, e)) return true;
87 }
88 return false;
89}
static bool ends_with(const std::string &s, const std::string &suf)
Definition ScanPage.cpp:71

References ends_with(), and isBuildArtifactExt().

Referenced by ScanPage::handleInotifyFileEvent(), and isBuildArtifactExt().

◆ isInBuildDir()

bool isInBuildDir ( const std::string & path)
static

Definition at line 93 of file ScanPage.cpp.

93 {
94 static const char* needles[] = {
95 "/build/", "/cmake-build-", "/CMakeFiles/", "/.ninja_",
96 "/target/", // Cargo / Rust, Maven
97 "/node_modules/", // npm
98 "/dist/", "/out/", "/bin/", "/obj/",
99 "/.gradle/", "/.m2/", "/.cargo/",
100 "/__pycache__/", "/.pytest_cache/",
101 "/.next/", "/.nuxt/", "/.svelte-kit/",
102 "/.tox/", "/.venv/", "/venv/",
103 "/Debug/", "/Release/"
104 };
105 for (auto* n : needles) {
106 if (path.find(n) != std::string::npos) return true;
107 }
108 return false;
109}

References isInBuildDir().

Referenced by ScanPage::addInotifyRecursive(), ScanPage::handleInotifyFileEvent(), and isInBuildDir().

◆ normalizePath()

std::string normalizePath ( std::string p)
static

Definition at line 111 of file ScanPage.cpp.

111 {
112 while (!p.empty() && p.back() == '/')
113 p.pop_back();
114 return p;
115}

References normalizePath().

Referenced by ScanPage::addInotifyRecursive(), ScanPage::enableAutoScanDownloads(), ScanPage::enableGlobalDownloadMonitor(), and normalizePath().

◆ nowMs()

int64_t nowMs ( )
static

Definition at line 66 of file ScanPage.cpp.

66 {
67 return std::chrono::duration_cast<std::chrono::milliseconds>(
68 std::chrono::steady_clock::now().time_since_epoch()).count();
69}

References nowMs().

Referenced by ScanPage::handleInotifyFileEvent(), and nowMs().

◆ safeSize()

std::uintmax_t safeSize ( const std::string & p)
noexcept

Definition at line 1340 of file ScanPage.cpp.

1341{
1342 try { return fs::file_size(p); }
1343 catch (...) { return 0; }
1344}

References safeSize().

Referenced by safeSize().

◆ trim()

std::string trim ( const std::string & s)
static

Definition at line 117 of file ScanPage.cpp.

117 {
118 size_t start = s.find_first_not_of(" \n\r\t");
119 if (start == std::string::npos) return "";
120 size_t end = s.find_last_not_of(" \n\r\t");
121 return s.substr(start, end - start + 1);
122}

References trim().

Referenced by ScanPage::loadCloudConfig(), and ScanPage::onStartScan().

Variable Documentation

◆ activeCloudChecks

std::atomic<int> activeCloudChecks {0}
static

Definition at line 1214 of file ScanPage.cpp.

Referenced by ScanPage::cloudCheckMalwareBazaar().

◆ g_burstWindowStartMs

std::atomic<int64_t> g_burstWindowStartMs {0}
static

Definition at line 58 of file ScanPage.cpp.

Referenced by ScanPage::handleInotifyFileEvent().

◆ g_recentEventCount

std::atomic<int> g_recentEventCount {0}
static

Definition at line 57 of file ScanPage.cpp.

Referenced by ScanPage::handleInotifyFileEvent().

◆ g_throttleUntilMs

std::atomic<int64_t> g_throttleUntilMs {0}
static

Definition at line 59 of file ScanPage.cpp.

Referenced by ScanPage::handleInotifyFileEvent().

◆ globalMalwareBazaarApiKey

std::string globalMalwareBazaarApiKey
extern

◆ kBurstThreshold

int kBurstThreshold = 20
staticconstexpr

Definition at line 63 of file ScanPage.cpp.

Referenced by ScanPage::handleInotifyFileEvent().

◆ kBurstWindowMs

int kBurstWindowMs = 2000
staticconstexpr

Definition at line 62 of file ScanPage.cpp.

Referenced by ScanPage::handleInotifyFileEvent().

◆ kThrottleHoldMs

int64_t kThrottleHoldMs = 5000
staticconstexpr

Definition at line 64 of file ScanPage.cpp.

Referenced by ScanPage::handleInotifyFileEvent().

◆ recentlyScanned

std::unordered_set<std::string> recentlyScanned
static