2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-07-27 02:35:29 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : ExtractFiles.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-07-27 02:35:29 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Verbs.
|
2016-07-27 02:35:29 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Implements the 'extract-files' verb.
|
2016-07-27 02:35:29 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-07-27 02:35:29 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-12-19 19:33:46 +00:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
2016-07-27 02:35:29 +01:00
|
|
|
using DiscImageChef.Console;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Core;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DiscImageChef.DiscImages;
|
2016-07-27 02:35:29 +01:00
|
|
|
using DiscImageChef.Filesystems;
|
2016-09-05 17:37:31 +01:00
|
|
|
using DiscImageChef.Filters;
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Commands
|
|
|
|
|
{
|
2017-12-07 02:30:54 +00:00
|
|
|
// TODO: Rewrite this, has an insane amount of repeating code ;)
|
2017-12-20 02:08:37 +00:00
|
|
|
static class ExtractFiles
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
internal static void DoExtractFiles(ExtractFilesOptions options)
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "--debug={0}", options.Debug);
|
|
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "--verbose={0}", options.Verbose);
|
|
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "--input={0}", options.InputFile);
|
|
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "--xattrs={0}", options.Xattrs);
|
|
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "--output={0}", options.OutputDir);
|
|
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
FiltersList filtersList = new FiltersList();
|
|
|
|
|
Filter inputFilter = filtersList.GetFilter(options.InputFile);
|
|
|
|
|
|
|
|
|
|
if(inputFilter == null)
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
DicConsole.ErrorWriteLine("Cannot open specified file.");
|
2016-07-27 02:35:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 23:54:02 +01:00
|
|
|
Encoding encoding = null;
|
|
|
|
|
|
|
|
|
|
if(options.EncodingName != null)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
encoding = Claunia.Encoding.Encoding.GetEncoding(options.EncodingName);
|
2017-12-19 20:33:03 +00:00
|
|
|
if(options.Verbose) DicConsole.VerboseWriteLine("Using encoding for {0}.", encoding.EncodingName);
|
2017-10-12 23:54:02 +01:00
|
|
|
}
|
|
|
|
|
catch(ArgumentException)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.ErrorWriteLine("Specified encoding is not supported.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
PluginBase plugins = new PluginBase();
|
2017-10-12 23:54:02 +01:00
|
|
|
plugins.RegisterAllPlugins(encoding);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-12-21 20:15:53 +00:00
|
|
|
ImagePlugin imageFormat = ImageFormat.Detect(inputFilter);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
if(imageFormat == null)
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
|
|
|
|
DicConsole.WriteLine("Image format not identified, not proceeding with analysis.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-12-21 02:57:32 +00:00
|
|
|
|
|
|
|
|
if(options.Verbose)
|
|
|
|
|
DicConsole.VerboseWriteLine("Image format identified by {0} ({1}).", imageFormat.Name,
|
|
|
|
|
imageFormat.PluginUuid);
|
|
|
|
|
else DicConsole.WriteLine("Image format identified by {0}.", imageFormat.Name);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
if(Directory.Exists(options.OutputDir) || File.Exists(options.OutputDir))
|
|
|
|
|
{
|
|
|
|
|
DicConsole.ErrorWriteLine("Destination exists, aborting.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(options.OutputDir);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
if(!imageFormat.OpenImage(inputFilter))
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
|
|
|
|
DicConsole.WriteLine("Unable to open image format");
|
|
|
|
|
DicConsole.WriteLine("No error given");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "Correctly opened image file.");
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "Image without headers is {0} bytes.",
|
2017-12-20 17:15:26 +00:00
|
|
|
imageFormat.GetImageSize());
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "Image has {0} sectors.",
|
2017-12-20 17:15:26 +00:00
|
|
|
imageFormat.GetSectors());
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", "Image identifies disk type as {0}.",
|
2017-12-20 17:15:26 +00:00
|
|
|
imageFormat.GetMediaType());
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
Core.Statistics.AddMediaFormat(imageFormat.GetImageFormat());
|
|
|
|
|
Core.Statistics.AddMedia(imageFormat.ImageInfo.MediaType, false);
|
2016-09-05 17:37:31 +01:00
|
|
|
Core.Statistics.AddFilter(inputFilter.Name);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.ErrorWriteLine("Unable to open image format");
|
|
|
|
|
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
List<Partition> partitions = Core.Partitions.GetAll(imageFormat);
|
|
|
|
|
Core.Partitions.AddSchemesToStats(partitions);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2017-12-21 20:15:53 +00:00
|
|
|
List<string> idPlugins;
|
|
|
|
|
Filesystem plugin;
|
|
|
|
|
Errno error;
|
2017-12-19 20:33:03 +00:00
|
|
|
if(partitions.Count == 0) DicConsole.DebugWriteLine("Extract-Files command", "No partitions found");
|
2016-07-27 02:35:29 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DicConsole.WriteLine("{0} partitions found.", partitions.Count);
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < partitions.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.WriteLine();
|
2017-07-19 16:37:11 +01:00
|
|
|
DicConsole.WriteLine("Partition {0}:", partitions[i].Sequence);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Identifying filesystem on partition");
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
Core.Filesystems.Identify(imageFormat, out idPlugins, partitions[i]);
|
|
|
|
|
if(idPlugins.Count == 0) DicConsole.WriteLine("Filesystem not identified");
|
|
|
|
|
else if(idPlugins.Count > 1)
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2017-12-21 17:58:51 +00:00
|
|
|
DicConsole.WriteLine($"Identified by {idPlugins.Count} plugins");
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(string pluginName in idPlugins)
|
|
|
|
|
if(plugins.PluginsList.TryGetValue(pluginName, out plugin))
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2017-12-21 17:58:51 +00:00
|
|
|
DicConsole.WriteLine($"As identified by {plugin.Name}.");
|
2017-12-20 17:15:26 +00:00
|
|
|
Filesystem fs = (Filesystem)plugin
|
2017-12-21 14:30:38 +00:00
|
|
|
.GetType().GetConstructor(new[]
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
typeof(ImagePlugin), typeof(Partition), typeof(Encoding)
|
2017-12-20 17:15:26 +00:00
|
|
|
}).Invoke(new object[] {imageFormat, partitions[i], null});
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
error = fs.Mount(options.Debug);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
|
|
|
|
List<string> rootDir = new List<string>();
|
|
|
|
|
error = fs.ReadDir("/", ref rootDir);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
foreach(string entry in rootDir)
|
2017-12-07 02:30:54 +00:00
|
|
|
{
|
|
|
|
|
FileEntryInfo stat = new FileEntryInfo();
|
|
|
|
|
|
2017-12-21 20:15:53 +00:00
|
|
|
string volumeName = string.IsNullOrEmpty(fs.XmlFSType.VolumeName) ? "NO NAME" : fs.XmlFSType.VolumeName;
|
2017-12-07 02:30:54 +00:00
|
|
|
|
|
|
|
|
error = fs.Stat(entry, ref stat);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
2017-12-21 20:15:53 +00:00
|
|
|
string outputPath;
|
|
|
|
|
FileStream outputFile;
|
2017-12-07 02:30:54 +00:00
|
|
|
if(options.Xattrs)
|
|
|
|
|
{
|
|
|
|
|
List<string> xattrs = new List<string>();
|
|
|
|
|
|
|
|
|
|
error = fs.ListXAttr(entry, ref xattrs);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
foreach(string xattr in xattrs)
|
|
|
|
|
{
|
|
|
|
|
byte[] xattrBuf = new byte[0];
|
|
|
|
|
error = fs.GetXattr(entry, xattr, ref xattrBuf);
|
2017-12-21 06:06:19 +00:00
|
|
|
if(error != Errno.NoError) continue;
|
|
|
|
|
|
|
|
|
|
Directory
|
|
|
|
|
.CreateDirectory(Path.Combine(options.OutputDir,
|
|
|
|
|
fs.XmlFSType.Type,
|
|
|
|
|
volumeName,
|
|
|
|
|
".xattrs",
|
|
|
|
|
xattr));
|
|
|
|
|
|
|
|
|
|
outputPath =
|
|
|
|
|
Path.Combine(options.OutputDir,
|
|
|
|
|
fs.XmlFSType.Type, volumeName,
|
|
|
|
|
".xattrs", xattr, entry);
|
|
|
|
|
|
|
|
|
|
if(!File.Exists(outputPath))
|
2017-12-07 02:30:54 +00:00
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
outputFile =
|
|
|
|
|
new FileStream(outputPath,
|
|
|
|
|
FileMode.CreateNew,
|
|
|
|
|
FileAccess.ReadWrite,
|
|
|
|
|
FileShare.None);
|
|
|
|
|
outputFile.Write(xattrBuf, 0, xattrBuf.Length);
|
|
|
|
|
outputFile.Close();
|
|
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-21 06:06:19 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
fi.CreationTimeUtc = stat.CreationTimeUtc;
|
|
|
|
|
}
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
fi.LastWriteTimeUtc = stat.LastWriteTimeUtc;
|
|
|
|
|
}
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
fi.LastAccessTimeUtc = stat.AccessTimeUtc;
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
DicConsole
|
|
|
|
|
.WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}",
|
|
|
|
|
xattrBuf.Length, xattr, entry,
|
|
|
|
|
outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
else
|
|
|
|
|
DicConsole
|
|
|
|
|
.ErrorWriteLine("Cannot write xattr {0} for {1}, output exists",
|
|
|
|
|
xattr, entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(Path.Combine(options.OutputDir,
|
2017-12-19 20:33:03 +00:00
|
|
|
fs.XmlFSType.Type,
|
|
|
|
|
volumeName));
|
2017-12-07 02:30:54 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
outputPath =
|
|
|
|
|
Path.Combine(options.OutputDir, fs.XmlFSType.Type, volumeName,
|
|
|
|
|
entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
|
|
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
byte[] outBuf = new byte[0];
|
|
|
|
|
|
|
|
|
|
error = fs.Read(entry, 0, stat.Length, ref outBuf);
|
|
|
|
|
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
outputFile =
|
|
|
|
|
new FileStream(outputPath, FileMode.CreateNew,
|
|
|
|
|
FileAccess.ReadWrite, FileShare.None);
|
2017-12-07 02:30:54 +00:00
|
|
|
outputFile.Write(outBuf, 0, outBuf.Length);
|
|
|
|
|
outputFile.Close();
|
|
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
|
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.CreationTimeUtc = stat.CreationTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-07 02:30:54 +00:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
DicConsole.WriteLine("Written {0} bytes of file {1} to {2}",
|
2017-12-19 20:33:03 +00:00
|
|
|
outBuf.Length, entry, outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} reading file {1}",
|
2017-12-19 20:33:03 +00:00
|
|
|
error, entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole
|
|
|
|
|
.ErrorWriteLine("Cannot write file {0}, output exists",
|
|
|
|
|
entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Error reading file {0}", entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.ErrorWriteLine("Error {0} reading root directory {0}",
|
|
|
|
|
error.ToString());
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
Core.Statistics.AddFilesystem(fs.XmlFSType.Type);
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.ErrorWriteLine("Unable to mount device, error {0}",
|
|
|
|
|
error.ToString());
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
plugins.PluginsList.TryGetValue(idPlugins[0], out plugin);
|
2017-12-21 17:58:51 +00:00
|
|
|
DicConsole.WriteLine($"Identified by {plugin.Name}.");
|
2017-12-20 17:15:26 +00:00
|
|
|
Filesystem fs = (Filesystem)plugin
|
2017-12-21 14:30:38 +00:00
|
|
|
.GetType().GetConstructor(new[]
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
typeof(ImagePlugin), typeof(Partition), typeof(Encoding)
|
2017-12-20 17:15:26 +00:00
|
|
|
}).Invoke(new object[] {imageFormat, partitions[i], null});
|
2016-07-27 02:35:29 +01:00
|
|
|
error = fs.Mount(options.Debug);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
|
|
|
|
List<string> rootDir = new List<string>();
|
|
|
|
|
error = fs.ReadDir("/", ref rootDir);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
foreach(string entry in rootDir)
|
2017-12-07 02:30:54 +00:00
|
|
|
{
|
|
|
|
|
FileEntryInfo stat = new FileEntryInfo();
|
|
|
|
|
|
2017-12-21 20:15:53 +00:00
|
|
|
string volumeName = string.IsNullOrEmpty(fs.XmlFSType.VolumeName) ? "NO NAME" : fs.XmlFSType.VolumeName;
|
2017-12-07 02:30:54 +00:00
|
|
|
|
|
|
|
|
error = fs.Stat(entry, ref stat);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
2017-12-21 20:15:53 +00:00
|
|
|
FileStream outputFile;
|
|
|
|
|
string outputPath;
|
2017-12-07 02:30:54 +00:00
|
|
|
if(options.Xattrs)
|
|
|
|
|
{
|
|
|
|
|
List<string> xattrs = new List<string>();
|
|
|
|
|
|
|
|
|
|
error = fs.ListXAttr(entry, ref xattrs);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
foreach(string xattr in xattrs)
|
|
|
|
|
{
|
|
|
|
|
byte[] xattrBuf = new byte[0];
|
|
|
|
|
error = fs.GetXattr(entry, xattr, ref xattrBuf);
|
2017-12-21 06:06:19 +00:00
|
|
|
if(error != Errno.NoError) continue;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Directory.CreateDirectory(Path.Combine(options.OutputDir,
|
|
|
|
|
fs.XmlFSType.Type,
|
|
|
|
|
volumeName,
|
|
|
|
|
".xattrs", xattr));
|
2017-12-07 02:30:54 +00:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
outputPath =
|
|
|
|
|
Path.Combine(options.OutputDir, fs.XmlFSType.Type,
|
|
|
|
|
volumeName, ".xattrs", xattr, entry);
|
|
|
|
|
|
|
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
outputFile =
|
|
|
|
|
new FileStream(outputPath, FileMode.CreateNew,
|
|
|
|
|
FileAccess.ReadWrite,
|
|
|
|
|
FileShare.None);
|
|
|
|
|
outputFile.Write(xattrBuf, 0, xattrBuf.Length);
|
|
|
|
|
outputFile.Close();
|
|
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.CreationTimeUtc = stat.CreationTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-07 02:30:54 +00:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-21 06:06:19 +00:00
|
|
|
DicConsole
|
|
|
|
|
.WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}",
|
|
|
|
|
xattrBuf.Length, xattr, entry,
|
|
|
|
|
outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
else
|
|
|
|
|
DicConsole
|
|
|
|
|
.ErrorWriteLine("Cannot write xattr {0} for {1}, output exists",
|
|
|
|
|
xattr, entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
Directory.CreateDirectory(Path.Combine(options.OutputDir, fs.XmlFSType.Type,
|
|
|
|
|
volumeName));
|
2017-12-07 02:30:54 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
outputPath =
|
|
|
|
|
Path.Combine(options.OutputDir, fs.XmlFSType.Type, volumeName, entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
|
|
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
byte[] outBuf = new byte[0];
|
|
|
|
|
|
|
|
|
|
error = fs.Read(entry, 0, stat.Length, ref outBuf);
|
|
|
|
|
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
outputFile =
|
|
|
|
|
new FileStream(outputPath, FileMode.CreateNew,
|
|
|
|
|
FileAccess.ReadWrite, FileShare.None);
|
2017-12-07 02:30:54 +00:00
|
|
|
outputFile.Write(outBuf, 0, outBuf.Length);
|
|
|
|
|
outputFile.Close();
|
|
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
|
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.CreationTimeUtc = stat.CreationTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-07 02:30:54 +00:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
DicConsole.WriteLine("Written {0} bytes of file {1} to {2}",
|
2017-12-19 20:33:03 +00:00
|
|
|
outBuf.Length, entry, outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} reading file {1}", error,
|
2017-12-19 20:33:03 +00:00
|
|
|
entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
DicConsole.ErrorWriteLine("Cannot write file {0}, output exists",
|
2017-12-19 20:33:03 +00:00
|
|
|
entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Error reading file {0}", entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
else
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} reading root directory {0}", error.ToString());
|
|
|
|
|
|
|
|
|
|
Core.Statistics.AddFilesystem(fs.XmlFSType.Type);
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Unable to mount device, error {0}", error.ToString());
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-19 16:31:08 +01:00
|
|
|
Partition wholePart = new Partition
|
|
|
|
|
{
|
2017-07-19 16:37:11 +01:00
|
|
|
Name = "Whole device",
|
2017-12-20 17:15:26 +00:00
|
|
|
Length = imageFormat.GetSectors(),
|
|
|
|
|
Size = imageFormat.GetSectors() * imageFormat.GetSectorSize()
|
2017-07-19 16:31:08 +01:00
|
|
|
};
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
Core.Filesystems.Identify(imageFormat, out idPlugins, wholePart);
|
|
|
|
|
if(idPlugins.Count == 0) DicConsole.WriteLine("Filesystem not identified");
|
|
|
|
|
else if(idPlugins.Count > 1)
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2017-12-21 17:58:51 +00:00
|
|
|
DicConsole.WriteLine($"Identified by {idPlugins.Count} plugins");
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
foreach(string pluginName in idPlugins)
|
|
|
|
|
if(plugins.PluginsList.TryGetValue(pluginName, out plugin))
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2017-12-21 17:58:51 +00:00
|
|
|
DicConsole.WriteLine($"As identified by {plugin.Name}.");
|
2017-12-20 17:15:26 +00:00
|
|
|
Filesystem fs = (Filesystem)plugin
|
2017-12-21 14:30:38 +00:00
|
|
|
.GetType().GetConstructor(new[]
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
typeof(ImagePlugin), typeof(Partition), typeof(Encoding)
|
2017-12-20 17:15:26 +00:00
|
|
|
}).Invoke(new object[] {imageFormat, wholePart, null});
|
2016-07-27 02:35:29 +01:00
|
|
|
error = fs.Mount(options.Debug);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
|
|
|
|
List<string> rootDir = new List<string>();
|
|
|
|
|
error = fs.ReadDir("/", ref rootDir);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
foreach(string entry in rootDir)
|
2017-12-07 02:30:54 +00:00
|
|
|
{
|
|
|
|
|
FileEntryInfo stat = new FileEntryInfo();
|
|
|
|
|
|
2017-12-21 20:15:53 +00:00
|
|
|
string volumeName = string.IsNullOrEmpty(fs.XmlFSType.VolumeName) ? "NO NAME" : fs.XmlFSType.VolumeName;
|
2017-12-07 02:30:54 +00:00
|
|
|
|
|
|
|
|
error = fs.Stat(entry, ref stat);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
2017-12-21 20:15:53 +00:00
|
|
|
FileStream outputFile;
|
|
|
|
|
string outputPath;
|
2017-12-07 02:30:54 +00:00
|
|
|
if(options.Xattrs)
|
|
|
|
|
{
|
|
|
|
|
List<string> xattrs = new List<string>();
|
|
|
|
|
|
|
|
|
|
error = fs.ListXAttr(entry, ref xattrs);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
foreach(string xattr in xattrs)
|
|
|
|
|
{
|
|
|
|
|
byte[] xattrBuf = new byte[0];
|
|
|
|
|
error = fs.GetXattr(entry, xattr, ref xattrBuf);
|
2017-12-21 06:06:19 +00:00
|
|
|
if(error != Errno.NoError) continue;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Directory.CreateDirectory(Path.Combine(options.OutputDir,
|
|
|
|
|
fs.XmlFSType.Type,
|
|
|
|
|
volumeName,
|
|
|
|
|
".xattrs", xattr));
|
2017-12-07 02:30:54 +00:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
outputPath =
|
|
|
|
|
Path.Combine(options.OutputDir, fs.XmlFSType.Type,
|
|
|
|
|
volumeName, ".xattrs", xattr, entry);
|
|
|
|
|
|
|
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
outputFile =
|
|
|
|
|
new FileStream(outputPath, FileMode.CreateNew,
|
|
|
|
|
FileAccess.ReadWrite,
|
|
|
|
|
FileShare.None);
|
|
|
|
|
outputFile.Write(xattrBuf, 0, xattrBuf.Length);
|
|
|
|
|
outputFile.Close();
|
|
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.CreationTimeUtc = stat.CreationTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-07 02:30:54 +00:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-21 06:06:19 +00:00
|
|
|
DicConsole
|
|
|
|
|
.WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}",
|
|
|
|
|
xattrBuf.Length, xattr, entry,
|
|
|
|
|
outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
else
|
|
|
|
|
DicConsole
|
|
|
|
|
.ErrorWriteLine("Cannot write xattr {0} for {1}, output exists",
|
|
|
|
|
xattr, entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
Directory.CreateDirectory(Path.Combine(options.OutputDir, fs.XmlFSType.Type,
|
|
|
|
|
volumeName));
|
2017-12-07 02:30:54 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
outputPath =
|
|
|
|
|
Path.Combine(options.OutputDir, fs.XmlFSType.Type, volumeName, entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
|
|
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
byte[] outBuf = new byte[0];
|
|
|
|
|
|
|
|
|
|
error = fs.Read(entry, 0, stat.Length, ref outBuf);
|
|
|
|
|
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
outputFile =
|
|
|
|
|
new FileStream(outputPath, FileMode.CreateNew,
|
|
|
|
|
FileAccess.ReadWrite, FileShare.None);
|
2017-12-07 02:30:54 +00:00
|
|
|
outputFile.Write(outBuf, 0, outBuf.Length);
|
|
|
|
|
outputFile.Close();
|
|
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
|
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.CreationTimeUtc = stat.CreationTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-07 02:30:54 +00:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
DicConsole.WriteLine("Written {0} bytes of file {1} to {2}",
|
2017-12-19 20:33:03 +00:00
|
|
|
outBuf.Length, entry, outputPath);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} reading file {1}", error,
|
2017-12-19 20:33:03 +00:00
|
|
|
entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
DicConsole.ErrorWriteLine("Cannot write file {0}, output exists",
|
2017-12-19 20:33:03 +00:00
|
|
|
entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Error reading file {0}", entry);
|
2017-12-07 02:30:54 +00:00
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
else
|
|
|
|
|
DicConsole.ErrorWriteLine("Error {0} reading root directory {0}", error.ToString());
|
|
|
|
|
|
|
|
|
|
Core.Statistics.AddFilesystem(fs.XmlFSType.Type);
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Unable to mount device, error {0}", error.ToString());
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
plugins.PluginsList.TryGetValue(idPlugins[0], out plugin);
|
2017-12-21 17:58:51 +00:00
|
|
|
DicConsole.WriteLine($"Identified by {plugin.Name}.");
|
2017-12-20 17:15:26 +00:00
|
|
|
Filesystem fs = (Filesystem)plugin
|
2017-12-21 14:30:38 +00:00
|
|
|
.GetType().GetConstructor(new[]
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
typeof(ImagePlugin), typeof(Partition), typeof(Encoding)
|
2017-12-20 17:15:26 +00:00
|
|
|
}).Invoke(new object[] {imageFormat, wholePart, null});
|
2016-07-27 02:35:29 +01:00
|
|
|
error = fs.Mount(options.Debug);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
|
|
|
|
List<string> rootDir = new List<string>();
|
|
|
|
|
error = fs.ReadDir("/", ref rootDir);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
foreach(string entry in rootDir)
|
|
|
|
|
{
|
|
|
|
|
FileEntryInfo stat = new FileEntryInfo();
|
|
|
|
|
|
2017-12-21 20:15:53 +00:00
|
|
|
string volumeName = string.IsNullOrEmpty(fs.XmlFSType.VolumeName) ? "NO NAME" : fs.XmlFSType.VolumeName;
|
2016-08-26 01:43:15 +01:00
|
|
|
|
2016-07-27 02:35:29 +01:00
|
|
|
error = fs.Stat(entry, ref stat);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
2017-12-21 20:15:53 +00:00
|
|
|
string outputPath;
|
|
|
|
|
FileStream outputFile;
|
2016-07-27 02:35:29 +01:00
|
|
|
if(options.Xattrs)
|
|
|
|
|
{
|
|
|
|
|
List<string> xattrs = new List<string>();
|
|
|
|
|
|
|
|
|
|
error = fs.ListXAttr(entry, ref xattrs);
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
foreach(string xattr in xattrs)
|
|
|
|
|
{
|
|
|
|
|
byte[] xattrBuf = new byte[0];
|
|
|
|
|
error = fs.GetXattr(entry, xattr, ref xattrBuf);
|
2017-12-21 06:06:19 +00:00
|
|
|
if(error != Errno.NoError) continue;
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Directory.CreateDirectory(Path.Combine(options.OutputDir,
|
|
|
|
|
fs.XmlFSType.Type,
|
|
|
|
|
volumeName, ".xattrs",
|
|
|
|
|
xattr));
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
outputPath =
|
|
|
|
|
Path.Combine(options.OutputDir, fs.XmlFSType.Type, volumeName,
|
|
|
|
|
".xattrs", xattr, entry);
|
|
|
|
|
|
|
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
outputFile =
|
|
|
|
|
new FileStream(outputPath, FileMode.CreateNew,
|
|
|
|
|
FileAccess.ReadWrite, FileShare.None);
|
|
|
|
|
outputFile.Write(xattrBuf, 0, xattrBuf.Length);
|
|
|
|
|
outputFile.Close();
|
|
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
2016-07-27 02:35:29 +01:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.CreationTimeUtc = stat.CreationTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-21 06:06:19 +00:00
|
|
|
DicConsole
|
|
|
|
|
.WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}",
|
|
|
|
|
xattrBuf.Length, xattr, entry, outputPath);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
else
|
|
|
|
|
DicConsole
|
|
|
|
|
.ErrorWriteLine("Cannot write xattr {0} for {1}, output exists",
|
|
|
|
|
xattr, entry);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
Directory.CreateDirectory(Path.Combine(options.OutputDir, fs.XmlFSType.Type,
|
2016-08-26 01:43:15 +01:00
|
|
|
volumeName));
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
outputPath = Path.Combine(options.OutputDir, fs.XmlFSType.Type, volumeName, entry);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
byte[] outBuf = new byte[0];
|
|
|
|
|
|
|
|
|
|
error = fs.Read(entry, 0, stat.Length, ref outBuf);
|
|
|
|
|
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
outputFile = new FileStream(outputPath, FileMode.CreateNew,
|
|
|
|
|
FileAccess.ReadWrite, FileShare.None);
|
2016-07-27 02:35:29 +01:00
|
|
|
outputFile.Write(outBuf, 0, outBuf.Length);
|
|
|
|
|
outputFile.Close();
|
2016-07-28 22:25:26 +01:00
|
|
|
FileInfo fi = new FileInfo(outputPath);
|
2016-07-27 02:35:29 +01:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.CreationTimeUtc = stat.CreationTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; }
|
2017-12-21 20:15:53 +00:00
|
|
|
catch { // ignored
|
|
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.WriteLine("Written {0} bytes of file {1} to {2}", outBuf.Length,
|
|
|
|
|
entry, outputPath);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Error {0} reading file {1}", error, entry);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Cannot write file {0}, output exists", entry);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Error reading file {0}", entry);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Error {0} reading root directory {0}", error.ToString());
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
Core.Statistics.AddFilesystem(fs.XmlFSType.Type);
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else DicConsole.ErrorWriteLine("Unable to mount device, error {0}", error.ToString());
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
2017-12-21 17:58:51 +00:00
|
|
|
DicConsole.ErrorWriteLine($"Error reading file: {ex.Message}");
|
2016-07-27 02:35:29 +01:00
|
|
|
DicConsole.DebugWriteLine("Extract-Files command", ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-04 23:07:31 +01:00
|
|
|
Core.Statistics.AddCommand("extract-files");
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|