-
Notifications
You must be signed in to change notification settings - Fork 4
/
NinkoConfig.cpp
121 lines (104 loc) · 2.95 KB
/
NinkoConfig.cpp
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
#include "NinkoConfig.h"
int NinkoConfig::parse(const std::string fileName)
{
char * config = NULL;
ifstream::pos_type size;
cerr << "Opening configuration file: " << fileName << endl;
std::ifstream config_file(fileName.c_str(), ios::in|ios::binary|ios::ate);
if (config_file.is_open())
{
size = config_file.tellg();
config_file.seekg (0, ios::beg);
config = new char [size];
config_file.read(config, size);
config_file.close();
cerr << "Config file contents: " << config << endl;
}
if (config == NULL)
{
return -1;
}
m_doc.Parse<0>(config);
if (m_doc.IsObject() == false)
{
cerr << "Document is not a valid object: " << m_doc.GetParseError() << endl;
return -1;
}
return 0;
}
void NinkoConfig::fillVars( ninko_t *vars )
{
vars->code_start = getAddr( "code_start" );
vars->code_end = getAddr( "code_end" );
vars->code_ignore = getArray( "code_ignore" );
vars->code_add = getArray( "code_add" );
vars->ignore_internal_calls = getBool( "ignore_internal_calls" );
vars->disable_log_calls = getBool( "disable_log_calls" );
vars->disable_log_writes = getBool( "disable_log_writes" );
vars->disable_log_reads = getBool( "disable_log_reads" );
vars->data_start = getAddr( "data_start" );
vars->data_end = getAddr( "data_end" );
vars->data_ignore = getArray( "data_ignore" );
vars->data_add = getArray( "data_add" );
vars->image_name = getString( "image_name" );
vars->hook_functions = getBool( "hook_functions" );
vars->stop_log_on_exec = getAddr( "stop_log_on_exec" );
vars->start_log_on_exec = getAddr( "start_log_on_exec" );
if (vars->start_log_on_exec != NULL)
{
vars->logging = false;
}
else
{
vars->logging = true;
}
}
bool NinkoConfig::fieldExists(const std::string fieldName)
{
if (!m_doc.HasMember(fieldName.c_str()))
{
return false;
}
return true;
}
std::string NinkoConfig::getString(const std::string fieldName)
{
if (fieldExists(fieldName) && m_doc[fieldName.c_str()].IsString())
{
return m_doc[fieldName.c_str()].GetString();
}
cerr << "Invalid string specified for " << fieldName << endl;
return NULL;
}
ADDRINT NinkoConfig::getAddr(const std::string fieldName)
{
if(fieldExists(fieldName) && m_doc[fieldName.c_str()].IsUint())
{
return static_cast<ADDRINT>(m_doc[fieldName.c_str()].GetUint());
}
else if (fieldExists(fieldName) && m_doc[fieldName.c_str()].IsUint64())
{
return static_cast<ADDRINT>(m_doc[fieldName.c_str()].GetUint64());
}
cerr << "Invalid address specified for " << fieldName << endl;
return NULL;
}
rapidjson::Value* NinkoConfig::getArray(const std::string fieldName)
{
if(!fieldExists(fieldName) || !m_doc[fieldName.c_str()].IsArray())
{
cerr << "Invalid type, expected an array for " << fieldName << endl;
return NULL;
}
return &m_doc[fieldName.c_str()];
}
/* Defaults to false.
*/
bool NinkoConfig::getBool(const std::string fieldName)
{
if(!fieldExists(fieldName) || !m_doc[fieldName.c_str()].IsBool())
{
return false;
}
return m_doc[fieldName.c_str()].GetBool();
}