Threader fix

This commit is contained in:
cora48 2015-04-02 15:18:42 +03:00
parent 391099eadc
commit f09e6e28b7
3 changed files with 47 additions and 58 deletions

View File

@ -8,7 +8,6 @@ std::queue<std::string> Threader::ipQueue;
void Threader::fireThread(std::string ip, void *func(void)) { void Threader::fireThread(std::string ip, void *func(void)) {
std::unique_lock<std::mutex> lk(m);
ipQueue.push(ip); ipQueue.push(ip);
if(threadId < gThreads) { if(threadId < gThreads) {
@ -18,7 +17,7 @@ void Threader::fireThread(std::string ip, void *func(void)) {
} }
ready = true; ready = true;
Threader::cv.notify_one(); cv.notify_one();
Sleep(gThreadDelay); Sleep(gThreadDelay);
} }

View File

@ -188,31 +188,28 @@ char *GetCodePage(const char *str)
int globalSearchNeg(const char *buffcpy, const char *ip, int port) int globalSearchNeg(const char *buffcpy, const char *ip, int port)
{ {
char negWord[256] = {0}; QTextCodec *nCodec = QTextCodec::codecForName("Windows-1251");
for(int i = 0; i < GlobalNegativeSize; ++i) for(int i = 0; i < GlobalNegativeSize; ++i)
{ {
FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready;}); FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready;});
if(!globalScanFlag) return -1; if(!globalScanFlag) return -1;
strcpy(negWord, GlobalNegatives[i]); if(strstr(buffcpy, GlobalNegatives[i]) != NULL)
if(strstr(buffcpy, negWord) != NULL)
{ {
if(gNegDebugMode) if(gNegDebugMode)
{ {
QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
QString neg = codec->toUnicode(negWord);
stt->doEmitionDebugFoundData("[<a href=\"http://" + QString(ip) + ":" + QString::number(port) + stt->doEmitionDebugFoundData("[<a href=\"http://" + QString(ip) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(ip) + ":" + QString::number(port) + "/\"><font color=\"#0084ff\">" + QString(ip) + ":" + QString::number(port) +
"</font></a>" + "]\tNegative hit: \"" + neg.toHtmlEscaped() + "\""); "</font></a>" + "]\tNegative hit: \"" + nCodec->toUnicode(GlobalNegatives[i]).toHtmlEscaped() + "\"");
if(strlen(negWord) < 2) if(strlen(GlobalNegatives[i]) < 2)
{ {
stt->doEmitionDebugFoundData(" Len:" + QString::number(strlen(negWord))); stt->doEmitionDebugFoundData(" Len:" + QString::number(strlen(GlobalNegatives[i])));
}; };
if(strcmp(negWord, "") == 0) if(strcmp(GlobalNegatives[i], "") == 0)
{ {
stt->doEmitionDebugFoundData("Empty hit!"); stt->doEmitionDebugFoundData("Empty hit!");
}; };
if(strcmp(negWord, " ") == 0) if(strcmp(GlobalNegatives[i], " ") == 0)
{ {
stt->doEmitionDebugFoundData("Space hit!"); stt->doEmitionDebugFoundData("Space hit!");
}; };
@ -221,8 +218,6 @@ int globalSearchNeg(const char *buffcpy, const char *ip, int port)
++Filt; ++Filt;
return -1; return -1;
}; };
ZeroMemory(negWord, 256);
}; };
} }

View File

@ -171,39 +171,6 @@ QString GetNSErrorDefinition(const char *str, const char *elem)
else return QString("No definition found!"); else return QString("No definition found!");
} }
void ConInc()
{
++ipCounter;
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock inc cons;
};
#else
asm("lock; incl cons");
#endif
stt->doEmitionThreads(QString::number(cons) + "/" + QString::number(gThreads));
}
void ConDec()
{
if(cons > 0)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock dec cons;
};
#else
asm("lock; decl cons");
#endif
};
stt->doEmitionThreads(QString::number(cons) + "/" + QString::number(gThreads));
}
void _SaveBackupToFile() void _SaveBackupToFile()
{ {
char saveStr[512] = {0}; char saveStr[512] = {0};
@ -384,6 +351,7 @@ void _timer() {
ZeroMemory(timeLeft, sizeof(timeLeft)); ZeroMemory(timeLeft, sizeof(timeLeft));
ZeroMemory(dbuffer, sizeof(dbuffer)); ZeroMemory(dbuffer, sizeof(dbuffer));
Sleep(1000); Sleep(1000);
}; };
} }
@ -1626,6 +1594,38 @@ int _getChunkCount(char *data) {
return secondPos - firstPos + 1; return secondPos - firstPos + 1;
} }
void ConInc()
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock inc cons;
};
#else
asm("lock; incl cons");
#endif
stt->doEmitionThreads(QString::number(cons) + "/" +
QString::number(gThreads));
}
void ConDec()
{
if(cons > 0)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock dec cons;
};
#else
asm("lock; decl cons");
#endif
};
stt->doEmitionThreads(QString::number(cons) + "/" +
QString::number(gThreads));
}
void _connect() { void _connect() {
std::string ip = ""; std::string ip = "";
@ -1637,6 +1637,7 @@ void _connect() {
--Threader::threadId; --Threader::threadId;
Threader::ready = false; Threader::ready = false;
lk.unlock(); lk.unlock();
Threader::cv.notify_one();
return; return;
} }
@ -1645,7 +1646,9 @@ void _connect() {
Threader::ipQueue.pop(); Threader::ipQueue.pop();
Threader::ready = false; Threader::ready = false;
lk.unlock(); lk.unlock();
Threader::cv.notify_one();
++ipCounter;
ConInc(); ConInc();
for (int i = 0; i <= overallPorts; ++i) for (int i = 0; i <= overallPorts; ++i)
{ {
@ -1745,14 +1748,6 @@ void runAuxiliaryThreads() {
} }
int startScan(char* args) { int startScan(char* args) {
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);