Ejemplo n.º 1
0
      public override void EraseFileSystemObject(StreamInfo info, ErasureMethod method,
 ErasureMethodProgressFunction callback)
      {
          VolumeInfo volume = VolumeInfo.FromMountpoint(info.DirectoryName);
             if (info.Length < Math.Max(volume.ClusterSize, 1024))
             {
          using (FileStream strm = info.Open(FileMode.Open, FileAccess.Write,
           FileShare.None))
          {
           method.Erase(strm, long.MaxValue,
            PrngManager.GetInstance(ManagerLibrary.Settings.ActivePrng), null);
          }
             }
             long fileArea = GetFileArea(info.FullName);
             if (fileArea == 0)
          return;
             using (FileStream strm = info.Open(FileMode.Open, FileAccess.Write,
          FileShare.None, FileOptions.WriteThrough))
             {
          strm.SetLength(fileArea);
          method.Erase(strm, long.MaxValue,
           PrngManager.GetInstance(ManagerLibrary.Settings.ActivePrng),
           callback
          );
          strm.Seek(0, SeekOrigin.Begin);
          strm.SetLength(0);
             }
      }
Ejemplo n.º 2
0
      public override void EraseClusterTips(VolumeInfo info, ErasureMethod method,
 ClusterTipsSearchProgress searchCallback, ClusterTipsEraseProgress eraseCallback)
      {
          List<string> files = new List<string>();
             if (!info.IsMounted)
          throw new InvalidOperationException(S._("Could not erase cluster tips in {0} " +
           "as the volume is not mounted.", info.VolumeId));
             ListFiles(new DirectoryInfo(info.MountPoints[0]), files, searchCallback);
             for (int i = 0, j = files.Count; i != j; ++i)
             {
          StreamInfo streamInfo = new StreamInfo(files[i]);
          FileAttributes fileAttr = streamInfo.Attributes;
          try
          {
           streamInfo.Attributes = FileAttributes.Normal;
           EraseFileClusterTips(files[i], method);
          }
          catch (UnauthorizedAccessException)
          {
           Logger.Log(S._("{0} did not have its cluster tips erased because you do not " +
            "have the required permissions to erase the file cluster tips.", files[i]),
            LogLevel.Information);
          }
          catch (IOException e)
          {
           Logger.Log(S._("{0} did not have its cluster tips erased. The error returned " +
            "was: {1}", files[i], e.Message), LogLevel.Error);
          }
          finally
          {
           streamInfo.Attributes = fileAttr;
          }
          eraseCallback(i, files.Count, files[i]);
             }
      }
Ejemplo n.º 3
0
 public FirstLast16KB()
 {
     try
        {
     if (DefaultPlugin.Settings.FL16Method != Guid.Empty)
      method = ErasureMethodManager.GetInstance(
       DefaultPlugin.Settings.FL16Method);
     else if (ManagerLibrary.Settings.DefaultFileErasureMethod != Guid)
      method = ErasureMethodManager.GetInstance(
       ManagerLibrary.Settings.DefaultFileErasureMethod);
     else
      method = ErasureMethodManager.GetInstance(new Gutmann().Guid);
        }
        catch (ErasureMethodNotFoundException)
        {
     MessageBox.Show(S._("The First/last 16KB erasure method " +
      "requires another erasure method to erase the file.\n\nThis must " +
      "be set in the Plugin Settings dialog."), Name, MessageBoxButtons.OK,
      MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
      S.IsRightToLeft(null) ? MessageBoxOptions.RtlReading : 0);
        }
 }
Ejemplo n.º 4
0
 private void EraseFileClusterTips(string file, ErasureMethod method)
 {
     StreamInfo streamInfo = new StreamInfo(file);
        DateTime lastAccess = streamInfo.LastAccessTime;
        DateTime lastWrite = streamInfo.LastWriteTime;
        DateTime created = streamInfo.CreationTime;
        long fileArea = GetFileArea(file);
        long fileLength = streamInfo.Length;
        if (fileArea == fileLength)
     return;
        using (FileStream stream = streamInfo.Open(FileMode.Open, FileAccess.Write,
     FileShare.None, FileOptions.WriteThrough))
        {
     try
     {
      stream.SetLength(fileArea);
      stream.Seek(fileLength, SeekOrigin.Begin);
      method.Erase(stream, long.MaxValue, PrngManager.GetInstance(
       ManagerLibrary.Settings.ActivePrng), null);
     }
     finally
     {
      stream.SetLength(fileLength);
      streamInfo.LastAccessTime = lastAccess;
      streamInfo.LastWriteTime = lastWrite;
      streamInfo.CreationTime = created;
     }
        }
 }
Ejemplo n.º 5
0
      public override void EraseOldFileSystemResidentFiles(VolumeInfo volume,
 DirectoryInfo tempDirectory, ErasureMethod method,
 FileSystemEntriesEraseProgress callback)
      {
          try
             {
          long oldMFTSize = NtfsApi.GetMftValidSize(volume);
          for (; ; )
          {
           using (FileStream strm = new FileStream(
            GenerateRandomFileName(tempDirectory, 18), FileMode.CreateNew,
            FileAccess.Write, FileShare.None, 8, FileOptions.WriteThrough))
           {
            long streamSize = 0;
            try
            {
             while (true)
             {
          strm.SetLength(++streamSize);
          method.Erase(strm, long.MaxValue,
           PrngManager.GetInstance(ManagerLibrary.Settings.ActivePrng),
           null);
             }
            }
            catch (IOException)
            {
             if (streamSize == 1)
          return;
            }
           }
           if (NtfsApi.GetMftValidSize(volume) > oldMFTSize)
            break;
          }
             }
             catch (IOException)
             {
             }
      }
Ejemplo n.º 6
0
      public abstract void EraseOldFileSystemResidentFiles(VolumeInfo volume,
 DirectoryInfo tempDirectory, ErasureMethod method,
 FileSystemEntriesEraseProgress callback);
Ejemplo n.º 7
0
      public abstract void EraseFileSystemObject(StreamInfo info, ErasureMethod method,
 ErasureMethodProgressFunction callback);
Ejemplo n.º 8
0
      public abstract void EraseClusterTips(VolumeInfo info, ErasureMethod method,
 Logger log, ClusterTipsSearchProgress searchCallback,
 ClusterTipsEraseProgress eraseCallback);
Ejemplo n.º 9
0
      public override void EraseFileSystemObject(StreamInfo info, ErasureMethod method,
 ErasureMethodProgressFunction callback)
      {
          long fileArea = GetFileArea(info.FullName);
             using (FileStream strm = info.Open(FileMode.Open, FileAccess.Write,
          FileShare.None, FileOptions.WriteThrough))
             {
          strm.SetLength(fileArea);
          if (strm.Length != 0)
          {
           method.Erase(strm, long.MaxValue,
            PrngManager.GetInstance(ManagerLibrary.Settings.ActivePrng),
            callback
           );
          }
          strm.Seek(0, SeekOrigin.Begin);
          strm.SetLength(0);
             }
      }
Ejemplo n.º 10
0
 public static void Register(ErasureMethod method, object[] parameters)
 {
     ConstructorInfo ctor = null;
        if (parameters == null || parameters.Length == 0)
     ctor = method.GetType().GetConstructor(Type.EmptyTypes);
        else
        {
     Type[] parameterTypes = new Type[parameters.Length];
     for (int i = 0; i < parameters.Length; ++i)
      parameterTypes[i] = parameters[i].GetType();
     ctor = method.GetType().GetConstructor(parameterTypes);
        }
        if (ctor == null)
     throw new ArgumentException(S._("Registered erasure methods must contain " +
      "a parameterless constructor that is called whenever clients request " +
      "for an instance of the method. If a constructor requires parameters, " +
      "specify it in the parameters parameter."));
        lock (ManagerLibrary.Instance.ErasureMethodManager.methods)
        {
     MethodConstructorInfo info = new MethodConstructorInfo();
     info.Constructor = ctor;
     info.Parameters = parameters == null || parameters.Length == 0 ? null : parameters;
     ManagerLibrary.Instance.ErasureMethodManager.methods.Add(method.Guid, info);
        }
        OnMethodRegistered(new ErasureMethodRegistrationEventArgs(method.Guid));
 }
Ejemplo n.º 11
0
 public static void Register(ErasureMethod method)
 {
     Register(method, new object[0]);
 }