public void Test() { for (int i = 0; i < testfiles.Length; i++) { string location = Path.Combine(Consts.TestFilesRoot, "filesystems", "fat16", testfiles[i]); IFilter filter = new LZip(); filter.Open(location); IMediaImage image = new ZZZRawImage(); Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); IFilesystem fs = new FAT(); var wholePart = new Partition { Name = "Whole device", Length = image.Info.Sectors, Size = image.Info.Sectors * image.Info.SectorSize }; Assert.AreEqual(true, fs.Identify(image, wholePart), testfiles[i]); fs.GetInformation(image, wholePart, out _, null); Assert.AreEqual(clusters[i], fs.XmlFsType.Clusters, testfiles[i]); Assert.AreEqual(clustersize[i], fs.XmlFsType.ClusterSize, testfiles[i]); Assert.AreEqual("FAT16", fs.XmlFsType.Type, testfiles[i]); Assert.AreEqual(volumename[i], fs.XmlFsType.VolumeName, testfiles[i]); Assert.AreEqual(volumeserial[i], fs.XmlFsType.VolumeSerial, testfiles[i]); Assert.AreEqual(oemid[i], fs.XmlFsType.SystemIdentifier, testfiles[i]); } }
public static void edit(IntPtr hFile, int clusterIndex, byte[] entity, byte head, FAT fat) { byte[] temp = new byte[ENTITY_SIZE]; Array.Copy(entity, temp, 32); temp[0] = head; edit(hFile, clusterIndex, entity, temp, fat); }
public void Test() { for (int i = 0; i < testfiles.Length; i++) { string location = Path.Combine(Consts.TestFilesRoot, "filesystems", "fat32_apm", testfiles[i]); IFilter filter = new LZip(); filter.Open(location); IMediaImage image = new Vdi(); Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); List <Partition> partitions = Core.Partitions.GetAll(image); IFilesystem fs = new FAT(); int part = -1; for (int j = 0; j < partitions.Count; j++) { if (partitions[j].Type == "DOS_FAT_32") { part = j; break; } } Assert.AreNotEqual(-1, part, $"Partition not found on {testfiles[i]}"); Assert.AreEqual(true, fs.Identify(image, partitions[part]), testfiles[i]); fs.GetInformation(image, partitions[part], out _, null); Assert.AreEqual(clusters[i], fs.XmlFsType.Clusters, testfiles[i]); Assert.AreEqual(clustersize[i], fs.XmlFsType.ClusterSize, testfiles[i]); Assert.AreEqual("FAT32", fs.XmlFsType.Type, testfiles[i]); Assert.AreEqual(volumename[i], fs.XmlFsType.VolumeName, testfiles[i]); Assert.AreEqual(volumeserial[i], fs.XmlFsType.VolumeSerial, testfiles[i]); Assert.AreEqual(oemid[i], fs.XmlFsType.SystemIdentifier, testfiles[i]); } }
public async Task <ResponseMessage> SaveFat([FromBody] FAT fat) { try { if (fat.Id == null) { fat.CreatedBy = LoginUser.Name; fat.CreatedDate = DateTime.UtcNow; } fat.UpdatedBy = LoginUser.Name; fat.UpdatedDate = DateTime.UtcNow; var savedFat = await _fatService.SaveFat(fat); if (savedFat == null) { return new ResponseMessage { Status = "Error", Message = "Error saving Fat." } } ; return(new ResponseMessage { Status = "Ok", Data = savedFat }); } catch (Exception ex) { _logger?.LogError(ex, "Error saving fat."); return(new ResponseMessage { Status = "Error", Message = "Error saving fat." }); } }
public FATExtract(string file) { InitializeComponent(); ReadLanguage(); this.file = file; fat = new FAT(); Read_NumFiles(); }
public static void deleteClusterTail(IntPtr hFile, int clusterNumber, FAT fat) { byte[] buffer = read(hFile, (int)LOCATION.FAT_TABLE_1, fat.FATTableSize, fat); int nextCluster = clusterNumber; do { int temp = buffer.ToList().GetRange(nextCluster * 2, 2).ToArray().ToInt32(); buffer[nextCluster * 2] = 0; buffer[nextCluster * 2 + 1] = 0; nextCluster = temp; } while (!(nextCluster == 0xFFF8 || nextCluster == 0xFFFF)); write(hFile, (int)LOCATION.FAT_TABLE_1, buffer, fat); }
public static void edit(IntPtr hFile, int clusterIndex, byte[] entity, byte[] newEntity, FAT fat) { if (clusterIndex == (int)LOCATION.ROOT_DIRECTORY) { int SIZE = fat.RootDirectorySize; byte[] buffer = read(hFile, (int)LOCATION.ROOT_DIRECTORY, SIZE, fat); for (int i = 0; i < SIZE / ENTITY_SIZE; i++) { int j = i * ENTITY_SIZE; byte[] temp = new byte[ENTITY_SIZE]; Array.Copy(buffer, j, temp, 0, 32); if (temp[0] == 0) break; if (temp.SequenceEqual(entity)) { Array.Copy(newEntity, 0, buffer, j, 32); write(hFile, (int)LOCATION.ROOT_DIRECTORY, buffer, fat); int x = entity.ToList().GetRange(26, 2).ToArray().ToInt32(); if (entity[0].Equals(0xE5) && !newEntity.Equals(0xE5)) undeleteClusterTail(hFile, x, fat); else if (newEntity[0].Equals(0xE5)) deleteClusterTail(hFile, x, fat); break; } } } else { int SIZE = fat.ClusterSize; byte[] buffer = read(hFile, clusterIndex, SIZE, fat); for (int i = 0; i < SIZE / ENTITY_SIZE; i++) { int j = i * ENTITY_SIZE; byte[] temp = new byte[ENTITY_SIZE]; Array.Copy(buffer, j, temp, 0, 32); if (temp[0] == 0) break; if (temp.SequenceEqual(entity)) { Array.Copy(newEntity, 0, buffer, j, 32); write(hFile, clusterIndex, buffer, fat); int x = entity.ToList().GetRange(26, 2).ToArray().ToInt32(); if (entity[0].Equals(0xE5) && !newEntity.Equals(0xE5)) undeleteClusterTail(hFile, x, fat); else if (newEntity[0].Equals(0xE5)) deleteClusterTail(hFile, x, fat); break; } } } }
private void directoryExplorerFiller(FAT fat) { var rootTreeNodes = new List<TreeNode>(); for (int i = 0; i < fat.SubDirectories.Count; i++) rootTreeNodes.Add(fat.SubDirectories[i].ToTreeNode()); foreach (var v in rootTreeNodes) treeView.Nodes.Add(v); //dirPlorer.Invoke(new MethodInvoker(() => { dirPlorer.Nodes.Add(v); })); foreach (var v in fat.SubFiles) fileView.Items.Add(v.ToListItem()); foreach (var v in rootTreeNodes) { directoryExplorer(v); } }
public bool Open(string name) { bool retVal; string FileName = "\\\\.\\" + name; RootPath = name + "\\"; Handle = PInvoke.CreateFile( FileName, //MAXIMUM_ALLOWED, // access PInvoke.GENERIC_READ, PInvoke.FILE_SHARE_READ | PInvoke.FILE_SHARE_WRITE, // share type IntPtr.Zero, // security descriptor PInvoke.OPEN_EXISTING, // open type 0, // attributes (none) IntPtr.Zero // template ); if (Handle.IsClosed || Handle.IsInvalid) { Debug.WriteLine("Unable to open volume. Error #{0} occurred", Marshal.GetLastWin32Error()); retVal = false; } else { // Get DriveInfo DriveInfo = new DriveInfo(RootPath); DriveStream = new FileStream(Handle, FileAccess.Read); // Detect filesystem //if (this._driveInfo.DriveFormat.ToUpper() == "NTFS") // this._partInfo = new NTFS(this); //else PartInfo = new FAT(this); retVal = true; } return(retVal); }
public void Test() { for (int i = 0; i < _testFiles.Length; i++) { string location = Path.Combine(Consts.TEST_FILES_ROOT, "Filesystems", "FAT16 (Human68K)", _testFiles[i]); IFilter filter = new ZZZNoFilter(); filter.Open(location); IMediaImage image = new AaruFormat(); Assert.AreEqual(true, image.Open(filter), _testFiles[i]); Assert.AreEqual(_sectors[i], image.Info.Sectors, _testFiles[i]); Assert.AreEqual(_sectorSize[i], image.Info.SectorSize, _testFiles[i]); List <Partition> partitions = Core.Partitions.GetAll(image); IFilesystem fs = new FAT(); int part = -1; for (int j = 0; j < partitions.Count; j++) { if (partitions[j].Type == "Human68k") { part = j; break; } } Assert.AreNotEqual(-1, part, $"Partition not found on {_testFiles[i]}"); Assert.AreEqual(true, fs.Identify(image, partitions[part]), _testFiles[i]); fs.GetInformation(image, partitions[part], out _, null); Assert.AreEqual(_clusters[i], fs.XmlFsType.Clusters, _testFiles[i]); Assert.AreEqual(_clusterSize[i], fs.XmlFsType.ClusterSize, _testFiles[i]); Assert.AreEqual("FAT16", fs.XmlFsType.Type, _testFiles[i]); Assert.AreEqual(_volumeName[i], fs.XmlFsType.VolumeName, _testFiles[i]); Assert.AreEqual(_volumeSerial[i], fs.XmlFsType.VolumeSerial, _testFiles[i]); Assert.AreEqual(_oemId[i], fs.XmlFsType.SystemIdentifier, _testFiles[i]); } }
//FILEBlock public SDAT(byte[] bytes) { using (var er = new EndianBinaryReader(new MemoryStream(bytes))) { FileHeader = er.ReadObject <FileHeader>(); SYMBOffset = er.ReadInt32(); SYMBLength = er.ReadInt32(); INFOOffset = er.ReadInt32(); INFOLength = er.ReadInt32(); FATOffset = er.ReadInt32(); FATLength = er.ReadInt32(); FILEOffset = er.ReadInt32(); FILELength = er.ReadInt32(); Padding = er.ReadBytes(16); if (SYMBOffset != 0 && SYMBLength != 0) { SYMBBlock = er.ReadObject <SYMB>(SYMBOffset); } INFOBlock = er.ReadObject <INFO>(INFOOffset); FATBlock = er.ReadObject <FAT>(FATOffset); } }
public void Test() { for (int i = 0; i < _testFiles.Length; i++) { string location = Path.Combine(Consts.TEST_FILES_ROOT, "Filesystems", "FAT32 (MBR)", _testFiles[i]); IFilter filter = new ZZZNoFilter(); filter.Open(location); IMediaImage image = new AaruFormat(); Assert.AreEqual(true, image.Open(filter), _testFiles[i]); Assert.AreEqual(_sectors[i], image.Info.Sectors, _testFiles[i]); Assert.AreEqual(_sectorSize[i], image.Info.SectorSize, _testFiles[i]); List <Partition> partitions = Core.Partitions.GetAll(image); IFilesystem fs = new FAT(); Assert.AreEqual(true, fs.Identify(image, partitions[0]), _testFiles[i]); fs.GetInformation(image, partitions[0], out _, null); Assert.AreEqual(_clusters[i], fs.XmlFsType.Clusters, _testFiles[i]); Assert.AreEqual(_clusterSize[i], fs.XmlFsType.ClusterSize, _testFiles[i]); Assert.AreEqual("FAT32", fs.XmlFsType.Type, _testFiles[i]); Assert.AreEqual(_volumeName[i], fs.XmlFsType.VolumeName, _testFiles[i]); Assert.AreEqual(_volumeSerial[i], fs.XmlFsType.VolumeSerial, _testFiles[i]); Assert.AreEqual(_oemId[i], fs.XmlFsType.SystemIdentifier, _testFiles[i]); } }
public void Test() { for (int i = 0; i < testfiles.Length; i++) { string location = Path.Combine(Consts.TestFilesRoot, "filesystems", "fat32_mbr", testfiles[i]); IFilter filter = new LZip(); filter.Open(location); IMediaImage image = new Vdi(); Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); List <Partition> partitions = Core.Partitions.GetAll(image); IFilesystem fs = new FAT(); Assert.AreEqual(true, fs.Identify(image, partitions[0]), testfiles[i]); fs.GetInformation(image, partitions[0], out _, null); Assert.AreEqual(clusters[i], fs.XmlFsType.Clusters, testfiles[i]); Assert.AreEqual(clustersize[i], fs.XmlFsType.ClusterSize, testfiles[i]); Assert.AreEqual("FAT32", fs.XmlFsType.Type, testfiles[i]); Assert.AreEqual(volumename[i], fs.XmlFsType.VolumeName, testfiles[i]); Assert.AreEqual(volumeserial[i], fs.XmlFsType.VolumeSerial, testfiles[i]); Assert.AreEqual(oemid[i], fs.XmlFsType.SystemIdentifier, testfiles[i]); } }
public SDAT(byte[] Data) { EndianBinaryReaderEx er = new EndianBinaryReaderEx(new MemoryStream(Data), Endianness.LittleEndian); try { Header = new SDATHeader(er); if (Header.SYMBOffset != 0 && Header.SYMBLength != 0) { er.BaseStream.Position = Header.SYMBOffset; SymbolBlock = new SYMB(er); } er.BaseStream.Position = Header.INFOOffset; InfoBlock = new INFO(er); er.BaseStream.Position = Header.FATOffset; FileAllocationTable = new FAT(er); er.BaseStream.Position = Header.FILEOffset; File = new FILE(er); } finally { er.Close(); } }
public static bool write(IntPtr hFile, int index, byte[] buffer, FAT fat) { seek(hFile, index, fat); uint length = 0; if (!WriteFile(hFile, buffer, (uint)buffer.Length, out length, IntPtr.Zero)) { int error = GetLastError(); throw new Exception("Error writing file" + error); } return true; }
public async Task <FAT> SaveFat(FAT fat) { return(await _fatRepository.UpdateOneAsync(fat)); }
public File(byte[] buffer, FAT fat, int ParentClusterNumber, Directory parent) : base(buffer, fat, ParentClusterNumber, parent) { }
public Directory(byte[] Buffer, FAT fat, int ParentClusterNumber, Directory parent) : base(Buffer, fat, ParentClusterNumber, parent) { subFiles = new List<File>(); subDirectories = new List<Directory>(); }
public Entity(byte[] Buffer, FAT fat, int clusterIndex, Directory parent) { this.buffer = Buffer; this.parent = parent; this.fat = fat; this.clusterIndex = clusterIndex; }
private void _mainDirFiller(object driveLetter) { fat = new FAT(driveLetter as string); directoryExplorerFiller(fat); }
public static void edit(IntPtr hFile, int clusterIndex, byte[] entity, FAT fat) { edit(hFile, clusterIndex, entity, 0xE5, fat); }
public static void quickFormat(IntPtr hFile, FAT fat) { byte[] buffer = read(hFile, (int)LOCATION.FAT_TABLE_1, fat); for (int i = 8; i < buffer.Length; i++) { if (buffer[i] == 0) continue; else buffer[i] = 0; } write(hFile, (int)LOCATION.FAT_TABLE_1, buffer, fat); buffer = read(hFile, (int)LOCATION.FAT_TABLE_2, fat); for (int i = 8; i < buffer.Length; i++) { if (buffer[i] == 0) continue; else buffer[i] = 0; } write(hFile, (int)LOCATION.FAT_TABLE_2, buffer, fat); buffer = read(hFile, (int)LOCATION.ROOT_DIRECTORY, fat); for (int i = 96; i < buffer.Length; i++) { if (buffer[i] == 0) continue; else buffer[i] = 0; } write(hFile, (int)LOCATION.ROOT_DIRECTORY, buffer, fat); int SIZE = fat.SectorsInVolume * fat.BytesPerSector - fat.RootDirectorySize; buffer = read(hFile, 0, SIZE/2,fat); for (int i = 0; i < buffer.Length/2; i++) { if (buffer[i] == 0) continue; else buffer[i] = 0; } write(hFile, 0, buffer, fat); }
public static byte[] read(IntPtr hFile, int index, FAT fat) { return read(hFile, index, 512, fat); }
public static bool seek(IntPtr hFile, int index, FAT fat) { if (index == (int)LOCATION.BOOT_SECTOR) { return true; } else if (index == (int)LOCATION.FAT_TABLE_1) { seek(hFile, fat.FATTableBlock_1, 0, fat.BytesPerSector); return true; } else if (index == (int)LOCATION.FAT_TABLE_2) { seek(hFile, fat.FATTableBlock_2, 0, fat.BytesPerSector); return true; } else if (index == (int)LOCATION.ROOT_DIRECTORY) { seek(hFile, fat.RootDirectoryBlock, 0, fat.BytesPerSector); return true; } else if (index > 0) { seek(hFile, fat.DataAreaBlock + (index - 2) * fat.SectorsPerCluster, 0, fat.BytesPerSector); return true; } return false; }
public static byte[] read(IntPtr hFile, int index, int size, FAT fat) { seek(hFile, index, fat); if (size % 512 != 0) throw new Exception("Size should be a coefficient of 512"); uint length = 0; var buffer = new byte[size]; if (!ReadFile(hFile, buffer, (uint)buffer.Length, out length, IntPtr.Zero)) { throw new Exception("Error reading file"); } return buffer; }