-
Notifications
You must be signed in to change notification settings - Fork 30
/
Mft2Csv.au3
5156 lines (4804 loc) · 238 KB
/
Mft2Csv.au3
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
;#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Icons\au3.ico
#AutoIt3Wrapper_Outfile=Mft2Csv.exe
#AutoIt3Wrapper_Outfile_x64=Mft2Csv64.exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_Comment=Decode $MFT and write to CSV
#AutoIt3Wrapper_Res_Description=Decode $MFT and write to CSV
#AutoIt3Wrapper_Res_Fileversion=2.0.0.51
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 5
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/sf /sv /rm /pe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <WinAPIEx.au3>
#Include <File.au3>
#include <String.au3>
#include <Date.au3>
#include <array.au3>
#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <FontConstants.au3>
Global $Progversion = "Mft2Csv 2.0.0.51"
; parts by Ddan, trancexxx, Ascend4nt & others
Global $DummyPrependBytes = "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
; output structure & csv
Global $OutputPath = @ScriptDir, $DoSplitCsv=False
; file handles
Global $csv, $I30EntriesCsv, $RBICsv, $EntriesObjectIdCsv, $ReparsePointCsv, $ReparsePointAppExecLinkCsv, $EaCsv, $LoggedUtilityStreamTxfDataCsv, $LoggedUtilityStreamCsv, $NewI30EntriesCsv, $AdditionalDataCsv, $csvExtra
; file names
Global $csvFile, $I30EntriesCsvFile, $RBICsvFile, $EntriesObjectIdCsvFile, $ReparsePointCsvFile, $ReparsePointAppExecLinkCsvFile, $EaCsvFile, $LoggedUtilityStreamTxfDataCsvFile, $LoggedUtilityStreamCsvFile, $NewI30EntriesCsvFile, $AdditionalDataCsvFile, $csvExtraFile
; arrays will be populated at file creation
Global $aFileNameAndHandle[0][2] ; FileName, FileHandle
Global $_COMMON_KERNEL32DLL=DllOpen("kernel32.dll"), $separator="|", $PrecisionSeparator=".", $PrecisionSeparator2="", $dol2t=False, $DoDefaultAll=False, $DoBodyfile=False, $SkipFixups=False, $MftIsBroken=False, $ExtractResidentData=False, $ExtractResidentSlack=False, $style
Global $RecordOffset, $RecordOffsetDec, $Signature, $ADS, $FN_NamePath, $UTCconfig, $de="|", $MftFileSize, $FN_FileName, $LogicalClusterNumberforthefileMFT, $ClustersPerFileRecordSegment, $MftAttrListString, $BytesPerSector, $SplitMftRecArr[1]
Global $HDR_LSN, $HDR_SequenceNo, $HDR_Flags, $HDR_RecRealSize, $HDR_RecAllocSize, $HDR_BaseRecord, $HDR_NextAttribID, $HDR_MFTREcordNumber, $HDR_HardLinkCount, $HDR_BaseRecSeqNo
Global $SI_CTime, $SI_ATime, $SI_MTime, $SI_RTime, $SI_FilePermission, $SI_USN, $Errors, $DT_AllocSize, $DT_RealSize, $DT_InitStreamSize, $RecordSlackSpace,$SI_Quota,$FN_EaSize,$FN_EaSize_2,$FN_EaSize_3
Global $SI_CTime_Core,$SI_ATime_Core,$SI_MTime_Core,$SI_RTime_Core,$SI_CTime_Precision,$SI_ATime_Precision,$SI_MTime_Precision,$SI_RTime_Precision
Global $FN_CTime, $FN_ATime, $FN_MTime, $FN_RTime, $FN_AllocSize, $FN_RealSize, $FN_Flags, $FN_Name, $DT_VCNs, $DT_NonResidentFlag, $FN_NameType
Global $FN_CTime_Core,$FN_ATime_Core,$FN_MTime_Core,$FN_RTime_Core,$FN_CTime_Precision,$FN_ATime_Precision,$FN_MTime_Precision,$FN_RTime_Precision
Global $FN_CTime_2, $FN_ATime_2, $FN_MTime_2, $FN_RTime_2, $FN_AllocSize_2, $FN_RealSize_2, $FN_Flags_2, $FN_NameLen_2, $FN_Name_2, $FN_NameType_2
Global $FN_CTime_2_Core,$FN_ATime_2_Core,$FN_MTime_2_Core,$FN_RTime_2_Core,$FN_CTime_2_Precision,$FN_ATime_2_Precision,$FN_MTime_2_Precision,$FN_RTime_2_Precision
Global $FN_CTime_3, $FN_ATime_3, $FN_MTime_3, $FN_RTime_3, $FN_AllocSize_3, $FN_RealSize_3, $FN_Flags_3, $FN_NameLen_3, $FN_Name_3, $FN_NameType_3
Global $FN_CTime_3_Core,$FN_ATime_3_Core,$FN_MTime_3_Core,$FN_RTime_3_Core,$FN_CTime_3_Precision,$FN_ATime_3_Precision,$FN_MTime_3_Precision,$FN_RTime_3_Precision
Global $DT_NameLength, $DT_NameRelativeOffset, $DT_Flags, $DT_NameSpace, $DT_Name, $RecordActive, $DT_ComprUnitSize, $DT_ComprUnitSize_2, $DT_ComprUnitSize_3
Global $DT_NonResidentFlag_2, $DT_NameLength_2, $DT_NameRelativeOffset_2, $DT_Flags_2, $DT_NameSpace_2, $DT_Name_2, $DT_StartVCN_2, $DT_LastVCN_2, $DT_VCNs_2, $DT_AllocSize_2, $DT_RealSize_2, $DT_InitStreamSize_2
Global $DT_NonResidentFlag_3, $DT_NameLength_3, $DT_NameRelativeOffset_3, $DT_Flags_3, $DT_NameSpace_3, $DT_Name_3, $DT_StartVCN_3, $DT_LastVCN_3, $DT_VCNs_3, $DT_AllocSize_3, $DT_RealSize_3, $DT_InitStreamSize_3
Global $FN_ParentRefNo, $FN_ParentSeqNo, $FN_ParentRefNo_2, $FN_ParentSeqNo_2, $FN_ParentRefNo_3, $FN_ParentSeqNo_3, $FN_ParentRefNo_4, $FN_ParentSeqNo_4, $RecordHealth
Global $DT_LengthOfAttribute, $DT_OffsetToAttribute, $DT_IndexedFlag, $DT_LengthOfAttribute_2, $DT_OffsetToAttribute_2, $DT_IndexedFlag_2, $DT_LengthOfAttribute_3, $DT_OffsetToAttribute_3, $DT_IndexedFlag_3
Global $hFile, $nBytes, $MSecTest, $CTimeTest, $SI_MaxVersions, $SI_VersionNumber, $SI_ClassID, $SI_OwnerID, $SI_SecurityID, $SI_HEADER_Flags, $SI_ON, $AL_ON, $FN_ON, $OI_ON, $SD_ON, $VN_ON, $VI_ON, $DT_ON, $IR_ON, $IA_ON, $BITMAP_ON, $RP_ON, $EAI_ON, $EA_ON, $PS_ON, $LUS_ON
Global $GUID_ObjectID, $GUID_BirthVolumeID, $GUID_BirthObjectID, $GUID_DomainID, $VOLUME_NAME_NAME, $VOL_INFO_NTFS_VERSION, $VOL_INFO_FLAGS, $INV_FNAME, $INV_FNAME_2, $INV_FNAME_3, $DT_Number
Global $FileSizeBytes, $IntegrityCheck, $ComboPhysicalDrives, $IsPhysicalDrive=False,$GlobalRefCounter=0,$IsShadowCopy=False,$EncodingWhenOpen=2,$DoBruteForceSlack=0
Global $SI_CTime_tmp, $FN_CTime_tmp
Global $TimestampErrorVal = "0000-00-00 00:00:00"
Global $TimeDiff = 5748192000000000 ; for use with guid only
Global Const $STANDARD_INFORMATION = '10000000'
Global Const $ATTRIBUTE_LIST = '20000000'
Global Const $FILE_NAME = '30000000'
Global Const $OBJECT_ID = '40000000'
Global Const $SECURITY_DESCRIPTOR = '50000000'
Global Const $VOLUME_NAME = '60000000'
Global Const $VOLUME_INFORMATION = '70000000'
Global Const $DATA = '80000000'
Global Const $INDEX_ROOT = '90000000'
Global Const $INDEX_ALLOCATION = 'A0000000'
Global Const $BITMAP = 'B0000000'
Global Const $REPARSE_POINT = 'C0000000'
Global Const $EA_INFORMATION = 'D0000000'
Global Const $EA = 'E0000000'
Global Const $PROPERTY_SET = 'F0000000'
Global Const $LOGGED_UTILITY_STREAM = '00010000'
Global Const $ATTRIBUTE_END_MARKER = 'FFFFFFFF'
Global $DateTimeFormat, $ExampleTimestampVal = "01CD74B3150770B8", $TimestampPrecision
Global $tDelta = _WinTime_GetUTCToLocalFileTimeDelta()
Global $TargetDrive = "", $MFT_Record_Size, $BytesPerCluster, $MFT_Offset, $MFT_Size, $sInput
Global $FileTree[1], $hDisk, $rBuffer, $NonResidentFlag, $zPath, $sBuffer, $Total, $MFTTree[1]
Global $ADS_Name, $Reparse = ""
Global $DT_Clusters, $DT_InitSize, $DataRun, $DT_DataRun
Global $IsCompressed, $IsSparse, $logfile = 0, $subst, $active = False
Global $RUN_VCN[1], $RUN_Clusters[1], $MFT_RUN_Clusters[1], $MFT_RUN_VCN[1], $DataQ[1], $AttrQ[1]
Global $TargetImageFile, $Entries, $IsImage = False, $ImageOffset=0, $IsMftFile=False, $TargetMftFile
Global $begin, $ElapsedTime, $InitState=1
Global $OverallProgress, $CurrentProgress=-1, $ProgressStatus, $ProgressFileName, $ProgressSize
Global $RegExPattern = "[1-9a-fA-F]"
Global Const $RecordSignatureBad = '42414144' ; BAAD signature
Global Const $RecordSignature = '46494C45' ; FILE signature
Global $myctredit, $CheckUnicode, $CheckCsvSplit, $checkFixups, $checkBrokenMFT, $checkBruteForceSlack, $SeparatorInput, $checkquotes, $ComboRecordSize, $sOutputFormat
Global $checkExtractResidentData, $checkExtractResidentSlack
Global $CommandlineMode
Global $buttonColor = 0xD8D8DF
If $cmdline[0] > 0 Then
$CommandlineMode = True
ConsoleWrite($Progversion & @CRLF)
_GetInputParams()
Else
DllCall("kernel32.dll", "bool", "FreeConsole")
$CommandlineMode = False
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$Form = GUICreate($Progversion, 700, 520, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_HandleExit", $Form)
$ComboPhysicalDrives = GUICtrlCreateCombo("", 200, 10, 350, 20, $CBS_DROPDOWNLIST)
$buttonScanPhysicalDrives = GUICtrlCreateButton("Scan Physical", 20, 10, 80, 25)
GUICtrlSetBkColor($buttonScanPhysicalDrives, $buttonColor)
GUICtrlSetOnEvent($buttonScanPhysicalDrives, "_HandleEvent")
$buttonScanShadowCopies = GUICtrlCreateButton("Scan Shadows", 110, 10, 80, 25)
GUICtrlSetBkColor($buttonScanShadowCopies, $buttonColor)
GUICtrlSetOnEvent($buttonScanShadowCopies, "_HandleEvent")
$buttonTestPhysicalDrive = GUICtrlCreateButton("<-- Verify Volumes", 570, 10, 110, 25)
GUICtrlSetBkColor($buttonTestPhysicalDrive, $buttonColor)
GUICtrlSetOnEvent($buttonTestPhysicalDrive, "_HandleEvent")
$buttonDrive = GUICtrlCreateButton("Scan Drives", 110, 45, 80, 25)
GUICtrlSetBkColor($buttonDrive, $buttonColor)
GUICtrlSetOnEvent($buttonDrive, "_HandleEvent")
$Combo = GUICtrlCreateCombo("", 200, 45, 350, 20, $CBS_DROPDOWNLIST)
$checkFixups = GUICtrlCreateCheckbox("Skip Fixups", 430, 70, 95, 20)
$checkBrokenMFT = GUICtrlCreateCheckbox("Broken $MFT", 430, 90, 95, 20)
$checkBruteForceSlack = GUICtrlCreateCheckbox("Scan slack", 430, 110, 95, 20)
GUICtrlCreateLabel("Extract resident:", 350, 140, 80, 20)
$checkExtractResidentSlack = GUICtrlCreateCheckbox("Slack", 430, 140, 50, 20)
$checkExtractResidentData = GUICtrlCreateCheckbox("Data", 480, 140, 50, 20)
$buttonImage = GUICtrlCreateButton("Choose Image", 570, 75, 110, 30)
GUICtrlSetBkColor($buttonImage, $buttonColor)
GUICtrlSetOnEvent($buttonImage, "_HandleEvent")
$buttonMftFile = GUICtrlCreateButton("Choose $MFT", 570, 115, 110, 30)
GUICtrlSetBkColor($buttonMftFile, $buttonColor)
GUICtrlSetOnEvent($buttonMftFile, "_HandleEvent")
GUICtrlCreateLabel("Set output format:", 20, 100, 100, 20)
$ComboOutputFormat = GUICtrlCreateCombo("", 150, 100, 90, 25, $CBS_DROPDOWNLIST)
$Label1 = GUICtrlCreateLabel("Timezone configuration:", 20, 130, 120, 20)
$Combo2 = GUICtrlCreateCombo("", 150, 130, 90, 25, $CBS_DROPDOWNLIST)
$LabelSeparator = GUICtrlCreateLabel("Separator:", 20, 180, 50, 20)
$SeparatorInput2 = GUICtrlCreateInput($separator, 80, 180, 30, 20)
GUICtrlSetState($SeparatorInput2, $GUI_DISABLE)
$SeparatorInput = GUICtrlCreateInput($separator, 130, 180, 20, 20)
$LabelRecordSize = GUICtrlCreateLabel("Record size:", 190, 180, 90, 20)
$ComboRecordSize = GUICtrlCreateCombo("", 270, 180, 50, 20, $CBS_DROPDOWNLIST)
$checkquotes = GUICtrlCreateCheckbox("Quotation mark", 430, 175, 100, 20)
GUICtrlSetState($checkquotes, $GUI_UNCHECKED)
$CheckUnicode = GUICtrlCreateCheckbox("Unicode", 430, 195, 60, 20)
GUICtrlSetState($CheckUnicode, $GUI_CHECKED)
$CheckCsvSplit = GUICtrlCreateCheckbox("split csv", 430, 215, 60, 20)
GUICtrlSetState($CheckCsvSplit, $GUI_UNCHECKED)
$buttonOutput = GUICtrlCreateButton("Set Output Path", 570, 175, 110, 30)
GUICtrlSetBkColor($buttonOutput, $buttonColor)
GUICtrlSetOnEvent($buttonOutput, "_HandleEvent")
$LabelTimestampFormat = GUICtrlCreateLabel("Timestamp format:", 20, 215, 90, 20)
$ComboTimestampFormat = GUICtrlCreateCombo("", 120, 215, 30, 25, $CBS_DROPDOWNLIST)
$LabelTimestampPrecision = GUICtrlCreateLabel("Precision:", 190, 215, 50, 20)
$ComboTimestampPrecision = GUICtrlCreateCombo("", 250, 215, 70, 25, $CBS_DROPDOWNLIST)
;$LabelTimestampError = GUICtrlCreateLabel("Timestamp ErrorVal:", 330, 215, 110, 20)
;$TimestampErrorInput = GUICtrlCreateInput($TimestampErrorVal, 440, 210, 130, 20)
$LabelPrecisionSeparator = GUICtrlCreateLabel("Precision separator:", 20, 255, 100, 20)
$PrecisionSeparatorInput = GUICtrlCreateInput($PrecisionSeparator, 135, 255, 15, 20)
$LabelPrecisionSeparator2 = GUICtrlCreateLabel("Precision separator2:", 190, 255, 100, 20)
$PrecisionSeparatorInput2 = GUICtrlCreateInput($PrecisionSeparator2, 305, 255, 15, 20)
$InputExampleTimestamp = GUICtrlCreateInput("", 345, 255, 200, 20)
GUICtrlSetState($InputExampleTimestamp, $GUI_DISABLE)
$buttonStart = GUICtrlCreateButton("Start Processing", 570, 240, 110, 50)
GUICtrlSetFont($buttonStart, 8.5, $FW_SEMIBOLD)
GUICtrlSetOnEvent($buttonStart, "_HandleEvent")
GUICtrlSetBkColor($buttonStart, $buttonColor)
$myctredit = GUICtrlCreateEdit("Decoding $MFT" & @CRLF, 0, 300, 700, 80, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_READONLY))
GUICtrlSetBkColor($myctredit, 0xFFFFFF)
_GetPhysicalDrives("PhysicalDrive")
_GetMountedDrivesInfo()
_InjectTimeZoneInfo()
_InjectTimestampFormat()
_InjectTimestampPrecision()
_TranslateTimestamp()
_InjectRecordSize()
_InjectOutputFormat()
$LogState = True
GUISetState(@SW_SHOW, $Form)
While Not $active
Sleep(50)
_TranslateSeparator()
$PrecisionSeparator = GUICtrlRead($PrecisionSeparatorInput)
$PrecisionSeparator2 = GUICtrlRead($PrecisionSeparatorInput2)
_TranslateTimestamp()
WEnd
$tDelta = _GetUTCRegion(GUICtrlRead($Combo2)) - $tDelta
If @error Then
_DisplayInfo("Error: Timezone configuration failed." & @CRLF)
Else
_DisplayInfo("Timestamps presented in UTC: " & $UTCconfig & @CRLF)
EndIf
$tDelta = $tDelta * -1 ;Since delta is substracted from timestamp later on
Select
Case $IsImage
$ImageOffset = Int(StringMid(GUICtrlRead($Combo), 10), 2)
_DisplayInfo(@CRLF & "Target is: " & GUICtrlRead($Combo) & @CRLF)
_DebugOut("Target image file: " & $TargetImageFile)
$sInput = $TargetImageFile
$hDisk = _WinAPI_CreateFile("\\.\" & $TargetImageFile, 2, 2, 7)
Case $IsMftFile
_DebugOut("Target $MFT file: " & $TargetMftFile)
$sInput = $TargetMftFile
$hDisk = _WinAPI_CreateFile("\\.\" & $TargetMftFile, 2, 2, 7)
$MftFileSize = _WinAPI_GetFileSizeEx($hDisk)
Case $IsPhysicalDrive = True
$ImageOffset = Int(StringMid(GUICtrlRead($Combo), 10), 2)
_DebugOut("Target is: \\.\" & $TargetImageFile)
$sInput = $TargetImageFile
$hDisk = _WinAPI_CreateFile("\\.\" & $TargetImageFile, 2, 2, 6)
Case $IsShadowCopy = True
$TargetDrive = "SC" & StringMid($TargetImageFile, 47)
$ImageOffset = Int(StringMid(GUICtrlRead($Combo), 10), 2)
_DebugOut("Target drive is: " & $TargetImageFile)
_DebugOut("Volume at offset: " & $ImageOffset)
$sInput = $TargetImageFile
$hDisk = _WinAPI_CreateFile($TargetImageFile, 2, 2, 6)
Case Else
$TargetDrive = StringMid(GUICtrlRead($Combo), 1, 2)
_DebugOut("Target volume: " & $TargetDrive)
$sInput = $TargetDrive
$hDisk = _WinAPI_CreateFile("\\.\" & $TargetDrive, 2, 2, 6)
EndSelect
If $hDisk = 0 Then
_DebugOut("Error in CreateFile: " & _WinAPI_GetLastErrorMessage())
Exit(1)
EndIf
EndIf
; start our timer
Local $hTimer = TimerInit()
; the main processing
_ExtractSystemfile()
If @error Then
_DisplayWrapper("Parsing failure" & @CRLF)
If Not $CommandlineMode Then
MsgBox(0, "Error", "Check the logs for more details")
EndIf
Exit(1)
EndIf
Local $fDiff = TimerDiff($hTimer)
_DisplayWrapper("Total processing time is " & _WinAPI_StrFromTimeInterval($fDiff))
If Not $CommandlineMode Then
; display a last message before application is closed
MsgBox(0, "Parsing finished", "Job took: " & @CRLF & _WinAPI_StrFromTimeInterval($fDiff) & @CRLF & @CRLF & "Output can be found in: " & @CRLF & $OutputPath)
EndIf
_WinAPI_CloseHandle($hDisk)
If $logfile Then FileClose($logfile)
$active = False
Exit
Func _HandleEvent()
If Not $active Then
Switch @GUI_CTRLID
Case $buttonDrive
_GetMountedDrivesInfo()
$IsImage = False
$IsShadowCopy = False
$IsPhysicalDrive = False
Case $buttonImage
_ProcessImage()
$IsImage = True
$IsShadowCopy = False
$IsPhysicalDrive = False
Case $buttonMftFile
_SelectMftFile()
$IsMftFile = True
$IsImage = False
Case $buttonStart
If $OutputPath="" Then
_DisplayInfo("Error: No output path selected" & @CRLF)
Return
EndIf
_DebugOut("Dumping output to: " & $OutputPath)
$active = True
Case $buttonOutput
_SetOutputPath()
Case $buttonScanPhysicalDrives
_GetPhysicalDrives("PhysicalDrive")
$IsShadowCopy = False
$IsPhysicalDrive = True
$IsImage = False
Case $buttonScanShadowCopies
_GetPhysicalDrives("GLOBALROOT\Device\HarddiskVolumeShadowCopy")
$IsShadowCopy = True
$IsPhysicalDrive = False
$IsImage = False
Case $buttonTestPhysicalDrive
_TestPhysicalDrive()
EndSwitch
EndIf
EndFunc
Func _HandleExit()
If $logfile Then FileClose($logfile)
If $hDisk Then _WinAPI_CloseHandle($hDisk)
Exit
EndFunc
Func _ExtractSystemfile()
Global $DataQ[1], $RUN_VCN[1], $RUN_Clusters[1]
If Not $CommandlineMode Then
$CheckUnicode = GUICtrlRead($CheckUnicode)
;$TimestampErrorVal = GUICtrlRead($TimestampErrorInput)
;$TimestampErrorVal = $TimestampErrorVal
$PrecisionSeparator = GUICtrlRead($PrecisionSeparatorInput)
$PrecisionSeparator2 = GUICtrlRead($PrecisionSeparatorInput2)
$CheckCsvSplit = GUICtrlRead($CheckCsvSplit)
$checkFixups = GUICtrlRead($checkFixups)
$checkBruteForceSlack = GUICtrlRead($checkBruteForceSlack)
$checkBrokenMFT = GUICtrlRead($checkBrokenMFT)
$checkExtractResidentData = GUICtrlRead($checkExtractResidentData)
$checkExtractResidentSlack = GUICtrlRead($checkExtractResidentSlack)
$sOutputFormat = GUICtrlRead($ComboOutputFormat)
$SeparatorInput = GUICtrlRead($SeparatorInput)
$checkquotes = GUICtrlRead($checkquotes)
$MFT_Record_Size = GUICtrlRead($ComboRecordSize)
EndIf
If $CheckCsvSplit = 1 Then
$DoSplitCsv = True
_DebugOut("Splitting csv")
EndIf
If $CheckUnicode = 1 Then
$EncodingWhenOpen = BitOR($FO_OVERWRITE, $FO_UTF8)
_DebugOut("UNICODE configured")
Else
$EncodingWhenOpen = BitOR($FO_OVERWRITE, $FO_ANSI)
_DebugOut("ANSI configured")
EndIf
Select
Case $sOutputFormat = "all"
$DoDefaultAll = True
Case $sOutputFormat = "bodyfile"
$DoBodyfile = True
Case $sOutputFormat = "l2t"
$Dol2t = True
Case Else
_DebugOut("Error: unexpected output format: " & $sOutputFormat)
Return SetError(1)
EndSelect
; Create output
_CreateOutputStructureAndFiles()
_DebugOut("Using input: " & $sInput)
_DebugOut("Using output format: " & $sOutputFormat)
If $checkquotes = 1 Then
_DebugOut("Writing variables surrounded with qoutes")
Else
_DebugOut("Writing variables without surrounding qoutes")
EndIf
_DebugOut("Timestamps presented in UTC " & $UTCconfig)
_DebugOut("Timestamp Precision: " & $TimestampPrecision)
If StringLen($PrecisionSeparator) <> 1 Then
If Not $CommandlineMode Then _DisplayInfo("Error: Precision separator not set properly" & @crlf)
_DebugOut("Error: Precision separator not set properly: " & $PrecisionSeparator)
Return SetError(1)
Else
_DebugOut("Using precision separator: " & $PrecisionSeparator)
EndIf
If Not $CommandlineMode Then _TranslateTimestamp()
If $checkFixups = 1 Then
$SkipFixups = True
_DebugOut("Skipping Fixups")
Else
$SkipFixups = False
EndIf
If $checkBruteForceSlack = 1 Then
$DoBruteForceSlack = 1
Else
$DoBruteForceSlack = 0
EndIf
_DebugOut("Scan record slack: " & $DoBruteForceSlack)
If $checkBrokenMFT = 1 Then
$MftIsBroken = True
_DebugOut("Handling broken $MFT")
EndIf
If $checkExtractResidentData = 1 Then
$ExtractResidentData = True
_DebugOut("Extracting resident data")
EndIf
If $checkExtractResidentSlack = 1 Then
$ExtractResidentSlack = True
_DebugOut("Extracting resident slack")
EndIf
If StringLen($SeparatorInput) <> 1 Then
If Not $CommandlineMode Then _DisplayInfo("Error: Separator not set properly" & @crlf)
_DebugOut("Error: Separator not set properly: " & $SeparatorInput)
Return SetError(1)
Else
$de = $SeparatorInput
_DebugOut("Using separator: " & $de)
EndIf
If (Not $IsImage and Not $IsMftFile and Not $IsShadowCopy) Then
If DriveGetFileSystem($TargetDrive) <> "NTFS" Then ;read boot sector and extract $MFT data
If Not $CommandlineMode Then _DisplayInfo("Error: Target volume " & $TargetDrive & " is not NTFS" & @crlf)
Return SetError(1)
EndIf
If Not $CommandlineMode Then _DisplayInfo("Target volume is: " & $TargetDrive & @crlf)
EndIf
If Not $IsMftFile Then
_WinAPI_SetFilePointerEx($hDisk, $ImageOffset, $FILE_BEGIN)
$BootRecord = _GetDiskConstants()
If $BootRecord = "" Then
_DebugOut("Unable to read Boot Sector")
Return SetError(1)
EndIf
Else
If $MFT_Record_Size <> 1024 And $MFT_Record_Size <> 4096 Then
_DebugOut("Bad mft record size: " & $MFT_Record_Size)
Return SetError(1)
EndIf
$BytesPerCluster = 512 * 8
$MFT_Offset = 0
$ClustersPerFileRecordSegment = Ceiling($MFT_Record_Size/$BytesPerCluster)
EndIf
_DebugOut("Using record size: " & $MFT_Record_Size)
$rBuffer = DllStructCreate("byte[" & $MFT_Record_Size & "]") ;buffer for records
$MFT = _ReadMFT()
If $MFT = "" And Not $MftIsBroken Then Return SetError(1) ;something wrong with record for $MFT
$MFT = _DecodeMFTRecord0($MFT, 0) ;produces DataQ for $MFT, record 0
If $MFT = "" And Not $MftIsBroken Then Return SetError(1)
_GetRunsFromAttributeListMFT0() ;produces datarun for $MFT and converts datarun to RUN_VCN[] and RUN_Clusters[]
$MFT_Size = $DT_RealSize
If ($IsMftFile Or $MftIsBroken) Then
; no need to deal with real clusters when input is standalone file
ReDim $RUN_VCN[2]
ReDim $RUN_Clusters[2]
$RUN_VCN[1] = 1
$RUN_Clusters[1] = Int(((512 + $MftFileSize - Mod($MftFileSize, 512)) / 512 / 8))
EndIf
$MFT_RUN_VCN = $RUN_VCN
$MFT_RUN_Clusters = $RUN_Clusters ;preserve values for $MFT
$Progress = GUICtrlCreateLabel("Decoding $MFT info and writing to csv", 20, 385, 540, 20)
GUICtrlSetFont($Progress, 12)
$ProgressStatus = GUICtrlCreateLabel("", 20, 415, 660, 20)
$ElapsedTime = GUICtrlCreateLabel("", 20, 430, 660, 20)
$OverallProgress = GUICtrlCreateProgress(20, 455, 660, 30)
If Not $MftIsBroken Then
_DoFileTree() ;creates folder structure
Else
$Total = ($MftFileSize/$MFT_Record_Size)
Redim $FileTree[$Total]
EndIf
$ProgressFileName = GUICtrlCreateLabel("", 20, 495, 660, 20, $DT_END_ELLIPSIS)
;$FileProgress = GUICtrlCreateProgress(20, 520, 660, 30)
AdlibRegister("_ExtractionProgress", 500)
$begin = TimerInit()
Local $nBytes
For $i = 0 To UBound($FileTree)-1 ;note $i is mft reference number
$CurrentProgress = $i
$Files = $Filetree[$i]
If StringInStr($Files, "/") > 0 Then ;MFT record was split across 2 dataruns
_DebugOut("Ref " & $i & " has its record split across 2 dataruns")
$SplitRecordPart1 = StringMid($Files, StringInStr($Files, "/")+1)
$SplitRecordPart2 = $SplitMftRecArr[$SplitRecordPart1]
$SplitRecordTestRef = StringMid($SplitRecordPart2, 1, StringInStr($SplitRecordPart2, "?")-1)
If $SplitRecordTestRef <> $i Then ;then something is not quite right
_DebugOut("Error: The ref in the array did not match target ref.")
ContinueLoop
EndIf
$SplitRecordPart3 = StringMid($SplitRecordPart2, StringInStr($SplitRecordPart2, "?")+1)
$SplitRecordArr = StringSplit($SplitRecordPart3,"|")
If UBound($SplitRecordArr) <> 3 Then
_DebugOut("Error: Array contained more elements than expected: " & UBound($SplitRecordArr))
ContinueLoop
EndIf
$MFTEntry="0x"
For $k = 1 To Ubound($SplitRecordArr)-1
$SplitRecordOffset = StringMid($SplitRecordArr[$k], 1, StringInStr($SplitRecordArr[$k], ",")-1)
$SplitRecordSize = StringMid($SplitRecordArr[$k], StringInStr($SplitRecordArr[$k], ",")+1)
_WinAPI_SetFilePointerEx($hDisk, $ImageOffset+$SplitRecordOffset, $FILE_BEGIN)
$kBuffer = DllStructCreate("byte["&$SplitRecordSize&"]")
_WinAPI_ReadFile($hDisk, DllStructGetPtr($kBuffer), $SplitRecordSize, $nBytes)
$MFTEntry &= StringMid(DllStructGetData($kBuffer,1),3)
$RecordOffsetDec = $SplitRecordOffset
_DebugOut(" part " & $k & " of record has " & $SplitRecordSize & " bytes at raw offset 0x" & Hex(Int($ImageOffset+$SplitRecordOffset)))
$kBuffer=0
Next
; ConsoleWrite(_HexEncode($MFTEntry) & @CRLF)
Else
If $IsMftFile Then
_WinAPI_SetFilePointerEx($hDisk, $i*$MFT_Record_Size, $FILE_BEGIN)
$RecordOffsetDec = $MFT_Record_Size * $i
Else
_WinAPI_SetFilePointerEx($hDisk, $MFTTree[$i], $FILE_BEGIN)
$RecordOffsetDec = $MFTTree[$i]
EndIf
$RecordOffsetDec = Int($RecordOffsetDec)
_WinAPI_ReadFile($hDisk, DllStructGetPtr($rBuffer), $MFT_Record_Size, $nBytes)
$MFTEntry = DllStructGetData($rBuffer, 1)
EndIf
$FN_NamePath = StringMid($Files, 1,StringInStr($Files, "?") - 1)
$FN_FileName = $FN_NamePath
If (StringMid($MFTEntry, 3, 8) = $RecordSignature) Then
$Signature = "GOOD"
ElseIf (StringMid($MFTEntry, 3, 8) = $RecordSignatureBad) Then
$Signature = "BAAD"
ElseIf (StringMid($MFTEntry, 3, 8) = '00000000') Then
_ClearVar()
$Signature = "ZERO"
$RecordOffset = "0x" & Hex($RecordOffsetDec)
If $DoDefaultAll Then
If $checkquotes = 1 Then
_WriteCSVwithQuotes()
If $DoSplitCsv Then _WriteCSVExtraWithQuotes()
Else
_WriteCSV()
If $DoSplitCsv Then _WriteCSVExtra()
Endif
Else
If $checkquotes = 1 Then
_WriteCSV2withQuotes()
Else
_WriteCSV2()
EndIf
EndIf
$Signature = ""
ContinueLoop
Else
_ClearVar()
$Signature = "UNKNOWN"
$RecordOffset = "0x" & Hex($RecordOffsetDec)
If $DoDefaultAll Then
If $checkquotes = 1 Then
_WriteCSVwithQuotes()
If $DoSplitCsv Then _WriteCSVExtraWithQuotes()
Else
_WriteCSV()
If $DoSplitCsv Then _WriteCSVExtra()
Endif
Else
If $checkquotes = 1 Then
_WriteCSV2withQuotes()
Else
_WriteCSV2()
EndIf
EndIf
$Signature = ""
ContinueLoop
EndIf
$RecordOffset = "0x" & Hex($RecordOffsetDec)
If $ExtractResidentData Then
_ExtractSingleFile($MFTEntry, $i)
EndIf
_ClearVar()
$RecordOffset = "0x" & Hex($RecordOffsetDec)
_ParserCodeOldVersion($MFTEntry)
If $DT_Number > 0 Then $ADS = $DT_Number - 1
;$RecordOffset = "0x" & Hex($RecordOffsetDec)
$CTimeTest = _Test_SI2FN_CTime()
If $DoDefaultAll Then
If $checkquotes = 1 Then
_WriteCSVwithQuotes()
If $DoSplitCsv Then _WriteCSVExtraWithQuotes()
Else
_WriteCSV()
If $DoSplitCsv Then _WriteCSVExtra()
Endif
Else
If $checkquotes = 1 Then
_WriteCSV2withQuotes()
Else
_WriteCSV2()
EndIf
EndIf
$Signature = ""
If Not Mod($i, 50000) Then
FileFlush($csv)
EndIf
Next
_WinAPI_CloseHandle($hDisk)
AdlibUnRegister()
GUIDelete($Progress)
_ExtractionProgress()
; close csv handles
For $x = 0 To UBound($aFileNameAndHandle) - 1
FileClose($aFileNameAndHandle[$x][1])
Next
; count the lines of small sized files, and rename if empty
For $x = 0 To UBound($aFileNameAndHandle) - 1
If FileGetSize($aFileNameAndHandle[$x][0]) < 100000 Then
If (_FileCountLines($aFileNameAndHandle[$x][0]) < 2) Then
FileMove($aFileNameAndHandle[$x][0], $aFileNameAndHandle[$x][0] & ".empty", 1)
_DebugOut("Empty output: " & $aFileNameAndHandle[$x][0] & " is now postfixed with .empty")
EndIf
EndIf
Next
_DisplayWrapper("Finished processing " & $Total & " records" & @CRLF)
EndFunc
Func _DoFileTree()
Local $nBytes, $ParentRef, $FileRef, $BaseRef, $testvar=0, $TmpRecord, $MFTClustersToKeep=0, $DoKeepCluster=0, $Subtr, $PartOfAttrList=0, $ArrSize
Local $FileSeq, $ParentSeq, $active, $BaseSeq
$Total = Int($MFT_Size/$MFT_Record_Size)
Global $FileTree[$Total] ;FilePath
; Local $FileTree1[$Total] ;active
Local $FileTree2[$Total] ;refseq
Local $FileTree3[$Total] ;parentrefseq
Global $MFTTree[$Total]
$ref = -1
$Pos=0
if $IsMftFile Then _WinAPI_SetFilePointerEx($hDisk, $Pos, $FILE_BEGIN)
AdlibRegister("_DoFileTreeProgress", 500)
$begin = TimerInit()
For $r = 1 To Ubound($MFT_RUN_VCN)-1
$DoKeepCluster=$MFTClustersToKeep
$MFTClustersToKeep = Mod($MFT_RUN_Clusters[$r]+($ClustersPerFileRecordSegment-$MFTClustersToKeep),$ClustersPerFileRecordSegment)
If $MFTClustersToKeep <> 0 Then
$MFTClustersToKeep = $ClustersPerFileRecordSegment - $MFTClustersToKeep ;How many clusters are we missing to get the full MFT record
EndIf
If Not $IsMftFile Then
$Pos = $MFT_RUN_VCN[$r]*$BytesPerCluster
_WinAPI_SetFilePointerEx($hDisk, $ImageOffset+$Pos, $FILE_BEGIN)
Else
$Pos = $testvar*$MFT_Record_Size
EndIf
If $MFTClustersToKeep Or $DoKeepCluster Then
$Subtr = 0
Else
$Subtr = $MFT_Record_Size
EndIf
$EndOfRun = $MFT_RUN_Clusters[$r]*$BytesPerCluster-$Subtr
For $i = 0 To $MFT_RUN_Clusters[$r]*$BytesPerCluster-$Subtr Step $MFT_Record_Size
If $MFTClustersToKeep Then
If $i >= $EndOfRun-(($ClustersPerFileRecordSegment-$MFTClustersToKeep)*$BytesPerCluster) Then
$BytesToGet = ($ClustersPerFileRecordSegment-$MFTClustersToKeep)*$BytesPerCluster
$CurrentOffset = DllCall('kernel32.dll', 'int', 'SetFilePointerEx', 'ptr', $hDisk, 'int64', 0, 'int64*', 0, 'dword', 1)
_WinAPI_ReadFile($hDisk, DllStructGetPtr($rBuffer), $BytesToGet, $nBytes)
$TmpRecord = StringMid(DllStructGetData($rBuffer, 1),1, 2+($BytesToGet*2))
$ArrSize = UBound($SplitMftRecArr)
ReDim $SplitMftRecArr[$ArrSize+1]
$SplitMftRecArr[$ArrSize] = $ref+1 & '?' & $CurrentOffset[3] & ',' & $BytesToGet
ContinueLoop
EndIf
EndIf
$ref += 1
If $ref > $Total Then ExitLoop
$testvar += 1
$CurrentProgress = $ref
If $i = 0 And $DoKeepCluster Then
If $TmpRecord <> "" Then $record = $TmpRecord
$BytesToGet = $DoKeepCluster*$BytesPerCluster
if $BytesToGet > $MFT_Record_Size Then
MsgBox(0,"Error","$BytesToGet > $MFT_Record_Size")
$BytesToGet = $MFT_Record_Size
EndIf
$CurrentOffset = DllCall('kernel32.dll', 'int', 'SetFilePointerEx', 'ptr', $hDisk, 'int64', 0, 'int64*', 0, 'dword', 1)
_WinAPI_ReadFile($hDisk, DllStructGetPtr($rBuffer), $BytesToGet, $nBytes)
$record &= StringMid(DllStructGetData($rBuffer, 1),3, $BytesToGet*2)
$TmpRecord=""
$SplitMftRecArr[$ArrSize] &= '|' & $CurrentOffset[3] & ',' & $BytesToGet
Else
_WinAPI_ReadFile($hDisk, DllStructGetPtr($rBuffer), $MFT_Record_Size, $nBytes)
$record = DllStructGetData($rBuffer, 1)
EndIf
If StringMid($record,3,8) <> $RecordSignature Then
_DebugOut($ref & " The record signature is bad", StringMid($record, 1, 34))
ContinueLoop
EndIf
$CurrentMFTOffset = DllCall('kernel32.dll', 'int', 'SetFilePointerEx', 'ptr', $hDisk, 'int64', 0, 'int64*', 0, 'dword', 1)
$MFTTree[$ref] = $CurrentMFTOffset[3]-$MFT_Record_Size
$Flags = Dec(StringMid($record,47,4))
If Not BitAND($Flags,Dec("0100")) Then
$active = 0
Else
$active = 1
EndIf
If Not $SkipFixups Then $record = _DoFixup($record, $ref)
If $record = "" then ContinueLoop ;corrupt, failed fixup
$FileRef = $ref
$FileSeq = Dec(_SwapEndian(StringMid($record,35,4)))
$BaseRef = Dec(_SwapEndian(StringMid($record,67,12)),2)
$BaseSeq = Dec(_SwapEndian(StringMid($record,79,4)))
If $active = 1 And ($BaseRef <> 0 Or StringInStr($MftAttrListString,','&$FileRef&',')) Then ;The baseRef can be 0 for the extra records when $MFT contains $ATTRIBUTE_LIST
_DebugOut("Ref " & $FileRef & " has baseref " & $BaseRef)
$FileTree[$FileRef] = $Pos + $i ;may contain data attribute
$FileRef = $BaseRef
$FileSeq = $BaseSeq
$PartOfAttrList=1
Else
$PartOfAttrList=0
EndIf
$Offset = (Dec(StringMid($record,43,2))*2)+3
$FileName = ""
While 1 ;only want names and reparse
$Type = Dec(StringMid($record,$Offset,8),2)
If $Type > Dec("30000000",2) Then ExitLoop ;no more names or reparse
$Size = Dec(_SwapEndian(StringMid($record,$Offset+8,8)),2)
If $Type = Dec("30000000",2) Then
$attr = StringMid($record,$Offset,$Size*2)
$ParentRef = Dec(_SwapEndian(StringMid($attr,49,12)),2)
$ParentSeq = Dec(_SwapEndian(StringMid($attr,61,4)))
$NameSpace = StringMid($attr,179,2)
If $NameSpace <> "02" Then ; skip DOS
$NameLength = Dec(StringMid($attr,177,2))
$FileName = StringMid($attr,181,$NameLength*4)
$FileName = BinaryToString("0x"&$FileName,2)
$FileTree[$FileRef] &= "**" & $ParentRef & "*" & $FileName
$FileTree3[$FileRef] &= "**" & $ParentRef & "-" & $ParentSeq
EndIf
EndIf
$Offset += $Size*2
WEnd
If Not BitAND($Flags,Dec("0200")) And $PartOfAttrList=0 And $FileTree[$FileRef] <> "" Then
$FileTree[$FileRef] &= "?" & ($Pos + $i) ;file also add FilePointer
EndIf
If StringInStr($FileTree[$FileRef], "**") = 1 Then $FileTree[$FileRef] = StringTrimLeft($FileTree[$FileRef],2) ;remove leading **
If StringInStr($FileTree3[$FileRef], "**") = 1 Then $FileTree3[$FileRef] = StringTrimLeft($FileTree3[$FileRef],2) ;remove leading **
If $i = 0 And $DoKeepCluster Then $FileTree[$FileRef] &= "/" & $ArrSize ;Mark record as being split across 2 runs
; $FileTree1[$FileRef] = $active
If $active = 0 And $PartOfAttrList = 0 Then $FileSeq -= 1 ; to get correct mapping with deleted items
$FileTree2[$FileRef] = $FileRef & "-" & $FileSeq
Next
Next
AdlibUnRegister()
If UBound($FileTree) > 5 Then
$FileTree[5] = ":"
EndIf
$begin = TimerInit()
AdlibRegister("_FolderStrucProgress", 1000)
Local $RefSeq1, $RefSeq2, $RefSeq1s
For $i = 0 to UBound($FileTree)-1
$CurrentProgress = $i
If StringInStr($FileTree[$i], "**") = 0 Then
$RefSeq1 = $FileTree3[$i]
While StringInStr($FileTree[$i], "*") > 0 ;single file
$Parent = StringMid($Filetree[$i], 1, StringInStr($FileTree[$i], "*")-1)
If $Parent < UBound($Filetree) Then
$RefSeq2 = $FileTree2[$Parent]
If StringInStr($Filetree[$Parent],"?")=0 And (StringInStr($Filetree[$Parent],"*")>0 Or StringInStr($Filetree[$Parent],":")>0) And $RefSeq1 = $RefSeq2 Then
$FileTree[$i] = StringReplace($FileTree[$i], $Parent & "*", $Filetree[$Parent] & "\")
$RefSeq1 = $FileTree3[$Parent]
Else
$FileTree[$i] = StringReplace($FileTree[$i], $Parent & "*", $Filetree[5] & "\ORPHAN\")
EndIf
Else
_DebugOut("Error: $Parent out of bounds: " & $Parent)
ExitLoop
EndIf
WEnd
Else
$Names = StringSplit($FileTree[$i], "**",3) ;hard links
$str = ""
$RefSeq1s = StringSplit($FileTree3[$i], "**",3)
For $n = 0 to UBound($Names) - 1
If $n < UBound($RefSeq1s) Then
$RefSeq1 = $RefSeq1s[$n]
Else
$RefSeq1 = ""
EndIf
While StringInStr($Names[$n], "*") > 0
$Parent=StringMid($Names[$n], 1, StringInStr($Names[$n], "*")-1)
If $Parent < UBound($Filetree) Then
$RefSeq2 = $FileTree2[$Parent]
If StringInStr($Filetree[$Parent],"?")=0 And (StringInStr($Filetree[$Parent],"*")>0 Or StringInStr($Filetree[$Parent],":")>0) And $RefSeq1 = $RefSeq2 Then
$Names[$n] = StringReplace($Names[$n], $Parent & "*", $Filetree[$Parent] & "\")
$RefSeq1 = $FileTree3[$Parent]
Else
$Names[$n] = StringReplace($Names[$n], $Parent & "*", $Filetree[5] & "\ORPHAN\")
EndIf
Else
_DebugOut("Error: $Parent out of bounds: " & $Parent)
ExitLoop
EndIf
WEnd
$str &= $Names[$n] & "*"
Next
$FileTree[$i] = StringTrimRight($str,1)
EndIf
Next
If UBound($FileTree) > 5 Then
$FileTree[5] &= "\"
EndIf
AdlibUnRegister()
For $i = 0 To UBound($FileTree) - 1
If StringInStr($FileTree[$i], "*") = 0 Then
ContinueLoop
EndIf
$myarr = StringSplit($FileTree[$i], "*")
_ArrayDelete($myarr, 0)
_ArraySort($myarr, 0)
$testvar = ""
For $j = 0 To UBound($myarr) - 1
If StringInStr($myarr[$j],"?") Then
$testvar &= StringMid($myarr[$j], 1,StringInStr($myarr[$j], "?") - 1) & "*"
Else
$testvar &= $myarr[$j] & "*"
EndIf
Next
;_DebugOut("Sorted: " & $testvar)
$FileTree[$i] = StringTrimRight($testvar, 1)
Next
EndFunc
Func _DecodeAttrList($FileRef, $AttrList)
Local $offset, $nBytes, $List = "", $str = ""
If StringMid($AttrList, 17, 2) = "00" Then ;attribute list is resident in AttrList
$offset = Dec(_SwapEndian(StringMid($AttrList, 41, 4)))
$List = StringMid($AttrList, $offset*2+1) ;gets list when resident
Else ;attribute list is found from data run in $AttrList
If $FileRef = 0 And $IsMftFile Then
_DebugOut("WARNING: A non-resident $ATTRIBUTE_LIST is not possible to resolve with an extracted $MFT file. The decoded record for $MFT itself will thus be incomplete.")
Return
EndIf
$size = Dec(_SwapEndian(StringMid($AttrList, $offset*2 + 97, 16)))
$offset = ($offset + Dec(_SwapEndian(StringMid($AttrList, $offset*2 + 65, 4))))*2
$DataRun = StringMid($AttrList, $offset+1, StringLen($AttrList)-$offset)
Global $RUN_VCN[1], $RUN_Clusters[1] ;redim arrays
_ExtractDataRuns()
$cBuffer = DllStructCreate("byte[" & $BytesPerCluster & "]")
For $r = 1 To Ubound($RUN_VCN)-1
_WinAPI_SetFilePointerEx($hDisk, $ImageOffset+$RUN_VCN[$r]*$BytesPerCluster, $FILE_BEGIN)
For $i = 1 To $RUN_Clusters[$r]
If Not _WinAPI_ReadFile($hDisk, DllStructGetPtr($cBuffer), $BytesPerCluster, $nBytes) Then
_DebugOut("_DecodeAttrList(): Error in ReadFile: " & _WinAPI_GetLastErrorMessage())
Exit(1)
EndIf
$List &= StringTrimLeft(DllStructGetData($cBuffer, 1),2)
Next
Next
$List = StringMid($List, 1, $size*2)
EndIf
If StringMid($List, 1, 8) <> "10000000" Then Return "" ;bad signature
$offset = 0
While StringLen($list) > $offset*2
$ref = Dec(_SwapEndian(StringMid($List, $offset*2 + 33, 8)))
If $ref <> $FileRef Then ;new attribute
If Not StringInStr($str, $ref) Then $str &= $ref & "-"
EndIf
$offset += Dec(_SwapEndian(StringMid($List, $offset*2 + 9, 4)))
WEnd
$AttrQ[0] = ""
If $str <> "" Then $AttrQ = StringSplit(StringTrimRight($str,1), "-")
Return $List
EndFunc
Func _StripMftRecord($record, $FileRef)
If Not $SkipFixups Then $record = _DoFixup($record, $FileRef)
If $record = "" then Return "" ;corrupt, failed fixup
$RecordSize = Dec(_SwapEndian(StringMid($record,51,8)),2)
$HeaderSize = Dec(_SwapEndian(StringMid($record,43,4)),2)
$record = StringMid($record,$HeaderSize*2+3,($RecordSize-$HeaderSize-8)*2) ;strip "0x..." and "FFFFFFFF..."
Return $record
EndFunc
Func _ExtractDataRuns()
$r=UBound($RUN_Clusters)
ReDim $RUN_Clusters[$r + $MFT_Record_Size], $RUN_VCN[$r + $MFT_Record_Size]
$i=1
$RUN_VCN[0] = 0
$BaseVCN = $RUN_VCN[0]
If $DataRun = "" Then $DataRun = "00"
Do
$RunListID = StringMid($DataRun,$i,2)
If $RunListID = "00" Then ExitLoop
$i += 2
$RunListClustersLength = Dec(StringMid($RunListID,2,1))
$RunListVCNLength = Dec(StringMid($RunListID,1,1))
$RunListClusters = Dec(_SwapEndian(StringMid($DataRun,$i,$RunListClustersLength*2)),2)
$i += $RunListClustersLength*2
$RunListVCN = _SwapEndian(StringMid($DataRun, $i, $RunListVCNLength*2))
;next line handles positive or negative move
$BaseVCN += Dec($RunListVCN,2)-(($r>1) And (Dec(StringMid($RunListVCN,1,1))>7))*Dec(StringMid("10000000000000000",1,$RunListVCNLength*2+1),2)
If $RunListVCN <> "" Then
$RunListVCN = $BaseVCN
Else
$RunListVCN = 0
EndIf
If (($RunListVCN=0) And ($RunListClusters>16) And (Mod($RunListClusters,16)>0)) Then
;may be sparse section at end of Compression Signature
$RUN_Clusters[$r] = Mod($RunListClusters,16)
$RUN_VCN[$r] = $RunListVCN
$RunListClusters -= Mod($RunListClusters,16)
$r += 1
ElseIf (($RunListClusters>16) And (Mod($RunListClusters,16)>0)) Then
;may be compressed data section at start of Compression Signature
$RUN_Clusters[$r] = $RunListClusters-Mod($RunListClusters,16)
$RUN_VCN[$r] = $RunListVCN
$RunListVCN += $RUN_Clusters[$r]
$RunListClusters = Mod($RunListClusters,16)
$r += 1
EndIf
;just normal or sparse data
$RUN_Clusters[$r] = $RunListClusters
$RUN_VCN[$r] = $RunListVCN
$r += 1
$i += $RunListVCNLength*2
Until $i > StringLen($DataRun)
ReDim $RUN_Clusters[$r], $RUN_VCN[$r]
EndFunc
Func _DecodeDataQEntry($attr) ;processes data attribute
$NonResidentFlag = StringMid($attr,17,2)
$NameLength = Dec(StringMid($attr,19,2))
$NameOffset = Dec(_SwapEndian(StringMid($attr,21,4)))
If $NameLength > 0 Then ;must be ADS
$ADS_Name = BinaryToString("0x"&StringMid($attr,$NameOffset*2 + 1,$NameLength*4),2)
$ADS_Name = $FN_Name & "[ADS_" & $ADS_Name & "]"
Else
$ADS_Name = $FN_Name ;need to preserve $FN_Name
EndIf
$Flags = StringMid($attr,25,4)
If BitAND($Flags,"0100") Then $IsCompressed = 1
If BitAND($Flags,"0080") Then $IsSparse = 1
If $NonResidentFlag = '01' Then
$DT_Clusters = Dec(_SwapEndian(StringMid($attr,49,16)),2) - Dec(_SwapEndian(StringMid($attr,33,16)),2) + 1
$DT_RealSize = Dec(_SwapEndian(StringMid($attr,97,16)),2)
$DT_InitSize = Dec(_SwapEndian(StringMid($attr,113,16)),2)
$Offset = Dec(_SwapEndian(StringMid($attr,65,4)))
$DataRun = StringMid($attr,$Offset*2+1,(StringLen($attr)-$Offset)*2)
ElseIf $NonResidentFlag = '00' Then
$DT_LengthOfAttribute = Dec(_SwapEndian(StringMid($attr,33,8)),2)
$Offset = Dec(_SwapEndian(StringMid($attr,41,4)))
$DataRun = StringMid($attr,$Offset*2+1,$DT_LengthOfAttribute*2)
EndIf
EndFunc
Func _DecodeMFTRecord0($record, $FileRef) ;produces DataQ
$MftAttrListString=","
If Not $SkipFixups Then $record = _DoFixup($record, $FileRef)
If $record = "" then Return "" ;corrupt, failed fixup