Skip to content

Commit

Permalink
Fix: fix crash when analyzing hash files passed as parameter. Parse h…
Browse files Browse the repository at this point in the history
…ash files without the asterisk character before file name.
  • Loading branch information
FelixdelasPozas committed Oct 2, 2016
1 parent 28a6472 commit e5bfc85
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 27 deletions.
2 changes: 1 addition & 1 deletion AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Project
#include <AboutDialog.h>

const QString VERSION = QString("version 1.0.0");
const QString VERSION = QString("version 1.0.1");

//-----------------------------------------------------------------
AboutDialog::AboutDialog(QWidget *parent, Qt::WindowFlags flags)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required (VERSION 2.8.6)
# Version Number
set (SIMPLE_HASHER_VERSION_MAJOR 1)
set (SIMPLE_HASHER_VERSION_MINOR 0)
set (SIMPLE_HASHER_VERSION_PATCH 0)
set (SIMPLE_HASHER_VERSION_PATCH 1)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand Down
80 changes: 59 additions & 21 deletions SimpleHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,23 +835,26 @@ const QString SimpleHasher::guessHash(QFile &file)
file.seek(0);
auto data = file.read(150); // a bit more than the largest of the hashes (512 bits/4 char bits = 128).

QRegExp reg{"(([a-h]*)([A-H]*)([0-9]*))*"};

if(reg.indexIn(data) != -1)
if(data.length() > 32)
{
auto hash = reg.cap();
QRegExp reg{"(([a-h]*)([A-H]*)([0-9]*))*"};

switch(hash.length())
if(reg.indexIn(data) != -1)
{
case 32 : return "MD5";
case 40 : return "SHA-1";
case 56 : return "SHA-224";
case 64 : return "SHA-256";
case 96 : return "SHA-384";
case 128: return "SHA-512";
case 48 : return "Tiger";
default:
break;
auto hash = reg.cap();

switch(hash.length())
{
case 32 : return "MD5";
case 40 : return "SHA-1";
case 56 : return "SHA-224";
case 64 : return "SHA-256";
case 96 : return "SHA-384";
case 128: return "SHA-512";
case 48 : return "Tiger";
default:
break;
}
}
}

Expand Down Expand Up @@ -964,17 +967,52 @@ void SimpleHasher::loadInformation()
QStringList files;
int begin = 0;
auto data = file.readAll();
while(data.indexOf('*', begin) != -1)

if(data.indexOf('*', begin) != -1)
{
while(data.indexOf('*', begin) != -1)
{
begin = data.indexOf('*', begin) + 1;
auto end = data.indexOf('\n', begin);
if(end == -1) end = data.length();

auto fileName = data.mid(begin, end-begin);

if(path.exists(fileName))
{
files << path.absoluteFilePath(fileName);
}

begin = end;
}
}
else
{
begin = data.indexOf('*', begin) + 1;
auto end = data.indexOf('\n', begin);
if(end == -1) end = data.length();
// files without '*' first.
file.seek(0);
auto line = file.readLine();
while(!line.isEmpty())
{
auto lineParts = QString(line).split(' ');
if(lineParts.size() == 2 && path.exists(lineParts[1]))
{
files << files << path.absoluteFilePath(lineParts[1]);
}

files << path.absoluteFilePath(data.mid(begin, end-begin));
begin = end;
line = file.readLine();
}
}

addFilesToTable(files);
if(!files.empty())
{
addFilesToTable(files);
}
else
{
fileErrors += tr("%1 error: %2\n").arg(filename).arg(tr("File doesn't contains hashes."));
file.close();
continue;
}

QRegExp hashexp{"(([a-h]*)([A-H]*)([0-9]*))*"};
hashexp.setMinimal(false);
Expand Down
2 changes: 1 addition & 1 deletion SimpleHasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#define SIMPLEHASHER_H_

// Qt
#include <QMainWindow>
#include "ui_SimpleHasher.h"
#include <QMainWindow>

// C++
#include <memory>
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ Configuration dialog
![configuration](https://cloud.githubusercontent.com/assets/12167134/15993540/76f68e16-30e9-11e6-852f-328f1455117a.jpg)

# Repository information
**Version**: 1.0.0
**Version**: 1.0.1

**Status**: finished

**cloc statistics**

| Language |files |blank |comment |code |
|:-----------------------------|--------------:|------------:|-----------------:|-------:|
| C++ | 13 | 459 | 377 | 2006 |
| C++ | 13 | 462 | 378 | 2040 |
| C/C++ Header | 12 | 199 | 493 | 383 |
| CMake | 1 | 16 | 10 | 63 |
| **Total** | **26** | **674** | **880** |**2452**|
| **Total** | **26** | **677** | **881** |**2486**|

0 comments on commit e5bfc85

Please sign in to comment.