-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
102 lines (85 loc) · 1.66 KB
/
main.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
#include <map>
#include <deque>
#include <fstream>
#include <iostream>
#include <openssl/md5.h>
using namespace std;
struct Signature
{
__int128 hash;
string name;
};
map <size_t, deque <Signature>> signs;
bool loadSignatures()
{
fstream file("main.mdb", ios::in);
if(!file.good())
{
cout<<"Unable to open file: main.mdb"<<endl;
return false;
}
while(1)
{
string str[3];
getline(file, str[0], ':');
getline(file, str[1], ':');
getline(file, str[2]);
if(file.eof())
break;
__int128 ret = 0;
for(int n = str[1].size()-1; n >= 0; n--)
{
if(n % 2 != 0)
swap(str[1][n], str[1][n-1]);
if(str[1][n] >= '0' && str[1][n] <= '9')
ret = (ret<<4)+(str[1][n] - 48);
else if(str[1][n] >= 'a' && str[1][n] <= 'f')
ret = (ret<<4)+(str[1][n] - 87);
}
signs[stoul(str[0])].push_back({ret, str[2]});
}
file.close();
return true;
}
int main(int argc, char** argv)
{
if(argc != 2)
{
cout<<"Syntax: "<<argv[0]<<" [file]"<<endl;
return 1;
}
if(!loadSignatures())
return 2;
fstream file;
file.open(argv[1], ios::in);
if(!file.good())
{
cout<<"Unable to open file: "<<argv[1]<<endl;
return 3;
}
file.seekg(0, file.end);
size_t size = file.tellg();
file.seekg (0, file.beg);
char *buf = new char[size];
file.read(buf, size);
file.close();
string found = "";
for(auto const& s : signs)
{
#pragma omp parallel for
for(size_t n = 0; n < size-s.first; n++)
{
__int128 result;
MD5((const unsigned char*)&buf[n], s.first, (unsigned char*)&result);
for(auto ss : s.second)
if(result == ss.hash)
found = ss.name;
}
if(found != "")
{
cout<<"Found "<<found<<endl;
return 0;
}
}
return 0;
}