8#pragma region Utility Functions
14 unsigned long value = std::stoul(str,
nullptr, 0);
15 return static_cast<DWORD>(value);
17 catch (
const std::invalid_argument& e) {
21 catch (
const std::out_of_range& e) {
31std::vector<std::string>
SplitString(
const std::string& input,
char delimiter =
',') {
32 std::vector<std::string>
result;
33 std::stringstream ss(input);
36 while (std::getline(ss, item, delimiter)) {
47 std::transform(str.begin(), str.end(), str.begin(),
48 [](
unsigned char c) { return std::tolower(c); });
79 if (
m_data[
"EventProviders"].is_array()) {
81 std::vector<std::string> selectedExtensibility =
m_data[
"EventProviders"].template get<std::vector<std::string>>();
83 for (std::string containerTypeStr : selectedExtensibility) {
85 if (splitStr.size() != 3) {
86 throw std::runtime_error(
"Invalid Event Provider format");
89 std::string providerName = splitStr[0];
90 unsigned long providerMatchAnyKeyword =
StringToDWORD(splitStr[1]);
91 unsigned long providerMatchAllKeyword =
StringToDWORD(splitStr[2]);
93 auto eventProviderInfo = std::make_tuple(providerName, providerMatchAnyKeyword, providerMatchAllKeyword);
98 throw std::runtime_error(
"EventProviders was not set in the the configuration");
105 if (
m_data[
"ExtensibilitySelected"].is_array()) {
106 std::vector<std::string> selectedExtensibility =
m_data[
"ExtensibilitySelected"].template get<std::vector<std::string>>();
108 for (std::string containerTypeStr : selectedExtensibility) {
115 else if (
StrToLower(containerTypeStr) ==
"pe") {
118 else if (
StrToLower(containerTypeStr) ==
"yara") {
122 throw std::runtime_error(
"Invalid Container Type");
129 throw std::runtime_error(
"ExtensibilitySelected was not set in the the configuration");
136 if (
m_data[
"Exclusions"].is_array()) {
140 throw std::runtime_error(
"Exclusions was not set in the the configuration");
146 if (
m_data[
"IgnoreDriver"].is_boolean()) {
150 throw std::runtime_error(
"IgnoreDriver was not set in the the configuration");
156 if (
m_data[
"QuarantineMaliciousFiles"].is_boolean()) {
160 throw std::runtime_error(
"QuarantineMaliciousFiles was not set in the the configuration");
167 std::vector<std::string> keys;
169 for (nlohmann::json::const_iterator it =
m_data.begin(); it !=
m_data.end(); ++it) {
170 keys.push_back(it.key());
174 throw std::runtime_error(
"The json data object was not set");
std::string StrToLower(std::string str)
Convert a string to lowercase.
std::vector< std::string > SplitString(const std::string &input, char delimiter=',')
Split a string into a vector of strings.
DWORD StringToDWORD(const std::string &str)
Convert a string to a DWORD.
std::vector< std::tuple< std::string, unsigned long, unsigned long > > m_eventProviders
The event providers from the configuration file.
Configuration(std::string configurationPath)
Constructor for the Configuration class.
std::vector< Configuration::ContainerType > m_extensibility
The extensibility selected from the configuration file.
std::vector< std::string > m_exclusions
The exclusions from the configuration file.
std::vector< std::string > GetJsonKeys()
Get the keys from the configuration file.
void GetIgnoreDriver()
Get the ignore driver from the configuration file.
ContainerType
The type of container that the extensibility is running in.
void Parse()
Parse the configuration file.
void IsValidJson()
Check if the configuration file is valid.
void GetScannerExclusions()
Get the scanner exclusions from the configuration file.
void GetQuarantineMaliciousFiles()
Get the quarantine malicious files from the configuration file.
std::ifstream m_fileStream
bool m_ignoreDriver
The ignore driver from the configuration file.
void GetExtensibilitySelected()
Get the extensibility selected from the configuration file.
void GetEventProviders()
Get the event providers from the configuration file.
bool m_quartine
The quarantine malicious files from the configuration file.