-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNinkoFilters.cpp
172 lines (161 loc) · 3.76 KB
/
NinkoFilters.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
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
#include "NinkoFilters.h"
ADDRINT IsStartLoggingLoc( ADDRINT ins )
{
if ( ins == g_vars.start_log_on_exec )
{
return 1;
}
return 0;
}
ADDRINT IsStopLoggingLoc( ADDRINT ins )
{
if (ins == g_vars.stop_log_on_exec )
{
return 1;
}
return 0;
}
ADDRINT IsWriteIgnored( ADDRINT ins )
{
return IsIgnored( ins, g_vars.data_ignore );
}
ADDRINT IsCodeIgnored( ADDRINT ins )
{
return IsIgnored( ins, g_vars.code_ignore );
}
/*
* Returns 1 if we should ignore.
* 0 if we should not ignore
*/
ADDRINT IsIgnored( ADDRINT ins, rapidjson::Value *ignore)
{
for (rapidjson::Value::ConstValueIterator itr = ignore->Begin(); itr != ignore->End(); ++itr)
{
if ( itr->IsUint() )
{
if ( ins == static_cast<ADDRINT>(itr->GetUint()) )
{
return 1;
}
}
else if (itr->IsUint64() )
{
if ( ins == static_cast<ADDRINT>(itr->GetUint64()) )
{
return 1;
}
}
}
return 0;
}
/*
* This checks to make sure the instruction is in the range of code we are monitoring.
* Note internal_check is for determining if we need to filter internal calls. In this
* case we don't want to return our code_add values.
* Returns 1 if the instruction is in range
* 0 ins is out of our code range.
*/
ADDRINT IsInstructionInRange( ADDRINT ins, bool internal_check )
{
if ( ins >= g_vars.code_start && ins <= g_vars.code_end )
{
return 1;
}
if ( internal_check == true )
{
return 0;
}
if ( g_vars.code_add != NULL )
{
for (rapidjson::Value::ConstValueIterator itr = g_vars.code_add->Begin(); itr != g_vars.code_add->End(); ++itr)
{
if ( itr->IsUint() )
{
if ( ins == static_cast<ADDRINT>( itr->GetUint()) )
{
return 1;
}
}
else if (itr->IsUint64() )
{
if ( ins == static_cast<ADDRINT>( itr->GetUint64()) )
{
return 1;
}
}
}
}
return 0;
}
ADDRINT IsReadInRange( THREADID threadid, VOID * readAddress )
{
if ( g_vars.data_add != NULL )
{
for (rapidjson::Value::ConstValueIterator itr = g_vars.data_add->Begin(); itr != g_vars.data_add->End(); ++itr)
{
if ( itr->IsUint() )
{
if ( (ADDRINT)readAddress == static_cast<ADDRINT>(itr->GetUint()) )
{
return 1;
}
}
else if (itr->IsUint64() )
{
if ( (ADDRINT)readAddress == static_cast<ADDRINT>(itr->GetUint64()) )
{
return 1;
}
}
}
}
if( (ADDRINT)readAddress >= g_vars.data_start && (ADDRINT)readAddress <= g_vars.data_end )
{
return 1;
}
return 0;
}
/*
* This checks to make sure the address that will be written is in the range of data we are monitoring.
* Returns 1 if the write address is in the range (i.e. we want to ignore the write)
* 0 the write address is outside of the range we care about.
*/
ADDRINT IsWriteInRange( THREADID threadid, VOID * writeAddress )
{
if ( g_vars.data_add != NULL )
{
for (rapidjson::Value::ConstValueIterator itr = g_vars.data_add->Begin(); itr != g_vars.data_add->End(); ++itr)
{
if ( itr->IsUint() )
{
if ( (ADDRINT)writeAddress == static_cast<ADDRINT>(itr->GetUint()) )
{
CaptureWriteEa( threadid, writeAddress );
return 1;
}
}
else if (itr->IsUint64() )
{
if ( (ADDRINT)writeAddress == static_cast<ADDRINT>(itr->GetUint64()) )
{
CaptureWriteEa( threadid, writeAddress );
return 1;
}
}
}
}
if ( ( !IsWriteIgnored((ADDRINT)writeAddress ) ) && ( (ADDRINT)writeAddress >= g_vars.data_start && (ADDRINT)writeAddress <= g_vars.data_end ) )
{
CaptureWriteEa( threadid, writeAddress );
return 1;
}
return 0;
}
/*
* This checks to see if the target for the call is contained in our code monitoring range.
* You would want to use this if you don't care about calls that occur inside of obfuscated code.
*/
ADDRINT IsCallInternal( ADDRINT callAddress )
{
return !IsInstructionInRange( callAddress, true );
}