├── .gitattributes
├── .github
└── workflows
│ └── publish.yml
├── .gitignore
├── Boot
├── Boot.cs
├── Boot.csproj
└── BootFile.cs
├── I30
├── I30.cs
├── I30.csproj
└── I30File.cs
├── LICENSE
├── LogFile
├── FixupData.cs
├── LogFile.cs
├── LogFile.csproj
├── LogPageRcrd.cs
├── LogPageRstr.cs
└── Log_File.cs
├── MFT.Test
├── MFT.Test.csproj
├── TestFiles
│ ├── $I30
│ │ ├── FirstDelete
│ │ │ └── $I30
│ │ ├── SecondDelete
│ │ │ └── $I30
│ │ └── Start
│ │ │ └── $I30
│ ├── Boot
│ │ └── $Boot
│ ├── NIST
│ │ └── DFR-16
│ │ │ └── $MFT
│ ├── Usn
│ │ └── record.usn
│ ├── tdungan
│ │ └── $MFT
│ └── xw
│ │ └── $MFT
└── TestMain.cs
├── MFT.sln
├── MFT
├── Attributes
│ ├── ACERecord.cs
│ ├── Attribute.cs
│ ├── AttributeList.cs
│ ├── Bitmap.cs
│ ├── Data.cs
│ ├── ExtendedAttribute.cs
│ ├── ExtendedAttributeInformation.cs
│ ├── FileInfo.cs
│ ├── FileName.cs
│ ├── Helpers.cs
│ ├── IndexAllocation.cs
│ ├── IndexNodeHeader.cs
│ ├── IndexRoot.cs
│ ├── LoggedUtilityStream.cs
│ ├── NonResidentData.cs
│ ├── ObjectId_.cs
│ ├── ReparsePoint.cs
│ ├── ResidentData.cs
│ ├── SKSecurityDescriptor.cs
│ ├── SecurityDescriptor.cs
│ ├── StandardInfo.cs
│ ├── VolumeInformation.cs
│ ├── VolumeName.cs
│ └── xACLRecord.cs
├── FileRecord.cs
├── MFT.csproj
├── Mft.cs
├── MftFile.cs
└── Other
│ ├── AdsInfo.cs
│ ├── AttributeInfo.cs
│ ├── DataRun.cs
│ ├── DirectoryNameMapValue.cs
│ ├── ExtensionMethods.cs
│ ├── FixupData.cs
│ ├── IndexEntry.cs
│ ├── IndexEntryI30.cs
│ ├── MftEntryInfo.cs
│ └── ParentMapEntry.cs
├── O
├── O.cs
├── O.csproj
└── OFile.cs
├── README.md
├── SDS
├── FixupData.cs
├── Sdh.cs
├── SdhFile.cs
├── Sds.cs
├── SdsEntry.cs
├── SdsFile.cs
├── Secure.csproj
├── Sii.cs
└── SiiFile.cs
├── Usn
├── MFTInformation.cs
├── Usn.cs
├── Usn.csproj
├── UsnEntry.cs
└── UsnFile.cs
└── icon.png
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2 |
3 | name: publish
4 | on:
5 | workflow_dispatch: # Allow running the workflow manually from the GitHub UI
6 | push:
7 | branches:
8 | - 'main' # Run the workflow when pushing to the main branch
9 | pull_request:
10 | branches:
11 | - '*' # Run the workflow for all pull requests
12 | release:
13 | types:
14 | - published # Run the workflow when a new GitHub release is published
15 |
16 | env:
17 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
18 | DOTNET_NOLOGO: true
19 | NuGetDirectory: ${{ github.workspace}}/nuget
20 |
21 | defaults:
22 | run:
23 | shell: pwsh
24 |
25 | jobs:
26 | create_nuget:
27 | runs-on: ubuntu-latest
28 | steps:
29 | - uses: actions/checkout@v4
30 | with:
31 | fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
32 |
33 | # Install the .NET SDK indicated in the global.json file
34 | - name: Setup .NET
35 | uses: actions/setup-dotnet@v4
36 |
37 | # Create the NuGet package in the folder from the environment variable NuGetDirectory
38 | - run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
39 |
40 | # Publish the NuGet package as an artifact, so they can be used in the following jobs
41 | - uses: actions/upload-artifact@v4
42 | with:
43 | name: nuget
44 | if-no-files-found: error
45 | retention-days: 7
46 | path: ${{ env.NuGetDirectory }}/*.nupkg
47 |
48 | validate_nuget:
49 | runs-on: ubuntu-latest
50 | needs: [ create_nuget ]
51 | steps:
52 | # Install the .NET SDK indicated in the global.json file
53 | - name: Setup .NET
54 | uses: actions/setup-dotnet@v4
55 |
56 | # Download the NuGet package created in the previous job
57 | - uses: actions/download-artifact@v4
58 | with:
59 | name: nuget
60 | path: ${{ env.NuGetDirectory }}
61 |
62 | - name: Install nuget validator
63 | run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
64 |
65 | # Validate metadata and content of the NuGet package
66 | # https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
67 | # If some rules are not applicable, you can disable them
68 | # using the --excluded-rules or --excluded-rule-ids option
69 | - name: Validate package
70 | run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")
71 |
72 | run_test:
73 | runs-on: ubuntu-latest
74 | steps:
75 | - uses: actions/checkout@v4
76 | - name: Setup .NET
77 | uses: actions/setup-dotnet@v4
78 | - name: Run tests
79 | run: dotnet test --configuration Release
80 |
81 | deploy:
82 | # Publish only when creating a GitHub Release
83 | # https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
84 | # You can update this logic if you want to manage releases differently
85 | if: github.event_name == 'release'
86 | runs-on: ubuntu-latest
87 | needs: [ validate_nuget ]
88 | steps:
89 | # Download the NuGet package created in the previous job
90 | - uses: actions/download-artifact@v4
91 | with:
92 | name: nuget
93 | path: ${{ env.NuGetDirectory }}
94 |
95 | # Install the .NET SDK indicated in the global.json file
96 | - name: Setup .NET Core
97 | uses: actions/setup-dotnet@v4
98 |
99 | # Publish all NuGet packages to NuGet.org
100 | # Use --skip-duplicate to prevent errors if a package with the same version already exists.
101 | # If you retry a failed workflow, already published packages will be skipped without error.
102 | - name: Publish NuGet package
103 | run: |
104 | foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
105 | dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
106 | }
107 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/Boot/Boot.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 | using Serilog;
5 |
6 | namespace Boot;
7 |
8 | public class Boot
9 | {
10 | public Boot(Stream fileStream)
11 | {
12 | const int expectedSectorSig = 0xaa55;
13 |
14 | var rawBytes = new byte[512];
15 | fileStream.Read(rawBytes, 0, 512);
16 |
17 | SectorSignature = BitConverter.ToUInt16(rawBytes, 510);
18 |
19 | if (SectorSignature != expectedSectorSig)
20 | {
21 | Log.Warning(
22 | "Expected signature (0x55 0xAA) not found at offset 0x1FE. Value found: {SectorSignature}",
23 | GetSectorSignature());
24 | }
25 |
26 | BootEntryPoint = $"0x{rawBytes[0]:X2} 0x{rawBytes[1]:X2} 0x{rawBytes[2]:X2}";
27 |
28 | FileSystemSignature = Encoding.ASCII.GetString(rawBytes, 3, 8);
29 |
30 | BytesPerSector = BitConverter.ToInt16(rawBytes, 11);
31 | SectorsPerCluster = rawBytes[13];
32 |
33 | ReservedSectors = BitConverter.ToInt16(rawBytes, 14);
34 | NumberOfFaTs = rawBytes[16];
35 |
36 | RootDirectoryEntries = BitConverter.ToInt16(rawBytes, 17);
37 | TotalNumberOfSectors16 = BitConverter.ToInt16(rawBytes, 19);
38 |
39 | MediaDescriptor = rawBytes[21];
40 |
41 | SectorsPerFat = BitConverter.ToInt16(rawBytes, 22);
42 |
43 | SectorsPerTrack = BitConverter.ToInt16(rawBytes, 24);
44 | NumberOfHeads = BitConverter.ToInt16(rawBytes, 26);
45 | NumberOfHiddenSectors = BitConverter.ToInt32(rawBytes, 28);
46 | TotalNumberOfSectors = BitConverter.ToInt32(rawBytes, 32);
47 |
48 | DiskUnitNumber = rawBytes[36];
49 | UnknownFlags = rawBytes[37];
50 | BpbVersionSignature = rawBytes[38];
51 | UnknownReserved = rawBytes[39];
52 |
53 | TotalSectors = BitConverter.ToInt64(rawBytes, 40);
54 | MftClusterBlockNumber = BitConverter.ToInt64(rawBytes, 48);
55 | MirrorMftClusterBlockNumber = BitConverter.ToInt64(rawBytes, 56);
56 |
57 | var clusterSize = BytesPerSector * SectorsPerCluster;
58 |
59 | var mftEntrySize = rawBytes[64];
60 |
61 | MftEntrySize = GetSizeAsBytes(mftEntrySize, clusterSize);
62 |
63 | var indexEntrySize = rawBytes[68];
64 |
65 | IndexEntrySize = GetSizeAsBytes(indexEntrySize, clusterSize);
66 |
67 | VolumeSerialNumberRaw = BitConverter.ToInt64(rawBytes, 72);
68 |
69 | Checksum = BitConverter.ToInt32(rawBytes, 80);
70 | }
71 |
72 | public string BootEntryPoint { get; }
73 | public string FileSystemSignature { get; }
74 |
75 | public int BytesPerSector { get; }
76 | public int SectorSignature { get; }
77 | public int SectorsPerCluster { get; }
78 |
79 | ///
80 | /// Not used by NTFS
81 | ///
82 | public int ReservedSectors { get; }
83 |
84 | ///
85 | /// Not used by NTFS
86 | ///
87 | public int NumberOfFaTs { get; }
88 |
89 | ///
90 | /// Not used by NTFS
91 | ///
92 | public int RootDirectoryEntries { get; }
93 |
94 | public int TotalNumberOfSectors16 { get; }
95 |
96 | public byte MediaDescriptor { get; }
97 |
98 | ///
99 | /// Not used by NTFS
100 | ///
101 | public int SectorsPerFat { get; }
102 |
103 | ///
104 | /// Not used by NTFS
105 | ///
106 | public int SectorsPerTrack { get; }
107 |
108 | ///
109 | /// Not used by NTFS
110 | ///
111 | public int NumberOfHeads { get; }
112 |
113 | ///
114 | /// Not used by NTFS
115 | ///
116 | public int NumberOfHiddenSectors { get; }
117 |
118 | ///
119 | /// Not used by NTFS
120 | ///
121 | public int TotalNumberOfSectors { get; }
122 |
123 | ///
124 | /// Not used by NTFS
125 | ///
126 | public byte DiskUnitNumber { get; }
127 |
128 | ///
129 | /// Not used by NTFS
130 | ///
131 | public byte UnknownFlags { get; }
132 |
133 | ///
134 | /// Not used by NTFS
135 | ///
136 | public byte BpbVersionSignature { get; }
137 |
138 | ///
139 | /// Not used by NTFS
140 | ///
141 | public byte UnknownReserved { get; }
142 |
143 | public long TotalSectors { get; }
144 | public long MftClusterBlockNumber { get; }
145 | public long MirrorMftClusterBlockNumber { get; }
146 |
147 | ///
148 | /// As bytes
149 | ///
150 | public int MftEntrySize { get; }
151 |
152 | ///
153 | /// As bytes
154 | ///
155 | public int IndexEntrySize { get; }
156 |
157 | ///
158 | /// Use GetVolumeSerialNumber() to convert to different forms
159 | ///
160 | public long VolumeSerialNumberRaw { get; }
161 |
162 | ///
163 | /// Not used by NTFS
164 | ///
165 | public int Checksum { get; }
166 |
167 | public string DecodeMediaDescriptor()
168 | {
169 | var desc = new StringBuilder();
170 |
171 | var mdBits = Convert.ToString(MediaDescriptor, 2);
172 |
173 | switch (mdBits[0])
174 | {
175 | case '0':
176 | desc.Append("Single-sided");
177 | break;
178 | default:
179 | desc.Append("Double-sided");
180 | break;
181 | }
182 |
183 | switch (mdBits[1])
184 | {
185 | case '0':
186 | desc.Append(", 9 sectors per track");
187 | break;
188 | default:
189 | desc.Append(", 8 sectors per track");
190 | break;
191 | }
192 |
193 | switch (mdBits[2])
194 | {
195 | case '0':
196 | desc.Append(", 80 tracks");
197 | break;
198 | default:
199 | desc.Append(", 40 tracks");
200 | break;
201 | }
202 |
203 | switch (mdBits[3])
204 | {
205 | case '0':
206 | desc.Append(", Fixed disc");
207 | break;
208 | default:
209 | desc.Append(", Removable disc");
210 | break;
211 | }
212 |
213 | return desc.ToString();
214 | }
215 |
216 | public string GetSectorSignature()
217 | {
218 | var b = BitConverter.GetBytes(SectorSignature);
219 | return $"{b[0]:X2} {b[1]:X2}";
220 | }
221 |
222 | public string GetVolumeSerialNumber(bool as32Bit = false, bool reverse = false)
223 | {
224 | var b = BitConverter.GetBytes(VolumeSerialNumberRaw);
225 |
226 | var sn = string.Empty;
227 |
228 | if (as32Bit)
229 | {
230 | if (reverse)
231 | {
232 | for (var i = 3; i > -1; i--)
233 | {
234 | sn = $"{sn} {b[i]:X2}";
235 | }
236 | }
237 | else
238 | {
239 | for (var i = 0; i < 4; i++)
240 | {
241 | sn = $"{sn} {b[i]:X2}";
242 | }
243 | }
244 |
245 | return sn.Trim();
246 | }
247 |
248 | for (var i = 0; i < 8; i++)
249 | {
250 | sn = $"{sn} {b[i]:X2}";
251 | }
252 |
253 | return sn.Trim();
254 | }
255 |
256 | private static int GetSizeAsBytes(byte size, int clusterSize)
257 | {
258 | if (size <= 127)
259 | {
260 | return size * clusterSize;
261 | }
262 |
263 | return (int)Math.Pow(2, 256 - size);
264 | }
265 | }
--------------------------------------------------------------------------------
/Boot/Boot.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 | MIT
5 | 10
6 | Boot parser
7 | Eric R. Zimmerman
8 | Eric R. Zimmerman
9 | https://github.com/EricZimmerman/MFT
10 | https://github.com/EricZimmerman/MFT
11 | 1.5.1
12 |
13 | $MFT, $Boot, usn, $J, $I30, NTFS
14 | README.md
15 | icon.png
16 | True
17 |
18 | $(NoWarn);CS1591
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | all
27 | runtime; build; native; contentfiles; analyzers; buildtransitive
28 |
29 |
30 | all
31 | runtime; build; native; contentfiles; analyzers; buildtransitive
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/Boot/BootFile.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace Boot;
4 |
5 | public static class BootFile
6 | {
7 | public static Boot Load(string bootFilePath)
8 | {
9 | if (File.Exists(bootFilePath) == false)
10 | {
11 | throw new FileNotFoundException($"'{bootFilePath}' not found");
12 | }
13 |
14 | using var fs = new FileStream(bootFilePath, FileMode.Open, FileAccess.Read);
15 | return new Boot(fs);
16 | }
17 | }
--------------------------------------------------------------------------------
/I30/I30.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using MFT;
5 | using MFT.Other;
6 | using Serilog;
7 |
8 | namespace I30;
9 |
10 | public class I30
11 | {
12 | public I30(Stream fileStream)
13 | {
14 | var pageSize = 0x1000;
15 |
16 | var sig = 0x58444E49;
17 |
18 | Entries = new List();
19 |
20 | var pages = new List();
21 |
22 | using (var br = new BinaryReader(fileStream))
23 | {
24 | while (br.BaseStream.Position < br.BaseStream.Length)
25 | {
26 | pages.Add(br.ReadBytes(pageSize));
27 | }
28 | }
29 |
30 | var uniqueSlackEntryMd5s = new HashSet();
31 |
32 | var pageNumber = 0;
33 | foreach (var page in pages)
34 | {
35 | //INDX pages are 4096 bytes each, so process them accordingly
36 |
37 | Log.Debug("Processing page 0x{PageNumber:X}", pageNumber);
38 |
39 | using (var br = new BinaryReader(new MemoryStream(page)))
40 | {
41 | var sigActual = br.ReadInt32();
42 |
43 | if (sigActual == 0x00)
44 | {
45 | //empty page
46 | Log.Warning("Empty page found at offset {Offset}. Skipping", $"0x{pageNumber * 0x1000:X}");
47 | pageNumber++;
48 | continue;
49 | }
50 |
51 | if (sig != sigActual)
52 | {
53 | throw new Exception("Invalid header! Expected 'INDX' Signature");
54 | }
55 |
56 | var fixupOffset = br.ReadInt16();
57 |
58 | var numFixupPairs = br.ReadInt16();
59 |
60 | var logFileSequenceNumber = br.ReadInt64();
61 |
62 | var virtualClusterNumber = br.ReadInt64();
63 |
64 | var dataStartOffset = br.ReadInt32();
65 | var dataSize = br.ReadInt32();
66 | var dataSizeAllocated = br.ReadInt32();
67 |
68 | var isLeafNode = br.ReadInt32() == 0; //this gets us by padding too
69 |
70 | var fixupTotalLength = numFixupPairs * 2;
71 |
72 | var fixupBuffer = new byte[fixupTotalLength];
73 |
74 | fixupBuffer = br.ReadBytes(fixupTotalLength);
75 |
76 | while (br.BaseStream.Position % 8 != 0)
77 | {
78 | br.ReadByte(); //gets us past padding
79 | }
80 |
81 | //since we need to change bytes for the index entries based on fixup, get an array of those bytes
82 |
83 | var rawBytes = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
84 |
85 | var fixupData = new FixupData(fixupBuffer);
86 |
87 | //fixup verification
88 | var counter =
89 | 512 - dataStartOffset -
90 | 0x18; //datastartOffset is relative, so we need to account for where it begins, at 0x18
91 | foreach (var bytese in fixupData.FixupActual)
92 | {
93 | //adjust the offset to where we need to check
94 | var fixupOffset1 = counter - 2;
95 |
96 | var expected = BitConverter.ToInt16(rawBytes, fixupOffset1);
97 | if (expected != fixupData.FixupExpected)
98 | {
99 | Log.Warning(
100 | "Fixup values do not match at 0x{FixupOffset1:X}. Expected: 0x{FixupExpected:X2}, actual: 0x{Expected:X2}",
101 | fixupOffset1, fixupData.FixupExpected, expected);
102 | }
103 |
104 | //replace fixup expected with actual bytes. bytese has actual replacement values in it.
105 | Buffer.BlockCopy(bytese, 0, rawBytes, fixupOffset1, 2);
106 |
107 | counter += 512;
108 | }
109 |
110 | //rawbytes contains the data from the current page we need to parse to get to indexes
111 | //datasize includes startoffset plus fixup, etc, so subtract data offset from size for the active index allocations
112 | //valid data is allocated - dataoffset
113 | //after that is slack
114 |
115 | var activeSpace = new byte[dataSize - dataStartOffset];
116 | Buffer.BlockCopy(rawBytes, 0, activeSpace, 0, activeSpace.Length);
117 |
118 | var slackSpace = new byte[rawBytes.Length - activeSpace.Length];
119 | Buffer.BlockCopy(rawBytes, dataSize - dataStartOffset, slackSpace, 0, slackSpace.Length);
120 |
121 | // File.WriteAllBytes($@"C:\temp\{pageNumber}_slack.bin",slackSpace);
122 |
123 | //absolute offset is page # * 0x1000 + 0x18 + datastartoffset
124 | //for slack, add activespace.len
125 |
126 | using (var binaryReader = new BinaryReader(new MemoryStream(activeSpace)))
127 | {
128 | while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
129 | {
130 | var absoluteOffset = pageNumber * 0x1000 + 0x18 + dataStartOffset +
131 | binaryReader.BaseStream.Position;
132 |
133 | Log.Verbose(
134 | "IN ACTIVE LOOP: Absolute offset: 0x{AbsoluteOffset:X} brActive.BaseStream.Position: 0x{Position:X}",
135 | absoluteOffset, binaryReader.BaseStream.Position);
136 |
137 | binaryReader.ReadInt64(); //mft info
138 | var indexSize = binaryReader.ReadInt16();
139 | binaryReader.BaseStream.Seek(-10, SeekOrigin.Current); //go back to start of the index data
140 |
141 | var indxBuffer = binaryReader.ReadBytes(indexSize);
142 |
143 | var ie = new IndexEntryI30(indxBuffer, absoluteOffset, pageNumber, false);
144 |
145 | if (ie.MftReferenceSelf.MftEntryNumber == 0)
146 | {
147 | continue;
148 | }
149 |
150 | //its ok
151 | Log.Debug("{Ie}", ie);
152 | Entries.Add(ie);
153 | }
154 | }
155 |
156 | Log.Verbose("IN SLACK LOOP for {Page", pageNumber);
157 | var slackAbsOffset = pageNumber * 0x1000 + 0x18 + dataStartOffset +
158 | activeSpace.Length;
159 |
160 | var slackIe = FileRecord.GetSlackFileEntries(slackSpace, pageNumber, slackAbsOffset,0);
161 |
162 | //var h = GetUnicodeHits(slackSpace);
163 |
164 | foreach (var indexEntry in slackIe)
165 | {
166 | if (uniqueSlackEntryMd5s.Contains(indexEntry.Md5))
167 | {
168 | Log.Debug("Discarding duplicate slack buffer with MD5 {Md5}", indexEntry.Md5);
169 | continue;
170 | }
171 |
172 | Entries.Add(indexEntry);
173 |
174 | uniqueSlackEntryMd5s.Add(indexEntry.Md5);
175 |
176 | }
177 | }
178 |
179 | pageNumber += 1;
180 | }
181 | }
182 |
183 |
184 | public List Entries { get; }
185 |
186 |
187 |
188 | }
189 |
190 |
--------------------------------------------------------------------------------
/I30/I30.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 | https://github.com/EricZimmerman/MFT
5 | https://github.com/EricZimmerman/MFT
6 | $I30 parser
7 | 10
8 |
9 | Eric R. Zimmerman
10 | Eric R. Zimmerman
11 | MIT
12 | 1.5.1
13 |
14 | $MFT, $Boot, usn, $J, $I30, NTFS
15 | README.md
16 | icon.png
17 | True
18 |
19 | $(NoWarn);CS1591
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | all
30 | runtime; build; native; contentfiles; analyzers; buildtransitive
31 |
32 |
33 | all
34 | runtime; build; native; contentfiles; analyzers; buildtransitive
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/I30/I30File.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace I30;
4 |
5 | public static class I30File
6 | {
7 | public static I30 Load(string indexFile)
8 | {
9 | if (File.Exists(indexFile) == false)
10 | {
11 | throw new FileNotFoundException($"'{indexFile}' not found");
12 | }
13 |
14 | using var fs = new FileStream(indexFile, FileMode.Open, FileAccess.Read);
15 | return new I30(fs);
16 | }
17 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Eric Zimmerman
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/LogFile/FixupData.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace LogFile;
6 |
7 | public class FixupData
8 | {
9 | public FixupData(byte[] fixupDataRaw)
10 | {
11 | FixupExpected = BitConverter.ToInt16(fixupDataRaw, 0);
12 | FixupActual = new List();
13 |
14 | var index = 2;
15 |
16 | while (index < fixupDataRaw.Length)
17 | {
18 | var b = new byte[2];
19 | Buffer.BlockCopy(fixupDataRaw, index, b, 0, 2);
20 | FixupActual.Add(b);
21 | index += 2;
22 | }
23 | }
24 |
25 | ///
26 | /// the data expected at the end of each 512 byte chunk
27 | ///
28 | public short FixupExpected { get; }
29 |
30 | ///
31 | /// The actual bytes to be overlayed before processing a record, in order
32 | ///
33 | public List FixupActual { get; }
34 |
35 | public override string ToString()
36 | {
37 | var sb = new StringBuilder();
38 |
39 | foreach (var bytese in FixupActual)
40 | {
41 | var bb = BitConverter.ToString(bytese);
42 | sb.Append($"{bb}|");
43 | }
44 |
45 | var fua = sb.ToString().TrimEnd('|');
46 |
47 | return $"Expected: {BitConverter.ToString(BitConverter.GetBytes(FixupExpected))} Fixup Actual: {fua}";
48 | }
49 | }
--------------------------------------------------------------------------------
/LogFile/LogFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using Serilog;
5 |
6 | namespace LogFile;
7 |
8 | public class LogFile
9 | {
10 | private const int PageSize = 0x1000;
11 |
12 | private const int RstrSig = 0x52545352;
13 | private const int RcrdSig = 0x44524352;
14 | private const int ChkdSig = 0x52545351;
15 |
16 | public static uint LastOffset;
17 |
18 | public LogFile(Stream fileStream)
19 | {
20 | //preliminary sig check to get us started
21 | const int sig = 0x52545352;
22 |
23 | var br = new BinaryReader(fileStream);
24 |
25 | var index = 0x0;
26 | var sigCheck = br.ReadInt32(); // BitConverter.ToInt32(rawBytes, index);
27 |
28 | if (sig != sigCheck)
29 | {
30 | throw new Exception("Invalid header! Expected 'RSTR' Signature.");
31 | }
32 |
33 | br.BaseStream.Seek(0, SeekOrigin.Begin); //reset
34 |
35 | NormalPageArea = new List();
36 |
37 | while (fileStream.Position < fileStream.Length)
38 | {
39 | LastOffset = (uint)index;
40 |
41 | var buff = br.ReadBytes(PageSize);
42 |
43 | Log.Debug("Processing log page at offset 0x{Index:X}", index);
44 |
45 | var sigActual = BitConverter.ToInt32(buff, 0);
46 |
47 | switch (sigActual)
48 | {
49 | case RstrSig:
50 | var lprstr = new LogPageRstr(buff, index);
51 |
52 | Log.Information("{Lprstr}", lprstr);
53 |
54 | if (index == 0)
55 | {
56 | PrimaryRstrPage = lprstr;
57 | }
58 | else
59 | {
60 | SecondaryRstrPage = lprstr;
61 | }
62 |
63 | break;
64 | case RcrdSig:
65 | //
66 | LogPageRcrd lprcrd = null;
67 |
68 | //loop thru all pages, then walk thru again, grouping into chunks based on PageCount
69 | //then process each chunk with each page inside
70 |
71 | try
72 | {
73 | lprcrd = new LogPageRcrd(buff, index);
74 | }
75 | catch (Exception e)
76 | {
77 | Console.WriteLine(e);
78 | }
79 |
80 |
81 | if (index == 0x2000)
82 | {
83 | BufferPrimary = lprcrd;
84 | }
85 | else if (index == 0x3000)
86 | {
87 | BufferSecondary = lprcrd;
88 | }
89 | else
90 | {
91 | NormalPageArea.Add(lprcrd);
92 | }
93 |
94 |
95 | break;
96 | // case chkd_sig: //havent seen one of these to test
97 | // PageType = PageTypes.Chkd;
98 | // break;
99 | default:
100 | throw new Exception(
101 | $"Invalid signature at offset 0x{index:X}! Expected 'RCRD|RSTR|CHKD' signature.");
102 | }
103 |
104 |
105 | index += PageSize;
106 | }
107 | }
108 |
109 | public List NormalPageArea { get; }
110 | public LogPageRstr PrimaryRstrPage { get; }
111 | public LogPageRstr SecondaryRstrPage { get; }
112 |
113 | public LogPageRcrd BufferPrimary { get; }
114 | public LogPageRcrd BufferSecondary { get; }
115 | }
--------------------------------------------------------------------------------
/LogFile/LogFile.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 | https://github.com/EricZimmerman/MFT
5 | https://github.com/EricZimmerman/MFT
6 | Eric R. Zimmerman
7 | 10
8 | Eric R. Zimmerman
9 | $LogFile parser
10 | MIT
11 | 1.5.1
12 |
13 | $MFT, $Boot, usn, $J, $I30, NTFS
14 | README.md
15 | icon.png
16 | True
17 |
18 | $(NoWarn);CS1591
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | all
28 | runtime; build; native; contentfiles; analyzers; buildtransitive
29 |
30 |
31 | all
32 | runtime; build; native; contentfiles; analyzers; buildtransitive
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/LogFile/LogPageRcrd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using Serilog;
5 |
6 | namespace LogFile;
7 |
8 | public enum PageRecordFlag
9 | {
10 | MultiplePages = 0x1,
11 | NoRedo = 0x2,
12 | NoUndo = 0x4
13 | }
14 |
15 | public class LogPageRcrd
16 | {
17 | private const int RcrdSig = 0x44524352;
18 |
19 | public LogPageRcrd(byte[] rawBytes, int offset)
20 | {
21 | var index = 0x0;
22 | var sigCheck = BitConverter.ToInt32(rawBytes, index);
23 |
24 | if (sigCheck != RcrdSig)
25 | {
26 | throw new Exception("Invalid signature! Expected 'RCRD' signature.");
27 | }
28 |
29 | Offset = offset;
30 |
31 | index += 4;
32 |
33 | var fixupOffset = BitConverter.ToInt16(rawBytes, index);
34 | index += 2;
35 | var numFixupPairs = BitConverter.ToInt16(rawBytes, index);
36 | index += 2;
37 |
38 | LastLogFileSequenceNumber = BitConverter.ToInt64(rawBytes, index);
39 | index += 8;
40 | Flags = BitConverter.ToInt32(rawBytes, index);
41 | index += 4;
42 |
43 | PageCount = BitConverter.ToInt16(rawBytes, index);
44 | index += 2;
45 |
46 | PagePosition = BitConverter.ToInt16(rawBytes, index);
47 | index += 2;
48 |
49 | FreeSpaceOffset = BitConverter.ToInt16(rawBytes, index);
50 | index += 2;
51 |
52 | var wordAlign = BitConverter.ToInt16(rawBytes, index);
53 | index += 2;
54 |
55 | var dwordAlign = BitConverter.ToInt32(rawBytes, index);
56 | index += 4;
57 |
58 | LastEndLogFileSequenceNumber = BitConverter.ToInt64(rawBytes, index);
59 | index += 8;
60 |
61 | var fixupTotalLength = numFixupPairs * 2;
62 |
63 | var fixupBuffer = new byte[fixupTotalLength];
64 | Buffer.BlockCopy(rawBytes, fixupOffset, fixupBuffer, 0, fixupTotalLength);
65 |
66 | var fixupData = new FixupData(fixupBuffer);
67 |
68 | var fixupOk = true;
69 |
70 | //fixup verification
71 | var counter = 512;
72 | foreach (var bytese in fixupData.FixupActual)
73 | {
74 | //adjust the offset to where we need to check
75 | var fixupOffset1 = counter - 2;
76 |
77 | var expected = BitConverter.ToInt16(rawBytes, fixupOffset1);
78 | if (expected != fixupData.FixupExpected)
79 | {
80 | fixupOk = false;
81 | Log.Warning(
82 | "Fixup values do not match at 0x{FixupOffset:X}. Expected: 0x{FixupExpected:X2}, actual: 0x{Expected:X2}",
83 | fixupOffset1, fixupData.FixupExpected, expected);
84 | }
85 |
86 | //replace fixup expected with actual bytes. bytese has actual replacement values in it.
87 | Buffer.BlockCopy(bytese, 0, rawBytes, fixupOffset1, 2);
88 |
89 | counter += 512;
90 | }
91 |
92 | index += fixupTotalLength;
93 |
94 | while (index % 8 != 0)
95 | {
96 | index += 1;
97 | }
98 |
99 | //header is 0x58 bytes, so go past it
100 |
101 | // index = 0x58;
102 |
103 | Log.Information(
104 | " LastLogFileSequenceNumber: 0x{LastLogFileSequenceNumber:X} Flags: {Flags} PageCount: 0x{PageCount:X} PagePosition: 0x{PagePosition:X} Free space offset: 0x{FreeSpaceOffset:X} " +
105 | "LastEndLogFileSequenceNumber: 0x{LastEndLogFileSequenceNumber:X} " +
106 | "LastLogFileSequenceNumber==LastEndLogFileSequenceNumber: {LastEndLogFileSequenceNumber==LastLogFileSequenceNumber}",
107 | LastLogFileSequenceNumber, Flags, PageCount, PagePosition, FreeSpaceOffset, LastEndLogFileSequenceNumber,
108 | LastEndLogFileSequenceNumber == LastLogFileSequenceNumber);
109 |
110 | //record is 0x30 + clientDatalen long
111 |
112 |
113 | Records = new List();
114 |
115 | while (index < rawBytes.Length)
116 | {
117 | var so = index;
118 | var thisLsn = BitConverter.ToInt64(rawBytes, index);
119 | var prevLsn = BitConverter.ToInt64(rawBytes, index + 8);
120 | var clientUndoLsn = BitConverter.ToInt64(rawBytes, index + 16);
121 |
122 | // _logger.Info($" this: {thisLsn:X} prev: {prevLsn:X} undo: {clientUndoLsn:X}");
123 | var clientDataLen = BitConverter.ToInt32(rawBytes, index + 24);
124 | var buff = new byte[clientDataLen + 0x30];
125 | Buffer.BlockCopy(rawBytes, index, buff, 0, buff.Length);
126 |
127 | var rec = new Record(buff);
128 |
129 | Records.Add(rec);
130 |
131 | index += buff.Length;
132 |
133 | Log.Information(" Record: {Record}", rec);
134 |
135 | if (thisLsn == LastEndLogFileSequenceNumber)
136 | {
137 | Log.Warning("At last LSN in this page (0x{ThisLsn:X}). Found it at offset 0x{So:X}\r\n", thisLsn, so);
138 | break;
139 | }
140 | }
141 |
142 | //Debug.WriteLine($"at abs offset: 0x{(offset+index):X}, RCRD Offset: 0x{Offset:X}");
143 | }
144 |
145 | public long LastLogFileSequenceNumber { get; }
146 | public int Flags { get; }
147 | public short PageCount { get; }
148 | public short PagePosition { get; }
149 | public short FreeSpaceOffset { get; }
150 | public long LastEndLogFileSequenceNumber { get; }
151 |
152 | public int Offset { get; }
153 |
154 | public List Records { get; }
155 | }
156 |
157 | public enum RecTypeFlag
158 | {
159 | RestRecord = 0x1,
160 | CheckPointRecord = 0x02
161 | }
162 |
163 | public enum RecordHeaderFlag
164 | {
165 | ClientRecord = 0x1,
166 | ClientRestartArea = 0x2
167 | }
168 |
169 | public enum OpCode
170 | {
171 | Noop = 0x00,
172 | CompensationlogRecord = 0x01,
173 | InitializeFileRecordSegment = 0x02,
174 | DeallocateFileRecordSegment = 0x03,
175 | WriteEndofFileRecordSegement = 0x04,
176 | CreateAttribute = 0x05,
177 | DeleteAttribute = 0x06,
178 | UpdateResidentValue = 0x07,
179 | UpdataeNonResidentValue = 0x08,
180 | UpdateMappingPairs = 0x09,
181 | DeleteDirtyClusters = 0x0A,
182 | SetNewAttributeSizes = 0x0B,
183 | AddIndexEntryRoot = 0x0C,
184 | DeleteIndexEntryRoot = 0x0D,
185 | AddIndexEntryAllocation = 0x0E,
186 | DeleteIndexEntryAllocation = 0x0F,
187 | WriteEndOfIndexBuffer = 0x10,
188 | SetIndexEntryVcnRoot = 0x11,
189 | SetIndexEntryVcnAllocation = 0x12,
190 | UpdateFileNameRoot = 0x13,
191 | UpdateFileNameAllocation = 0x14,
192 | SetBitsInNonresidentBitMap = 0x15,
193 | ClearBitsInNonresidentBitMap = 0x16,
194 | HotFix = 0x17,
195 | EndTopLevelAction = 0x18,
196 | PrepareTransaction = 0x19,
197 | CommitTransaction = 0x1A,
198 | ForgetTransaction = 0x1B,
199 | OpenNonresidentAttribute = 0x1C,
200 | OpenAttributeTableDump = 0x1D,
201 | AttributeNamesDump = 0x1E,
202 | DirtyPageTableDump = 0x1F,
203 | TransactionTableDump = 0x20,
204 | UpdateRecordDataRoot = 0x21,
205 | UpdateRecordDataAllocation = 0x22,
206 | UpdateRelativeDataIndex = 0x23,
207 | UpdateRelativeDataAllocation = 0x24,
208 | ZeroEndOfFileRecord = 0x25
209 | }
210 |
211 | public class Record
212 | {
213 | public Record(byte[] rawBytes)
214 | {
215 | var br = new BinaryReader(new MemoryStream(rawBytes));
216 |
217 | ThisLsn = br.ReadInt64();
218 | PreviousLsn = br.ReadInt64();
219 | UndoLsn = br.ReadInt64();
220 |
221 | DataLength = br.ReadInt32();
222 | ClientId = br.ReadInt32();
223 | RecordType = (RecTypeFlag)br.ReadInt32();
224 | TransactionId = br.ReadInt32();
225 |
226 | Flags = (RecordHeaderFlag)br.ReadInt16();
227 | RedoOpCode = (OpCode)br.ReadInt16();
228 | UndoOpCode = (OpCode)br.ReadInt16();
229 | RedoOffset = br.ReadInt16();
230 | RedoLength = br.ReadInt16();
231 | UndoOffset = br.ReadInt16();
232 | UndoLength = br.ReadInt16();
233 | TargetAtrribute = br.ReadInt16();
234 | LcnToFollow = br.ReadInt16();
235 | RecordOffset = br.ReadInt16();
236 | AttributeOffset = br.ReadInt16();
237 | ClusterBlockOffset = br.ReadInt16();
238 | TargetblockSize = br.ReadInt16();
239 |
240 | TargetVcn = br.ReadInt64();
241 |
242 | // var l = LogManager.GetCurrentClassLogger();
243 | // l.Info($"This LSN: 0x{br.ReadInt64():X}"); //this
244 | // l.Info($"prev LSN: 0x{br.ReadInt64():X}"); //this
245 | // l.Info($"undo LSN: 0x{br.ReadInt64():X}"); //this
246 | //
247 | // l.Info($"data len: 0x{br.ReadInt32():X}"); //this
248 | // l.Info($"clientid: 0x{br.ReadInt32():X}"); //this
249 | // l.Info($"rec type: 0x{br.ReadInt32():X}"); //this
250 | // l.Info($"trans id: 0x{br.ReadInt32():X}"); //this
251 | //
252 | // l.Info($"flags: 0x{br.ReadInt16():X}"); //this
253 | //
254 | // br.ReadBytes(6); //reserved
255 | //
256 | // l.Info($"redo op: 0x{br.ReadInt16():X}"); //this
257 | // l.Info($"undo op: 0x{br.ReadInt16():X}"); //this
258 | // l.Info($"redo offset: 0x{br.ReadInt16():X}"); //this
259 | // l.Info($"redo len:0x {br.ReadInt16():X}"); //this
260 | // l.Info($"undo offset: 0x{br.ReadInt16():X}"); //this
261 | // l.Info($"undo len: 0x{br.ReadInt16():X}"); //this
262 | // l.Info($"target attr: 0x{br.ReadInt16():X}"); //this
263 | // l.Info($"LCN to follow: 0x{br.ReadInt16():X}"); //this
264 | // l.Info($"record offset: 0x{br.ReadInt16():X}"); //this
265 | // l.Info($"attr offset: 0x{br.ReadInt16():X}"); //this
266 | // l.Info($"clusterblockOffset 0x{br.ReadInt16():X}"); //this
267 | // l.Info($"TargetblockSize 0x{br.ReadInt16():X}"); //this
268 | //
269 | //
270 | // l.Info($"target vcn: 0x{br.ReadInt64():X}"); //this
271 |
272 | //lcns are here
273 |
274 | // var ClusterNums = new List();
275 | //
276 | // for (int i = 0; i < LcnToFollow; i++)
277 | // {
278 | // var lc = br.ReadInt64();
279 | // ClusterNums.Add(lc);
280 | // }
281 | }
282 |
283 | public long ThisLsn { get; }
284 | public long PreviousLsn { get; }
285 | public long UndoLsn { get; }
286 |
287 | public int DataLength { get; }
288 | public int ClientId { get; }
289 | public RecTypeFlag RecordType { get; }
290 | public int TransactionId { get; }
291 | public RecordHeaderFlag Flags { get; }
292 | public OpCode RedoOpCode { get; }
293 | public OpCode UndoOpCode { get; }
294 | public short RedoOffset { get; }
295 | public short RedoLength { get; }
296 | public short UndoOffset { get; }
297 | public short UndoLength { get; }
298 | public short TargetAtrribute { get; }
299 | public short LcnToFollow { get; }
300 | public short RecordOffset { get; }
301 | public short AttributeOffset { get; }
302 | public short ClusterBlockOffset { get; }
303 | public short TargetblockSize { get; }
304 | public long TargetVcn { get; }
305 |
306 | public override string ToString()
307 | {
308 | return
309 | $"ThisLsn: 0x{ThisLsn:X} PrevLsn: 0x{PreviousLsn:X} UndoLsn: 0x{UndoLsn:X} size: 0x{DataLength:X} Client id: 0x{ClientId:X} Rec type: {RecordType} TransId: 0x{TransactionId:X} Flags: {Flags} Redo code: {RedoOpCode} Undo code: {UndoOpCode} redo offset: 0x{RedoOffset:X} redo len: 0x{RedoLength:X} undo offset: 0x{UndoOffset:X} undo len: 0x{UndoLength:X} target attr: 0x{TargetAtrribute:X} LsnToFollow: 0x{LcnToFollow:X} RecordOffset: 0x{RecordOffset:X} attr offset: 0x{AttributeOffset:X} cluster block offset: 0x{ClusterBlockOffset:X} target block size: 0x{TargetblockSize:X} target vcn: 0x{TargetVcn:X}";
310 | }
311 | }
--------------------------------------------------------------------------------
/LogFile/LogPageRstr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 | using Serilog;
6 |
7 | namespace LogFile;
8 |
9 | public enum RestartFlag
10 | {
11 | None = 0x0,
12 | OneByOne = 0x1,
13 | NewArea = 0x2
14 | }
15 |
16 | public class LogPageRstr
17 | {
18 | private const int RstrSig = 0x52545352;
19 | private const int ChkdSig = 0x52545351;
20 | public long CheckDiskLsn;
21 | public short ClientArrayOffset;
22 | public short ClientFreeList;
23 | public short ClientInUseList;
24 | public long CurrentLsn;
25 | public RestartFlag Flags;
26 | public int LastLsnDataLen;
27 | public short LogClientCount;
28 | public long LogFileSize;
29 | public short LogPageDataOffset;
30 | public int LogPageSize;
31 | public short MajorFormatVersion;
32 | public short MinorFormatVersion;
33 | public short RecordHeaderLen;
34 | public short RestartAreaLen;
35 | public short RestartOffset;
36 | public int RevisionNumber;
37 | public int SeqNumBits;
38 | public int SystemPageSize;
39 |
40 | public LogPageRstr(byte[] rawBytes, int offset)
41 | {
42 | var index = 0x0;
43 |
44 | var sigCheck = BitConverter.ToInt32(rawBytes, index);
45 |
46 | if (sigCheck != RstrSig && sigCheck != ChkdSig)
47 | {
48 | throw new Exception("Invalid signature! Expected 'RSTR|CHKD' signature.");
49 | }
50 |
51 | Offset = offset;
52 |
53 | index += 4;
54 |
55 | var fixupOffset = BitConverter.ToInt16(rawBytes, index);
56 | index += 2;
57 | var numFixupPairs = BitConverter.ToInt16(rawBytes, index);
58 | index += 2;
59 |
60 | CheckDiskLsn = BitConverter.ToInt64(rawBytes, index);
61 | index += 8;
62 | SystemPageSize = BitConverter.ToInt32(rawBytes, index);
63 | index += 4;
64 |
65 | LogPageSize = BitConverter.ToInt32(rawBytes, index);
66 | index += 4;
67 |
68 | RestartOffset = BitConverter.ToInt16(rawBytes, index);
69 | index += 2;
70 |
71 | MinorFormatVersion = BitConverter.ToInt16(rawBytes, index);
72 | index += 2;
73 |
74 | MajorFormatVersion = BitConverter.ToInt16(rawBytes, index);
75 | index += 2;
76 |
77 |
78 | var fixupTotalLength = numFixupPairs * 2;
79 |
80 | var fixupBuffer = new byte[fixupTotalLength];
81 | Buffer.BlockCopy(rawBytes, fixupOffset, fixupBuffer, 0, fixupTotalLength);
82 |
83 | var fixupData = new FixupData(fixupBuffer);
84 |
85 | var fixupOk = true;
86 |
87 | //fixup verification
88 | var counter = 512;
89 | foreach (var bytese in fixupData.FixupActual)
90 | {
91 | //adjust the offset to where we need to check
92 | var fixupOffset1 = counter - 2;
93 |
94 | var expected = BitConverter.ToInt16(rawBytes, fixupOffset1);
95 | if (expected != fixupData.FixupExpected)
96 | {
97 | fixupOk = false;
98 | Log.Warning(
99 | "Fixup values do not match at 0x{FixupOffset1:X}. Expected: 0x{FixupExpected:X2}, actual: 0x{Expected:X2}",
100 | fixupOffset1, fixupData.FixupExpected, expected);
101 | }
102 |
103 | //replace fixup expected with actual bytes. bytese has actual replacement values in it.
104 | Buffer.BlockCopy(bytese, 0, rawBytes, fixupOffset1, 2);
105 |
106 | counter += 512;
107 | }
108 |
109 | index += fixupTotalLength;
110 |
111 | while (index % 8 != 0)
112 | {
113 | index += 1;
114 | }
115 |
116 | CurrentLsn = BitConverter.ToInt64(rawBytes, index);
117 | index += 8;
118 | LogClientCount = BitConverter.ToInt16(rawBytes, index);
119 | index += 2;
120 | ClientFreeList = BitConverter.ToInt16(rawBytes, index);
121 | index += 2;
122 | ClientInUseList = BitConverter.ToInt16(rawBytes, index);
123 | index += 2;
124 | Flags = (RestartFlag)BitConverter.ToInt16(rawBytes, index);
125 | index += 2;
126 | SeqNumBits = BitConverter.ToInt32(rawBytes, index);
127 | index += 4;
128 | RestartAreaLen = BitConverter.ToInt16(rawBytes, index);
129 | index += 2;
130 | ClientArrayOffset = BitConverter.ToInt16(rawBytes, index);
131 | index += 2;
132 | LogFileSize = BitConverter.ToInt64(rawBytes, index);
133 | index += 8;
134 | LastLsnDataLen = BitConverter.ToInt32(rawBytes, index);
135 | index += 4;
136 | RecordHeaderLen = BitConverter.ToInt16(rawBytes, index);
137 | index += 2;
138 | LogPageDataOffset = BitConverter.ToInt16(rawBytes, index);
139 | index += 2;
140 | RevisionNumber = BitConverter.ToInt32(rawBytes, index);
141 |
142 | index = 0x30 + ClientArrayOffset;
143 | ClientRecords = new List();
144 |
145 | for (var i = 0; i < LogClientCount; i++)
146 | {
147 | var buff = new byte[160]; //len of clientRecord
148 |
149 | Buffer.BlockCopy(rawBytes, index, buff, 0, 160);
150 |
151 | var cr = new ClientRecord(buff);
152 | ClientRecords.Add(cr);
153 | index += 160;
154 | }
155 | }
156 |
157 | public int Offset { get; }
158 |
159 | public List ClientRecords { get; }
160 |
161 | public override string ToString()
162 | {
163 | var sb = new StringBuilder();
164 |
165 | sb.Append($"checkDiskLsn: 0x{CheckDiskLsn:X} ");
166 | sb.Append($"systemPageSize: 0x{SystemPageSize:X} ");
167 | sb.Append($"logPageSize: 0x{LogPageSize:X} ");
168 | sb.Append($"restartOffset: 0x{RestartOffset:X} ");
169 | sb.Append($"majorFormatVersion: 0x{MajorFormatVersion:X} ");
170 | sb.Append($"minorFormatVersion: 0x{MinorFormatVersion:X} ");
171 | sb.Append($"currentLsn: 0x{CurrentLsn:X} ");
172 | sb.Append($"logClient: 0x{LogClientCount:X} ");
173 | sb.Append($"ClientFreeList: 0x{ClientFreeList:X} ");
174 | sb.Append($"ClientInUseList: 0x{ClientInUseList:X} ");
175 | sb.Append($"flags: {Flags} ");
176 | sb.Append($"SeqNumBits: 0x{SeqNumBits:X} ");
177 | sb.Append($"RestartAreaLen: 0x{RestartAreaLen:X} ");
178 | sb.Append($"ClientArrayOffset: 0x{ClientArrayOffset:X} ");
179 | sb.Append($"LogFileSize: 0x{LogFileSize:X} ");
180 | sb.Append($"lastLsnDataLen: 0x{LastLsnDataLen:X} ");
181 | sb.Append($"recordHeaderLen: 0x{RecordHeaderLen:X} ");
182 | sb.Append($"LogPageDataOffset: 0x{LogPageDataOffset:X} ");
183 | sb.Append($"revisionNumber: 0x{RevisionNumber:X} ");
184 | sb.AppendLine();
185 |
186 | sb.AppendLine($"Client Records ({ClientRecords.Count:N0})");
187 | foreach (var clientRecord in ClientRecords)
188 | {
189 | sb.AppendLine(clientRecord.ToString());
190 | }
191 |
192 | sb.AppendLine();
193 |
194 | return sb.ToString();
195 | }
196 | }
197 |
198 | public class ClientRecord
199 | {
200 | public ClientRecord(byte[] rawBytes)
201 | {
202 | var br = new BinaryReader(new MemoryStream(rawBytes));
203 |
204 | OldestLsn = br.ReadInt64();
205 | ClientRestartLsn = br.ReadInt64();
206 | PrevClient = br.ReadInt16();
207 | NextClient = br.ReadInt16();
208 | SeqNumber = br.ReadInt16();
209 | br.ReadBytes(6); //skip
210 | var clientNameLen = br.ReadInt32();
211 |
212 | ClientName = Encoding.Unicode.GetString(br.ReadBytes(clientNameLen));
213 | }
214 |
215 | public long OldestLsn { get; }
216 | public long ClientRestartLsn { get; }
217 | public short PrevClient { get; }
218 | public short NextClient { get; }
219 | public short SeqNumber { get; }
220 | public string ClientName { get; }
221 |
222 | public override string ToString()
223 | {
224 | return
225 | $" oldestLsn: 0x{OldestLsn:X} clientRestartLsn: 0x{ClientRestartLsn:X} prevClient: 0x{PrevClient:X} nextClient: 0x{NextClient:X} seqNumber: 0x{SeqNumber:X} ClientName: {ClientName}";
226 | }
227 | }
--------------------------------------------------------------------------------
/LogFile/Log_File.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace LogFile;
4 |
5 | public static class Log_File
6 | {
7 | public static LogFile Load(string logFile)
8 | {
9 | if (File.Exists(logFile) == false)
10 | {
11 | throw new FileNotFoundException($"'{logFile}' not found");
12 | }
13 |
14 | using var fs = new FileStream(logFile, FileMode.Open, FileAccess.Read);
15 | return new LogFile(fs);
16 | }
17 |
18 | public static byte[] ReadAllBytes(this BinaryReader reader)
19 | {
20 | const int bufferSize = 4096;
21 | using var ms = new MemoryStream();
22 | var buffer = new byte[bufferSize];
23 | int count;
24 | while ((count = reader.Read(buffer, 0, buffer.Length)) != 0)
25 | {
26 | ms.Write(buffer, 0, count);
27 | }
28 |
29 | return ms.ToArray();
30 | }
31 | }
--------------------------------------------------------------------------------
/MFT.Test/MFT.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net462;net6.0
4 | 10
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | 17.12.0
22 |
23 |
24 |
25 | 4.3.2
26 |
27 |
28 | 6.0.0
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/MFT.Test/TestFiles/$I30/FirstDelete/$I30:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricZimmerman/MFT/50e4ea636a96359f1d5f0ee0f993802564ff6b86/MFT.Test/TestFiles/$I30/FirstDelete/$I30
--------------------------------------------------------------------------------
/MFT.Test/TestFiles/$I30/SecondDelete/$I30:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricZimmerman/MFT/50e4ea636a96359f1d5f0ee0f993802564ff6b86/MFT.Test/TestFiles/$I30/SecondDelete/$I30
--------------------------------------------------------------------------------
/MFT.Test/TestFiles/$I30/Start/$I30:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricZimmerman/MFT/50e4ea636a96359f1d5f0ee0f993802564ff6b86/MFT.Test/TestFiles/$I30/Start/$I30
--------------------------------------------------------------------------------
/MFT.Test/TestFiles/Boot/$Boot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricZimmerman/MFT/50e4ea636a96359f1d5f0ee0f993802564ff6b86/MFT.Test/TestFiles/Boot/$Boot
--------------------------------------------------------------------------------
/MFT.Test/TestFiles/NIST/DFR-16/$MFT:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricZimmerman/MFT/50e4ea636a96359f1d5f0ee0f993802564ff6b86/MFT.Test/TestFiles/NIST/DFR-16/$MFT
--------------------------------------------------------------------------------
/MFT.Test/TestFiles/Usn/record.usn:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricZimmerman/MFT/50e4ea636a96359f1d5f0ee0f993802564ff6b86/MFT.Test/TestFiles/Usn/record.usn
--------------------------------------------------------------------------------
/MFT.Test/TestFiles/tdungan/$MFT:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricZimmerman/MFT/50e4ea636a96359f1d5f0ee0f993802564ff6b86/MFT.Test/TestFiles/tdungan/$MFT
--------------------------------------------------------------------------------
/MFT.Test/TestFiles/xw/$MFT:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricZimmerman/MFT/50e4ea636a96359f1d5f0ee0f993802564ff6b86/MFT.Test/TestFiles/xw/$MFT
--------------------------------------------------------------------------------
/MFT.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.28803.452
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MFT", "MFT\MFT.csproj", "{DDA9E417-B536-4730-B578-AA45F8B130C7}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MFT.Test", "MFT.Test\MFT.Test.csproj", "{6DDDB050-A947-4B94-8E1C-70326008C65B}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Boot", "Boot\Boot.csproj", "{BA9C6030-EC7D-4C1D-A6BC-0D86824E1111}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Usn", "Usn\Usn.csproj", "{23D6FA96-D020-4CB6-8ED8-82D3F49317A2}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Secure", "SDS\Secure.csproj", "{21E6B751-CA17-4612-9806-9B52D3031FCF}"
15 | EndProject
16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogFile", "LogFile\LogFile.csproj", "{CCC2144C-33A7-41B9-8355-C240307A9611}"
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "O", "O\O.csproj", "{9B30002D-B041-41E6-9EDD-34CF16EFCFCF}"
19 | EndProject
20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "I30", "I30\I30.csproj", "{7D1BAE41-7E23-42EC-AA25-7F54716655AD}"
21 | EndProject
22 | Global
23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
24 | Debug|Any CPU = Debug|Any CPU
25 | Release|Any CPU = Release|Any CPU
26 | EndGlobalSection
27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
28 | {DDA9E417-B536-4730-B578-AA45F8B130C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {DDA9E417-B536-4730-B578-AA45F8B130C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {DDA9E417-B536-4730-B578-AA45F8B130C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {DDA9E417-B536-4730-B578-AA45F8B130C7}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {6DDDB050-A947-4B94-8E1C-70326008C65B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {6DDDB050-A947-4B94-8E1C-70326008C65B}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {6DDDB050-A947-4B94-8E1C-70326008C65B}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {6DDDB050-A947-4B94-8E1C-70326008C65B}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {BA9C6030-EC7D-4C1D-A6BC-0D86824E1111}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {BA9C6030-EC7D-4C1D-A6BC-0D86824E1111}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {BA9C6030-EC7D-4C1D-A6BC-0D86824E1111}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {BA9C6030-EC7D-4C1D-A6BC-0D86824E1111}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {23D6FA96-D020-4CB6-8ED8-82D3F49317A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {23D6FA96-D020-4CB6-8ED8-82D3F49317A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {23D6FA96-D020-4CB6-8ED8-82D3F49317A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {23D6FA96-D020-4CB6-8ED8-82D3F49317A2}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {21E6B751-CA17-4612-9806-9B52D3031FCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {21E6B751-CA17-4612-9806-9B52D3031FCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {21E6B751-CA17-4612-9806-9B52D3031FCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {21E6B751-CA17-4612-9806-9B52D3031FCF}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {CCC2144C-33A7-41B9-8355-C240307A9611}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {CCC2144C-33A7-41B9-8355-C240307A9611}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {CCC2144C-33A7-41B9-8355-C240307A9611}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {CCC2144C-33A7-41B9-8355-C240307A9611}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {9B30002D-B041-41E6-9EDD-34CF16EFCFCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {9B30002D-B041-41E6-9EDD-34CF16EFCFCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {9B30002D-B041-41E6-9EDD-34CF16EFCFCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {9B30002D-B041-41E6-9EDD-34CF16EFCFCF}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {7D1BAE41-7E23-42EC-AA25-7F54716655AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57 | {7D1BAE41-7E23-42EC-AA25-7F54716655AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
58 | {7D1BAE41-7E23-42EC-AA25-7F54716655AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {7D1BAE41-7E23-42EC-AA25-7F54716655AD}.Release|Any CPU.Build.0 = Release|Any CPU
60 | EndGlobalSection
61 | GlobalSection(SolutionProperties) = preSolution
62 | HideSolutionNode = FALSE
63 | EndGlobalSection
64 | GlobalSection(ExtensibilityGlobals) = postSolution
65 | SolutionGuid = {84153A83-ACF2-4023-B3AC-6E55C42DB388}
66 | EndGlobalSection
67 | EndGlobal
68 |
--------------------------------------------------------------------------------
/MFT/Attributes/ACERecord.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | // namespaces...
5 |
6 | namespace MFT.Attributes;
7 |
8 | // public classes...
9 | public class AceRecord
10 | {
11 | // public enums...
12 | [Flags]
13 | public enum AceFlagsEnum
14 | {
15 | ContainerInheritAce = 0x02,
16 | FailedAccessAceFlag = 0x80,
17 | InheritedAce = 0x10,
18 | InheritOnlyAce = 0x08,
19 | None = 0x0,
20 | NoPropagateInheritAce = 0x04,
21 | ObjectInheritAce = 0x01,
22 | SuccessfulAccessAceFlag = 0x40
23 | }
24 |
25 | public enum AceTypeEnum
26 | {
27 | AccessAllowed = 0x0,
28 | AccessAllowedCompound = 0x4,
29 | AccessAllowedObject = 0x5,
30 | AccessDenied = 0x1,
31 | AccessDeniedObject = 0x6,
32 | SystemAlarm = 0x3,
33 | SystemAlarmObject = 0x8,
34 | SystemAudit = 0x2,
35 | SystemAuditObject = 0x7,
36 | AccessAllowedCallback = 0x9,
37 | AccessDeniedCallback = 0xa,
38 | AccessAllowedCallbackObject = 0xb,
39 | AccessDeniedCallbackObject = 0xc,
40 | SystemAuditCallback = 0xd,
41 | SystemAlarmCallback = 0xe,
42 | SystemAuditCallbackObject = 0xf,
43 | SystemAlarmCallbackObject = 0x10,
44 | SystemMandatoryLabel = 0x11,
45 | SystemResourceAttribute = 0x12,
46 | SystemScopedPolicyId = 0x13,
47 | SystemProcessTrustLabel = 0x14,
48 | Unknown = 0x99
49 | }
50 |
51 | [Flags]
52 | public enum MasksEnum
53 | {
54 | FilEExecute = 0x00000020,
55 | CreateSubDir = 0x00000004,
56 | ReadAttrs = 0x00000080,
57 | WriteAttrs = 0x00000100,
58 | WriteOwnProp = 0x00000200,
59 | DeleteOwnProp = 0x00000400,
60 | ViewOwnProp = 0x00000800,
61 | Delete = 0x00010000,
62 | ReadEa = 0x00000008,
63 | FullControl = 0x000F003F,
64 | WriteEa = 0x00000010,
65 | FileReadDirList = 0x00000001,
66 | ReadControl = 0x00020000,
67 | FileWriteFileAdd = 0x00000002,
68 | WriteDac = 0x00040000,
69 | WriteOwner = 0x00080000,
70 | Synchronize = 0x000100000,
71 | TrusteeOwn = 0x00004000,
72 | UserAsContact = 0x00008000
73 | }
74 |
75 | // public constructors...
76 | ///
77 | /// Initializes a new instance of the class.
78 | ///
79 | public AceRecord(byte[] rawBytes)
80 | {
81 | RawBytes = rawBytes;
82 | }
83 |
84 | // public properties...
85 | public AceFlagsEnum AceFlags => (AceFlagsEnum)RawBytes[1];
86 |
87 | public ushort AceSize => BitConverter.ToUInt16(RawBytes, 2);
88 |
89 | public AceTypeEnum AceType
90 | {
91 | get
92 | {
93 | switch (RawBytes[0])
94 | {
95 | case 0x0:
96 | return AceTypeEnum.AccessAllowed;
97 | //ncrunch: no coverage start
98 | case 0x1:
99 | return AceTypeEnum.AccessDenied;
100 |
101 | case 0x2:
102 | return AceTypeEnum.SystemAudit;
103 |
104 | case 0x3:
105 | return AceTypeEnum.SystemAlarm;
106 |
107 | case 0x4:
108 | return AceTypeEnum.AccessAllowedCompound;
109 |
110 | case 0x5:
111 | return AceTypeEnum.AccessAllowedObject;
112 |
113 | case 0x6:
114 | return AceTypeEnum.AccessDeniedObject;
115 |
116 | case 0x7:
117 | return AceTypeEnum.SystemAuditObject;
118 |
119 | case 0x8:
120 | return AceTypeEnum.SystemAlarmObject;
121 | case 0x9:
122 | return AceTypeEnum.AccessAllowedCallback;
123 | case 0xa:
124 | return AceTypeEnum.AccessDeniedCallback;
125 | case 0xb:
126 | return AceTypeEnum.AccessAllowedCallbackObject;
127 | case 0xc:
128 | return AceTypeEnum.AccessDeniedCallbackObject;
129 | case 0xd:
130 | return AceTypeEnum.SystemAuditCallback;
131 | case 0xe:
132 | return AceTypeEnum.SystemAlarmCallback;
133 | case 0xf:
134 | return AceTypeEnum.SystemAuditCallbackObject;
135 | case 0x10:
136 | return AceTypeEnum.SystemAlarmCallbackObject;
137 | case 0x11:
138 | return AceTypeEnum.SystemMandatoryLabel;
139 | case 0x12:
140 | return AceTypeEnum.SystemResourceAttribute;
141 | case 0x13:
142 | return AceTypeEnum.SystemScopedPolicyId;
143 | case 0x14:
144 | return AceTypeEnum.SystemProcessTrustLabel;
145 | default:
146 | return AceTypeEnum.Unknown;
147 | //ncrunch: no coverage end
148 | }
149 | }
150 | }
151 |
152 | public MasksEnum Mask => (MasksEnum)BitConverter.ToUInt32(RawBytes, 4);
153 |
154 | public byte[] RawBytes { get; }
155 |
156 | public string Sid
157 | {
158 | get
159 | {
160 | var rawSidBytes = new byte[AceSize - 0x8];
161 | Buffer.BlockCopy(RawBytes, 0x8, rawSidBytes, 0, rawSidBytes.Length);
162 |
163 | return Helpers.ConvertHexStringToSidString(rawSidBytes);
164 | }
165 | }
166 |
167 | public Helpers.SidTypeEnum SidType => Helpers.GetSidTypeFromSidString(Sid);
168 |
169 | // public methods...
170 | public override string ToString()
171 | {
172 | var sb = new StringBuilder();
173 |
174 | sb.AppendLine($"ACE Size: 0x{AceSize:X}");
175 |
176 | sb.AppendLine($"ACE Type: {AceType}");
177 |
178 | sb.AppendLine($"ACE Flags: {AceFlags.ToString().Replace(", ", "|")}");
179 |
180 | sb.AppendLine($"Mask: {Mask}");
181 |
182 | sb.AppendLine($"SID: {Sid}");
183 | sb.AppendLine($"SID Type: {SidType}");
184 |
185 | sb.AppendLine($"SID Type Description: {Helpers.GetDescriptionFromEnumValue(SidType)}");
186 |
187 | return sb.ToString();
188 | }
189 | }
--------------------------------------------------------------------------------
/MFT/Attributes/Attribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace MFT.Attributes;
5 |
6 | public enum AttributeType
7 | {
8 | EndOfAttributes = -0x1,
9 | Unused = 0x0,
10 | StandardInformation = 0x10,
11 | AttributeList = 0x20,
12 | FileName = 0x30,
13 | VolumeVersionObjectId = 0x40,
14 | SecurityDescriptor = 0x50,
15 | VolumeName = 0x60,
16 | VolumeInformation = 0x70,
17 | Data = 0x80,
18 | IndexRoot = 0x90,
19 | IndexAllocation = 0xa0,
20 | Bitmap = 0xb0,
21 | ReparsePoint = 0xc0,
22 | EaInformation = 0xd0,
23 | Ea = 0xe0,
24 | PropertySet = 0xf0,
25 | LoggedUtilityStream = 0x100,
26 | UserDefinedAttribute = 0x1000
27 | }
28 |
29 | [Flags]
30 | public enum AttributeDataFlag
31 | {
32 | Compressed = 0x0001,
33 | Encrypted = 0x4000,
34 | Sparse = 0x8000
35 | }
36 |
37 | public abstract class Attribute
38 | {
39 | protected Attribute(byte[] rawBytes)
40 | {
41 | AttributeNumber = BitConverter.ToInt16(rawBytes, 0xE);
42 |
43 | AttributeType = (AttributeType)BitConverter.ToInt32(rawBytes, 0);
44 | AttributeSize = BitConverter.ToInt32(rawBytes, 4);
45 |
46 | IsResident = rawBytes[0x8] == 0;
47 |
48 | NameSize = rawBytes[0x09];
49 | NameOffset = BitConverter.ToInt16(rawBytes, 0xA);
50 |
51 | AttributeDataFlag = (AttributeDataFlag)BitConverter.ToInt16(rawBytes, 0xC);
52 |
53 | AttributeContentLength = BitConverter.ToInt32(rawBytes, 0x10);
54 | ContentOffset = BitConverter.ToInt16(rawBytes, 0x14);
55 |
56 | Name = string.Empty;
57 | if (NameSize > 0)
58 | {
59 | Name = Encoding.Unicode.GetString(rawBytes, NameOffset, NameSize * 2);
60 | }
61 | }
62 |
63 | public AttributeType AttributeType { get; }
64 | public int AttributeSize { get; }
65 | public int AttributeContentLength { get; }
66 | public int NameSize { get; }
67 | public int NameOffset { get; }
68 |
69 | public AttributeDataFlag AttributeDataFlag { get; }
70 |
71 | public string Name { get; }
72 | public int AttributeNumber { get; }
73 |
74 | public bool IsResident { get; }
75 |
76 | public short ContentOffset { get; }
77 |
78 | public override string ToString()
79 | {
80 | var name = string.Empty;
81 |
82 | if (NameSize > 0)
83 | {
84 | name = $", Name: {Name}";
85 | }
86 |
87 | var flags = string.Empty;
88 |
89 | if (AttributeDataFlag > 0)
90 | {
91 | flags = $" Attribute flags: {AttributeDataFlag.ToString().Replace(", ", "|")},";
92 | }
93 |
94 | return
95 | $"Type: {AttributeType}, Attribute #: 0x{AttributeNumber:X},{flags} Size: 0x{AttributeSize:X}, Content size: 0x{AttributeContentLength:X}, Name size: 0x{NameSize:X}{name}, Content offset: 0x{ContentOffset:X}, Resident: {IsResident}";
96 | }
97 | }
--------------------------------------------------------------------------------
/MFT/Attributes/AttributeList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using MFT.Other;
5 | using Serilog;
6 |
7 | namespace MFT.Attributes;
8 |
9 | public class AttributeList : Attribute
10 | {
11 | public AttributeList(byte[] rawBytes) : base(rawBytes)
12 | {
13 | DataRuns = new List();
14 | AttributeInformations = new List();
15 |
16 | //TODO Refactor using the NonResident and ResidentData classes?
17 |
18 | if (IsResident)
19 | {
20 | var index = ContentOffset;
21 |
22 | while (index < rawBytes.Length)
23 | {
24 | var size = BitConverter.ToInt16(rawBytes, index + 4);
25 |
26 | if (size < rawBytes.Length - index)
27 | {
28 | Log.Debug("Not enough data to process attribute list. {Msg}","Skipping remaining bytes in attribute list");
29 | break;
30 | }
31 |
32 | var buffer = new byte[size];
33 | Buffer.BlockCopy(rawBytes, index, buffer, 0, size);
34 |
35 | var er = new AttributeInfo(buffer);
36 |
37 | AttributeInformations.Add(er);
38 |
39 | index += size;
40 | }
41 | }
42 | else
43 | {
44 | StartingVirtualCluster = BitConverter.ToUInt64(rawBytes, 0x10);
45 | EndingVirtualCluster = BitConverter.ToUInt64(rawBytes, 0x18);
46 | OffsetToDataRun = BitConverter.ToUInt16(rawBytes, 0x20);
47 | AllocatedSize = BitConverter.ToUInt64(rawBytes, 0x28);
48 | ActualSize = BitConverter.ToUInt64(rawBytes, 0x30);
49 | InitializedSize = BitConverter.ToUInt64(rawBytes, 0x38);
50 |
51 | var index = OffsetToDataRun;
52 |
53 | var hasAnother = rawBytes[index] > 0;
54 |
55 | //when data is split across several entries, must find them all and process in order of
56 | //StartingVCN: 0x0 EndingVCN: 0x57C
57 | //StartingVCN: 0x57D EndingVCN: 0x138F
58 | //so things go back in right order
59 |
60 | //TODO this should be a function vs here and in Data class.
61 |
62 | while (hasAnother)
63 | {
64 | var drStart = rawBytes[index];
65 | index += 1;
66 |
67 | var clustersToReadAtOffset = (byte)(drStart & 0x0F);
68 | var offsetToRun = (byte)((drStart & 0xF0) >> 4);
69 |
70 | var clusterCountRaw = new byte[8];
71 | var offsetToRunRaw = new byte[8];
72 |
73 | Buffer.BlockCopy(rawBytes, index, clusterCountRaw, 0, clustersToReadAtOffset);
74 |
75 | index += clustersToReadAtOffset;
76 | Buffer.BlockCopy(rawBytes, index, offsetToRunRaw, 0, offsetToRun);
77 | index += offsetToRun;
78 |
79 | var clusterCount = BitConverter.ToUInt64(clusterCountRaw, 0);
80 | var offset = BitConverter.ToInt64(offsetToRunRaw, 0);
81 |
82 | var dr = new DataRun(clusterCount, offset);
83 | DataRuns.Add(dr);
84 |
85 | hasAnother = rawBytes[index] > 0;
86 | }
87 | }
88 | }
89 |
90 | public ushort OffsetToDataRun { get; }
91 | public ulong StartingVirtualCluster { get; }
92 | public ulong EndingVirtualCluster { get; }
93 | public ulong AllocatedSize { get; }
94 | public ulong ActualSize { get; }
95 | public ulong InitializedSize { get; }
96 |
97 | ///
98 | /// Contains cluster where the actual data lives when it is non-resident
99 | ///
100 | public List DataRuns { get; }
101 |
102 | public List AttributeInformations { get; }
103 |
104 | public override string ToString()
105 | {
106 | var sb = new StringBuilder();
107 |
108 | sb.AppendLine("**** ATTRIBUTE LIST ****");
109 |
110 | sb.AppendLine(base.ToString());
111 |
112 | sb.AppendLine();
113 |
114 | sb.AppendLine(
115 | $"DataRuns: {string.Join("\r\n", DataRuns)}\r\nAttribute Infos: {string.Join("\r\n", AttributeInformations)}");
116 |
117 | return sb.ToString();
118 | }
119 | }
--------------------------------------------------------------------------------
/MFT/Attributes/Bitmap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace MFT.Attributes;
5 |
6 | public class Bitmap : Attribute
7 | {
8 | public Bitmap(byte[] rawBytes) : base(rawBytes)
9 | {
10 | if (IsResident)
11 | {
12 | var content = new byte[AttributeContentLength];
13 |
14 | Buffer.BlockCopy(rawBytes, ContentOffset, content, 0, AttributeContentLength);
15 |
16 | ResidentData = new ResidentData(content);
17 | }
18 | else
19 | {
20 | NonResidentData = new NonResidentData(rawBytes);
21 | }
22 | }
23 |
24 | public ResidentData ResidentData { get; }
25 |
26 | public NonResidentData NonResidentData { get; }
27 |
28 | public override string ToString()
29 | {
30 | var sb = new StringBuilder();
31 |
32 | sb.AppendLine("**** BITMAP ****");
33 |
34 | sb.AppendLine(base.ToString());
35 |
36 | sb.AppendLine();
37 |
38 | if (ResidentData == null)
39 | {
40 | sb.AppendLine("Non Resident Data");
41 | sb.AppendLine(NonResidentData.ToString());
42 | }
43 | else
44 | {
45 | sb.AppendLine("Resident Data");
46 | sb.AppendLine(ResidentData.ToString());
47 | }
48 |
49 | return sb.ToString();
50 | }
51 | }
--------------------------------------------------------------------------------
/MFT/Attributes/Data.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace MFT.Attributes;
5 |
6 | public class Data : Attribute
7 | {
8 | public Data(byte[] rawBytes) : base(rawBytes)
9 | {
10 | if (IsResident)
11 | {
12 | var content = new byte[AttributeContentLength];
13 |
14 | Buffer.BlockCopy(rawBytes, ContentOffset, content, 0, AttributeContentLength);
15 |
16 | ResidentData = new ResidentData(content);
17 | }
18 | else
19 | {
20 | NonResidentData = new NonResidentData(rawBytes);
21 | }
22 | }
23 |
24 | public ResidentData ResidentData { get; }
25 | public NonResidentData NonResidentData { get; }
26 |
27 | public override string ToString()
28 | {
29 | var sb = new StringBuilder();
30 |
31 | sb.AppendLine("**** DATA ****");
32 |
33 | sb.AppendLine(base.ToString());
34 |
35 | sb.AppendLine();
36 |
37 | if (ResidentData == null)
38 | {
39 | sb.AppendLine("Non Resident Data");
40 | sb.AppendLine(NonResidentData.ToString());
41 | }
42 | else
43 | {
44 | sb.AppendLine("Resident Data");
45 | sb.AppendLine(ResidentData.ToString());
46 | }
47 |
48 | return sb.ToString();
49 | }
50 | }
--------------------------------------------------------------------------------
/MFT/Attributes/ExtendedAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Text;
5 | using Serilog;
6 |
7 | namespace MFT.Attributes;
8 |
9 | public interface IEa
10 | {
11 | public string InternalName { get; }
12 | }
13 |
14 | public class ExtendedAttribute : Attribute
15 | {
16 | public ExtendedAttribute(byte[] rawBytes) : base(rawBytes)
17 | {
18 | Content = new byte[AttributeContentLength];
19 |
20 | Buffer.BlockCopy(rawBytes, ContentOffset, Content, 0, AttributeContentLength);
21 |
22 | SubItems = new List