@@ -36,6 +36,30 @@ typedef struct _PVP_HASH_CONTEXT
36
36
PVOID Hash ;
37
37
} PVP_HASH_CONTEXT , * PPVP_HASH_CONTEXT ;
38
38
39
+ typedef enum _PV_HASHLIST_CATEGORY
40
+ {
41
+ PV_HASHLIST_CATEGORY_FILEHASH ,
42
+ PV_HASHLIST_CATEGORY_IMPORTHASH ,
43
+ PV_HASHLIST_CATEGORY_FUZZYHASH ,
44
+ PV_HASHLIST_CATEGORY_MAXIMUM
45
+ } PV_HASHLIST_CATEGORY ;
46
+
47
+ typedef enum _PV_HASHLIST_INDEX
48
+ {
49
+ PV_HASHLIST_INDEX_CRC32 ,
50
+ PV_HASHLIST_INDEX_MD5 ,
51
+ PV_HASHLIST_INDEX_SHA1 ,
52
+ PV_HASHLIST_INDEX_SHA256 ,
53
+ PV_HASHLIST_INDEX_SHA348 ,
54
+ PV_HASHLIST_INDEX_SHA512 ,
55
+ PV_HASHLIST_INDEX_AUTHENTIHASH ,
56
+ PV_HASHLIST_INDEX_IMPHASH ,
57
+ PV_HASHLIST_INDEX_IMPHASHMSFT ,
58
+ PV_HASHLIST_INDEX_SSDEEP ,
59
+ PV_HASHLIST_INDEX_TLSH ,
60
+ PV_HASHLIST_INDEX_MAXIMUM
61
+ } PV_HASHLIST_INDEX ;
62
+
39
63
NTSTATUS fuzzy_hash_file (
40
64
_In_ HANDLE FileHandle ,
41
65
_Out_ PPH_STRING * HashResult
@@ -446,8 +470,8 @@ VOID PvpPeEnumFileHashes(
446
470
)
447
471
{
448
472
ULONG count = 0 ;
449
- INT lvItemIndex ;
450
473
HANDLE fileHandle ;
474
+ INT lvItemIndex ;
451
475
PPH_STRING crc32HashString = NULL ;
452
476
PPH_STRING md5HashString = NULL ;
453
477
PPH_STRING sha1HashString = NULL ;
@@ -462,9 +486,9 @@ VOID PvpPeEnumFileHashes(
462
486
WCHAR number [PH_PTR_STR_LEN_1 ];
463
487
464
488
ListView_EnableGroupView (ListViewHandle , TRUE);
465
- PhAddListViewGroup (ListViewHandle , 0 , L"File hashes" );
466
- PhAddListViewGroup (ListViewHandle , 1 , L"Import hashes" );
467
- PhAddListViewGroup (ListViewHandle , 2 , L"Fuzzy hashes" );
489
+ PhAddListViewGroup (ListViewHandle , PV_HASHLIST_CATEGORY_FILEHASH , L"File hashes" );
490
+ PhAddListViewGroup (ListViewHandle , PV_HASHLIST_CATEGORY_IMPORTHASH , L"Import hashes" );
491
+ PhAddListViewGroup (ListViewHandle , PV_HASHLIST_CATEGORY_FUZZYHASH , L"Fuzzy hashes" );
468
492
469
493
if (NT_SUCCESS (PhCreateFileWin32 (
470
494
& fileHandle ,
@@ -473,7 +497,7 @@ VOID PvpPeEnumFileHashes(
473
497
FILE_ATTRIBUTE_NORMAL ,
474
498
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
475
499
FILE_OPEN ,
476
- FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
500
+ FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY
477
501
)))
478
502
{
479
503
impMsftHashString = PvpGetMappedImageImphashMsft (fileHandle );
@@ -488,136 +512,179 @@ VOID PvpPeEnumFileHashes(
488
512
& sha512HashString
489
513
);
490
514
491
- //LARGE_INTEGER filePosition;
492
- //filePosition.QuadPart = 0;
493
- //PhSetFilePosition(fileHandle, &filePosition);
494
- //
495
- //fuzzy_hash_file(fileHandle, &ssdeepHashString);
496
-
497
- fuzzy_hash_buffer (
498
- PvMappedImage .ViewBase ,
499
- PvMappedImage .Size ,
500
- & ssdeepHashString
501
- );
515
+ PhSetFilePosition (fileHandle , NULL );
516
+ fuzzy_hash_file (fileHandle , & ssdeepHashString );
502
517
503
- PvGetTlshBufferHash (
504
- PvMappedImage .ViewBase ,
505
- PvMappedImage .Size ,
506
- & tlshHashString
507
- );
518
+ PhSetFilePosition (fileHandle , NULL );
519
+ PvGetTlshFileHash (fileHandle , & tlshHashString );
508
520
509
521
NtClose (fileHandle );
510
522
}
511
523
512
- if (! PhIsNullOrEmptyString (crc32HashString ))
524
+ if (PhIsNullOrEmptyString (ssdeepHashString ))
513
525
{
514
- PhPrintUInt32 (number , ++ count );
515
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 0 , MAXINT , number , NULL );
526
+ fuzzy_hash_buffer (PvMappedImage .ViewBase , PvMappedImage .Size , & ssdeepHashString );
527
+ }
528
+
529
+ if (PhIsNullOrEmptyString (tlshHashString ))
530
+ {
531
+ PvGetTlshBufferHash (PvMappedImage .ViewBase , PvMappedImage .Size , & tlshHashString );
532
+ }
516
533
517
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"CRC32" );
534
+ PhPrintUInt32 (number , ++ count );
535
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FILEHASH , PV_HASHLIST_INDEX_CRC32 , number , NULL );
536
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"CRC32" );
537
+
538
+ if (!PhIsNullOrEmptyString (crc32HashString ))
539
+ {
518
540
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (crc32HashString ));
519
541
PhDereferenceObject (crc32HashString );
520
542
}
543
+ else
544
+ {
545
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
546
+ }
547
+
548
+ PhPrintUInt32 (number , ++ count );
549
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FILEHASH , PV_HASHLIST_INDEX_MD5 , number , NULL );
550
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"MD5" );
521
551
522
552
if (!PhIsNullOrEmptyString (md5HashString ))
523
553
{
524
- PhPrintUInt32 (number , ++ count );
525
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 0 , MAXINT , number , NULL );
526
-
527
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"MD5" );
528
554
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (md5HashString ));
529
555
PhDereferenceObject (md5HashString );
530
556
}
557
+ else
558
+ {
559
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
560
+ }
561
+
562
+ PhPrintUInt32 (number , ++ count );
563
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FILEHASH , PV_HASHLIST_INDEX_SHA1 , number , NULL );
564
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SHA-1" );
531
565
532
566
if (!PhIsNullOrEmptyString (sha1HashString ))
533
567
{
534
- PhPrintUInt32 (number , ++ count );
535
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 0 , MAXINT , number , NULL );
536
-
537
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SHA-1" );
538
568
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (sha1HashString ));
539
569
PhDereferenceObject (sha1HashString );
540
570
}
571
+ else
572
+ {
573
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
574
+ }
575
+
576
+ PhPrintUInt32 (number , ++ count );
577
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FILEHASH , PV_HASHLIST_INDEX_SHA256 , number , NULL );
578
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SHA-256" );
541
579
542
580
if (!PhIsNullOrEmptyString (sha2HashString ))
543
581
{
544
- PhPrintUInt32 (number , ++ count );
545
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 0 , MAXINT , number , NULL );
546
-
547
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SHA-256" );
548
582
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (sha2HashString ));
549
583
PhDereferenceObject (sha2HashString );
550
584
}
585
+ else
586
+ {
587
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
588
+ }
589
+
590
+ PhPrintUInt32 (number , ++ count );
591
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FILEHASH , PV_HASHLIST_INDEX_SHA348 , number , NULL );
592
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SHA-384" );
551
593
552
594
if (!PhIsNullOrEmptyString (sha384HashString ))
553
595
{
554
- PhPrintUInt32 (number , ++ count );
555
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 0 , MAXINT , number , NULL );
556
-
557
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SHA-384" );
558
596
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (sha384HashString ));
559
597
PhDereferenceObject (sha384HashString );
560
598
}
599
+ else
600
+ {
601
+
602
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
603
+ }
604
+
605
+ PhPrintUInt32 (number , ++ count );
606
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FILEHASH , PV_HASHLIST_INDEX_SHA512 , number , NULL );
607
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SHA-512" );
561
608
562
609
if (!PhIsNullOrEmptyString (sha512HashString ))
563
610
{
564
- PhPrintUInt32 (number , ++ count );
565
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 0 , MAXINT , number , NULL );
566
-
567
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SHA-512" );
568
611
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (sha512HashString ));
569
612
PhDereferenceObject (sha512HashString );
570
613
}
614
+ else
615
+ {
616
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
617
+ }
618
+
619
+ PhPrintUInt32 (number , ++ count );
620
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FILEHASH , PV_HASHLIST_INDEX_AUTHENTIHASH , number , NULL );
621
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"Authentihash" );
571
622
572
623
if (authentihashString = PvpGetMappedImageAuthentihash ())
573
624
{
574
- PhPrintUInt32 (number , ++ count );
575
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 0 , MAXINT , number , NULL );
576
-
577
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"Authentihash" );
578
625
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (authentihashString ));
579
626
PhDereferenceObject (authentihashString );
580
627
}
581
-
582
- if (imphashString = PvpGetMappedImageImphash ())
628
+ else
583
629
{
584
- PhPrintUInt32 ( number , ++ count );
585
- lvItemIndex = PhAddListViewGroupItem ( ListViewHandle , 1 , MAXINT , number , NULL );
630
+ PhSetListViewSubItem ( ListViewHandle , lvItemIndex , 2 , L"ERROR" );
631
+ }
586
632
587
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"Imphash" );
633
+ PhPrintUInt32 (number , ++ count );
634
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_IMPORTHASH , PV_HASHLIST_INDEX_IMPHASH , number , NULL );
635
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"Imphash" );
636
+
637
+ if (imphashString = PvpGetMappedImageImphash ())
638
+ {
588
639
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (imphashString ));
589
640
PhDereferenceObject (imphashString );
590
641
}
642
+ else
643
+ {
644
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
645
+ }
646
+
647
+ PhPrintUInt32 (number , ++ count );
648
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_IMPORTHASH , PV_HASHLIST_INDEX_IMPHASHMSFT , number , NULL );
649
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"Imphash (msft)" );
591
650
592
651
if (!PhIsNullOrEmptyString (impMsftHashString ))
593
652
{
594
- PhPrintUInt32 (number , ++ count );
595
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 1 , MAXINT , number , NULL );
596
-
597
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"Imphash (msft)" );
598
653
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (impMsftHashString ));
599
654
PhDereferenceObject (impMsftHashString );
600
655
}
656
+ else
657
+ {
658
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
659
+ }
660
+
661
+ PhPrintUInt32 (number , ++ count );
662
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FUZZYHASH , PV_HASHLIST_INDEX_SSDEEP , number , NULL );
663
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SSDEEP" );
601
664
602
665
if (!PhIsNullOrEmptyString (ssdeepHashString ))
603
666
{
604
- PhPrintUInt32 (number , ++ count );
605
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 2 , MAXINT , number , NULL );
606
-
607
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"SSDEEP" );
608
667
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (ssdeepHashString ));
609
668
PhDereferenceObject (ssdeepHashString );
610
669
}
670
+ else
671
+ {
672
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
673
+ }
674
+
675
+ PhPrintUInt32 (number , ++ count );
676
+ lvItemIndex = PhAddListViewGroupItem (ListViewHandle , PV_HASHLIST_CATEGORY_FUZZYHASH , PV_HASHLIST_INDEX_TLSH , number , NULL );
677
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"TLSH" );
611
678
612
679
if (!PhIsNullOrEmptyString (tlshHashString ))
613
680
{
614
- PhPrintUInt32 (number , ++ count );
615
- lvItemIndex = PhAddListViewGroupItem (ListViewHandle , 2 , MAXINT , number , NULL );
616
-
617
- PhSetListViewSubItem (ListViewHandle , lvItemIndex , 1 , L"TLSH" );
618
681
PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , PhGetString (tlshHashString ));
619
682
PhDereferenceObject (tlshHashString );
620
683
}
684
+ else
685
+ {
686
+ PhSetListViewSubItem (ListViewHandle , lvItemIndex , 2 , L"ERROR" );
687
+ }
621
688
}
622
689
623
690
typedef struct _PV_PE_HASH_CONTEXT
0 commit comments