-
Notifications
You must be signed in to change notification settings - Fork 7
/
SetMace.au3
6453 lines (6192 loc) · 322 KB
/
SetMace.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_Change2CUI=y
#AutoIt3Wrapper_Res_Comment=Advanced timestamp manipulation on NTFS
#AutoIt3Wrapper_Res_Description=Change or dump any file timestamp by using low level disk access
#AutoIt3Wrapper_Res_Fileversion=1.0.0.16
#AutoIt3Wrapper_Res_LegalCopyright=Joakim Schicht
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_File_Add=C:\tmp\sectorio.sys
#AutoIt3Wrapper_Res_File_Add=C:\tmp\sectorio64.sys
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <WinAPIEx.au3>
#include <Array.au3>
#Include <String.au3>
#Include <FileConstants.au3>
#Include <APIConstants.au3>
;
; https://github.com/jschicht
; http://code.google.com/p/mft2csv/
;
Global $DoSi=0 ; -x, -si
Global $DoFn=0 ; -x, -fn
Global $DoCTime=0 ; -z, -c
Global $DoATime=0 ; -z, -m
Global $DoMTime=0 ; -z, -e
Global $DoRTime=0 ; -z, -a
Global $DoAll4Timestamps=0 ; -z
Global $DoRead=0 ; -d
Global $DoShadows=0 ; -shadow
Global $NeedLock=0, $drive, $FormattedTimestamp1, $SIArrValue[13][1], $SIArrOffset[13][1], $SIArrSize[13][1], $FNArrValue[14][1], $FNArrOffset[14][1], $IsFirstRun=1, $SI_Number, $FN_Number
Global $LockedFileName,$DirArray,$NeedIndx=0, $ResidentIndx, $AttributesArr[18][4], $DoExtractMeta=False, $TargetFileName, $DATA_Name, $FN_FileName, $NameQ[5], $FN_ParentReferenceNo, $HEADER_MFTREcordNumber
Global $TargetImageFile, $Entries, $InputFile, $IsRawShadowCopy=0, $IsPhysicalDrive=False, $IsImage=False, $hDisk, $sBuffer, $ComboPhysicalDrives, $Combo, $Mode2Data, $SkipFixups=0, $LogicalClusterNumberforthefileMFT, $ClustersPerFileRecordSegment, $MftAttrListString
Global $OutPutPath=@ScriptDir, $InitState = False, $DATA_Clusters, $AttributeOutFileName, $DATA_InitSize, $ImageOffset=0, $ADS_Name, $IndexNumber, $NonResidentFlag, $DATA_RealSize, $DataRun, $DATA_LengthOfAttribute
Global $TargetDrive = "", $ALInnerCouner, $MFTSize, $TargetOffset, $SectorsPerCluster,$MFT_Record_Size,$BytesPerCluster,$BytesPerSector,$MFT_Offset,$IsDirectory, $SplitMftRecArr[1]
Global $IsolatedAttributeList, $AttribListNonResident=0,$IsCompressed,$IsSparse, $_COMMON_KERNEL32DLL=DllOpen("kernel32.dll"),$Drivername = "sectorio", $RawTestOffsetArray, $ParentMode=0, $IndxCTimeFromParentArr[1],$IndxATimeFromParentArr[1],$IndxMTimeFromParentArr[1],$IndxRTimeFromParentArr[1],$IndxFileNameFromParentArr[1],$IndxMFTReferenceFromParentArr[1],$IndxMFTReferenceOfParentFromParentArr[1]
Global $RUN_VCN[1],$RUN_Clusters[1],$MFT_RUN_Clusters[1],$MFT_RUN_VCN[1],$DataQ[1],$sBuffer,$AttrQ[1],$IndxCTimeFromParentCurrentArr,$IndxATimeFromParentCurrentArr,$IndxMTimeFromParentCurrentArr,$IndxRTimeFromParentCurrentArr,$IndxFileNameFromParentCurrentArr,$IndxMFTReferenceFromParentCurrentArr,$IndxMFTReferenceOfParentFromParentCurrentArr
Global $IndxEntryNumberArr[1],$IndxMFTReferenceArr[1],$IndxMFTRefSeqNoArr[1],$IndxMFTReferenceOfParentArr[1],$IndxMFTParentRefSeqNoArr[1],$IndxCTimeArr[1],$IndxATimeArr[1],$IndxMTimeArr[1],$IndxRTimeArr[1],$IndxFileNameArr[1]
;Global $IndxEntryNumberArr[1],$IndxMFTReferenceArr[1],$IndxMFTRefSeqNoArr[1],$IndxIndexFlagsArr[1],$IndxMFTReferenceOfParentArr[1],$IndxMFTParentRefSeqNoArr[1],$IndxCTimeArr[1],$IndxATimeArr[1],$IndxMTimeArr[1],$IndxRTimeArr[1],$IndxAllocSizeArr[1],$IndxRealSizeArr[1],$IndxFileFlagsArr[1],$IndxFileNameArr[1],$IndxSubNodeVCNArr[1],$IndxNameSpaceArr[1]
Global $IndxEntryNumberArr2[1],$IndxMFTReferenceArr2[1],$IndxFileNameArr2[1],$ShadowModifyMftArr[1],$ShadowModifyIndxArr[1],$ShadowModifyParentMftArr[1],$RawOffsetIndxArray[1]
Global $IRArr[12][2],$IndxArr[20][2],$InfoArrShadowMainTarget[3],$InfoArrShadowParent[3],$NewTimestampShifted,$IRTimestampsArray[1][4],$DummyVar=0,$IsCurrentIndxOfParent=0,$DoIndxOffsetArray=0
Global $ShadowPath = "System Volume Information\", $ShadowGuid = "{3808876b-c176-4e48-b7ae-04046e6cc752}", $GlobalShadowArray[1][8], $GlobalShadowFileCounter=0, $ShadowPathResolved, $FromHarddiskVolumeShadowCopyXArr[15][1],$INDX_Record_Size=4096
Global $DateTimeFormat = 6 ; YYYY-MM-DD HH:MM:SS:MSMSMS:NSNSNSNS = 2007-08-18 08:15:37:733:1234
Global $tDelta = _WinTime_GetUTCToLocalFileTimeDelta()
Global Const $RecordSignature = '46494C45' ; FILE signature
Global Const $RecordSignatureBad = '44414142' ; BAAD signature
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 Const $tagUNICODESTRING = "ushort Length;ushort MaximumLength;ptr Buffer"
Global $Timerstart = TimerInit()
ConsoleWrite("Starting SetMace by Joakim Schicht" & @CRLF)
ConsoleWrite("Version 1.0.0.16" & @CRLF & @CRLF)
If Not $cmdline[0] Then
ConsoleWrite("Error: Missing parameters" & @CRLF)
_PrintHelp()
Exit
EndIf
$TargetDrive = StringMid($cmdline[1],1,2)
$IndexNumber = StringMid($cmdline[1],3)
If Not StringIsDigit($IndexNumber) Then $TargetFileName = $cmdline[1]
_validate_parameters()
If Not $DoRead Then
$FormattedTimestamp = _config_timestamp()
$FormattedTimestamp1 = StringMid($FormattedTimestamp[0],1,14) & $FormattedTimestamp[8]
EndIf
;ConsoleWrite("$TargetDrive: " & $TargetDrive & @CRLF)
_ReadBootSector($TargetDrive)
If @error Then
ConsoleWrite("Error: Filesystem not NTFS" & @CRLF)
Exit
EndIf
$hDisk = _WinAPI_CreateFile("\\.\" & $TargetDrive,2,2,7)
If $hDisk = 0 Then
ConsoleWrite("CreateFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Exit
EndIf
$MFTEntry = _FindMFT($TargetDrive,0)
If $MFTEntry = "" Then ;something wrong with record for $MFT
ConsoleWrite("Error: Getting MFT record 0" & @CRLF)
Exit
EndIf
$MFT = _DecodeMFTRecord0($MFTEntry, 0) ;produces DataQ for $MFT, record 0
If $MFT = "" Then
ConsoleWrite("Error: Parsing the MFT record 0" & @CRLF)
Exit
EndIf
_GetRunsFromAttributeListMFT0() ;produces datarun for $MFT and converts datarun to RUN_VCN[] and RUN_Clusters[]
_WinAPI_CloseHandle($hDisk)
$MFTSize = $DATA_RealSize
$MFT_RUN_VCN = $RUN_VCN
$MFT_RUN_Clusters = $RUN_Clusters
$IsFirstRun=0
_GenRefArray()
If Not _Prep($TargetDrive,$IndexNumber,$TargetFileName) Then
ConsoleWrite("Error initializing structs and arrays" & @crlf)
Exit
EndIf
If $DoRead Then
ConsoleWrite("Start reading timestamps from disk" & @crlf)
_DumpTimestampsToConsole()
ConsoleWrite("Finished reading timestamps from disk" & @crlf & @crlf)
EndIf
$hDisk = _WinAPI_CreateFile("\\.\" & $TargetDrive,2,2,7)
If Not $hDisk Then
ConsoleWrite("Error CreateFile in core script returned: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Exit
EndIf
If $DoShadows And $DoRead Then
;Get some volume information to compare against with shadows
$VolumeInfoTarget = _WinAPI_GetVolumeInformationByHandle($hDisk)
;Start VSS info gathering by vssadmin+++
$sVolumeMountPoint = StringUpper($TargetDrive) & "\"
;ConsoleWrite("$sVolumeMountPoint: " & $sVolumeMountPoint & @CRLF)
$Ret = DllCall('kernel32.dll', 'int', 'GetVolumeNameForVolumeMountPointW', 'wstr', $sVolumeMountPoint, 'wstr', '', 'dword', 256)
If Not $Ret[0] Then
ConsoleWrite("Error in GetVolumeNameForVolumeMountPoint: " & _WinAPI_GetLastErrorMessage() & @CRLF)
EndIf
;ConsoleWrite("GetVolumeNameForVolumeMountPoint: " & $Ret[2] & @CRLF)
$VolumeGUIDPath = $Ret[2]
$vssPID = run("cmd /c vssadmin list shadows /for="&$TargetDrive,"",@SW_HIDE, 0x2)
ProcessWaitClose($vssPID)
$sOutput = StdoutRead($vssPID)
;ConsoleWrite($sOutput & @CRLF)
$VssArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@CRLF)), @CRLF)
;_ArrayDisplay($VssArray)
Global $ShadowsArray[UBound($VssArray)/3][7]
$ShadowsArray[0][0] = "ShadowCopySetId"
$ShadowsArray[0][1] = "Creation Time"
$ShadowsArray[0][2] = "ShadowCopyId"
$ShadowsArray[0][3] = "ShadowOriginalVolume"
$ShadowsArray[0][4] = "ShadowCopyVolume"
$ShadowsArray[0][5] = "Originating Machine"
$ShadowsArray[0][6] = "Servicing Machine"
$tCounter=0
;Note: the parsing of vssadmin output is language dependent, however that limitation does not make any difference as the result is not currently used when parsing
For $VssLine = 1 To UBound($VssArray)-1
If StringInStr($VssArray[$VssLine],"Contents of shadow copy set ID: {") Then
$ShadowCopySetId = $VssArray[$VssLine]
$ShadowCopySetId = StringMid($ShadowCopySetId,StringInStr($ShadowCopySetId,":")+2)
If StringRight($ShadowCopySetId,1) <> "}" Or StringLeft($ShadowCopySetId,1) <> "{" Then ConsoleWrite("Error: Something went wrong with parsing the output of vssadmin.exe" & @CRLF)
$ShadowCreationTime = $VssArray[$VssLine+1]
$ShadowCreationTime = StringMid($ShadowCreationTime,StringInStr($ShadowCreationTime,":")+2)
EndIf
If StringInStr($VssArray[$VssLine],"Shadow Copy ID: {") Then
$ShadowCopyId = $VssArray[$VssLine]
$ShadowCopyId = StringMid($ShadowCopyId,StringInStr($ShadowCopyId,":")+2)
If StringRight($ShadowCopyId,1) <> "}" Or StringLeft($ShadowCopyId,1) <> "{" Then ConsoleWrite("Error: Something went wrong with parsing the output of vssadmin.exe" & @CRLF)
$ShadowOriginalVolume = $VssArray[$VssLine+1]
$ShadowOriginalVolume = StringMid($ShadowOriginalVolume,StringInStr($ShadowOriginalVolume,"("))
$ShadowCopyVolume = $VssArray[$VssLine+2]
$ShadowCopyVolume = StringMid($ShadowCopyVolume,StringInStr($ShadowCopyVolume,"\\"))
$ShadowOriginatingMachine = $VssArray[$VssLine+3]
$ShadowOriginatingMachine = StringMid($ShadowOriginatingMachine,StringInStr($ShadowOriginatingMachine,":")+2)
$ShadowServicingMachine = $VssArray[$VssLine+4]
$ShadowServicingMachine = StringMid($ShadowServicingMachine,StringInStr($ShadowServicingMachine,":")+2)
If StringInStr($ShadowOriginalVolume,$VolumeGUIDPath) Then
$tCounter+=1
#cs
ConsoleWrite(@CRLF & "Shadow copy matches:" & @CRLF)
ConsoleWrite("$ShadowCopySetId: " & $ShadowCopySetId & @CRLF)
ConsoleWrite("$ShadowCreationTime: " & $ShadowCreationTime & @CRLF)
ConsoleWrite("$ShadowCopyId: " & $ShadowCopyId & @CRLF)
ConsoleWrite("$ShadowOriginalVolume: " & $ShadowOriginalVolume & @CRLF)
ConsoleWrite("$ShadowCopyVolume: " & $ShadowCopyVolume & @CRLF)
ConsoleWrite("$ShadowOriginatingMachine: " & $ShadowOriginatingMachine & @CRLF)
ConsoleWrite("$ShadowServicingMachine: " & $ShadowServicingMachine & @CRLF)
#ce
$ShadowsArray[$tCounter][0] = $ShadowCopySetId
$ShadowsArray[$tCounter][1] = $ShadowCreationTime
$ShadowsArray[$tCounter][2] = $ShadowCopyId
$ShadowsArray[$tCounter][3] = $ShadowOriginalVolume
$ShadowsArray[$tCounter][4] = $ShadowCopyVolume
$ShadowsArray[$tCounter][5] = $ShadowOriginatingMachine
$ShadowsArray[$tCounter][6] = $ShadowServicingMachine
EndIf
EndIf
Next
ReDim $ShadowsArray[$tCounter+1][7]
;_ArrayDisplay($ShadowsArray)
$IndexNumberBak = $IndexNumber
$TargetMatchInShadowsCounter=1
;With dump mode, search through each and every ShadowCopy for a match
If $DoRead Then
$DummyVar=1
ConsoleWrite("Start reading timestamps from symbolic links of shadow copies" & @crlf & @crlf)
$FromHarddiskVolumeShadowCopyXArr[0][0] = "VolumeShadowCopy"
$FromHarddiskVolumeShadowCopyXArr[1][0] = "FileName"
$FromHarddiskVolumeShadowCopyXArr[2][0] = "IndexNumber"
$FromHarddiskVolumeShadowCopyXArr[3][0] = "SI: CreationTime"
$FromHarddiskVolumeShadowCopyXArr[4][0] = "SI: LastWriteTime"
$FromHarddiskVolumeShadowCopyXArr[5][0] = "SI: ChangeTime(MFT)"
$FromHarddiskVolumeShadowCopyXArr[6][0] = "SI: LastAccessTime"
$FromHarddiskVolumeShadowCopyXArr[7][0] = "FN: CreationTime"
$FromHarddiskVolumeShadowCopyXArr[8][0] = "FN: LastWriteTime"
$FromHarddiskVolumeShadowCopyXArr[9][0] = "FN: ChangeTime(MFT)"
$FromHarddiskVolumeShadowCopyXArr[10][0] = "FN: LastAccessTime"
$FromHarddiskVolumeShadowCopyXArr[11][0] = "INDX: CreationTime"
$FromHarddiskVolumeShadowCopyXArr[12][0] = "INDX: LastWriteTime"
$FromHarddiskVolumeShadowCopyXArr[13][0] = "INDX: ChangeTime(MFT)"
$FromHarddiskVolumeShadowCopyXArr[14][0] = "INDX: LastAccessTime"
$k=1 ;We traverse from 1 to 50 although we strictly speaking could have grabbed the relevant shadows from $ShadowsArray and saved a couple of sec.
$sDrivePath = '\\.\GLOBALROOT\Device\HarddiskVolumeShadowCopy'
Do
$hDisk = _WinAPI_CreateFile($sDrivePath & $k,2,2,2)
If $hDisk <> 0 Then
$HarddiskVolumeShadowCopyX = StringMid($sDrivePath,5)&$k
$VolumeInfoShadow = _WinAPI_GetVolumeInformationByHandle($hDisk)
_WinAPI_CloseHandle($hDisk)
If $VolumeInfoTarget[0] = $VolumeInfoShadow[0] And $VolumeInfoTarget[1] = $VolumeInfoShadow[1] Then ;Likely a shadow of target volume
; 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]
ConsoleWrite("Found shadow: " & $sDrivePath & $k & @CRLF)
_ReadBootSector($HarddiskVolumeShadowCopyX)
If @error Then
ConsoleWrite("Error: Filesystem not NTFS" & @CRLF)
$k+=1
Continueloop
EndIf
$BytesPerCluster = $SectorsPerCluster*$BytesPerSector
$MFTEntry = _FindMFT($HarddiskVolumeShadowCopyX,0)
$IndexNumber = $IndexNumberBak
If _DecodeMFTRecord($HarddiskVolumeShadowCopyX,$MFTEntry,0) < 1 Then
ConsoleWrite("Could not verify MFT record of MFT itself (volume corrupt)" & @CRLF)
$k+=1
Continueloop
EndIf
_DecodeDataQEntry($DataQ[1])
$MFTSize = $DATA_RealSize
Global $RUN_VCN[1], $RUN_Clusters[1]
_ExtractDataRuns()
$MFT_RUN_VCN = $RUN_VCN
$MFT_RUN_Clusters = $RUN_Clusters
;Parent of target
$RetRec = _FindFileMFTRecord($HarddiskVolumeShadowCopyX,$InfoArrShadowParent[0])
$NewRecord = $RetRec[1]
If _DecodeMFTRecord($HarddiskVolumeShadowCopyX,$NewRecord,1) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $RetRec[0] & @CRLF)
$k+=1
Continueloop
EndIf
If $InfoArrShadowParent[0] = $HEADER_MFTREcordNumber And $InfoArrShadowParent[1] = $FN_FileName Then
; ConsoleWrite("Found parent of target with ref " & $HEADER_MFTREcordNumber & " and name " & $FN_FileName & " at offset: 0x" & Hex($RetRec[0])& @CRLF)
Else
ConsoleWrite("Error: target file not found by parent object comparison in " & $HarddiskVolumeShadowCopyX & @CRLF) ;Validation check 1
$k+=1
ContinueLoop
EndIf
If Not _PopulateIndxTimestamps($InfoArrShadowMainTarget[1],$InfoArrShadowMainTarget[0]) Then
ConsoleWrite("Error: target file not found by INDX method in " & $HarddiskVolumeShadowCopyX & @CRLF) ;Validation check 2
$k+=1
ContinueLoop
EndIf
Redim $FromHarddiskVolumeShadowCopyXArr[15][$TargetMatchInShadowsCounter+1]
;Target
$RetRec = _FindFileMFTRecord($HarddiskVolumeShadowCopyX,$InfoArrShadowMainTarget[0])
$NewRecord = $RetRec[1]
If _DecodeMFTRecord($HarddiskVolumeShadowCopyX,$NewRecord,1) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $RetRec[0] & @CRLF)
$k+=1
Continueloop
EndIf
If $InfoArrShadowMainTarget[0] = $HEADER_MFTREcordNumber And $InfoArrShadowMainTarget[1] = $FN_FileName And $InfoArrShadowParent[0] = $FN_ParentReferenceNo Then
; ConsoleWrite("Found main target with ref " & $HEADER_MFTREcordNumber & " and name " & $FN_FileName & " at offset: 0x" & Hex($RetRec[0])& @CRLF)
Else
ConsoleWrite("Error: target file not found by direct $MFT method in " & $HarddiskVolumeShadowCopyX & @CRLF) ;Validation check 3
$k+=1
ContinueLoop
EndIf
_DumpTimestampsToConsole()
_PopulateShadowTimestampsArray($TargetMatchInShadowsCounter)
$FromHarddiskVolumeShadowCopyXArr[0][$TargetMatchInShadowsCounter] = $HarddiskVolumeShadowCopyX
$TargetMatchInShadowsCounter+=1
Else
; ConsoleWrite("Shadow of other volume: " & $sDrivePath & $k & @CRLF)
EndIf
$VolumeInfoShadow=''
EndIf
$k+=1
Until $k = 50
If $TargetMatchInShadowsCounter = 1 Then ConsoleWrite("No shadow copies for volume " & $TargetDrive & " contained target file" & @CRLF)
ConsoleWrite("Finished reading symbolic links of shadow copies" & @CRLF & @CRLF)
$DummyVar=0
; _ArrayDisplay($FromHarddiskVolumeShadowCopyXArr,"$FromHarddiskVolumeShadowCopyXArr")
EndIf
EndIf
If Not $DoRead Then
;Prep timestamp before write
$NewTimestamp = Hex($FormattedTimestamp1)
If NOT IsInt(StringLen($NewTimestamp)/2) Then
$NewTimestamp = '0' & $NewTimestamp
EndIf
$StrLn = StringLen($NewTimestamp)
Select
Case $StrLn = 0
$out = '0000000000000000'
Case $StrLn = 2
$out = '00000000000000' & $NewTimestamp
Case $StrLn = 4
$out = '000000000000' & $NewTimestamp
Case $StrLn = 6
$out = '0000000000' & $NewTimestamp
Case $StrLn = 8
$out = '00000000' & $NewTimestamp
Case $StrLn = 10
$out = '000000' & $NewTimestamp
Case $StrLn = 12
$out = '0000' & $NewTimestamp
Case $StrLn = 14
$out = '00' & $NewTimestamp
Case $StrLn = 16
$out = $NewTimestamp
EndSelect
$NewTimestampShifted = _ShiftEndian($out)
;Start write
ConsoleWrite("Start patching timestamps" & @CRLF & @CRLF)
ConsoleWrite("Trying volume offset 0x" & Hex(Int($InfoArrShadowMainTarget[2])) & @CRLF)
_RawModMft($InfoArrShadowMainTarget[2],$InfoArrShadowMainTarget[0])
If $DoSi Then
ConsoleWrite(@CRLF & "Patching resident INDX records of parent ($INDEX_ROOT)" & @CRLF)
ConsoleWrite(@CRLF & "Trying volume offset 0x" & Hex(Int($InfoArrShadowParent[2])) & @CRLF)
_RawModIndexRoot($TargetDrive,$InfoArrShadowParent[2],$InfoArrShadowMainTarget[0])
;Check for current INDX of parent
ConsoleWrite(@CRLF & "Patching non-resident INDX records of parent ($INDEX_ALLOCATION)" & @CRLF)
If IsArray($RawOffsetIndxArray) And Ubound($RawOffsetIndxArray) > 1 Then
; _ArrayDisplay($RawOffsetIndxArray,"$RawOffsetIndxArray")
For $i = 1 To UBound($RawOffsetIndxArray)-1
ConsoleWrite(@CRLF & "Trying volume offset 0x" & Hex(Int($RawOffsetIndxArray[$i][0])) & @CRLF)
_RawModIndx($RawOffsetIndxArray[$i][0],$RawOffsetIndxArray[$i][2]/4096,$InfoArrShadowParent[0],$InfoArrShadowMainTarget[0])
Next
Else
ConsoleWrite("There was no INDX records of parent to patch" & @CRLF)
EndIf
EndIf
EndIf
If $DoShadows Then
;Scan shadow copies for MFT and INDX records
ConsoleWrite(@CRLF & "Start parsing shadow copies in raw mode (modified clusters)" & @CRLF & @CRLF)
_RawShadowParse($TargetDrive)
ConsoleWrite(@CRLF & "Finished parsing shadow copies in raw mode (modified clusters)" & @CRLF & @CRLF)
EndIf
If $DoShadows And Not $DoRead Then
ConsoleWrite("Start patching timestamps within shadow copies" & @CRLF & @CRLF)
ConsoleWrite("Patching $MFT records of target" & @CRLF)
;Write directly to MFT records within shadow copies
If UBound($ShadowModifyMftArr) > 1 Then
For $i = 1 To UBound($ShadowModifyMftArr)-1
ConsoleWrite(@CRLF & "Trying volume offset 0x" & Hex(Int($ShadowModifyMftArr[$i])) & @CRLF)
_RawModMft($ShadowModifyMftArr[$i],$InfoArrShadowMainTarget[0])
Next
Else
ConsoleWrite("There was no $MFT records of target to patch" & @CRLF)
EndIf
;$STANDARD_INFORMATION related operations
If $DoSi Then
ConsoleWrite(@CRLF & "Patching resident INDX records of parent ($INDEX_ROOT)" & @CRLF)
;Write directly to parent MFT record within shadow copies
If UBound($ShadowModifyParentMftArr) > 1 Then
For $i = 1 To UBound($ShadowModifyParentMftArr)-1
ConsoleWrite(@CRLF & "Trying volume offset 0x" & Hex(Int($ShadowModifyParentMftArr[$i])) & @CRLF)
_RawModIndexRoot($TargetDrive,$ShadowModifyParentMftArr[$i],$InfoArrShadowMainTarget[0])
Next
Else
ConsoleWrite("There was no $MFT records of parent with $INDEX_ROOT attributes to patch" & @CRLF)
EndIf
ConsoleWrite(@CRLF & "Patching non-resident INDX records of parent ($INDEX_ALLOCATION)" & @CRLF)
;Write directly to INDX records within shadow copies
If UBound($ShadowModifyIndxArr) > 1 Then
For $i = 1 To UBound($ShadowModifyIndxArr)-1
ConsoleWrite(@CRLF & "Trying volume offset 0x" & Hex(Int($ShadowModifyIndxArr[$i])) & @CRLF)
_RawModIndx($ShadowModifyIndxArr[$i],1,$InfoArrShadowParent[0],$InfoArrShadowMainTarget[0])
Next
Else
ConsoleWrite("There was no INDX records of parent to patch" & @CRLF)
EndIf
EndIf
EndIf
;Close existing handle to volume
_WinAPI_CloseHandle($hDisk)
If Not $DoRead Then
; Trick to force the cache manager to re-generate file system cache (effectively wiping the timestamps stored in memory by the system)
$ret = DllCall('kernel32.dll', 'ptr', 'CreateFileW', 'wstr', "\\.\" & $TargetDrive, 'dword', $GENERIC_READ , 'dword', 1, 'ptr', 0, 'dword', 3, 'dword', 0x20000000, 'ptr', 0)
$hDisk = $ret[0]
If $hDisk Then
_WinAPI_CloseHandle($hDisk)
EndIf
ConsoleWrite(@CRLF & "File system cache cleared in RAM" & @CRLF)
EndIf
_End($Timerstart)
Func _SplitPath($InPath)
Local $Reconstruct,$FilePathSplit[3], $DirArray
; ConsoleWrite("_SplitPath()" & @CRLF)
; ConsoleWrite("$InPath: " & $InPath & @CRLF)
If StringRight($InPath,1) = "\" Then $InPath = StringTrimRight($InPath,1)
$DirArray = StringSplit($InPath,"\")
; ConsoleWrite("$DirArray[0]: " & $DirArray[0] & @CRLF)
If StringLen($InPath) = 2 Then
$FilePathSplit[0] = $InPath
$FilePathSplit[1] = ""
$FilePathSplit[2] = ""
Return $FilePathSplit
EndIf
If $DirArray[0] = 2 Then
$FilePathSplit[0] = $DirArray[1]
$FilePathSplit[1] = $DirArray[2]
$FilePathSplit[2] = ""
Return $FilePathSplit
EndIf
For $i = 1 To $DirArray[0]-2
; ConsoleWrite("$DirArray[$i]: " & $DirArray[$i] & @CRLF)
$Reconstruct &= $DirArray[$i]&"\"
Next
$Reconstruct = StringTrimRight($Reconstruct,1)
$FilePathSplit[0] = $Reconstruct
$FilePathSplit[1] = $DirArray[Ubound($DirArray)-2]
$FilePathSplit[2] = $DirArray[Ubound($DirArray)-1]
Return $FilePathSplit
EndFunc
Func _GenDirArray($InPath)
Local $Reconstruct
; ConsoleWrite("_GenDirArray()" & @CRLF)
; ConsoleWrite("$InPath: " & $InPath & @CRLF)
Global $DirArray = StringSplit($InPath,"\")
$LockedFileName = $DirArray[$DirArray[0]]
For $i = 1 To $DirArray[0]-1
$Reconstruct &= $DirArray[$i]&"\"
Next
$Reconstruct = StringTrimRight($Reconstruct,1)
Return $Reconstruct
EndFunc
Func _RawResolveRef($TargetDevice,$ParentPath, $FileName, $ReParseNtfs)
Local $ParentDir,$NextRef,$ResolvedPath,$RetRec[2],$NewRecord,$ResolvedRef;,$StartStr,$TargetDriveLocal
Local $ResolvedRef=0 ;We don't use this function for resolving $MFT itself anyway
; ConsoleWrite("$ParentPath: " & $ParentPath & @CRLF)
; ConsoleWrite("$FileName: " & $FileName & @CRLF)
If StringLen($ParentPath)=2 Then $ParentPath&="\"
$ParentDir = _GenDirArray($ParentPath)
; ConsoleWrite("$ParentDir: " & $ParentDir & @CRLF)
Global $MftRefArray[$DirArray[0]+1]
If $ReParseNtfs Then
_ReadBootSector($TargetDevice)
If @error Then
ConsoleWrite("Error: Filesystem not NTFS" & @CRLF)
Exit
EndIf
$hDisk = _WinAPI_CreateFile("\\.\" & $TargetDevice,2,2,7)
If $hDisk = 0 Then
ConsoleWrite("CreateFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Exit
EndIf
$MFTEntry = _FindMFT($TargetDevice,0)
If $MFTEntry = "" Then ;something wrong with record for $MFT
ConsoleWrite("Error: Getting MFT record 0" & @CRLF)
Exit
EndIf
$MFT = _DecodeMFTRecord0($MFTEntry, 0) ;produces DataQ for $MFT, record 0
If $MFT = "" Then
ConsoleWrite("Error: Parsing the MFT record 0" & @CRLF)
Exit
EndIf
_GetRunsFromAttributeListMFT0() ;produces datarun for $MFT and converts datarun to RUN_VCN[] and RUN_Clusters[]
_WinAPI_CloseHandle($hDisk)
$MFTSize = $DATA_RealSize
$MFT_RUN_VCN = $RUN_VCN
$MFT_RUN_Clusters = $RUN_Clusters
_GenRefArray()
EndIf
$NextRef = 5
$MftRefArray[1]=$NextRef
$ResolvedPath = $DirArray[1]
For $i = 2 To $DirArray[0]
Global $DataQ[1]
$RetRec = _FindFileMFTRecord($TargetDevice,$NextRef)
If Not IsArray($RetRec) Then Return SetError(1,0,0)
$NewRecord = $RetRec[1]
If _DecodeMFTRecord($TargetDevice,$NewRecord,1) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $RetRec[0] & @CRLF)
Return 0
EndIf
$NextRef = _ParseIndex($DirArray[$i])
$MftRefArray[$i]=$NextRef
If @error Then
Global $DataQ[1]
$RetRec = _FindFileMFTRecord($TargetDevice,$MftRefArray[$i-1])
If Not IsArray($RetRec) Then Return SetError(1,0,0)
$NewRecord = $RetRec[1]
If _DecodeMFTRecord($TargetDevice,$NewRecord,1) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $RetRec[0] & @CRLF)
Return 0
EndIf
$ResolvedRef = _GetMftRefFromIndex($FileName)
ElseIf $i=$DirArray[0] Then
Global $DataQ[1]
$RetRec = _FindFileMFTRecord($TargetDevice,$MftRefArray[$i])
If Not IsArray($RetRec) Then Return SetError(1,0,0)
$NewRecord = $RetRec[1]
If _DecodeMFTRecord($TargetDevice,$NewRecord,1) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $RetRec[0] & @CRLF)
Return 0
EndIf
$ResolvedRef = _GetMftRefFromIndex($FileName)
If @error Then ; In case last part was a file and not a directory
Global $DataQ[1]
$RetRec = _FindFileMFTRecord($TargetDevice,$MftRefArray[$i-1])
If Not IsArray($RetRec) Then Return SetError(1,0,0)
$NewRecord = $RetRec[1]
If _DecodeMFTRecord($TargetDevice,$NewRecord,1) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $RetRec[0] & @CRLF)
Return 0
EndIf
$ResolvedRef = _GetMftRefFromIndex($FileName)
EndIf
ElseIf StringIsDigit($NextRef) Then
$ResolvedPath &= "\" & $DirArray[$i]
ContinueLoop
Else
ConsoleWrite("Error: Something went wrong" & @CRLF)
ExitLoop
EndIf
Next
; If StringRight($ParentPath,1) = "\" Then $ParentPath = StringTrimRight($ParentPath,1)
; If $FileName <> "$MFT" And $ResolvedRef <> 0 Then ConsoleWrite("MFT Ref of " & $ParentPath & "\" & $FileName & ": " & $ResolvedRef & @CRLF)
Return $ResolvedRef
EndFunc
Func _RawShadowParse($TargetDevice)
Local $tBuffer,$nBytes,$hVol,$VolDataTmp,$ShadowDataTmp
$GlobalShadowArray[0][0] = "FileRef"
$GlobalShadowArray[0][1] = "FileName"
$GlobalShadowArray[0][2] = "CreationTime"
$GlobalShadowArray[0][3] = "StoreHeaderOffset"
$GlobalShadowArray[0][4] = "BlockListOffset"
$GlobalShadowArray[0][5] = "StoreBlockRangeListOffset"
$GlobalShadowArray[0][6] = "ShadowCopyIdGuid"
$GlobalShadowArray[0][7] = "ShadowCopySetIdGuid"
;Resolve the MFT ref of the Shadow copy master file
$ShadowPathResolved = $TargetDevice & "\" & $ShadowPath
$ShadowMasterRef = _RawResolveRef($TargetDevice,$ShadowPathResolved, $ShadowGuid, 1)
If $ShadowMasterRef Then
; ConsoleWrite("$ShadowMasterRef: " & $ShadowMasterRef & @CRLF)
Else
ConsoleWrite("Error resolving: " & $ShadowPathResolved & $ShadowGuid & " (no shadow copy found)" & @CRLF)
Return 0
EndIf
;Find the MFT record and decode it
$NewRecord = _FindFileMFTRecord($TargetDevice,$ShadowMasterRef)
If _DecodeMFTRecord($TargetDevice,$NewRecord[1],2) < 1 Then
ConsoleWrite("Could not verify MFT record at offset: 0x" & $NewRecord[0] & @CRLF)
Return 0
EndIf
;Read the shadow information from the volume offset 0x1e00
$hVol = _WinAPI_CreateFile("\\.\" & $TargetDevice,2,6,6)
If $hVol = 0 Then
ConsoleWrite("CreateFile in function _RawShadowParse(): " & _WinAPI_GetLastErrorMessage() & @CRLF)
Return 0
EndIf
_WinAPI_SetFilePointerEx($hVol, 0x1e00, $FILE_BEGIN)
$tBuffer = DllStructCreate("byte[512]")
If Not _WinAPI_ReadFile($hVol, DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer), $nBytes) Then
ConsoleWrite("Error in ReadFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Return 0
EndIf
$VolDataTmp = DllStructGetData($tBuffer,1)
;_WinAPI_CloseHandle($hVol)
; ConsoleWrite("Volume VSS data decode of: " & $TargetDevice & @CRLF)
; ConsoleWrite(_HexEncode($VolDataTmp) & @CRLF)
; _DecodeVolumeVssData($VolDataTmp)
;Decode the VSS master file
_DecodeShadowMasterFileData($TargetDevice,$Mode2Data)
; _ArrayDisplay($GlobalShadowArray,"$GlobalShadowArray")
For $i = 1 To Ubound($GlobalShadowArray)-1
ConsoleWrite("Scanning Shadow Copy with filename: " & $GlobalShadowArray[$i][1] & @CRLF)
$SkipFixups=0
$IsRawShadowCopy=0 ;The file itself is not a shadow copy, only its content :)
$NewRecord = _FindFileMFTRecord($TargetDevice,$GlobalShadowArray[$i][0])
_DecodeMFTRecord($TargetDevice,$NewRecord[1],3) ;Mode=3 will populate $RawTestOffsetArray
$TestOffset = $RawTestOffsetArray[1][0]
$BlockSize = 16384
;$SkipFixups=1 ;For MFT records found within shadow copies, fixups are already applied.
$IsRawShadowCopy=1 ;The MFT records we process from here are from within a shadow copy
$ParentMode=0
; _ArrayDisplay($RawTestOffsetArray,"$RawTestOffsetArray")
For $j = 1 To UBound($RawTestOffsetArray)-1
$TestOffset = Int($RawTestOffsetArray[$j][0])
$BytesProcessed = 0
; ConsoleWrite("Loop per run: " & $j & @CRLF)
Do
; ConsoleWrite("Loop within run for each 0x4000 bytes: " & @CRLF)
;ConsoleWrite("$BytesProcessed: " & $BytesProcessed & @CRLF)
_WinAPI_SetFilePointerEx($hVol, $TestOffset, $FILE_BEGIN)
$tBuffer = DllStructCreate("byte[512]")
If Not _WinAPI_ReadFile($hVol, DllStructGetPtr($tBuffer), 512, $nBytes) Then
ConsoleWrite("Error in ReadFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Return 0
EndIf
$ShadowDataTmp = DllStructGetData($tBuffer,1)
$tBuffer=0
$First4Bytes = StringMid($ShadowDataTmp,3,8)
If $First4Bytes = '46494C45' Then ;FILE
_WinAPI_SetFilePointerEx($hVol, $TestOffset, $FILE_BEGIN)
$tBuffer = DllStructCreate("byte["&$MFT_Record_Size&"]")
If Not _WinAPI_ReadFile($hVol, DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer), $nBytes) Then
ConsoleWrite("Error in ReadFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Return 0
EndIf
$ShadowDataTmp = DllStructGetData($tBuffer,1)
$tBuffer=0
$HEADER_MFTREcordNumber = StringMid($ShadowDataTmp, 91, 8)
$HEADER_MFTREcordNumber = Dec(_SwapEndian($HEADER_MFTREcordNumber),2)
_DecodeMFTRecord($TargetDevice,$ShadowDataTmp,1)
; ConsoleWrite("MFT record " & $HEADER_MFTREcordNumber & " with name " & $FN_FileName & " found at offset: 0x" & Hex($TestOffset) & @crlf)
;If $InfoArrShadowMainTarget[0] = $HEADER_MFTREcordNumber And $InfoArrShadowMainTarget[1] = $FN_FileName Then
If $InfoArrShadowMainTarget[0] = $HEADER_MFTREcordNumber And $InfoArrShadowMainTarget[1] = $FN_FileName And $InfoArrShadowParent[0] = $FN_ParentReferenceNo Then
; ConsoleWrite("Found main target with ref " & $HEADER_MFTREcordNumber & " and name " & $FN_FileName & " at offset: 0x" & Hex($TestOffset)& @CRLF)
If $DoRead Then _DumpTimestampsToConsole()
ReDim $ShadowModifyMftArr[Ubound($ShadowModifyMftArr)+1]
$ShadowModifyMftArr[Ubound($ShadowModifyMftArr)-1] = $TestOffset
EndIf
If $InfoArrShadowParent[0] = $HEADER_MFTREcordNumber And $InfoArrShadowParent[1] = $FN_FileName Then
; ConsoleWrite("Found parent of target with ref " & $HEADER_MFTREcordNumber & " and name " & $FN_FileName & " at offset: 0x" & Hex($TestOffset)& @CRLF)
ReDim $ShadowModifyParentMftArr[Ubound($ShadowModifyParentMftArr)+1]
$ShadowModifyParentMftArr[Ubound($ShadowModifyParentMftArr)-1] = $TestOffset
EndIf
$BytesProcessed2=$MFT_Record_Size
$TestOffset2 = Int($TestOffset) + Int($MFT_Record_Size)
Do
;ConsoleWrite("Loop inner most " & @CRLF)
_WinAPI_SetFilePointerEx($hVol, $TestOffset2, $FILE_BEGIN)
$tBuffer = DllStructCreate("byte["&$MFT_Record_Size&"]")
If Not _WinAPI_ReadFile($hVol, DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer), $nBytes) Then
ConsoleWrite("Error in ReadFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Return 0
EndIf
$ShadowDataTmp = DllStructGetData($tBuffer,1)
$First4Bytes = StringMid($ShadowDataTmp,3,8)
If $First4Bytes = '46494C45' Then ;FILE
$HEADER_MFTREcordNumber = StringMid($ShadowDataTmp, 91, 8)
$HEADER_MFTREcordNumber = Dec(_SwapEndian($HEADER_MFTREcordNumber),2)
_DecodeMFTRecord($TargetDevice,$ShadowDataTmp,1)
; ConsoleWrite("MFT record " & $HEADER_MFTREcordNumber & " with name " & $FN_FileName & " found at offset: 0x" & Hex($TestOffset2) & @crlf)
;If $InfoArrShadowMainTarget[0] = $HEADER_MFTREcordNumber And $InfoArrShadowMainTarget[1] = $FN_FileName Then
If $InfoArrShadowMainTarget[0] = $HEADER_MFTREcordNumber And $InfoArrShadowMainTarget[1] = $FN_FileName And $InfoArrShadowParent[0] = $FN_ParentReferenceNo Then
; ConsoleWrite("Found main target with ref " & $HEADER_MFTREcordNumber & " and name " & $FN_FileName & " at offset: 0x" & Hex($TestOffset2)& @CRLF)
If $DoRead Then _DumpTimestampsToConsole()
ReDim $ShadowModifyMftArr[Ubound($ShadowModifyMftArr)+1]
$ShadowModifyMftArr[Ubound($ShadowModifyMftArr)-1] = $TestOffset2
EndIf
If $InfoArrShadowParent[0] = $HEADER_MFTREcordNumber And $InfoArrShadowParent[1] = $FN_FileName Then
; ConsoleWrite("Found parent of target with ref " & $HEADER_MFTREcordNumber & " and name " & $FN_FileName & " at offset: 0x" & Hex($TestOffset2)& @CRLF)
ReDim $ShadowModifyParentMftArr[Ubound($ShadowModifyParentMftArr)+1]
$ShadowModifyParentMftArr[Ubound($ShadowModifyParentMftArr)-1] = $TestOffset2
EndIf
$TestOffset2+=$MFT_Record_Size
$BytesProcessed2+=$MFT_Record_Size
ElseIf $First4Bytes = '494e4458' Then ;INDX
$ShadowDataTmp=""
_WinAPI_SetFilePointerEx($hVol, $TestOffset2, $FILE_BEGIN)
$tBuffer = DllStructCreate("byte["&$INDX_Record_Size&"]")
If Not _WinAPI_ReadFile($hVol, DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer), $nBytes) Then
ConsoleWrite("Error in ReadFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Return 0
EndIf
$ShadowDataTmp = DllStructGetData($tBuffer,1)
; ConsoleWrite("Found INDX at offset: 0x" & Hex($TestOffset2)& @CRLF)
$FixedIndxRecord = _StripIndxRecord(StringTrimLeft($ShadowDataTmp,2))
If _DecodeIndxEntriesExpress($FixedIndxRecord) Then
; ConsoleWrite("INDX success at offset: 0x" & Hex($TestOffset2)& @CRLF)
ReDim $ShadowModifyIndxArr[Ubound($ShadowModifyIndxArr)+1]
$ShadowModifyIndxArr[Ubound($ShadowModifyIndxArr)-1] = $TestOffset2
EndIf
;$IndxEntryNumberArr2[1],$IndxMFTReferenceArr2[1],$IndxFileNameArr2[1]
$TestOffset2+=$INDX_Record_Size
$BytesProcessed2+=$INDX_Record_Size
Else
$TestOffset2+=$MFT_Record_Size
$BytesProcessed2+=$MFT_Record_Size
EndIf
$ShadowDataTmp=""
$tBuffer=0
; $TestOffset2+=$MFT_Record_Size
; $BytesProcessed2+=$MFT_Record_Size
Until $BytesProcessed2 >= $BlockSize
ElseIf $First4Bytes = '494e4458' Then ;INDX
; #cs
; ConsoleWrite("Found INDX at offset: 0x" & Hex($TestOffset)& @CRLF)
_WinAPI_SetFilePointerEx($hVol, $TestOffset, $FILE_BEGIN)
$tBuffer = DllStructCreate("byte["&$INDX_Record_Size&"]")
If Not _WinAPI_ReadFile($hVol, DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer), $nBytes) Then
ConsoleWrite("Error in ReadFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Return 0
EndIf
$ShadowDataTmp = DllStructGetData($tBuffer,1)
$tBuffer=0
$FixedIndxRecord = _StripIndxRecord(StringTrimLeft($ShadowDataTmp,2))
If _DecodeIndxEntriesExpress($FixedIndxRecord) Then
; ConsoleWrite("INDX success at offset: 0x" & Hex($TestOffset)& @CRLF)
ReDim $ShadowModifyIndxArr[Ubound($ShadowModifyIndxArr)+1]
$ShadowModifyIndxArr[Ubound($ShadowModifyIndxArr)-1] = $TestOffset
EndIf
$BytesProcessed2=$INDX_Record_Size
$TestOffset2 = Int($TestOffset) + Int($INDX_Record_Size)
Do
_WinAPI_SetFilePointerEx($hVol, $TestOffset2, $FILE_BEGIN)
$tBuffer = DllStructCreate("byte["&$INDX_Record_Size&"]")
If Not _WinAPI_ReadFile($hVol, DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer), $nBytes) Then
ConsoleWrite("Error in ReadFile: " & _WinAPI_GetLastErrorMessage() & @CRLF)
Return 0
EndIf
$ShadowDataTmp = DllStructGetData($tBuffer,1)
$First4Bytes = StringMid($ShadowDataTmp,3,8)
;--------------------------------Should never occur..?
If $First4Bytes = '46494C45' Then ;FILE
$HEADER_MFTREcordNumber = StringMid($ShadowDataTmp, 91, 8)
$HEADER_MFTREcordNumber = Dec(_SwapEndian($HEADER_MFTREcordNumber),2)
_DecodeMFTRecord($TargetDevice,$ShadowDataTmp,1)
;ConsoleWrite("MFT record " & $HEADER_MFTREcordNumber & " with name " & $FN_FileName & " found at offset: 0x" & Hex($TestOffset2) & @crlf)
;If $InfoArrShadowMainTarget[0] = $HEADER_MFTREcordNumber And $InfoArrShadowMainTarget[1] = $FN_FileName Then
If $InfoArrShadowMainTarget[0] = $HEADER_MFTREcordNumber And $InfoArrShadowMainTarget[1] = $FN_FileName And $InfoArrShadowParent[0] = $FN_ParentReferenceNo Then
; ConsoleWrite("Found main target with ref " & $HEADER_MFTREcordNumber & " and name " & $FN_FileName & " at offset: 0x" & Hex($TestOffset2)& @CRLF)
If $DoRead Then _DumpTimestampsToConsole()
ReDim $ShadowModifyMftArr[Ubound($ShadowModifyMftArr)+1]
$ShadowModifyMftArr[Ubound($ShadowModifyMftArr)-1] = $TestOffset2
EndIf
If $InfoArrShadowParent[0] = $HEADER_MFTREcordNumber And $InfoArrShadowParent[1] = $FN_FileName Then
; ConsoleWrite("Found parent of target with ref " & $HEADER_MFTREcordNumber & " and name " & $FN_FileName & " at offset: 0x" & Hex($TestOffset2)& @CRLF)
ReDim $ShadowModifyParentMftArr[Ubound($ShadowModifyParentMftArr)+1]
$ShadowModifyParentMftArr[Ubound($ShadowModifyParentMftArr)-1] = $TestOffset2
EndIf
; MsgBox(0,"Warning","Unexpected data in shadow copy.")
ElseIf $First4Bytes = '494e4458' Then ;INDX
; ConsoleWrite("Found INDX at offset: 0x" & Hex($TestOffset)& @CRLF)
$FixedIndxRecord = _StripIndxRecord(StringTrimLeft($ShadowDataTmp,2))
If _DecodeIndxEntriesExpress($FixedIndxRecord) Then
; ConsoleWrite("INDX success at offset: 0x" & Hex($TestOffset2)& @CRLF)
ReDim $ShadowModifyIndxArr[Ubound($ShadowModifyIndxArr)+1]
$ShadowModifyIndxArr[Ubound($ShadowModifyIndxArr)-1] = $TestOffset2
EndIf
EndIf
$tBuffer=0
$TestOffset2+=$INDX_Record_Size
$BytesProcessed2+=$INDX_Record_Size
Until $BytesProcessed2 >= $BlockSize
EndIf
$TestOffset+=$BlockSize
$BytesProcessed+=$BlockSize
Until $BytesProcessed >= $RawTestOffsetArray[$j][2]
Next
Next
_WinAPI_CloseHandle($hVol)
Return 1
EndFunc
Func _DecodeVolumeVssData($InputData)
Local $VssGuid,$CatalogEntryType,$vssRecordType,$vssCurrentOffset,$vssUnknownNextOffset,$vssUnknown1,$vssCatalogOffset,$vssMaxSize,$vssVolumeIdGuid,$vssVolumeIdGuidMod,$vssVolumeIdGuidMod2,$vssShadowStorageIdGuid,$vssShadowStorageIdGuidMod,$vssShadowStorageIdGuidMod2
If StringLeft($InputData,2) = "0x" Then $InputData = StringTrimLeft($InputData,2)
ConsoleWrite(@CRLF & "Decode of Volume VSS data" & @CRLF)
$VssGuid = StringMid($InputData,1,32)
If Not $VssGuid = "6b87083876c1484eb7ae04046e6cc752" Then
ConsoleWrite("Error the header Guid is not as expected: " & $VssGuid& @CRLF)
Return 0
EndIf
$vssVersion = StringMid($InputData,33,8)
$vssVersion = Dec(_SwapEndian($vssVersion))
$vssRecordType = StringMid($InputData,41,8)
$vssRecordType = Dec(_SwapEndian($vssRecordType))
$vssCurrentOffset = StringMid($InputData,49,16)
$vssCurrentOffset = _SwapEndian($vssCurrentOffset)
$vssUnknownNextOffset = StringMid($InputData,65,16)
$vssUnknownNextOffset = _SwapEndian($vssUnknownNextOffset)
$vssUnknown1 = StringMid($InputData,81,16)
$vssUnknown1 = _SwapEndian($vssUnknown1)
$vssCatalogOffset = StringMid($InputData,97,16)
$vssCatalogOffset = _SwapEndian($vssCatalogOffset)
$vssMaxSize = StringMid($InputData,113,16)
$vssMaxSize = _SwapEndian($vssMaxSize)
$vssVolumeIdGuid = StringMid($InputData,129,32)
;$vssVolumeIdGuid = _SwapEndian($vssVolumeIdGuid)
$vssVolumeIdGuidMod = _SwapEndian(StringMid($vssVolumeIdGuid,1,8)) & _SwapEndian(StringMid($vssVolumeIdGuid,9,4)) & _SwapEndian(StringMid($vssVolumeIdGuid,13,4)) & StringMid($vssVolumeIdGuid,17,4) & StringMid($vssVolumeIdGuid,21,12)
$vssVolumeIdGuidMod2 = "{" & _SwapEndian(StringMid($vssVolumeIdGuid,1,8)) & "-" & _SwapEndian(StringMid($vssVolumeIdGuid,9,4)) & "-" & _SwapEndian(StringMid($vssVolumeIdGuid,13,4)) & "-" & StringMid($vssVolumeIdGuid,17,4) & "-" & StringMid($vssVolumeIdGuid,21,12) & "}"
$vssShadowStorageIdGuid = StringMid($InputData,161,32)
;$vssShadowStorageIdGuid = _SwapEndian($vssShadowStorageIdGuid)
$vssShadowStorageIdGuidMod = _SwapEndian(StringMid($vssShadowStorageIdGuid,1,8)) & _SwapEndian(StringMid($vssShadowStorageIdGuid,9,4)) & _SwapEndian(StringMid($vssShadowStorageIdGuid,13,4)) & StringMid($vssShadowStorageIdGuid,17,4) & StringMid($vssShadowStorageIdGuid,21,12)
$vssShadowStorageIdGuidMod2 = "{" & _SwapEndian(StringMid($vssShadowStorageIdGuid,1,8)) & "-" & _SwapEndian(StringMid($vssShadowStorageIdGuid,9,4)) & "-" & _SwapEndian(StringMid($vssShadowStorageIdGuid,13,4)) & "-" & StringMid($vssShadowStorageIdGuid,17,4) & "-" & StringMid($vssShadowStorageIdGuid,21,12) & "}"
;$vssUnknown2 = StringMid($InputData,195,8)
;$vssUnknown2 = _SwapEndian($vssUnknown2)
;$vssUnknown3 = StringMid($InputData,203,824)
;$vssUnknown3 = _SwapEndian($vssUnknown3)
ConsoleWrite("$vssVersion: " & $vssVersion & @CRLF)
ConsoleWrite("$vssRecordType: " & $vssRecordType & @CRLF)
ConsoleWrite("$vssCurrentOffset: " & $vssCurrentOffset & @CRLF)
ConsoleWrite("$vssUnknownNextOffset: " & $vssUnknownNextOffset & @CRLF)
ConsoleWrite("$vssUnknown1: " & $vssUnknown1 & @CRLF)
ConsoleWrite("$vssCatalogOffset: " & $vssCatalogOffset & @CRLF)
ConsoleWrite("$vssMaxSize: " & $vssMaxSize & @CRLF)
; ConsoleWrite("$vssVolumeIdGuid: " & $vssVolumeIdGuid & @CRLF)
; ConsoleWrite("$vssVolumeIdGuidMod: " & $vssVolumeIdGuidMod & @CRLF)
ConsoleWrite("$vssVolumeIdGuidMod2: " & $vssVolumeIdGuidMod2 & @CRLF)
; ConsoleWrite("$vssShadowStorageIdGuid: " & $vssShadowStorageIdGuid & @CRLF)
; ConsoleWrite("$vssShadowStorageIdGuidMod: " & $vssShadowStorageIdGuidMod & @CRLF)
ConsoleWrite("$vssShadowStorageIdGuidMod2: " & $vssShadowStorageIdGuidMod2 & @CRLF)
Return 1
EndFunc
Func _DecodeShadowMasterFileData($TargetDevice,$InputDataFull)
Local $VssGuid,$vssVersion,$vssRecordType,$vssOffset1,$vssOffset2,$vssOffset3,$CatalogEntryType,$CatalogEntry
;Catalog block header
; ConsoleWrite("Decode of Shadow Master File" & @CRLF)
$StartPos=1
$DataSize = BinaryLen($InputDataFull)
; ConsoleWrite("$DataSize: " & $DataSize & @CRLF)
For $i = 1 To $DataSize/16384
$InputData = StringMid($InputDataFull,$StartPos,32768)
; ConsoleWrite(_HexEncode("0x"&StringMid($InputData,1,1024)) & @CRLF)
; ConsoleWrite(@CRLF & "Decode of Catalog block header " & $i & @CRLF)
$VssGuid = StringMid($InputData,1,32)
If Not $VssGuid = "6b87083876c1484eb7ae04046e6cc752" Then
; ConsoleWrite("Error the header Guid is not as expected: " & $VssGuid & @CRLF)
Return 0
EndIf
; ConsoleWrite("Header GUID OK" & @CRLF)
$vssVersion = StringMid($InputData,33,8)
$vssVersion = Dec(_SwapEndian($vssVersion))
$vssRecordType = StringMid($InputData,41,8)
$vssRecordType = Dec(_SwapEndian($vssRecordType))
$vssOffset1 = StringMid($InputData,49,16)
$vssOffset1 = _SwapEndian($vssOffset1)
$vssOffset2 = StringMid($InputData,65,16)
$vssOffset2 = _SwapEndian($vssOffset2)
$vssOffset3 = StringMid($InputData,81,16)
$vssOffset3 = _SwapEndian($vssOffset3)
;$vssUnknown1 = StringMid($InputData,97,160) ;Irrelevant
; ConsoleWrite("$vssVersion: " & $vssVersion & @CRLF)
; ConsoleWrite("$vssRecordType: " & $vssRecordType & @CRLF)
; ConsoleWrite("$vssOffset1: " & $vssOffset1 & @CRLF)
; ConsoleWrite("$vssOffset2: " & $vssOffset2 & @CRLF)
; ConsoleWrite("$vssOffset3: " & $vssOffset3 & @CRLF)
$sCounter = 1
Do
$sCounter += 256
;Catalog entry
$CatalogEntryType = StringMid($InputData,$sCounter,16)
$CatalogEntryType = Dec(_SwapEndian($CatalogEntryType))
; ConsoleWrite("$CatalogEntryType: " & $CatalogEntryType & @CRLF)
;Put this into a loop
$CatalogEntry = StringMid($InputData,$sCounter,256)
Select
Case $CatalogEntryType = 1
_DecodeCatalogEntryType1($CatalogEntry)
Case $CatalogEntryType = 2
_DecodeCatalogEntryType2($CatalogEntry)
Case $CatalogEntryType = 3
_DecodeCatalogEntryType3($TargetDevice,$CatalogEntry)
EndSelect
Until $CatalogEntryType <> 2 And $CatalogEntryType <> 3
$StartPos+=32768
Next
Return 1
EndFunc
Func _DecodeCatalogEntryType1($InputData)
ConsoleWrite("Catalog type 1 (not in use ?)" & @CRLF)
Return 0
EndFunc
Func _DecodeCatalogEntryType2($InputData)
Local $CECatalogEntryType,$CEVolumeSize,$CEGuidFilename,$CEGuidFilenameMod,$CEGuidFilenameMod2,$CESequenceNumber,$CEFlags,$CEShadowTimestamp,$CEShadowTimestamp_tmp,$ActualShadowFileName,$ActualShadowFileNameRef
$CECatalogEntryType = StringMid($InputData,1,16)
$CECatalogEntryType = Dec(_SwapEndian($CECatalogEntryType))
; ConsoleWrite(@CRLF & "Decode of Catalog type 2" & @CRLF)
If Not $CECatalogEntryType = 2 Then
ConsoleWrite("Error: Received wrong catalog type: " & $CECatalogEntryType & @CRLF)
Return 0
EndIf
; ConsoleWrite(_HexEncode("0x"&$InputData) & @CRLF)
$CEVolumeSize = StringMid($InputData,17,16)
$CEVolumeSize = _SwapEndian($CEVolumeSize)
$CEGuidFilename = StringMid($InputData,33,32)
$CEGuidFilenameMod = _SwapEndian(StringMid($CEGuidFilename,1,8)) & _SwapEndian(StringMid($CEGuidFilename,9,4)) & _SwapEndian(StringMid($CEGuidFilename,13,4)) & StringMid($CEGuidFilename,17,4) & StringMid($CEGuidFilename,21,12)
$CEGuidFilenameMod2 = "{" & _SwapEndian(StringMid($CEGuidFilename,1,8)) & "-" & _SwapEndian(StringMid($CEGuidFilename,9,4)) & "-" & _SwapEndian(StringMid($CEGuidFilename,13,4)) & "-" & StringMid($CEGuidFilename,17,4) & "-" & StringMid($CEGuidFilename,21,12) & "}"
$CESequenceNumber = StringMid($InputData,65,16)
$CESequenceNumber = _SwapEndian($CESequenceNumber)
$CEFlags = StringMid($InputData,81,16)
$CEFlags = _SwapEndian($CEFlags)
$CEShadowTimestamp = StringMid($InputData,97,16)
$CEShadowTimestamp = _SwapEndian($CEShadowTimestamp)
$CEShadowTimestamp_tmp = _WinTime_UTCFileTimeToLocalFileTime("0x" & $CEShadowTimestamp)
$CEShadowTimestamp = _WinTime_UTCFileTimeFormat(Dec($CEShadowTimestamp)-$tDelta,$DateTimeFormat,2)
$CEShadowTimestamp = $CEShadowTimestamp & ":" & _FillZero(StringRight($CEShadowTimestamp_tmp,4))
;$CEUnknown1 = StringMid($InputData,115,144) ;Irrelevant
$ActualShadowFileName = $CEGuidFilenameMod2&$ShadowGuid
; ConsoleWrite("$CEVolumeSize: 0x" & $CEVolumeSize & @CRLF)
; ConsoleWrite("$CEGuidFilenameMod2: " & $CEGuidFilenameMod2 & @CRLF)
; ConsoleWrite("$CESequenceNumber: " & $CESequenceNumber & @CRLF)
; ConsoleWrite("$CEFlags: " & $CEFlags & @CRLF)
; ConsoleWrite("$CEShadowTimestamp: " & $CEShadowTimestamp & @CRLF)
; ConsoleWrite("$ActualShadowFileName: " & $ActualShadowFileName & @CRLF)
$ActualShadowFileNameRef = _RawResolveRef($TargetDrive,$ShadowPathResolved, $ActualShadowFileName, 1)
;$ActualShadowFileNameRef = _RawResolveRef($TargetDrive,$ShadowPathResolved, $ShadowGuid)
#cs
;--------------------Check deactivated because in some rare cases there will be an actual mismatch here. Bug from Microsoft side??
If $ActualShadowFileNameRef Then
;ConsoleWrite("$ActualShadowFileNameRef: " & $ActualShadowFileNameRef & @CRLF)
$GlobalShadowFileCounter+=1
Redim $GlobalShadowArray[Ubound($GlobalShadowArray)+1][8]
$GlobalShadowArray[$GlobalShadowFileCounter][0] = $ActualShadowFileNameRef
$GlobalShadowArray[$GlobalShadowFileCounter][1] = $ActualShadowFileName
$GlobalShadowArray[$GlobalShadowFileCounter][2] = $CEShadowTimestamp
Return 1
Else
ConsoleWrite("Error resolving: " & $ShadowPathResolved & $ActualShadowFileName & @CRLF)
Return 0
EndIf
#ce
$GlobalShadowFileCounter+=1
Redim $GlobalShadowArray[Ubound($GlobalShadowArray)+1][8]
$GlobalShadowArray[$GlobalShadowFileCounter][0] = $ActualShadowFileNameRef
$GlobalShadowArray[$GlobalShadowFileCounter][1] = $ActualShadowFileName
$GlobalShadowArray[$GlobalShadowFileCounter][2] = $CEShadowTimestamp
Return 1
EndFunc
Func _DecodeCatalogEntryType3($TargetDevice,$InputData)
Local $CECatalogEntryType,$CEBlockListOffset,$CEStoreIdGuid,$CEStoreIdGuidMod2,$CEStoreHeaderOffset,$CEStoreBlockRangeListOffset,$CEStoreCurrentBitampOffset,$CENtfsMetaDataFileReference,$CENtfsMetaDataFileReferenceSeqNo
Local $CEAllocatedSize,$CEStorePreviousBitmapOffset,$CEUnknownIndex,$CEUnknown1,$nBytes
$CECatalogEntryType = StringMid($InputData,1,16)
$CECatalogEntryType = Dec(_SwapEndian($CECatalogEntryType))
; ConsoleWrite(@CRLF & "Decode of Catalog type 3" & @CRLF)
If Not $CECatalogEntryType = 3 Then
ConsoleWrite("Error: Received wrong catalog type: " & $CECatalogEntryType & @CRLF)
Return 0
EndIf
; ConsoleWrite(_HexEncode("0x"&$InputData) & @CRLF)
$CEBlockListOffset = StringMid($InputData,17,16)
$CEBlockListOffset = _SwapEndian($CEBlockListOffset)
$CEStoreIdGuid = StringMid($InputData,33,32)
$CEStoreIdGuidMod2 = "{" & _SwapEndian(StringMid($CEStoreIdGuid,1,8)) & "-" & _SwapEndian(StringMid($CEStoreIdGuid,9,4)) & "-" & _SwapEndian(StringMid($CEStoreIdGuid,13,4)) & "-" & StringMid($CEStoreIdGuid,17,4) & "-" & StringMid($CEStoreIdGuid,21,12) & "}"
$CEStoreHeaderOffset = StringMid($InputData,65,16)
$CEStoreHeaderOffset = _SwapEndian($CEStoreHeaderOffset)