-
Notifications
You must be signed in to change notification settings - Fork 20
/
ExtractUsnJrnl.au3
3373 lines (3248 loc) · 152 KB
/
ExtractUsnJrnl.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
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Icons\au3.ico
#AutoIt3Wrapper_Outfile=ExtractUsnJrnl.exe
#AutoIt3Wrapper_Outfile_x64=ExtractUsnJrnl64.exe
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_Comment=Quickly extract $UsnJrnl from an NTFS volume
#AutoIt3Wrapper_Res_Description=Quickly extract $UsnJrnl from an NTFS volume
#AutoIt3Wrapper_Res_Fileversion=1.0.0.5
#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 <Array.au3>
#Include <String.au3>
#Include <FileConstants.au3>
#Include <APIConstants.au3>
Global Const $RecordSignature = '46494C45' ; FILE signature
Global $IsPhysicalDrive=False,$IsImage=False
Global $GlobUsnJrnlFileSize, $GlobUsnJrnlSparseBytes, $LogicalClusterNumberforthefileMFT, $NonResidentFlag, $InitState = False, $IsCompressed, $Data_Clusters, $ClustersPerFileRecordSegment,$OutputName="$UsnJrnl_$J.bin"
Global $RUN_VCN[1],$RUN_Clusters[1],$MFT_RUN_Clusters[1],$MFT_RUN_VCN[1],$DataQ[1],$sBuffer,$AttrQ[1],$NameQ[5],$AttributesArr[18][4],$Entries,$TargetDrive,$OutPutPath=@ScriptDir,$TargetImageFile,$ImageOffset=0
Global $SectorsPerCluster,$BytesPerSector,$DATA_Name,$_COMMON_KERNEL32DLL=DllOpen("kernel32.dll"),$INDX_Record_Size=4096,$HEADER_MFTREcordNumber,$FN_ParentReferenceNo,$RawTestOffsetArray
Global $IndxEntryNumberArr[1],$IndxMFTReferenceArr[1],$IndxMFTRefSeqNoArr[1],$IndxMFTReferenceOfParentArr[1],$IndxMFTParentRefSeqNoArr[1],$IndxCTimeArr[1],$IndxATimeArr[1],$IndxMTimeArr[1],$IndxRTimeArr[1],$IndxFileNameArr[1]
Global $DATA_RealSize,$FN_FileName,$DataRun,$MFT_Record_Size,$MFT_Offset,$SkipFixups=0,$IsRawShadowCopy=0,$DoIndxOffsetArray=0,$IsFirstRun=1,$IsCurrentIndxOfParent=0,$ResidentIndx
Global $InfoArrShadowMainTarget[3],$InfoArrShadowParent[3],$IndxFileNameFromParentArr[1],$IndxMFTReferenceFromParentArr[1],$IndxMFTReferenceOfParentFromParentArr[1],$IndxCTimeFromParentArr[1],$IndxATimeFromParentArr[1],$IndxMTimeFromParentArr[1],$IndxRTimeFromParentArr[1]
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 = 6 ; YYYY-MM-DD HH:MM:SS:MSMSMS:NSNSNSNS = 2007-08-18 08:15:37:733:1234
Global $tDelta = _WinTime_GetUTCToLocalFileTimeDelta(), $TimestampPrecision
Global $VolumesArray[1][3]
$VolumesArray[0][0] = "Type"
$VolumesArray[0][1] = "ByteOffset"
$VolumesArray[0][2] = "Sectors"
$DoRead=1
ConsoleWrite("ExtractUsnJrnl v1.0.0.5" & @CRLF & @CRLF)
_GetInputParams()
;_ArrayDisplay($VolumesArray,"$VolumesArray")
$TargetFileName = "x:\$Extend\$UsnJrnl"
$IndexNumber=""
$begin = TimerInit()
_ReadBootSector($TargetDrive)
If @error Then
ConsoleWrite("Error: Filesystem not NTFS" & @CRLF)
Exit
EndIf
$BytesPerCluster = $SectorsPerCluster*$BytesPerSector
$MFTEntry = _FindMFT($TargetDrive,0)
$MFT = _DecodeMFTRecord0($MFTEntry, 0) ;produces DataQ for $MFT, record 0
If $MFT = "" Then
ConsoleWrite("Error: Parsing the MFT record 0" & @CRLF)
Exit
EndIf
_GetRunsFromAttributeListMFT0()
$MFTSize = $DATA_RealSize
$MFT_RUN_VCN = $RUN_VCN
$MFT_RUN_Clusters = $RUN_Clusters
If Not _Prep($TargetDrive,$IndexNumber,$TargetFileName) Then
ConsoleWrite("Error initializing structs and arrays" & @crlf)
Exit
EndIf
$RetRec = _FindFileMFTRecord($TargetDrive,$InfoArrShadowMainTarget[0])
$NewRecord = $RetRec[1]
If _DecodeMFTRecord($TargetDrive,$NewRecord,1) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $RetRec[0] & @CRLF)
Exit
EndIf
$RetRec = _FindFileMFTRecord($TargetDrive,$InfoArrShadowMainTarget[0])
$NewRecord = $RetRec[1]
If _DecodeMFTRecord($TargetDrive,$NewRecord,3) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $RetRec[0] & @CRLF)
Exit
EndIf
;_ArrayDisplay($RawTestOffsetArray,"$RawTestOffsetArray")
If Ubound($RawTestOffsetArray) > 1 Then
Dim $nBytes
$OutUsnJrnlFile = $OutPutPath & "\" & $OutputName
$hVol = _WinAPI_CreateFile($TargetDrive,2,2,7)
If $hVol = 0 Then
ConsoleWrite("Error: Creating handle on " & $TargetDrive & @CRLF)
Exit
EndIf
If FileExists($OutUsnJrnlFile) Then
$CurrentTimestamp = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC
FileMove($OutUsnJrnlFile,$OutUsnJrnlFile&".renamed_"&$CurrentTimestamp)
ConsoleWrite("Previous output file renamed to prevent overwrite: " & $OutUsnJrnlFile&".renamed_"&$CurrentTimestamp & @CRLF)
EndIf
$hOutFile = _WinAPI_CreateFile("\\.\" & $OutUsnJrnlFile, 1, 6, 6)
If $hOutFile = 0 Then
ConsoleWrite("Error in function CreateFile on " & $OutUsnJrnlFile & " : " & _WinAPI_GetLastErrorMessage() & @CRLF)
Exit
EndIf
For $i = 1 To UBound($RawTestOffsetArray)-1
If $RawTestOffsetArray[$i][0] = 0 Then ContinueLoop
ConsoleWrite(@CRLF & "Trying volume offset 0x" & Hex(Int($RawTestOffsetArray[$i][0])) & @CRLF)
_WinAPI_SetFilePointerEx($hVol, $RawTestOffsetArray[$i][0], $FILE_BEGIN)
$End=0
If Mod($RawTestOffsetArray[$i][2],512) Then
; ConsoleWrite("Corrected chunk size" & @crlf)
Do
$End += 1
until Mod($RawTestOffsetArray[$i][2]+$End,512)=1
$End -= 1
EndIf
$tBuffer = DllStructCreate("byte[" & $RawTestOffsetArray[$i][2]+$End & "]")
If Not _WinAPI_ReadFile($hVol, DllStructGetPtr($tBuffer), $RawTestOffsetArray[$i][2]+$End, $nBytes) Then
ConsoleWrite("Error in function ReadFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
EndIf
If Not _WinAPI_WriteFile($hOutFile, DllStructGetPtr($tBuffer), $RawTestOffsetArray[$i][2], $nBytes) Then
ConsoleWrite("Error in function WriteFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
EndIf
Next
_WinAPI_CloseHandle($hVol)
_WinAPI_CloseHandle($hOutFile)
EndIf
ConsoleWrite("Extract took " & _WinAPI_StrFromTimeInterval(TimerDiff($begin)) & @CRLF)
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 = _UnicodeHexToStr(StringMid($attr,$NameOffset*2 + 1,$NameLength*4))
$ADS_Name = $FN_FileName & "[ADS_" & $ADS_Name & "]"
Else
$ADS_Name = $FN_FileName ;need to preserve $FN_FileName
EndIf
$Flags = StringMid($attr,25,4)
If BitAND($Flags,"0100") Then $IsCompressed = 1
;If BitAND($Flags,"0080") Then $IsSparse = 1
If $NonResidentFlag = '01' Then
$DATA_Clusters = Dec(_SwapEndian(StringMid($attr,49,16)),2) - Dec(_SwapEndian(StringMid($attr,33,16)),2) + 1
$DATA_RealSize = Dec(_SwapEndian(StringMid($attr,97,16)),2)
;$DATA_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
$DATA_LengthOfAttribute = Dec(_SwapEndian(StringMid($attr,33,8)),2)
$Offset = Dec(_SwapEndian(StringMid($attr,41,4)))
$DataRun = StringMid($attr,$Offset*2+1,$DATA_LengthOfAttribute*2)
EndIf
EndFunc
Func _SwapEndian($iHex)
Return StringMid(Binary(Dec($iHex,2)),3, StringLen($iHex))
EndFunc
Func _ExtractDataRuns()
$r=UBound($RUN_Clusters)
$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 ;$RUN_VCN[$r-1] ;0
EndIf
If (($RunListVCN=0) And ($RunListClusters>16) And (Mod($RunListClusters,16)>0)) Then
;may be sparse section at end of Compression Signature
_ArrayAdd($RUN_Clusters,Mod($RunListClusters,16))
_ArrayAdd($RUN_VCN,$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
_ArrayAdd($RUN_Clusters,$RunListClusters-Mod($RunListClusters,16))
_ArrayAdd($RUN_VCN,$RunListVCN)
$RunListVCN += $RUN_Clusters[$r]
$RunListClusters = Mod($RunListClusters,16)
$r += 1
EndIf
;just normal or sparse data
_ArrayAdd($RUN_Clusters,$RunListClusters)
_ArrayAdd($RUN_VCN,$RunListVCN)
$r += 1
$i += $RunListVCNLength*2
Until $i > StringLen($DataRun)
EndFunc
Func _FindMFT($TargetDevice,$TargetFile)
Local $nBytes;, $MFT_Record_Size=1024
$tBuffer = DllStructCreate("byte[" & $MFT_Record_Size & "]")
$hFile = _WinAPI_CreateFile($TargetDevice, 2, 2, 7)
If $hFile = 0 Then
ConsoleWrite("Error CreateFile in function _FindMFT(): " & _WinAPI_GetLastErrorMessage() & " for " & $TargetDevice & @CRLF)
Return SetError(1,0,0)
EndIf
_WinAPI_SetFilePointerEx($hFile, $ImageOffset+$MFT_Offset, $FILE_BEGIN)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $MFT_Record_Size, $nBytes)
_WinAPI_CloseHandle($hFile)
$record = DllStructGetData($tBuffer, 1)
If NOT StringMid($record,1,8) = '46494C45' Then
ConsoleWrite("MFT record signature not found. "& @crlf)
Return ""
EndIf
If StringMid($record,47,4) = "0100" AND Dec(_SwapEndian(StringMid($record,91,8))) = $TargetFile Then
; ConsoleWrite("MFT record found" & @CRLF)
Return $record ;returns record for MFT
EndIf
ConsoleWrite("MFT record not found" & @CRLF)
Return ""
EndFunc
Func _ReadBootSector($TargetDevice)
Local $nbytes
$tBuffer=DllStructCreate("byte[512]")
$hFile = _WinAPI_CreateFile($TargetDevice,2,2,7)
If $hFile = 0 then
ConsoleWrite("Error CreateFile in function _ReadBootSector(): " & _WinAPI_GetLastErrorMessage() & " for: " & $TargetDevice & @crlf)
Return SetError(1,0,0)
EndIf
_WinAPI_SetFilePointerEx($hFile, $ImageOffset, $FILE_BEGIN)
$read = _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 512, $nBytes)
If $read = 0 then
ConsoleWrite("Error in function ReadFile: " & _WinAPI_GetLastErrorMessage() & " for: " & "\\.\" & $TargetDevice & @crlf)
Return SetError(1,0,0)
EndIf
_WinAPI_CloseHandle($hFile)
; Good starting point from KaFu & trancexx at the AutoIt forum
$tBootSectorSections = DllStructCreate("align 1;" & _
"byte Jump[3];" & _
"char SystemName[8];" & _
"ushort BytesPerSector;" & _
"ubyte SectorsPerCluster;" & _
"ushort ReservedSectors;" & _
"ubyte[3];" & _
"ushort;" & _
"ubyte MediaDescriptor;" & _
"ushort;" & _
"ushort SectorsPerTrack;" & _
"ushort NumberOfHeads;" & _
"dword HiddenSectors;" & _
"dword;" & _
"dword;" & _
"int64 TotalSectors;" & _
"int64 LogicalClusterNumberforthefileMFT;" & _
"int64 LogicalClusterNumberforthefileMFTMirr;" & _
"dword ClustersPerFileRecordSegment;" & _
"dword ClustersPerIndexBlock;" & _
"int64 NTFSVolumeSerialNumber;" & _
"dword Checksum", DllStructGetPtr($tBuffer))
If Not DllStructGetData($tBootSectorSections, "SystemName") = "NTFS" Then Return SetError(1,0,0)
$BytesPerSector = DllStructGetData($tBootSectorSections, "BytesPerSector")
$SectorsPerCluster = DllStructGetData($tBootSectorSections, "SectorsPerCluster")
$BytesPerCluster = $BytesPerSector * $SectorsPerCluster
$ClustersPerFileRecordSegment = DllStructGetData($tBootSectorSections, "ClustersPerFileRecordSegment")
$LogicalClusterNumberforthefileMFT = DllStructGetData($tBootSectorSections, "LogicalClusterNumberforthefileMFT")
$MFT_Offset = $BytesPerCluster * $LogicalClusterNumberforthefileMFT
If $ClustersPerFileRecordSegment > 127 Then
$MFT_Record_Size = 2 ^ (256 - $ClustersPerFileRecordSegment)
Else
$MFT_Record_Size = $BytesPerCluster * $ClustersPerFileRecordSegment
EndIf
$MFT_Record_Size=Int($MFT_Record_Size)
$ClustersPerFileRecordSegment = Ceiling($MFT_Record_Size/$BytesPerCluster)
EndFunc
Func _HexEncode($bInput)
Local $tInput = DllStructCreate("byte[" & BinaryLen($bInput) & "]")
DllStructSetData($tInput, 1, $bInput)
Local $a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr($tInput), _
"dword", DllStructGetSize($tInput), _
"dword", 11, _
"ptr", 0, _
"dword*", 0)
If @error Or Not $a_iCall[0] Then
Return SetError(1, 0, "")
EndIf
Local $iSize = $a_iCall[5]
Local $tOut = DllStructCreate("char[" & $iSize & "]")
$a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr($tInput), _
"dword", DllStructGetSize($tInput), _
"dword", 11, _
"ptr", DllStructGetPtr($tOut), _
"dword*", $iSize)
If @error Or Not $a_iCall[0] Then
Return SetError(2, 0, "")
EndIf
Return SetError(0, 0, DllStructGetData($tOut, 1))
EndFunc
Func _DecodeMFTRecord($TargetDevice,$MFTEntry,$MFTMode)
;Global $IndxEntryNumberArr[1],$IndxMFTReferenceArr[1],$IndxIndexFlagsArr[1],$IndxMFTReferenceOfParentArr[1],$IndxCTimeArr[1],$IndxATimeArr[1],$IndxMTimeArr[1],$IndxRTimeArr[1],$IndxAllocSizeArr[1],$IndxRealSizeArr[1],$IndxFileFlagsArr[1],$IndxFileNameArr[1],$IndxSubNodeVCNArr[1],$IndxNameSpaceArr[1]
Global $IndxEntryNumberArr[1],$IndxMFTReferenceArr[1],$IndxMFTReferenceOfParentArr[1],$IndxCTimeArr[1],$IndxATimeArr[1],$IndxMTimeArr[1],$IndxRTimeArr[1],$IndxFileNameArr[1]
Global $SIArrValue[13][1], $SIArrOffset[13][1], $SIArrSize[13][1], $FNArrValue[14][1], $FNArrOffset[14][1], $FN_Number=0, $Header_SequenceNo='', $Header_HardLinkCount=''
Local $SI_Number, $INDEXROOT_Number
Local $INDEX_ROOT_ON="FALSE",$INDEX_ALLOCATION_ON="FALSE",$CoreData[2],$CoreDataChunk,$CoreIndexAllocation,$CoreIndexAllocationChunk,$CoreIndexAllocationName
Local $UpdSeqArrPart0, $UpdSeqArrPart1, $UpdSeqArrPart2, $RecordEnd1, $RecordEnd2
Global $DataQ[1],$Mode2Data=""
Global $IRArr[12][2],$IndxArr[20][2]
_SetArrays()
$HEADER_RecordRealSize = ""
$HEADER_MFTREcordNumber = ""
$UpdSeqArrOffset = Dec(_SwapEndian(StringMid($MFTEntry,11,4)))
$UpdSeqArrSize = Dec(_SwapEndian(StringMid($MFTEntry,15,4)))
$UpdSeqArr = StringMid($MFTEntry,3+($UpdSeqArrOffset*2),$UpdSeqArrSize*2*2)
If Not $SkipFixups Then
If $MFT_Record_Size = 1024 Then
$UpdSeqArrPart0 = StringMid($UpdSeqArr,1,4)
$UpdSeqArrPart1 = StringMid($UpdSeqArr,5,4)
$UpdSeqArrPart2 = StringMid($UpdSeqArr,9,4)
$RecordEnd1 = StringMid($MFTEntry,1023,4)
$RecordEnd2 = StringMid($MFTEntry,2047,4)
If $UpdSeqArrPart0 <> $RecordEnd1 OR $UpdSeqArrPart0 <> $RecordEnd2 Then
; _DebugOut("The record failed Fixup", $MFTEntry)
ConsoleWrite("The record failed Fixup:" & @CRLF)
ConsoleWrite(_HexEncode($MFTEntry) & @CRLF)
Return -1
EndIf
$MFTEntry = StringMid($MFTEntry,1,1022) & $UpdSeqArrPart1 & StringMid($MFTEntry,1027,1020) & $UpdSeqArrPart2
ElseIf $MFT_Record_Size = 4096 Then
$UpdSeqArrPart0 = StringMid($UpdSeqArr,1,4)
$UpdSeqArrPart1 = StringMid($UpdSeqArr,5,4)
$UpdSeqArrPart2 = StringMid($UpdSeqArr,9,4)
Local $UpdSeqArrPart3 = StringMid($UpdSeqArr,13,4)
Local $UpdSeqArrPart4 = StringMid($UpdSeqArr,17,4)
Local $UpdSeqArrPart5 = StringMid($UpdSeqArr,21,4)
Local $UpdSeqArrPart6 = StringMid($UpdSeqArr,25,4)
Local $UpdSeqArrPart7 = StringMid($UpdSeqArr,29,4)
Local $UpdSeqArrPart8 = StringMid($UpdSeqArr,33,4)
$RecordEnd1 = StringMid($MFTEntry,1023,4)
$RecordEnd2 = StringMid($MFTEntry,2047,4)
Local $RecordEnd3 = StringMid($MFTEntry,3071,4)
Local $RecordEnd4 = StringMid($MFTEntry,4095,4)
Local $RecordEnd5 = StringMid($MFTEntry,5119,4)
Local $RecordEnd6 = StringMid($MFTEntry,6143,4)
Local $RecordEnd7 = StringMid($MFTEntry,7167,4)
Local $RecordEnd8 = StringMid($MFTEntry,8191,4)
If $UpdSeqArrPart0 <> $RecordEnd1 OR $UpdSeqArrPart0 <> $RecordEnd2 OR $UpdSeqArrPart0 <> $RecordEnd3 OR $UpdSeqArrPart0 <> $RecordEnd4 OR $UpdSeqArrPart0 <> $RecordEnd5 OR $UpdSeqArrPart0 <> $RecordEnd6 OR $UpdSeqArrPart0 <> $RecordEnd7 OR $UpdSeqArrPart0 <> $RecordEnd8 Then
; _DebugOut("The record failed Fixup", $MFTEntry)
ConsoleWrite("The record failed Fixup:" & @CRLF)
ConsoleWrite(_HexEncode($MFTEntry) & @CRLF)
Return -1
Else
$MFTEntry = StringMid($MFTEntry,1,1022) & $UpdSeqArrPart1 & StringMid($MFTEntry,1027,1020) & $UpdSeqArrPart2 & StringMid($MFTEntry,2051,1020) & $UpdSeqArrPart3 & StringMid($MFTEntry,3075,1020) & $UpdSeqArrPart4 & StringMid($MFTEntry,4099,1020) & $UpdSeqArrPart5 & StringMid($MFTEntry,5123,1020) & $UpdSeqArrPart6 & StringMid($MFTEntry,6147,1020) & $UpdSeqArrPart7 & StringMid($MFTEntry,7171,1020) & $UpdSeqArrPart8
EndIf
EndIf
EndIf
;If $SkipFixups Then
; $record_tmp = _DoFixup($record, $FileRef)
; If Not $record_tmp = "" Then $record = $record_tmp
;EndIf
;If $record = "" then Return "" ;corrupt, failed fixup
;------------If Not $SkipFixups Then $record = _DoFixup($record, $ref)
$HEADER_RecordRealSize = Dec(_SwapEndian(StringMid($MFTEntry,51,8)),2)
If $UpdSeqArrOffset = 48 Then
$HEADER_MFTREcordNumber = Dec(_SwapEndian(StringMid($MFTEntry,91,8)),2)
Else
$HEADER_MFTREcordNumber = "NT style"
EndIf
$Header_SequenceNo = Dec(_SwapEndian(StringMid($MFTEntry,35,4)))
$Header_HardLinkCount = Dec(_SwapEndian(StringMid($MFTEntry,39,4)))
$AttributeOffset = (Dec(StringMid($MFTEntry,43,2))*2)+3
While 1
$AttributeType = StringMid($MFTEntry,$AttributeOffset,8)
$AttributeSize = StringMid($MFTEntry,$AttributeOffset+8,8)
$AttributeSize = Dec(_SwapEndian($AttributeSize),2)
; ConsoleWrite("$AttributeType: " & $AttributeType & @CRLF)
Select
Case $AttributeType = $STANDARD_INFORMATION
; $STANDARD_INFORMATION_ON = "TRUE"
$SI_Number += 1
_Get_StandardInformation($MFTEntry,$AttributeOffset,$SI_Number)
Case $AttributeType = $ATTRIBUTE_LIST
; $ATTRIBUTE_LIST_ON = "TRUE"
;$ATTRIBLIST_Number += 1
;$MFTEntryOrig = $MFTEntry
$AttrList = StringMid($MFTEntry,$AttributeOffset,$AttributeSize*2)
_DecodeAttrList($HEADER_MFTRecordNumber, $AttrList) ;produces $AttrQ - extra record list
$str = ""
For $i = 1 To $AttrQ[0]
$RetRec = _FindFileMFTRecord($TargetDevice,$AttrQ[$i])
$record = $RetRec[1]
$str &= _StripMftRecord($record) ;no header or end marker
Next
$str &= "FFFFFFFF" ;add end marker
$MFTEntry = StringMid($MFTEntry,1,($HEADER_RecordRealSize-8)*2+2) & $str ;strip "FFFFFFFF..." first
Case $AttributeType = $FILE_NAME
; $FILE_NAME_ON = "TRUE"
$FN_Number += 1
$attr = StringMid($MFTEntry,$AttributeOffset,$AttributeSize*2)
$NameSpace = StringMid($attr,179,2)
Select
Case $NameSpace = "00" ;POSIX
$NameQ[2] = $attr
Case $NameSpace = "01" ;WIN32
$NameQ[4] = $attr
Case $NameSpace = "02" ;DOS
$NameQ[1] = $attr
Case $NameSpace = "03" ;DOS+WIN32
$NameQ[3] = $attr
EndSelect
_Get_FileName($MFTEntry,$AttributeOffset,$FN_Number)
Case $AttributeType = $OBJECT_ID
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $OBJECT_ID_ON = "TRUE"
;$OBJID_Number += 1
Case $AttributeType = $SECURITY_DESCRIPTOR
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $SECURITY_DESCRIPTOR_ON = "TRUE"
;$SECURITY_Number += 1
Case $AttributeType = $VOLUME_NAME
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $VOLUME_NAME_ON = "TRUE"
;$VOLNAME_Number += 1
Case $AttributeType = $VOLUME_INFORMATION
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $VOLUME_INFORMATION_ON = "TRUE"
;$VOLINFO_Number += 1
Case $AttributeType = $DATA
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $DATA_ON = "TRUE"
;$DATA_Number += 1
; ConsoleWrite("$DATA_Number: " & $DATA_Number & @CRLF)
_ArrayAdd($DataQ, StringMid($MFTEntry,$AttributeOffset,$AttributeSize*2))
If $MFTMode = 2 Then ;For files that we need the content of, like the shadow copy master file. It is a small file so load it to memory
$CoreData = _GetAttributeEntry($TargetDevice,StringMid($MFTEntry,$AttributeOffset,$AttributeSize*2))
$CoreDataChunk = $CoreData[0]
;$CoreDataName = $CoreData[1]
;ConsoleWrite("Retrieved data:" & @CRLF)
;ConsoleWrite(_HexEncode("0x"&$CoreDataChunk) & @CRLF)
$Mode2Data = $CoreDataChunk
ElseIf $MFTMode = 3 Then ;For the actual shadow copy files we only want to locate the clusters
$CoreData = _GetAttributeEntryNoRead($TargetDevice,StringMid($MFTEntry,$AttributeOffset,$AttributeSize*2))
; ConsoleWrite("$CoreData[1]: " & $CoreData[1] & @CRLF)
; If $CoreData[1] = "$J" Then Return 2
EndIf
Case $AttributeType = $INDEX_ROOT
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
$INDEX_ROOT_ON = "TRUE"
$INDEXROOT_Number += 1
ReDim $IRArr[12][$INDEXROOT_Number+1]
;INDEX_ROOT is ok to process for shadows copy data as it is resident
; If Not $IsRawShadowCopy Then
$CoreIndexRoot = _GetAttributeEntry($TargetDevice,StringMid($MFTEntry,$AttributeOffset,$AttributeSize*2))
$CoreIndexRootChunk = $CoreIndexRoot[0]
$CoreIndexRootName = $CoreIndexRoot[1]
If $CoreIndexRootName = "$I30" Then _Get_IndexRoot($CoreIndexRootChunk,$INDEXROOT_Number,$CoreIndexRootName)
; EndIf
Case $AttributeType = $INDEX_ALLOCATION
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
$INDEX_ALLOCATION_ON = "TRUE"
;$INDEXALLOC_Number += 1
If $DoIndxOffsetArray Then $IsCurrentIndxOfParent=1
; ConsoleWrite("IsShadowCopy: " & $IsRawShadowCopy & @CRLF)
; If Not $IsRawShadowCopy Then ;INDX may point to somewhere on the volume, and not within the shadow copy file
If $MFTMode = 1 Then ;Regular mode, only parse
$CoreIndexAllocation = _GetAttributeEntry($TargetDevice,StringMid($MFTEntry,$AttributeOffset,$AttributeSize*2))
$CoreIndexAllocationChunk = $CoreIndexAllocation[0]
$CoreIndexAllocationName = $CoreIndexAllocation[1]
; _Arrayadd($HexDumpIndxRecord,$CoreIndexAllocationChunk)
If $CoreIndexAllocationName = "$I30" Then _Get_IndexAllocation($CoreIndexAllocationChunk)
EndIf
Case $AttributeType = $BITMAP
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $BITMAP_ON = "TRUE"
;$BITMAP_Number += 1
Case $AttributeType = $REPARSE_POINT
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $REPARSE_POINT_ON = "TRUE"
;$REPARSEPOINT_Number += 1
Case $AttributeType = $EA_INFORMATION
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $EA_INFORMATION_ON = "TRUE"
;$EAINFO_Number += 1
Case $AttributeType = $EA
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $EA_ON = "TRUE"
;$EA_Number += 1
Case $AttributeType = $PROPERTY_SET
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $PROPERTY_SET_ON = "TRUE"
;$PROPERTYSET_Number += 1
Case $AttributeType = $LOGGED_UTILITY_STREAM
If $IsRawShadowCopy Then Return 1 ;We are only interested in ref and name for comparison.
; $LOGGED_UTILITY_STREAM_ON = "TRUE"
;$LOGGEDUTILSTREAM_Number += 1
Case $AttributeType = $ATTRIBUTE_END_MARKER
ExitLoop
EndSelect
$AttributeOffset += $AttributeSize*2
WEnd
$AttributesArr[9][2] = $INDEX_ROOT_ON
$AttributesArr[10][2] = $INDEX_ALLOCATION_ON
Return 2
EndFunc
Func _UnicodeHexToStr($FileName)
$str = ""
For $i = 1 To StringLen($FileName) Step 4
$str &= ChrW(Dec(_SwapEndian(StringMid($FileName, $i, 4))))
Next
Return $str
EndFunc
Func _SetArrays()
$SIArrValue[0][0] = "Field name:"
$SIArrValue[1][0] = "HEADER_Flags"
$SIArrValue[2][0] = "CTime"
$SIArrValue[3][0] = "ATime"
$SIArrValue[4][0] = "MTime"
$SIArrValue[5][0] = "RTime"
$SIArrValue[6][0] = "DOS File Permissions"
$SIArrValue[7][0] = "Max Versions"
$SIArrValue[8][0] = "Version Number"
$SIArrValue[9][0] = "Class ID"
$SIArrValue[10][0] = "Owner ID"
$SIArrValue[11][0] = "Security ID"
$SIArrValue[12][0] = "USN"
$FNArrValue[0][0] = "Field name"
$FNArrValue[1][0] = "ParentReferenceNo"
$FNArrValue[2][0] = "ParentSequenceNo"
$FNArrValue[3][0] = "CTime"
$FNArrValue[4][0] = "ATime"
$FNArrValue[5][0] = "MTime"
$FNArrValue[6][0] = "RTime"
$FNArrValue[7][0] = "AllocSize"
$FNArrValue[8][0] = "RealSize"
$FNArrValue[9][0] = "Flags"
$FNArrValue[10][0] = "NameLength"
$FNArrValue[11][0] = "NameType"
$FNArrValue[12][0] = "NameSpace"
$FNArrValue[13][0] = "FileName"
$IndxEntryNumberArr[0] = "Entry number"
$IndxMFTReferenceArr[0] = "MFTReference"
$IndxMFTRefSeqNoArr[0] = "MFTReference SeqNo"
; $IndxIndexFlagsArr[0] = "IndexFlags"
$IndxMFTReferenceOfParentArr[0] = "Parent MFTReference"
$IndxMFTParentRefSeqNoArr[0] = "Parent MFTReference SeqNo"
$IndxCTimeArr[0] = "CTime"
$IndxATimeArr[0] = "ATime"
$IndxMTimeArr[0] = "MTime"
$IndxRTimeArr[0] = "RTime"
; $IndxAllocSizeArr[0] = "AllocSize"
; $IndxRealSizeArr[0] = "RealSize"
; $IndxFileFlagsArr[0] = "File flags"
$IndxFileNameArr[0] = "FileName"
; $IndxNameSpaceArr[0] = "NameSpace"
; $IndxSubNodeVCNArr[0] = "SubNodeVCN"
EndFunc
Func _Get_StandardInformation($MFTEntry,$SI_Offset,$SI_Number)
Redim $SIArrValue[13][$SI_Number+1]
Redim $SIArrOffset[13][$SI_Number+1]
Redim $SIArrSize[13][$SI_Number+1]
$SI_HEADER_Flags = StringMid($MFTEntry,$SI_Offset+24,4)
$SI_HEADER_Flags = _SwapEndian($SI_HEADER_Flags)
$SI_HEADER_Flags = _AttribHeaderFlags("0x" & $SI_HEADER_Flags)
;
$SI_CTime = StringMid($MFTEntry,$SI_Offset+48,16)
$SI_CTime = _SwapEndian($SI_CTime)
$SI_CTime_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $SI_CTime)
$SI_CTime = _WinTime_UTCFileTimeFormat(Dec($SI_CTime)-$tDelta,$DateTimeFormat,2)
$SI_CTime = $SI_CTime & ":" & _FillZero(StringRight($SI_CTime_tmp,4))
;
$SI_ATime = StringMid($MFTEntry,$SI_Offset+64,16)
$SI_ATime = _SwapEndian($SI_ATime)
$SI_ATime_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $SI_ATime)
$SI_ATime = _WinTime_UTCFileTimeFormat(Dec($SI_ATime)-$tDelta,$DateTimeFormat,2)
$SI_ATime = $SI_ATime & ":" & _FillZero(StringRight($SI_ATime_tmp,4))
;
$SI_MTime = StringMid($MFTEntry,$SI_Offset+80,16)
$SI_MTime = _SwapEndian($SI_MTime)
$SI_MTime_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $SI_MTime)
$SI_MTime = _WinTime_UTCFileTimeFormat(Dec($SI_MTime)-$tDelta,$DateTimeFormat,2)
$SI_MTime = $SI_MTime & ":" & _FillZero(StringRight($SI_MTime_tmp,4))
;
$SI_RTime = StringMid($MFTEntry,$SI_Offset+96,16)
$SI_RTime = _SwapEndian($SI_RTime)
$SI_RTime_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $SI_RTime)
$SI_RTime = _WinTime_UTCFileTimeFormat(Dec($SI_RTime)-$tDelta,$DateTimeFormat,2)
$SI_RTime = $SI_RTime & ":" & _FillZero(StringRight($SI_RTime_tmp,4))
;
$SI_FilePermission = StringMid($MFTEntry,$SI_Offset+112,8)
;ConsoleWrite("$SI_FilePermission: " & $SI_FilePermission & @CRLF)
$SI_FilePermission = _SwapEndian($SI_FilePermission)
$SI_FilePermission = _File_Permissions("0x" & $SI_FilePermission)
;ConsoleWrite("$SI_FilePermission: " & $SI_FilePermission & @CRLF)
$SI_MaxVersions = StringMid($MFTEntry,$SI_Offset+120,8)
$SI_MaxVersions = Dec(_SwapEndian($SI_MaxVersions))
$SI_VersionNumber = StringMid($MFTEntry,$SI_Offset+128,8)
$SI_VersionNumber = Dec(_SwapEndian($SI_VersionNumber))
$SI_ClassID = StringMid($MFTEntry,$SI_Offset+136,8)
$SI_ClassID = Dec(_SwapEndian($SI_ClassID))
$SI_OwnerID = StringMid($MFTEntry,$SI_Offset+144,8)
$SI_OwnerID = Dec(_SwapEndian($SI_OwnerID))
$SI_SecurityID = StringMid($MFTEntry,$SI_Offset+152,8)
$SI_SecurityID = Dec(_SwapEndian($SI_SecurityID))
$SI_USN = StringMid($MFTEntry,$SI_Offset+176,16)
$SI_USN = Dec(_SwapEndian($SI_USN))
If Not $IsFirstRun Then
$SIArrValue[1][$SI_Number] = $SI_HEADER_Flags
$SIArrValue[2][$SI_Number] = $SI_CTime
$SIArrValue[3][$SI_Number] = $SI_ATime
$SIArrValue[4][$SI_Number] = $SI_MTime
$SIArrValue[5][$SI_Number] = $SI_RTime
$SIArrValue[6][$SI_Number] = $SI_FilePermission
$SIArrValue[7][$SI_Number] = $SI_MaxVersions
$SIArrValue[8][$SI_Number] = $SI_VersionNumber
$SIArrValue[9][$SI_Number] = $SI_ClassID
$SIArrValue[10][$SI_Number] = $SI_OwnerID
$SIArrValue[11][$SI_Number] = $SI_SecurityID
$SIArrValue[12][$SI_Number] = $SI_USN
; _ArrayDisplay($SIArrValue,"$SIArrValue")
;
$SIArrOffset[1][$SI_Number] = $SI_Offset+24
$SIArrOffset[2][$SI_Number] = $SI_Offset+48
$SIArrOffset[3][$SI_Number] = $SI_Offset+64
$SIArrOffset[4][$SI_Number] = $SI_Offset+80
$SIArrOffset[5][$SI_Number] = $SI_Offset+96
$SIArrOffset[6][$SI_Number] = $SI_Offset+112
$SIArrOffset[7][$SI_Number] = $SI_Offset+120
$SIArrOffset[8][$SI_Number] = $SI_Offset+128
$SIArrOffset[9][$SI_Number] = $SI_Offset+136
$SIArrOffset[10][$SI_Number] = $SI_Offset+144
$SIArrOffset[11][$SI_Number] = $SI_Offset+152
$SIArrOffset[12][$SI_Number] = $SI_Offset+176
;
$SIArrSize[1][$SI_Number] = 2
$SIArrSize[2][$SI_Number] = 8
$SIArrSize[3][$SI_Number] = 8
$SIArrSize[4][$SI_Number] = 8
$SIArrSize[5][$SI_Number] = 8
$SIArrSize[6][$SI_Number] = 4
$SIArrSize[7][$SI_Number] = 4
$SIArrSize[8][$SI_Number] = 4
$SIArrSize[9][$SI_Number] = 4
$SIArrSize[10][$SI_Number] = 4
$SIArrSize[11][$SI_Number] = 4
$SIArrSize[12][$SI_Number] = 8
EndIf
EndFunc
Func _Get_FileName($MFTEntry,$FN_Offset,$FN_Number)
Redim $FNArrValue[14][$FN_Number+1]
Redim $FNArrOffset[14][$FN_Number+1]
$FN_ParentReferenceNo = StringMid($MFTEntry,$FN_Offset+48,12)
$FN_ParentReferenceNo = Dec(_SwapEndian($FN_ParentReferenceNo))
$FN_ParentSequenceNo = StringMid($MFTEntry,$FN_Offset+60,4)
$FN_ParentSequenceNo = Dec(_SwapEndian($FN_ParentSequenceNo))
;
$FN_CTime = StringMid($MFTEntry,$FN_Offset+64,16)
$FN_CTime = _SwapEndian($FN_CTime)
$FN_CTime_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $FN_CTime)
$FN_CTime = _WinTime_UTCFileTimeFormat(Dec($FN_CTime)-$tDelta,$DateTimeFormat,2)
$FN_CTime = $FN_CTime & ":" & _FillZero(StringRight($FN_CTime_tmp,4))
;
$FN_ATime = StringMid($MFTEntry,$FN_Offset+80,16)
$FN_ATime = _SwapEndian($FN_ATime)
$FN_ATime_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $FN_ATime)
$FN_ATime = _WinTime_UTCFileTimeFormat(Dec($FN_ATime)-$tDelta,$DateTimeFormat,2)
$FN_ATime = $FN_ATime & ":" & _FillZero(StringRight($FN_ATime_tmp,4))
;
$FN_MTime = StringMid($MFTEntry,$FN_Offset+96,16)
$FN_MTime = _SwapEndian($FN_MTime)
$FN_MTime_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $FN_MTime)
$FN_MTime = _WinTime_UTCFileTimeFormat(Dec($FN_MTime)-$tDelta,$DateTimeFormat,2)
$FN_MTime = $FN_MTime & ":" & _FillZero(StringRight($FN_MTime_tmp,4))
;
$FN_RTime = StringMid($MFTEntry,$FN_Offset+112,16)
$FN_RTime = _SwapEndian($FN_RTime)
$FN_RTime_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $FN_RTime)
$FN_RTime = _WinTime_UTCFileTimeFormat(Dec($FN_RTime)-$tDelta,$DateTimeFormat,2)
$FN_RTime = $FN_RTime & ":" & _FillZero(StringRight($FN_RTime_tmp,4))
;
$FN_AllocSize = StringMid($MFTEntry,$FN_Offset+128,16)
$FN_AllocSize = Dec(_SwapEndian($FN_AllocSize))
$FN_RealSize = StringMid($MFTEntry,$FN_Offset+144,16)
$FN_RealSize = Dec(_SwapEndian($FN_RealSize))
$FN_Flags = StringMid($MFTEntry,$FN_Offset+160,8)
;ConsoleWrite("$FN_Flags: " & $FN_Flags & @CRLF)
$FN_Flags = _SwapEndian($FN_Flags)
$FN_Flags = _File_Permissions("0x" & $FN_Flags)
;ConsoleWrite("$FN_Flags: " & $FN_Flags & @CRLF)
$FN_NameLength = StringMid($MFTEntry,$FN_Offset+176,2)
$FN_NameLength = Dec($FN_NameLength)
$FN_NameType = StringMid($MFTEntry,$FN_Offset+178,2)
Select
Case $FN_NameType = '00'
$FN_NameType = 'POSIX'
Case $FN_NameType = '01'
$FN_NameType = 'WIN32'
Case $FN_NameType = '02'
$FN_NameType = 'DOS'
Case $FN_NameType = '03'
$FN_NameType = 'DOS+WIN32'
Case $FN_NameType <> '00' AND $FN_NameType <> '01' AND $FN_NameType <> '02' AND $FN_NameType <> '03'
$FN_NameType = 'UNKNOWN'
EndSelect
$FN_NameSpace = $FN_NameLength-1
$FN_FileName = StringMid($MFTEntry,$FN_Offset+180,($FN_NameLength+$FN_NameSpace)*2)
$FN_FileName = _UnicodeHexToStr($FN_FileName)
;If StringLen($FN_FileName) <> $FN_NameLength Then $INVALID_FILENAME = 1
If Not $IsFirstRun Then
$FNArrValue[0][$FN_Number] = "FN Number " & $FN_Number
$FNArrValue[1][$FN_Number] = $FN_ParentReferenceNo
$FNArrValue[2][$FN_Number] = $FN_ParentSequenceNo
$FNArrValue[3][$FN_Number] = $FN_CTime
$FNArrValue[4][$FN_Number] = $FN_ATime
$FNArrValue[5][$FN_Number] = $FN_MTime
$FNArrValue[6][$FN_Number] = $FN_RTime
$FNArrValue[7][$FN_Number] = $FN_AllocSize
$FNArrValue[8][$FN_Number] = $FN_RealSize
$FNArrValue[9][$FN_Number] = $FN_Flags
$FNArrValue[10][$FN_Number] = $FN_NameLength
$FNArrValue[11][$FN_Number] = $FN_NameType
$FNArrValue[12][$FN_Number] = $FN_NameSpace
$FNArrValue[13][$FN_Number] = $FN_FileName
; _ArrayDisplay($FNArrValue,"$FNArrValue")
$FNArrOffset[0][$FN_Number] = "Internal offset"
$FNArrOffset[1][$FN_Number] = $FN_Offset+48
$FNArrOffset[2][$FN_Number] = $FN_Offset+60
$FNArrOffset[3][$FN_Number] = $FN_Offset+64
$FNArrOffset[4][$FN_Number] = $FN_Offset+80
$FNArrOffset[5][$FN_Number] = $FN_Offset+96
$FNArrOffset[6][$FN_Number] = $FN_Offset+112
$FNArrOffset[7][$FN_Number] = $FN_Offset+128
$FNArrOffset[8][$FN_Number] = $FN_Offset+144
$FNArrOffset[9][$FN_Number] = $FN_Offset+160
$FNArrOffset[10][$FN_Number] = $FN_Offset+176
$FNArrOffset[11][$FN_Number] = $FN_Offset+178
$FNArrOffset[12][$FN_Number] = ""
$FNArrOffset[13][$FN_Number] = $FN_Offset+180
EndIf
EndFunc
Func _DecodeAttrList($TargetFile, $AttrList)
Local $offset, $nBytes, $hFile, $LocalName, $ALNameLength
If StringMid($AttrList, 17, 2) = "00" Then ;attribute list is in $AttrList
$offset = Dec(_SwapEndian(StringMid($AttrList, 41, 4)))
$List = StringMid($AttrList, $offset*2+1)
; $IsolatedAttributeList = $list
Else ;attribute list is found from data run in $AttrList
$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)
; ConsoleWrite("Attribute_List DataRun is " & $DataRun & @CRLF)
Global $RUN_VCN[1], $RUN_Clusters[1]
_ExtractDataRuns()
$tBuffer = DllStructCreate("byte[" & $BytesPerCluster & "]")
$hFile = _WinAPI_CreateFile($TargetDrive, 2, 6, 6)
If $hFile = 0 Then
ConsoleWrite("Error in function CreateFile when trying to locate Attribute List." & @CRLF)
_WinAPI_CloseHandle($hFile)
Return SetError(1,0,0)
EndIf
$List = ""
For $r = 1 To Ubound($RUN_VCN)-1
_WinAPI_SetFilePointerEx($hFile, $ImageOffset+($RUN_VCN[$r]*$BytesPerCluster), $FILE_BEGIN)
For $i = 1 To $RUN_Clusters[$r]
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $BytesPerCluster, $nBytes)
$List &= StringTrimLeft(DllStructGetData($tBuffer, 1),2)
Next
Next
; _DebugOut("***AttrList New:",$List)
_WinAPI_CloseHandle($hFile)
$List = StringMid($List, 1, $size*2)
EndIf
;$IsolatedAttributeList = $list
$offset=0
$str=""
While StringLen($list) > $offset*2
$type=StringMid($List, ($offset*2)+1, 8)
;$ALRecordLength = Dec(_SwapEndian(StringMid($List, $offset*2 + 9, 4)))
$ALNameLength = Dec(_SwapEndian(StringMid($List, $offset*2 + 13, 2)))
;$ALNameOffset = Dec(_SwapEndian(StringMid($List, $offset*2 + 15, 2)))
;$TestVCN = Dec(_SwapEndian(StringMid($List, $offset*2 + 17, 16)))
$ref=Dec(_SwapEndian(StringMid($List, $offset*2 + 33, 8)))
;$LocalAttribID = "0x" & StringMid($List, $offset*2 + 49, 2) & StringMid($List, $offset*2 + 51, 2)
If $ALNameLength > 0 Then
$LocalName = StringMid($List, $offset*2 + 53, $ALNameLength*2*2)
$LocalName = _UnicodeHexToStr($LocalName)
Else
$LocalName = ""
EndIf
If $ref <> $TargetFile Then ;new attribute
If Not StringInStr($str, $ref) Then $str &= $ref & "-"
EndIf
If $type=$DATA Then
;$DataInAttrlist=1
;$IsolatedData=StringMid($List, ($offset*2)+1, $ALRecordLength*2)
;If $TestVCN=0 Then $DataIsResident=1
EndIf
$offset += Dec(_SwapEndian(StringMid($List, $offset*2 + 9, 4)))
WEnd
If $str = "" Then
ConsoleWrite("No extra MFT records found" & @CRLF)
Else
$AttrQ = StringSplit(StringTrimRight($str,1), "-")
; ConsoleWrite("Decode of $ATTRIBUTE_LIST reveiled extra MFT Records to be examined = " & _ArrayToString($AttrQ, @CRLF) & @CRLF)
EndIf
EndFunc
Func _FindFileMFTRecord($TargetDevice,$TargetFile)
Local $nBytes, $TmpOffset, $Counter, $Counter2, $RecordJumper, $TargetFileDec, $RecordsTooMuch, $RetVal[2], $Final, $i=0
$tBuffer = DllStructCreate("byte[" & $MFT_Record_Size & "]")
$hFile = _WinAPI_CreateFile($TargetDevice, 2, 6, 6)
If $hFile = 0 Then
ConsoleWrite("Error CreateFile in function _FindFileMFTRecord(): " & _WinAPI_GetLastErrorMessage() & " for " & $TargetDevice & @CRLF)
_WinAPI_CloseHandle($hFile)
Return SetError(1,0,0)
EndIf
$TargetFile = _DecToLittleEndian($TargetFile)
$TargetFileDec = Dec(_SwapEndian($TargetFile),2)
; ConsoleWrite("$TargetFileDec: " & $TargetFileDec & @CRLF)
; ConsoleWrite("$SectorsPerCluster: " & $SectorsPerCluster & @CRLF)
; ConsoleWrite("UBound($MFT_RUN_Clusters): " & UBound($MFT_RUN_Clusters) & @CRLF)
Local $RecordsDivisor = $MFT_Record_Size/512
; ConsoleWrite("$RecordsDivisor: " & $RecordsDivisor & @CRLF)
For $i = 1 To UBound($MFT_RUN_Clusters)-1
$CurrentClusters = $MFT_RUN_Clusters[$i]
$RecordsInCurrentRun = ($CurrentClusters*$SectorsPerCluster)/$RecordsDivisor
; ConsoleWrite("$CurrentClusters: " & $CurrentClusters & @CRLF)
; ConsoleWrite("$RecordsInCurrentRun: " & $RecordsInCurrentRun & @CRLF)
$Counter+=$RecordsInCurrentRun
; ConsoleWrite("$Counter: " & $Counter & @CRLF)
If $Counter>$TargetFileDec Then
ExitLoop
EndIf
Next
; ConsoleWrite("$i: " & $i & @CRLF)
$TryAt = $Counter-$RecordsInCurrentRun
; ConsoleWrite("$TryAt: " & $TryAt & @CRLF)
;$TryAtArrIndex = $i
$RecordsPerCluster = $SectorsPerCluster/$RecordsDivisor
Do
$RecordJumper+=$RecordsPerCluster
$Counter2+=1
$Final = $TryAt+$RecordJumper
Until $Final>=$TargetFileDec
$RecordsTooMuch = $Final-$TargetFileDec
; ConsoleWrite("$RecordsTooMuch: " & $RecordsTooMuch & @CRLF)
_WinAPI_SetFilePointerEx($hFile, $ImageOffset+($MFT_RUN_VCN[$i]*$BytesPerCluster)+($Counter2*$BytesPerCluster)-($RecordsTooMuch*$MFT_Record_Size), $FILE_BEGIN)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $MFT_Record_Size, $nBytes)
$record = DllStructGetData($tBuffer, 1)
; ConsoleWrite("Record:" & @CRLF)
; ConsoleWrite(_HexEncode($record) & @CRLF)
If StringMid($record,91,8) = $TargetFile Then
$TmpOffset = DllCall('kernel32.dll', 'int', 'SetFilePointerEx', 'ptr', $hFile, 'int64', 0, 'int64*', 0, 'dword', 1)
$FoundOffset = Int($TmpOffset[3])-Int($MFT_Record_Size)
; ConsoleWrite("Record number: " & Dec(_SwapEndian($TargetFile),2) & " found at volume offset: 0x" & Hex($FoundOffset) & @CRLF)
_WinAPI_CloseHandle($hFile)
$RetVal[0] = $FoundOffset
$RetVal[1] = $record
Return $RetVal
Else
_WinAPI_CloseHandle($hFile)
Return ""
EndIf
EndFunc
Func _StripMftRecord($MFTEntry)
Local $UpdSeqArrPart0, $UpdSeqArrPart1, $UpdSeqArrPart2, $RecordEnd1, $RecordEnd2
$UpdSeqArrOffset = Dec(_SwapEndian(StringMid($MFTEntry,11,4)))
$UpdSeqArrSize = Dec(_SwapEndian(StringMid($MFTEntry,15,4)))
$UpdSeqArr = StringMid($MFTEntry,3+($UpdSeqArrOffset*2),$UpdSeqArrSize*2*2)
If $MFT_Record_Size = 1024 Then
$UpdSeqArrPart0 = StringMid($UpdSeqArr,1,4)
$UpdSeqArrPart1 = StringMid($UpdSeqArr,5,4)
$UpdSeqArrPart2 = StringMid($UpdSeqArr,9,4)
$RecordEnd1 = StringMid($MFTEntry,1023,4)
$RecordEnd2 = StringMid($MFTEntry,2047,4)
If $UpdSeqArrPart0 <> $RecordEnd1 OR $UpdSeqArrPart0 <> $RecordEnd2 Then
; _DebugOut("The record failed Fixup", $MFTEntry)
ConsoleWrite("The record failed Fixup:" & @CRLF)
ConsoleWrite(_HexEncode($MFTEntry) & @CRLF)
Return ""
EndIf
$MFTEntry = StringMid($MFTEntry,1,1022) & $UpdSeqArrPart1 & StringMid($MFTEntry,1027,1020) & $UpdSeqArrPart2
ElseIf $MFT_Record_Size = 4096 Then
$UpdSeqArrPart0 = StringMid($UpdSeqArr,1,4)
$UpdSeqArrPart1 = StringMid($UpdSeqArr,5,4)
$UpdSeqArrPart2 = StringMid($UpdSeqArr,9,4)
Local $UpdSeqArrPart3 = StringMid($UpdSeqArr,13,4)
Local $UpdSeqArrPart4 = StringMid($UpdSeqArr,17,4)
Local $UpdSeqArrPart5 = StringMid($UpdSeqArr,21,4)
Local $UpdSeqArrPart6 = StringMid($UpdSeqArr,25,4)
Local $UpdSeqArrPart7 = StringMid($UpdSeqArr,29,4)
Local $UpdSeqArrPart8 = StringMid($UpdSeqArr,33,4)
$RecordEnd1 = StringMid($MFTEntry,1023,4)
$RecordEnd2 = StringMid($MFTEntry,2047,4)
Local $RecordEnd3 = StringMid($MFTEntry,3071,4)
Local $RecordEnd4 = StringMid($MFTEntry,4095,4)
Local $RecordEnd5 = StringMid($MFTEntry,5119,4)
Local $RecordEnd6 = StringMid($MFTEntry,6143,4)
Local $RecordEnd7 = StringMid($MFTEntry,7167,4)
Local $RecordEnd8 = StringMid($MFTEntry,8191,4)
If $UpdSeqArrPart0 <> $RecordEnd1 OR $UpdSeqArrPart0 <> $RecordEnd2 OR $UpdSeqArrPart0 <> $RecordEnd3 OR $UpdSeqArrPart0 <> $RecordEnd4 OR $UpdSeqArrPart0 <> $RecordEnd5 OR $UpdSeqArrPart0 <> $RecordEnd6 OR $UpdSeqArrPart0 <> $RecordEnd7 OR $UpdSeqArrPart0 <> $RecordEnd8 Then
; _DebugOut("The record failed Fixup", $MFTEntry)
ConsoleWrite("The record failed Fixup:" & @CRLF)
ConsoleWrite(_HexEncode($MFTEntry) & @CRLF)
Return ""
Else
$MFTEntry = StringMid($MFTEntry,1,1022) & $UpdSeqArrPart1 & StringMid($MFTEntry,1027,1020) & $UpdSeqArrPart2 & StringMid($MFTEntry,2051,1020) & $UpdSeqArrPart3 & StringMid($MFTEntry,3075,1020) & $UpdSeqArrPart4 & StringMid($MFTEntry,4099,1020) & $UpdSeqArrPart5 & StringMid($MFTEntry,5123,1020) & $UpdSeqArrPart6 & StringMid($MFTEntry,6147,1020) & $UpdSeqArrPart7 & StringMid($MFTEntry,7171,1020) & $UpdSeqArrPart8
EndIf
EndIf
$RecordSize = Dec(_SwapEndian(StringMid($MFTEntry,51,8)),2)
$HeaderSize = Dec(_SwapEndian(StringMid($MFTEntry,43,4)),2)
$MFTEntry = StringMid($MFTEntry,$HeaderSize*2+3,($RecordSize-$HeaderSize-8)*2) ;strip "0x..." and "FFFFFFFF..."
Return $MFTEntry
EndFunc
Func _GetAttributeEntry($TargetDevice,$Entry)
Local $CoreAttribute,$CoreAttributeTmp,$CoreAttributeArr[2],$TestArray,$Bytes
Local $ATTRIBUTE_HEADER_Length,$ATTRIBUTE_HEADER_NonResidentFlag,$ATTRIBUTE_HEADER_NameLength,$ATTRIBUTE_HEADER_NameRelativeOffset,$ATTRIBUTE_HEADER_Name,$ATTRIBUTE_HEADER_Flags,$ATTRIBUTE_HEADER_AttributeID,$ATTRIBUTE_HEADER_StartVCN,$ATTRIBUTE_HEADER_LastVCN
Local $ATTRIBUTE_HEADER_OffsetToDataRuns,$ATTRIBUTE_HEADER_CompressionUnitSize,$ATTRIBUTE_HEADER_Padding,$ATTRIBUTE_HEADER_AllocatedSize,$ATTRIBUTE_HEADER_RealSize,$ATTRIBUTE_HEADER_InitializedStreamSize,$RunListOffset
Local $ATTRIBUTE_HEADER_LengthOfAttribute,$ATTRIBUTE_HEADER_OffsetToAttribute
If $IsCurrentIndxOfParent Then Global $RawOffsetIndxArray
$ATTRIBUTE_HEADER_Length = StringMid($Entry,9,8)
$ATTRIBUTE_HEADER_Length = Dec(StringMid($ATTRIBUTE_HEADER_Length,7,2) & StringMid($ATTRIBUTE_HEADER_Length,5,2) & StringMid($ATTRIBUTE_HEADER_Length,3,2) & StringMid($ATTRIBUTE_HEADER_Length,1,2))
$ATTRIBUTE_HEADER_NonResidentFlag = StringMid($Entry,17,2)
; ConsoleWrite("$ATTRIBUTE_HEADER_NonResidentFlag = " & $ATTRIBUTE_HEADER_NonResidentFlag & @crlf)
$ATTRIBUTE_HEADER_NameLength = Dec(StringMid($Entry,19,2))
; ConsoleWrite("$ATTRIBUTE_HEADER_NameLength = " & $ATTRIBUTE_HEADER_NameLength & @crlf)
$ATTRIBUTE_HEADER_NameRelativeOffset = StringMid($Entry,21,4)
; ConsoleWrite("$ATTRIBUTE_HEADER_NameRelativeOffset = " & $ATTRIBUTE_HEADER_NameRelativeOffset & @crlf)
$ATTRIBUTE_HEADER_NameRelativeOffset = Dec(_SwapEndian($ATTRIBUTE_HEADER_NameRelativeOffset))
; ConsoleWrite("$ATTRIBUTE_HEADER_NameRelativeOffset = " & $ATTRIBUTE_HEADER_NameRelativeOffset & @crlf)
If $ATTRIBUTE_HEADER_NameLength > 0 Then
$ATTRIBUTE_HEADER_Name = _UnicodeHexToStr(StringMid($Entry,$ATTRIBUTE_HEADER_NameRelativeOffset*2 + 1,$ATTRIBUTE_HEADER_NameLength*4))
Else
$ATTRIBUTE_HEADER_Name = ""
EndIf
$ATTRIBUTE_HEADER_Flags = _SwapEndian(StringMid($Entry,25,4))
; ConsoleWrite("$ATTRIBUTE_HEADER_Flags = " & $ATTRIBUTE_HEADER_Flags & @crlf)
$Flags = ""
If $ATTRIBUTE_HEADER_Flags = "0000" Then
$Flags = "NORMAL"
Else
If BitAND($ATTRIBUTE_HEADER_Flags,"0001") Then
$IsCompressed = 1
$Flags &= "COMPRESSED+"
EndIf
If BitAND($ATTRIBUTE_HEADER_Flags,"4000") Then
;$IsEncrypted = 1
$Flags &= "ENCRYPTED+"