From f09e6e28b7644227e6b180a80233eff8038e960e Mon Sep 17 00:00:00 2001 From: cora48 Date: Thu, 2 Apr 2015 15:18:42 +0300 Subject: [PATCH] Threader fix --- Threader.cpp | 3 +- finder.cpp | 23 +++++-------- nesca_startModule.cpp | 79 ++++++++++++++++++++----------------------- 3 files changed, 47 insertions(+), 58 deletions(-) diff --git a/Threader.cpp b/Threader.cpp index 317f00b..52acc10 100644 --- a/Threader.cpp +++ b/Threader.cpp @@ -8,7 +8,6 @@ std::queue Threader::ipQueue; void Threader::fireThread(std::string ip, void *func(void)) { - std::unique_lock lk(m); ipQueue.push(ip); if(threadId < gThreads) { @@ -18,7 +17,7 @@ void Threader::fireThread(std::string ip, void *func(void)) { } ready = true; - Threader::cv.notify_one(); + cv.notify_one(); Sleep(gThreadDelay); } diff --git a/finder.cpp b/finder.cpp index 1782a8e..3b5211a 100644 --- a/finder.cpp +++ b/finder.cpp @@ -188,31 +188,28 @@ char *GetCodePage(const char *str) 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) { FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready;}); if(!globalScanFlag) return -1; - strcpy(negWord, GlobalNegatives[i]); - if(strstr(buffcpy, negWord) != NULL) + if(strstr(buffcpy, GlobalNegatives[i]) != NULL) { if(gNegDebugMode) - { - QTextCodec *codec = QTextCodec::codecForName("Windows-1251"); - QString neg = codec->toUnicode(negWord); + { stt->doEmitionDebugFoundData("[" + QString(ip) + ":" + QString::number(port) + - "" + "]\tNegative hit: \"" + neg.toHtmlEscaped() + "\""); - if(strlen(negWord) < 2) + "" + "]\tNegative hit: \"" + nCodec->toUnicode(GlobalNegatives[i]).toHtmlEscaped() + "\""); + 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!"); }; - if(strcmp(negWord, " ") == 0) + if(strcmp(GlobalNegatives[i], " ") == 0) { stt->doEmitionDebugFoundData("Space hit!"); }; @@ -220,9 +217,7 @@ int globalSearchNeg(const char *buffcpy, const char *ip, int port) ++Filt; return -1; - }; - - ZeroMemory(negWord, 256); + }; }; } diff --git a/nesca_startModule.cpp b/nesca_startModule.cpp index affd362..5811326 100644 --- a/nesca_startModule.cpp +++ b/nesca_startModule.cpp @@ -171,39 +171,6 @@ QString GetNSErrorDefinition(const char *str, const char *elem) 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() { char saveStr[512] = {0}; @@ -384,7 +351,8 @@ void _timer() { ZeroMemory(timeLeft, sizeof(timeLeft)); ZeroMemory(dbuffer, sizeof(dbuffer)); - Sleep(1000); + + Sleep(1000); }; } @@ -1626,6 +1594,38 @@ int _getChunkCount(char *data) { 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() { std::string ip = ""; @@ -1637,6 +1637,7 @@ void _connect() { --Threader::threadId; Threader::ready = false; lk.unlock(); + Threader::cv.notify_one(); return; } @@ -1645,7 +1646,9 @@ void _connect() { Threader::ipQueue.pop(); Threader::ready = false; lk.unlock(); + Threader::cv.notify_one(); + ++ipCounter; ConInc(); for (int i = 0; i <= overallPorts; ++i) { @@ -1745,14 +1748,6 @@ void runAuxiliaryThreads() { } - - - - - - - - int startScan(char* args) { curl_global_init(CURL_GLOBAL_ALL);