[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [messagelib] webengineviewer/src/checkphishingurl: Try to make search hash working
From:       Montel Laurent <montel () kde ! org>
Date:       2016-11-26 10:55:31
Message-ID: E1cAadn-0002Yf-M6 () code ! kde ! org
[Download RAW message or body]

Git commit b3f255a9ad0c2e9383699ca626d63b4ec3fa402d by Montel Laurent.
Committed on 26/11/2016 at 10:55.
Pushed by mlaurent into branch 'master'.

Try to make search hash working

M  +13   -3    webengineviewer/src/checkphishingurl/autotests/localdatabasefiletest.cpp
 M  +6    -11   webengineviewer/src/checkphishingurl/localdatabasefile.cpp
M  +1    -1    webengineviewer/src/checkphishingurl/localdatabasefile.h

https://commits.kde.org/messagelib/b3f255a9ad0c2e9383699ca626d63b4ec3fa402d

diff --git a/webengineviewer/src/checkphishingurl/autotests/localdatabasefiletest.cpp \
b/webengineviewer/src/checkphishingurl/autotests/localdatabasefiletest.cpp index \
                0df4cbd..09fa317 100644
--- a/webengineviewer/src/checkphishingurl/autotests/localdatabasefiletest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/localdatabasefiletest.cpp
@@ -56,13 +56,16 @@ void LocalDataBaseFileTest::shouldBeInvalidWithUnExistingFile()
 void LocalDataBaseFileTest::shouldCheckHashBinaryFile_data()
 {
     QTest::addColumn<QByteArray>("hash");
+    QTest::addColumn<QByteArray>("resultHash");
     QTest::addColumn<bool>("found");
-    QTest::newRow("nohash") << QByteArrayLiteral("foo") << false;
+    QTest::newRow("nohash") << QByteArrayLiteral("foo") << QByteArray() << false;
+    QTest::newRow("foundhash") << QByteArrayLiteral("1111") << QByteArray() << \
false;  }
 
 void LocalDataBaseFileTest::shouldCheckHashBinaryFile()
 {
     QFETCH(QByteArray, hash);
+    QFETCH(QByteArray, resultHash);
     QFETCH(bool, found);
     WebEngineViewer::CreateDatabaseFileJob databasejob;
     const QString createDataBaseName = \
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + \
QStringLiteral("/phishingurl") + QStringLiteral("/correctBinary.db"); @@ -110,9 \
+113,16 @@ void LocalDataBaseFileTest::shouldCheckHashBinaryFile()  \
QVERIFY(newFile.isValid());  QCOMPARE(newFile.getUint16(0), static_cast<quint16>(1));
     QCOMPARE(newFile.getUint16(2), static_cast<quint16>(0));
-    QCOMPARE(newFile.getUint64(4), static_cast<quint64>(9));
+    quint64 number = newFile.getUint64(4);
+    QCOMPARE(number, static_cast<quint64>(9));
     int index = 4 + sizeof(quint64);
-
+    const QByteArray val = newFile.searchHash(12, hash);
+    qDebug() << "result : " << val;
+    QCOMPARE(!val.isEmpty(), found);
+    if (!val.isEmpty()) {
+        //Port to QByteArray ?
+        QCOMPARE(resultHash, val);
+    }
     //TODO
 }
 
diff --git a/webengineviewer/src/checkphishingurl/localdatabasefile.cpp \
b/webengineviewer/src/checkphishingurl/localdatabasefile.cpp index 288aa59..f900f25 \
                100644
--- a/webengineviewer/src/checkphishingurl/localdatabasefile.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasefile.cpp
@@ -133,30 +133,25 @@ bool LocalDataBaseFile::reload()
     return d->reload();
 }
 
-QString LocalDataBaseFile::searchHash(int posListOffset, const QByteArray \
&hashToSearch) +QByteArray LocalDataBaseFile::searchHash(int posListOffset, const \
QByteArray &hashToSearch)  {
-#if 0
-    const int hashsListOffset = getUint32(posListOffset);
-    const int numHash = getUint32(hashsListOffset);
+    const int numHash = getUint64(posListOffset);
     int begin = 0;
     int end = numHash - 1;
     while (begin <= end) {
         const int medium = (begin + end) / 2;
-        const int off = hashsListOffset + 4 + 8 * medium;
+        const int off = posListOffset + 4 + 8 * medium;
         const int hashOffset = getUint32(off);
         const char *hashCharStar = getCharStar(hashOffset);
-        const int cmp = qstrcmp(mime, inputMime);
+        const int cmp = qstrcmp(hashCharStar, hashToSearch.constData());
+        qDebug() << " begin " << begin << " end " << end << " hashCharStar" \
<<hashCharStar;  if (cmp < 0) {
             begin = medium + 1;
         } else if (cmp > 0) {
             end = medium - 1;
-        } else {
-            const int iconOffset = getUint32(off + 4);
-            return QLatin1String(getCharStar(iconOffset));
         }
     }
-#endif
-    return QString();
+    return QByteArray();
 }
 
 bool LocalDataBaseFile::shouldCheck()
diff --git a/webengineviewer/src/checkphishingurl/localdatabasefile.h \
b/webengineviewer/src/checkphishingurl/localdatabasefile.h index 3660cae..620f10c \
                100644
--- a/webengineviewer/src/checkphishingurl/localdatabasefile.h
+++ b/webengineviewer/src/checkphishingurl/localdatabasefile.h
@@ -56,7 +56,7 @@ public:
     quint64 getUint64(int offset) const;
     const char *getCharStar(int offset) const;
 
-    QString searchHash(int posListOffset, const QByteArray &hashToSearch);
+    QByteArray searchHash(int posListOffset, const QByteArray &hashToSearch);
 
     bool shouldCheck();
     bool checkFileChanged();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic