Skip to content

Commit

Permalink
Threadpool refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
cora32 committed Apr 4, 2015
1 parent 4f8cb2c commit e3407a5
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 147 deletions.
13 changes: 7 additions & 6 deletions ActivityDrawerTh_HorNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ void ActivityDrawerTh_HorNet::run()
adtHN->doEmitDrawGrid();
int maxAct = Activity + 1;
int nm = 0;
while(true)
while (true)
{
if(maxAct < Activity) maxAct = Activity;
if(maxAct > 1000) nm = maxAct-=1000;
else if(maxAct > 10) nm = maxAct-=10;
makeActLine(((float)Activity/(nm != 0 ? nm : 1)) * 10);
if (maxAct < Activity) maxAct = Activity;
if (maxAct > 1000) nm = maxAct -= 1000;
else if (maxAct > 10) nm = maxAct -= 10;

makeActLine(((float)Activity / (nm != 0 ? nm : 1)) * 10);
adtHN->doEmitDrawActivityLine(QString::number(Activity) + "b");
Activity = 0;
msleep(130);
msleep(150);
};
}
14 changes: 7 additions & 7 deletions BasicAuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ bool BA::checkOutput(const string *buffer, const char *ip, const int port) {
lopaStr BA::BABrute(const char *ip, const int port) {
string buffer;
string lpString;
lopaStr lps{"UNKNOWN", "", ""};
ZeroMemory(lps.login, sizeof(lps.login));
ZeroMemory(lps.pass, sizeof(lps.pass));
ZeroMemory(lps.other, sizeof(lps.other));
lopaStr lps = {"UNKNOWN", "", ""};
int passCounter = 0;
int res = 0;

Expand Down Expand Up @@ -73,13 +70,16 @@ lopaStr BA::BALobby(const char *ip, const int port) {

while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000);

BruteUtils::BConInc();
++baCount;
++BrutingThrds;
//BruteUtils::BConInc();
const lopaStr &lps = BABrute(ip, port);
BruteUtils::BConDec();
//BruteUtils::BConDec();
--BrutingThrds;

return lps;
} else {
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
return lps;
}
}
44 changes: 22 additions & 22 deletions BruteUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@

void BruteUtils::BConInc()
{
++BA;
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock inc BrutingThrds;
};
#else
asm("lock incl BrutingThrds");
#endif
stt->doEmitionUpdateArc(gTargets);
// ++BA;
//#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
//__asm
// {
// lock inc BrutingThrds;
// };
//#else
// asm("lock incl BrutingThrds");
//#endif
// stt->doEmitionUpdateArc(gTargets);
}

void BruteUtils::BConDec()
{
if(BrutingThrds > 0)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
__asm
{
lock dec BrutingThrds;
};
#else
asm("lock decl BrutingThrds");
#endif
}
stt->doEmitionUpdateArc(gTargets);
// if(BrutingThrds > 0)
// {
//#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
// __asm
// {
// lock dec BrutingThrds;
// };
//#else
// asm("lock decl BrutingThrds");
//#endif
// }
// stt->doEmitionUpdateArc(gTargets);
}
8 changes: 4 additions & 4 deletions DrawerTh_ME2Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ int MakePolygonLine(int gWidth)

if(xtx > 74 && xtx < 112)
{
qp = QPointF(xtx, state ? qrand() % 3 + ME2YPOS - BA * 2 - fact3 : ME2YPOS);
qp = QPointF(xtx, state ? qrand() % 3 + ME2YPOS - baCount * 2 - fact3 : ME2YPOS);

if(BA > 0)
if (baCount > 0)
{
if(xtx < 92 ) fact3+=2;
else fact3-=2;
Expand Down Expand Up @@ -120,7 +120,7 @@ int MakePolygonLine(int gWidth)

AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;
Expand Down Expand Up @@ -150,7 +150,7 @@ void DrawerTh_ME2Scanner::run()
msleep(1000);
AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;
Expand Down
6 changes: 3 additions & 3 deletions DrawerTh_QoSScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void DrawerTh_QoSScanner::run()
lstOfLabels.append(WF);
lstOfLabels.append(Susp);
lstOfLabels.append(Lowl);
lstOfLabels.append(BA);
lstOfLabels.append(baCount);
lstOfLabels.append(Overl);
lstOfLabels.append(ssh);

Expand All @@ -29,7 +29,7 @@ void DrawerTh_QoSScanner::run()
msleep(500);
AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;
Expand All @@ -40,7 +40,7 @@ void DrawerTh_QoSScanner::run()

AnomC1 = 0;
WF = 0;
BA = 0;
baCount = 0;
Filt = 0;
Overl = 0;
Lowl = 0;
Expand Down
6 changes: 3 additions & 3 deletions DrawerTh_VoiceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ void DrawerTh_VoiceScanner::run()
{
if(widgetIsHidden == false && tray->isVisible() == false)
{
makeVoiceLine(Alive, AnomC1, WF, Susp, Lowl, BA, Overl, WF, ssh);
makeVoiceLine(Alive, AnomC1, WF, Susp, Lowl, baCount, Overl, WF, ssh);
Alive = 0;
AnomC1 = 0;
WF = 0;
Filt = 0;
Lowl = 0;
BA = 0;
baCount = 0;
Overl = 0;
Susp = 0;
ssh = 0;
Expand All @@ -126,7 +126,7 @@ void DrawerTh_VoiceScanner::run()
WF = 0;
Filt = 0;
Lowl = 0;
BA = 0;
baCount = 0;
Overl = 0;
Susp = 0;
ssh = 0;
Expand Down
14 changes: 8 additions & 6 deletions FTPAuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ bool FTPA::checkOutput(const string *buffer) {
lopaStr FTPA::FTPBrute(const char *ip, const int port, PathStr *ps) {
string buffer;
string lpString;
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};

strcpy(lps.login, "UNKNOWN");
int res = 0;
int passCounter = 0;

Expand Down Expand Up @@ -68,13 +67,16 @@ lopaStr FTPA::FTPLobby(const char *ip, const int port, PathStr *ps) {
if(gMaxBrutingThreads > 0) {
while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000);

BruteUtils::BConInc();
const lopaStr &lps = FTPBrute(ip, port, ps);
BruteUtils::BConDec();
++baCount;
//BruteUtils::BConInc();
++BrutingThrds;
const lopaStr &lps = FTPBrute(ip, port, ps);
--BrutingThrds;
//BruteUtils::BConDec();

return lps;
} else {
lopaStr lps{"UNKNOWN", "", ""};;
lopaStr lps = {"UNKNOWN", "", ""};;
return lps;
}
}
13 changes: 8 additions & 5 deletions IPCAuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

lopaStr IPC::IPCBrute(const char *ip, int port, char *SPEC)
{
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
bool result = true;
char login[128] = {0};
char pass[128] = {0};
Expand Down Expand Up @@ -177,13 +177,16 @@ lopaStr IPC::IPCLobby(const char *ip, int port, char *SPEC) {
if(gMaxBrutingThreads > 0) {
while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000);

BruteUtils::BConInc();
lopaStr lps = IPCBrute(ip, port, SPEC);
BruteUtils::BConDec();
//BruteUtils::BConInc();
++baCount;
++BrutingThrds;
lopaStr lps = IPCBrute(ip, port, SPEC);
--BrutingThrds;
//BruteUtils::BConDec();

return lps;
} else {
lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};
return lps;
}
}
8 changes: 5 additions & 3 deletions SSHAuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ int SSHAuth::SSHLobby(const char *ip, int port, std::string *buffer)
const char &banner = _get_ssh_banner(ip, port);
if(strlen(&banner) > 0)
{
BruteUtils::BConInc();
int res = SSHBrute(ip, port, buffer, &banner);
BruteUtils::BConDec();
//BruteUtils::BConInc();
++BrutingThrds;
int res = SSHBrute(ip, port, buffer, &banner);
--BrutingThrds;
//BruteUtils::BConDec();
return res;
};
return -1;
Expand Down
8 changes: 5 additions & 3 deletions Threader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ void Threader::fireThread(std::string ip, void *func(void)) {
workerThread.detach();
}

ready = true;
cv.notify_one();
ready = true;
cv.notify_one();
Sleep(gThreadDelay);
}

void Threader::cleanUp() {
ready = true;
cv.notify_one();
cv.notify_all();
//Wait for threads to exit correctly
Sleep(gTimeOut*1000 + 2000);
std::unique_lock<std::mutex> lk(m);
lk.unlock();
lk.release();
Expand Down
2 changes: 1 addition & 1 deletion WebformWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ lopaStr WFClass::_WFBrute( const char *ip,
char *passVal,
char *formVal) {

lopaStr lps{"UNKNOWN", "", ""};
lopaStr lps = {"UNKNOWN", "", ""};

if(strstri(methodVal, "get") != NULL) {
lps = doGetCheck(ip, port, actionVal, userVal, passVal, formVal);
Expand Down
8 changes: 6 additions & 2 deletions WebformWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ class WFClass : BruteUtils {
while(BrutingThrds >= gMaxBrutingThreads) Sleep(700);

++WF;
BConInc();

++BrutingThrds;
//BConInc();
passCounter = 1;
}
}

~WFClass(){
BConDec();
//BConDec();

--BrutingThrds;
}

lopaStr _WFBrute(const char *ip,
Expand Down
2 changes: 1 addition & 1 deletion externData.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern int found, indexIP, gMode,
gThreadDelay, AnomC1, Filt, Overl, Lowl, Alive, saved,
Susp,
WF,
BA,
baCount,
offlines, ssh, globalPinger, gPingTimeout, nickFlag, offlineFlag;
extern unsigned int Activity;
extern char trcSrv[256], trcScr[256], trcProxy[128], trcPersKey[64],
Expand Down
7 changes: 0 additions & 7 deletions externFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
#define EF_H

extern std::string toLowerStr(const char *str);
extern int recvS(int lSock, char *recvBuffT, int len);
extern int sendS(int lSock, char *msg, int len, int mode);
extern void UserNickInit();
extern void GetNicks();
extern int startScan(char* argv);
extern void BConInc();
extern void BConDec();
extern QString GetNSErrorDefinition(const char *str, const char *defin);
extern void _SaveBackupToFile();
extern char* strstri(const char *_Str, const char *_SubStr);
Expand All @@ -17,7 +11,6 @@ extern void getSubStr(char *src, char *startStr, char *endStr, char *dest, int s
extern void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest);
extern void _SaveBackupToFile();
extern char *_findFirst(const char *str, char *delim);
//extern int nConnect(char *ip, int port, std::string *buffer);


#endif // EF_H
Loading

0 comments on commit e3407a5

Please sign in to comment.