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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
|
// ****************************************************************************
// Project: GUYMAGER
// ****************************************************************************
// Programmer: Guy Voncken
// Police Grand-Ducale
// Service de Police Judiciaire
// Section Nouvelles Technologies
// ****************************************************************************
// Module: The DeviceList represents the central data structure of
// the application. Its contents are displayed in the main
// window.
// ****************************************************************************
#include <float.h>
#include <QString>
#include <QList>
#include "toolconstants.h"
#include "common.h"
#include "config.h"
#include "mainwindow.h"
#include "main.h"
// ---------------------------
// t_Device
// ---------------------------
static const int DEVICE_MIN_RUNNING_SECONDS = 20; // The minmum number of acquisition seconds before any estimation can be made
void t_Device::Initialise (void)
{
static bool Initialised = false;
if (!Initialised)
{
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DEVICE_SERNR_MATCH_MODEL_MISMATCH ))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DEVICE_SERNR_MATCH_LENGTH_MISMATCH))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DEVICE_BAD_STATE ))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DEVICE_BAD_ABORTREASON ))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DEVICE_NOT_CLEAN ))
Initialised = true;
}
// this->SerialNumber = QString();
// this->LinuxDevice = QString();
// this->Model = QString();
this->Local = false;
this->SectorSize = 0;
this->SectorSizePhys = 0;
this->Size = 0;
this->Removable = false;
this->State = Idle;
// this->Acquisition.Message = QString();
this->AbortRequest = false;
this->AbortReason = None;
this->DeleteAfterAbort = false;
this->pFifoRead = NULL;
this->pThreadRead = NULL;
this->pFileSrc = NULL;
this->CurrentReadPos = 0;
// this->BadSectors
// this->BadSectorsVerify
this->FallbackMode = false;
this->StartTimestamp = QDateTime();
this->StartTimestampVerify = QDateTime();
this->StopTimestamp = QDateTime();
this->pThreadWrite = NULL;
this->CurrentWritePos = 0;
this->CurrentVerifyPos = 0;
this->pFifoWrite = NULL;
this->pThreadHash = NULL;
this->pFifoHashIn = NULL;
this->pFifoHashOut = NULL;
memset (&this->MD5Digest , 0, sizeof(this->MD5Digest ));
memset (&this->MD5DigestVerify , 0, sizeof(this->MD5DigestVerify ));
memset (&this->SHA256Digest , 0, sizeof(this->SHA256Digest ));
memset (&this->SHA256DigestVerify, 0, sizeof(this->SHA256DigestVerify));
this->pFifoCompressIn = NULL;
this->pFifoCompressOut = NULL;
this->FifoMaxBlocks = 0;
this->FifoBlockSize = 0;
// this->Acquisition.Path = QString();
// this->Acquisition.ImageFilename = QString();
// this->Acquisition.InfoFilename = QString();
this->Acquisition.Format = t_File::NotSet;
this->Acquisition.CalcHashes = false;
this->Acquisition.VerifySource = false;
// this->Acquisition.CaseNumber = QString();
// this->Acquisition.EvidenceNumber= QString();
// this->Acquisition.Examiner = QString();
// this->Acquisition.Description = QString();
// this->Acquisition.Notes = QString();
this->Info.SetDevice(this);
this->PrevTimestamp = QTime();
this->PrevSpeed = 0.0;
this->Checked = false;
}
void t_Device::InitialiseDeviceSpecific (const QString &SerialNumber, const QString &LinuxDevice, const QString &Model,
quint64 SectorSize, quint64 SectorSizePhys, quint64 Size)
{ //lint !e578: Declaration of symbol 'Xxx' hides symbol 't_Device::Xxx'
this->SerialNumber = SerialNumber;
this->LinuxDevice = LinuxDevice;
// this->LinuxDevice = "/data/virtualbox/knoppicilin.iso";
this->Model = Model;
this->SectorSize = SectorSize;
this->SectorSizePhys = SectorSizePhys;
this->Size = Size;
// this->Size = std::min (10737418240ULL, Size; // For faster testing (we make guymager believe that the device is smaller)
// this->Size = std::min (1073741824ULL, Size); // For faster testing (we make guymager believe that the device is smaller)
}
t_Device::t_Device (const QString &SerialNumber, const QString &LinuxDevice, const QString &Model,
quint64 SectorSize, quint64 SectorSizePhys, quint64 Size)
{ //lint !e578: Declaration of symbol 'Xxx' hides symbol 't_Device::Xxx'
Initialise ();
InitialiseDeviceSpecific (SerialNumber, LinuxDevice, Model, SectorSize, SectorSizePhys, Size);
}
t_Device::t_Device (const QString &SerialNumber, const PedDevice *pPedDev)
{ //lint !e578: Declaration of symbol 'Xxx' hides symbol 't_Device::Xxx'
Initialise ();
InitialiseDeviceSpecific (SerialNumber, pPedDev->path, pPedDev->model,
(quint64) pPedDev->sector_size, (quint64) pPedDev->phys_sector_size,
(quint64) pPedDev->length * (quint64) pPedDev->sector_size);
}
t_Device::~t_Device()
{
if (pThreadRead || pFifoRead ||
pThreadHash || pFifoHashIn ||
pThreadWrite || pFifoHashOut ||
pFileSrc || pFifoWrite )
CHK_EXIT (ERROR_DEVICE_NOT_CLEAN)
pThreadRead = NULL; pFifoRead = NULL;
pThreadHash = NULL; pFifoHashIn = NULL;
pThreadWrite = NULL; pFifoHashOut = NULL;
pFileSrc = NULL; pFifoWrite = NULL;
}
bool t_Device::HasHashThread (void) const
{
return Acquisition.CalcHashes && CONFIG (UseSeparateHashThread);
}
bool t_Device::HasCompressionThreads (void) const
{
return (CONFIG (CompressionThreads) > 0) && ((Acquisition.Format == t_File::EWF) ||
(Acquisition.Format == t_File::AFF));
}
//lint -save -e818 pDevice could have declared as pointing to const
QVariant t_Device::GetSerialNumber (t_pDevice pDevice)
{
return pDevice->SerialNumber;
}
QVariant t_Device::GetLinuxDevice (t_pDevice pDevice)
{
return pDevice->LinuxDevice;
}
QVariant t_Device::GetModel (t_pDevice pDevice)
{
return pDevice->Model;
}
QVariant t_Device::GetState (t_pDevice pDevice)
{
QString State;
switch (pDevice->State)
{
case Idle : if (pDevice->Local)
State = t_MainWindow::tr("Local device");
else State = t_MainWindow::tr("Idle");
break;
case Acquire : State = t_MainWindow::tr("Acquisition running" ); break;
case Verify : State = t_MainWindow::tr("Verification running"); break;
case AcquirePaused: State = t_MainWindow::tr("Device disconnected, acquisition paused" ); break;
case VerifyPaused : State = t_MainWindow::tr("Device disconnected, verification paused"); break;
case Cleanup : State = t_MainWindow::tr("Cleanup" ); break;
case Finished : if (pDevice->Acquisition.VerifySource)
{
if (HashMD5Match (&pDevice->MD5Digest , &pDevice->MD5DigestVerify ) &&
HashSHA256Match(&pDevice->SHA256Digest, &pDevice->SHA256DigestVerify))
State = t_MainWindow::tr("Finished - hashes verified & ok" );
else State = t_MainWindow::tr("Finished - hash verification mismatch");
}
else
{
State = t_MainWindow::tr("Finished");
}
break;
case Aborted : switch (pDevice->AbortReason)
{
case t_Device::None : State = t_MainWindow::tr("Aborted - Error: Reason is 'none'" ); break;
case t_Device::UserRequest : State = t_MainWindow::tr("Aborted by user" ); break;
case t_Device::ThreadWriteFileError: State = t_MainWindow::tr("Aborted - Image file write error" ); break;
case t_Device::ThreadReadFileError : State = t_MainWindow::tr("Aborted - Device read error" ); break;
default : CHK_EXIT (ERROR_DEVICE_BAD_ABORTREASON)
}
break;
default : CHK_EXIT (ERROR_DEVICE_BAD_STATE)
}
if (pDevice->State != Aborted)
{
QString Msg;
CHK_EXIT (pDevice->GetMessage (Msg))
if (!Msg.isEmpty())
State += " - " + Msg;
}
return State;
}
QVariant t_Device::GetSectorSize (t_pDevice pDevice)
{
return pDevice->SectorSize;
}
QVariant t_Device::GetSectorSizePhys (t_pDevice pDevice)
{
return pDevice->SectorSizePhys;
}
QVariant t_Device::GetSize (t_pDevice pDevice)
{
return pDevice->Size;
}
QVariant t_Device::GetSizeHumanFrac (t_pDevice pDevice, bool SI, int FracLen, int UnitThreshold)
{
QString SizeHuman;
const char *pUnit;
double Sz;
double Divisor;
if (SI)
Divisor = 1000.0;
else Divisor = 1024.0;
if (UnitThreshold == AutoUnitThreshold)
UnitThreshold = (int) Divisor;
Sz = pDevice->Size;
pUnit = "Byte";
if (Sz >= UnitThreshold) { Sz = Sz / Divisor; pUnit = SI ? "kB" : "KiB"; }
if (Sz >= UnitThreshold) { Sz = Sz / Divisor; pUnit = SI ? "MB" : "MiB"; }
if (Sz >= UnitThreshold) { Sz = Sz / Divisor; pUnit = SI ? "GB" : "GiB"; }
if (Sz >= UnitThreshold) { Sz = Sz / Divisor; pUnit = SI ? "TB" : "TiB"; }
if (Sz >= UnitThreshold) { Sz = Sz / Divisor; pUnit = SI ? "PB" : "PiB"; }
if (Sz >= UnitThreshold) { Sz = Sz / Divisor; pUnit = SI ? "EB" : "EiB"; }
if (Sz >= UnitThreshold) { Sz = Sz / Divisor; pUnit = SI ? "ZB" : "ZiB"; }
if (Sz >= UnitThreshold) { Sz = Sz / Divisor; pUnit = SI ? "YB" : "YiB"; }
if (FracLen == AutoFracLen)
{
if (Sz >= 100) FracLen = 0;
else if (Sz >= 10 ) FracLen = 1;
else FracLen = 2;
}
SizeHuman = MainGetpNumberLocale()->toString (Sz, 'f', FracLen) + pUnit;
return SizeHuman;
}
QVariant t_Device::GetSizeHuman (t_pDevice pDevice)
{
return GetSizeHumanFrac (pDevice, true, 1);
}
QVariant t_Device::GetBadSectorCount (t_pDevice pDevice)
{
if (!pDevice->StartTimestamp.isNull())
return pDevice->GetBadSectorCount (false);
else return "";
}
static void DeviceGetProgress (t_pDevice pDevice, quint64 *pCurrent=NULL, quint64 *pTotal=NULL)
{
quint64 Current, Total;
if (pDevice->Acquisition.VerifySource)
{
Total = 2 * pDevice->Size;
if (pDevice->StartTimestampVerify.isNull())
Current = pDevice->GetCurrentWritePos ();
else Current = pDevice->GetCurrentVerifyPos() + pDevice->Size;
}
else
{
Total = pDevice->Size;
Current = pDevice->GetCurrentWritePos();
}
if (pTotal ) *pTotal = Total;
if (pCurrent) *pCurrent = Current;
}
QVariant t_Device::GetProgress (t_pDevice pDevice)
{
quint64 Current, Total;
if (!pDevice->StartTimestamp.isNull())
{
DeviceGetProgress (pDevice, &Current, &Total);
return (double) Current / Total;
}
return -DBL_MAX;
}
QVariant t_Device::GetCurrentSpeed (t_pDevice pDevice)
{
QString Result;
QTime Now;
double MBs;
double Speed;
int MilliSeconds;
quint64 CurrentPos;
if ((pDevice->State == Acquire) || // Don't display anything if no acquisition is running
(pDevice->State == Verify ))
{
Now = QTime::currentTime();
DeviceGetProgress (pDevice, &CurrentPos);
if (!pDevice->PrevTimestamp.isNull())
{
MilliSeconds = pDevice->PrevTimestamp.msecsTo (Now); // As this fn is called within 1s-interval, time_t would not be precise enough
if (MilliSeconds > 0)
{
MBs = (double) (CurrentPos - pDevice->PrevPos) / BYTES_PER_MEGABYTE;
Speed = (1000.0*MBs) / MilliSeconds;
pDevice->PrevSpeed = (pDevice->PrevSpeed + Speed) / 2.0;
}
Result = MainGetpNumberLocale()->toString (pDevice->PrevSpeed, 'f', 2);
}
pDevice->PrevTimestamp = Now;
pDevice->PrevPos = CurrentPos;
}
return Result;
}
QVariant t_Device::GetAverageSpeed (t_pDevice pDevice)
{
QLocale Locale;
QString Result;
double MBs;
int Seconds;
quint64 CurrentPos;
if (pDevice->StartTimestamp.isNull())
return QString();
if (pDevice->StopTimestamp.isNull()) // As long as the stop timestamp is Null, the acquisition is still running
Seconds = pDevice->StartTimestamp.secsTo (QDateTime::currentDateTime());
else Seconds = pDevice->StartTimestamp.secsTo (pDevice->StopTimestamp);
if ((pDevice->StopTimestamp.isNull()) && (Seconds < DEVICE_MIN_RUNNING_SECONDS))
return "--";
DeviceGetProgress (pDevice, &CurrentPos);
MBs = ((double) CurrentPos) / BYTES_PER_MEGABYTE;
Result = Locale.toString (MBs/Seconds, 'f', 2);
return Result;
}
QVariant t_Device::GetRemaining (t_pDevice pDevice)
{
QString Result;
char Buff[10];
int TotalSeconds;
time_t Now;
int hh, mm, ss;
quint64 Current, Total;
if ((pDevice->State == Acquire) || // Don't display anything if no acquisition is running
(pDevice->State == Verify ))
{
time (&Now);
TotalSeconds = pDevice->StartTimestamp.secsTo (QDateTime::currentDateTime());
if (TotalSeconds < DEVICE_MIN_RUNNING_SECONDS)
{
Result = "--";
}
else
{
DeviceGetProgress (pDevice, &Current, &Total);
ss = (int) ((double)Total / Current * TotalSeconds); // Estimated total time
ss -= TotalSeconds; // Estimated remaining time
hh = ss / SECONDS_PER_HOUR; ss %= SECONDS_PER_HOUR;
mm = ss / SECONDS_PER_MINUTE; ss %= SECONDS_PER_MINUTE;
snprintf (Buff, sizeof(Buff), "%02d:%02d:%02d", hh, mm, ss);
Result = Buff;
}
}
return Result;
}
static inline int DeviceFifoUsage (t_pFifo pFifo)
{
int Usage;
CHK_EXIT (pFifo->Usage(Usage))
return Usage;
}
QVariant t_Device::GetFifoStatus (t_pDevice pDevice)
{
QString Result;
if ((pDevice->State == Acquire) || // Don't display anything if no acquisition is running
(pDevice->State == Verify ))
{
if (!pDevice->HasHashThread() && !pDevice->HasCompressionThreads())
{
Result = QString ("r %1 w") .arg (DeviceFifoUsage(pDevice->pFifoRead));
}
else if (!pDevice->HasHashThread() && pDevice->HasCompressionThreads())
{
Result = QString ("r %1 c %2 w") .arg (DeviceFifoUsage(pDevice->pFifoRead ))
.arg (DeviceFifoUsage(pDevice->pFifoCompressOut));
}
else if (pDevice->HasHashThread() && !pDevice->HasCompressionThreads())
{
Result = QString ("r %1 m %2 w") .arg (DeviceFifoUsage(pDevice->pFifoRead ))
.arg (DeviceFifoUsage(pDevice->pFifoHashOut));
}
else if (pDevice->HasHashThread() && pDevice->HasCompressionThreads())
{
Result = QString ("r %1 h %2 c %3 w") .arg (DeviceFifoUsage(pDevice->pFifoRead ))
.arg (DeviceFifoUsage(pDevice->pFifoHashOut ))
.arg (DeviceFifoUsage(pDevice->pFifoCompressOut));
}
}
return Result;
}
//lint -restore
// ---------------------------
// t_DeviceList
// ---------------------------
t_DeviceList::t_DeviceList(void)
:QList<t_pDevice>()
{
static bool Initialised = false;
if (!Initialised)
{
Initialised = true;
qRegisterMetaType<t_pDeviceList>("t_pDeviceList");
}
}
t_DeviceList::~t_DeviceList()
{
int i;
for (i=0; i<count(); i++)
delete at(i);
}
t_pDevice t_DeviceList::AppendNew (const QString &SerialNumber, const PedDevice *pPedDev)
{
t_pDevice pDev;
pDev = new t_Device (SerialNumber, pPedDev);
append (pDev);
return pDev;
}
t_pDevice t_DeviceList::AppendNew (const QString &SerialNumber, const QString &LinuxDevice, const QString &Model,
quint64 SectorSize, quint64 SectorSizePhys, quint64 Size)
{
t_pDevice pDev;
pDev = new t_Device (SerialNumber, LinuxDevice, Model, SectorSize, SectorSizePhys, Size);
append (pDev);
return pDev;
}
//t_pDevice t_DeviceList::SearchLinuxDevice (const QString &LinuxDevice)
//{
// t_pDevice pDev;
// int i;
//
// for (i=0; i<count(); i++)
// {
// pDev = at(i);
// if (pDev->LinuxDevice == LinuxDevice)
// return pDev;
// }
// return NULL;
//}
//
//t_pDevice t_DeviceList::SearchSerialNumber (const QString &SerialNumber)
//{
// t_pDevice pDev;
// int i;
//
// for (i=0; i<count(); i++)
// {
// pDev = at(i);
// if (pDev->SerialNumber == SerialNumber)
// return pDev;
// }
// return NULL;
//}
APIRET t_DeviceList::MatchDevice (t_pcDevice pDevCmp, t_pDevice &pDevMatch)
{
bool Found = false;
int i;
for (i=0; (i<count()) && !Found; i++)
{
pDevMatch = at(i);
if (pDevMatch->SerialNumber.isEmpty())
{
Found = (pDevCmp->SerialNumber.isEmpty() && (pDevMatch->State != t_Device::AcquirePaused) &&
(pDevMatch->State != t_Device::VerifyPaused ) &&
(pDevMatch->Model == pDevCmp->Model ) &&
(pDevMatch->Size == pDevCmp->Size ));
}
else
{
// Found = (pDevMatch->SerialNumber == pDevCmp->SerialNumber);
// if (Found)
// { // If the serial numbers match, the whole
// if (pDevMatch->Model != pDevCmp->Model) return ERROR_DEVICE_SERNR_MATCH_MODEL_MISMATCH; // rest must match as well. Otherwise,
// if (pDevMatch->Size != pDevCmp->Size ) return ERROR_DEVICE_SERNR_MATCH_LENGTH_MISMATCH; // something very strange is going on...
// }
// The comparision above cannot be used, because there are certain devices, that behave as if 2 devices aer connected when
// plugged in - with the same serial number!! Example: I once had a memory stick from Intuix, that reported 2 devices: The
// memory stick itself and a CD-Rom memory stick itself and a CD-Rom containing device drivers for some strange OS. Both
// devices had the same serial number. That's why the check now also includes the size and the model.
Found = ((pDevMatch->SerialNumber == pDevCmp->SerialNumber) &&
(pDevMatch->Size == pDevCmp->Size ) &&
(pDevMatch->Model == pDevCmp->Model));
}
}
if (!Found)
pDevMatch = NULL;
return NO_ERROR;
}
const char *t_Device::StateStr (void)
{
const char *pStr;
switch (State)
{
case Idle : pStr = "Idle"; break;
case Acquire : pStr = "Acquire"; break;
case AcquirePaused: pStr = "AcquirePaused"; break;
case Verify : pStr = "Verify"; break;
case VerifyPaused : pStr = "VerifyPaused"; break;
case Cleanup : pStr = "Cleanup"; break;
case Finished : pStr = "Finished"; break;
case Aborted : pStr = "Aborte"; break;
default : pStr = "Unknown";
}
return pStr;
}
|