public bool Close() { if (!IsWriting) { ErrorMessage = "Image is not opened for writing"; return(false); } byte[] hdr = new byte[Marshal.SizeOf <QedHeader>()]; MemoryMarshal.Write(hdr, ref qHdr); writingStream.Seek(0, SeekOrigin.Begin); writingStream.Write(hdr, 0, hdr.Length); writingStream.Seek((long)qHdr.l1_table_offset, SeekOrigin.Begin); byte[] l1TableB = MemoryMarshal.Cast <ulong, byte>(l1Table).ToArray(); writingStream.Write(l1TableB, 0, l1TableB.Length); writingStream.Flush(); writingStream.Close(); IsWriting = false; ErrorMessage = ""; return(true); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { uint sbSize = (uint)(Marshal.SizeOf <RefsVolumeHeader>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <RefsVolumeHeader>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + sbSize >= partition.End) { return(false); } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <RefsVolumeHeader>()) { return(false); } RefsVolumeHeader refsVhdr = Marshal.ByteArrayToStructureLittleEndian <RefsVolumeHeader>(sector); return(refsVhdr.identifier == FSRS && ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.mustBeZero) && refsVhdr.signature.SequenceEqual(refsSignature)); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } uint sbSize = (uint)(Marshal.SizeOf <UNICOS_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <UNICOS_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <UNICOS_Superblock>()) { return(false); } UNICOS_Superblock unicosSb = Marshal.ByteArrayToStructureBigEndian <UNICOS_Superblock>(sector); AaruConsole.DebugWriteLine("UNICOS plugin", "magic = 0x{0:X16} (expected 0x{1:X16})", unicosSb.s_magic, UNICOS_MAGIC); return(unicosSb.s_magic == UNICOS_MAGIC); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { ulong sbSectorOff = SB_POS / imagePlugin.Info.SectorSize; uint sbOff = SB_POS % imagePlugin.Info.SectorSize; if (sbSectorOff + partition.Start >= partition.End) { return(false); } int sbSizeInBytes = Marshal.SizeOf <ext2FSSuperBlock>(); uint sbSizeInSectors = (uint)(sbSizeInBytes / imagePlugin.Info.SectorSize); if (sbSizeInBytes % imagePlugin.Info.SectorSize > 0) { sbSizeInSectors++; } byte[] sbSector = imagePlugin.ReadSectors(sbSectorOff + partition.Start, sbSizeInSectors); byte[] sb = new byte[sbSizeInBytes]; if (sbOff + sbSizeInBytes > sbSector.Length) { return(false); } Array.Copy(sbSector, sbOff, sb, 0, sbSizeInBytes); ushort magic = BitConverter.ToUInt16(sb, 0x038); return(magic == EXT2_MAGIC || magic == EXT2_MAGIC_OLD); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15"); information = ""; if (imagePlugin.Info.SectorSize < 512) { return; } uint sbAddr = REISER4_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <Reiser4_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Reiser4_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <Reiser4_Superblock>()) { return; } Reiser4_Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian <Reiser4_Superblock>(sector); if (!reiser4_magic.SequenceEqual(reiserSb.magic)) { return; } var sb = new StringBuilder(); sb.AppendLine("Reiser 4 filesystem"); sb.AppendFormat("{0} bytes per block", reiserSb.blocksize).AppendLine(); sb.AppendFormat("Volume disk format: {0}", reiserSb.diskformat).AppendLine(); sb.AppendFormat("Volume UUID: {0}", reiserSb.uuid).AppendLine(); sb.AppendFormat("Volume name: {0}", StringHandlers.CToString(reiserSb.label, Encoding)).AppendLine(); information = sb.ToString(); XmlFsType = new FileSystemType { Type = "Reiser 4 filesystem", ClusterSize = reiserSb.blocksize, Clusters = ((partition.End - partition.Start) * imagePlugin.Info.SectorSize) / reiserSb.blocksize, VolumeName = StringHandlers.CToString(reiserSb.label, Encoding), VolumeSerial = reiserSb.uuid.ToString() }; }
public bool Close() { if (!IsWriting) { ErrorMessage = "Image is not opened for writing"; return(false); } if ((_imageInfo.MediaType == MediaType.Unknown || _imageInfo.MediaType == MediaType.GENERIC_HDD || _imageInfo.MediaType == MediaType.FlashDrive || _imageInfo.MediaType == MediaType.CompactFlash || _imageInfo.MediaType == MediaType.CompactFlashType2 || _imageInfo.MediaType == MediaType.PCCardTypeI || _imageInfo.MediaType == MediaType.PCCardTypeII || _imageInfo.MediaType == MediaType.PCCardTypeIII || _imageInfo.MediaType == MediaType.PCCardTypeIV) && _fdihdr.cylinders == 0) { _fdihdr.cylinders = (int)(_imageInfo.Sectors / 8 / 33); _fdihdr.heads = 8; _fdihdr.spt = 33; while (_fdihdr.cylinders == 0) { _fdihdr.heads--; if (_fdihdr.heads == 0) { _fdihdr.spt--; _fdihdr.heads = 8; } _fdihdr.cylinders = (int)_imageInfo.Sectors / _fdihdr.heads / _fdihdr.spt; if (_fdihdr.cylinders == 0 && _fdihdr.heads == 0 && _fdihdr.spt == 0) { break; } } } byte[] hdr = new byte[Marshal.SizeOf <Anex86Header>()]; MemoryMarshal.Write(hdr, ref _fdihdr); _writingStream.Seek(0, SeekOrigin.Begin); _writingStream.Write(hdr, 0, hdr.Length); _writingStream.Flush(); _writingStream.Close(); IsWriting = false; ErrorMessage = ""; return(true); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15"); information = ""; var sb = new StringBuilder(); int sbSizeInBytes = Marshal.SizeOf <XiaSuperBlock>(); uint sbSizeInSectors = (uint)(sbSizeInBytes / imagePlugin.Info.SectorSize); if (sbSizeInBytes % imagePlugin.Info.SectorSize > 0) { sbSizeInSectors++; } byte[] sbSector = imagePlugin.ReadSectors(partition.Start, sbSizeInSectors); XiaSuperBlock supblk = Marshal.ByteArrayToStructureLittleEndian <XiaSuperBlock>(sbSector); sb.AppendFormat("{0} bytes per zone", supblk.s_zone_size).AppendLine(); sb.AppendFormat("{0} zones in volume ({1} bytes)", supblk.s_nzones, supblk.s_nzones * supblk.s_zone_size). AppendLine(); sb.AppendFormat("{0} inodes", supblk.s_ninodes).AppendLine(); sb.AppendFormat("{0} data zones ({1} bytes)", supblk.s_ndatazones, supblk.s_ndatazones * supblk.s_zone_size).AppendLine(); sb.AppendFormat("{0} imap zones ({1} bytes)", supblk.s_imap_zones, supblk.s_imap_zones * supblk.s_zone_size).AppendLine(); sb.AppendFormat("{0} zmap zones ({1} bytes)", supblk.s_zmap_zones, supblk.s_zmap_zones * supblk.s_zone_size).AppendLine(); sb.AppendFormat("First data zone: {0}", supblk.s_firstdatazone).AppendLine(); sb.AppendFormat("Maximum filesize is {0} bytes ({1} MiB)", supblk.s_max_size, supblk.s_max_size / 1048576). AppendLine(); sb.AppendFormat("{0} zones reserved for kernel images ({1} bytes)", supblk.s_kernzones, supblk.s_kernzones * supblk.s_zone_size).AppendLine(); sb.AppendFormat("First kernel zone: {0}", supblk.s_firstkernzone).AppendLine(); XmlFsType = new FileSystemType { Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(supblk.s_boot_segment), Clusters = supblk.s_nzones, ClusterSize = supblk.s_zone_size, Type = "Xia filesystem" }; information = sb.ToString(); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 256) { return(false); } // Documentation says ID should be sector 0 // I've found that OS-9/X68000 has it on sector 4 // I've read OS-9/Apple2 has it on sector 15 foreach (int i in new[] { 0, 4, 15 }) { ulong location = (ulong)i; uint sbSize = (uint)(Marshal.SizeOf <RBF_IdSector>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <RBF_IdSector>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + location + sbSize >= imagePlugin.Info.Sectors) { break; } byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); if (sector.Length < Marshal.SizeOf <RBF_IdSector>()) { return(false); } RBF_IdSector rbfSb = Marshal.ByteArrayToStructureBigEndian <RBF_IdSector>(sector); RBF_NewIdSector rbf9000Sb = Marshal.ByteArrayToStructureBigEndian <RBF_NewIdSector>(sector); AaruConsole.DebugWriteLine("RBF plugin", "magic at {0} = 0x{1:X8} or 0x{2:X8} (expected 0x{3:X8} or 0x{4:X8})", location, rbfSb.dd_sync, rbf9000Sb.rid_sync, RBF_SYNC, RBF_CNYS); if (rbfSb.dd_sync == RBF_SYNC || rbf9000Sb.rid_sync == RBF_SYNC || rbf9000Sb.rid_sync == RBF_CNYS) { return(true); } } return(false); }
public void Close() { var cmdPkt = new AaruPacketCmdClose { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <AaruPacketCmdClose>(), version = Consts.PacketVersion, packetType = AaruPacketType.CommandCloseDevice } }; byte[] buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); _socket.Send(buf, SocketFlags.None); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } for (ulong location = 0; location <= 8; location++) { uint sbSize = (uint)(Marshal.SizeOf <Locus_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Locus_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + location + sbSize >= imagePlugin.Info.Sectors) { break; } byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); if (sector.Length < Marshal.SizeOf <Locus_Superblock>()) { return(false); } Locus_Superblock locusSb = Marshal.ByteArrayToStructureLittleEndian <Locus_Superblock>(sector); AaruConsole.DebugWriteLine("Locus plugin", "magic at {1} = 0x{0:X8}", locusSb.s_magic, location); if (locusSb.s_magic == LOCUS_MAGIC || locusSb.s_magic == LOCUS_CIGAM || locusSb.s_magic == LOCUS_MAGIC_OLD || locusSb.s_magic == LOCUS_CIGAM_OLD) { return(true); } } return(false); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { int sbSizeInBytes = Marshal.SizeOf <XiaSuperBlock>(); uint sbSizeInSectors = (uint)(sbSizeInBytes / imagePlugin.Info.SectorSize); if (sbSizeInBytes % imagePlugin.Info.SectorSize > 0) { sbSizeInSectors++; } if (sbSizeInSectors + partition.Start >= partition.End) { return(false); } byte[] sbSector = imagePlugin.ReadSectors(partition.Start, sbSizeInSectors); XiaSuperBlock supblk = Marshal.ByteArrayToStructureLittleEndian <XiaSuperBlock>(sbSector); return(supblk.s_magic == XIAFS_SUPER_MAGIC); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } // It should be start of a tape or floppy or file if (partition.Start != 0) { return(false); } uint sbSize = (uint)(Marshal.SizeOf <s_spcl>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <s_spcl>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <s_spcl>()) { return(false); } spcl16 oldHdr = Marshal.ByteArrayToStructureLittleEndian <spcl16>(sector); spcl_aix aixHdr = Marshal.ByteArrayToStructureLittleEndian <spcl_aix>(sector); s_spcl newHdr = Marshal.ByteArrayToStructureLittleEndian <s_spcl>(sector); AaruConsole.DebugWriteLine("dump(8) plugin", "old magic = 0x{0:X8}", oldHdr.c_magic); AaruConsole.DebugWriteLine("dump(8) plugin", "aix magic = 0x{0:X8}", aixHdr.c_magic); AaruConsole.DebugWriteLine("dump(8) plugin", "new magic = 0x{0:X8}", newHdr.c_magic); return(oldHdr.c_magic == OFS_MAGIC || aixHdr.c_magic == XIX_MAGIC || aixHdr.c_magic == XIX_CIGAM || newHdr.c_magic == OFS_MAGIC || newHdr.c_magic == NFS_MAGIC || newHdr.c_magic == OFS_CIGAM || newHdr.c_magic == NFS_CIGAM || newHdr.c_magic == UFS2_MAGIC || newHdr.c_magic == UFS2_CIGAM); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <Reiser_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Reiser_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + sbAddr + sbSize >= partition.End) { return(false); } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <Reiser_Superblock>()) { return(false); } Reiser_Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian <Reiser_Superblock>(sector); return(reiser35_magic.SequenceEqual(reiserSb.magic) || reiser36_magic.SequenceEqual(reiserSb.magic) || reiserJr_magic.SequenceEqual(reiserSb.magic)); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < F2FS_MIN_SECTOR || imagePlugin.Info.SectorSize > F2FS_MAX_SECTOR) { return(false); } uint sbAddr = F2FS_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <F2FS_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <F2FS_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + sbAddr >= partition.End) { return(false); } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <F2FS_Superblock>()) { return(false); } F2FS_Superblock f2fsSb = Marshal.ByteArrayToStructureLittleEndian <F2FS_Superblock>(sector); return(f2fsSb.magic == F2FS_MAGIC); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = Encoding.UTF8; information = ""; uint sbSize = (uint)(Marshal.SizeOf <RefsVolumeHeader>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <RefsVolumeHeader>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + sbSize >= partition.End) { return; } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <RefsVolumeHeader>()) { return; } RefsVolumeHeader refsVhdr = Marshal.ByteArrayToStructureLittleEndian <RefsVolumeHeader>(sector); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.jump empty? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.jump)); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.signature = {0}", StringHandlers.CToString(refsVhdr.signature)); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.mustBeZero empty? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.mustBeZero)); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.identifier = {0}", StringHandlers.CToString(BitConverter.GetBytes(refsVhdr.identifier))); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.length = {0}", refsVhdr.length); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.checksum = 0x{0:X4}", refsVhdr.checksum); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.sectors = {0}", refsVhdr.sectors); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.bytesPerSector = {0}", refsVhdr.bytesPerSector); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.sectorsPerCluster = {0}", refsVhdr.sectorsPerCluster); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown1 zero? = {0}", refsVhdr.unknown1 == 0); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown2 zero? = {0}", refsVhdr.unknown2 == 0); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown3 zero? = {0}", refsVhdr.unknown3 == 0); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown4 zero? = {0}", refsVhdr.unknown4 == 0); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown5 empty? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.unknown5)); if (refsVhdr.identifier != FSRS || !ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.mustBeZero) || !refsVhdr.signature.SequenceEqual(refsSignature)) { return; } var sb = new StringBuilder(); sb.AppendLine("Microsoft Resilient File System"); sb.AppendFormat("Volume uses {0} bytes per sector", refsVhdr.bytesPerSector).AppendLine(); sb.AppendFormat("Volume uses {0} sectors per cluster ({1} bytes)", refsVhdr.sectorsPerCluster, refsVhdr.sectorsPerCluster * refsVhdr.bytesPerSector).AppendLine(); sb.AppendFormat("Volume has {0} sectors ({1} bytes)", refsVhdr.sectors, refsVhdr.sectors * refsVhdr.bytesPerSector).AppendLine(); information = sb.ToString(); XmlFsType = new FileSystemType { Type = "Resilient File System", ClusterSize = refsVhdr.bytesPerSector * refsVhdr.sectorsPerCluster, Clusters = refsVhdr.sectors / refsVhdr.sectorsPerCluster }; }
public bool GetFireWireData(out uint idVendor, out uint idProduct, out ulong guid, out string vendor, out string model) { idVendor = 0; idProduct = 0; guid = 0; vendor = null; model = null; var cmdPkt = new AaruPacketCmdGetFireWireData { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <AaruPacketCmdGetFireWireData>(), version = Consts.PacketVersion, packetType = AaruPacketType.CommandGetFireWireData } }; byte[] buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); int len = _socket.Send(buf, SocketFlags.None); if (len != buf.Length) { AaruConsole.ErrorWriteLine("Could not write to the network..."); return(false); } byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(false); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); return(false); } if (hdr.packetType != AaruPacketType.ResponseGetFireWireData) { AaruConsole.ErrorWriteLine("Expected FireWire Data Response Packet, got packet type {0}...", hdr.packetType); return(false); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(false); } AaruPacketResGetFireWireData res = Marshal.ByteArrayToStructureLittleEndian <AaruPacketResGetFireWireData>(buf); if (!res.isFireWire) { return(false); } idVendor = res.idVendor; idProduct = res.idModel; guid = res.guid; vendor = res.vendor; model = res.model; return(true); }
public bool Open(IFilter imageFilter) { Stream stream = imageFilter.GetDataForkStream(); stream.Seek(0, SeekOrigin.Begin); if (stream.Length < 512) { return(false); } byte[] qHdrB = new byte[Marshal.SizeOf <QCow2Header>()]; stream.Read(qHdrB, 0, Marshal.SizeOf <QCow2Header>()); qHdr = Marshal.SpanToStructureBigEndian <QCow2Header>(qHdrB); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.magic = 0x{0:X8}", qHdr.magic); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.version = {0}", qHdr.version); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.backing_file_offset = {0}", qHdr.backing_file_offset); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.backing_file_size = {0}", qHdr.backing_file_size); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.cluster_bits = {0}", qHdr.cluster_bits); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.size = {0}", qHdr.size); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.crypt_method = {0}", qHdr.crypt_method); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.l1_size = {0}", qHdr.l1_size); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.l1_table_offset = {0}", qHdr.l1_table_offset); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.refcount_table_offset = {0}", qHdr.refcount_table_offset); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.refcount_table_clusters = {0}", qHdr.refcount_table_clusters); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.nb_snapshots = {0}", qHdr.nb_snapshots); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.snapshots_offset = {0}", qHdr.snapshots_offset); if (qHdr.version >= QCOW_VERSION3) { AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.features = {0:X}", qHdr.features); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.compat_features = {0:X}", qHdr.compat_features); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.autoclear_features = {0:X}", qHdr.autoclear_features); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.refcount_order = {0}", qHdr.refcount_order); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.header_length = {0}", qHdr.header_length); if ((qHdr.features & QCOW_FEATURE_MASK) != 0) { throw new ImageNotSupportedException($"Unknown incompatible features {qHdr.features & QCOW_FEATURE_MASK:X} enabled, not proceeding."); } } if (qHdr.size <= 1) { throw new ArgumentOutOfRangeException(nameof(qHdr.size), "Image size is too small"); } if (qHdr.cluster_bits < 9 || qHdr.cluster_bits > 16) { throw new ArgumentOutOfRangeException(nameof(qHdr.cluster_bits), "Cluster size must be between 512 bytes and 64 Kbytes"); } if (qHdr.crypt_method > QCOW_ENCRYPTION_AES) { throw new ArgumentOutOfRangeException(nameof(qHdr.crypt_method), "Invalid encryption method"); } if (qHdr.crypt_method > QCOW_ENCRYPTION_NONE) { throw new NotImplementedException("AES encrypted images not yet supported"); } if (qHdr.backing_file_offset != 0) { throw new NotImplementedException("Differencing images not yet supported"); } clusterSize = 1 << (int)qHdr.cluster_bits; clusterSectors = 1 << ((int)qHdr.cluster_bits - 9); l2Bits = (int)(qHdr.cluster_bits - 3); l2Size = 1 << l2Bits; AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.clusterSize = {0}", clusterSize); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.clusterSectors = {0}", clusterSectors); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.qHdr.l1_size = {0}", qHdr.l1_size); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.l2Size = {0}", l2Size); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.sectors = {0}", imageInfo.Sectors); byte[] l1TableB = new byte[qHdr.l1_size * 8]; stream.Seek((long)qHdr.l1_table_offset, SeekOrigin.Begin); stream.Read(l1TableB, 0, (int)qHdr.l1_size * 8); l1Table = MemoryMarshal.Cast <byte, ulong>(l1TableB).ToArray(); AaruConsole.DebugWriteLine("QCOW plugin", "Reading L1 table"); for (long i = 0; i < l1Table.LongLength; i++) { l1Table[i] = Swapping.Swap(l1Table[i]); } l1Mask = 0; int c = 0; l1Shift = (int)(l2Bits + qHdr.cluster_bits); for (int i = 0; i < 64; i++) { l1Mask <<= 1; if (c >= 64 - l1Shift) { continue; } l1Mask += 1; c++; } l2Mask = 0; for (int i = 0; i < l2Bits; i++) { l2Mask = (l2Mask << 1) + 1; } l2Mask <<= (int)qHdr.cluster_bits; sectorMask = 0; for (int i = 0; i < qHdr.cluster_bits; i++) { sectorMask = (sectorMask << 1) + 1; } AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.l1Mask = {0:X}", l1Mask); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.l1Shift = {0}", l1Shift); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.l2Mask = {0:X}", l2Mask); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.sectorMask = {0:X}", sectorMask); maxL2TableCache = MAX_CACHE_SIZE / (l2Size * 8); maxClusterCache = MAX_CACHE_SIZE / clusterSize; imageStream = stream; sectorCache = new Dictionary <ulong, byte[]>(); l2TableCache = new Dictionary <ulong, ulong[]>(); clusterCache = new Dictionary <ulong, byte[]>(); imageInfo.CreationTime = imageFilter.GetCreationTime(); imageInfo.LastModificationTime = imageFilter.GetLastWriteTime(); imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename()); imageInfo.Sectors = qHdr.size / 512; imageInfo.SectorSize = 512; imageInfo.XmlMediaType = XmlMediaType.BlockMedia; imageInfo.MediaType = MediaType.GENERIC_HDD; imageInfo.ImageSize = qHdr.size; imageInfo.Version = $"{qHdr.version}"; imageInfo.Cylinders = (uint)(imageInfo.Sectors / 16 / 63); imageInfo.Heads = 16; imageInfo.SectorsPerTrack = 63; return(true); }
public bool Identify(IMediaImage imagePlugin, Partition partition) { if (imagePlugin.Info.SectorSize < 512) { return(false); } // Misaligned if (imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc) { uint sbSize = (uint)((Marshal.SizeOf <XFS_Superblock>() + 0x400) / imagePlugin.Info.SectorSize); if ((Marshal.SizeOf <XFS_Superblock>() + 0x400) % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <XFS_Superblock>()) { return(false); } byte[] sbpiece = new byte[Marshal.SizeOf <XFS_Superblock>()]; foreach (int location in new[] { 0, 0x200, 0x400 }) { Array.Copy(sector, location, sbpiece, 0, Marshal.SizeOf <XFS_Superblock>()); XFS_Superblock xfsSb = Marshal.ByteArrayToStructureBigEndian <XFS_Superblock>(sbpiece); AaruConsole.DebugWriteLine("XFS plugin", "magic at 0x{0:X3} = 0x{1:X8} (expected 0x{2:X8})", location, xfsSb.magicnum, XFS_MAGIC); if (xfsSb.magicnum == XFS_MAGIC) { return(true); } } } else { foreach (int i in new[] { 0, 1, 2 }) { ulong location = (ulong)i; uint sbSize = (uint)(Marshal.SizeOf <XFS_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <XFS_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); if (sector.Length < Marshal.SizeOf <XFS_Superblock>()) { return(false); } XFS_Superblock xfsSb = Marshal.ByteArrayToStructureBigEndian <XFS_Superblock>(sector); AaruConsole.DebugWriteLine("XFS plugin", "magic at {0} = 0x{1:X8} (expected 0x{2:X8})", location, xfsSb.magicnum, XFS_MAGIC); if (xfsSb.magicnum == XFS_MAGIC) { return(true); } } } return(false); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15"); information = ""; if (imagePlugin.Info.SectorSize < 512) { return; } var xfsSb = new XFS_Superblock(); // Misaligned if (imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc) { uint sbSize = (uint)((Marshal.SizeOf <XFS_Superblock>() + 0x400) / imagePlugin.Info.SectorSize); if ((Marshal.SizeOf <XFS_Superblock>() + 0x400) % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <XFS_Superblock>()) { return; } byte[] sbpiece = new byte[Marshal.SizeOf <XFS_Superblock>()]; foreach (int location in new[] { 0, 0x200, 0x400 }) { Array.Copy(sector, location, sbpiece, 0, Marshal.SizeOf <XFS_Superblock>()); xfsSb = Marshal.ByteArrayToStructureBigEndian <XFS_Superblock>(sbpiece); AaruConsole.DebugWriteLine("XFS plugin", "magic at 0x{0:X3} = 0x{1:X8} (expected 0x{2:X8})", location, xfsSb.magicnum, XFS_MAGIC); if (xfsSb.magicnum == XFS_MAGIC) { break; } } } else { foreach (int i in new[] { 0, 1, 2 }) { ulong location = (ulong)i; uint sbSize = (uint)(Marshal.SizeOf <XFS_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <XFS_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize); if (sector.Length < Marshal.SizeOf <XFS_Superblock>()) { return; } xfsSb = Marshal.ByteArrayToStructureBigEndian <XFS_Superblock>(sector); AaruConsole.DebugWriteLine("XFS plugin", "magic at {0} = 0x{1:X8} (expected 0x{2:X8})", location, xfsSb.magicnum, XFS_MAGIC); if (xfsSb.magicnum == XFS_MAGIC) { break; } } } if (xfsSb.magicnum != XFS_MAGIC) { return; } var sb = new StringBuilder(); sb.AppendLine("XFS filesystem"); sb.AppendFormat("Filesystem version {0}", xfsSb.version & 0xF).AppendLine(); sb.AppendFormat("{0} bytes per sector", xfsSb.sectsize).AppendLine(); sb.AppendFormat("{0} bytes per block", xfsSb.blocksize).AppendLine(); sb.AppendFormat("{0} bytes per inode", xfsSb.inodesize).AppendLine(); sb.AppendFormat("{0} data blocks in volume, {1} free", xfsSb.dblocks, xfsSb.fdblocks).AppendLine(); sb.AppendFormat("{0} blocks per allocation group", xfsSb.agblocks).AppendLine(); sb.AppendFormat("{0} allocation groups in volume", xfsSb.agcount).AppendLine(); sb.AppendFormat("{0} inodes in volume, {1} free", xfsSb.icount, xfsSb.ifree).AppendLine(); if (xfsSb.inprogress > 0) { sb.AppendLine("fsck in progress"); } sb.AppendFormat("Volume name: {0}", StringHandlers.CToString(xfsSb.fname, Encoding)).AppendLine(); sb.AppendFormat("Volume UUID: {0}", xfsSb.uuid).AppendLine(); information = sb.ToString(); XmlFsType = new FileSystemType { Type = "XFS filesystem", ClusterSize = xfsSb.blocksize, Clusters = xfsSb.dblocks, FreeClusters = xfsSb.fdblocks, FreeClustersSpecified = true, Files = xfsSb.icount - xfsSb.ifree, FilesSpecified = true, Dirty = xfsSb.inprogress > 0, VolumeName = StringHandlers.CToString(xfsSb.fname, Encoding), VolumeSerial = xfsSb.uuid.ToString() }; }
public bool GetPcmciaData(out byte[] cis) { cis = null; var cmdPkt = new AaruPacketCmdGetPcmciaData { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <AaruPacketCmdGetPcmciaData>(), version = Consts.PacketVersion, packetType = AaruPacketType.CommandGetPcmciaData } }; byte[] buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); int len = _socket.Send(buf, SocketFlags.None); if (len != buf.Length) { AaruConsole.ErrorWriteLine("Could not write to the network..."); return(false); } byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(false); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); return(false); } if (hdr.packetType != AaruPacketType.ResponseGetPcmciaData) { AaruConsole.ErrorWriteLine("Expected PCMCIA Data Response Packet, got packet type {0}...", hdr.packetType); return(false); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(false); } AaruPacketResGetPcmciaData res = Marshal.ByteArrayToStructureLittleEndian <AaruPacketResGetPcmciaData>(buf); if (!res.isPcmcia) { return(false); } cis = res.cis; return(true); }
public Remote(string host) { _host = host; IPHostEntry ipHostEntry = Dns.GetHostEntry(host); IPAddress ipAddress = ipHostEntry.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork); if (ipAddress is null) { AaruConsole.ErrorWriteLine("Host not found"); throw new SocketException(11001); } var ipEndPoint = new IPEndPoint(ipAddress, 6666); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _socket.Connect(ipEndPoint); AaruConsole.WriteLine("Connected to {0}", host); byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; int len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); throw new ArgumentException(); } byte[] buf; if (hdr.packetType != AaruPacketType.Hello) { if (hdr.packetType != AaruPacketType.Nop) { AaruConsole.ErrorWriteLine("Expected Hello Packet, got packet type {0}...", hdr.packetType); throw new ArgumentException(); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } AaruPacketNop nop = Marshal.ByteArrayToStructureLittleEndian <AaruPacketNop>(buf); AaruConsole.ErrorWriteLine($"{nop.reason}"); throw new ArgumentException(); } if (hdr.version != Consts.PacketVersion) { AaruConsole.ErrorWriteLine("Unrecognized packet version..."); throw new ArgumentException(); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } AaruPacketHello serverHello = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHello>(buf); ServerApplication = serverHello.application; ServerVersion = serverHello.version; ServerOperatingSystem = serverHello.sysname; ServerOperatingSystemVersion = serverHello.release; ServerArchitecture = serverHello.machine; ServerProtocolVersion = serverHello.maxProtocol; var clientHello = new AaruPacketHello { application = "Aaru", version = Version.GetVersion(), maxProtocol = Consts.MaxProtocol, sysname = DetectOS.GetPlatformName(DetectOS.GetRealPlatformID(), DetectOS.GetVersion()), release = DetectOS.GetVersion(), machine = RuntimeInformation.ProcessArchitecture.ToString(), hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <AaruPacketHello>(), version = Consts.PacketVersion, packetType = AaruPacketType.Hello } }; buf = Marshal.StructureToByteArrayLittleEndian(clientHello); len = _socket.Send(buf, SocketFlags.None); if (len >= buf.Length) { return; } AaruConsole.ErrorWriteLine("Could not write to the network..."); throw new IOException(); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = Encoding.Unicode; information = ""; if (imagePlugin.Info.SectorSize < F2FS_MIN_SECTOR || imagePlugin.Info.SectorSize > F2FS_MAX_SECTOR) { return; } uint sbAddr = F2FS_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <F2FS_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <F2FS_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <F2FS_Superblock>()) { return; } F2FS_Superblock f2fsSb = Marshal.ByteArrayToStructureLittleEndian <F2FS_Superblock>(sector); if (f2fsSb.magic != F2FS_MAGIC) { return; } var sb = new StringBuilder(); sb.AppendLine("F2FS filesystem"); sb.AppendFormat("Version {0}.{1}", f2fsSb.major_ver, f2fsSb.minor_ver).AppendLine(); sb.AppendFormat("{0} bytes per sector", 1 << (int)f2fsSb.log_sectorsize).AppendLine(); sb.AppendFormat("{0} sectors ({1} bytes) per block", 1 << (int)f2fsSb.log_sectors_per_block, 1 << (int)f2fsSb.log_blocksize).AppendLine(); sb.AppendFormat("{0} blocks per segment", f2fsSb.log_blocks_per_seg).AppendLine(); sb.AppendFormat("{0} blocks in volume", f2fsSb.block_count).AppendLine(); sb.AppendFormat("{0} segments per section", f2fsSb.segs_per_sec).AppendLine(); sb.AppendFormat("{0} sections per zone", f2fsSb.secs_per_zone).AppendLine(); sb.AppendFormat("{0} sections", f2fsSb.section_count).AppendLine(); sb.AppendFormat("{0} segments", f2fsSb.segment_count).AppendLine(); sb.AppendFormat("Root directory resides on inode {0}", f2fsSb.root_ino).AppendLine(); sb.AppendFormat("Volume UUID: {0}", f2fsSb.uuid).AppendLine(); sb.AppendFormat("Volume name: {0}", StringHandlers.CToString(f2fsSb.volume_name, Encoding.Unicode, true)). AppendLine(); sb.AppendFormat("Volume last mounted on kernel version: {0}", StringHandlers.CToString(f2fsSb.version)). AppendLine(); sb.AppendFormat("Volume created on kernel version: {0}", StringHandlers.CToString(f2fsSb.init_version)). AppendLine(); information = sb.ToString(); XmlFsType = new FileSystemType { Type = "F2FS filesystem", SystemIdentifier = Encoding.ASCII.GetString(f2fsSb.version), Clusters = f2fsSb.block_count, ClusterSize = (uint)(1 << (int)f2fsSb.log_blocksize), DataPreparerIdentifier = Encoding.ASCII.GetString(f2fsSb.init_version), VolumeName = StringHandlers.CToString(f2fsSb.volume_name, Encoding.Unicode, true), VolumeSerial = f2fsSb.uuid.ToString() }; }
public DeviceInfo[] ListDevices() { var cmdPkt = new AaruPacketCommandListDevices { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <AaruPacketCommandListDevices>(), version = Consts.PacketVersion, packetType = AaruPacketType.CommandListDevices } }; byte[] buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); int len = _socket.Send(buf, SocketFlags.None); if (len != buf.Length) { AaruConsole.ErrorWriteLine("Could not write to the network..."); return(new DeviceInfo[0]); } byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(new DeviceInfo[0]); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); return(new DeviceInfo[0]); } if (hdr.packetType != AaruPacketType.ResponseListDevices) { if (hdr.packetType != AaruPacketType.Nop) { AaruConsole.ErrorWriteLine("Expected List Devices Response Packet, got packet type {0}...", hdr.packetType); return(new DeviceInfo[0]); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(new DeviceInfo[0]); } AaruPacketNop nop = Marshal.ByteArrayToStructureLittleEndian <AaruPacketNop>(buf); AaruConsole.ErrorWriteLine($"{nop.reason}"); return(new DeviceInfo[0]); } if (hdr.version != Consts.PacketVersion) { AaruConsole.ErrorWriteLine("Unrecognized packet version..."); return(new DeviceInfo[0]); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(new DeviceInfo[0]); } AaruPacketResponseListDevices response = Marshal.ByteArrayToStructureLittleEndian <AaruPacketResponseListDevices>(buf); List <DeviceInfo> devices = new List <DeviceInfo>(); int offset = Marshal.SizeOf <AaruPacketResponseListDevices>(); int devInfoLen = Marshal.SizeOf <DeviceInfo>(); for (ushort i = 0; i < response.devices; i++) { DeviceInfo dev = Marshal.ByteArrayToStructureLittleEndian <DeviceInfo>(buf, offset, devInfoLen); dev.Path = dev.Path[0] == '/' ? $"aaru://{_host}{dev.Path}" : $"aaru://{_host}/{dev.Path}"; devices.Add(dev); offset += devInfoLen; } return(devices.ToArray()); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15"); information = ""; if (imagePlugin.Info.SectorSize < 512) { return; } if (partition.Start != 0) { return; } uint sbSize = (uint)(Marshal.SizeOf <s_spcl>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <s_spcl>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <s_spcl>()) { return; } spcl16 oldHdr = Marshal.ByteArrayToStructureLittleEndian <spcl16>(sector); spcl_aix aixHdr = Marshal.ByteArrayToStructureLittleEndian <spcl_aix>(sector); s_spcl newHdr = Marshal.ByteArrayToStructureLittleEndian <s_spcl>(sector); bool useOld = false; bool useAix = false; if (newHdr.c_magic == OFS_MAGIC || newHdr.c_magic == NFS_MAGIC || newHdr.c_magic == OFS_CIGAM || newHdr.c_magic == NFS_CIGAM || newHdr.c_magic == UFS2_MAGIC || newHdr.c_magic == UFS2_CIGAM) { if (newHdr.c_magic == OFS_CIGAM || newHdr.c_magic == NFS_CIGAM || newHdr.c_magic == UFS2_CIGAM) { newHdr = Marshal.ByteArrayToStructureBigEndian <s_spcl>(sector); } } else if (aixHdr.c_magic == XIX_MAGIC || aixHdr.c_magic == XIX_CIGAM) { useAix = true; if (aixHdr.c_magic == XIX_CIGAM) { aixHdr = Marshal.ByteArrayToStructureBigEndian <spcl_aix>(sector); } } else if (oldHdr.c_magic == OFS_MAGIC) { useOld = true; // Swap PDP-11 endian oldHdr.c_date = (int)Swapping.PDPFromLittleEndian((uint)oldHdr.c_date); oldHdr.c_ddate = (int)Swapping.PDPFromLittleEndian((uint)oldHdr.c_ddate); } else { information = "Could not read dump(8) header block"; return; } var sb = new StringBuilder(); XmlFsType = new FileSystemType { ClusterSize = 1024, Clusters = partition.Size / 1024 }; if (useOld) { XmlFsType.Type = "Old 16-bit dump(8)"; sb.AppendLine(XmlFsType.Type); if (oldHdr.c_date > 0) { XmlFsType.CreationDate = DateHandlers.UnixToDateTime(oldHdr.c_date); XmlFsType.CreationDateSpecified = true; sb.AppendFormat("Dump created on {0}", XmlFsType.CreationDate).AppendLine(); } if (oldHdr.c_ddate > 0) { XmlFsType.BackupDate = DateHandlers.UnixToDateTime(oldHdr.c_ddate); XmlFsType.BackupDateSpecified = true; sb.AppendFormat("Previous dump created on {0}", XmlFsType.BackupDate).AppendLine(); } sb.AppendFormat("Dump volume number: {0}", oldHdr.c_volume).AppendLine(); } else if (useAix) { XmlFsType.Type = "AIX dump(8)"; sb.AppendLine(XmlFsType.Type); if (aixHdr.c_date > 0) { XmlFsType.CreationDate = DateHandlers.UnixToDateTime(aixHdr.c_date); XmlFsType.CreationDateSpecified = true; sb.AppendFormat("Dump created on {0}", XmlFsType.CreationDate).AppendLine(); } if (aixHdr.c_ddate > 0) { XmlFsType.BackupDate = DateHandlers.UnixToDateTime(aixHdr.c_ddate); XmlFsType.BackupDateSpecified = true; sb.AppendFormat("Previous dump created on {0}", XmlFsType.BackupDate).AppendLine(); } sb.AppendFormat("Dump volume number: {0}", aixHdr.c_volume).AppendLine(); } else { XmlFsType.Type = "dump(8)"; sb.AppendLine(XmlFsType.Type); if (newHdr.c_ndate > 0) { XmlFsType.CreationDate = DateHandlers.UnixToDateTime(newHdr.c_ndate); XmlFsType.CreationDateSpecified = true; sb.AppendFormat("Dump created on {0}", XmlFsType.CreationDate).AppendLine(); } else if (newHdr.c_date > 0) { XmlFsType.CreationDate = DateHandlers.UnixToDateTime(newHdr.c_date); XmlFsType.CreationDateSpecified = true; sb.AppendFormat("Dump created on {0}", XmlFsType.CreationDate).AppendLine(); } if (newHdr.c_nddate > 0) { XmlFsType.BackupDate = DateHandlers.UnixToDateTime(newHdr.c_nddate); XmlFsType.BackupDateSpecified = true; sb.AppendFormat("Previous dump created on {0}", XmlFsType.BackupDate).AppendLine(); } else if (newHdr.c_ddate > 0) { XmlFsType.BackupDate = DateHandlers.UnixToDateTime(newHdr.c_ddate); XmlFsType.BackupDateSpecified = true; sb.AppendFormat("Previous dump created on {0}", XmlFsType.BackupDate).AppendLine(); } sb.AppendFormat("Dump volume number: {0}", newHdr.c_volume).AppendLine(); sb.AppendFormat("Dump level: {0}", newHdr.c_level).AppendLine(); string dumpname = StringHandlers.CToString(newHdr.c_label); if (!string.IsNullOrEmpty(dumpname)) { XmlFsType.VolumeName = dumpname; sb.AppendFormat("Dump label: {0}", dumpname).AppendLine(); } string str = StringHandlers.CToString(newHdr.c_filesys); if (!string.IsNullOrEmpty(str)) { sb.AppendFormat("Dumped filesystem name: {0}", str).AppendLine(); } str = StringHandlers.CToString(newHdr.c_dev); if (!string.IsNullOrEmpty(str)) { sb.AppendFormat("Dumped device: {0}", str).AppendLine(); } str = StringHandlers.CToString(newHdr.c_host); if (!string.IsNullOrEmpty(str)) { sb.AppendFormat("Dump hostname: {0}", str).AppendLine(); } } information = sb.ToString(); }
public DeviceType GetDeviceType() { var cmdPkt = new AaruPacketCmdGetDeviceType { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <AaruPacketCmdGetDeviceType>(), version = Consts.PacketVersion, packetType = AaruPacketType.CommandGetType } }; byte[] buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); int len = _socket.Send(buf, SocketFlags.None); if (len != buf.Length) { AaruConsole.ErrorWriteLine("Could not write to the network..."); return(DeviceType.Unknown); } byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(DeviceType.Unknown); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); return(DeviceType.Unknown); } if (hdr.packetType != AaruPacketType.ResponseGetType) { AaruConsole.ErrorWriteLine("Expected Device Type Response Packet, got packet type {0}...", hdr.packetType); return(DeviceType.Unknown); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(DeviceType.Unknown); } AaruPacketResGetDeviceType res = Marshal.ByteArrayToStructureLittleEndian <AaruPacketResGetDeviceType>(buf); return(res.device_type); }
public int SendMmcCommand(MmcCommands command, bool write, bool isApplication, MmcFlags flags, uint argument, uint blockSize, uint blocks, ref byte[] buffer, out uint[] response, out double duration, out bool sense, uint timeout = 0) { duration = 0; sense = true; response = null; var cmdPkt = new AaruPacketCmdSdhci { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, version = Consts.PacketVersion, packetType = AaruPacketType.CommandAtaLba48 }, command = command, write = write, application = isApplication, flags = flags, argument = argument, block_size = blockSize, blocks = blocks, timeout = timeout * 1000 }; if (buffer != null) { cmdPkt.buf_len = (uint)buffer.Length; } cmdPkt.hdr.len = (uint)(Marshal.SizeOf <AaruPacketCmdSdhci>() + cmdPkt.buf_len); byte[] pktBuf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); byte[] buf = new byte[cmdPkt.hdr.len]; Array.Copy(pktBuf, 0, buf, 0, Marshal.SizeOf <AaruPacketCmdSdhci>()); if (buffer != null) { Array.Copy(buffer, 0, buf, Marshal.SizeOf <AaruPacketCmdSdhci>(), cmdPkt.buf_len); } int len = _socket.Send(buf, SocketFlags.None); if (len != buf.Length) { AaruConsole.ErrorWriteLine("Could not write to the network..."); return(-1); } byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(-1); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); return(-1); } if (hdr.packetType != AaruPacketType.ResponseSdhci) { AaruConsole.ErrorWriteLine("Expected SDHCI Response Packet, got packet type {0}...", hdr.packetType); return(-1); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(-1); } AaruPacketResSdhci res = Marshal.ByteArrayToStructureLittleEndian <AaruPacketResSdhci>(buf); buffer = new byte[res.buf_len]; Array.Copy(buf, Marshal.SizeOf <AaruPacketResSdhci>(), buffer, 0, res.buf_len); duration = res.duration; sense = res.sense != 0; response = new uint[4]; response[0] = res.response[0]; response[1] = res.response[1]; response[2] = res.response[2]; response[3] = res.response[3]; return((int)res.error_no); }
public bool Open(string devicePath, out int lastError) { lastError = 0; var cmdPkt = new AaruPacketCommandOpenDevice { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <AaruPacketCommandOpenDevice>(), version = Consts.PacketVersion, packetType = AaruPacketType.CommandOpen }, device_path = devicePath }; byte[] buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); int len = _socket.Send(buf, SocketFlags.None); if (len != buf.Length) { AaruConsole.ErrorWriteLine("Could not write to the network..."); lastError = -1; return(false); } byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); lastError = -1; return(false); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); lastError = -1; return(false); } if (hdr.packetType != AaruPacketType.Nop) { AaruConsole.ErrorWriteLine("Expected List Devices Response Packet, got packet type {0}...", hdr.packetType); lastError = -1; return(false); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); lastError = -1; return(false); } AaruPacketNop nop = Marshal.ByteArrayToStructureLittleEndian <AaruPacketNop>(buf); switch (nop.reasonCode) { case AaruNopReason.OpenOk: return(true); case AaruNopReason.NotImplemented: throw new NotImplementedException($"{nop.reason}"); } AaruConsole.ErrorWriteLine($"{nop.reason}"); lastError = nop.errno; return(false); }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15"); information = ""; if (imagePlugin.Info.SectorSize < 512) { return; } uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize; if (sbAddr == 0) { sbAddr = 1; } uint sbSize = (uint)(Marshal.SizeOf <Reiser_Superblock>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <Reiser_Superblock>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize); if (sector.Length < Marshal.SizeOf <Reiser_Superblock>()) { return; } Reiser_Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian <Reiser_Superblock>(sector); if (!reiser35_magic.SequenceEqual(reiserSb.magic) && !reiser36_magic.SequenceEqual(reiserSb.magic) && !reiserJr_magic.SequenceEqual(reiserSb.magic)) { return; } var sb = new StringBuilder(); if (reiser35_magic.SequenceEqual(reiserSb.magic)) { sb.AppendLine("Reiser 3.5 filesystem"); } else if (reiser36_magic.SequenceEqual(reiserSb.magic)) { sb.AppendLine("Reiser 3.6 filesystem"); } else if (reiserJr_magic.SequenceEqual(reiserSb.magic)) { sb.AppendLine("Reiser Jr. filesystem"); } sb.AppendFormat("Volume has {0} blocks with {1} blocks free", reiserSb.block_count, reiserSb.free_blocks). AppendLine(); sb.AppendFormat("{0} bytes per block", reiserSb.blocksize).AppendLine(); sb.AppendFormat("Root directory resides on block {0}", reiserSb.root_block).AppendLine(); if (reiserSb.umount_state == 2) { sb.AppendLine("Volume has not been cleanly umounted"); } sb.AppendFormat("Volume last checked on {0}", DateHandlers.UnixUnsignedToDateTime(reiserSb.last_check)). AppendLine(); if (reiserSb.version >= 2) { sb.AppendFormat("Volume UUID: {0}", reiserSb.uuid).AppendLine(); sb.AppendFormat("Volume name: {0}", Encoding.GetString(reiserSb.label)).AppendLine(); } information = sb.ToString(); XmlFsType = new FileSystemType(); if (reiser35_magic.SequenceEqual(reiserSb.magic)) { XmlFsType.Type = "Reiser 3.5 filesystem"; } else if (reiser36_magic.SequenceEqual(reiserSb.magic)) { XmlFsType.Type = "Reiser 3.6 filesystem"; } else if (reiserJr_magic.SequenceEqual(reiserSb.magic)) { XmlFsType.Type = "Reiser Jr. filesystem"; } XmlFsType.ClusterSize = reiserSb.blocksize; XmlFsType.Clusters = reiserSb.block_count; XmlFsType.FreeClusters = reiserSb.free_blocks; XmlFsType.FreeClustersSpecified = true; XmlFsType.Dirty = reiserSb.umount_state == 2; if (reiserSb.version < 2) { return; } XmlFsType.VolumeName = Encoding.GetString(reiserSb.label); XmlFsType.VolumeSerial = reiserSb.uuid.ToString(); }
public int SendAtaCommand(AtaRegistersLba48 registers, out AtaErrorRegistersLba48 errorRegisters, AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout, bool transferBlocks, out double duration, out bool sense) { duration = 0; sense = true; errorRegisters = new AtaErrorRegistersLba48(); var cmdPkt = new AaruPacketCmdAtaLba48 { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, version = Consts.PacketVersion, packetType = AaruPacketType.CommandAtaLba48 }, registers = registers, protocol = (byte)protocol, transferRegister = (byte)transferRegister, transferBlocks = transferBlocks, timeout = timeout * 1000 }; if (buffer != null) { cmdPkt.buf_len = (uint)buffer.Length; } cmdPkt.hdr.len = (uint)(Marshal.SizeOf <AaruPacketCmdAtaLba48>() + cmdPkt.buf_len); byte[] pktBuf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); byte[] buf = new byte[cmdPkt.hdr.len]; Array.Copy(pktBuf, 0, buf, 0, Marshal.SizeOf <AaruPacketCmdAtaLba48>()); if (buffer != null) { Array.Copy(buffer, 0, buf, Marshal.SizeOf <AaruPacketCmdAtaLba48>(), cmdPkt.buf_len); } int len = _socket.Send(buf, SocketFlags.None); if (len != buf.Length) { AaruConsole.ErrorWriteLine("Could not write to the network..."); return(-1); } byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(-1); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); return(-1); } if (hdr.packetType != AaruPacketType.ResponseAtaLba48) { AaruConsole.ErrorWriteLine("Expected ATA LBA48 Response Packet, got packet type {0}...", hdr.packetType); return(-1); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(-1); } AaruPacketResAtaLba48 res = Marshal.ByteArrayToStructureLittleEndian <AaruPacketResAtaLba48>(buf); buffer = new byte[res.buf_len]; Array.Copy(buf, Marshal.SizeOf <AaruPacketResAtaLba48>(), buffer, 0, res.buf_len); duration = res.duration; sense = res.sense != 0; errorRegisters = res.registers; return((int)res.error_no); }
public int SendScsiCommand(byte[] cdb, ref byte[] buffer, out byte[] senseBuffer, uint timeout, ScsiDirection direction, out double duration, out bool sense) { senseBuffer = null; duration = 0; sense = true; var cmdPkt = new AaruPacketCmdScsi { hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, version = Consts.PacketVersion, packetType = AaruPacketType.CommandScsi }, direction = (int)direction, timeout = timeout * 1000 }; if (cdb != null) { cmdPkt.cdb_len = (uint)cdb.Length; } if (buffer != null) { cmdPkt.buf_len = (uint)buffer.Length; } cmdPkt.hdr.len = (uint)(Marshal.SizeOf <AaruPacketCmdScsi>() + cmdPkt.cdb_len + cmdPkt.buf_len); byte[] pktBuf = Marshal.StructureToByteArrayLittleEndian(cmdPkt); byte[] buf = new byte[cmdPkt.hdr.len]; Array.Copy(pktBuf, 0, buf, 0, Marshal.SizeOf <AaruPacketCmdScsi>()); if (cdb != null) { Array.Copy(cdb, 0, buf, Marshal.SizeOf <AaruPacketCmdScsi>(), cmdPkt.cdb_len); } if (buffer != null) { Array.Copy(buffer, 0, buf, Marshal.SizeOf <AaruPacketCmdScsi>() + cmdPkt.cdb_len, cmdPkt.buf_len); } int len = _socket.Send(buf, SocketFlags.None); if (len != buf.Length) { AaruConsole.ErrorWriteLine("Could not write to the network..."); return(-1); } byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(-1); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); return(-1); } if (hdr.packetType != AaruPacketType.ResponseScsi) { AaruConsole.ErrorWriteLine("Expected SCSI Response Packet, got packet type {0}...", hdr.packetType); return(-1); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); return(-1); } AaruPacketResScsi res = Marshal.ByteArrayToStructureLittleEndian <AaruPacketResScsi>(buf); senseBuffer = new byte[res.sense_len]; Array.Copy(buf, Marshal.SizeOf <AaruPacketResScsi>(), senseBuffer, 0, res.sense_len); buffer = new byte[res.buf_len]; Array.Copy(buf, Marshal.SizeOf <AaruPacketResScsi>() + res.sense_len, buffer, 0, res.buf_len); duration = res.duration; sense = res.sense != 0; return((int)res.error_no); }