File: threadhash.cpp

package info (click to toggle)
guymager 0.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 932 kB
  • ctags: 1,580
  • sloc: cpp: 8,522; ansic: 2,571; makefile: 49; sh: 23
file content (134 lines) | stat: -rw-r--r-- 4,279 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// ****************************************************************************
//  Project:        GUYMAGER
// ****************************************************************************
//  Programmer:     Guy Voncken
//                  Police Grand-Ducale
//                  Service de Police Judiciaire
//                  Section Nouvelles Technologies
// ****************************************************************************
//  Module:         Thread for calculating hashes
// ****************************************************************************

#include <QtCore>

#include "common.h"
#include "device.h"
#include "threadhash.h"
#include "threadwrite.h"
#include "hash.h"

class t_ThreadHashLocal
{
   public:
      t_pDevice pDevice;
};

t_ThreadHash::t_ThreadHash(void)
{
   CHK_EXIT (ERROR_THREADHASH_CONSTRUCTOR_NOT_SUPPORTED)
} //lint !e1401 not initialised


t_ThreadHash::t_ThreadHash (t_pDevice pDevice)
{
   static bool Initialised = false;

   if (!Initialised)
   {
      CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_THREADHASH_CONSTRUCTOR_NOT_SUPPORTED))
      CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_THREADHASH_LIBEWF_FAILED))
      Initialised = true;
   }

   pOwn = new t_ThreadHashLocal;
   pOwn->pDevice = pDevice;

   CHK_QT_EXIT (connect (this, SIGNAL(finished()), this, SLOT(SlotFinished())))
}

t_ThreadHash::~t_ThreadHash (void)
{
   delete pOwn;
}

void t_ThreadHash::run (void)
{
   t_pDevice          pDevice;
   t_pFifoBlock       pFifoBlock;
   bool                Finished;
   quint64           *pBlocks;
   quint64             BlocksCalculated = 0;
   quint64             BlocksVerified   = 0;
   t_HashContextMD5    HashContextMD5;
   t_HashContextSHA256 HashContextSHA256;
   bool                VerifyLoop = false;

   LOG_INFO ("Acquisition of %s: Hash thread started", QSTR_TO_PSZ (pOwn->pDevice->LinuxDevice))
   pDevice = pOwn->pDevice;
   pBlocks = &BlocksCalculated;
   for (;;)  // The whole loop is done 2 times if the user chose to do a source verification, 1 time otherwise.
   {
      *pBlocks = 0;
      Finished = false;
      CHK_EXIT (HashMD5Init    (&HashContextMD5   ))
      CHK_EXIT (HashSHA256Init (&HashContextSHA256))
      do
      {
         CHK_EXIT (pDevice->pFifoHashIn->Get (pFifoBlock))
         if (pFifoBlock)
         {
            (*pBlocks)++;
            CHK_EXIT (HashMD5Append    (&HashContextMD5   , pFifoBlock->Buffer, pFifoBlock->DataSize))
            CHK_EXIT (HashSHA256Append (&HashContextSHA256, pFifoBlock->Buffer, pFifoBlock->DataSize))
            if (VerifyLoop)
            {
               pDevice->IncCurrentVerifyPos(pFifoBlock->DataSize);
               CHK_EXIT (t_Fifo::Destroy              (pFifoBlock))
            }
            else
            {
               CHK_EXIT (pDevice->pFifoHashOut->Insert (pFifoBlock))
            }
         }
         else
         {
            LOG_INFO ("Dummy block")
            Finished = true;
         }
      } while (!Finished && !pDevice->AbortRequest);
      if (pDevice->AbortRequest)
      {
         break;
      }
      else if (VerifyLoop)
      {
         CHK_EXIT (HashMD5Digest    (&HashContextMD5   , &pDevice->MD5DigestVerify   ))
         CHK_EXIT (HashSHA256Digest (&HashContextSHA256, &pDevice->SHA256DigestVerify))
         break;
      }
      else if (pDevice->Acquisition.VerifySource)
      {
         CHK_EXIT (HashMD5Digest    (&HashContextMD5   , &pDevice->MD5Digest   ))
         CHK_EXIT (HashSHA256Digest (&HashContextSHA256, &pDevice->SHA256Digest))
         pBlocks = &BlocksVerified;
         VerifyLoop = true;
      }
      else
      {
         CHK_EXIT (HashMD5Digest    (&HashContextMD5   , &pDevice->MD5Digest   ))
         CHK_EXIT (HashSHA256Digest (&HashContextSHA256, &pDevice->SHA256Digest))
         break;
      }
   }

   if (pDevice->Acquisition.VerifySource)
        LOG_INFO ("Hash thread exits now (device %s, %Ld blocks processed, %Ld blocks verified)", QSTR_TO_PSZ (pOwn->pDevice->LinuxDevice), BlocksCalculated, BlocksVerified)
   else LOG_INFO ("Hash thread exits now (device %s, %Ld blocks processed)"                     , QSTR_TO_PSZ (pOwn->pDevice->LinuxDevice), BlocksCalculated)
}


void t_ThreadHash::SlotFinished (void)
{
   emit SignalEnded (pOwn->pDevice);
}