6

いくつかのラップトップの空き容量をすべて 3 回上書きするように依頼されました。いくつかの代替手段があることは知っていますが、物事がどのように機能するか、C# で自分でできるかどうかを知りたいです。

1) はい、これを行うフリーウェア アプリケーションがたくさんあることは知っています。

2) いいえ、特定の政府基準に準拠する必要はありません。

これを開始する方法についてのアイデアはどこで探せばよいですか?

正しい方向に向けていただければ幸いです。

C# を使用して実現できますか? もしそうなら、どのように?

4

6 に答える 6

3

これは本当に危険ですが..

Defrag API(ここではC#ラッパー)を使用して、ドライブの「マップ」を取得し、特に空き領域をターゲットにして、ディスクのそれらの部分にジャンクを書き込むことができます。

于 2010-01-14T15:33:08.050 に答える
3

単純なアルゴリズム:

  • 任意のテキストでいっぱいの大きなテキスト ファイルを作成します (パフォーマンス上の理由から、ランダムに再生成するのではなく、事前に作成されたファイルを使用することをお勧めします。テストしてください)。
  • ファイルを追跡できるように、巧妙なフォルダーとファイルの命名スキームを作成します。また、アプリでファイルを追跡する必要がありますが、特に最初の数回のテスト実行の終わり近くでアプリがクラッシュした場合は、便利な作業を簡単に見つけてクリーンアップできるようにする必要があります。
  • HDDがいっぱいになるまで書き込む
  • 作成したファイルを削除する
  • 上記の手順をあと 2 回繰り返します

更新:その後の議論によるワイプに関するより高度な考慮事項:

  • 最初のパスでは、値が 0x0000 のファイルを書き込みます (すべてのビットがオフ)
  • 2 番目のパスでは、すべてのビットを 0xFFFF として書き込みます (すべてのビットがオン)。
  • 最後のパスで 0x0000 で繰り返す

上記は、ファイルの最適なサイズは何か、とにかくファイルシステムに依存するなど、いくつかのアイデアを無視しています。また、満杯の HDD に近づくと、OS から異なる動作が発生する可能性があります...

于 2010-01-14T15:21:07.983 に答える
1

SDeleteのドキュメントを確認してください。手がかりが得られるかもしれません。

于 2010-01-14T15:23:10.533 に答える
0

いくつかの低レベルの操作を行う必要があるため、確実に Win32 API と対話する必要があります。私はこの種のことを行っていないので、詳細を説明することはできませんが、探し始めるのに適した場所は Win32 API リファレンスです: http://msdn.microsoft.com/en-us/library/aa383749 %28VS.85%29.aspx

私はこの分野の専門家ではありませんが、私の素朴な理解では、次のことを行う必要があるように思われます。空き領域の物理的な場所のリストを取得する 3) それらの場所に 0 を書き込む

私はその分野の専門家ではないので、これは素晴らしい答えではないかもしれませんが、コメントするには少し長すぎました;)少し役立つことを願っています.

于 2010-01-14T15:21:42.210 に答える
0

このコードはThe Code Project のものだと思います。元の記事がどこにあるかはわかりませんが、あなたが要求したことを実行します:

コメントに基づいて、私は明らかにもう少しスプーンフィードする必要があります..

これは、要件に基づいて非常に簡単に行うことができます。

  1. ドライブの残りの空きサイズを満たす 1 つの大きなファイルを作成します。次に、このファイルを消去します。

  2. ドライブがいっぱいになるまで、いくつかのファイルを作成します。(進行中にマシンを使用したい場合は、これの方が良いかもしれません)。その後、各ファイルのワイプを開始できるため、実質的に、システムのハード ディスク ドライブがいっぱいになっている合計時間は、方法 1 を使用するよりも短くなります。

を使用する利点は、いくつかの簡単なコードを使用できることです。あなたを台無しにするような低レベルの API をいじる必要はありません。

using System;
using System.IO;
using System.Security.Cryptography;

namespace QuickStarterShared
{
    public class Wipe
    {
        /// <summary>
        /// Deletes a file in a secure way by overwriting it with
        /// random garbage data n times.
        /// </summary>
        /// <param name="filename">Full path of the file to be deleted</param>
        /// <param name="timesToWrite">Specifies the number of times the file should be overwritten</param>
        public void WipeFile(string filename, int timesToWrite)
        {
#if !DEBUG
            try
            {
#endif
                if (File.Exists(filename))
                {
                    // Set the files attributes to normal in case it's read-only.
                    File.SetAttributes(filename, FileAttributes.Normal);

                    // Calculate the total number of sectors in the file.
                    double sectors = Math.Ceiling(new FileInfo(filename).Length/512.0);

                    // Create a dummy-buffer the size of a sector.
                    byte[] dummyBuffer = new byte[512];

                    // Create a cryptographic Random Number Generator.
                    // This is what I use to create the garbage data.
                    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

                    // Open a FileStream to the file.
                    FileStream inputStream = new FileStream(filename, FileMode.Open);
                    for (int currentPass = 0; currentPass < timesToWrite; currentPass++)
                    {
                        // Go to the beginning of the stream
                        inputStream.Position = 0;

                        // Loop all sectors
                        for (int sectorsWritten = 0; sectorsWritten < sectors; sectorsWritten++)
                        {
                            // Fill the dummy-buffer with random data
                            rng.GetBytes(dummyBuffer);
                            // Write it to the stream
                            inputStream.Write(dummyBuffer, 0, dummyBuffer.Length);
                        }
                    }
                    // Truncate the file to 0 bytes.
                    // This will hide the original file-length if you try to recover the file.
                    inputStream.SetLength(0);
                    // Close the stream.
                    inputStream.Close();

                    // As an extra precaution I change the dates of the file so the
                    // original dates are hidden if you try to recover the file.
                    DateTime dt = new DateTime(2037, 1, 1, 0, 0, 0);
                    File.SetCreationTime(filename, dt);
                    File.SetLastAccessTime(filename, dt);
                    File.SetLastWriteTime(filename, dt);

                    File.SetCreationTimeUtc(filename, dt);
                    File.SetLastAccessTimeUtc(filename, dt);
                    File.SetLastWriteTimeUtc(filename, dt);

                    // Finally, delete the file
                    File.Delete(filename);
                }
#if !DEBUG
            }
            catch(Exception e)
            {

            }
#endif
        }
    }

    # region Events
    # region PassInfo
    public delegate void PassInfoEventHandler(PassInfoEventArgs e); 
    public class PassInfoEventArgs : EventArgs
    {
        private readonly int cPass;
        private readonly int tPass;

        public PassInfoEventArgs(int currentPass, int totalPasses)
        {
            cPass = currentPass;
            tPass = totalPasses;
        }

        /// <summary> Get the current pass </summary>
        public int CurrentPass { get { return cPass; } }
        /// <summary> Get the total number of passes to be run </summary> 
        public int TotalPasses { get { return tPass; } }
    }
    # endregion

    # region SectorInfo        
    public delegate void SectorInfoEventHandler(SectorInfoEventArgs e);
    public class SectorInfoEventArgs : EventArgs
    {
        private readonly int cSector;
        private readonly int tSectors;

        public SectorInfoEventArgs(int currentSector, int totalSectors)
        {
            cSector = currentSector;
            tSectors = totalSectors;
        }

        /// <summary> Get the current sector </summary> 
        public int CurrentSector { get { return cSector; } }
        /// <summary> Get the total number of sectors to be run </summary> 
        public int TotalSectors { get { return tSectors; } }
    }
    # endregion

    # region WipeDone        
    public delegate void WipeDoneEventHandler(WipeDoneEventArgs e);
    public class WipeDoneEventArgs : EventArgs
    {
    }
    # endregion

    # region WipeError
    public delegate void WipeErrorEventHandler(WipeErrorEventArgs e);
    public class WipeErrorEventArgs : EventArgs
    {
        private readonly Exception e;

        public WipeErrorEventArgs(Exception error)
        {
            e = error;
        }

        public Exception WipeError{get{ return e;}}
    }
    # endregion
    # endregion
}
于 2010-01-14T15:24:24.883 に答える
-1
System.Diagonstics.Process.Start("chipher.exe /WC:\");

これはデフォルトで非同期です。

于 2010-01-14T15:26:53.287 に答える