Changeset 2360
- Timestamp:
- 11/7/2011 7:03:45 AM (19 months ago)
- Location:
- branches/eraser6/pluginsRewrite
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/pluginsRewrite/Eraser.DefaultPlugins/ErasureTargets/FileSystemObjectErasureTarget.cs
r2344 r2360 369 369 } 370 370 } 371 372 /// <summary> 373 /// Writes a file for plausible deniability over the current stream. 374 /// </summary> 375 /// <param name="stream">The stream to write the data to.</param> 376 protected static void CopyPlausibleDeniabilityFile(Stream stream) 377 { 378 //Get the template file to copy 379 FileInfo shadowFileInfo; 380 { 381 string shadowFile = null; 382 List<string> entries = new List<string>( 383 ManagerLibrary.Settings.PlausibleDeniabilityFiles); 384 Prng prng = Host.Instance.Prngs.ActivePrng; 385 do 386 { 387 if (entries.Count == 0) 388 throw new FatalException(S._("Plausible deniability was selected, " + 389 "but no decoy files were found. The current file has been only " + 390 "replaced with random data.")); 391 392 //Get an item from the list of files, and then check that the item exists. 393 int index = prng.Next(entries.Count - 1); 394 shadowFile = entries[index]; 395 if (File.Exists(shadowFile) || Directory.Exists(shadowFile)) 396 { 397 if ((File.GetAttributes(shadowFile) & FileAttributes.Directory) != 0) 398 { 399 DirectoryInfo dir = new DirectoryInfo(shadowFile); 400 FileInfo[] files = dir.GetFiles("*", SearchOption.AllDirectories); 401 entries.Capacity += files.Length; 402 foreach (FileInfo f in files) 403 entries.Add(f.FullName); 404 } 405 else 406 shadowFile = entries[index]; 407 } 408 else 409 shadowFile = null; 410 411 entries.RemoveAt(index); 412 } 413 while (string.IsNullOrEmpty(shadowFile)); 414 shadowFileInfo = new FileInfo(shadowFile); 415 } 416 417 //Dump the copy (the first 4MB, or less, depending on the file size and size of 418 //the original file) 419 long amountToCopy = Math.Min(stream.Length, 420 Math.Min(4 * 1024 * 1024, shadowFileInfo.Length)); 421 using (FileStream shadowFileStream = shadowFileInfo.OpenRead()) 422 { 423 while (stream.Position < amountToCopy) 424 { 425 byte[] buf = new byte[524288]; 426 int bytesRead = shadowFileStream.Read(buf, 0, buf.Length); 427 428 //Stop bothering if the input stream is at the end 429 if (bytesRead == 0) 430 break; 431 432 //Dump the read contents onto the file to be deleted 433 stream.Write(buf, 0, 434 (int)Math.Min(bytesRead, amountToCopy - stream.Position)); 435 } 436 } 437 } 371 438 } 372 439 } -
branches/eraser6/pluginsRewrite/Eraser.Plugins/ExtensionPoints/FileSystem.cs
r2359 r2360 122 122 123 123 return result; 124 }125 126 /// <summary>127 /// Writes a file for plausible deniability over the current stream.128 /// </summary>129 /// <param name="stream">The stream to write the data to.</param>130 protected static void CopyPlausibleDeniabilityFile(Stream stream)131 {132 //Get the template file to copy133 FileInfo shadowFileInfo;134 {135 string shadowFile = null;136 List<string> entries = new List<string>(137 ManagerLibrary.Settings.PlausibleDeniabilityFiles);138 Prng prng = Host.Instance.Prngs.ActivePrng;139 do140 {141 if (entries.Count == 0)142 throw new FatalException(S._("Plausible deniability was selected, " +143 "but no decoy files were found. The current file has been only " +144 "replaced with random data."));145 146 //Get an item from the list of files, and then check that the item exists.147 int index = prng.Next(entries.Count - 1);148 shadowFile = entries[index];149 if (File.Exists(shadowFile) || Directory.Exists(shadowFile))150 {151 if ((File.GetAttributes(shadowFile) & FileAttributes.Directory) != 0)152 {153 DirectoryInfo dir = new DirectoryInfo(shadowFile);154 FileInfo[] files = dir.GetFiles("*", SearchOption.AllDirectories);155 entries.Capacity += files.Length;156 foreach (FileInfo f in files)157 entries.Add(f.FullName);158 }159 else160 shadowFile = entries[index];161 }162 else163 shadowFile = null;164 165 entries.RemoveAt(index);166 }167 while (string.IsNullOrEmpty(shadowFile));168 shadowFileInfo = new FileInfo(shadowFile);169 }170 171 //Dump the copy (the first 4MB, or less, depending on the file size and size of172 //the original file)173 long amountToCopy = Math.Min(stream.Length,174 Math.Min(4 * 1024 * 1024, shadowFileInfo.Length));175 using (FileStream shadowFileStream = shadowFileInfo.OpenRead())176 {177 while (stream.Position < amountToCopy)178 {179 byte[] buf = new byte[524288];180 int bytesRead = shadowFileStream.Read(buf, 0, buf.Length);181 182 //Stop bothering if the input stream is at the end183 if (bytesRead == 0)184 break;185 186 //Dump the read contents onto the file to be deleted187 stream.Write(buf, 0,188 (int)Math.Min(bytesRead, amountToCopy - stream.Position));189 }190 }191 124 } 192 125
Note: See TracChangeset
for help on using the changeset viewer.
