2018-07-16 00:45:29 -07:00
//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 ;
2019-09-27 23:52:24 -07:00
using System.Threading ;
2020-09-10 21:10:32 -07:00
using BurnOutSharp.FileType ;
2019-09-27 23:52:24 -07:00
using BurnOutSharp.ProtectionType ;
2018-07-16 00:45:29 -07:00
namespace BurnOutSharp
{
public static class ProtectionFind
{
2020-10-28 12:05:48 -07:00
/// <summary>
/// Progress indicator
/// </summary>
private static IProgress < FileProtection > FileProgress = null ;
2018-07-16 00:45:29 -07:00
/// <summary>
/// Scan a path to find any known copy protection(s)
/// </summary>
2018-07-16 17:28:47 -07:00
/// <param name="path">Path to scan for protection(s)</param>
2020-09-10 21:47:14 -07:00
/// <param name="includePosition">True to include scanned copy protection position, false otherwise (default)</param>
2018-07-18 10:11:49 -07:00
/// <param name="progress">Optional progress indicator that will return a float in the range from 0 to 1</param>
2018-07-16 17:28:47 -07:00
/// <returns>Dictionary of filename to protection mappings, if possible</returns>
2020-09-10 21:43:18 -07:00
public static Dictionary < string , string > Scan ( string path , bool includePosition = false , IProgress < FileProtection > progress = null )
2018-07-16 00:45:29 -07:00
{
2020-10-28 12:05:48 -07:00
// Set the progress indicator, if it's not set already
if ( FileProgress = = null )
FileProgress = progress ;
// Initialize the protections dictionary
2018-07-16 00:45:29 -07:00
var protections = new Dictionary < string , string > ( ) ;
2018-07-18 10:11:49 -07:00
// Checkpoint
2020-10-28 12:05:48 -07:00
FileProgress ? . Report ( new FileProtection ( null , 0 , null ) ) ;
2018-07-18 10:11:49 -07:00
2020-10-28 13:17:26 -07:00
// Temp variables for reporting
string tempFilePath = Path . GetTempPath ( ) ;
string tempFilePathWithGuid = Path . Combine ( tempFilePath , Guid . NewGuid ( ) . ToString ( ) ) ;
2018-07-16 17:25:36 -07:00
// If we have a file
if ( File . Exists ( path ) )
2018-07-16 00:45:29 -07:00
{
2020-10-28 13:17:26 -07:00
// Get the reportable file name
string reportableFileName = path ;
if ( reportableFileName . StartsWith ( tempFilePath ) )
reportableFileName = reportableFileName . Substring ( tempFilePathWithGuid . Length ) ;
2020-10-28 13:25:58 -07:00
// Checkpoint
FileProgress ? . Report ( new FileProtection ( reportableFileName , 1 , "Checking file" + ( path ! = reportableFileName ? " from archive" : string . Empty ) ) ) ;
2019-09-29 11:57:46 -07:00
// Try using just the file first to get protection info
string fileProtection = ScanPath ( path , false ) ;
if ( ! string . IsNullOrWhiteSpace ( fileProtection ) )
protections [ path ] = fileProtection ;
2018-07-16 00:45:29 -07:00
// Now check to see if the file contains any additional information
2020-09-10 21:43:18 -07:00
string contentProtection = ScanContent ( path , includePosition ) ? . Replace ( "" + ( char ) 0x00 , "" ) ;
2019-09-27 23:52:24 -07:00
if ( ! string . IsNullOrWhiteSpace ( contentProtection ) )
{
if ( protections . ContainsKey ( path ) )
protections [ path ] + = $", {contentProtection}" ;
else
protections [ path ] = contentProtection ;
}
2018-07-18 10:38:41 -07:00
// Checkpoint
2020-10-28 13:06:45 -07:00
protections . TryGetValue ( path , out string fullProtection ) ;
2020-10-28 13:17:26 -07:00
FileProgress ? . Report ( new FileProtection ( reportableFileName , 1 , fullProtection ? ? string . Empty ) ) ;
2018-07-16 17:25:36 -07:00
}
// If we have a directory
else if ( Directory . Exists ( path ) )
{
// Get the lists of files to be used
2019-09-27 23:52:24 -07:00
var files = Directory . EnumerateFiles ( path , "*" , SearchOption . AllDirectories ) ;
2018-07-16 17:25:36 -07:00
2019-09-27 23:52:24 -07:00
// Try using just the path first to get protection info
string pathProtection = ScanPath ( path , true ) ;
if ( ! string . IsNullOrWhiteSpace ( pathProtection ) )
protections [ path ] = pathProtection ;
2018-07-16 17:25:36 -07:00
2019-09-27 23:52:24 -07:00
// Loop through all files and scan their contents
for ( int i = 0 ; i < files . Count ( ) ; i + + )
2018-07-16 17:25:36 -07:00
{
2018-07-18 10:11:49 -07:00
// Get the current file
2019-09-27 23:52:24 -07:00
string file = files . ElementAt ( i ) ;
2018-07-16 17:25:36 -07:00
2020-10-28 13:17:26 -07:00
// Get the reportable file name
string reportableFileName = file ;
if ( reportableFileName . StartsWith ( tempFilePath ) )
reportableFileName = reportableFileName . Substring ( tempFilePathWithGuid . Length ) ;
2020-10-28 13:06:45 -07:00
// Checkpoint
2020-10-28 13:25:58 -07:00
FileProgress ? . Report ( new FileProtection ( reportableFileName , i / ( float ) files . Count ( ) , "Checking file" + ( file ! = reportableFileName ? " from archive" : string . Empty ) ) ) ;
2020-10-28 13:06:45 -07:00
2019-09-29 11:57:46 -07:00
// Try using just the file first to get protection info
string fileProtection = ScanPath ( file , false ) ;
if ( ! string . IsNullOrWhiteSpace ( fileProtection ) )
protections [ file ] = fileProtection ;
2018-07-16 17:25:36 -07:00
// Now check to see if the file contains any additional information
2020-09-10 21:43:18 -07:00
string contentProtection = ScanContent ( file , includePosition ) ? . Replace ( "" + ( char ) 0x00 , "" ) ;
2019-09-27 23:52:24 -07:00
if ( ! string . IsNullOrWhiteSpace ( contentProtection ) )
2019-09-29 11:57:46 -07:00
{
if ( protections . ContainsKey ( file ) )
protections [ file ] + = $", {contentProtection}" ;
else
protections [ file ] = contentProtection ;
}
2018-07-18 10:38:41 -07:00
// Checkpoint
2020-10-28 13:06:45 -07:00
protections . TryGetValue ( file , out string fullProtection ) ;
2020-10-28 13:21:42 -07:00
FileProgress ? . Report ( new FileProtection ( reportableFileName , ( i + 1 ) / ( float ) files . Count ( ) , fullProtection ? ? string . Empty ) ) ;
2018-07-16 17:25:36 -07:00
}
2018-07-16 00:45:29 -07:00
}
// If we have an empty list, we need to take care of that
2019-09-27 23:52:24 -07:00
if ( protections . Count ( p = > ! string . IsNullOrWhiteSpace ( p . Value ) ) = = 0 )
2018-07-16 00:45:29 -07:00
{
2018-07-16 17:25:36 -07:00
protections = new Dictionary < string , string > ( ) ;
2018-07-16 00:45:29 -07:00
}
return protections ;
}
2019-09-27 23:52:24 -07:00
/// <summary>
/// Scan a path for indications of copy protection
/// </summary>
/// <param name="path"></param>
/// <param name="isDirectory"></param>
/// <returns></returns>
2019-09-30 11:08:44 -07:00
public static string ScanPath ( string path , bool isDirectory )
2019-09-27 23:52:24 -07:00
{
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 ) ;
2019-09-28 01:51:06 -07:00
// SafeDisc
protection = SafeDisc . CheckPath ( path , files , isDirectory ) ;
if ( ! string . IsNullOrWhiteSpace ( protection ) )
protections . Add ( protection ) ;
2019-09-27 23:52:24 -07:00
// 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 ) ;
}
2018-07-16 00:45:29 -07:00
/// <summary>
/// Scan an individual file for copy protection
/// </summary>
2019-09-30 11:08:44 -07:00
/// <param name="file">File path for scanning</param>
2020-09-10 21:43:18 -07:00
/// <param name="includePosition">True to include scanned copy protection position, false otherwise (default)</param>
public static string ScanContent ( string file , bool includePosition = false )
2018-07-16 00:45:29 -07:00
{
2020-09-10 21:10:32 -07:00
using ( FileStream fs = File . OpenRead ( file ) )
2018-07-16 00:45:29 -07:00
{
2020-09-10 21:43:18 -07:00
return ScanContent ( fs , file , includePosition ) ;
2018-07-16 00:45:29 -07:00
}
}
2019-09-30 11:08:44 -07:00
/// <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>
2020-09-10 21:43:18 -07:00
/// <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 )
2019-09-30 11:08:44 -07:00
{
2020-09-10 21:10:32 -07:00
// Get the extension for certain checks
string extension = Path . GetExtension ( file ) . ToLower ( ) . TrimStart ( '.' ) ;
2019-09-30 11:08:44 -07:00
// Assume the first part of the stream is the start of a file
2020-09-10 21:10:32 -07:00
byte [ ] magic = new byte [ 16 ] ;
2019-09-30 11:08:44 -07:00
try
{
2020-09-10 21:10:32 -07:00
stream . Read ( magic , 0 , 16 ) ;
stream . Seek ( - 16 , SeekOrigin . Current ) ;
2019-09-30 11:08:44 -07:00
}
catch
{
2020-09-10 21:10:32 -07:00
// We don't care what the issue was, we can't read or seek the file
2019-09-30 11:08:44 -07:00
return null ;
}
// Files can be protected in multiple ways
List < string > protections = new List < string > ( ) ;
2020-09-10 21:10:32 -07:00
// 7-Zip archive
if ( SevenZip . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( SevenZip . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// BFPK archive
if ( BFPK . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( BFPK . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// BZip2
if ( BZip2 . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( BZip2 . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// Executable
if ( Executable . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( Executable . Scan ( stream , file , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// GZIP
if ( GZIP . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( GZIP . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// InstallShield Cabinet
if ( file ! = null & & InstallShieldCAB . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( InstallShieldCAB . Scan ( file , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// Microsoft Cabinet
if ( file ! = null & & MicrosoftCAB . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( MicrosoftCAB . Scan ( file , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-10-28 22:51:33 -07:00
// MSI
if ( file ! = null & & MSI . ShouldScan ( magic ) )
protections . AddRange ( MSI . Scan ( file , includePosition ) ) ;
2020-09-10 21:10:32 -07:00
// MPQ archive
if ( file ! = null & & MPQ . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( MPQ . Scan ( file , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// PKZIP archive (and derivatives)
if ( PKZIP . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( PKZIP . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// RAR archive
if ( RAR . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( RAR . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// Tape Archive
if ( TapeArchive . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( TapeArchive . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// Text-based files
if ( Textfile . ShouldScan ( magic , extension ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( Textfile . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// Valve archive formats
if ( file ! = null & & Valve . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( Valve . Scan ( file , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
2020-09-10 21:10:32 -07:00
// XZ
if ( XZ . ShouldScan ( magic ) )
2020-09-10 21:43:18 -07:00
protections . AddRange ( XZ . Scan ( stream , includePosition ) ) ;
2019-09-30 11:08:44 -07:00
// Return blank if nothing found, or comma-separated list of protections
if ( protections . Count ( ) = = 0 )
return string . Empty ;
else
return string . Join ( ", " , protections ) ;
}
2019-09-27 23:52:24 -07:00
/// <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 )
2018-07-16 00:45:29 -07:00
{
2019-09-27 23:52:24 -07:00
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 )
2018-07-16 00:45:29 -07:00
{
2019-09-27 23:52:24 -07:00
// 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 )
2018-07-16 00:45:29 -07:00
{
2019-09-27 23:52:24 -07:00
buffer = new byte [ sectorsize ] ;
Utilities . ReadFileEx (
hDisk ,
buffer ,
( uint ) sectorsize ,
ref no ,
null ) ;
Utilities . SetFilePointerEx (
hDisk ,
sectorsize ,
ref pt ,
Utilities . FileCurrent ) ;
2018-07-16 00:45:29 -07:00
}
}
2019-09-27 23:52:24 -07:00
Utilities . CloseHandle ( hDisk ) ;
2018-07-16 00:45:29 -07:00
2019-09-27 23:52:24 -07:00
return null ;
2018-07-16 00:45:29 -07:00
}
}
}