Skip to content

Commit

Permalink
Add support for viewing NTFS partition contents
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeFZ committed Mar 8, 2024
1 parent 53e27d0 commit 3ae6a77
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 44 deletions.
2 changes: 0 additions & 2 deletions XvdTool.Streaming/HttpFileStream.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Diagnostics;
using System.Net;
using System.Net.Http.Headers;
using System;

namespace XvdTool.Streaming;

Expand Down
10 changes: 5 additions & 5 deletions XvdTool.Streaming/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ internal abstract class XvdCommand<T> : Command<T> where T : XvdCommandSettings
{
protected StreamedXvdFile XvdFile = default!;

protected void Initialize(XvdCommandSettings settings)
protected void Initialize(XvdCommandSettings settings, bool requiresWriting)
{
Debug.Assert(settings.XvcPath != null, "settings.XvcPath != null");

var path = settings.XvcPath;

XvdFile = path.StartsWith("http")
? StreamedXvdFile.OpenFromUrl(path)
: StreamedXvdFile.OpenFromFile(path);
: StreamedXvdFile.OpenFromFile(path, requiresWriting);

XvdFile.Parse();
}
Expand All @@ -89,7 +89,7 @@ internal abstract class CryptoCommand<T> : XvdCommand<T> where T : CryptoCommand

protected bool Initialize(CryptoCommandSettings settings, out KeyEntry entry)
{
base.Initialize(settings);
base.Initialize(settings, requiresWriting: true);

Debug.Assert(XvdFile != null, "XvdFile != null");

Expand Down Expand Up @@ -158,7 +158,7 @@ public sealed class Settings : XvdCommandSettings

public override int Execute(CommandContext context, Settings settings)
{
Initialize(settings);
Initialize(settings, requiresWriting: false);

Debug.Assert(XvdFile != null, "XvdFile != null");

Expand Down Expand Up @@ -241,7 +241,7 @@ public sealed class Settings : XvdCommandSettings;

public override int Execute(CommandContext context, Settings settings)
{
Initialize(settings);
Initialize(settings, requiresWriting: false);

Debug.Assert(XvdFile != null, "XvdFile != null");

Expand Down
10 changes: 3 additions & 7 deletions XvdTool.Streaming/StreamedXvdFile.LocalImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ private void LocalDecryptData(in KeyEntry key, bool recalculateHashes)
{
// TODO
}

memoryFile.Dispose();
}
// ReSharper restore AccessToDisposedClosure

Expand Down Expand Up @@ -155,8 +153,7 @@ private void LocalDecryptSection(ProgressTask progressTask, MemoryMappedFile mem

using var directAccessor = memoryFile.CreateDirectAccessor(
(long)(offset + mappedPageOffset * XvdFile.PAGE_SIZE),
(long)pageCountThisOffset * XvdFile.PAGE_SIZE,
MemoryMappedFileAccess.ReadWrite);
(long)pageCountThisOffset * XvdFile.PAGE_SIZE);

for (uint i = 0; i < pageCountThisOffset; i++)
{
Expand Down Expand Up @@ -195,14 +192,13 @@ private Span<uint> CacheDataUnits(ulong startPage, ulong count)

_stream.Position = hashPageOffset;

int read;
for (ulong i = 0; i < count; i++)
{
if (refreshCache)
{
refreshCache = false;

read = _stream.Read(pageCache);
var read = _stream.Read(pageCache);
Debug.Assert(read == pageCache.Length, "read == pageCache.Length");
}

Expand Down Expand Up @@ -269,11 +265,11 @@ private bool LocalVerifyDataHashesTask(ProgressContext ctx)

var task = ctx.AddTask("Verifying hashes", maxValue: (long) dataBlockCount * (int) XvdFile.PAGE_SIZE);

int read;
for (ulong i = 0; i < dataBlockCount; i++)
{
task.Increment(XvdFile.PAGE_SIZE);

int read;
if (refreshCache)
{
refreshCache = false;
Expand Down
Loading

0 comments on commit 3ae6a77

Please sign in to comment.