-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathSettings.h
More file actions
236 lines (203 loc) · 6.99 KB
/
Settings.h
File metadata and controls
236 lines (203 loc) · 6.99 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#pragma once
#include <iostream>
#include <string>
#include <map>
#include <set>
#include "FuncWatch.h"
#include "EvasionWatch.h"
typedef enum {
SHELLC_DO_NOT_FOLLOW = 0, // trace only the main target module
SHELLC_FOLLOW_FIRST = 1, // follow only the first shellcode called from the main module
SHELLC_FOLLOW_RECURSIVE = 2, // follow also the shellcodes called recursively from the the original shellcode
SHELLC_FOLLOW_ANY = 3, // follow any shellcodes
SHELLC_OPTIONS_COUNT
} t_shellc_options;
t_shellc_options ConvertShcOption(unsigned int value);
//---
class SyscallsTable {
public:
static bool isSyscallFuncName(const std::string &name)
{
if (name.length() < 2) return false;
if ((name[0] == 'Z' && name[1] == 'w') ||
(name[0] == 'N' && name[1] == 't' && name[2] >= 'A' && name[2] <= 'Z'))
{
return true;
}
return false;
}
static bool isSyscallDll(const std::string& dllName)
{
if (util::iequals("ntdll", dllName)
|| util::iequals("win32u", dllName))
{
return true;
}
return false;
}
static std::string convertNameToNt(std::string funcName)
{
std::string prefix1("Nt");
std::string prefix2("Zw");
if (!funcName.compare(0, prefix2.size(), prefix2)) {
funcName.replace(0, 2, prefix1); // replace with Nt prefix
}
return funcName;
}
size_t load(const std::string& file);
std::string getName(int syscallID);
size_t count() { return syscallToFuncName.size(); }
protected:
std::map<int, std::string> syscallToFuncName;
};
//---
struct StopOffset
{
ADDRINT rva;
size_t times;
StopOffset(ADDRINT _rva = 0, size_t _times = 0)
: rva(_rva), times(_times)
{
}
StopOffset(const StopOffset& other)
{
this->rva = other.rva;
this->times = other.times;
}
StopOffset& operator=(const StopOffset& other)
{
this->rva = other.rva;
this->times = other.times;
return *this;
}
bool load(const std::string& sline, char delimiter);
bool operator<(const StopOffset& other) const
{
return (this->rva < other.rva);
}
};
//---
struct DisasmRange
{
ADDRINT start;
ADDRINT stop;
std::string label;
DisasmRange(ADDRINT _start, ADDRINT _stop, const std::string& _label="")
: start(_start), stop(_stop), label(_label)
{
}
bool isInRange(const ADDRINT& addr) const
{
if (addr == start || addr == stop) return true;
return (addr >= start && addr <= stop) ? true : false;
}
DisasmRange& operator=(const DisasmRange& n)
{
this->start = n.start;
this->stop = n.stop;
this->label = n.label;
return *this;
}
bool operator<(const DisasmRange& n) const
{
return start < n.start;
}
};
typedef enum disasm_status {
DISASM_NONE = 0,
DISASM_START = 1,
DISASM_IN_RANGE = 2,
DISASM_STOP = 3,
COUNT_DISASM_STATUS
} t_disasm_status;
typedef enum {
DISASM_DISABLED = 0,
DISASM_OUTER = 1,
DISASM_INNER = 2,
DISASM_FOLLOW_THREADS = 3,
DISASM_OPTIONS_COUNT
} t_disasm_level;
class Settings {
public:
static void stripComments(std::string& str);
static size_t loadOffsetsList(const char* filename, std::set<StopOffset>& offsetsList);
static size_t loadCustomDefs(const char* filename, std::map<ADDRINT, std::string> &customDefs);
static size_t loadDisasmRanges(const char* filename, std::set<DisasmRange> &disasmRanges);
Settings()
: followShellcode(SHELLC_FOLLOW_FIRST),
followChildprocesses(false),
traceRDTSC(false),
traceINT(false),
traceSYSCALL(true),
logSectTrans(true),
logShelcTrans(true),
shortLogging(true),
logIndirect(false),
hexdumpSize(8),
hookSleep(false),
parseExports(false),
sleepTime(0),
stopOffsetTime(30),
antidebug(WATCH_DISABLED),
antivm(WATCH_DISABLED),
useDebugSym(false),
isHyperVSet(false),
emulateSingleStep(true),
disasmCtx(false), disasmDepth(DISASM_INNER),
logReturn(false), followArgReturn(false),
volumeID(0)
{
}
bool loadINI(const std::string &filename);
bool saveINI(const std::string &filename);
size_t loadExcluded(const char* excludedList);
t_shellc_options followShellcode;
const t_disasm_status findInDisasmRange(const ADDRINT& addr, std::string* rangeLabel = nullptr)
{
for (auto itr = this->disasmRanges.begin(); itr != disasmRanges.end(); ++itr) {
if (itr->isInRange(addr)) {
if (rangeLabel) {
(*rangeLabel) = itr->label;
}
if (itr->start == addr) {
return DISASM_START;
}
if (itr->stop == addr) {
return DISASM_STOP;
}
return DISASM_IN_RANGE;
}
}
return DISASM_NONE;
}
bool followChildprocesses; // Follow Child Processes
bool traceRDTSC; // Trace RDTSC
bool traceINT; // trace INT
bool traceSYSCALL; // Trace syscall instructions (i.e., syscall, int 2Eh, sysenter)
bool logSectTrans; // watch transitions between sections
bool logShelcTrans; // watch transitions between shellcodes
bool shortLogging; // Use short call logging (without a full DLL path)
bool logIndirect;
size_t hexdumpSize;
bool hookSleep;
bool parseExports;
size_t sleepTime; // Define the time that will be passed to the hooked sleep function (in miliseconds)
size_t stopOffsetTime; // Sleep time at the stop offset (in seconds)
t_watch_level antidebug; // Trace Anti-VM techniques, and bypasses some of them
t_watch_level antivm; // Trace Anti-VM techniques, and bypasses some of them
bool useDebugSym;
bool isHyperVSet; // emulate HyperV via CPUID (it changes execution path of some protectors, i.e. VMProtect). Works when antivm is enabled.
bool emulateSingleStep; // If the Trap Flag is set, throw a SINGLE_STEP exception emulating the typical behavior. Works when antidebug is enabled.
bool disasmCtx; // show context in a disasm mode
t_disasm_level disasmDepth; //in disasm mode: define how to follow the disasm range
bool logReturn; // Log return value
bool followArgReturn; // Log changes of args and returns ptr
uint32_t volumeID;
SyscallsTable syscallsTable; //Syscalls table: mapping the syscall ID to the function name
FuncWatchList funcWatch; //List of functions, arguments of which are going to be logged
FuncList<WFuncInfo> excludedFuncs; //List of functions that will NOT be logged
std::set<std::string> excludedDll; //List of DLLs calls from which will NOT be logged
std::set<StopOffset> stopOffsets; //List of offsets at which the execution should pause
std::map<ADDRINT, std::string> customDefs;
std::set<DisasmRange> disasmRanges;
};