Fixed up the rest of the fuzzing window. It should be pretty complete
and functional now.
This commit is contained in:
+122
-8
@@ -2,6 +2,7 @@
|
|||||||
#include "ui_fuzzingwindow.h"
|
#include "ui_fuzzingwindow.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
FuzzingWindow::FuzzingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
FuzzingWindow::FuzzingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
@@ -22,13 +23,19 @@ FuzzingWindow::FuzzingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
|||||||
connect(ui->spinBytes, SIGNAL(valueChanged(int)), this, SLOT(changedNumDataBytes(int)));
|
connect(ui->spinBytes, SIGNAL(valueChanged(int)), this, SLOT(changedNumDataBytes(int)));
|
||||||
connect(ui->bitfield, SIGNAL(gridClicked(int,int)), this, SLOT(bitfieldClicked(int,int)));
|
connect(ui->bitfield, SIGNAL(gridClicked(int,int)), this, SLOT(bitfieldClicked(int,int)));
|
||||||
|
|
||||||
|
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
|
||||||
|
|
||||||
refreshIDList();
|
refreshIDList();
|
||||||
|
|
||||||
currentlyFuzzing = false;
|
currentlyFuzzing = false;
|
||||||
|
|
||||||
for (int j = 0; j < 64; j++) bitGrid[j] = 1;
|
for (int j = 0; j < 64; j++) bitGrid[j] = 1;
|
||||||
|
numBits = 64;
|
||||||
|
bitAccum = 0;
|
||||||
redrawGrid();
|
redrawGrid();
|
||||||
|
|
||||||
|
fuzzTimer->setInterval(ui->spinTiming->value());
|
||||||
|
|
||||||
ui->cbBuses->addItem(tr("0"));
|
ui->cbBuses->addItem(tr("0"));
|
||||||
ui->cbBuses->addItem(tr("1"));
|
ui->cbBuses->addItem(tr("1"));
|
||||||
ui->cbBuses->addItem(tr("Both"));
|
ui->cbBuses->addItem(tr("Both"));
|
||||||
@@ -39,6 +46,41 @@ FuzzingWindow::~FuzzingWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FuzzingWindow::updatedFrames(int numFrames)
|
||||||
|
{
|
||||||
|
CANFrame thisFrame;
|
||||||
|
int id;
|
||||||
|
if (numFrames == -1) //all frames deleted. Kill the display
|
||||||
|
{
|
||||||
|
ui->listID->clear();
|
||||||
|
foundIDs.clear();
|
||||||
|
refreshIDList();
|
||||||
|
}
|
||||||
|
else if (numFrames == -2) //all new set of frames. Reset
|
||||||
|
{
|
||||||
|
ui->listID->clear();
|
||||||
|
foundIDs.clear();
|
||||||
|
refreshIDList();
|
||||||
|
}
|
||||||
|
else //just got some new frames. See if they are relevant.
|
||||||
|
{
|
||||||
|
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
|
||||||
|
{
|
||||||
|
id = modelFrames->at(i).ID;
|
||||||
|
if (!foundIDs.contains(id))
|
||||||
|
{
|
||||||
|
foundIDs.append(id);
|
||||||
|
selectedIDs.append(id);
|
||||||
|
QListWidgetItem *thisItem = new QListWidgetItem();
|
||||||
|
thisItem->setText(Utility::formatNumber(id));
|
||||||
|
thisItem->setFlags(thisItem->flags() | Qt::ItemIsUserCheckable);
|
||||||
|
thisItem->setCheckState(Qt::Checked);
|
||||||
|
ui->listID->addItem(thisItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FuzzingWindow::changePlaybackSpeed(int newSpeed)
|
void FuzzingWindow::changePlaybackSpeed(int newSpeed)
|
||||||
{
|
{
|
||||||
fuzzTimer->setInterval(newSpeed);
|
fuzzTimer->setInterval(newSpeed);
|
||||||
@@ -116,15 +158,18 @@ void FuzzingWindow::setAllFilters()
|
|||||||
void FuzzingWindow::calcNextID()
|
void FuzzingWindow::calcNextID()
|
||||||
{
|
{
|
||||||
if (seqIDScan)
|
if (seqIDScan)
|
||||||
{
|
{
|
||||||
currentID++;
|
|
||||||
if (rangeIDSelect)
|
if (rangeIDSelect)
|
||||||
{
|
{
|
||||||
|
currentID++;
|
||||||
if (currentID > endID) currentID = startID;
|
if (currentID > endID) currentID = startID;
|
||||||
}
|
}
|
||||||
else //IDs by filter. So, select the first filter
|
else //IDs by filter. So, select the first filter
|
||||||
{
|
{
|
||||||
if (currentID > selectedIDs.length()) currentID = 0;
|
currentIdx++;
|
||||||
|
if (currentIdx >= selectedIDs.length()) currentIdx = 0;
|
||||||
|
currentID = selectedIDs[currentIdx];
|
||||||
|
qDebug() << "idx id: " << currentID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //random IDs
|
else //random IDs
|
||||||
@@ -137,13 +182,16 @@ void FuzzingWindow::calcNextID()
|
|||||||
}
|
}
|
||||||
else //IDs by filter so pick a random selected ID from the filter list
|
else //IDs by filter so pick a random selected ID from the filter list
|
||||||
{
|
{
|
||||||
currentID = qrand() % selectedIDs.length();
|
currentIdx = qrand() % selectedIDs.length();
|
||||||
|
currentID = selectedIDs[currentIdx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuzzingWindow::calcNextBitPattern()
|
void FuzzingWindow::calcNextBitPattern()
|
||||||
{
|
{
|
||||||
|
uint64_t accum;
|
||||||
|
|
||||||
switch (bitSequenceType)
|
switch (bitSequenceType)
|
||||||
{
|
{
|
||||||
case BitSequenceType::Random:
|
case BitSequenceType::Random:
|
||||||
@@ -163,8 +211,53 @@ void FuzzingWindow::calcNextBitPattern()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BitSequenceType::Sequential:
|
case BitSequenceType::Sequential:
|
||||||
|
bitAccum++;
|
||||||
|
bitAccum &= ((1 << numBits) - 1);
|
||||||
|
accum = bitAccum;
|
||||||
|
for (int byt = 0; byt < ui->spinBytes->value(); byt++)
|
||||||
|
{
|
||||||
|
currentBytes[byt] = 0;
|
||||||
|
for (int bit = 0; bit < 8; bit++)
|
||||||
|
{
|
||||||
|
thisBit = bitGrid[byt * 8 + bit];
|
||||||
|
if (thisBit == 1)
|
||||||
|
{
|
||||||
|
if (accum & 1) currentBytes[byt] |= (1 << bit);
|
||||||
|
accum >>= 1;
|
||||||
|
}
|
||||||
|
if (thisBit == 2) currentBytes[byt] |= (1 << bit);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BitSequenceType::Sweeping:
|
case BitSequenceType::Sweeping:
|
||||||
|
qDebug() << "Start " << bitAccum;
|
||||||
|
accum = bitAccum;
|
||||||
|
|
||||||
|
int offset;
|
||||||
|
for (int i = 1; i < 64; i++)
|
||||||
|
{
|
||||||
|
offset = (i + bitAccum) % 64;
|
||||||
|
if (bitGrid[offset] == 1)
|
||||||
|
{
|
||||||
|
bitAccum = offset;
|
||||||
|
qDebug() << "End " << bitAccum;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int byt = 0; byt < ui->spinBytes->value(); byt++)
|
||||||
|
{
|
||||||
|
currentBytes[byt] = 0;
|
||||||
|
for (int bit = 0; bit < 8; bit++)
|
||||||
|
{
|
||||||
|
thisBit = bitGrid[byt * 8 + bit];
|
||||||
|
if (thisBit == 1 && (byt * 8 + bit) == bitAccum)
|
||||||
|
{
|
||||||
|
currentBytes[byt] |= (1 << bit);
|
||||||
|
}
|
||||||
|
if (thisBit == 2) currentBytes[byt] |= (1 << bit);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,8 +281,23 @@ void FuzzingWindow::toggleFuzzing()
|
|||||||
seqIDScan = ui->rbSequentialID->isChecked();
|
seqIDScan = ui->rbSequentialID->isChecked();
|
||||||
rangeIDSelect = ui->rbRangeIDSel->isChecked();
|
rangeIDSelect = ui->rbRangeIDSel->isChecked();
|
||||||
if (ui->rbSequentialBits->isChecked()) bitSequenceType = BitSequenceType::Sequential;
|
if (ui->rbSequentialBits->isChecked()) bitSequenceType = BitSequenceType::Sequential;
|
||||||
if (ui->rbRandomBits->isChecked()) bitSequenceType = BitSequenceType::Random;
|
if (ui->rbRandomBits->isChecked())
|
||||||
if (ui->rbSweep->isChecked()) bitSequenceType = BitSequenceType::Sweeping;
|
{
|
||||||
|
bitSequenceType = BitSequenceType::Random;
|
||||||
|
bitAccum = 0;
|
||||||
|
}
|
||||||
|
if (ui->rbSweep->isChecked())
|
||||||
|
{
|
||||||
|
bitSequenceType = BitSequenceType::Sweeping;
|
||||||
|
for (int i = 0; i < 64; i++)
|
||||||
|
{
|
||||||
|
if (bitGrid[i] == 1)
|
||||||
|
{
|
||||||
|
bitAccum = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
numSentFrames = 0;
|
numSentFrames = 0;
|
||||||
|
|
||||||
@@ -201,7 +309,8 @@ void FuzzingWindow::toggleFuzzing()
|
|||||||
}
|
}
|
||||||
else //IDs by filter. So, select the first filter
|
else //IDs by filter. So, select the first filter
|
||||||
{
|
{
|
||||||
currentID = 0;
|
currentIdx = 0;
|
||||||
|
currentID = selectedIDs[currentIdx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //random IDs
|
else //random IDs
|
||||||
@@ -214,7 +323,8 @@ void FuzzingWindow::toggleFuzzing()
|
|||||||
}
|
}
|
||||||
else //IDs by filter so pick a random selected ID from the filter list
|
else //IDs by filter so pick a random selected ID from the filter list
|
||||||
{
|
{
|
||||||
currentID = qrand() % selectedIDs.length();
|
currentIdx = qrand() % selectedIDs.length();
|
||||||
|
currentID = selectedIDs[currentIdx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +337,7 @@ void FuzzingWindow::toggleFuzzing()
|
|||||||
void FuzzingWindow::refreshIDList()
|
void FuzzingWindow::refreshIDList()
|
||||||
{
|
{
|
||||||
ui->listID->clear();
|
ui->listID->clear();
|
||||||
|
foundIDs.clear();
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
for (int i = 0; i < modelFrames->count(); i++)
|
for (int i = 0; i < modelFrames->count(); i++)
|
||||||
@@ -298,6 +409,8 @@ void FuzzingWindow::redrawGrid()
|
|||||||
usedBytes[j] = 0;
|
usedBytes[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numBits = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 64; i++)
|
for (int i = 0; i < 64; i++)
|
||||||
{
|
{
|
||||||
int byt = i / 8;
|
int byt = i / 8;
|
||||||
@@ -308,6 +421,7 @@ void FuzzingWindow::redrawGrid()
|
|||||||
break;
|
break;
|
||||||
case 1: //Green, fuzz this bit
|
case 1: //Green, fuzz this bit
|
||||||
dataBytes[byt] |= (1 << bit);
|
dataBytes[byt] |= (1 << bit);
|
||||||
|
numBits++;
|
||||||
break;
|
break;
|
||||||
case 2: //black, bit always set
|
case 2: //black, bit always set
|
||||||
dataBytes[byt] |= (1 << bit);
|
dataBytes[byt] |= (1 << bit);
|
||||||
|
|||||||
+4
-1
@@ -41,6 +41,7 @@ private slots:
|
|||||||
void idListChanged(QListWidgetItem *item);
|
void idListChanged(QListWidgetItem *item);
|
||||||
void bitfieldClicked(int, int);
|
void bitfieldClicked(int, int);
|
||||||
void changedNumDataBytes(int newVal);
|
void changedNumDataBytes(int newVal);
|
||||||
|
void updatedFrames(int numFrames);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FuzzingWindow *ui;
|
Ui::FuzzingWindow *ui;
|
||||||
@@ -49,12 +50,14 @@ private:
|
|||||||
QList<int> foundIDs;
|
QList<int> foundIDs;
|
||||||
QList<int> selectedIDs;
|
QList<int> selectedIDs;
|
||||||
QList<CANFrame> sendingBuffer;
|
QList<CANFrame> sendingBuffer;
|
||||||
int startID, endID, currentID;
|
int startID, endID, currentID, currentIdx;
|
||||||
bool seqIDScan, rangeIDSelect;
|
bool seqIDScan, rangeIDSelect;
|
||||||
int bitSequenceType;
|
int bitSequenceType;
|
||||||
bool currentlyFuzzing;
|
bool currentlyFuzzing;
|
||||||
uint8_t currentBytes[8];
|
uint8_t currentBytes[8];
|
||||||
uint8_t bitGrid[64];
|
uint8_t bitGrid[64];
|
||||||
|
uint8_t numBits;
|
||||||
|
uint64_t bitAccum;
|
||||||
int numSentFrames;
|
int numSentFrames;
|
||||||
|
|
||||||
void refreshIDList();
|
void refreshIDList();
|
||||||
|
|||||||
Reference in New Issue
Block a user