mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-04-21 21:54:13 +00:00
A bit of cleanup
This commit is contained in:
@@ -1,560 +0,0 @@
|
||||
////this file is part of BurnOut
|
||||
////Copyright (C)2005-2010 Gernot Knippen
|
||||
////Ported code with augments Copyright (C)2018 Matt Nadareski
|
||||
////
|
||||
////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 2 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 can get a copy of the GNU General Public License
|
||||
////by writing to the Free Software
|
||||
////Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Threading;
|
||||
//using BurnOutSharp.FileType;
|
||||
//using BurnOutSharp.ProtectionType;
|
||||
|
||||
//namespace BurnOutSharp
|
||||
//{
|
||||
// public static class ProtectionFind
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// Progress indicator
|
||||
// /// </summary>
|
||||
// private static IProgress<FileProtection> FileProgress = null;
|
||||
|
||||
// /// <summary>
|
||||
// /// Scan a path to find any known copy protection(s)
|
||||
// /// </summary>
|
||||
// /// <param name="path">Path to scan for protection(s)</param>
|
||||
// /// <param name="includePosition">True to include scanned copy protection position, false otherwise (default)</param>
|
||||
// /// <param name="progress">Optional progress indicator that will return a float in the range from 0 to 1</param>
|
||||
// /// <returns>Dictionary of filename to protection mappings, if possible</returns>
|
||||
// public static Dictionary<string, string> Scan(string path, bool includePosition = false, IProgress<FileProtection> progress = null)
|
||||
// {
|
||||
// // Set the progress indicator, if it's not set already
|
||||
// if (FileProgress == null)
|
||||
// FileProgress = progress;
|
||||
|
||||
// // Initialize the protections dictionary
|
||||
// var protections = new Dictionary<string, string>();
|
||||
|
||||
// // Checkpoint
|
||||
// FileProgress?.Report(new FileProtection(null, 0, null));
|
||||
|
||||
// // Temp variables for reporting
|
||||
// string tempFilePath = Path.GetTempPath();
|
||||
// string tempFilePathWithGuid = Path.Combine(tempFilePath, Guid.NewGuid().ToString());
|
||||
|
||||
// // If we have a file
|
||||
// if (File.Exists(path))
|
||||
// {
|
||||
// // Get the reportable file name
|
||||
// string reportableFileName = path;
|
||||
// if (reportableFileName.StartsWith(tempFilePath))
|
||||
// reportableFileName = reportableFileName.Substring(tempFilePathWithGuid.Length);
|
||||
|
||||
// // Checkpoint
|
||||
// FileProgress?.Report(new FileProtection(reportableFileName, 1, "Checking file" + (path != reportableFileName ? " from archive" : string.Empty)));
|
||||
|
||||
// // Try using just the file first to get protection info
|
||||
// string fileProtection = ScanPath(path, false);
|
||||
// if (!string.IsNullOrWhiteSpace(fileProtection))
|
||||
// protections[path] = fileProtection;
|
||||
|
||||
// // Now check to see if the file contains any additional information
|
||||
// string contentProtection = ScanContent(path, includePosition)?.Replace("" + (char)0x00, "");
|
||||
// if (!string.IsNullOrWhiteSpace(contentProtection))
|
||||
// {
|
||||
// if (protections.ContainsKey(path))
|
||||
// protections[path] += $", {contentProtection}";
|
||||
// else
|
||||
// protections[path] = contentProtection;
|
||||
// }
|
||||
|
||||
// // Checkpoint
|
||||
// protections.TryGetValue(path, out string fullProtection);
|
||||
// FileProgress?.Report(new FileProtection(reportableFileName, 1, fullProtection ?? string.Empty));
|
||||
// }
|
||||
// // If we have a directory
|
||||
// else if (Directory.Exists(path))
|
||||
// {
|
||||
// // Get the lists of files to be used
|
||||
// var files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
|
||||
|
||||
// // Try using just the path first to get protection info
|
||||
// string pathProtection = ScanPath(path, true);
|
||||
// if (!string.IsNullOrWhiteSpace(pathProtection))
|
||||
// protections[path] = pathProtection;
|
||||
|
||||
// // Loop through all files and scan their contents
|
||||
// for (int i = 0; i < files.Count(); i++)
|
||||
// {
|
||||
// // Get the current file
|
||||
// string file = files.ElementAt(i);
|
||||
|
||||
// // Get the reportable file name
|
||||
// string reportableFileName = file;
|
||||
// if (reportableFileName.StartsWith(tempFilePath))
|
||||
// reportableFileName = reportableFileName.Substring(tempFilePathWithGuid.Length);
|
||||
|
||||
// // Checkpoint
|
||||
// FileProgress?.Report(new FileProtection(reportableFileName, i / (float)files.Count(), "Checking file" + (file != reportableFileName ? " from archive" : string.Empty)));
|
||||
|
||||
// // Try using just the file first to get protection info
|
||||
// string fileProtection = ScanPath(file, false);
|
||||
// if (!string.IsNullOrWhiteSpace(fileProtection))
|
||||
// protections[file] = fileProtection;
|
||||
|
||||
// // Now check to see if the file contains any additional information
|
||||
// string contentProtection = ScanContent(file, includePosition)?.Replace("" + (char)0x00, "");
|
||||
// if (!string.IsNullOrWhiteSpace(contentProtection))
|
||||
// {
|
||||
// if (protections.ContainsKey(file))
|
||||
// protections[file] += $", {contentProtection}";
|
||||
// else
|
||||
// protections[file] = contentProtection;
|
||||
// }
|
||||
|
||||
// // Checkpoint
|
||||
// protections.TryGetValue(file, out string fullProtection);
|
||||
// FileProgress?.Report(new FileProtection(reportableFileName, (i + 1) / (float)files.Count(), fullProtection ?? string.Empty));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // If we have an empty list, we need to take care of that
|
||||
// if (protections.Count(p => !string.IsNullOrWhiteSpace(p.Value)) == 0)
|
||||
// {
|
||||
// protections = new Dictionary<string, string>();
|
||||
// }
|
||||
|
||||
// return protections;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Scan a path for indications of copy protection
|
||||
// /// </summary>
|
||||
// /// <param name="path">Path to scan file and folder names</param>
|
||||
// /// <param name="isDirectory">True if the path is a directory, false otherwise</param>
|
||||
// /// <returns></returns>
|
||||
// public static string ScanPath(string path, bool isDirectory)
|
||||
// {
|
||||
// List<string> protections = new List<string>();
|
||||
// string protection;
|
||||
|
||||
// // If we have a directory, get the files in the directory for searching
|
||||
// IEnumerable<string> files = null;
|
||||
// if (isDirectory)
|
||||
// files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
|
||||
|
||||
// // AACS
|
||||
// protection = AACS.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Alpha-DVD
|
||||
// protection = AlphaDVD.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Bitpool
|
||||
// protection = Bitpool.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // ByteShield
|
||||
// protection = ByteShield.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Cactus Data Shield
|
||||
// protection = CactusDataShield.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // CD-Cops
|
||||
// protection = CDCops.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // CD-Lock
|
||||
// protection = CDLock.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // CD-Protector
|
||||
// protection = CDProtector.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // CD-X
|
||||
// protection = CDX.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// /*
|
||||
// // CopyKiller
|
||||
// protection = CopyKiller.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
// */
|
||||
|
||||
// // DiscGuard
|
||||
// protection = DiscGuard.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // DVD Crypt
|
||||
// protection = DVDCrypt.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // DVD-Movie-PROTECT
|
||||
// protection = DVDMoviePROTECT.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // FreeLock
|
||||
// protection = FreeLock.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Games for Windows - Live
|
||||
// protection = GFWL.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Hexalock AutoLock
|
||||
// protection = HexalockAutoLock.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Impulse Reactor
|
||||
// protection = ImpulseReactor.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // IndyVCD
|
||||
// protection = IndyVCD.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Key2Audio XS
|
||||
// protection = Key2AudioXS.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // LaserLock
|
||||
// protection = LaserLock.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // MediaCloQ
|
||||
// protection = MediaCloQ.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // MediaMax CD3
|
||||
// protection = MediaMaxCD3.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Origin
|
||||
// protection = Origin.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Protect DVD-Video
|
||||
// protection = ProtectDVDVideo.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // SafeCast
|
||||
// protection = SafeCast.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // SafeDisc
|
||||
// protection = SafeDisc.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // SafeDisc Lite
|
||||
// protection = SafeDiscLite.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // SafeLock
|
||||
// protection = SafeLock.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // SecuROM
|
||||
// protection = SecuROM.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // SmartE
|
||||
// protection = SmartE.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // SoftLock
|
||||
// protection = SoftLock.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // SolidShield
|
||||
// protection = SolidShield.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // StarForce
|
||||
// protection = StarForce.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Steam
|
||||
// protection = Steam.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // TAGES
|
||||
// protection = Tages.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // TZCopyProtector
|
||||
// protection = TZCopyProtector.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Uplay
|
||||
// protection = Uplay.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // VOB ProtectCD/DVD
|
||||
// protection = VOBProtectCDDVD.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Winlock
|
||||
// protection = Winlock.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // WTM CD Protect
|
||||
// protection = WTMCDProtect.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // XCP
|
||||
// protection = XCP.CheckPath(path, files, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Zzxzz
|
||||
// protection = Zzxzz.CheckPath(path, isDirectory);
|
||||
// if (!string.IsNullOrWhiteSpace(protection))
|
||||
// protections.Add(protection);
|
||||
|
||||
// // Now combine any found protections, or null if empty
|
||||
// if (protections.Count() == 0)
|
||||
// return null;
|
||||
// else
|
||||
// return string.Join(", ", protections);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Scan an individual file for copy protection
|
||||
// /// </summary>
|
||||
// /// <param name="file">File path for scanning</param>
|
||||
// /// <param name="includePosition">True to include scanned copy protection position, false otherwise (default)</param>
|
||||
// public static string ScanContent(string file, bool includePosition = false)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// using (FileStream fs = File.OpenRead(file))
|
||||
// {
|
||||
// return ScanContent(fs, file, includePosition);
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Scan an individual stream for copy protection
|
||||
// /// </summary>
|
||||
// /// <param name="stream">Generic stream to scan</param>
|
||||
// /// <param name="file">File path to be used for name checks (optional)</param>
|
||||
// /// <param name="includePosition">True to include scanned copy protection position, false otherwise (default)</param>
|
||||
// public static string ScanContent(Stream stream, string file = null, bool includePosition = false)
|
||||
// {
|
||||
// // Get the extension for certain checks
|
||||
// string extension = Path.GetExtension(file).ToLower().TrimStart('.');
|
||||
|
||||
// // Assume the first part of the stream is the start of a file
|
||||
// byte[] magic = new byte[16];
|
||||
// try
|
||||
// {
|
||||
// stream.Read(magic, 0, 16);
|
||||
// stream.Seek(-16, SeekOrigin.Current);
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// // We don't care what the issue was, we can't read or seek the file
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// // Files can be protected in multiple ways
|
||||
// List<string> protections = new List<string>();
|
||||
|
||||
// #region Non-Archive Formats
|
||||
|
||||
// // Executable
|
||||
// if (Executable.ShouldScan(magic))
|
||||
// protections.AddRange(Executable.Scan(stream, file, includePosition));
|
||||
|
||||
// // Text-based files
|
||||
// if (Textfile.ShouldScan(magic, extension))
|
||||
// protections.AddRange(Textfile.Scan(stream, includePosition));
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region Archive Formats
|
||||
|
||||
// // 7-Zip archive
|
||||
// if (SevenZip.ShouldScan(magic))
|
||||
// protections.AddRange(SevenZip.Scan(stream, includePosition));
|
||||
|
||||
// // BFPK archive
|
||||
// if (BFPK.ShouldScan(magic))
|
||||
// protections.AddRange(BFPK.Scan(stream, includePosition));
|
||||
|
||||
// // BZip2
|
||||
// if (BZip2.ShouldScan(magic))
|
||||
// protections.AddRange(BZip2.Scan(stream, includePosition));
|
||||
|
||||
// // GZIP
|
||||
// if (GZIP.ShouldScan(magic))
|
||||
// protections.AddRange(GZIP.Scan(stream, includePosition));
|
||||
|
||||
// // InstallShield Cabinet
|
||||
// if (file != null && InstallShieldCAB.ShouldScan(magic))
|
||||
// protections.AddRange(InstallShieldCAB.Scan(file, includePosition));
|
||||
|
||||
// // Microsoft Cabinet
|
||||
// if (file != null && MicrosoftCAB.ShouldScan(magic))
|
||||
// protections.AddRange(MicrosoftCAB.Scan(file, includePosition));
|
||||
|
||||
// // MSI
|
||||
// if (file != null && MSI.ShouldScan(magic))
|
||||
// protections.AddRange(MSI.Scan(file, includePosition));
|
||||
|
||||
// // MPQ archive
|
||||
// if (file != null && MPQ.ShouldScan(magic))
|
||||
// protections.AddRange(MPQ.Scan(file, includePosition));
|
||||
|
||||
// // PKZIP archive (and derivatives)
|
||||
// if (PKZIP.ShouldScan(magic))
|
||||
// protections.AddRange(PKZIP.Scan(stream, includePosition));
|
||||
|
||||
// // RAR archive
|
||||
// if (RAR.ShouldScan(magic))
|
||||
// protections.AddRange(RAR.Scan(stream, includePosition));
|
||||
|
||||
// // Tape Archive
|
||||
// if (TapeArchive.ShouldScan(magic))
|
||||
// protections.AddRange(TapeArchive.Scan(stream, includePosition));
|
||||
|
||||
// // Valve archive formats
|
||||
// if (file != null && Valve.ShouldScan(magic))
|
||||
// protections.AddRange(Valve.Scan(file, includePosition));
|
||||
|
||||
// // XZ
|
||||
// if (XZ.ShouldScan(magic))
|
||||
// protections.AddRange(XZ.Scan(stream, includePosition));
|
||||
|
||||
// #endregion
|
||||
|
||||
// // Return blank if nothing found, or comma-separated list of protections
|
||||
// if (protections.Count() == 0)
|
||||
// return string.Empty;
|
||||
// else
|
||||
// return string.Join(", ", protections);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Scan a disc sector by sector for protection
|
||||
// /// </summary>
|
||||
// /// <remarks>
|
||||
// /// https://stackoverflow.com/questions/8819188/c-sharp-classes-to-undelete-files/8820157#8820157
|
||||
// /// TODO: Finish implementation
|
||||
// /// </remarks>
|
||||
// private static string ScanSectors(char driveLetter, int sectorsize)
|
||||
// {
|
||||
// string fsName = Utilities.GetFileSystemName(driveLetter);
|
||||
|
||||
// // Gets a handle to the physical disk
|
||||
// IntPtr hDisk = Utilities.CreateFile($"\\\\.\\{driveLetter}:",
|
||||
// FileAccess.Read,
|
||||
// FileShare.ReadWrite,
|
||||
// IntPtr.Zero,
|
||||
// FileMode.Open,
|
||||
// 0,
|
||||
// IntPtr.Zero);
|
||||
|
||||
// // If we have a good pointer
|
||||
// if (hDisk.ToInt32() != -1)
|
||||
// {
|
||||
// // Setup vars
|
||||
// byte[] buffer = new byte[sectorsize];
|
||||
// IntPtr pt = IntPtr.Zero;
|
||||
// NativeOverlapped no = new NativeOverlapped();
|
||||
|
||||
// // Set initial offset
|
||||
// Utilities.SetFilePointerEx(
|
||||
// hDisk,
|
||||
// 0,
|
||||
// ref pt,
|
||||
// Utilities.FileBegin);
|
||||
|
||||
// // Read a whole sector
|
||||
// while (true)
|
||||
// {
|
||||
// buffer = new byte[sectorsize];
|
||||
// Utilities.ReadFileEx(
|
||||
// hDisk,
|
||||
// buffer,
|
||||
// (uint)sectorsize,
|
||||
// ref no,
|
||||
// null);
|
||||
|
||||
// Utilities.SetFilePointerEx(
|
||||
// hDisk,
|
||||
// sectorsize,
|
||||
// ref pt,
|
||||
// Utilities.FileCurrent);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Utilities.CloseHandle(hDisk);
|
||||
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -459,7 +459,6 @@ namespace BurnOutSharp
|
||||
#region Archive File Types
|
||||
|
||||
// If we're scanning archives, we have a few to try out
|
||||
// TODO: All archives should prefix internal paths properly
|
||||
if (ScanArchives)
|
||||
{
|
||||
// 7-Zip archive
|
||||
|
||||
@@ -3,9 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace BurnOutSharp
|
||||
{
|
||||
@@ -235,267 +232,5 @@ namespace BurnOutSharp
|
||||
else
|
||||
return fvinfo.ProductVersion.Replace(", ", ".");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the filesystem name for the given drive letter
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://pinvoke.net/default.aspx/kernel32/GetVolumeInformation.html
|
||||
/// </remarks>
|
||||
public static string GetFileSystemName(char driveLetter)
|
||||
{
|
||||
string fsName = null;
|
||||
|
||||
StringBuilder volname = new StringBuilder(261);
|
||||
StringBuilder fsname = new StringBuilder(261);
|
||||
|
||||
if (GetVolumeInformation($"{driveLetter}:\\", volname, volname.Capacity, out uint sernum, out uint maxlen, out FileSystemFeature flags, fsname, fsname.Capacity))
|
||||
{
|
||||
// Now you know the file system of your drive
|
||||
// NTFS or FAT16 or UDF for instance
|
||||
fsName = fsname.ToString();
|
||||
}
|
||||
|
||||
return fsName;
|
||||
}
|
||||
|
||||
#region P/Invoke
|
||||
|
||||
// https://stackoverflow.com/questions/8819188/c-sharp-classes-to-undelete-files/8820157#8820157
|
||||
|
||||
// Move Method
|
||||
public const uint FileBegin = 0;
|
||||
public const uint FileCurrent = 1;
|
||||
public const uint FileEnd = 2;
|
||||
|
||||
// Handle Constants
|
||||
public const uint INVALID_HANDLE_VALUE = 0;
|
||||
public const int IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080;
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern bool CloseHandle(IntPtr handle);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CreateFile(
|
||||
[MarshalAs(UnmanagedType.LPTStr)] string filename,
|
||||
[MarshalAs(UnmanagedType.U4)] FileAccess access,
|
||||
[MarshalAs(UnmanagedType.U4)] FileShare share,
|
||||
IntPtr securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero
|
||||
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
|
||||
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
|
||||
IntPtr templateFile);
|
||||
|
||||
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public extern static bool GetVolumeInformation(
|
||||
string rootPathName,
|
||||
StringBuilder volumeNameBuffer,
|
||||
int volumeNameSize,
|
||||
out uint volumeSerialNumber,
|
||||
out uint maximumComponentLength,
|
||||
out FileSystemFeature fileSystemFlags,
|
||||
StringBuilder fileSystemNameBuffer,
|
||||
int nFileSystemNameSize);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true)]
|
||||
public extern static bool DeviceIoControl(
|
||||
IntPtr hDevice,
|
||||
uint IoControlCode,
|
||||
IntPtr InMediaRemoval,
|
||||
uint InBufferSize,
|
||||
IntPtr OutBuffer,
|
||||
int OutBufferSize,
|
||||
out int BytesReturned,
|
||||
IntPtr Overlapped);
|
||||
|
||||
// Used to read in a file
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern bool ReadFile(
|
||||
IntPtr hFile,
|
||||
byte[] lpBuffer,
|
||||
uint nNumberOfBytesToRead,
|
||||
ref uint lpNumberOfBytesRead,
|
||||
IntPtr lpOverlapped);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern bool ReadFileEx(
|
||||
IntPtr hFile,
|
||||
[Out] byte[] lpBuffer,
|
||||
uint nNumberOfBytesToRead,
|
||||
[In] ref NativeOverlapped lpOverlapped,
|
||||
IOCompletionCallback lpCompletionRoutine);
|
||||
|
||||
// Used to set the offset in file to start reading
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern bool SetFilePointerEx(
|
||||
IntPtr hFile,
|
||||
long liDistanceToMove,
|
||||
ref IntPtr lpNewFilePointer,
|
||||
uint dwMoveMethod);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct STORAGE_DEVICE_NUMBER
|
||||
{
|
||||
public int DeviceType;
|
||||
public int DeviceNumber;
|
||||
public int PartitionNumber;
|
||||
}
|
||||
|
||||
public enum MEDIA_TYPE : uint
|
||||
{
|
||||
Unknown,
|
||||
F5_1Pt2_512,
|
||||
F3_1Pt44_512,
|
||||
F3_2Pt88_512,
|
||||
F3_20Pt8_512,
|
||||
F3_720_512,
|
||||
F5_360_512,
|
||||
F5_320_512,
|
||||
F5_320_1024,
|
||||
F5_180_512,
|
||||
F5_160_512,
|
||||
RemovableMedia,
|
||||
FixedMedia,
|
||||
F3_120M_512,
|
||||
F3_640_512,
|
||||
F5_640_512,
|
||||
F5_720_512,
|
||||
F3_1Pt2_512,
|
||||
F3_1Pt23_1024,
|
||||
F5_1Pt23_1024,
|
||||
F3_128Mb_512,
|
||||
F3_230Mb_512,
|
||||
F8_256_128,
|
||||
F3_200Mb_512,
|
||||
F3_240M_512,
|
||||
F3_32M_512
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DISK_GEOMETRY
|
||||
{
|
||||
public long Cylinders;
|
||||
public MEDIA_TYPE MediaType;
|
||||
public int TracksPerCylinder;
|
||||
public int SectorsPerTrack;
|
||||
public int BytesPerSector;
|
||||
|
||||
public long DiskSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return Cylinders * (long)TracksPerCylinder * (long)SectorsPerTrack * (long)BytesPerSector;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FileSystemFeature : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// The file system preserves the case of file names when it places a name on disk.
|
||||
/// </summary>
|
||||
CasePreservedNames = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports case-sensitive file names.
|
||||
/// </summary>
|
||||
CaseSensitiveSearch = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The specified volume is a direct access (DAX) volume. This flag was introduced in Windows 10, version 1607.
|
||||
/// </summary>
|
||||
DaxVolume = 0x20000000,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports file-based compression.
|
||||
/// </summary>
|
||||
FileCompression = 0x10,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports named streams.
|
||||
/// </summary>
|
||||
NamedStreams = 0x40000,
|
||||
|
||||
/// <summary>
|
||||
/// The file system preserves and enforces access control lists (ACL).
|
||||
/// </summary>
|
||||
PersistentACLS = 8,
|
||||
|
||||
/// <summary>
|
||||
/// The specified volume is read-only.
|
||||
/// </summary>
|
||||
ReadOnlyVolume = 0x80000,
|
||||
|
||||
/// <summary>
|
||||
/// The volume supports a single sequential write.
|
||||
/// </summary>
|
||||
SequentialWriteOnce = 0x100000,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports the Encrypted File System (EFS).
|
||||
/// </summary>
|
||||
SupportsEncryption = 0x20000,
|
||||
|
||||
/// <summary>
|
||||
/// The specified volume supports extended attributes. An extended attribute is a piece of
|
||||
/// application-specific metadata that an application can associate with a file and is not part
|
||||
/// of the file's data.
|
||||
/// </summary>
|
||||
SupportsExtendedAttributes = 0x00800000,
|
||||
|
||||
/// <summary>
|
||||
/// The specified volume supports hard links. For more information, see Hard Links and Junctions.
|
||||
/// </summary>
|
||||
SupportsHardLinks = 0x00400000,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports object identifiers.
|
||||
/// </summary>
|
||||
SupportsObjectIDs = 0x10000,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports open by FileID. For more information, see FILE_ID_BOTH_DIR_INFO.
|
||||
/// </summary>
|
||||
SupportsOpenByFileId = 0x01000000,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports re-parse points.
|
||||
/// </summary>
|
||||
SupportsReparsePoints = 0x80,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports sparse files.
|
||||
/// </summary>
|
||||
SupportsSparseFiles = 0x40,
|
||||
|
||||
/// <summary>
|
||||
/// The volume supports transactions.
|
||||
/// </summary>
|
||||
SupportsTransactions = 0x200000,
|
||||
|
||||
/// <summary>
|
||||
/// The specified volume supports update sequence number (USN) journals. For more information,
|
||||
/// see Change Journal Records.
|
||||
/// </summary>
|
||||
SupportsUsnJournal = 0x02000000,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports Unicode in file names as they appear on disk.
|
||||
/// </summary>
|
||||
UnicodeOnDisk = 4,
|
||||
|
||||
/// <summary>
|
||||
/// The specified volume is a compressed volume, for example, a DoubleSpace volume.
|
||||
/// </summary>
|
||||
VolumeIsCompressed = 0x8000,
|
||||
|
||||
/// <summary>
|
||||
/// The file system supports disk quotas.
|
||||
/// </summary>
|
||||
VolumeQuotas = 0x20
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@ namespace Test
|
||||
|
||||
Console.WriteLine("Press any button to close...");
|
||||
Console.ReadLine();
|
||||
|
||||
//ProtectionFind.ScanSectors('D', 2048);
|
||||
}
|
||||
|
||||
private static void Changed(object source, FileProtection value)
|
||||
|
||||
Reference in New Issue
Block a user