public bool Identify(IFilter imageFilter) { Stream stream = imageFilter.GetDataForkStream(); if (stream.Length < Marshal.SizeOf <RayHdr>()) { return(false); } byte[] buffer = new byte[Marshal.SizeOf <RayHdr>()]; stream.Seek(0, SeekOrigin.Begin); stream.Read(buffer, 0, buffer.Length); RayHdr header = Marshal.ByteArrayToStructureLittleEndian <RayHdr>(buffer); string signature = StringHandlers.CToString(header.signature); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.signature = {0}", signature); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.diskType = {0}", header.diskType); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.heads = {0}", header.heads); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.cylinders = {0}", header.cylinders); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.sectorsPerTrack = {0}", header.sectorsPerTrack); Regex sx = new Regex(REGEX_SIGNATURE); Match sm = sx.Match(signature); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.signature matches? = {0}", sm.Success); return(sm.Success); }
public bool Close() { if (!IsWriting) { ErrorMessage = "Image is not opened for writing"; return(false); } string headerSignature = $"Disk IMage VER 1.0 Copyright (C) {DateTime.Now.Year:D4} Ray Arachelian, All Rights Reserved. Aaru "; var header = new RayHdr { signature = Encoding.ASCII.GetBytes(headerSignature), cylinders = (byte)_imageInfo.Cylinders, diskType = RayDiskTypes.Mf2ed, heads = (byte)_imageInfo.Heads, sectorsPerTrack = (byte)_imageInfo.SectorsPerTrack }; header.signature[0x4A] = 0x00; byte[] hdr = new byte[Marshal.SizeOf <RayHdr>()]; IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf <RayHdr>()); System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true); System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length); System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr); _writingStream.Seek(0, SeekOrigin.Begin); _writingStream.Write(hdr, 0, hdr.Length); _writingStream.Flush(); _writingStream.Close(); IsWriting = false; ErrorMessage = ""; return(true); }
public bool Identify(IFilter imageFilter) { Stream stream = imageFilter.GetDataForkStream(); if (stream.Length < Marshal.SizeOf(typeof(RayHdr))) { return(false); } byte[] buffer = new byte[Marshal.SizeOf(typeof(RayHdr))]; stream.Seek(0, SeekOrigin.Begin); stream.Read(buffer, 0, buffer.Length); IntPtr ftrPtr = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, ftrPtr, buffer.Length); RayHdr header = (RayHdr)Marshal.PtrToStructure(ftrPtr, typeof(RayHdr)); Marshal.FreeHGlobal(ftrPtr); string signature = StringHandlers.CToString(header.signature); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.signature = {0}", signature); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.diskType = {0}", header.diskType); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.heads = {0}", header.heads); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.cylinders = {0}", header.cylinders); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.sectorsPerTrack = {0}", header.sectorsPerTrack); Regex sx = new Regex(REGEX_SIGNATURE); Match sm = sx.Match(signature); DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.signature matches? = {0}", sm.Success); return(sm.Success); }
public bool Open(IFilter imageFilter) { Stream stream = imageFilter.GetDataForkStream(); if (stream.Length < Marshal.SizeOf <RayHdr>()) { return(false); } byte[] buffer = new byte[Marshal.SizeOf <RayHdr>()]; stream.Seek(0, SeekOrigin.Begin); stream.Read(buffer, 0, buffer.Length); RayHdr header = Marshal.ByteArrayToStructureLittleEndian <RayHdr>(buffer); string signature = StringHandlers.CToString(header.signature); Regex sx = new Regex(REGEX_SIGNATURE); Match sm = sx.Match(signature); if (!sm.Success) { return(false); } imageInfo.ApplicationVersion = $"{sm.Groups["major"].Value}.{sm.Groups["minor"].Value}"; imageInfo.Cylinders = (uint)(header.cylinders + 1); imageInfo.Heads = (uint)(header.heads + 1); imageInfo.SectorsPerTrack = header.sectorsPerTrack; imageInfo.Sectors = imageInfo.Cylinders * imageInfo.Heads * imageInfo.SectorsPerTrack; imageInfo.SectorSize = 512; byte[] sectors = new byte[imageInfo.SectorsPerTrack * imageInfo.SectorSize]; disk = new MemoryStream(); for (int i = 0; i < imageInfo.SectorsPerTrack * imageInfo.SectorSize; i++) { stream.Read(sectors, 0, sectors.Length); stream.Seek(imageInfo.SectorsPerTrack, SeekOrigin.Current); disk.Write(sectors, 0, sectors.Length); } imageInfo.MediaType = Geometry.GetMediaType(((ushort)imageInfo.Cylinders, (byte)imageInfo.Heads, (ushort)imageInfo.SectorsPerTrack, 512, MediaEncoding.MFM, false)); switch (imageInfo.MediaType) { case MediaType.NEC_525_HD when header.diskType == RayDiskTypes.Mf2hd || header.diskType == RayDiskTypes.Mf2ed: imageInfo.MediaType = MediaType.NEC_35_HD_8; break; case MediaType.DOS_525_HD when header.diskType == RayDiskTypes.Mf2hd || header.diskType == RayDiskTypes.Mf2ed: imageInfo.MediaType = MediaType.NEC_35_HD_15; break; case MediaType.RX50 when header.diskType == RayDiskTypes.Md2dd || header.diskType == RayDiskTypes.Md2hd: imageInfo.MediaType = MediaType.ATARI_35_SS_DD; break; } imageInfo.XmlMediaType = XmlMediaType.BlockMedia; return(true); }