-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathanalyzerNgram.cpp
More file actions
46 lines (38 loc) · 792 Bytes
/
analyzerNgram.cpp
File metadata and controls
46 lines (38 loc) · 792 Bytes
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
#include "analyzerNgram.h"
#define THRESHOLD 0.5
namespace detect_similar
{
AnalyzerNgram::AnalyzerNgram()
: Analyzer()
{
_className = "AnalyzerNgram";
}
AnalyzerNgram::AnalyzerNgram(const unsigned char* data, uint size)
: Analyzer(data, size)
{
_className = "AnalyzerNgram";
}
string AnalyzerNgram::analyze()
{
float max_coef = 0;
int max_ans = 0, ind_max = 0;
for (unsigned int i = 0; i < _shellcodes.size(); i++)
{
int ans = _data.compareNgram(_shellcodes[i]);
float coef = ans * 1.0 / _shellcodes[i].size;
if (coef > THRESHOLD)
{
if (coef > max_coef)
{
max_coef = coef;
}
if (ans > max_ans)
{
max_ans = ans;
ind_max = i;
}
}
}
return (max_coef <= THRESHOLD) ? string() : _shellcodes[ind_max].name;
}
} //namespace detect_similar