Exemplo n.º 1
0
        /// <summary>
        ///     Sends the SBC READ LONG (16) command
        /// </summary>
        /// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
        /// <param name="buffer">Buffer where the SCSI READ LONG response will be stored</param>
        /// <param name="senseBuffer">Sense buffer.</param>
        /// <param name="timeout">Timeout in seconds.</param>
        /// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
        /// <param name="correct">If set to <c>true</c> ask the drive to try to correct errors in the sector.</param>
        /// <param name="lba">LBA to read.</param>
        /// <param name="transferBytes">
        ///     How many bytes to read. If the number is not exactly the drive's size, the command will
        ///     fail and incidate a delta of the size in SENSE.
        /// </param>
        public bool ReadLong16(out byte[] buffer, out byte[] senseBuffer, bool correct, ulong lba, uint transferBytes,
                               uint timeout, out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb      = new byte[16];
            byte[] lbaBytes = BitConverter.GetBytes(lba);

            cdb[0]  = (byte)ScsiCommands.ServiceActionIn;
            cdb[1]  = (byte)ScsiServiceActions.ReadLong16;
            cdb[2]  = lbaBytes[7];
            cdb[3]  = lbaBytes[6];
            cdb[4]  = lbaBytes[5];
            cdb[5]  = lbaBytes[4];
            cdb[6]  = lbaBytes[3];
            cdb[7]  = lbaBytes[2];
            cdb[8]  = lbaBytes[1];
            cdb[9]  = lbaBytes[0];
            cdb[12] = (byte)((transferBytes & 0xFF00) >> 8);
            cdb[13] = (byte)(transferBytes & 0xFF);
            if (correct)
            {
                cdb[14] += 0x01;
            }

            buffer = new byte[transferBytes];

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
                                        out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device", "READ LONG (16) took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Writes data to a newly created file
        /// </summary>
        /// <param name="who">Who asked the file to be written (class, plugin, etc.)</param>
        /// <param name="filename">Filename to create</param>
        /// <param name="data">Data to write</param>
        /// <param name="whatWriting">What is the data about?</param>
        /// <param name="overwrite">If set to <c>true</c> overwrites the file, does nothing otherwise</param>
        public static void WriteTo(string who, string filename, byte[] data, string whatWriting = null,
                                   bool overwrite = false)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            if (File.Exists(filename))
            {
                if (overwrite)
                {
                    File.Delete(filename);
                }
                else
                {
                    DicConsole.ErrorWriteLine("Not overwriting file {0}", filename);
                    return;
                }
            }

            try
            {
                DicConsole.DebugWriteLine(who, "Writing " + whatWriting + " to {0}", filename);
                FileStream outputFs = new FileStream(filename, FileMode.CreateNew);
                outputFs.Write(data, 0, data.Length);
                outputFs.Close();
            }
            catch { DicConsole.ErrorWriteLine("Unable to write file {0}", filename); }
        }
Exemplo n.º 3
0
        public static BurstCuttingArea?Decode(byte[] BCAResponse)
        {
            if (BCAResponse == null)
            {
                return(null);
            }

            if (BCAResponse.Length != 68)
            {
                DicConsole.DebugWriteLine("BD BCA decoder", "Found incorrect Blu-ray BCA size ({0} bytes)",
                                          BCAResponse.Length);
                return(null);
            }

            BurstCuttingArea decoded = new BurstCuttingArea
            {
                DataLength = BigEndianBitConverter.ToUInt16(BCAResponse, 0),
                Reserved1  = BCAResponse[2],
                Reserved2  = BCAResponse[3],
                BCA        = new byte[64]
            };

            Array.Copy(BCAResponse, 4, decoded.BCA, 0, 64);

            return(decoded);
        }
Exemplo n.º 4
0
        public bool SetCdSpeed(out byte[] senseBuffer, RotationalControl rotationalControl, ushort readSpeed,
                               ushort writeSpeed, uint timeout, out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb    = new byte[12];
            byte[] buffer = new byte[0];

            cdb[0] = (byte)ScsiCommands.SetCdSpeed;
            cdb[1] = (byte)((byte)rotationalControl & 0x03);
            cdb[2] = (byte)((readSpeed & 0xFF00) >> 8);
            cdb[3] = (byte)(readSpeed & 0xFF);
            cdb[4] = (byte)((writeSpeed & 0xFF00) >> 8);
            cdb[5] = (byte)(writeSpeed & 0xFF);

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
                                        out bool sense);

            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device",
                                      "SET CD SPEED (Rotational Control: {1}, Read Speed: {2}, Write Speed: {3}, Sense: {4}, Last Error: {5}) took {0} ms.",
                                      duration, rotationalControl, readSpeed, writeSpeed, sense, LastError);

            return(sense);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Sends the Pioneer READ CD-DA MSF command
        /// </summary>
        /// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
        /// <param name="buffer">Buffer where the Pioneer READ CD-DA MSF response will be stored</param>
        /// <param name="senseBuffer">Sense buffer.</param>
        /// <param name="timeout">Timeout in seconds.</param>
        /// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
        /// <param name="startMsf">Start MM:SS:FF of read encoded as 0x00MMSSFF.</param>
        /// <param name="endMsf">End MM:SS:FF of read encoded as 0x00MMSSFF.</param>
        /// <param name="blockSize">Block size.</param>
        /// <param name="subchannel">Subchannel selection.</param>
        public bool PioneerReadCdDaMsf(out byte[] buffer, out byte[] senseBuffer, uint startMsf, uint endMsf,
                                       uint blockSize, PioneerSubchannel subchannel, uint timeout, out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb = new byte[12];

            cdb[0]  = (byte)ScsiCommands.ReadCdDaMsf;
            cdb[3]  = (byte)((startMsf & 0xFF0000) >> 16);
            cdb[4]  = (byte)((startMsf & 0xFF00) >> 8);
            cdb[5]  = (byte)(startMsf & 0xFF);
            cdb[7]  = (byte)((endMsf & 0xFF0000) >> 16);
            cdb[8]  = (byte)((endMsf & 0xFF00) >> 8);
            cdb[9]  = (byte)(endMsf & 0xFF);
            cdb[10] = (byte)subchannel;

            uint transferLength = (uint)((cdb[7] - cdb[3]) * 60 * 75 + (cdb[8] - cdb[4]) * 75 + (cdb[9] - cdb[5]));

            buffer = new byte[blockSize * transferLength];

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
                                        out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device", "PIONEER READ CD-DA MSF took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 6
0
        /// <summary>Sends the MMC READ DISC INFORMATION command</summary>
        /// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
        /// <param name="buffer">Buffer where the SCSI READ DISC INFORMATION response will be stored</param>
        /// <param name="senseBuffer">Sense buffer.</param>
        /// <param name="dataType">Which disc information to read</param>
        /// <param name="timeout">Timeout in seconds.</param>
        /// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
        public bool ReadDiscInformation(out byte[] buffer, out byte[] senseBuffer, MmcDiscInformationDataTypes dataType,
                                        uint timeout, out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb       = new byte[10];
            byte[] tmpBuffer = new byte[804];

            cdb[0] = (byte)ScsiCommands.ReadDiscInformation;
            cdb[1] = (byte)dataType;
            cdb[7] = (byte)((tmpBuffer.Length & 0xFF00) >> 8);
            cdb[8] = (byte)(tmpBuffer.Length & 0xFF);

            LastError = SendScsiCommand(cdb, ref tmpBuffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
                                        out bool sense);

            Error = LastError != 0;

            uint strctLength = (uint)((tmpBuffer[0] << 8) + tmpBuffer[1] + 2);

            if (strctLength > tmpBuffer.Length)
            {
                strctLength = (uint)tmpBuffer.Length;
            }

            buffer = new byte[strctLength];
            Array.Copy(tmpBuffer, 0, buffer, 0, buffer.Length);

            DicConsole.DebugWriteLine("SCSI Device",
                                      "READ DISC INFORMATION (Data Type: {1}, Sense: {2}, Last Error: {3}) took {0} ms.",
                                      duration, dataType, sense, LastError);

            return(sense);
        }
Exemplo n.º 7
0
        public bool ReadMcn(out string mcn, out byte[] buffer, out byte[] senseBuffer, uint timeout,
                            out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb = new byte[10];
            mcn = null;

            cdb[0] = (byte)ScsiCommands.ReadSubChannel;
            cdb[1] = 0;
            cdb[2] = 0x40;
            cdb[3] = 0x02;
            cdb[7] = (23 & 0xFF00) >> 8;
            cdb[8] = 23 & 0xFF;

            buffer = new byte[23];

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
                                        out bool sense);

            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device",
                                      "READ READ SUB-CHANNEL (MCN, Sense {1}, Last Error {2}) took {0} ms.", duration,
                                      sense, LastError);

            if (!sense &&
                (buffer[8] & 0x80) == 0x80)
            {
                mcn = Encoding.ASCII.GetString(buffer, 9, 13);
            }

            return(sense);
        }
Exemplo n.º 8
0
        public bool ReadLog(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, byte logAddress,
                            ushort pageNumber, ushort count, uint timeout,
                            out double duration)
        {
            buffer = new byte[512 * count];
            AtaRegistersLba48 registers = new AtaRegistersLba48
            {
                Command     = (byte)AtaCommands.ReadLogExt,
                SectorCount = count,
                LbaLow      = (ushort)((pageNumber & 0xFF) * 0x100),
                LbaHigh     = (ushort)((pageNumber & 0xFF00) / 0x100)
            };

            registers.LbaLow += logAddress;

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
                                       AtaTransferRegister.SectorCount, ref buffer, timeout, true,
                                       out duration,
                                       out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("ATA Device", "READ LOG EXT took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 9
0
        public bool Identify(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            if (stream.Length % 256 != 0)
            {
                return(false);
            }

            byte[] hdrB = new byte[256];
            stream.Read(hdrB, 0, hdrB.Length);

            for (int i = 4; i < 256; i++)
            {
                if (hdrB[i] != 0)
                {
                    return(false);
                }
            }

            int cylinders = BitConverter.ToInt32(hdrB, 0);

            DicConsole.DebugWriteLine("T98 plugin", "cylinders = {0}", cylinders);

            // This format is expanding, so length can be smaller
            // Just grow it, I won't risk false positives...
            return(stream.Length == cylinders * 8 * 33 * 256 + 256);
        }
Exemplo n.º 10
0
        public bool Read(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
                         uint timeout, out double duration)
        {
            buffer = count == 0 ? new byte[512 * 65536] : new byte[512 * count];
            AtaRegistersLba48 registers = new AtaRegistersLba48
            {
                Command     = (byte)AtaCommands.ReadExt,
                SectorCount = count,
                LbaHigh     = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
                LbaMid      = (ushort)((lba & 0xFFFF0000) / 0x10000),
                LbaLow      = (ushort)((lba & 0xFFFF) / 0x1)
            };

            registers.DeviceHead += 0x40;

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
                                       AtaTransferRegister.SectorCount, ref buffer, timeout, true,
                                       out duration,
                                       out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("ATA Device", "READ SECTORS EXT took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 11
0
        public bool GetNativeMaxAddressExt(out ulong lba, out AtaErrorRegistersLba48 statusRegisters, uint timeout,
                                           out double duration)
        {
            lba = 0;
            byte[]            buffer    = new byte[0];
            AtaRegistersLba48 registers =
                new AtaRegistersLba48 {
                Command = (byte)AtaCommands.NativeMaxAddress, Feature = 0x0000
            };

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
                                       AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
                                       out duration,
                                       out bool sense);
            Error = LastError != 0;

            if ((statusRegisters.Status & 0x23) == 0)
            {
                lba  = statusRegisters.LbaHigh;
                lba *= 0x100000000;
                lba += (ulong)(statusRegisters.LbaMid << 16);
                lba += statusRegisters.LbaLow;
            }

            DicConsole.DebugWriteLine("ATA Device", "GET NATIVE MAX ADDRESS EXT took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 12
0
        public bool Identify(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            fdihdr = new Anex86Header();

            if (stream.Length < Marshal.SizeOf(fdihdr))
            {
                return(false);
            }

            byte[] hdrB = new byte[Marshal.SizeOf(fdihdr)];
            stream.Read(hdrB, 0, hdrB.Length);

            GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);

            fdihdr = (Anex86Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Anex86Header));
            handle.Free();

            DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.unknown = {0}", fdihdr.unknown);
            DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.hddtype = {0}", fdihdr.hddtype);
            DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.hdrSize = {0}", fdihdr.hdrSize);
            DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.dskSize = {0}", fdihdr.dskSize);
            DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.bps = {0}", fdihdr.bps);
            DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.spt = {0}", fdihdr.spt);
            DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.heads = {0}", fdihdr.heads);
            DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.cylinders = {0}", fdihdr.cylinders);

            return(stream.Length == fdihdr.hdrSize + fdihdr.dskSize &&
                   fdihdr.dskSize == fdihdr.bps * fdihdr.spt * fdihdr.heads * fdihdr.cylinders);
        }
Exemplo n.º 13
0
        internal static void DoList()
        {
            List <CommonEncodingInfo> encodings = Encoding
                                                  .GetEncodings()
                                                  .Select(info => new CommonEncodingInfo
            {
                Name        = info.Name,
                DisplayName = info.GetEncoding().EncodingName
            }).ToList();

            encodings.AddRange(Claunia.Encoding.Encoding.GetEncodings()
                               .Select(info => new CommonEncodingInfo
            {
                Name        = info.Name,
                DisplayName = info.DisplayName
            }));

            DicConsole.WriteLine("{0,-16} {1,-8}", "Name", "Description");

            foreach (CommonEncodingInfo info in encodings.OrderBy(t => t.DisplayName))
            {
                DicConsole.WriteLine("{0,-16} {1,-8}", info.Name, info.DisplayName);
            }

            Core.Statistics.AddCommand("list-encodings");
        }
Exemplo n.º 14
0
        /// <summary>
        ///     Sends the SBC READ (6) command
        /// </summary>
        /// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
        /// <param name="buffer">Buffer where the SCSI READ response will be stored</param>
        /// <param name="senseBuffer">Sense buffer.</param>
        /// <param name="timeout">Timeout in seconds.</param>
        /// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
        /// <param name="lba">Starting block.</param>
        /// <param name="blockSize">Block size in bytes.</param>
        /// <param name="transferLength">How many blocks to read.</param>
        public bool Read6(out byte[] buffer, out byte[] senseBuffer, uint lba, uint blockSize, byte transferLength,
                          uint timeout, out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb = new byte[6];

            cdb[0] = (byte)ScsiCommands.Read6;
            cdb[1] = (byte)((lba & 0x1F0000) >> 16);
            cdb[2] = (byte)((lba & 0xFF00) >> 8);
            cdb[3] = (byte)(lba & 0xFF);
            cdb[4] = transferLength;

            if (transferLength == 0)
            {
                buffer = new byte[256 * blockSize];
            }
            else
            {
                buffer = new byte[transferLength * blockSize];
            }

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
                                        out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device", "READ (6) took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 15
0
        public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry, uint lba,
                            byte count, uint timeout, out double duration)
        {
            buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
            AtaRegistersLba28 registers = new AtaRegistersLba28
            {
                SectorCount = count,
                DeviceHead  = (byte)((lba & 0xF000000) / 0x1000000),
                LbaHigh     = (byte)((lba & 0xFF0000) / 0x10000),
                LbaMid      = (byte)((lba & 0xFF00) / 0x100),
                LbaLow      = (byte)((lba & 0xFF) / 0x1),
                Command     = retry ? (byte)AtaCommands.ReadDmaRetry : (byte)AtaCommands.ReadDma
            };

            registers.DeviceHead += 0x40;

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma,
                                       AtaTransferRegister.SectorCount,
                                       ref buffer, timeout, true, out duration, out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("ATA Device", "READ DMA took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 16
0
        public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, ushort cylinder,
                                 byte head, byte sector, byte count,
                                 uint timeout, out double duration)
        {
            buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
            AtaRegistersChs registers = new AtaRegistersChs
            {
                Command      = (byte)AtaCommands.ReadMultiple,
                SectorCount  = count,
                CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
                CylinderLow  = (byte)((cylinder & 0xFF) / 0x1),
                DeviceHead   = (byte)(head & 0x0F),
                Sector       = sector
            };

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
                                       AtaTransferRegister.SectorCount, ref buffer, timeout, true,
                                       out duration,
                                       out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("ATA Device", "READ MULTIPLE took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 17
0
        public static IPBin?DecodeIPBin(byte[] ipbin_sector)
        {
            if (ipbin_sector == null)
            {
                return(null);
            }

            if (ipbin_sector.Length < 512)
            {
                return(null);
            }

            IntPtr ptr = Marshal.AllocHGlobal(512);

            Marshal.Copy(ipbin_sector, 0, ptr, 512);
            IPBin ipbin = (IPBin)Marshal.PtrToStructure(ptr, typeof(IPBin));

            Marshal.FreeHGlobal(ptr);

            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.volume_name = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.volume_name));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.system_name = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.system_name));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.volume_version = \"{0:X}\"",
                                      ipbin.volume_version);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.volume_type = 0x{0:X8}", ipbin.volume_type);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.system_version = 0x{0:X8}", ipbin.system_version);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.ip_address = 0x{0:X8}", ipbin.ip_address);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.ip_loadsize = {0}", ipbin.ip_loadsize);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.ip_entry_address = 0x{0:X8}",
                                      ipbin.ip_entry_address);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.ip_work_ram_size = {0}", ipbin.ip_work_ram_size);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.sp_address = 0x{0:X8}", ipbin.sp_address);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.sp_loadsize = {0}", ipbin.sp_loadsize);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.sp_entry_address = 0x{0:X8}",
                                      ipbin.sp_entry_address);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.sp_work_ram_size = {0}", ipbin.sp_work_ram_size);
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.release_date = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.release_date));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.release_date2 = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.release_date2));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.developer_code = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.developer_code));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.domestic_title = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.domestic_title));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.overseas_title = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.overseas_title));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.product_code = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.product_code));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.peripherals = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.peripherals));
            DicConsole.DebugWriteLine("ISO9660 plugin", "segacd_ipbin.region_codes = \"{0}\"",
                                      Encoding.ASCII.GetString(ipbin.region_codes));

            string id = Encoding.ASCII.GetString(ipbin.SegaHardwareID);

            return(id == "SEGADISCSYSTEM  " || id == "SEGADATADISC    " || id == "SEGAOS          "
                       ? ipbin
                       : (IPBin?)null);
        }
Exemplo n.º 18
0
        public bool ReadLong(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, bool retry, ushort cylinder,
                             byte head, byte sector, uint blockSize, uint timeout,
                             out double duration)
        {
            buffer = new byte[blockSize];
            AtaRegistersChs registers = new AtaRegistersChs
            {
                Command      = retry ? (byte)AtaCommands.ReadLongRetry : (byte)AtaCommands.ReadLong,
                SectorCount  = 1,
                CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
                CylinderLow  = (byte)((cylinder & 0xFF) / 0x1),
                DeviceHead   = (byte)(head & 0x0F),
                Sector       = sector
            };

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
                                       AtaTransferRegister.SectorCount, ref buffer, timeout, true,
                                       out duration,
                                       out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("ATA Device", "READ LONG took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 19
0
        public bool PreventAllowMediumRemoval(out byte[] senseBuffer, bool persistent, bool prevent, uint timeout,
                                              out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb    = new byte[6];
            byte[] buffer = new byte[0];

            cdb[0] = (byte)ScsiCommands.PreventAllowMediumRemoval;

            if (prevent)
            {
                cdb[4] += 0x01;
            }

            if (persistent)
            {
                cdb[4] += 0x02;
            }

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
                                        out bool sense);

            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device",
                                      "PREVENT ALLOW MEDIUM REMOVAL (Persistent: {1}, Prevent: {2}, Sense: {3}, LastError: {4}) took {0} ms.",
                                      duration, persistent, prevent, sense, LastError);

            return(sense);
        }
Exemplo n.º 20
0
        public bool SetFeatures(out AtaErrorRegistersChs statusRegisters, AtaFeatures feature, ushort cylinder,
                                byte head, byte sector, byte sectorCount,
                                uint timeout, out double duration)
        {
            byte[]          buffer    = new byte[0];
            AtaRegistersChs registers = new AtaRegistersChs
            {
                Command      = (byte)AtaCommands.SetFeatures,
                CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
                CylinderLow  = (byte)((cylinder & 0xFF) / 0x1),
                DeviceHead   = (byte)(head & 0x0F),
                Sector       = sector,
                SectorCount  = sectorCount,
                Feature      = (byte)feature
            };

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
                                       AtaTransferRegister.NoTransfer, ref buffer, timeout, true, out duration,
                                       out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("ATA Device", "SET FEATURES took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 21
0
        public bool ReadIsrc(byte trackNumber, out string isrc, out byte[] buffer, out byte[] senseBuffer, uint timeout,
                             out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb = new byte[10];
            isrc = null;

            cdb[0] = (byte)ScsiCommands.ReadSubChannel;
            cdb[1] = 0;
            cdb[2] = 0x40;
            cdb[3] = 0x03;
            cdb[6] = trackNumber;
            cdb[7] = (23 & 0xFF00) >> 8;
            cdb[8] = 23 & 0xFF;

            buffer = new byte[23];

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
                                        out bool sense);

            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device",
                                      "READ READ SUB-CHANNEL (ISRC, Track Number: {1}, Sense: {2}, Last Error: {3}) took {0} ms.",
                                      duration, trackNumber, sense, LastError);

            if (!sense &&
                (buffer[8] & 0x80) == 0x80)
            {
                isrc = Encoding.ASCII.GetString(buffer, 9, 12);
            }

            return(sense);
        }
Exemplo n.º 22
0
        static dk_label16 SwapDiskLabel(dk_label16 label)
        {
            DicConsole.DebugWriteLine("Sun plugin", "Swapping dk_label16");
            label = (dk_label16)Marshal.SwapStructureMembersEndian(label);
            for (int i = 0; i < label.dkl_vtoc.v_bootinfo.Length; i++)
            {
                label.dkl_vtoc.v_bootinfo[i] = Swapping.Swap(label.dkl_vtoc.v_bootinfo[i]);
            }
            for (int i = 0; i < label.dkl_vtoc.v_part.Length; i++)
            {
                label.dkl_vtoc.v_part[i].p_flag  = (SunFlags)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_flag);
                label.dkl_vtoc.v_part[i].p_tag   = (SunTag)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_tag);
                label.dkl_vtoc.v_part[i].p_size  = Swapping.Swap(label.dkl_vtoc.v_part[i].p_size);
                label.dkl_vtoc.v_part[i].p_start = Swapping.Swap(label.dkl_vtoc.v_part[i].p_start);
            }

            for (int i = 0; i < label.dkl_vtoc.v_timestamp.Length; i++)
            {
                label.dkl_vtoc.v_timestamp[i] = Swapping.Swap(label.dkl_vtoc.v_timestamp[i]);
            }
            for (int i = 0; i < label.dkl_vtoc.v_reserved.Length; i++)
            {
                label.dkl_vtoc.v_reserved[i] = Swapping.Swap(label.dkl_vtoc.v_reserved[i]);
            }

            return(label);
        }
Exemplo n.º 23
0
        /// <summary>
        ///     Sends the Pioneer READ CD-DA command
        /// </summary>
        /// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
        /// <param name="buffer">Buffer where the Pioneer READ CD-DA response will be stored</param>
        /// <param name="senseBuffer">Sense buffer.</param>
        /// <param name="timeout">Timeout in seconds.</param>
        /// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
        /// <param name="lba">Start block address.</param>
        /// <param name="transferLength">How many blocks to read.</param>
        /// <param name="blockSize">Block size.</param>
        /// <param name="subchannel">Subchannel selection.</param>
        public bool PioneerReadCdDa(out byte[] buffer, out byte[] senseBuffer, uint lba, uint blockSize,
                                    uint transferLength, PioneerSubchannel subchannel, uint timeout,
                                    out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb = new byte[12];

            cdb[0]  = (byte)ScsiCommands.ReadCdDa;
            cdb[2]  = (byte)((lba & 0xFF000000) >> 24);
            cdb[3]  = (byte)((lba & 0xFF0000) >> 16);
            cdb[4]  = (byte)((lba & 0xFF00) >> 8);
            cdb[5]  = (byte)(lba & 0xFF);
            cdb[7]  = (byte)((transferLength & 0xFF0000) >> 16);
            cdb[8]  = (byte)((transferLength & 0xFF00) >> 8);
            cdb[9]  = (byte)(transferLength & 0xFF);
            cdb[10] = (byte)subchannel;

            buffer = new byte[blockSize * transferLength];

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
                                        out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device", "PIONEER READ CD-DA took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 24
0
        public static CDTOC? Decode(byte[] CDTOCResponse)
        {
            if(CDTOCResponse == null) return null;

            CDTOC decoded = new CDTOC();

            BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;

            decoded.DataLength       = BigEndianBitConverter.ToUInt16(CDTOCResponse, 0);
            decoded.FirstTrack       = CDTOCResponse[2];
            decoded.LastTrack        = CDTOCResponse[3];
            decoded.TrackDescriptors = new CDTOCTrackDataDescriptor[(decoded.DataLength - 2) / 8];

            if(decoded.DataLength + 2 != CDTOCResponse.Length)
            {
                DicConsole.DebugWriteLine("CD TOC decoder",
                                          "Expected CDTOC size ({0} bytes) is not received size ({1} bytes), not decoding",
                                          decoded.DataLength + 2, CDTOCResponse.Length);
                return null;
            }

            for(int i = 0; i < (decoded.DataLength - 2) / 8; i++)
            {
                decoded.TrackDescriptors[i].Reserved1   = CDTOCResponse[0 + i * 8 + 4];
                decoded.TrackDescriptors[i].ADR         = (byte)((CDTOCResponse[1 + i * 8 + 4] & 0xF0) >> 4);
                decoded.TrackDescriptors[i].CONTROL     = (byte)(CDTOCResponse[1 + i * 8 + 4] & 0x0F);
                decoded.TrackDescriptors[i].TrackNumber = CDTOCResponse[2 + i * 8 + 4];
                decoded.TrackDescriptors[i].Reserved2   = CDTOCResponse[3 + i * 8 + 4];
                decoded.TrackDescriptors[i].TrackStartAddress =
                    BigEndianBitConverter.ToUInt32(CDTOCResponse, 4 + i * 8 + 4);
            }

            return decoded;
        }
Exemplo n.º 25
0
        public bool Identify(IFilter imageFilter)
        {
            imageStream                          = imageFilter.GetDataForkStream();
            BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;

            NeroV1Footer footerV1 = new NeroV1Footer();
            NeroV2Footer footerV2 = new NeroV2Footer();

            imageStream.Seek(-8, SeekOrigin.End);
            byte[] buffer = new byte[8];
            imageStream.Read(buffer, 0, 8);
            footerV1.ChunkId          = BigEndianBitConverter.ToUInt32(buffer, 0);
            footerV1.FirstChunkOffset = BigEndianBitConverter.ToUInt32(buffer, 4);

            imageStream.Seek(-12, SeekOrigin.End);
            buffer = new byte[12];
            imageStream.Read(buffer, 0, 12);
            footerV2.ChunkId          = BigEndianBitConverter.ToUInt32(buffer, 0);
            footerV2.FirstChunkOffset = BigEndianBitConverter.ToUInt64(buffer, 4);

            DicConsole.DebugWriteLine("Nero plugin", "imageStream.Length = {0}",        imageStream.Length);
            DicConsole.DebugWriteLine("Nero plugin", "footerV1.ChunkID = 0x{0:X8}",     footerV1.ChunkId);
            DicConsole.DebugWriteLine("Nero plugin", "footerV1.FirstChunkOffset = {0}", footerV1.FirstChunkOffset);
            DicConsole.DebugWriteLine("Nero plugin", "footerV2.ChunkID = 0x{0:X8}",     footerV2.ChunkId);
            DicConsole.DebugWriteLine("Nero plugin", "footerV2.FirstChunkOffset = {0}", footerV2.FirstChunkOffset);

            if(footerV2.ChunkId == NERO_FOOTER_V2 && footerV2.FirstChunkOffset < (ulong)imageStream.Length) return true;

            return footerV1.ChunkId == NERO_FOOTER_V1 && footerV1.FirstChunkOffset < (ulong)imageStream.Length;
        }
Exemplo n.º 26
0
        public bool ReadNativeMaxAddress(out uint lba, out AtaErrorRegistersLba28 statusRegisters, uint timeout,
                                         out double duration)
        {
            lba = 0;
            byte[]            buffer    = new byte[0];
            AtaRegistersLba28 registers = new AtaRegistersLba28 {
                Command = (byte)AtaCommands.ReadNativeMaxAddress
            };

            registers.DeviceHead += 0x40;

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
                                       AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
                                       out duration,
                                       out bool sense);
            Error = LastError != 0;

            if ((statusRegisters.Status & 0x23) == 0)
            {
                lba += (uint)(statusRegisters.DeviceHead & 0xF);
                lba *= 0x1000000;
                lba += (uint)(statusRegisters.LbaHigh << 16);
                lba += (uint)(statusRegisters.LbaMid << 8);
                lba += statusRegisters.LbaLow;
            }

            DicConsole.DebugWriteLine("ATA Device", "READ NATIVE MAX ADDRESS took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        public bool ReadLong(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry,
                             uint lba,
                             uint blockSize, uint timeout, out double duration)
        {
            buffer = new byte[blockSize];
            AtaRegistersLba28 registers = new AtaRegistersLba28
            {
                SectorCount = 1,
                DeviceHead  = (byte)((lba & 0xF000000) / 0x1000000),
                LbaHigh     = (byte)((lba & 0xFF0000) / 0x10000),
                LbaMid      = (byte)((lba & 0xFF00) / 0x100),
                LbaLow      = (byte)((lba & 0xFF) / 0x1),
                Command     = retry ? (byte)AtaCommands.ReadLongRetry : (byte)AtaCommands.ReadLong
            };

            registers.DeviceHead += 0x40;

            LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
                                       AtaTransferRegister.SectorCount, ref buffer, timeout, true,
                                       out duration,
                                       out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("ATA Device", "READ LONG took {0} ms.", duration);

            return(sense);
        }
Exemplo n.º 29
0
        public bool Identify(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            if (stream.Length < 512)
            {
                return(false);
            }

            byte[] headerB = new byte[256];
            stream.Read(headerB, 0, 256);
            IntPtr headerPtr = Marshal.AllocHGlobal(256);

            Marshal.Copy(headerB, 0, headerPtr, 256);
            CpcDiskInfo header = (CpcDiskInfo)Marshal.PtrToStructure(headerPtr, typeof(CpcDiskInfo));

            Marshal.FreeHGlobal(headerPtr);

            DicConsole.DebugWriteLine("CPCDSK plugin", "header.magic = \"{0}\"",
                                      StringHandlers.CToString(header.magic));

            return(cpcdskId.SequenceEqual(header.magic) || edskId.SequenceEqual(header.magic) ||
                   du54Id.SequenceEqual(header.magic));
        }
Exemplo n.º 30
0
        /// <summary>
        ///     Sends the SBC READ LONG (10) command
        /// </summary>
        /// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
        /// <param name="buffer">Buffer where the SCSI READ LONG response will be stored</param>
        /// <param name="senseBuffer">Sense buffer.</param>
        /// <param name="timeout">Timeout in seconds.</param>
        /// <param name="relAddr"></param>
        /// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
        /// <param name="correct">If set to <c>true</c> ask the drive to try to correct errors in the sector.</param>
        /// <param name="lba">LBA to read.</param>
        /// <param name="transferBytes">
        ///     How many bytes to read. If the number is not exactly the drive's size, the command will
        ///     fail and incidate a delta of the size in SENSE.
        /// </param>
        public bool ReadLong10(out byte[] buffer, out byte[] senseBuffer, bool correct, bool relAddr,
                               uint lba,
                               ushort transferBytes, uint timeout, out double duration)
        {
            senseBuffer = new byte[32];
            byte[] cdb = new byte[10];

            cdb[0] = (byte)ScsiCommands.ReadLong;
            if (correct)
            {
                cdb[1] += 0x02;
            }
            if (relAddr)
            {
                cdb[1] += 0x01;
            }
            cdb[2] = (byte)((lba & 0xFF000000) >> 24);
            cdb[3] = (byte)((lba & 0xFF0000) >> 16);
            cdb[4] = (byte)((lba & 0xFF00) >> 8);
            cdb[5] = (byte)(lba & 0xFF);
            cdb[7] = (byte)((transferBytes & 0xFF00) >> 8);
            cdb[8] = (byte)(transferBytes & 0xFF);

            buffer = new byte[transferBytes];

            LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
                                        out bool sense);
            Error = LastError != 0;

            DicConsole.DebugWriteLine("SCSI Device", "READ LONG (10) took {0} ms.", duration);

            return(sense);
        }