forked from tedsmith/quickhash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit2.pas
executable file
·5110 lines (4633 loc) · 199 KB
/
unit2.pas
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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
Quick Hash - A Linux, Windows and Apple Mac OSX GUI for quickly selecting one or more files
and generating hash values for them.
Copyright (C) 2011-2020 Ted Smith www.quickhash-gui.org
The use of the word 'quick' refers to the ease in which the software operates
in both Linux, Apple Mac and Windows (very few options to worry about, no
syntax to remember etc) though tests suggest that in most cases the hash
values are generated as quick or quicker than most mainstream tools.
The user should be aware of other data hashing tools and use them to cross-check
findings for critical data :
md5sum, sha1sum, sha256sum and sha512sum (for Linux),
FTK Imager, X-Ways Forensics, WinHex, EnCase, FTK (Windows) and many more
Benchmark tests are welcomed.
Contributions from members at the Lazarus forums, Stackoverflow and other
StackExchnage groups are welcomed and acknowledged. Contributions from
DaReal Shinji are also welcomed and acknowledged, particularly helping with
Debian package creation and ideas
NOTE: Date and time values, as computed in recursive directory hashing, are not
daylight saving time adjusted. Source file date and time values are recorded.
Open-Source license:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version. This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You can read a copy of the GNU General Public License at
http://www.gnu.org/licenses/>. Also, http://www.gnu.org/copyleft/gpl.html
Use of the name 'QuickHash GUI' must refer to this utility
only and must not be re-used in another tool if based upon this code.
The code is Copyright of Ted Smith 2011 - 2019 (www.quickhash-gui.org)
HashLib4Pascal and xxHash64 libraries are both licensed under the MIT License
https://opensource.org/licenses/MIT
HashLib4Pascal : https://github.com/Xor-el/HashLib4Pascal and developed by
Github user Xor-el (Ugochukwu Stanley). Use of the
library is welcomed and acknowledged and very much appreciated,
as is the help that was offered by the developer of said library
xxHash64 : https://github.com/Cyan4973/xxHash and http://cyan4973.github.io/xxHash/
Github user Cyan4973. Use of the library is also welcomed and acknowledged
and very much appreciated
BLAKE2 is specified in RFC 7693, and available on GitHub.
It is licensed under CC0 (public domain-like) and made available only in 256 bit mode
in QuickHash-GUI (first appearing in v3.1.0) for now.
SHA-3 is made available only in 256 bit mode in QuickHash-GUI
(first appearing in v3.1.0) for now.
QuickHash is created using the Freepascal Compiler and Lazarus-IDE
http://www.lazarus-ide.org/ developed by Sourceforge users :
mgaertner,
mhess,
user4martin,
vlx,
vsnijders
QuickHash was first registered on sourceforge on 29th May 2011 and was later
migrated to the domain www.quickhash-gui.org in December 2016.
Read more about it's development history online at :
https://quickhash-gui.org/about-quickhash-gui/
}
unit Unit2; // Unit 1 was superseeded with v2.0.0
{$mode objfpc}{$H+} // {$H+} ensures strings are of unlimited size
interface
uses
{$IFDEF UNIX}
{$IFDEF UseCThreads}
cthreads,
{$ENDIF}
{$ENDIF}
{$IFNDEF Linux}
Strutils,
{$ENDIF}
Classes, SysUtils, FileUtil, LResources, Forms, Controls,
Graphics, Dialogs, StdCtrls, Menus, ComCtrls, LazUTF8, LazUTF8Classes,
LazFileUtils, Grids, ExtCtrls, sysconst, lclintf, ShellCtrls,
XMLPropStorage, diskmodule,
clipbrd, DBGrids, DbCtrls, ZVDateTimePicker, frmAboutUnit, base64,
FindAllFilesEnhanced, // an enhanced version of FindAllFiles, to ensure hidden files are found, if needed
// New as of v2.8.0 - HashLib4Pascal Unit, superseeds DCPCrypt.
HlpHashFactory,
HlpIHash,
HlpIHashResult,
HlpBlake3,
// New as of v3.0.0
dbases_sqlite, uDisplayGrid,
// New as of v3.2.0
udisplaygrid3,
// Also new as of v3.0.0, for creating hash lists for faster comparisons of two folders
contnrs,
// Also new as of v3.0.0, for importing hash lists
uKnownHashLists,
// Remaining Uses clauses for specific OS's
{$IFDEF Windows}
Windows,
// For Windows, this is a specific disk hashing tab for QuickHash. Not needed for Linux
types;
{$ENDIF}
{$IFDEF Darwin}
MacOSAll;
{$else}
{$IFDEF UNIX and !$ifdef Darwin}
UNIX;
{$ENDIF}
{$ENDIF}
{ Deprecated uses clauses, discarded as a result of migrating to HashLib4Pascal
with QuickHash v2.8.0 in Feb 2017.
// previously we had to use a customised MD5 & SHA-1 library to process Unicode on Windows and
// to run a customised MD5Transform and SHA1Transform function that was converted to assembly.
// No longer needed but the source code remains in the project because the
// Assembly transforms that forum user Engkin helped me with rocked!
md5customised,
sha1customised,
// The DCPCrypt library was used for SHA256 and SHA512 which are not part of FPC
// but as of v2.80, DCPCrypt was discarded in favour of HashLib4Pascal
DCPsha512, DCPsha256, DCPsha1, DCPmd5,
}
type
{ TMainForm }
MEMORYSTATUSEX = record
dwLength : DWORD;
dwMemoryLoad : DWORD;
ullTotalPhys : uint64;
ullAvailPhys : uint64;
ullTotalPageFile : uint64;
ullAvailPageFile : uint64;
ullTotalVirtual : uint64;
ullAvailVirtual : uint64;
ullAvailExtendedVirtual : uint64;
end;
TMainForm = class(TForm)
AlgorithmChoiceRadioBox1 : TRadioGroup;
AlgorithmChoiceRadioBox2 : TRadioGroup;
AlgorithmChoiceRadioBox3 : TRadioGroup;
AlgorithmChoiceRadioBox4 : TRadioGroup;
AlgorithmChoiceRadioBox5 : TRadioGroup;
AlgorithmChoiceRadioBox6 : TRadioGroup;
AlgorithmChoiceRadioBox7 : TRadioGroup;
b64FileGridPopupMenu : TPopupMenu;
b64DecoderProgress : TEdit;
b64StringGrid2FileS : TStringGrid;
btnClearTextArea : TButton;
btnCompare : TButton;
btnCompareTwoFiles : TButton;
btnCompareTwoFilesSaveAs : TButton;
btnFileACompare : TButton;
btnFileBCompare : TButton;
btnFLBL : TButton;
btnHashFile : TButton;
btnLBL : TButton;
btnRecursiveDirectoryHashing : TButton;
btnClipboardResults : TButton;
btnCallDiskHasherModule : TButton;
btnStopScan1 : TButton;
btnStopScan2 : TButton;
btnClearHashField : TButton;
btnB64FileChooser : TButton;
btnB64FileSChooser : TButton;
btnB64JustDecodeFiles : TButton;
btnMakeTextUpper : TButton;
btnMakeTextLower : TButton;
btnLoadHashList : TButton;
Button8CopyAndHash : TButton;
cbFlipCaseFILE : TCheckBox;
cbToggleInputDataToOutputFile : TCheckBox;
b64ProgressFileS : TEdit;
cbFlipCaseTEXT : TCheckBox;
cbUNCModeCompFolders : TCheckBox;
cbSaveComparisons : TCheckBox;
cbLoadHashList : TCheckBox;
edtUNCPathCompareA : TEdit;
edtUNCPathCompareB : TEdit;
FileSDBNavigator : TDBNavigator;
lblTotalFileCountNumberA : TLabel;
lblTotalFileCountA : TLabel;
lblCompareTwoFoldersInstruction1 : TLabel;
lblCompareTwoFoldersInstruction2 : TLabel;
lblTotalFileCountB : TLabel;
lblTotalFileCountNumberB : TLabel;
memFolderCompareSummary : TMemo;
MenuItem_CopyAllHashesToClipboardFILES: TMenuItem;
MenuItem_FilterOutYes : TMenuItem;
MenuItem_FilterOutNo : TMenuItem;
MenuItem_SortByHashList : TMenuItem;
MenuItem_SortByID : TMenuItem;
MenuItem_DeleteDups : TMenuItem;
MenuItem_SaveFILESTabToHTML : TMenuItem;
MenuItem_CopyGridToClipboardFILES : TMenuItem;
MenuItem_CopySelectedRow : TMenuItem;
MenuItem_SaveToHTML : TMenuItem;
HashListChooserDialog : TOpenDialog;
pbCompareDirA : TProgressBar;
pbCompareDirB : TProgressBar;
RecursiveDisplayGrid1 : TDBGrid;
MenuItem_CopyFilepathOfSelectedCell : TMenuItem;
MenuItem_CopyHashOfSelectedCell : TMenuItem;
MenuItem_CopyFileNameOfSelectedCell : TMenuItem;
MenuItem_CopySelectedRowFILESTAB : TMenuItem;
MenuItem_SortByFilePath : TMenuItem;
MenuItem_SortByFilename : TMenuItem;
MenuItem_SortByHash : TMenuItem;
MenuItem_RestoreListFILES : TMenuItem;
MenuItem_SaveToCSV : TMenuItem;
MenuItem_ShowDuplicates : TMenuItem;
popmenuDBGrid_Files : TPopupMenu;
lblPercentageProgressFileTab : TLabel;
lblB64Warning : TLabel;
lblB64DecoderWarning : TLabel;
lblNoOfFilesToExamine2 : TLabel;
lblschedulertickboxCompareTab : TCheckBox;
lblschedulertickboxCompareDirsTab : TCheckBox;
lblschedulertickboxFileSTab : TCheckBox;
lblschedulertickboxCopyTab : TCheckBox;
lblschedulertickboxFileTab : TCheckBox;
edtFileBName : TEdit;
edtFileAName : TEdit;
FileTypeMaskCheckBox2 : TCheckBox;
chkUNCMode : TCheckBox;
chkHiddenFiles : TCheckBox;
chkCopyHidden : TCheckBox;
CheckBoxListOfDirsAndFilesOnly : TCheckBox;
CheckBoxListOfDirsOnly : TCheckBox;
chkNoRecursiveCopy : TCheckBox;
chkNoPathReconstruction : TCheckBox;
chkRecursiveDirOverride : TCheckBox;
CopyFilesHashingGroupBox : TGroupBox;
DirectoryHashingGroupBox : TGroupBox;
DirSelectedField : TEdit;
Edit2SourcePath : TEdit;
Edit3DestinationPath : TEdit;
FileHashingGroupBox : TGroupBox;
edtFileNameToBeHashed : TEdit;
FileMaskField : TEdit;
FileMaskField2 : TEdit;
FileTypeMaskCheckBox1 : TCheckBox;
GroupBox1 : TGroupBox;
GroupBox2 : TGroupBox;
GroupBox4 : TGroupBox;
GroupBox5 : TGroupBox;
Label15 : TLabel;
lbEndedFileAt : TLabel;
MainMenu1 : TMainMenu;
MenuItem1 : TMenuItem;
MenuItem2 : TMenuItem;
MenuItem2A : TMenuItem;
MenuItem1C : TMenuItem;
MenuItem1A : TMenuItem;
MenuItem1B : TMenuItem;
b64FileChooserDialog : TOpenDialog;
MenuItem3 : TMenuItem;
MenuItem4 : TMenuItem;
MenuItem5 : TMenuItem;
MenuItem6 : TMenuItem;
pbFileS : TProgressBar;
pbCopy : TProgressBar;
b64FilesGridPopupMenu : TPopupMenu;
b64SaveDialog : TSaveDialog;
pbFile : TProgressBar;
FilesDBGrid_SaveCSVDialog : TSaveDialog;
FilesSaveAsHTMLDialog : TSaveDialog;
SaveDialog8_SaveJustHashes : TSaveDialog;
sdFileAndFolderListOnly : TSaveDialog;
sdHashListLookupResults : TSaveDialog;
SaveErrorsCompareDirsSaveDialog8 : TSaveDialog;
b64FileSChooserDialog : TSelectDirectoryDialog;
b64FileSSourceDecoderDialog : TSelectDirectoryDialog;
b64FileSDestinationDecoderDialog : TSelectDirectoryDialog;
ShellTreeView_FolderA : TShellTreeView;
ShellTreeView_FolderB : TShellTreeView;
StatusBar6 : TStatusBar;
b64StringGrid1File : TStringGrid;
SystemRAMGroupBox : TGroupBox;
ImageList1 : TImageList;
lblRAM : TLabel;
lbleExpectedHash : TLabeledEdit;
lbleExpectedHashText : TLabeledEdit;
lblURLBanner : TLabel;
Label8 : TLabel;
Label9 : TLabel;
lblFolderAName : TLabel;
lblFolderBName : TLabel;
lblFileAHash : TLabel;
lblFileBHash : TLabel;
lblFilesCopiedPercentage : TLabel;
lblDataCopiedSoFar : TLabel;
lblHashMatchResult : TLabel;
lblNoOfFilesToExamine : TLabel;
lblPercentageComplete : TLabel;
lblTotalBytesExamined : TLabel;
lblFilesExamined : TLabel;
lblNoFilesInDir : TLabel;
lblDragAndDropNudge : TLabel;
lblDiskHashingRunAsAdminWarning : TLabel;
lblStatusA : TLabel;
Label11 : TLabel;
Label12 : TLabel;
Label13 : TLabel;
lblTimeTaken6C : TLabel;
lblTimeTaken5C : TLabel;
lblTimeTaken6A : TLabel;
lblTimeTaken6B : TLabel;
lblTimeTaken5B : TLabel;
lblTimeTaken5A : TLabel;
lblTimeTaken4 : TLabel;
lblTimeTaken3 : TLabel;
Label2 : TLabel;
Label4 : TLabel;
Label5 : TLabel;
Label6 : TLabel;
lblStartedFileAt : TLabel;
lblFileTimeTaken : TLabel;
memFileHashField : TMemo;
FLBLDialog : TOpenDialog;
SaveDialog5 : TSaveDialog;
SaveDialog6 : TSaveDialog;
SaveDialog7 : TSaveDialog;
SelectDirectoryDialog4 : TSelectDirectoryDialog;
SelectDirectoryDialog5 : TSelectDirectoryDialog;
DirListA : TShellTreeView;
DirListB : TShellTreeView;
StatusBar1 : TStatusBar;
StatusBar2 : TStatusBar;
StatusBar3 : TStatusBar;
StatusBar4 : TStatusBar;
StrHashValue : TMemo;
memoHashText : TMemo;
NoOfFilesExamined : TEdit;
OpenDialog1 : TOpenDialog;
PageControl1 : TPageControl;
Panel1CopyAndHashOptions : TPanel;
PercentageComplete : TLabel;
SaveDialog1 : TSaveDialog;
SaveDialog2 : TSaveDialog;
SaveDialog3 : TSaveDialog;
SaveDialog4 : TSaveDialog;
SaveToCSVCheckBox2 : TCheckBox;
SaveFILESTabToHTMLCheckBox2 : TCheckBox;
SelectDirectoryDialog1 : TSelectDirectoryDialog;
SelectDirectoryDialog2 : TSelectDirectoryDialog;
SelectDirectoryDialog3 : TSelectDirectoryDialog;
sysRAMTimer : TTimer;
TabSheet1 : TTabSheet;
TabSheet2 : TTabSheet;
TabSheet3 : TTabSheet;
TabSheet4 : TTabSheet;
TabSheet5 : TTabSheet;
TabSheet6 : TTabSheet;
TabSheet7 : TTabSheet;
TabSheet8 : TTabSheet;
TextHashingGroupBox : TGroupBox;
QH_MainFormXMLPropStorage : TXMLPropStorage;
SchedulerTimer : TTimer;
TextHashingGroupBox1 : TGroupBox;
ZVDateTimePickerCompareDirsTab : TZVDateTimePicker;
ZVDateTimePickerCopyTab : TZVDateTimePicker;
ZVDateTimePickerCompareTab : TZVDateTimePicker;
ZVDateTimePickerFileTab : TZVDateTimePicker;
ZVDateTimePickerFileSTab : TZVDateTimePicker;
// Procedures
procedure AlgorithmChoiceRadioBox1Click(Sender: TObject);
procedure AlgorithmChoiceRadioBox2Click(Sender: TObject);
procedure AlgorithmChoiceRadioBox3Click(Sender: TObject);
procedure AlgorithmChoiceRadioBox7Click(Sender: TObject);
procedure AlgorithmChoiceRadioBox4Click(Sender: TObject);
procedure AlgorithmChoiceRadioBox5Click(Sender: TObject);
procedure AlgorithmChoiceRadioBox6Click(Sender: TObject);
procedure btnB64FileSChooserClick(Sender: TObject);
procedure btnClearHashFieldClick(Sender: TObject);
procedure btnClearHashFieldKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure btnB64FileChooserClick(Sender: TObject);
procedure btnB64JustDecodeFilesClick(Sender: TObject);
procedure btnLoadHashListClick(Sender: TObject);
procedure btnMakeTextLowerClick(Sender: TObject);
procedure btnMakeTextUpperClick(Sender: TObject);
procedure cbFlipCaseFILEChange(Sender: TObject);
procedure cbFlipCaseTEXTChange(Sender: TObject);
procedure cbLoadHashListChange(Sender: TObject);
procedure cbToggleInputDataToOutputFileChange(Sender: TObject);
procedure cbUNCModeCompFoldersChange(Sender: TObject);
procedure edtUNCPathCompareAChange(Sender: TObject);
procedure edtUNCPathCompareBChange(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure lblDonateClick(Sender: TObject);
procedure lbleExpectedHashChange(Sender: TObject);
procedure lbleExpectedHashEnter(Sender: TObject);
procedure lbleExpectedHashTextChange(Sender: TObject);
procedure lblFileAHashClick(Sender: TObject);
procedure lblFileBHashClick(Sender: TObject);
procedure lblschedulertickboxFileSTabChange(Sender: TObject);
procedure lblschedulertickboxFileTabChange(Sender: TObject);
procedure lblschedulertickboxCopyTabChange(Sender: TObject);
procedure lblschedulertickboxCompareTabChange(Sender: TObject);
procedure lblschedulertickboxCompareTwoDirectoriesTabChange(Sender: TObject);
procedure MenuItem1AClick(Sender: TObject);
procedure MenuItem1Click(Sender: TObject);
procedure MenuItem2AClick(Sender: TObject);
procedure MenuItem1CClick(Sender: TObject);
procedure MenuItem3Click(Sender: TObject);
procedure MenuItem4Click(Sender: TObject);
procedure MenuItem5Click(Sender: TObject);
procedure MenuItem6Click(Sender: TObject);
procedure MenuItem_CopyAllHashesToClipboardFILESClick(Sender: TObject);
procedure MenuItem_DeleteDupsClick(Sender: TObject);
procedure MenuItem_CopyGridToClipboardFILESClick(Sender: TObject);
procedure MenuItem_CopyHashOfSelectedCellClick(Sender: TObject);
procedure MenuItem_CopyFilepathOfSelectedCellClick(Sender: TObject);
procedure MenuItem_CopyFileNameOfSelectedCellClick(Sender: TObject);
procedure MenuItem_CopySelectedRowFILESTABClick(Sender: TObject);
procedure MenuItem_FilterOutNoClick(Sender: TObject);
procedure MenuItem_FilterOutYesClick(Sender: TObject);
procedure MenuItem_RestoreListFILESClick(Sender: TObject);
procedure MenuItem_SaveToCSVClick(Sender: TObject);
procedure MenuItem_SaveToHTMLClick(Sender: TObject);
procedure MenuItem_ShowDuplicatesClick(Sender: TObject);
procedure MenuItem_SortByFilenameClick(Sender: TObject);
procedure MenuItem_SortByFilePathClick(Sender: TObject);
procedure MenuItem_SortByHashClick(Sender: TObject);
procedure MenuItem_SortByHashListClick(Sender: TObject);
procedure MenuItem_SortByIDClick(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure Panel1CopyAndHashOptionsClick(Sender: TObject);
procedure popmenuDBGrid_FilesPopup(Sender: TObject);
procedure ShellTreeView_FolderAChange(Sender: TObject; Node: TTreeNode);
procedure ShellTreeView_FolderBChange(Sender: TObject; Node: TTreeNode);
procedure sysRAMTimerTimer(Sender: TObject);
procedure AlgorithmChoiceRadioBox2SelectionChanged(Sender: TObject);
procedure AlgorithmChoiceRadioBox5SelectionChanged(Sender: TObject);
procedure btnClipboardHashValueClick(Sender: TObject);
procedure btnCompareTwoFilesClick(Sender: TObject);
procedure btnCompareTwoFilesSaveAsClick(Sender: TObject);
procedure btnDirAClick(Sender: TObject);
procedure btnDirBClick(Sender: TObject);
procedure btnFileACompareClick(Sender: TObject);
procedure btnFileBCompareClick(Sender: TObject);
//procedure btnHashTextClick(Sender: TObject);
procedure btnHashFileClick(Sender: TObject);
procedure btnLaunchDiskModuleClick(Sender: TObject);
procedure btnLBLClick(Sender: TObject);
procedure btnRecursiveDirectoryHashingClick(Sender: TObject);
procedure btnStopScan1Click(Sender: TObject);
procedure btnClipboardResultsClick(Sender: TObject);
procedure btnStopScan2Click(Sender: TObject);
procedure btnCallDiskHasherModuleClick(Sender: TObject);
procedure btnCompareClick(Sender: TObject);
procedure btnClearTextAreaClick(Sender: TObject);
procedure btnFLBLClick(Sender: TObject);
procedure Button8CopyAndHashClick(Sender: TObject);
procedure CheckBoxListOfDirsAndFilesOnlyChange(Sender: TObject);
procedure CheckBoxListOfDirsOnlyChange(Sender: TObject);
procedure chkUNCModeChange(Sender: TObject);
procedure DirListAClick(Sender: TObject);
procedure DirListBClick(Sender: TObject);
procedure Edit2SourcePathEnter(Sender: TObject);
procedure Edit3DestinationPathEnter(Sender: TObject);
procedure FileTypeMaskCheckBox1Change(Sender: TObject);
procedure FileTypeMaskCheckBox2Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
procedure HashFile(FileIterator: TFileIterator);
procedure lblURLBannerClick(Sender: TObject);
procedure ProcessDir(SourceDirName: string);
procedure CompareTwoHashes(FileAHash, FileBHash : string);
procedure HashText(Sender: TObject);
procedure ClearText(Sender: TObject);
procedure TabSheet6ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure SHA1RadioButton3Change(Sender: TObject);
procedure TabSheet1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure TabSheet3ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure SaveOutputAsCSV(Filename : string; GridName : TStringGrid);
procedure EmptyDisplayGrid(Grid : TStringGrid);
procedure CheckSchedule(DesiredStartTime : TDateTime);
procedure InvokeScheduler(Sender : TObject);
procedure CommitCount(Sender : TObject);
// Functions
function RoundToNearest(TheDateTime,TheRoundStep:TDateTime):TdateTime;
function ValidateTextWithHash(strToBeHashed:ansistring): string;
function CalcTheHashString(strToBeHashed:ansistring):string;
function CalcTheHashFile(FileToBeHashed:string):string;
function FormatByteSize(const bytes: QWord): string;
function RemoveLongPathOverrideChars(strPath : string; LongPathOverrideVal : string) : string;
function RetrieveFileList(FolderName : string) : TStringList;
function HashFolderListA(Path : string; slFileListA : TStringList; intFileCount : integer; SaveData : Boolean) : TFPHashList;
function HashFolderListB(Path : string; slFileListB : TStringList; intFileCount : integer; SaveData : Boolean) : TFPHashList;
function CompareHashLists(aHashList1, aHashlist2: TFPHashList): Boolean;
function ComputeWhatHashesAreMissing(aHashList1, aHashList2 : TFPHashList) : TStringList;
function GetSubDirListing(FolderName : string) : TStringList;
function GetSubDirAndFileListing(FolderName : string) : TStringList;
// function FileSizeWithLongPath(strFileName : string) : Int64;
{$IFDEF Windows}
function DateAttributesOfCurrentFile(var SourceDirectoryAndFileName:string):string;
function FileTimeToDTime(FTime: TFileTime): TDateTime;
function GetSystemMem: string; { Returns installed RAM (as viewed by your OS) in GB, with 2 decimals }
{$ENDIF}
{$IFDEF LINUX}
function DateAttributesOfCurrentFileLinux(var SourceDirectoryAndFileName:string):string;
{$ENDIF}
{$ifdef UNIX}
{$ifdef Darwin}
function DateAttributesOfCurrentFileLinux(var SourceDirectoryAndFileName:string):string;
{$ENDIF}
{$ENDIF}
function CustomisedForceDirectoriesUTF8(const Dir: string; PreserveTime: Boolean): Boolean;
private
// Global handle exception controller, courtesy of GetMem from the forums
// http://forum.lazarus.freepascal.org/index.php/topic,39842.0.html
procedure HandleExceptions(Sender: TObject; E: Exception);
{ private declarations }
public
{ public declarations }
FileCounter, NoOfFilesInDir2: integer; // Used jointly by Button3Click and Hashfile procedures
CommitFrequencyChecker, tmp : integer; // To keep track of SQLite commits
TotalBytesRead : UInt64;
StopScan1, StopScan2, SourceDirValid, DestDirValid : Boolean;
SourceDir, DestDir : string; // For the joint copy and hash routines
DirA, DirB : string;
sValue1 : string; // Set by GetWin32_DiskDriveInfo then used by ListDisks OnClick event - Windows only
slMultipleDirNames : TStringList;
fsSaveFolderComparisonsLogFile : TFileStream;
MultipleDirsChosen, StartHashing : boolean;
{$IFDEF WINDOWS}
// For copying better with 260 MAX_PATH limits of Windows. Instead we invoke Unicode
// variant of FindAllFiles by using '\\?\' and '\\?\UNC\' prefixes. LongPathOverride
// will always either be '\\?\' or '\\?\UNC\'
LongPathOverride : string;
{$else}
{$IFDEF Darwin}
const
LongPathOverride : string = ''; // MAX_PATH is 4096 is Linux & Mac, so not needed
LongPathOverrideA : string = '';
LongPathOverrideB : string = '';
{$else}
{$IFDEF UNIX and !$ifdef Darwin}
const
LongPathOverride : string = '';
LongPathOverrideA : string = '';
LongPathOverrideB : string = '';
{$ENDIF}
{$ENDIF}
{$ENDIF}
end;
var
MainForm: TMainForm;
{$R *.lfm}
implementation
procedure TMainForm.HandleExceptions(Sender: TObject; E: Exception);
begin
// see http://forum.lazarus.freepascal.org/index.php/topic,39842.0.html
end;
// Global function, CommitCount, keeps track of file counts and updates the SQLIte DB periodically
// to avoid unnecessary database commits, which slow it down
procedure TMainForm.CommitCount(Sender : TObject);
begin
inc(CommitFrequencyChecker, 1);
if CommitFrequencyChecker = 1000 then
begin
frmSQLiteDBases.SQLTransaction1.CommitRetaining;
CommitFrequencyChecker := 0;
end;
end;
{$IFDEF WINDOWS}
// Populate interface with quick view to RAM status
function GlobalMemoryStatusEx(var Buffer: MEMORYSTATUSEX): BOOL; stdcall; external 'kernel32' name 'GlobalMemoryStatusEx';
{$ENDIF}
{ TMainForm }
procedure TMainForm.FormCreate(Sender: TObject);
var
x, y : integer;
begin
x := screen.Width;
y := screen.Height;
tmp := 1;
{No longer needed since v3.2.0 due to implementing "LCL Scaling" in project options
but lets keep it here for now in case users report issues
if x < MainForm.Width then
begin
MainForm.Width := x - 50;
frmDisplayGrid1.Width := MainForm.Width - 20;
frmDisplayGrid3.Width := MainForm.Width - 20;
end;
if y < MainForm.Height then
begin
Mainform.Height := y - 50;
frmDisplayGrid1.Width := MainForm.Width - 20;
frmDisplayGrid3.Width := MainForm.Width - 20;
end;
}
StartHashing := false;
StopScan1 := false;
StopScan2 := false;
{$ifdef Windows}
// These are the default values to be prefixed before a path to invoke the 32K
// NTFS filename length over the 260 MAX_PATH. Where the user opts for UNC paths
// as well, it becomes '\\?\UNC\'
LongPathOverride := '\\?\';
{$endif}
// In Lazarus versions < 1.4.4, the 'FileSortType' property of ShellTreeViews
// would cause the listing to be doubled if anything other than fstNone was chosen
// So this will ensure I have sorting until that is fixed.
// http://bugs.freepascal.org/view.php?id=0028565
DirListA.AlphaSort;
DirListB.AlphaSort;
// The DBGrid in FileS tab to be hidden initially
RecursiveDisplayGrid1.Visible:= false;
{$ifdef CPU64}
AlgorithmChoiceRadioBox1.Items.Strings[5] := 'xxHash64';
AlgorithmChoiceRadioBox2.Items.Strings[5] := 'xxHash64';
AlgorithmChoiceRadioBox3.Items.Strings[5] := 'xxHash64';
AlgorithmChoiceRadioBox4.Items.Strings[5] := 'xxHash64';
AlgorithmChoiceRadioBox5.Items.Strings[5] := 'xxHash64';
AlgorithmChoiceRadioBox6.Items.Strings[5] := 'xxHash64';
MainForm.Caption := MainForm.Caption + ', 64-bit';
{$else if CPU32}
AlgorithmChoiceRadioBox1.Items.Strings[5] := 'xxHash32';
AlgorithmChoiceRadioBox2.Items.Strings[5] := 'xxHash32';
AlgorithmChoiceRadioBox3.Items.Strings[5] := 'xxHash32';
AlgorithmChoiceRadioBox4.Items.Strings[5] := 'xxHash32';
AlgorithmChoiceRadioBox5.Items.Strings[5] := 'xxHash32';
AlgorithmChoiceRadioBox6.Items.Strings[5] := 'xxHash32';
MainForm.Caption := MainForm.Caption + ', 32-bit';
{$endif}
{$IFDEF WINDOWS}
Label8.Caption := '';
chkCopyHidden.Enabled := false;
chkCopyHidden.ShowHint := true;
chkCopyHidden.Hint := 'On Windows, QuickHash finds hidden files and folders by default';
// Remove the advice about using the File tab for hashing files.
Label6.Caption := '';
SystemRAMGroupBox.Visible := true;
sysRAMTimer.enabled := true;
lblRAM.Caption := GetSystemMem;
Edit2SourcePath.Enabled :=true;
Edit2SourcePath.Visible :=true;
Edit3DestinationPath.Enabled:=true;
Edit3DestinationPath.Visible:=true;
{$ENDIF}
{$IFDEF Windows}
btnCallDiskHasherModule.Enabled := true;
{$ENDIF}
{$IFDEF Darwin}
btnCallDiskHasherModule.Enabled := false; // disabled for OSX currently
{$else}
{$IFDEF UNIX and !$ifdef Darwin}
btnCallDiskHasherModule.Enabled := true; // as of v2.7.0 - disabled for Linux previously
{$ENDIF}
{$ENDIF}
{$IFDEF LINUX}
Label8.Caption := 'LINUX USERS - You may prefer to hash disks using ' + #13#10 +
'the "File" tab and navigate to /dev/sdX or /dev/sdXX as root';
// For Linux users, it's helpful for the user to see as a full path the folder
// they have chosen, so make source and destination edit fields visible, but
// disabled, as we don't want them to be used.
Edit2SourcePath.Visible:= true;
Edit2SourcePath.Enabled:= false;
Edit3DestinationPath.Visible:=true;
Edit3DestinationPath.Enabled:=false;
Tabsheet5.Enabled := true;
Tabsheet5.Visible := true;
chkCopyHidden.Enabled := true;
chkCopyHidden.ShowHint := true;
chkCopyHidden.Hint := 'In Linux, tick this to ensure hidden directories and hidden files in them are detected, if you want them';
// UNC mode is for Windows only so disable in Linux
chkUNCMode.Enabled := false;
chkUNCMode.Visible := false;
cbUNCModeCompFolders.Enabled := false;
cbUNCModeCompFolders.Visible := false;
Edit2SourcePath.Text := 'Source directory selection';
Edit3DestinationPath.Text := 'Destination directory selection';
// RAM status stuff needs to be disabled on Linux
sysRAMTimer.enabled := false;
SystemRAMGroupBox.Visible := false;
{$Endif}
{$ifdef UNIX}
{$ifdef Darwin}
// For Apple Mac users, we don't want them trying to use the Windows Disk hashing module
// created for Windows users.
btnCallDiskHasherModule.Enabled := false;
Tabsheet5.Enabled := true;
Tabsheet5.Visible := true;
Label8.Caption := 'Apple Mac Users - Hash disks using "File" tab and navigate to /dev/sdX or /dev/sdXX as root';
chkCopyHidden.Enabled := true;
chkCopyHidden.ShowHint := true;
chkCopyHidden.Hint := 'In Apple Mac, tick this to ensure hidden directories and hidden files in them are detected, if you want them';
// UNC mode is for Windows only so disable in Apple Mac
chkUNCMode.Enabled := false;
chkUNCMode.Visible := false;
cbUNCModeCompFolders.Enabled := false;
cbUNCModeCompFolders.Visible := false;
Edit2SourcePath.Text := 'Source directory selection';
Edit3DestinationPath.Text := 'Destination directory selection';
{$ENDIF}
{$ENDIF}
end;
// Checks if the desired start date and time has arrived yet by starting timer
// If it has, disable timer. Otherwise, keep it going.
procedure TMainForm.CheckSchedule(DesiredStartTime : TDateTime);
var
t : TDateTime;
begin
t := Now;
// Round the chosen time and the current time to the nearest second
// https://stackoverflow.com/questions/4122218/in-delphi-how-do-i-round-a-tdatetime-to-closest-second-minute-five-minute-etc
t := RoundToNearest(t, EncodeTime(0,0,1,0));
DesiredStartTime := RoundToNearest(DesiredStartTime, EncodeTime(0,0,1,0));
if t = DesiredStartTime then
begin
SchedulerTimer.Enabled := false;
StartHashing := true;
end
else
begin
// and to avoid 100% CPU usage, sleep every 1/3 of a second
sleep(300);
SchedulerTimer.Enabled := true;
StartHashing := false;
end;
end;
function TMainForm.RoundToNearest(TheDateTime,TheRoundStep:TDateTime):TdateTime;
begin
if 0=TheRoundStep
then
begin // If round step is zero there is no round at all
RoundToNearest:=TheDateTime;
end
else
begin // Just round to nearest multiple of TheRoundStep
RoundToNearest:=Round(TheDateTime/TheRoundStep)*TheRoundStep;
end;
end;
// Start a timer schedule for future hashing
procedure TMainForm.InvokeScheduler(Sender : TObject);
var
scheduleStartTime : TDateTime;
begin
// File Tab scheduling
if PageControl1.ActivePage = TabSheet2 then // File tab
begin
if ZVDateTimePickerFileTab.DateTime < Now then
begin
ShowMessage('Scheduled start time is in the past. Correct it.');
exit;
end
else begin
StartHashing := false;
scheduleStartTime := ZVDateTimePickerFileTab.DateTime;
StatusBar1.SimpleText := 'Waiting....scheduled for a start time of ' + FormatDateTime('YY/MM/DD HH:MM', schedulestarttime);
// Set the interval as the milliseconds remaining until the future start time
SchedulerTimer.Interval:= trunc((schedulestarttime - Now) * 24 * 60 * 60 * 1000);
// and then enable the timer
SchedulerTimer.Enabled := true;
// and then check if current date and time is equal to desired scheduled date and time
repeat
Application.ProcessMessages;
CheckSchedule(scheduleStartTime);
until (StartHashing = true);
end
end
// FileS Tab scheduling
else if PageControl1.ActivePage = TabSheet3 then // FileS tab
begin
if ZVDateTimePickerFileSTab.DateTime < Now then
begin
ShowMessage('Scheduled start time is in the past. Correct it.');
exit;
end
else begin
StartHashing := false;
scheduleStartTime := ZVDateTimePickerFileSTab.DateTime;
StatusBar2.SimpleText := 'Waiting....scheduled for a start time of ' + FormatDateTime('YY/MM/DD HH:MM', schedulestarttime);
// Set the interval as the milliseconds remaining until the future start time
SchedulerTimer.Interval:= trunc((schedulestarttime - Now) * 24 * 60 * 60 * 1000);
// and then enable the timer
SchedulerTimer.Enabled := true;
// and then check if current date and time is equal to desired scheduled date and time
repeat
Application.ProcessMessages;
CheckSchedule(scheduleStartTime);
until (StartHashing = true);
end;
end
else if PageControl1.ActivePage = TabSheet4 then // Copy tab
begin
if ZVDateTimePickerCopyTab.DateTime < Now then
begin
ShowMessage('Scheduled start time is in the past. Correct it.');
exit;
end
else begin
StartHashing := false;
scheduleStartTime := ZVDateTimePickerCopyTab.DateTime;
StatusBar3.SimpleText := 'Waiting....scheduled for a start time of ' + FormatDateTime('YY/MM/DD HH:MM', schedulestarttime);
// Set the interval as the milliseconds remaining until the future start time
SchedulerTimer.Interval:= trunc((schedulestarttime - Now) * 24 * 60 * 60 * 1000);
// and then enable the timer
SchedulerTimer.Enabled := true;
// and then check if current date and time is equal to desired scheduled date and time
repeat
Application.ProcessMessages;
CheckSchedule(scheduleStartTime);
until (StartHashing = true);
end
end
// Compare Two Files scheduler
else if PageControl1.ActivePage = TabSheet5 then // Compare Two Files tab
begin
if ZVDateTimePickerCompareTab.DateTime < Now then
begin
ShowMessage('Scheduled start time is in the past. Correct it.');
exit;
end
else begin
StartHashing := false;
scheduleStartTime := ZVDateTimePickerCompareTab.DateTime;
StatusBar4.SimpleText := 'Waiting....scheduled for a start time of ' + FormatDateTime('YY/MM/DD HH:MM', schedulestarttime);
// Set the interval as the milliseconds remaining until the future start time
SchedulerTimer.Interval:= trunc((schedulestarttime - Now) * 24 * 60 * 60 * 1000);
// and then enable the timer
SchedulerTimer.Enabled := true;
// and then check if current date and time is equal to desired scheduled date and time
repeat
Application.ProcessMessages;
CheckSchedule(scheduleStartTime);
until (StartHashing = true);
end;
end
else if PageControl1.ActivePage = TabSheet6 then // Compare Two Folders tab
begin
if ZVDateTimePickerCompareDirsTab.DateTime < Now then
begin
ShowMessage('Scheduled start time is in the past. Correct it.');
exit;
end
else begin
StartHashing := false;
scheduleStartTime := ZVDateTimePickerCompareDirsTab.DateTime;
StatusBar6.SimpleText := 'Waiting....scheduled for a start time of ' + FormatDateTime('YY/MM/DD HH:MM', schedulestarttime);
// Set the interval as the milliseconds remaining until the future start time
SchedulerTimer.Interval:= trunc((schedulestarttime - Now) * 24 * 60 * 60 * 1000);
// and then enable the timer
SchedulerTimer.Enabled := true;
// and then check if current date and time is equal to desired scheduled date and time
repeat
Application.ProcessMessages;
CheckSchedule(scheduleStartTime);
until (StartHashing = true);
end;
end;
end;
// FormDropFiles is the same as btnHashFileClick, except it disables the OpenDialog
// element and computes the filename from the drag n drop variable and hashes the file.
procedure TMainForm.FormDropFiles(Sender: TObject;
const FileNames: array of String);
var
filename, fileHashValue : ansistring;
start, stop, elapsed : TDateTime;
begin
// First, clear the captions from any earlier file hashing actions
StatusBar1.SimpleText := '';
lblStartedFileAt.Caption := '...';
lblFileTimeTaken.Caption := '...';
memFileHashField.Clear;
tabsheet2.Visible:= true;
tabsheet2.Show;
begin
filename := FileNames[0];
if LazFileUtils.DirectoryExistsUTF8(filename) then
begin
ShowMessage('Drag and drop of folders is not supported in this tab.');
end
else
// User has selected a file, so check its valid
if LazFileUtils.FileExistsUTF8(filename) then
begin
// Now start a scheduled time, if selected
if lblschedulertickboxFileTab.Checked then
begin
InvokeScheduler(self);
end;
start := Now;
lblStartedFileAt.Caption := 'Started at : '+ DateTimeToStr(Start);
edtFileNameToBeHashed.Caption := (filename);
StatusBar1.SimpleText := ' H A S H I N G F I L E...P L E A S E W A I T';
Application.ProcessMessages;
fileHashValue := CalcTheHashFile(Filename); // Custom function
memFileHashField.Lines.Add(UpperCase(fileHashValue));
StatusBar1.SimpleText := ' H A S H I N G C OM P L E T E !';
OpenDialog1.Close;
stop := Now;
elapsed := stop - start;
lbEndedFileAt.Caption := 'Ended at : '+ DateTimeToStr(stop);
lblFileTimeTaken.Caption := 'Time taken : '+ TimeToStr(elapsed);
Application.ProcessMessages;
// If the user has ane existing hash to check, compare it here
if (lbleExpectedHash.Text = '') then exit
else
if (lbleExpectedHash.Text <> '...') then
begin
if Uppercase(fileHashValue) = Trim(Uppercase(lbleExpectedHash.Text)) then
begin
Showmessage('Expected hash matches the computed file hash, OK');
end
else
begin
Showmessage('Expected hash DOES NOT match the computed file hash!');
end;
end;
end
else
ShowMessage('An error occured opening the file. Error code: ' + SysErrorMessageUTF8(GetLastOSError));
end;
end;
procedure TMainForm.HashText(Sender: TObject);
var
s : string;