Improving tests

This commit is contained in:
nik012003
2022-06-26 00:56:03 +02:00
committed by DomySh
parent bf3a97e9e0
commit 282438b005
3 changed files with 49 additions and 42 deletions

View File

@@ -5,6 +5,7 @@
#include <csignal>
#include <fstream>
#include <regex>
#include <mutex>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
@@ -13,7 +14,7 @@
#include <boost/asio.hpp>
#include <boost/thread/mutex.hpp>
//#define DEBUG
#define DEBUG
using namespace std;
@@ -38,18 +39,21 @@ unhexlify(InputIterator first, InputIterator last, OutputIterator ascii) {
return 0;
}
vector<pair<string,regex>> regex_s_c_w, regex_c_s_w, regex_s_c_b, regex_c_s_b;
vector<pair<string,regex>> *regex_s_c_w, *regex_c_s_w, *regex_s_c_b, *regex_c_s_b;
const char* config_file;
mutex mtx;
bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pair<string,regex>> const &blacklist, vector<pair<string,regex>> const &whitelist){
#ifdef DEBUG
bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pair<string,regex>> *const blacklist, vector<pair<string,regex>> *const whitelist){
#ifdef DEBUG_PACKET
cout << "---------------- Packet ----------------" << endl;
for(int i=0;i<bytes_transferred;i++){
cout << data[i];
}
cout << "\n" << "---------------- End Packet ----------------" << endl;
#endif
for (pair<string,regex> ele:blacklist){
vector<pair<string,regex>> *bp = blacklist;
for (pair<string,regex> ele:*bp){
cout << "TRYING" << ele.first << endl;
cmatch what;
try{
regex_search(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data)+bytes_transferred, what, ele.second);
@@ -61,7 +65,8 @@ bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pa
cerr << "Error while matching regex: " << ele.first << endl;
}
}
for (pair<string,regex> ele:whitelist){
vector<pair<string,regex>> *wp = whitelist;
for (pair<string,regex> ele:*wp){
cmatch what;
try{
regex_search(reinterpret_cast<const char*>(data),reinterpret_cast<const char*>(data)+bytes_transferred, what, ele.second);
@@ -320,7 +325,8 @@ namespace tcp_proxy
};
}
void push_regex(char* arg, bool case_sensitive, vector<pair<string,regex>> &v){
void push_regex(char* arg, bool case_sensitive, vector<pair<string,regex>> *v){
std::unique_lock<std::mutex> lck(mtx);
size_t expr_len = (strlen(arg)-2)/2;
char expr[expr_len];
unhexlify(arg+2, arg+strlen(arg)-1, expr);
@@ -331,13 +337,13 @@ void push_regex(char* arg, bool case_sensitive, vector<pair<string,regex>> &v){
#ifdef DEBUG
cout << "Added case sensitive regex " << expr_str << endl;
#endif
v.push_back(make_pair(string(arg), regex));
v->push_back(make_pair(string(arg), regex));
} else {
regex regex(expr_str,regex_constants::icase);
#ifdef DEBUG
cout << "Added case insensitive regex " << expr_str << endl;
#endif
v.push_back(make_pair(string(arg), regex));
v->push_back(make_pair(string(arg), regex));
}
} catch(...){
cerr << "Regex " << expr << " was not compiled successfully" << endl;
@@ -352,11 +358,16 @@ void update_regex(){
cerr << "Error: config file couln't be opened" << endl;
exit(1);
}
regex_s_c_w.clear();
regex_c_s_w.clear();
regex_s_c_b.clear();
regex_c_s_b.clear();
/*
regex_s_c_w.reset(new vector<pair<string,regex>>);
regex_c_s_w.reset(new vector<pair<string,regex>>);
regex_s_c_b.reset(new vector<pair<string,regex>>);
regex_c_s_b.reset(new vector<pair<string,regex>>);
*/
regex_s_c_w = new vector<pair<string,regex>>;
regex_c_s_w = new vector<pair<string,regex>>;
regex_s_c_b = new vector<pair<string,regex>>;
regex_c_s_b = new vector<pair<string,regex>>;
string line;
while(getline(fd, line)){

View File

@@ -1,31 +1,29 @@
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930