-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGREWIA.cpp
More file actions
73 lines (70 loc) · 2.79 KB
/
Copy pathGREWIA.cpp
File metadata and controls
73 lines (70 loc) · 2.79 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
#include <iostream>
#include <fstream>
#include <locale>
#include <codecvt>
#include <unistd.h>
#include "Solver/solver_kind.h"
#include "Parser/parser.h"
#include "Solver/DetectAmbiguity_WithLookAround/DetectAmbiguity.h"
int main(int argc, char* argv[]){
if (argc != 7){
std::cout << "parameter error" << std::endl;
std::cout << "Usage: ./GREWIA [RegexFile] [OutputDirectory] [AttackStringLength] [SimplifiedModeOn] [DecrementalOn] [MatchingFunction]" << std::endl;
std::cout << "[RegexFile]: Path of a file which contain a regex." << std::endl;
std::cout << "[OutputDirectory]: Path of a directory where the candidate attack string will be write to." << std::endl;
std::cout << "[AttackStringLength] is MaxLength of candidate attack string" << std::endl;
std::cout << "[SimplifiedModeOn]: Set to 1 indicate letting GREWIA generate a attack strings; Set to 0 indicate letting GREWIA generate a series of attack strings." << std::endl;
std::cout << "[DecrementalOn]: Set to 1 indicate Decremental method is on and vice verse." << std::endl;
std::cout << "[MatchingFunction]: Set to 1 indicate targeting to partialmatch; Set to 0 indicate targeting to fullmatch." << std::endl;
return 0;
}
std::ifstream infile;
infile.open(argv[1], std::ios::binary);
std::string line;
bool Ret = true;
std::vector<std::wstring> Regex_list;
wchar_t c;
while (getline(infile, line))
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring unicodeStr = converter.from_bytes(line);
c = unicodeStr.back();
if (c == '\r'){
unicodeStr.pop_back();
}
if (unicodeStr[0] == '/'){
for (int j = unicodeStr.length()-1; j > 1; j--){
if (unicodeStr[j] == '/' ){
unicodeStr.erase(j, unicodeStr.length());
unicodeStr.erase(0, 1);
break;
}
}
}
if (std::stoi(argv[6]) == 1){
int i = 0;
while (unicodeStr[i] == '(')
i++;
if (unicodeStr[i] != '^'){
unicodeStr.insert(0, L".*(");
unicodeStr.insert(unicodeStr.size(), L")");
}
}
Regex_list.emplace_back(unicodeStr);
std::vector<solverbin::REnodeClass> ReList;
std::wcout.sync_with_stdio(true);
for (auto str : Regex_list){
if (solverbin::debug.PrintRegexString) std::wcout << L"Regex: " << str << std::endl;
auto ren = solverbin::Parer(str, true);
ReList.emplace_back(ren.Re);
auto kk = solverbin::DetectABTNFA_Lookaround(ren.Re, std::stoi(argv[3]), argv[2], std::stoi(argv[4]), std::stoi(argv[5]), std::stoi(argv[6]), 0);
auto k1 = kk.IsABT(kk.SSBegin);
if (k1){
std::cout << "prefix: " << kk.InterStr << std::endl;
std::cout << "infix: " << kk.WitnessStr << std::endl;
}
else
std::cout << "false" << std::endl;
}
}
}