nesca/FileUpdater.cpp

336 lines
9.1 KiB
C++
Raw Normal View History

2015-03-24 14:29:27 +00:00
#include "FileUpdater.h"
2015-03-28 05:30:41 +00:00
#include "externFunctions.h"
2015-03-25 14:29:08 +00:00
#include "STh.h"
#include "mainResources.h"
2015-03-24 14:29:27 +00:00
2015-04-01 19:23:52 +00:00
bool FileUpdater::running = false;
2015-03-24 14:29:27 +00:00
long FileUpdater::oldNegLstSize = 0;
long FileUpdater::oldLoginLstSize = 0;
long FileUpdater::oldPassLstSize = 0;
long FileUpdater::oldSSHLstSize = 0;
long FileUpdater::oldWFLoginLstSize = 0;
long FileUpdater::oldWFPassLstSize = 0;
int FileUpdater::gNegativeSize = 0;
2015-03-25 14:29:08 +00:00
std::mutex FileUpdater::filesUpdatingMutex;
std::condition_variable FileUpdater::cv;
bool FileUpdater::ready = false;
std::unique_lock<std::mutex> FileUpdater::lk;
std::vector<std::string> FileUpdater::negativeVector;
2015-03-25 14:29:08 +00:00
void negativeLoader() {
std::ifstream file("negatives.txt");
std::string line;
2015-03-25 14:29:08 +00:00
while (std::getline(file, line)) FileUpdater::negativeVector.push_back(line);
2015-03-25 14:29:08 +00:00
}
2015-03-28 05:30:41 +00:00
void updateNegatives() {
FileUpdater::negativeVector.clear();
2015-03-24 14:29:27 +00:00
negativeLoader();
}
2015-03-28 05:30:41 +00:00
void updateLogin() {
2015-03-24 14:29:27 +00:00
if(loginLst != NULL)
{
for(int i = 0; i < MaxLogin; ++i) delete []loginLst[i];
delete []loginLst;
loginLst = NULL;
};
MaxLogin = 0;
char buffFG[32] = {0};
FILE *loginList = fopen("login.txt", "r");
if(loginList != NULL)
{
while(fgets(buffFG, 32, loginList) != NULL)
{
MaxLogin++;
ZeroMemory(buffFG, sizeof(buffFG));
};
rewind(loginList);
loginLst = new char*[MaxLogin];
for(int j = 0; j < MaxLogin; j++)
{
loginLst[j] = new char[32];
};
int i = 0;
while(fgets(buffFG, 32, loginList) != NULL)
{
memset(loginLst[i], 0, strlen(buffFG) + 1);
if(strstr(buffFG, "\n") != NULL) strncat(loginLst[i++], buffFG, strlen(buffFG) - 1);
else strncat(loginLst[i++], buffFG, strlen(buffFG));
ZeroMemory(buffFG, sizeof(buffFG));
};
2015-03-27 14:12:58 +00:00
if(FileUpdater::oldLoginLstSize == 0) stt->doEmitionGreenFoundData("Login list loaded (" + QString::number(MaxLogin) + " entries)");
else stt->doEmitionFoundData("<font color=\"Pink\">Login list updated (" + QString::number(MaxLogin) + " entries)</font>");
2015-03-24 14:29:27 +00:00
fclose(loginList);
}
else
{
stt->doEmitionRedFoundData("No login list found");
stt->doEmitionKillSttThread();
};
}
2015-03-28 05:30:41 +00:00
void updatePass() {
2015-03-24 14:29:27 +00:00
if(passLst != NULL)
{
for(int i = 0; i < MaxPass; ++i) delete []passLst[i];
delete []passLst;
passLst = NULL;
};
MaxPass = 0;
char buffFG[32] = {0};
FILE *passList = fopen("pass.txt", "r");
if(passList != NULL)
{
while(fgets(buffFG, 32, passList) != NULL)
{
MaxPass++;
ZeroMemory(buffFG, sizeof(buffFG));
};
rewind(passList);
passLst = new char*[MaxPass];
for(int j = 0; j < MaxPass; j++)
{
passLst[j] = new char[32];
};
int i = 0;
while(fgets(buffFG, 32, passList) != NULL)
{
memset(passLst[i], 0, strlen(buffFG) + 1);
if(strstr(buffFG, "\n") != NULL) strncat(passLst[i++], buffFG, strlen(buffFG) - 1);
else strncat(passLst[i++], buffFG, strlen(buffFG));
ZeroMemory(buffFG, sizeof(buffFG));
};
2015-03-27 14:12:58 +00:00
if(FileUpdater::oldPassLstSize == 0) stt->doEmitionGreenFoundData("Password list loaded (" + QString::number(MaxPass) + " entries)");
else stt->doEmitionFoundData("<font color=\"Pink\">Password list updated (" + QString::number(MaxPass) + " entries)</font>");
2015-03-24 14:29:27 +00:00
fclose(passList);
}
else
{
stt->doEmitionRedFoundData("No password list found");
stt->doEmitionKillSttThread();
};
}
2015-03-28 05:30:41 +00:00
void updateSSH() {
2015-03-24 14:29:27 +00:00
if(sshlpLst != NULL)
{
for(int i = 0; i < MaxSSHPass; ++i) delete []sshlpLst[i];
delete []sshlpLst;
sshlpLst = NULL;
};
MaxSSHPass = 0;
2015-03-25 14:29:08 +00:00
char buffFG[32] = {0};
2015-03-24 14:29:27 +00:00
ZeroMemory(buffFG, sizeof(buffFG));
2015-03-25 14:29:08 +00:00
FILE *sshlpList = fopen("sshpass.txt", "r");
2015-03-24 14:29:27 +00:00
if(sshlpList != NULL)
{
while(fgets(buffFG, 32, sshlpList) != NULL)
{
++MaxSSHPass;
ZeroMemory(buffFG, sizeof(buffFG));
};
rewind(sshlpList);
sshlpLst = new char*[MaxSSHPass];
for(int j = 0; j < MaxSSHPass; j++)
{
sshlpLst[j] = new char[32];
};
int i = 0;
while(fgets(buffFG, 32, sshlpList) != NULL)
{
memset(sshlpLst[i], 0, strlen(buffFG) + 1);
if(strstr(buffFG, "\n") != NULL) strncat(sshlpLst[i++], buffFG, strlen(buffFG) - 1);
else strncat(sshlpLst[i++], buffFG, strlen(buffFG));
ZeroMemory(buffFG, sizeof(buffFG));
};
2015-03-27 14:12:58 +00:00
if(FileUpdater::oldSSHLstSize == 0) stt->doEmitionGreenFoundData("SSH Password list loaded (" + QString::number(MaxSSHPass) + " entries)");
else stt->doEmitionFoundData("<font color=\"Pink\">SSH list updated (" + QString::number(MaxSSHPass) + " entries)</font>");
2015-03-24 14:29:27 +00:00
fclose(sshlpList);
}
else
{
stt->doEmitionRedFoundData("No password/login list found");
stt->doEmitionKillSttThread();
};
}
2015-03-28 05:30:41 +00:00
void updateWFLogin() {
2015-03-24 14:29:27 +00:00
if(wfLoginLst != NULL)
{
for(int i = 0; i < MaxWFLogin; ++i) delete []wfLoginLst[i];
delete []wfLoginLst;
wfLoginLst = NULL;
};
MaxWFLogin = 0;
2015-03-25 14:29:08 +00:00
char buffFG[32] = {0};
2015-03-24 14:29:27 +00:00
ZeroMemory(buffFG, sizeof(buffFG));
2015-03-25 14:29:08 +00:00
FILE *wfLoginList = fopen("wflogin.txt", "r");
2015-03-24 14:29:27 +00:00
if(wfLoginList != NULL)
{
while(fgets(buffFG, 32, wfLoginList) != NULL)
{
MaxWFLogin++;
ZeroMemory(buffFG, sizeof(buffFG));
};
rewind(wfLoginList);
wfLoginLst = new char*[MaxWFLogin];
for(int j = 0; j < MaxWFLogin; j++)
{
wfLoginLst[j] = new char[32];
};
int i = 0;
while(fgets(buffFG, 32, wfLoginList) != NULL)
{
memset(wfLoginLst[i], 0, strlen(buffFG) + 1);
if(strstr(buffFG, "\n") != NULL) strncat(wfLoginLst[i++], buffFG, strlen(buffFG) - 1);
else strncat(wfLoginLst[i++], buffFG, strlen(buffFG));
ZeroMemory(buffFG, sizeof(buffFG));
};
2015-03-27 14:12:58 +00:00
if(FileUpdater::oldWFLoginLstSize == 0) stt->doEmitionGreenFoundData("WFLogin list loaded (" + QString::number(MaxWFLogin) + " entries)");
else stt->doEmitionFoundData("<font color=\"Pink\">WFLogin list updated (" + QString::number(MaxWFLogin) + " entries)</font>");
2015-03-24 14:29:27 +00:00
fclose(wfLoginList);
}
}
2015-03-28 05:30:41 +00:00
void updateWFPass() {
2015-03-24 14:29:27 +00:00
if(wfPassLst != NULL)
{
for(int i = 0; i < MaxWFPass; ++i) delete []wfPassLst[i];
delete []wfPassLst;
wfPassLst = NULL;
};
MaxWFPass = 0;
2015-03-25 14:29:08 +00:00
char buffFG[32] = {0};
2015-03-24 14:29:27 +00:00
ZeroMemory(buffFG, sizeof(buffFG));
2015-03-25 14:29:08 +00:00
FILE *wfPassList = fopen("wfpass.txt", "r");
2015-03-24 14:29:27 +00:00
if(wfPassList != NULL)
{
while(fgets(buffFG, 32, wfPassList) != NULL)
{
MaxWFPass++;
ZeroMemory(buffFG, sizeof(buffFG));
};
rewind(wfPassList);
wfPassLst = new char*[MaxWFPass];
for(int j = 0; j < MaxWFPass; j++)
{
wfPassLst[j] = new char[32];
};
int i = 0;
while(fgets(buffFG, 32, wfPassList) != NULL)
{
memset(wfPassLst[i], 0, strlen(buffFG) + 1);
if(strstr(buffFG, "\n") != NULL) strncat(wfPassLst[i++], buffFG, strlen(buffFG) - 1);
else strncat(wfPassLst[i++], buffFG, strlen(buffFG));
ZeroMemory(buffFG, sizeof(buffFG));
};
2015-03-27 14:12:58 +00:00
if(FileUpdater::oldWFPassLstSize == 0) stt->doEmitionGreenFoundData("WFPassword list loaded (" + QString::number(MaxWFPass) + " entries)");
else stt->doEmitionFoundData("<font color=\"Pink\">WFPassword list updated (" + QString::number(MaxWFPass) + " entries)</font>");
2015-03-24 14:29:27 +00:00
fclose(wfPassList);
}
}
long getFileSize(const char *fileName) {
std::ifstream in(fileName, std::ifstream::ate | std::ifstream::binary);
return in.tellg();
}
2015-03-25 14:29:08 +00:00
void updateList(const char *fileName, long *szPtr, void *funcPtr(void)) {
2015-03-24 14:29:27 +00:00
long sz = getFileSize(fileName);
2015-03-25 14:29:08 +00:00
if(sz != *szPtr) {
FileUpdater::lk = std::unique_lock<std::mutex> (FileUpdater::filesUpdatingMutex);
funcPtr();
2015-03-27 14:12:58 +00:00
*szPtr = sz;
2015-03-25 14:29:08 +00:00
FileUpdater::lk.unlock();
FileUpdater::ready = true;
FileUpdater::cv.notify_one();
2015-03-24 14:29:27 +00:00
}
}
2015-03-28 05:30:41 +00:00
void FileUpdater::updateLists() {
2015-04-01 19:23:52 +00:00
running = true;
2015-03-24 14:29:27 +00:00
while(globalScanFlag) {
2015-04-02 10:32:26 +00:00
Sleep(600000);
2015-03-27 13:38:53 +00:00
if(!globalScanFlag) break;
loadOnce();
2015-03-24 14:29:27 +00:00
}
2015-04-01 19:23:52 +00:00
running = false;
2015-03-24 14:29:27 +00:00
}
2015-03-27 13:38:53 +00:00
2015-03-28 05:30:41 +00:00
void FileUpdater::loadOnce() {
updateList("negatives.txt", &oldNegLstSize, (void*(*)(void))updateNegatives);
updateList("login.txt", &oldLoginLstSize, (void*(*)(void))updateLogin);
updateList("pass.txt", &oldPassLstSize, (void*(*)(void))updatePass);
updateList("sshpass.txt", &oldSSHLstSize, (void*(*)(void))updateSSH);
updateList("wflogin.txt", &oldWFLoginLstSize, (void*(*)(void))updateWFLogin);
updateList("wfpass.txt", &oldWFPassLstSize, (void*(*)(void))updateWFPass);
2015-03-27 13:38:53 +00:00
}
void FileUpdater::FUClear() {
2015-04-02 10:26:32 +00:00
running = false;
2015-03-27 13:38:53 +00:00
oldNegLstSize = 0;
oldLoginLstSize = 0;
oldPassLstSize = 0;
oldSSHLstSize = 0;
oldWFLoginLstSize = 0;
oldWFPassLstSize = 0;
}