public void CloseContainer() { fsHandler = null; discFs.Dispose(); fsInfo = null; volume = null; disk.Dispose(); File.Delete(originalPath); Crypto.EncryptFile(temporaryPath, originalPath, pwdKey, new AesEngine(), 128, 128); File.Delete(temporaryPath); }
static void Main(string[] args) { SetupHelper.RegisterAssembly(typeof(Program).Assembly); MemoryStream dummyFileSystemData = new MemoryStream(Encoding.ASCII.GetBytes("MYFS")); VirtualDisk dummyDisk = new DiscUtils.Raw.Disk(dummyFileSystemData, Ownership.None); VolumeManager volMgr = new VolumeManager(dummyDisk); VolumeInfo volInfo = volMgr.GetLogicalVolumes()[0]; DiscUtils.FileSystemInfo fsInfo = FileSystemManager.DetectFileSystems(volInfo)[0]; DiscFileSystem fs = fsInfo.Open(volInfo); ShowDir(fs.Root, 4); }
protected override void DoRun() { VolumeManager volMgr = new VolumeManager(); foreach (string disk in _diskFiles.Values) { volMgr.AddDisk(VirtualDisk.OpenDisk(disk, _diskType.IsPresent ? _diskType.Value : null, FileAccess.Read, UserName, Password)); } VolumeInfo volInfo = null; if (!string.IsNullOrEmpty(VolumeId)) { volInfo = volMgr.GetVolume(VolumeId); } else if (Partition >= 0) { volInfo = volMgr.GetPhysicalVolumes()[Partition]; } else { volInfo = volMgr.GetLogicalVolumes()[0]; } DiscUtils.FileSystemInfo fsInfo = FileSystemManager.DetectDefaultFileSystems(volInfo)[0]; using (DiscFileSystem fs = fsInfo.Open(volInfo)) { using (Stream source = fs.OpenFile(_inFilePath.Value, FileMode.Open, FileAccess.Read)) { using (FileStream outFile = new FileStream(_outFilePath.Value, FileMode.Create, FileAccess.ReadWrite)) { PumpStreams(source, outFile); } if (_hexDump.IsPresent) { source.Position = 0; HexDump.Generate(source, Console.Out); } } } }
private void LoadContainer(string filePath) { disk = VirtualDisk.OpenDisk(filePath, FileAccess.ReadWrite); Debug.WriteLine(disk.Capacity + ", " + disk.DiskTypeInfo.Name); volume = VolumeManager.GetPhysicalVolumes(disk.Content)[0]; fsInfo = FileSystemManager.DetectFileSystems(volume)[0]; discFs = fsInfo.Open(volume); tmpFiles = new List <string>(); Debug.WriteLine(fsInfo.Name + " - " + fsInfo.Description); fsHandler = new FileSystemHandler.FileSystemHandler(this); }
public static void GetFile(string DiskPath, string FilePath, string DestinationFile) { if (File.Exists(DiskPath) && Directory.Exists(Path.GetDirectoryName(DestinationFile))) { if (Path.GetFileName(DestinationFile) == "") { DestinationFile += Path.GetFileName(FilePath); } VolumeManager volMgr = new VolumeManager(); VirtualDisk disk = VirtualDisk.OpenDisk(DiskPath, FileAccess.Read); volMgr.AddDisk(disk); VolumeInfo volInfo = null; if (disk.Partitions.Count > 1) { Console.WriteLine("\r\n[*] Target has more than one partition\r\n"); foreach (var physVol in volMgr.GetPhysicalVolumes()) { Console.WriteLine(" Identity: " + physVol.Identity); Console.WriteLine(" Type: " + physVol.VolumeType); Console.WriteLine(" Disk Id: " + physVol.DiskIdentity); Console.WriteLine(" Disk Sig: " + physVol.DiskSignature.ToString("X8")); Console.WriteLine(" Part Id: " + physVol.PartitionIdentity); Console.WriteLine(" Length: " + physVol.Length + " bytes"); Console.WriteLine(" Disk Geometry: " + physVol.PhysicalGeometry); Console.WriteLine(" First Sector: " + physVol.PhysicalStartSector); Console.WriteLine(); if (!string.IsNullOrEmpty(physVol.Identity)) { volInfo = volMgr.GetVolume(physVol.Identity); } DiscUtils.FileSystemInfo fsInfo = FileSystemManager.DetectFileSystems(volInfo)[0]; using (NtfsFileSystem diskntfs = new NtfsFileSystem(physVol.Partition.Open())) { if (diskntfs.FileExists("\\\\" + FilePath)) { long fileLength = diskntfs.GetFileLength("\\\\" + FilePath); using (Stream bootStream = diskntfs.OpenFile("\\\\" + FilePath, FileMode.Open, FileAccess.Read)) { byte[] file = new byte[bootStream.Length]; int totalRead = 0; while (totalRead < file.Length) { totalRead += bootStream.Read(file, totalRead, file.Length - totalRead); FileStream fileStream = File.Create(DestinationFile, (int)bootStream.Length); bootStream.CopyTo(fileStream); fileStream.Write(file, 0, (int)bootStream.Length); } long destinationLength = new FileInfo(DestinationFile).Length; if (fileLength != destinationLength) { Console.WriteLine( "[!] Something went wrong. Source file has size {0} and destination file has size {1}", fileLength, destinationLength); } else { Console.WriteLine("\r\n[*] File {0} was successfully copied to {1}", FilePath, DestinationFile); } } } else { Console.WriteLine("\r\n [!] File {0} can not be found", FilePath); } } } } else { foreach (var physVol in volMgr.GetPhysicalVolumes()) { Console.WriteLine(" Identity: " + physVol.Identity); Console.WriteLine(" Type: " + physVol.VolumeType); Console.WriteLine(" Disk Id: " + physVol.DiskIdentity); Console.WriteLine(" Disk Sig: " + physVol.DiskSignature.ToString("X8")); Console.WriteLine(" Part Id: " + physVol.PartitionIdentity); Console.WriteLine(" Length: " + physVol.Length + " bytes"); Console.WriteLine(" Disk Geometry: " + physVol.PhysicalGeometry); Console.WriteLine(" First Sector: " + physVol.PhysicalStartSector); Console.WriteLine(); NtfsFileSystem diskntfs = new NtfsFileSystem(disk.Partitions[0].Open()); if (diskntfs.FileExists("\\\\" + FilePath)) { long fileLength = diskntfs.GetFileLength("\\\\" + FilePath); using (Stream bootStream = diskntfs.OpenFile("\\\\" + FilePath, FileMode.Open, FileAccess.Read)) { byte[] file = new byte[bootStream.Length]; int totalRead = 0; while (totalRead < file.Length) { totalRead += bootStream.Read(file, totalRead, file.Length - totalRead); FileStream fileStream = File.Create(DestinationFile, (int)bootStream.Length); bootStream.CopyTo(fileStream); fileStream.Write(file, 0, (int)bootStream.Length); } } long destinationLength = new FileInfo(DestinationFile).Length; if (fileLength != destinationLength) { Console.WriteLine( "[!] Something went wrong. Source file has size {0} and destination file has size {1}", fileLength, destinationLength); } else { Console.WriteLine("\r\n[*] File {0} was successfully copied to {1}", FilePath, DestinationFile); } } else { Console.WriteLine("\r\n [!] File {0} can not be found", FilePath); } } } } else { Console.WriteLine( "\r\n [!] The provided VMDK image does not exist / can not be accessed or the destination folder does not exist"); } }
private static string RedirectISO(string filename) { string _result = null; try { if (!string.IsNullOrEmpty(filename) && File.Exists(filename)) { List <string> _candidates = new List <string>(); // open the ISO file VolumeManager volMgr = new VolumeManager(); volMgr.AddDisk(VirtualDisk.OpenDisk(filename, FileAccess.Read)); VolumeInfo volInfo = null; volInfo = volMgr.GetLogicalVolumes()[0]; DiscUtils.FileSystemInfo fsInfo = FileSystemManager.DetectDefaultFileSystems(volInfo)[0]; using (DiscFileSystem _dfs = fsInfo.Open(volInfo)) { foreach (string _fname in _dfs.GetFiles("", "*.*", SearchOption.AllDirectories)) { string _fileExt = System.IO.Path.GetExtension(_fname).ToLowerInvariant(); if (_fileExt == ".ifo" || _fileExt == ".mpls") { _candidates.Add(_fname); } } double _biggestDuration = 0d; string _tmpBRResult = ""; // select from the candidates the one that has the longest duration (if mpls skip files bigger than 10K) foreach (string _cpath in _candidates) { string _cext = Path.GetExtension(_cpath).ToLowerInvariant(); string _tmp = Helpers.GetUniqueFilename(_cext); using (FileStream _fs = new FileStream(_tmp, FileMode.Create, FileAccess.Write)) { using (Stream source = _dfs.OpenFile(_cpath, FileMode.Open, FileAccess.Read)) { source.CopyTo(_fs); } } // if it is a DVD iso if (_cext == ".ifo") { if (string.Compare(Path.GetFileNameWithoutExtension(_cpath), "video_ts", true) == 0) { File.Delete(_tmp); // skip the menu continue; } // use first ifo that is not the menu FileManager.AddToGarbageFiles(_tmp); _result = _tmp; break; } // if it is a BLURAY iso (choose biggest mpls file) if (_cext == ".mpls") { long _length = new FileInfo(_tmp).Length; if (Path.GetExtension(_cpath).ToLowerInvariant() == ".mpls" && _length > 10 * 1024) { File.Delete(_tmp); continue; // take next one, this is too big and mediainfo will hang } if (GetDurationMilliseconds(_tmp) > _biggestDuration) { // important.. add it to the garbage files //FileManager.AddToGarbageFiles(_tmp); //_result = _tmp; if (!string.IsNullOrEmpty(_tmpBRResult)) { File.Delete(_tmpBRResult); // remove previous winner and remember the current one } _tmpBRResult = _tmp; } else { File.Delete(_tmp); } } } if (string.IsNullOrEmpty(_result) && !string.IsNullOrEmpty(_tmpBRResult)) { FileManager.AddToGarbageFiles(_tmpBRResult); _result = _tmpBRResult; } } } } catch (Exception ex) { Loggy.Logger.DebugException("ISO Processing", ex); } return(_result); }