-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTamperMethod.hpp
109 lines (95 loc) · 3.01 KB
/
TamperMethod.hpp
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
#ifndef _TAMPER_METHOD_HPP_
#define _TAMPER_METHOD_HPP_
#include <cstdint>
#include <string>
#include <map>
/**
* @brief Method used to tamper with packet data
*/
class TamperMethod {
private:
double probability = 1; /*!< Probability between 0 and 1 that this tamper method will act on a given packet */
public:
/**
* @brief Initialize a new tamper method
*
* @param _opts Map of supplied configuration options
*/
TamperMethod(std::map<std::string, std::string> &_opts);
/**
* @brief Apply tampering on packet data
*
* @param len Length of data
* @param data Pointer to modifiable data
*
* @return <Return value currently unused, returns 0>
*/
virtual int tamper(size_t len, uint8_t *data) = 0;
/**
* @brief Get the configured execution probability
*/
double getProbability(void);
/**
* @brief Create TamperMethod from configuration string
*
* @param _str Configuration string
*/
static TamperMethod *create(std::string &_str);
/**
* @brief Parse range string from configuration
*
* The following formats are currently supported:
* <val>
* -1
* <min>:<max>
* <min>:-1
*
* @param _str Configuration value string
* @param _min Output minimum
* @param _max Output maximum
*
* @return 0 on success, < 0 on failure
*/
static int parseRange(std::string &_str, int &_min, int &_max);
/**
* @brief Parse boolean string from configuration
*
* The following formats are currently supported:
* 0
* false
* 1
* true
*
* @param _str Configuration value string
* @param _val Output boolean
*
* @return 0 on success, < 0 on failure
*/
static int parseBool(std::string &_str, bool &_val);
/**
* @brief Parse hex string from configuration
*
* The format is byte-ordered groups of two hexadecimal characters:
* <byte0>[<byte1>[<byte2>[...]]]
*
* Where each of <byteX> is a sequence of two characters, e.g.:
* C0FFEE1234
*
* @param _str Configuration value string
* @param _val Output byte vector
*
* @return 0 on success, < 0 on failure
*/
static int parseHex(std::string &_str, std::vector<uint8_t> &_val);
/**
* @brief Generates a random non-negative number in the given range
*
* @param _min Minimum value, -1 = _sz
* @param _max Maximum value, -1 = _sz
* @param _sz Absolute limit
*
* @return Random value
*/
static size_t randRange(int _min, int _max, size_t _sz);
};
#endif /* _TAMPER_METHOD_HPP_ */