/
modus_operandi.h
169 lines (135 loc) · 4.51 KB
/
modus_operandi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* 2011, 2012, 201, 2014 SRI International
* See LICENSE for other credits and copying information
*/
#ifndef MODUS_OPERANDI_H
#define MODUS_OPERANDI_H
#include <string>
#include <stdint.h>
#include <vector>
#include <algorithm>
#include <getopt.h>
#include <yaml-cpp/yaml.h>
#include "cpp.h"
//#include "steg/jel_knobs.h"
using std::vector;
using std::string;
enum class StegData { TRACES, IMAGES, PDFS, STREAM };
#define STEG_TRACES_DIR "./traces"
/* for parsing in chop.cc */
class down_address_t {
public: down_address_t(void);
public: void parse(string);
public: bool ok;
public: string ip;
public: string steg;
};
/**
* read, validate and update the config structure.
*/
class modus_operandi_t {
protected:
/* A string listing valid short options letters.*/
const char* const short_options = "hc:l:s:ntkr:p:d";
const std::vector<std::string> config_valid_extra_key_words = {"protocols"};
/* An array describing valid long options. */
static const struct option long_options[];
/**
* spots line curresponding to the long option in the getopts
* option list.
*
* @param the option keyword to search for
*
* @return the index of the option in the array or -1
* if not found
*/
int find_long_option(const string& long_option_name) {
for(int i = 0; long_options[i].name != nullptr; i++)
if (long_option_name == long_options[i].name)
return i;
return -1;
}
/**
* validate the config by checking for unknown keyword at
* stegotorus level (protocol are responsible to check for
* validity of the config*/
bool validate_top_level_config(const YAML::Node& conf_node);
/**
* read the hierechical struture of the protocol from the YAML configs
* and store them in the protocols_config_dict. abort if config has
* problem.
*
* @param protocols_node the YAML node which points to protocols:
* node in the config file
*/
void process_protocols(const YAML::Node& protocols_node);
/**
* read the hierechical struture of the protocol from the commandline
* args store them in the protocols_config_dict. abort if config has
* problem.
*/
void process_protocol(const char* argv);
public:
//TODO: these needs access function
YAML::Node protocol_configs;
//This is basically to track if user has specified any protocol
size_t number_of_protocols = 0;
config_dict_t top_level_confs_dict;
modus_operandi_t();
/**
* reads the file using yaml module, validate it and store the
* config values in hierarchical dicts.
*/
void load_file(const string& path);
/**
* processes the command line argument based on the place they
* have been mentioned they might over write config file options
*
* @param argv the array containing command line arguments
* @param argc number of elements in argv
*
* @return the index of where the protocol options start
*
*/
int process_command_line_config(const char *const *argv, const int argc);
/**
* helper functions which uniformizes the value of boolean config to
* one string represetation.
*
* @param stringized_boolean_value a string which represent a boolean
* value. 0, False, FALSE, false represents false. 1, True, TRUE
* true represent true.
*
*
* @return "false" or "true" for valid values or "" for invalid value.
**/
static std::string uniformize_boolean_value(const std::string& stringized_boolean_value)
{
static const std::vector<std::string> false_representations = {"0", "False", "FALSE", "false"};
static const std::vector<std::string> true_representations = {"1", "True", "TRUE", "true", ""};
if (std::find(false_representations.begin(),false_representations.end(),stringized_boolean_value) != false_representations.end())
return false_string;
else if (std::find(true_representations.begin(),true_representations.end(),stringized_boolean_value) != true_representations.end())
return true_string;
else
return "";
}
/**
* a helper function to check if a specific config
* keyboard exists in the config dictionary
*
* @param keyword_option the keyword specifying the option
*
* @return true if the option is exists in the config dictionary otherwise returns
* false.
*/
bool is_set(std::string keyword_option)
{
return (top_level_confs_dict.find(keyword_option) != top_level_confs_dict.end());
}
/**
Prints usage instructions then exits.
*/
static void ATTR_NORETURN
usage(void);
};
#endif