checkbrute/src/brutethread.cpp

45 lines
2.3 KiB
C++
Raw Permalink Normal View History

2020-10-24 23:51:02 +02:00
/*****************************************************************************
* checkbrute Checksum Bruteforcing Tool
* Copyright (C) 2020 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
2020-10-25 02:54:22 +02:00
#include <QDebug>
2020-10-24 23:51:02 +02:00
#include <QTextStream>
#include "brutethread.h"
2020-10-25 19:16:08 +01:00
brutethread::brutethread(const QByteArray &fileContent, quint64 length, quint64 begin, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums, bool strictMatch) : checksum_vector(checksum_vector), checksums(checksums), fileContent(fileContent), strictMatch(strictMatch), length(length), begin(begin) {}
2020-10-24 23:51:02 +02:00
void brutethread::run()
{
quint64 size = fileContent.size();
for (quint64 seek = 0; seek + length < size; seek++) {
for (checksum *generator : checksum_vector) {
const QByteArray content = fileContent.mid(seek, length);
2020-10-25 02:54:22 +02:00
const QByteArray generatedHash = generator->generateChecksum(content);
2020-10-24 23:51:02 +02:00
for (const QByteArray &hash : checksums) {
2020-10-25 00:24:45 +02:00
if (!strictMatch && generatedHash.left(hash.length()) == hash) {
2020-10-25 19:16:08 +01:00
QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << begin+seek << " End " << begin+seek+length << Qt::endl;
2020-10-25 00:24:45 +02:00
emit matched();
}
else if (strictMatch && generatedHash.length() == hash.length() && generatedHash == hash) {
2020-10-25 19:16:08 +01:00
QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << begin+seek << " End " << begin+seek+length << Qt::endl;
2020-10-24 23:51:02 +02:00
emit matched();
}
}
}
}
}