static short dupProcess(PacketNode *head, PacketNode *tail) { short duped = FALSE; PacketNode *pac = head->next; while (pac != tail) { if (checkDirection(pac->addr.Direction, dupInbound, dupOutbound) && calcChance(chance)) { short copies = count - 1; LOG("duplicating w/ chance %.1f%%, cloned additionally %d packets", chance/100.0, copies); while (copies--) { PacketNode *copy = createNode(pac->packet, pac->packetLen, &(pac->addr)); insertBefore(copy, pac); // must insertBefore or next packet is still pac } duped = TRUE; } pac = pac->next; } return duped; }
static short dropProcess(PacketNode *head, PacketNode* tail) { int dropped = 0; while (head->next != tail) { PacketNode *pac = head->next; // chance in range of [0, 1000] if (checkDirection(pac->addr.Direction, dropInbound, dropOutbound) && calcChance(chance)) { LOG("dropped with chance %.1f%%, direction %s", chance/10.0, BOUND_TEXT(pac->addr.Direction)); freeNode(popNode(pac)); ++dropped; } else { head = head->next; } } return dropped > 0; }
static short resetProcess(PacketNode *head, PacketNode *tail) { short reset = FALSE; PacketNode *pac = head->next; while (pac != tail) { if (checkDirection(pac->addr.Direction, resetInbound, resetOutbound) && pac->packetLen > TCP_MIN_SIZE && (setNextCount || calcChance(chance))) { PWINDIVERT_TCPHDR pTcpHdr; WinDivertHelperParsePacket( pac->packet, pac->packetLen, NULL, NULL, NULL, NULL, &pTcpHdr, NULL, NULL, NULL); if (pTcpHdr != NULL) { LOG("injecting reset w/ chance %.1f%%", chance/100.0); pTcpHdr->Rst = 1; WinDivertHelperCalcChecksums(pac->packet, pac->packetLen, 0); reset = TRUE; if (setNextCount > 0) { InterlockedDecrement16(&setNextCount); } } } pac = pac->next; } return reset; }
static short tamperProcess(PacketNode *head, PacketNode *tail) { short tampered = FALSE; PacketNode *pac = head->next; while (pac != tail) { if (checkDirection(pac->addr.Direction, tamperInbound, tamperOutbound) && calcChance(chance)) { char *data = NULL; UINT dataLen = 0; if (WinDivertHelperParsePacket(pac->packet, pac->packetLen, NULL, NULL, NULL, NULL, NULL, NULL, (PVOID*)&data, &dataLen) && data != NULL && dataLen != 0) { // try to tamper the central part of the packet, // since common packets put their checksum at head or tail if (dataLen <= 4) { // for short packet just tamper it all tamper_buf(data, dataLen); LOG("tampered w/ chance %.1f, dochecksum: %d, short packet changed all", chance/10.0, doChecksum); } else { // for longer ones process 1/4 of the lens start somewhere in the middle UINT len = dataLen; UINT len_d4 = len / 4; tamper_buf(data + len/2 - len_d4/2 + 1, len_d4); LOG("tampered w/ chance %.1f, dochecksum: %d, changing %d bytes out of %u", chance/10.0, doChecksum, len_d4, len); } // FIXME checksum seems to have some problem if (doChecksum) { WinDivertHelperCalcChecksums(pac->packet, pac->packetLen, 0); } tampered = TRUE; } } pac = pac->next; } return tampered; }
void MainWindow::outGraph() { calcCentr(); calcChance(); cPlotResults->clearGraphs(); cPlotTime->clearGraphs(); double max = 0.0; for(int i = 0; i < FloydCentr.size(); i++) { if(FloydCentr.at(i) > max || max == 0.0) { max = FloydCentr.at(i); } } for(int i = 0; i < RandCentr.size(); i++) { if(RandCentr.at(i) > max || max == 0.0) { max = RandCentr.at(i); } } // results QPen floyd; floyd.setColor(QColor(Qt::red)); floyd.setWidthF(6); QPen dijkstra; dijkstra.setColor(QColor(30, 40, 255, 150)); dijkstra.setStyle(Qt::DotLine); dijkstra.setWidthF(5); QPen randPen; randPen.setColor(QColor(Qt::yellow)); randPen.setStyle(Qt::DashDotDotLine); randPen.setWidthF(4); cPlotResults->addGraph(); //будем выводить результат к количеству вершин //floyd.setStyle(Qt::DotLine); cPlotResults->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::white, 7)); cPlotResults->graph(0)->setPen(floyd); cPlotResults->graph(0)->setData(steps, FloydCentr); cPlotResults->addGraph(); cPlotResults->graph(1)->setPen(dijkstra); cPlotResults->graph(1)->setData(steps, DijkstraCentr); cPlotResults->addGraph(); cPlotResults->graph(2)->setPen(randPen); cPlotResults->graph(2)->setData(steps, RandCentr); cPlotResults->xAxis->setLabel("Количество вершин"); cPlotResults->yAxis->setLabel("Результат"); cPlotResults->xAxis->setRange(STEP_SIZE, m_le_countTops->text().toInt()); cPlotResults->yAxis->setRange(0, max); cPlotResults->replot(); cPlotResults->show(); //time //results = getResults(0,1); cPlotTime->addGraph(); cPlotTime->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::white, 7)); cPlotTime->graph(0)->setPen(floyd); cPlotTime->graph(0)->setData(steps, FloydCentrTime); max = 0; for(int i = 0; i < FloydCentrTime.size(); i++) { if(FloydCentrTime.at(i) > max) max = FloydCentrTime.at(i); } for(int i = 0; i < DijkstraCentrTime.size(); i++) { if(DijkstraCentrTime.at(i) > max) max = DijkstraCentrTime.at(i); } for(int i = 0; i < RandCentrTime.size(); i++) { if(RandCentrTime.at(i) > max) max = RandCentrTime.at(i); } cPlotTime->addGraph(); cPlotTime->graph(1)->setPen(dijkstra); // results = getResults(1,1); cPlotTime->graph(1)->setData(steps, DijkstraCentrTime); cPlotTime->addGraph(); cPlotTime->graph(2)->setPen(randPen); cPlotTime->graph(2)->setData(steps, RandCentrTime); cPlotTime->xAxis->setLabel("Количество вершин"); cPlotTime->yAxis->setLabel("Время"); cPlotTime->xAxis->setRange(STEP_SIZE, m_le_countTops->text().toInt()); cPlotTime->yAxis->setRange(0, max); cPlotTime->replot(); cPlotTime->show(); //solve cPlotSolve->addGraph(); cPlotSolve->graph(0)->setLineStyle(QCPGraph::lsStepCenter); cPlotSolve->graph(0)->setPen(dijkstra); cPlotSolve->graph(0)->setData(steps, chanceDijkstra); cPlotSolve->addGraph(); cPlotSolve->graph(1)->setLineStyle(QCPGraph::lsStepCenter); cPlotSolve->graph(1)->setPen(randPen); cPlotSolve->graph(1)->setData(steps, chanceRand); cPlotSolve->xAxis->setLabel("Количество вершин"); cPlotSolve->yAxis->setLabel("Вероятность успеха"); cPlotSolve->xAxis->setRange(STEP_SIZE, m_le_countTops->text().toInt()); cPlotSolve->yAxis->setRange(0, 1.3); cPlotSolve->replot(); cPlotSolve->show(); }