Skip to content

Commit

Permalink
Hash verification for 4 hash types.
Browse files Browse the repository at this point in the history
Hash verification for 4 hash types.  Limit file size 2gb.
  • Loading branch information
kn0w0n3 committed Jan 4, 2021
1 parent f8e2788 commit 4e58710
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 20 deletions.
40 changes: 29 additions & 11 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QPainter>
#include<QDebug>
#include <QCryptographicHash>
#include <QDataStream>


MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
Expand All @@ -37,7 +38,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
checkTextOne = false;
checkTextTwo = false;
stopMouseMovement = false;

}

MainWindow::~MainWindow() {
Expand Down Expand Up @@ -115,17 +115,29 @@ void MainWindow::on_scanSingleFile_clicked() {
QFileInfo fi(file);
QString name = fi.fileName();
QFile fileLocation(file);
QByteArray hashData;

if (fileLocation.open(QIODevice::ReadOnly))
{
QByteArray fileData = fileLocation.readAll();
QByteArray hashDataMd4;
QByteArray hashDataMd5;
QByteArray hashDataSha1;
QByteArray hashDataSha256;

hashData = QCryptographicHash::hash(fileData, QCryptographicHash::Md5); // or QCryptographicHash::Sha1
qDebug().noquote() << hashData.toHex(); // 0e0c2180dfd784dd84423b00af86e2fc
qDebug() << hashData.toHex(); // 0e0c2180dfd784dd84423b00af86e2fc
QStringList hashList;

}
//Check to see if file is bigger than 2 GB
if(fi.size() > 2147483648){
ui->listWidget->addItem("Error: File size exceeded. Maximum file size is 2GB");
return;
}

if (fileLocation.open(QIODevice::ReadOnly)){
QByteArray fileData = fileLocation.readAll();
hashDataMd4 = QCryptographicHash::hash(fileData, QCryptographicHash::Md4).toHex();
hashDataMd5 = QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
hashDataSha1 = QCryptographicHash::hash(fileData, QCryptographicHash::Sha1).toHex();
hashDataSha256 = QCryptographicHash::hash(fileData, QCryptographicHash::Sha256).toHex();
hashList << hashDataMd4 << hashDataMd5 << hashDataSha1 << hashDataSha256;
qDebug() << hashDataMd5;
}

//QFile inputFile("C:/Users/Desktop/Genome/viruslist.txt");
QFile inputFile(":/data/viruslist.txt");
Expand All @@ -138,9 +150,9 @@ void MainWindow::on_scanSingleFile_clicked() {
QString line = in.readLine();
virusList << line;
}

inputFile.close();
singleScanThread = new SingleScanThread(virusList,name,file,hashData.toHex());

singleScanThread = new SingleScanThread(virusList, name, file, hashList);
connect(singleScanThread, &SingleScanThread::scanStart, this, &MainWindow::handleScanStart);
connect(singleScanThread, &SingleScanThread::scanComplete, this, &MainWindow::handleScanComplete);
connect(singleScanThread, &SingleScanThread::infectedFiles, this, &MainWindow::displayInfectedFiles);
Expand All @@ -164,6 +176,8 @@ void MainWindow::on_scanSingleFile_clicked() {
}
}



void MainWindow::on_scanDirectory_clicked() {

stopMouseMovement = true;
Expand Down Expand Up @@ -215,6 +229,9 @@ void MainWindow::on_scanDirectory_clicked() {

void MainWindow::handleScanStart() {

if(checkTextTwo){
delete textTwo;
}
textOne = new StatusOne(QPixmap(":images/textOne"));
textOne->setPos(80,90);
scene->addItem(textOne);
Expand Down Expand Up @@ -425,3 +442,4 @@ void MainWindow::on_actionClose_hovered() {

stopMouseMovement = true;
}

46 changes: 39 additions & 7 deletions singlescanthread.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
#include "singlescanthread.h"
#include <QDebug>

SingleScanThread::SingleScanThread(QStringList list, QString fileToScan, QString fileLocation, QString hash, QThread *parent) : QThread(parent), virusList(list), passFileToScan(fileToScan), location(fileLocation), hashValue(hash)
SingleScanThread::SingleScanThread(QStringList list, QString fileToScan, QString fileLocation, QStringList hash, QThread *parent) : QThread(parent), virusList(list), passFileToScan(fileToScan), location(fileLocation), hashValues(hash)
{

}

void SingleScanThread::run() {

emit scanStart();

foreach (const QString &str, virusList) {
hashType = 0;
if(!stopSingleThread){
if (str.contains(hashValue)) {
emit infectedFiles(location);
emit infectedFiles("Hash: " + hashValue);

foreach(const QString &hString, hashValues){
hashType++;
if (hString.toLower() == str.toLower()) {
emit infectedFiles(location);
emit infectedFiles("Hash: " + hString);

if(hashType == 1){
emit infectedFiles("Hash Type: MD4");
}
else if(hashType == 2){
emit infectedFiles("Hash Type: MD5");
}
else if(hashType == 3){
emit infectedFiles("Hash Type: SHA1");
}
else if(hashType == 4){
emit infectedFiles("Hash Type: SHA256");
}
}
}
}
}
Expand All @@ -25,5 +39,23 @@ void SingleScanThread::run() {























9 changes: 7 additions & 2 deletions singlescanthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SingleScanThread : public QThread
Q_OBJECT

public:
SingleScanThread(QStringList, QString, QString, QString, QThread *parent = 0);
SingleScanThread(QStringList, QString, QString, QStringList, QThread *parent = 0);
void run();
bool stopSingleThread;

Expand All @@ -28,9 +28,14 @@ public slots:
QString passFileToScan;
QStringList alist;
QString location;
QString hashValue;
QStringList hashValues;
int hashType;

};

#endif // SINGLESCANTHREAD_H





0 comments on commit 4e58710

Please sign in to comment.