forked from AmrThabet/pySRDF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic.cpp
84 lines (67 loc) · 1.75 KB
/
static.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
// static.cpp : includes all static search and check like yara scanner, ssdeep and md5
//
#include "stdafx.h"
#include "pySRDF.h"
YaraScanner::YaraScanner()
{
YaraScan = new cYaraScanner();
}
void YaraScanner::AddRule(char* Name, char* Rule)
{
cString Signature = Rule;
Signature.Replace(':',' ');
cString NewRule = YaraScan->CreateRule(Name,Signature);
YaraScan->AddRule(NewRule);
}
array<YARA_SEARCH*> YaraScanner::Search(char* buff, DWORD size)
{
unsigned char* Address = (unsigned char*)buff;
array<YARA_SEARCH*> found;
found.init(sizeof(YARA_SEARCH));
if (Address == NULL)return found;
cList* Results = YaraScan->Scan(Address,size);
if (Results == NULL)return found;
for (int i = 0; i < Results->GetNumberOfItems();i++)
{
_YARA_RESULT* Result = (_YARA_RESULT*)Results->GetItem(i);
for (int l = 0; l < Result->Matches->GetNumberOfItems();l++)
{
YARA_SEARCH item = {0};
MSTRING* Match = (MSTRING*)Result->Matches->GetItem(l);
//cout << "FOUND RULE: " << Result->RuleIdentifier << "\t" << (int*)(Match->offset) << "\n";
item.Offset = Match->offset;
item.Name = Result->RuleIdentifier;
found.additem(&item);
}
}
return found;
}
YaraScanner::~YaraScanner()
{
delete YaraScan;
}
//===================
//SSDeep
char* ssdeep(char* buff, DWORD size)
{
SSDeep ssdeep;
if (size == 0)size = strlen(buff);
cString r = ssdeep.Hash((const unsigned char *)buff,size);
char* s = (char*)malloc(r.GetLength());
memcpy(s,r.GetChar(),r.GetLength());
return s;
}
DWORD ssdeepcompare(char* sig1, char* sig2)
{
SSDeep ssdeep;
return ssdeep.Compare(sig1,sig2);
}
//===================
//MD5
char* md5(char* buff,DWORD size)
{
if (size == 0)size = strlen(buff);
cMD5String* md5 = new cMD5String();
md5->Encrypt(buff,size);
return *md5;
}