Skip to content
API Documentation
BastionGuard™
bsc::proc::anonymous_namespace{ProcMon.cpp} Namespace Reference

Functions

std::string slurp (const fs::path &p, bool binary=false)
std::vector< std::string > split_nulls (const std::string &s)
std::string md5_file (const fs::path &p)
std::string sha1_file (const fs::path &p)
std::string sha256_file (const fs::path &p)

Variables

constexpr auto kFreshCacheTtl = std::chrono::seconds(3)
constexpr auto kRecentExitTtl = std::chrono::seconds(2)

Function Documentation

◆ md5_file()

std::string bsc::proc::anonymous_namespace{ProcMon.cpp}::md5_file ( const fs::path & p)

Definition at line 31 of file ProcMon.cpp.

31 {
32 std::ifstream in(p, std::ios::binary); if (!in) return {};
33 MD5_CTX ctx; MD5_Init(&ctx);
34 char buf[8192];
35 while (in.read(buf, sizeof(buf)) || in.gcount() > 0) MD5_Update(&ctx, buf, static_cast<size_t>(in.gcount()));
36 unsigned char out[MD5_DIGEST_LENGTH]; MD5_Final(out, &ctx);
37 static const char* hex = "0123456789abcdef";
38 std::string s; s.reserve(MD5_DIGEST_LENGTH * 2);
39 for (unsigned char b : out) { s.push_back(hex[b >> 4]); s.push_back(hex[b & 0xF]); }
40 return s;
41}

References md5_file().

Referenced by md5_file().

◆ sha1_file()

std::string bsc::proc::anonymous_namespace{ProcMon.cpp}::sha1_file ( const fs::path & p)

Definition at line 42 of file ProcMon.cpp.

42 {
43 std::ifstream in(p, std::ios::binary); if (!in) return {};
44 SHA_CTX ctx; SHA1_Init(&ctx);
45 char buf[8192];
46 while (in.read(buf, sizeof(buf)) || in.gcount() > 0) SHA1_Update(&ctx, buf, static_cast<size_t>(in.gcount()));
47 unsigned char out[SHA_DIGEST_LENGTH]; SHA1_Final(out, &ctx);
48 static const char* hex = "0123456789abcdef";
49 std::string s; s.reserve(SHA_DIGEST_LENGTH * 2);
50 for (unsigned char b : out) { s.push_back(hex[b >> 4]); s.push_back(hex[b & 0xF]); }
51 return s;
52}

References sha1_file().

Referenced by sha1_file().

◆ sha256_file()

std::string bsc::proc::anonymous_namespace{ProcMon.cpp}::sha256_file ( const fs::path & p)

Definition at line 53 of file ProcMon.cpp.

53 {
54 std::ifstream in(p, std::ios::binary); if (!in) return {};
55 SHA256_CTX ctx; SHA256_Init(&ctx);
56 char buf[8192];
57 while (in.read(buf, sizeof(buf)) || in.gcount() > 0) SHA256_Update(&ctx, buf, static_cast<size_t>(in.gcount()));
58 unsigned char out[SHA256_DIGEST_LENGTH]; SHA256_Final(out, &ctx);
59 static const char* hex = "0123456789abcdef";
60 std::string s; s.reserve(SHA256_DIGEST_LENGTH * 2);
61 for (unsigned char b : out) { s.push_back(hex[b >> 4]); s.push_back(hex[b & 0xF]); }
62 return s;
63}

References sha256_file().

Referenced by sha256_file().

◆ slurp()

std::string bsc::proc::anonymous_namespace{ProcMon.cpp}::slurp ( const fs::path & p,
bool binary = false )

Definition at line 17 of file ProcMon.cpp.

17 {
18 std::ifstream in(p, binary ? std::ios::binary : std::ios::in);
19 if (!in) return {};
20 std::ostringstream ss; ss << in.rdbuf(); return ss.str();
21}

References slurp().

Referenced by slurp().

◆ split_nulls()

std::vector< std::string > bsc::proc::anonymous_namespace{ProcMon.cpp}::split_nulls ( const std::string & s)

Definition at line 22 of file ProcMon.cpp.

22 {
23 std::vector<std::string> out; std::string cur;
24 for (char c : s) {
25 if (c == '\0') { if (!cur.empty()) out.push_back(cur); cur.clear(); }
26 else cur.push_back(c);
27 }
28 if (!cur.empty()) out.push_back(cur);
29 return out;
30}

References split_nulls().

Referenced by split_nulls().

Variable Documentation

◆ kFreshCacheTtl

auto bsc::proc::anonymous_namespace{ProcMon.cpp}::kFreshCacheTtl = std::chrono::seconds(3)
constexpr

Definition at line 14 of file ProcMon.cpp.

◆ kRecentExitTtl

auto bsc::proc::anonymous_namespace{ProcMon.cpp}::kRecentExitTtl = std::chrono::seconds(2)
constexpr

Definition at line 15 of file ProcMon.cpp.