2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-07-28 18:13:49 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Entropy.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Verbs.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Implements the 'entropy' verb.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
2015-05-19 06:04:21 +01:00
|
|
|
|
2018-06-25 19:08:16 +01:00
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2015-10-18 22:04:03 +01:00
|
|
|
using DiscImageChef.Console;
|
2017-05-27 15:17:20 +01:00
|
|
|
using DiscImageChef.Core;
|
2015-05-19 06:04:21 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Commands
|
|
|
|
|
{
|
2017-12-20 02:08:37 +00:00
|
|
|
static class Entropy
|
2015-05-19 06:04:21 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
internal static void DoEntropy(EntropyOptions options)
|
2015-05-19 06:04:21 +01:00
|
|
|
{
|
2018-02-03 17:39:49 +00:00
|
|
|
DicConsole.DebugWriteLine("Entropy command", "--debug={0}", options.Debug);
|
|
|
|
|
DicConsole.DebugWriteLine("Entropy command", "--verbose={0}", options.Verbose);
|
|
|
|
|
DicConsole.DebugWriteLine("Entropy command", "--separated-tracks={0}", options.SeparatedTracks);
|
|
|
|
|
DicConsole.DebugWriteLine("Entropy command", "--whole-disc={0}", options.WholeDisc);
|
|
|
|
|
DicConsole.DebugWriteLine("Entropy command", "--input={0}", options.InputFile);
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.DebugWriteLine("Entropy command", "--duplicated-sectors={0}", options.DuplicatedSectors);
|
2015-05-19 06:04:21 +01:00
|
|
|
|
2016-09-05 17:37:31 +01:00
|
|
|
FiltersList filtersList = new FiltersList();
|
2018-02-03 17:39:49 +00:00
|
|
|
IFilter inputFilter = filtersList.GetFilter(options.InputFile);
|
2016-09-05 17:37:31 +01:00
|
|
|
|
|
|
|
|
if(inputFilter == null)
|
2016-02-04 16:51:03 +00:00
|
|
|
{
|
2016-09-05 17:37:31 +01:00
|
|
|
DicConsole.ErrorWriteLine("Cannot open specified file.");
|
2016-02-04 16:51:03 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
IMediaImage inputFormat = ImageFormat.Detect(inputFilter);
|
2015-05-19 06:04:21 +01:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(inputFormat == null)
|
2015-05-19 06:04:21 +01:00
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.ErrorWriteLine("Unable to recognize image format, not checksumming");
|
2015-05-19 06:04:21 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
inputFormat.Open(inputFilter);
|
|
|
|
|
Core.Statistics.AddMediaFormat(inputFormat.Format);
|
2017-12-26 06:05:12 +00:00
|
|
|
Core.Statistics.AddMedia(inputFormat.Info.MediaType, false);
|
2016-09-05 17:37:31 +01:00
|
|
|
Core.Statistics.AddFilter(inputFilter.Name);
|
2015-05-19 06:04:21 +01:00
|
|
|
|
2018-10-13 14:39:26 +01:00
|
|
|
Core.Entropy entropyCalculator = new Core.Entropy(options.Debug, options.Verbose, inputFormat);
|
|
|
|
|
entropyCalculator.InitProgressEvent += Progress.InitProgress;
|
|
|
|
|
entropyCalculator.InitProgress2Event += Progress.InitProgress2;
|
|
|
|
|
entropyCalculator.UpdateProgressEvent += Progress.UpdateProgress;
|
|
|
|
|
entropyCalculator.UpdateProgress2Event += Progress.UpdateProgress2;
|
|
|
|
|
entropyCalculator.EndProgressEvent += Progress.EndProgress;
|
|
|
|
|
entropyCalculator.EndProgress2Event += Progress.EndProgress2;
|
2015-05-19 06:04:21 +01:00
|
|
|
|
2018-10-13 14:39:26 +01:00
|
|
|
if(options.SeparatedTracks)
|
2017-12-21 06:06:19 +00:00
|
|
|
{
|
2018-10-13 14:39:26 +01:00
|
|
|
EntropyResults[] tracksEntropy = entropyCalculator.CalculateTracksEntropy(options.DuplicatedSectors);
|
|
|
|
|
foreach(EntropyResults trackEntropy in tracksEntropy)
|
2017-12-21 06:06:19 +00:00
|
|
|
{
|
2018-10-13 14:39:26 +01:00
|
|
|
DicConsole.WriteLine("Entropy for track {0} is {1:F4}.", trackEntropy.Track, trackEntropy.Entropy);
|
|
|
|
|
if(trackEntropy.UniqueSectors != null)
|
2018-10-14 19:10:30 +01:00
|
|
|
DicConsole.WriteLine("Track {0} has {1} unique sectors ({2:P3})", trackEntropy.Track,
|
2018-10-13 14:39:26 +01:00
|
|
|
trackEntropy.UniqueSectors,
|
|
|
|
|
(double)trackEntropy.UniqueSectors / (double)trackEntropy.Sectors);
|
2015-05-19 06:04:21 +01:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-13 14:39:26 +01:00
|
|
|
if(!options.WholeDisc)
|
|
|
|
|
{
|
|
|
|
|
Core.Statistics.AddCommand("entropy");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-19 06:04:21 +01:00
|
|
|
|
2018-10-13 14:39:26 +01:00
|
|
|
EntropyResults entropy = entropyCalculator.CalculateMediaEntropy(options.DuplicatedSectors);
|
2015-05-19 06:04:21 +01:00
|
|
|
|
2018-10-13 14:39:26 +01:00
|
|
|
DicConsole.WriteLine("Entropy for disk is {0:F4}.", entropy.Entropy);
|
|
|
|
|
if(entropy.UniqueSectors != null)
|
|
|
|
|
DicConsole.WriteLine("Disk has {0} unique sectors ({1:P3})", entropy.UniqueSectors,
|
|
|
|
|
(double)entropy.UniqueSectors / (double)entropy.Sectors);
|
2015-05-19 06:04:21 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
Core.Statistics.AddCommand("entropy");
|
2015-05-19 06:04:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|