Changeset 2352
- Timestamp:
- 11/6/2011 11:56:04 PM (19 months ago)
- Location:
- branches/eraser6/pluginsRewrite
- Files:
-
- 6 added
- 17 edited
-
Eraser.Manager/EntropySource.cs (modified) (1 diff)
-
Eraser.Manager/ErasureMethod.cs (modified) (2 diffs)
-
Eraser.Manager/ErasureTarget.cs (modified) (1 diff)
-
Eraser.Manager/FileSystem.cs (modified) (1 diff)
-
Eraser.Manager/PRNG.cs (modified) (1 diff)
-
Eraser.Manager/Strings.en.resx (modified) (2 diffs)
-
Eraser.Manager/Strings.it.resx (modified) (2 diffs)
-
Eraser.Manager/Strings.nl.resx (modified) (2 diffs)
-
Eraser.Manager/Strings.pl.resx (modified) (2 diffs)
-
Eraser.Manager/Strings.resx (modified) (2 diffs)
-
Eraser.Plugins/Eraser.Plugins.csproj (modified) (1 diff)
-
Eraser.Plugins/ExtensionPoints (added)
-
Eraser.Plugins/ExtensionPoints/EntropySource.cs (added)
-
Eraser.Plugins/ExtensionPoints/ErasureMethod.cs (added)
-
Eraser.Plugins/ExtensionPoints/ErasureTarget.cs (added)
-
Eraser.Plugins/ExtensionPoints/FileSystem.cs (added)
-
Eraser.Plugins/ExtensionPoints/Prng.cs (added)
-
Eraser.Plugins/IRegistrar.cs (modified) (1 diff)
-
Eraser.Plugins/Strings.en.resx (modified) (1 diff)
-
Eraser.Plugins/Strings.it.resx (modified) (1 diff)
-
Eraser.Plugins/Strings.nl.resx (modified) (1 diff)
-
Eraser.Plugins/Strings.pl.resx (modified) (1 diff)
-
Eraser.Plugins/Strings.resx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/pluginsRewrite/Eraser.Manager/EntropySource.cs
r2055 r2352 30 30 using System.Reflection; 31 31 32 using Eraser.Plugins; 33 using Eraser.Plugins.ExtensionPoints; 34 32 35 namespace Eraser.Manager 33 36 { 34 /// <summary>35 /// Provides an abstract interface to allow multiple sources of entropy into36 /// the EntropyPoller class.37 /// </summary>38 public abstract class EntropySource : IRegisterable39 {40 /// <summary>41 /// Constructor.42 /// </summary>43 protected EntropySource()44 {45 }46 47 /// <summary>48 /// The name of the entropy source49 /// </summary>50 public abstract string Name51 {52 get;53 }54 55 /// <summary>56 /// The guid representing this entropy source57 /// </summary>58 public abstract Guid Guid59 {60 get;61 }62 63 /// <summary>64 /// Gets a primer to add to the pool when this source is first initialised, to65 /// further add entropy to the pool.66 /// </summary>67 /// <returns>A byte array containing the entropy.</returns>68 public abstract byte[] GetPrimer();69 70 /// <summary>71 /// Retrieve entropy from a source which will have slow rate of72 /// entropy polling.73 /// </summary>74 /// <returns></returns>75 public abstract byte[] GetSlowEntropy();76 77 /// <summary>78 /// Retrieve entropy from a soruce which will have a fast rate of79 /// entropy polling.80 /// </summary>81 /// <returns></returns>82 public abstract byte[] GetFastEntropy();83 84 /// <summary>85 /// Gets entropy from the entropy source. This will be called repetitively.86 /// </summary>87 /// <returns>A byte array containing the entropy, both slow rate and fast rate.</returns>88 public abstract byte[] GetEntropy();89 90 /// <summary>91 /// Converts value types into a byte array. This is a helper function to allow92 /// inherited classes to convert value types into byte arrays which can be93 /// returned to the EntropyPoller class.94 /// </summary>95 /// <typeparam name="T">Any value type</typeparam>96 /// <param name="entropy">A value which will be XORed with pool contents.</param>97 protected static byte[] StructToBuffer<T>(T entropy) where T : struct98 {99 int sizeofObject = Marshal.SizeOf(entropy);100 IntPtr memory = Marshal.AllocHGlobal(sizeofObject);101 try102 {103 Marshal.StructureToPtr(entropy, memory, false);104 byte[] dest = new byte[sizeofObject];105 106 //Copy the memory107 Marshal.Copy(memory, dest, 0, sizeofObject);108 return dest;109 }110 finally111 {112 Marshal.FreeHGlobal(memory);113 }114 }115 }116 117 37 /// <summary> 118 38 /// A class which manages all of the instances of the EntropySources -
branches/eraser6/pluginsRewrite/Eraser.Manager/ErasureMethod.cs
r2085 r2352 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 26 using System.Reflection; 25 27 using System.IO; 26 using System.Reflection; 28 27 29 using Eraser.Util; 30 using Eraser.Plugins; 31 using Eraser.Plugins.ExtensionPoints; 28 32 29 33 namespace Eraser.Manager 30 34 { 31 /// <summary>32 /// An interface class representing the method for erasure. If classes only33 /// inherit this class, then the method can only be used to erase abstract34 /// streams, not unused drive space.35 /// </summary>36 public abstract class ErasureMethod : IRegisterable37 {38 public override string ToString()39 {40 if (Passes == 0)41 return Name;42 return Passes == 1 ? S._("{0} (1 pass)", Name) :43 S._("{0} ({1} passes)", Name, Passes);44 }45 46 /// <summary>47 /// The name of this erase pass, used for display in the UI48 /// </summary>49 public abstract string Name50 {51 get;52 }53 54 /// <summary>55 /// The number of erase passes for this erasure method.56 /// </summary>57 public abstract int Passes58 {59 get;60 }61 62 /// <summary>63 /// The GUID for this erasure method.64 /// </summary>65 public abstract Guid Guid66 {67 get;68 }69 70 /// <summary>71 /// Calculates the total size of the erasure data that needs to be written.72 /// This is mainly for use by the Manager to determine how much data needs73 /// to be written to disk.74 /// </summary>75 /// <param name="paths">The list containing the file paths to erase. This76 /// may be null if the list of paths are unknown.</param>77 /// <param name="targetSize">The precomputed value of the total size of78 /// the files to be erased.</param>79 /// <returns>The total size of the files that need to be erased.</returns>80 /// <remarks>This function MAY be slow. Most erasure methods can81 /// calculate this amount fairly quickly as the number of files and the82 /// total size of the files (the ones that take most computation time)83 /// are already provided. However some exceptional cases may take a84 /// long time if the data set is large.</remarks>85 public abstract long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize);86 87 /// <summary>88 /// The main bit of the class! This function is called whenever data has89 /// to be erased. Erase the stream passed in, using the given PRNG for90 /// randomness where necessary.91 ///92 /// This function should be implemented thread-safe as using the same93 /// instance, this function may be called across different threads.94 /// </summary>95 /// <param name="stream">The stream which needs to be erased.</param>96 /// <param name="erasureLength">The length of the stream to erase. If all97 /// data in the stream should be overwritten, then pass in the maximum98 /// value for long, the function will take the minimum.</param>99 /// <param name="prng">The PRNG source for random data.</param>100 /// <param name="callback">The progress callback function.</param>101 public abstract void Erase(Stream stream, long erasureLength, Prng prng,102 ErasureMethodProgressFunction callback);103 104 /// <summary>105 /// Disk operation write unit. Chosen such that this value mod 3, 4, 512,106 /// and 1024 is 0107 /// </summary>108 public const int DiskOperationUnit = 1536 * 4096;109 110 /// <summary>111 /// Unused space erasure file size. Each of the files used in erasing112 /// unused space will be of this size.113 /// </summary>114 public const int FreeSpaceFileUnit = DiskOperationUnit * 36;115 116 /// <summary>117 /// Shuffles the passes in the input array, effectively randomizing the118 /// order or rewrites.119 /// </summary>120 /// <param name="passes">The input set of passes.</param>121 /// <returns>The shuffled set of passes.</returns>122 protected static ErasureMethodPass[] ShufflePasses(ErasureMethodPass[] passes)123 {124 //Make a copy.125 ErasureMethodPass[] result = new ErasureMethodPass[passes.Length];126 passes.CopyTo(result, 0);127 128 //Randomize.129 Prng rand = ManagerLibrary.Instance.PrngRegistrar[ManagerLibrary.Settings.ActivePrng];130 for (int i = 0; i < result.Length; ++i)131 {132 int val = rand.Next(result.Length - 1);133 ErasureMethodPass tmpPass = result[val];134 result[val] = result[i];135 result[i] = tmpPass;136 }137 138 return result;139 }140 141 /// <summary>142 /// Helper function. This function will write random data to the stream143 /// using the provided PRNG.144 /// </summary>145 /// <param name="strm">The buffer to populate with data to write to disk.</param>146 /// <param name="prng">The PRNG used.</param>147 public static void WriteRandom(byte[] buffer, object value)148 {149 ((Prng)value).NextBytes(buffer);150 }151 152 /// <summary>153 /// Helper function. This function will write the repeating pass constant.154 /// to the provided buffer.155 /// </summary>156 /// <param name="strm">The buffer to populate with data to write to disk.</param>157 /// <param name="value">The byte[] to write.</param>158 public static void WriteConstant(byte[] buffer, object value)159 {160 byte[] constant = (byte[])value;161 for (int i = 0; i < buffer.Length; ++i)162 buffer[i] = constant[i % constant.Length];163 }164 }165 166 /// <summary>167 /// A simple callback for clients to retrieve progress information from168 /// the erase method.169 /// </summary>170 /// <param name="lastWritten">The amount of data written to the stream since171 /// the last call to the delegate.</param>172 /// <param name="totalData">The total amount of data that must be written to173 /// complete the erasure.</param>174 /// <param name="currentPass">The current pass number. The total number175 /// of passes can be found from the Passes property.</param>176 public delegate void ErasureMethodProgressFunction(long lastWritten, long totalData,177 int currentPass);178 179 /// <summary>180 /// A pass object. This object holds both the pass function, as well as the181 /// data used for the pass (random, byte, or triplet)182 /// </summary>183 public class ErasureMethodPass184 {185 public override string ToString()186 {187 return OpaqueValue == null ? S._("Random") : OpaqueValue.ToString();188 }189 190 /// <summary>191 /// Constructor.192 /// </summary>193 /// <param name="function">The delegate to the function.</param>194 /// <param name="opaqueValue">The opaque value passed to the function.</param>195 public ErasureMethodPass(ErasureMethodPassFunction function, object opaqueValue)196 {197 Function = function;198 OpaqueValue = opaqueValue;199 }200 201 /// <summary>202 /// Executes the pass.203 /// </summary>204 /// <param name="buffer">The buffer to populate with the data to write.</param>205 /// <param name="prng">The PRNG used for random passes.</param>206 public void Execute(byte[] buffer, Prng prng)207 {208 Function(buffer, OpaqueValue == null ? prng : OpaqueValue);209 }210 211 /// <summary>212 /// The function to execute for this pass.213 /// </summary>214 public ErasureMethodPassFunction Function { get; set; }215 216 /// <summary>217 /// The value to be passed to the executing function.218 /// </summary>219 public object OpaqueValue { get; set; }220 }221 222 /// <summary>223 /// The prototype of a pass.224 /// </summary>225 /// <param name="strm">The buffer to populate with data to write to disk.</param>226 /// <param name="opaque">An opaque value, depending on the type of callback.</param>227 public delegate void ErasureMethodPassFunction(byte[] buffer, object opaque);228 229 /// <summary>230 /// This class adds functionality to the ErasureMethod class to erase231 /// unused drive space.232 /// </summary>233 public abstract class UnusedSpaceErasureMethod : ErasureMethod234 {235 /// <summary>236 /// This function will allow clients to erase a file in a set of files237 /// used to fill the disk, thus achieving disk unused space erasure.238 ///239 /// By default, this function will simply call the Erase method inherited240 /// from the ErasureMethod class.241 ///242 /// This function should be implemented thread-safe as using the same243 /// instance, this function may be called across different threads.244 /// </summary>245 /// <param name="strm">The stream which needs to be erased.</param>246 /// <param name="prng">The PRNG source for random data.</param>247 /// <param name="callback">The progress callback function.</param>248 public virtual void EraseUnusedSpace(Stream stream, Prng prng, ErasureMethodProgressFunction callback)249 {250 Erase(stream, long.MaxValue, prng, callback);251 }252 }253 254 /// <summary>255 /// Pass-based erasure method. This subclass of erasure methods follow a fixed256 /// pattern (constant or random data) for every pass, although the order of257 /// passes can be randomized. This is to simplify definitions of classes in258 /// plugins.259 ///260 /// Since instances of this class apply data by passes, they can by default261 /// erase unused drive space as well.262 /// </summary>263 public abstract class PassBasedErasureMethod : UnusedSpaceErasureMethod264 {265 public override int Passes266 {267 get { return PassesSet.Length; }268 }269 270 /// <summary>271 /// Whether the passes should be randomized before running them in random272 /// order.273 /// </summary>274 protected abstract bool RandomizePasses275 {276 get;277 }278 279 /// <summary>280 /// The set of Pass objects describing the passes in this erasure method.281 /// </summary>282 protected abstract ErasureMethodPass[] PassesSet283 {284 get;285 }286 287 public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize)288 {289 //Simple. Amount of data multiplied by passes.290 return targetSize * Passes;291 }292 293 public override void Erase(Stream stream, long erasureLength, Prng prng,294 ErasureMethodProgressFunction callback)295 {296 //Randomize the order of the passes297 ErasureMethodPass[] randomizedPasses = PassesSet;298 if (RandomizePasses)299 randomizedPasses = ShufflePasses(randomizedPasses);300 301 //Remember the starting position of the stream.302 long strmStart = stream.Position;303 long strmLength = Math.Min(stream.Length - strmStart, erasureLength);304 long totalData = CalculateEraseDataSize(null, strmLength);305 306 //Allocate memory for a buffer holding data for the pass.307 byte[] buffer = new byte[Math.Min(DiskOperationUnit, strmLength)];308 309 //Run every pass!310 for (int pass = 0; pass < Passes; ++pass)311 {312 //Do a progress callback first.313 if (callback != null)314 callback(0, totalData, pass + 1);315 316 //Start from the beginning again317 stream.Seek(strmStart, SeekOrigin.Begin);318 319 //Write the buffer to disk.320 long toWrite = strmLength;321 int dataStopped = buffer.Length;322 while (toWrite > 0)323 {324 //Calculate how much of the buffer to write to disk.325 int amount = (int)Math.Min(toWrite, buffer.Length - dataStopped);326 327 //If we have no data left, get more!328 if (amount == 0)329 {330 randomizedPasses[pass].Execute(buffer, prng);331 dataStopped = 0;332 continue;333 }334 335 //Write the data.336 stream.Write(buffer, dataStopped, amount);337 stream.Flush();338 toWrite -= amount;339 340 //Do a progress callback.341 if (callback != null)342 callback(amount, totalData, pass + 1);343 }344 }345 }346 }347 348 35 /// <summary> 349 36 /// Class managing all the erasure methods. This class pairs GUIDs with constructor … … 383 70 384 71 public override void Erase(Stream strm, long erasureLength, Prng prng, 385 ErasureMethod ProgressFunction callback)72 ErasureMethod.ErasureMethodProgressFunction callback) 386 73 { 387 74 throw new InvalidOperationException("The DefaultMethod class should never " + -
branches/eraser6/pluginsRewrite/Eraser.Manager/ErasureTarget.cs
r2132 r2352 25 25 using System.Text; 26 26 27 using System.Runtime.Serialization; 27 28 using System.Security.Permissions; 28 using System.Runtime.Serialization;29 29 30 30 using Eraser.Util; 31 31 using Eraser.Util.ExtensionMethods; 32 using Eraser.Plugins; 33 using Eraser.Plugins.ExtensionPoints; 32 34 33 35 namespace Eraser.Manager 34 36 { 35 /// <summary>36 /// Represents a generic target of erasure37 /// </summary>38 [Serializable]39 public abstract class ErasureTarget : ISerializable, IRegisterable40 {41 #region Serialization code42 protected ErasureTarget(SerializationInfo info, StreamingContext context)43 {44 Guid methodGuid = (Guid)info.GetValue("Method", typeof(Guid));45 if (methodGuid == Guid.Empty)46 Method = ErasureMethodRegistrar.Default;47 else48 Method = ManagerLibrary.Instance.ErasureMethodRegistrar[methodGuid];49 }50 51 [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]52 public virtual void GetObjectData(SerializationInfo info, StreamingContext context)53 {54 info.AddValue("Method", Method.Guid);55 }56 #endregion57 58 #region IRegisterable Members59 60 public abstract Guid Guid61 {62 get;63 }64 65 #endregion66 67 /// <summary>68 /// Constructor.69 /// </summary>70 protected ErasureTarget()71 {72 Method = ErasureMethodRegistrar.Default;73 }74 75 /// <summary>76 /// The task which owns this target.77 /// </summary>78 public Task Task { get; internal set; }79 80 /// <summary>81 /// The name of the type of the Erasure target.82 /// </summary>83 public abstract string Name84 {85 get;86 }87 88 /// <summary>89 /// The method used for erasing the file.90 /// </summary>91 public ErasureMethod Method92 {93 get94 {95 return method;96 }97 set98 {99 if (!SupportsMethod(value))100 throw new ArgumentException(S._("The selected erasure method is not " +101 "supported for this erasure target."));102 method = value;103 }104 }105 106 /// <summary>107 /// Gets the effective erasure method for the current target (i.e., returns108 /// the correct erasure method for cases where the <see cref="Method"/>109 /// property is <see cref="ErasureMethodRegistrar.Default"/>110 /// </summary>111 /// <returns>The Erasure method which the target should be erased with.112 /// This function will never return <see cref="ErasureMethodRegistrar.Default"/></returns>113 public virtual ErasureMethod EffectiveMethod114 {115 get116 {117 if (Method != ErasureMethodRegistrar.Default)118 return Method;119 120 throw new InvalidOperationException("The effective method of the erasure " +121 "target cannot be ErasureMethodRegistrar.Default");122 }123 }124 125 /// <summary>126 /// Checks whether the provided erasure method is supported by this current127 /// target.128 /// </summary>129 /// <param name="method">The erasure method to check.</param>130 /// <returns>True if the erasure method is supported, false otherwise.</returns>131 public virtual bool SupportsMethod(ErasureMethod method)132 {133 return true;134 }135 136 /// <summary>137 /// Retrieves the text to display representing this target.138 /// </summary>139 public abstract string UIText140 {141 get;142 }143 144 /// <summary>145 /// The progress of this target.146 /// </summary>147 public ProgressManagerBase Progress148 {149 get;150 protected set;151 }152 153 /// <summary>154 /// The Progress Changed event handler of the owning task.155 /// </summary>156 protected internal Action<ErasureTarget, ProgressChangedEventArgs> OnProgressChanged157 {158 get;159 internal set;160 }161 162 /// <summary>163 /// Gets an <see cref="IErasureTargetConfigurer"/> which contains settings for164 /// configuring this task, or null if this erasure target has no settings to be set.165 /// </summary>166 /// <remarks>The result should be able to be passed to the <see cref="Configure"/>167 /// function, and settings for this task will be according to the returned168 /// control.</remarks>169 public abstract IErasureTargetConfigurer Configurer170 {171 get;172 }173 174 /// <summary>175 /// Executes the given target.176 /// </summary>177 public abstract void Execute();178 179 /// <summary>180 /// The backing variable for the <see cref="Method"/> property.181 /// </summary>182 private ErasureMethod method;183 }184 185 /// <summary>186 /// Represents an interface for an abstract erasure target configuration187 /// object.188 /// </summary>189 public interface IErasureTargetConfigurer : ICliConfigurer<ErasureTarget>190 {191 }192 193 37 public class ErasureTargetRegistrar : FactoryRegistrar<ErasureTarget> 194 38 { -
branches/eraser6/pluginsRewrite/Eraser.Manager/FileSystem.cs
r2161 r2352 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.IO; 25 26 26 using Eraser.Util; 27 using Eraser.Plugins; 28 using Eraser.Plugins.ExtensionPoints; 27 29 28 30 namespace Eraser.Manager 29 31 { 30 /// <summary>31 /// Provides functions to handle erasures specfic to file systems.32 /// </summary>33 public abstract class FileSystem : IRegisterable34 {35 /// <summary>36 /// Generates a random file name with the given length.37 /// </summary>38 /// <remarks>The generated file name is guaranteed not to exist.</remarks>39 /// <param name="info">The directory to generate the file name in. This40 /// parameter can be null to indicate merely a random file name</param>41 /// <param name="length">The length of the file name to generate.</param>42 /// <returns>A full path to a file containing random file name.</returns>43 public static string GenerateRandomFileName(DirectoryInfo info, int length)44 {45 //Get the PRNG we are going to use46 Prng prng = ManagerLibrary.Instance.PrngRegistrar[ManagerLibrary.Settings.ActivePrng];47 48 //Initialsie the base name, if any.49 string resultPrefix = info == null ? string.Empty : info.FullName +50 Path.DirectorySeparatorChar;51 52 //Variables to store the intermediates.53 byte[] resultAry = new byte[length];54 string result = string.Empty;55 List<string> prohibitedFileNames = new List<string>(new string[] {56 "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4",57 "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3",58 "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"59 });60 61 do62 {63 prng.NextBytes(resultAry);64 65 //Validate the name66 string validFileNameChars = "0123456789abcdefghijklmnopqrstuvwxyz" +67 "ABCDEFGHIJKLMNOPQRSTUVWXYZ _+=-()[]{}',`~!";68 for (int j = 0, k = resultAry.Length; j < k; ++j)69 {70 resultAry[j] = (byte)validFileNameChars[71 (int)resultAry[j] % validFileNameChars.Length];72 73 if (j == 0 || j == k - 1)74 //The first or last character cannot be whitespace75 while (Char.IsWhiteSpace((char)resultAry[j]))76 resultAry[j] = (byte)validFileNameChars[77 (int)resultAry[j] % validFileNameChars.Length];78 }79 80 result = Encoding.UTF8.GetString(resultAry);81 }82 while (info != null &&83 prohibitedFileNames.IndexOf(Path.GetFileNameWithoutExtension(result)) != -1 ||84 (Directory.Exists(resultPrefix + result) || File.Exists(resultPrefix + result)));85 return resultPrefix + result;86 }87 88 /// <summary>89 /// Gets a random file from within the provided directory.90 /// </summary>91 /// <param name="info">The directory to get a random file name from.</param>92 /// <returns>A string containing the full path to the file.</returns>93 public static string GetRandomFile(DirectoryInfo info)94 {95 //First retrieve the list of files and folders in the provided directory.96 FileSystemInfo[] entries = null;97 try98 {99 entries = info.GetFileSystemInfos();100 }101 catch (DirectoryNotFoundException)102 {103 return string.Empty;104 }105 if (entries.Length == 0)106 return string.Empty;107 108 //Find a random entry.109 Prng prng = ManagerLibrary.Instance.PrngRegistrar[ManagerLibrary.Settings.ActivePrng];110 string result = string.Empty;111 while (result.Length == 0)112 {113 int index = prng.Next(entries.Length - 1);114 if (entries[index] is DirectoryInfo)115 result = GetRandomFile((DirectoryInfo)entries[index]);116 else117 result = ((FileInfo)entries[index]).FullName;118 }119 120 return result;121 }122 123 /// <summary>124 /// Writes a file for plausible deniability over the current stream.125 /// </summary>126 /// <param name="stream">The stream to write the data to.</param>127 protected static void CopyPlausibleDeniabilityFile(Stream stream)128 {129 //Get the template file to copy130 FileInfo shadowFileInfo;131 {132 string shadowFile = null;133 List<string> entries = new List<string>(134 ManagerLibrary.Settings.PlausibleDeniabilityFiles);135 Prng prng = ManagerLibrary.Instance.PrngRegistrar[ManagerLibrary.Settings.ActivePrng];136 do137 {138 if (entries.Count == 0)139 throw new FatalException(S._("Plausible deniability was selected, " +140 "but no decoy files were found. The current file has been only " +141 "replaced with random data."));142 143 //Get an item from the list of files, and then check that the item exists.144 int index = prng.Next(entries.Count - 1);145 shadowFile = entries[index];146 if (File.Exists(shadowFile) || Directory.Exists(shadowFile))147 {148 if ((File.GetAttributes(shadowFile) & FileAttributes.Directory) != 0)149 {150 DirectoryInfo dir = new DirectoryInfo(shadowFile);151 FileInfo[] files = dir.GetFiles("*", SearchOption.AllDirectories);152 entries.Capacity += files.Length;153 foreach (FileInfo f in files)154 entries.Add(f.FullName);155 }156 else157 shadowFile = entries[index];158 }159 else160 shadowFile = null;161 162 entries.RemoveAt(index);163 }164 while (string.IsNullOrEmpty(shadowFile));165 shadowFileInfo = new FileInfo(shadowFile);166 }167 168 //Dump the copy (the first 4MB, or less, depending on the file size and size of169 //the original file)170 long amountToCopy = Math.Min(stream.Length,171 Math.Min(4 * 1024 * 1024, shadowFileInfo.Length));172 using (FileStream shadowFileStream = shadowFileInfo.OpenRead())173 {174 while (stream.Position < amountToCopy)175 {176 byte[] buf = new byte[524288];177 int bytesRead = shadowFileStream.Read(buf, 0, buf.Length);178 179 //Stop bothering if the input stream is at the end180 if (bytesRead == 0)181 break;182 183 //Dump the read contents onto the file to be deleted184 stream.Write(buf, 0,185 (int)Math.Min(bytesRead, amountToCopy - stream.Position));186 }187 }188 }189 190 /// <summary>191 /// The Guid of the current filesystem.192 /// </summary>193 public abstract Guid Guid194 {195 get;196 }197 198 /// <summary>199 /// The name of the current filesystem.200 /// </summary>201 public abstract string Name202 {203 get;204 }205 206 /// <summary>207 /// Resets the created, modified, accessed and last update times for the given208 /// <paramref name="info"/>.209 /// </summary>210 /// <param name="info">The file to reset times.</param>211 public abstract void ResetFileTimes(FileSystemInfo info);212 213 /// <summary>214 /// Securely deletes the file reference from the directory structures215 /// as well as resetting the Date Created, Date Accessed and Date Modified216 /// records.217 /// </summary>218 /// <param name="info">The file to delete.</param>219 public abstract void DeleteFile(FileInfo info);220 221 /// <summary>222 /// Securely deletes the folder reference from the directory structures223 /// as well as all subfolders and files, resetting the Date Created, Date224 /// Accessed and Date Modified records.225 /// </summary>226 /// <param name="info">The folder to delete</param>227 /// <param name="recursive">True if the folder and all its subfolders and228 /// files to be securely deleted.</param>229 public abstract void DeleteFolder(DirectoryInfo info, bool recursive);230 231 /// <seealso cref="DeleteFolder"/>232 /// <param name="info">The folder to delete.</param>233 public void DeleteFolder(DirectoryInfo info)234 {235 DeleteFolder(info, true);236 }237 238 /// <summary>239 /// Erases all file cluster tips in the given volume.240 /// </summary>241 /// <param name="info">The volume to search for file cluster tips and erase them.</param>242 /// <param name="method">The erasure method being employed.</param>243 /// <param name="log">The log manager instance that tracks log messages.</param>244 /// <param name="searchCallback">The callback function for search progress.</param>245 /// <param name="eraseCallback">The callback function for erasure progress.</param>246 public abstract void EraseClusterTips(VolumeInfo info, ErasureMethod method,247 ClusterTipsSearchProgress searchCallback, ClusterTipsEraseProgress eraseCallback);248 249 /// <summary>250 /// Erases old file system table-resident files. This creates small one-byte251 /// files until disk is full. This will erase unused space which was used for252 /// files resident in the file system table.253 /// </summary>254 /// <param name="volume">The directory information structure containing255 /// the path to store the temporary one-byte files. The file system table256 /// of that drive will be erased.</param>257 /// <param name="tempDirectory">The directory structure containing the path258 /// to store temporary files used for resident file cleaning.</param>259 /// <param name="method">The method used to erase the files.</param>260 public abstract void EraseOldFileSystemResidentFiles(VolumeInfo volume,261 DirectoryInfo tempDirectory, ErasureMethod method,262 FileSystemEntriesEraseProgress callback);263 264 /// <summary>265 /// Erases the unused space in the main filesystem structures by creating,266 /// files until the table grows.267 ///268 /// This will overwrite unused portions of the table which were previously269 /// used to store file entries.270 /// </summary>271 /// <param name="info">The directory information structure containing272 /// the path to store the temporary files.</param>273 /// <param name="callback">The callback function to handle the progress274 /// of the file system entry erasure.</param>275 public abstract void EraseDirectoryStructures(VolumeInfo info,276 FileSystemEntriesEraseProgress callback);277 278 /// <summary>279 /// Erases the file system object from the drive.280 /// </summary>281 /// <param name="info"></param>282 public abstract void EraseFileSystemObject(StreamInfo info, ErasureMethod method,283 ErasureMethodProgressFunction callback);284 285 //TODO: This is supposed to be in VolumeInfo!286 /// <summary>287 /// Retrieves the size of the file on disk, calculated by the amount of288 /// clusters allocated by it.289 /// </summary>290 /// <param name="streamInfo">The Stream to get the area for.</param>291 /// <returns>The area of the file.</returns>292 public abstract long GetFileArea(StreamInfo filePath);293 294 /// <summary>295 /// The number of times file names are renamed to erase the file name from296 /// the file system table.297 /// </summary>298 public const int FileNameErasePasses = 7;299 300 /// <summary>301 /// The maximum number of times Eraser tries to erase a file/folder before302 /// it gives up.303 /// </summary>304 public const int FileNameEraseTries = 50;305 }306 307 /// <summary>308 /// The function prototype for cluster tip search progress callbacks. This is309 /// called when the cluster tips are being searched.310 /// </summary>311 /// <param name="currentPath">The directory being searched</param>312 public delegate void ClusterTipsSearchProgress(string currentPath);313 314 /// <summary>315 /// The function prototype for cluster tip erasure callbacks. This is called when316 /// the cluster tips are being erased.317 /// </summary>318 /// <param name="currentFile">The current file index being erased.</param>319 /// <param name="totalFiles">The total number of files to be erased.</param>320 /// <param name="currentFilePath">The path to the current file being erased.</param>321 public delegate void ClusterTipsEraseProgress(int currentFile, int totalFiles,322 string currentFilePath);323 324 /// <summary>325 /// The prototype of callbacks handling the file system table erase progress.326 /// </summary>327 /// <param name="currentFile">The current file being erased.</param>328 /// <param name="totalFiles">The estimated number of files that must be329 /// erased.</param>330 public delegate void FileSystemEntriesEraseProgress(int currentFile, int totalFiles);331 332 32 public class FileSystemRegistrar : Registrar<FileSystem> 333 33 { -
branches/eraser6/pluginsRewrite/Eraser.Manager/PRNG.cs
r1802 r2352 32 32 using System.IO; 33 33 using Microsoft.Win32.SafeHandles; 34 34 35 using Eraser.Util; 36 using Eraser.Plugins; 37 using Eraser.Plugins.ExtensionPoints; 35 38 36 39 namespace Eraser.Manager 37 40 { 38 /// <summary>39 /// An interface class for all pseudorandom number generators used for the40 /// random data erase passes.41 /// </summary>42 public abstract class Prng : IRegisterable43 {44 public override string ToString()45 {46 return Name;47 }48 49 /// <summary>50 /// The name of this erase pass, used for display in the UI51 /// </summary>52 public abstract string Name53 {54 get;55 }56 57 /// <summary>58 /// The GUID for this PRNG.59 /// </summary>60 public abstract Guid Guid61 {62 get;63 }64 65 /// <summary>66 /// Reseeds the PRNG. This can be called by inherited classes, but its most67 /// important function is to provide new seeds regularly. The PRNGManager68 /// will call this function once in a whle to maintain the quality of69 /// generated numbers.70 /// </summary>71 /// <param name="seed">An arbitrary length of information that will be72 /// used to reseed the PRNG</param>73 protected internal abstract void Reseed(byte[] seed);74 75 #region Random members76 /// <summary>77 /// Returns a nonnegative random number less than the specified maximum.78 /// </summary>79 /// <param name="maxValue">The exclusive upper bound of the random number80 /// to be generated. maxValue must be greater than or equal to zero.</param>81 /// <returns>A 32-bit signed integer greater than or equal to zero, and82 /// less than maxValue; that is, the range of return values ordinarily83 /// includes zero but not maxValue. However, if maxValue equals zero,84 /// maxValue is returned.</returns>85 public int Next(int maxValue)86 {87 if (maxValue == 0)88 return 0;89 return Next() % maxValue;90 }91 92 /// <summary>93 /// Returns a random number within a specified range.94 /// </summary>95 /// <param name="minValue">The inclusive lower bound of the random number96 /// returned.</param>97 /// <param name="maxValue">The exclusive upper bound of the random number98 /// returned. maxValue must be greater than or equal to minValue.</param>99 /// <returns>A 32-bit signed integer greater than or equal to minValue and100 /// less than maxValue; that is, the range of return values includes minValue101 /// but not maxValue. If minValue equals maxValue, minValue is returned.</returns>102 public int Next(int minValue, int maxValue)103 {104 if (minValue > maxValue)105 throw new ArgumentOutOfRangeException("minValue", minValue,106 "minValue is greater than maxValue");107 else if (minValue == maxValue)108 return minValue;109 return (Next() % (maxValue - minValue)) + minValue;110 }111 112 /// <summary>113 /// Returns a nonnegative random number.114 /// </summary>115 /// <returns>A 32-bit signed integer greater than or equal to zero and less116 /// than System.Int32.MaxValue.</returns>117 public int Next()118 {119 //Get the random-valued bytes to fill the int.120 byte[] rand = new byte[sizeof(int)];121 NextBytes(rand);122 123 //Then return the integral representation of the buffer.124 return Math.Abs(BitConverter.ToInt32(rand, 0));125 }126 127 /// <summary>128 /// Fills the elements of a specified array of bytes with random numbers.129 /// </summary>130 /// <param name="buffer">An array of bytes to contain random numbers.</param>131 public abstract void NextBytes(byte[] buffer);132 #endregion133 }134 135 41 /// <summary> 136 42 /// Class managing all the PRNG algorithms. -
branches/eraser6/pluginsRewrite/Eraser.Manager/Strings.en.resx
r2286 r2352 118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 119 119 </resheader> 120 <data name="{0} (1 pass)" xml:space="preserve">121 <value>{0} (1 pass)</value>122 </data>123 <data name="{0} ({1} passes)" xml:space="preserve">124 <value>{0} ({1} passes)</value>125 </data>126 <data name="Random" xml:space="preserve">127 <value>Random</value>128 </data>129 120 <data name="(default)" xml:space="preserve"> 130 121 <value>(default)</value> 131 </data>132 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve">133 <value>The selected erasure method is not supported for this erasure target.</value>134 122 </data> 135 123 <data name="EntropySource GUID not found: {0}" xml:space="preserve"> … … 141 129 <data name="PRNG not found: {0}" xml:space="preserve"> 142 130 <value>PRNG not found: {0}</value> 143 </data>144 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve">145 <value>Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data.</value>146 131 </data> 147 132 <data name="The file system on the drive {0} is not supported." xml:space="preserve"> -
branches/eraser6/pluginsRewrite/Eraser.Manager/Strings.it.resx
r2286 r2352 118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 119 119 </resheader> 120 <data name="{0} (1 pass)" xml:space="preserve">121 <value>{0} (1 passo)</value>122 </data>123 <data name="{0} ({1} passes)" xml:space="preserve">124 <value>{0} ({1} passi)</value>125 </data>126 <data name="Random" xml:space="preserve">127 <value>Casuale</value>128 </data>129 120 <data name="(default)" xml:space="preserve"> 130 <value>(Untranslated)</value>131 </data>132 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve">133 121 <value>(Untranslated)</value> 134 122 </data> … … 141 129 <data name="PRNG not found: {0}" xml:space="preserve"> 142 130 <value>PRNG not found: {0}</value> 143 </data>144 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve">145 <value>E' stata selezionata una "Plausible deniability", but no decoy files were found. The current file has been only replaced with random data.</value>146 131 </data> 147 132 <data name="The file system on the drive {0} is not supported." xml:space="preserve"> -
branches/eraser6/pluginsRewrite/Eraser.Manager/Strings.nl.resx
r2286 r2352 118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 119 119 </resheader> 120 <data name="{0} (1 pass)" xml:space="preserve">121 <value>(Untranslated)</value>122 </data>123 <data name="{0} ({1} passes)" xml:space="preserve">124 <value>(Untranslated)</value>125 </data>126 <data name="Random" xml:space="preserve">127 <value>(Untranslated)</value>128 </data>129 120 <data name="(default)" xml:space="preserve"> 130 <value>(Untranslated)</value>131 </data>132 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve">133 121 <value>(Untranslated)</value> 134 122 </data> … … 140 128 </data> 141 129 <data name="PRNG not found: {0}" xml:space="preserve"> 142 <value>(Untranslated)</value>143 </data>144 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve">145 130 <value>(Untranslated)</value> 146 131 </data> -
branches/eraser6/pluginsRewrite/Eraser.Manager/Strings.pl.resx
r2286 r2352 118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 119 119 </resheader> 120 <data name="{0} (1 pass)" xml:space="preserve">121 <value>{0} (1 przebieg)</value>122 </data>123 <data name="{0} ({1} passes)" xml:space="preserve">124 <value>{0} ({1} przebiegów)</value>125 </data>126 <data name="Random" xml:space="preserve">127 <value>Losowy</value>128 </data>129 120 <data name="(default)" xml:space="preserve"> 130 121 <value>(domyślny)</value> 131 </data>132 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve">133 <value>(Untranslated)</value>134 122 </data> 135 123 <data name="EntropySource GUID not found: {0}" xml:space="preserve"> … … 141 129 <data name="PRNG not found: {0}" xml:space="preserve"> 142 130 <value>Nie znaleziono PRNG: {0}</value> 143 </data>144 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve">145 <value>Wybrano wymazywanie z opcją prawdopodobnego zaprzeczenia, ale nie wybrano żadnych plików na przynęte. Obecny plik został zastąpiony danymi losowymi.</value>146 131 </data> 147 132 <data name="The file system on the drive {0} is not supported." xml:space="preserve"> -
branches/eraser6/pluginsRewrite/Eraser.Manager/Strings.resx
r2286 r2352 118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 119 119 </resheader> 120 <data name="{0} (1 pass)" xml:space="preserve">121 <value>{0} (1 pass)</value>122 </data>123 <data name="{0} ({1} passes)" xml:space="preserve">124 <value>{0} ({1} passes)</value>125 </data>126 <data name="Random" xml:space="preserve">127 <value>Random</value>128 </data>129 120 <data name="(default)" xml:space="preserve"> 130 121 <value>(default)</value> 131 </data>132 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve">133 <value>The selected erasure method is not supported for this erasure target.</value>134 122 </data> 135 123 <data name="EntropySource GUID not found: {0}" xml:space="preserve"> … … 141 129 <data name="PRNG not found: {0}" xml:space="preserve"> 142 130 <value>PRNG not found: {0}</value> 143 </data>144 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve">145 <value>Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data.</value>146 131 </data> 147 132 <data name="The file system on the drive {0} is not supported." xml:space="preserve"> -
branches/eraser6/pluginsRewrite/Eraser.Plugins/Eraser.Plugins.csproj
r2346 r2352 54 54 </Compile> 55 55 <Compile Include="AssemblyInfo.cs" /> 56 <Compile Include="ExtensionPoints\EntropySource.cs" /> 57 <Compile Include="ExtensionPoints\ErasureMethod.cs" /> 58 <Compile Include="ExtensionPoints\ErasureTarget.cs" /> 59 <Compile Include="ExtensionPoints\FileSystem.cs" /> 60 <Compile Include="ExtensionPoints\Prng.cs" /> 56 61 <Compile Include="IConfigurer.cs" /> 57 62 <Compile Include="IPlugin.cs" /> -
branches/eraser6/pluginsRewrite/Eraser.Plugins/IRegistrar.cs
r2286 r2352 26 26 using System.Reflection; 27 27 28 namespace Eraser. Manager28 namespace Eraser.Plugins 29 29 { 30 30 /// <summary> -
branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.en.resx
r2346 r2352 127 127 <value>Could not load the plugin.</value> 128 128 </data> 129 <data name="{0} (1 pass)" xml:space="preserve"> 130 <value>{0} (1 pass)</value> 131 </data> 132 <data name="{0} ({1} passes)" xml:space="preserve"> 133 <value>{0} ({1} passes)</value> 134 </data> 135 <data name="Random" xml:space="preserve"> 136 <value>Random</value> 137 </data> 138 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 139 <value>The selected erasure method is not supported for this erasure target.</value> 140 </data> 141 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve"> 142 <value>Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data.</value> 143 </data> 129 144 </root> -
branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.it.resx
r2346 r2352 127 127 <value>(Untranslated)</value> 128 128 </data> 129 <data name="{0} (1 pass)" xml:space="preserve"> 130 <value>(Untranslated)</value> 131 </data> 132 <data name="{0} ({1} passes)" xml:space="preserve"> 133 <value>(Untranslated)</value> 134 </data> 135 <data name="Random" xml:space="preserve"> 136 <value>(Untranslated)</value> 137 </data> 138 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 139 <value>(Untranslated)</value> 140 </data> 141 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve"> 142 <value>(Untranslated)</value> 143 </data> 129 144 </root> -
branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.nl.resx
r2346 r2352 127 127 <value>(Untranslated)</value> 128 128 </data> 129 <data name="{0} (1 pass)" xml:space="preserve"> 130 <value>(Untranslated)</value> 131 </data> 132 <data name="{0} ({1} passes)" xml:space="preserve"> 133 <value>(Untranslated)</value> 134 </data> 135 <data name="Random" xml:space="preserve"> 136 <value>(Untranslated)</value> 137 </data> 138 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 139 <value>(Untranslated)</value> 140 </data> 141 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve"> 142 <value>(Untranslated)</value> 143 </data> 129 144 </root> -
branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.pl.resx
r2346 r2352 127 127 <value>(Untranslated)</value> 128 128 </data> 129 <data name="{0} (1 pass)" xml:space="preserve"> 130 <value>(Untranslated)</value> 131 </data> 132 <data name="{0} ({1} passes)" xml:space="preserve"> 133 <value>(Untranslated)</value> 134 </data> 135 <data name="Random" xml:space="preserve"> 136 <value>(Untranslated)</value> 137 </data> 138 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 139 <value>(Untranslated)</value> 140 </data> 141 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve"> 142 <value>(Untranslated)</value> 143 </data> 129 144 </root> -
branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.resx
r2346 r2352 127 127 <value>Could not load the plugin.</value> 128 128 </data> 129 <data name="{0} (1 pass)" xml:space="preserve"> 130 <value>{0} (1 pass)</value> 131 </data> 132 <data name="{0} ({1} passes)" xml:space="preserve"> 133 <value>{0} ({1} passes)</value> 134 </data> 135 <data name="Random" xml:space="preserve"> 136 <value>Random</value> 137 </data> 138 <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 139 <value>The selected erasure method is not supported for this erasure target.</value> 140 </data> 141 <data name="Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data." xml:space="preserve"> 142 <value>Plausible deniability was selected, but no decoy files were found. The current file has been only replaced with random data.</value> 143 </data> 129 144 </root>
Note: See TracChangeset
for help on using the changeset viewer.
