Esempio n. 1
0
        public static byte[] EncodeMode10(DecodedMode mode, PeripheralDeviceTypes deviceType)
        {
            int modeSize = 0;

            if (mode.Pages != null)
            {
                modeSize += mode.Pages.Sum(page => page.PageResponse.Length);
            }

            byte[] hdr = EncodeModeHeader10(mode.Header, deviceType);
            modeSize += hdr.Length;
            byte[] md = new byte[modeSize];

            Array.Copy(hdr, 0, md, 0, hdr.Length);

            if (mode.Pages == null)
            {
                return(md);
            }

            {
                int offset = hdr.Length;
                foreach (ModePage page in mode.Pages)
                {
                    Array.Copy(page.PageResponse, 0, md, offset, page.PageResponse.Length);
                    offset += page.PageResponse.Length;
                }
            }

            return(md);
        }
Esempio n. 2
0
        public static ModeHeader?DecodeModeHeader6(byte[] modeResponse, PeripheralDeviceTypes deviceType)
        {
            if (modeResponse == null || modeResponse.Length < 4 || modeResponse.Length < modeResponse[0] + 1)
            {
                return(null);
            }

            ModeHeader header = new ModeHeader {
                MediumType = (MediumTypes)modeResponse[1]
            };

            if (modeResponse[3] > 0)
            {
                header.BlockDescriptors = new BlockDescriptor[modeResponse[3] / 8];
                for (int i = 0; i < header.BlockDescriptors.Length; i++)
                {
                    header.BlockDescriptors[i].Density      = (DensityType)modeResponse[0 + i * 8 + 4];
                    header.BlockDescriptors[i].Blocks      += (ulong)(modeResponse[1 + i * 8 + 4] << 16);
                    header.BlockDescriptors[i].Blocks      += (ulong)(modeResponse[2 + i * 8 + 4] << 8);
                    header.BlockDescriptors[i].Blocks      += modeResponse[3 + i * 8 + 4];
                    header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[5 + i * 8 + 4] << 16);
                    header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[6 + i * 8 + 4] << 8);
                    header.BlockDescriptors[i].BlockLength += modeResponse[7 + i * 8 + 4];
                }
            }

            switch (deviceType)
            {
            case PeripheralDeviceTypes.DirectAccess:
            case PeripheralDeviceTypes.MultiMediaDevice:
                header.WriteProtected = (modeResponse[2] & 0x80) == 0x80;
                header.DPOFUA         = (modeResponse[2] & 0x10) == 0x10;
                break;

            case PeripheralDeviceTypes.SequentialAccess:
                header.WriteProtected = (modeResponse[2] & 0x80) == 0x80;
                header.Speed          = (byte)(modeResponse[2] & 0x0F);
                header.BufferedMode   = (byte)((modeResponse[2] & 0x70) >> 4);
                break;

            case PeripheralDeviceTypes.PrinterDevice:
                header.BufferedMode = (byte)((modeResponse[2] & 0x70) >> 4);
                break;

            case PeripheralDeviceTypes.OpticalDevice:
                header.WriteProtected = (modeResponse[2] & 0x80) == 0x80;
                header.EBC            = (modeResponse[2] & 0x01) == 0x01;
                header.DPOFUA         = (modeResponse[2] & 0x10) == 0x10;
                break;
            }

            return(header);
        }
Esempio n. 3
0
        public static void Print(Modes.DecodedMode decMode, PeripheralDeviceTypes devType, byte[] vendorId)
        {
            DicConsole.WriteLine(Modes.PrettifyModeHeader(decMode.Header, devType));

            if (decMode.Pages == null)
            {
                return;
            }

            foreach (Modes.ModePage page in decMode.Pages)
            {
                //DicConsole.WriteLine("Page {0:X2}h subpage {1:X2}h is {2} bytes long", page.Page, page.Subpage, page.PageResponse.Length);
                switch (page.Page)
                {
                case 0x00:
                {
                    if (devType == PeripheralDeviceTypes.MultiMediaDevice &&
                        page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_00_SFF(page.PageResponse));
                    }
                    else
                    {
                        if (page.Subpage != 0)
                        {
                            DicConsole.WriteLine("Found unknown vendor mode page {0:X2}h subpage {1:X2}h",
                                                 page.Page, page.Subpage);
                        }
                        else
                        {
                            DicConsole.WriteLine("Found unknown vendor mode page {0:X2}h", page.Page);
                        }
                    }

                    break;
                }

                case 0x01:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(devType == PeripheralDeviceTypes.MultiMediaDevice
                                                     ? Modes.PrettifyModePage_01_MMC(page.PageResponse)
                                                     : Modes.PrettifyModePage_01(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x02:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_02(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x03:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_03(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x04:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_04(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x05:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_05(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x06:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_06(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x07:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(devType == PeripheralDeviceTypes.MultiMediaDevice
                                                     ? Modes.PrettifyModePage_07_MMC(page.PageResponse)
                                                     : Modes.PrettifyModePage_07(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x08:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_08(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0A:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_0A(page.PageResponse));
                    }
                    else if (page.Subpage == 1)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_0A_S01(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0B:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_0B(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0D:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_0D(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0E:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_0E(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0F:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_0F(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x10:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(devType == PeripheralDeviceTypes.SequentialAccess
                                                     ? Modes.PrettifyModePage_10_SSC(page.PageResponse)
                                                     : Modes.PrettifyModePage_10(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x11:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_11(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x12:
                case 0x13:
                case 0x14:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_12_13_14(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x1A:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_1A(page.PageResponse));
                    }
                    else if (page.Subpage == 1)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_1A_S01(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x1B:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_1B(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x1C:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(devType == PeripheralDeviceTypes.MultiMediaDevice
                                                     ? Modes.PrettifyModePage_1C_SFF(page.PageResponse)
                                                     : Modes.PrettifyModePage_1C(page.PageResponse));
                    }
                    else if (page.Subpage == 1)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_1C_S01(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x1D:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_1D(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x21:
                {
                    if (StringHandlers.CToString(vendorId).Trim() == "CERTANCE")
                    {
                        DicConsole.WriteLine(Modes.PrettifyCertanceModePage_21(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x22:
                {
                    if (StringHandlers.CToString(vendorId).Trim() == "CERTANCE")
                    {
                        DicConsole.WriteLine(Modes.PrettifyCertanceModePage_22(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x24:
                {
                    if (StringHandlers.CToString(vendorId).Trim() == "IBM")
                    {
                        DicConsole.WriteLine(Modes.PrettifyIBMModePage_24(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x2A:
                {
                    if (page.Subpage == 0)
                    {
                        DicConsole.WriteLine(Modes.PrettifyModePage_2A(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x2F:
                {
                    if (StringHandlers.CToString(vendorId).Trim() == "IBM")
                    {
                        DicConsole.WriteLine(Modes.PrettifyIBMModePage_2F(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x30:
                {
                    if (Modes.IsAppleModePage_30(page.PageResponse))
                    {
                        DicConsole.WriteLine("Drive identifies as Apple OEM drive");
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x3B:
                {
                    if (StringHandlers.CToString(vendorId).Trim() == "HP")
                    {
                        DicConsole.WriteLine(Modes.PrettifyHPModePage_3B(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x3C:
                {
                    if (StringHandlers.CToString(vendorId).Trim() == "HP")
                    {
                        DicConsole.WriteLine(Modes.PrettifyHPModePage_3C(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x3D:
                {
                    if (StringHandlers.CToString(vendorId).Trim() == "IBM")
                    {
                        DicConsole.WriteLine(Modes.PrettifyIBMModePage_3D(page.PageResponse));
                    }
                    else if (StringHandlers.CToString(vendorId).Trim() == "HP")
                    {
                        DicConsole.WriteLine(Modes.PrettifyHPModePage_3D(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x3E:
                {
                    if (StringHandlers.CToString(vendorId).Trim() == "FUJITSU")
                    {
                        DicConsole.WriteLine(Modes.PrettifyFujitsuModePage_3E(page.PageResponse));
                    }
                    else if (StringHandlers.CToString(vendorId).Trim() == "HP")
                    {
                        DicConsole.WriteLine(Modes.PrettifyHPModePage_3E(page.PageResponse));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                default:
                {
                    if (page.Subpage != 0)
                    {
                        DicConsole.WriteLine("Found unknown mode page {0:X2}h subpage {1:X2}h", page.Page,
                                             page.Subpage);
                    }
                    else
                    {
                        DicConsole.WriteLine("Found unknown mode page {0:X2}h", page.Page);
                    }

                    break;
                }
                }
            }
        }
Esempio n. 4
0
        public static ModeHeader?DecodeModeHeader10(byte[] modeResponse, PeripheralDeviceTypes deviceType)
        {
            if (modeResponse == null || modeResponse.Length < 8)
            {
                return(null);
            }

            ushort modeLength      = (ushort)((modeResponse[0] << 8) + modeResponse[1]);
            ushort blockDescLength = (ushort)((modeResponse[6] << 8) + modeResponse[7]);

            if (modeResponse.Length < modeLength)
            {
                return(null);
            }

            ModeHeader header = new ModeHeader {
                MediumType = (MediumTypes)modeResponse[2]
            };

            bool longLBA = (modeResponse[4] & 0x01) == 0x01;

            if (blockDescLength > 0)
            {
                if (longLBA)
                {
                    header.BlockDescriptors = new BlockDescriptor[blockDescLength / 16];
                    for (int i = 0; i < header.BlockDescriptors.Length; i++)
                    {
                        if (12 + i * 16 + 8 >= modeResponse.Length)
                        {
                            break;
                        }

                        header.BlockDescriptors[i] = new BlockDescriptor {
                            Density = DensityType.Default
                        };
                        byte[] temp = new byte[8];
                        temp[0] = modeResponse[7 + i * 16 + 8];
                        temp[1] = modeResponse[6 + i * 16 + 8];
                        temp[2] = modeResponse[5 + i * 16 + 8];
                        temp[3] = modeResponse[4 + i * 16 + 8];
                        temp[4] = modeResponse[3 + i * 16 + 8];
                        temp[5] = modeResponse[2 + i * 16 + 8];
                        temp[6] = modeResponse[1 + i * 16 + 8];
                        temp[7] = modeResponse[0 + i * 16 + 8];
                        header.BlockDescriptors[i].Blocks       = BitConverter.ToUInt64(temp, 0);
                        header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[15 + i * 16 + 8] << 24);
                        header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[14 + i * 16 + 8] << 16);
                        header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[13 + i * 16 + 8] << 8);
                        header.BlockDescriptors[i].BlockLength += modeResponse[12 + i * 16 + 8];
                    }
                }
                else
                {
                    header.BlockDescriptors = new BlockDescriptor[blockDescLength / 8];
                    for (int i = 0; i < header.BlockDescriptors.Length; i++)
                    {
                        if (7 + i * 8 + 8 >= modeResponse.Length)
                        {
                            break;
                        }

                        header.BlockDescriptors[i] = new BlockDescriptor();
                        if (deviceType != PeripheralDeviceTypes.DirectAccess)
                        {
                            header.BlockDescriptors[i].Density = (DensityType)modeResponse[0 + i * 8 + 8];
                        }
                        else
                        {
                            header.BlockDescriptors[i].Density = DensityType.Default;
                            header.BlockDescriptors[i].Blocks += (ulong)(modeResponse[0 + i * 8 + 8] << 24);
                        }

                        header.BlockDescriptors[i].Blocks      += (ulong)(modeResponse[1 + i * 8 + 8] << 16);
                        header.BlockDescriptors[i].Blocks      += (ulong)(modeResponse[2 + i * 8 + 8] << 8);
                        header.BlockDescriptors[i].Blocks      += modeResponse[3 + i * 8 + 8];
                        header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[5 + i * 8 + 8] << 16);
                        header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[6 + i * 8 + 8] << 8);
                        header.BlockDescriptors[i].BlockLength += modeResponse[7 + i * 8 + 8];
                    }
                }
            }

            switch (deviceType)
            {
            case PeripheralDeviceTypes.DirectAccess:
            case PeripheralDeviceTypes.MultiMediaDevice:
                header.WriteProtected = (modeResponse[3] & 0x80) == 0x80;
                header.DPOFUA         = (modeResponse[3] & 0x10) == 0x10;
                break;

            case PeripheralDeviceTypes.SequentialAccess:
                header.WriteProtected = (modeResponse[3] & 0x80) == 0x80;
                header.Speed          = (byte)(modeResponse[3] & 0x0F);
                header.BufferedMode   = (byte)((modeResponse[3] & 0x70) >> 4);
                break;

            case PeripheralDeviceTypes.PrinterDevice:
                header.BufferedMode = (byte)((modeResponse[3] & 0x70) >> 4);
                break;

            case PeripheralDeviceTypes.OpticalDevice:
                header.WriteProtected = (modeResponse[3] & 0x80) == 0x80;
                header.EBC            = (modeResponse[3] & 0x01) == 0x01;
                header.DPOFUA         = (modeResponse[3] & 0x10) == 0x10;
                break;
            }

            return(header);
        }
Esempio n. 5
0
        public static byte[] EncodeModeHeader10(ModeHeader header, PeripheralDeviceTypes deviceType,
                                                bool longLBA = false)
        {
            byte[] hdr;

            if (header.BlockDescriptors != null)
            {
                hdr = longLBA
                          ? new byte[8 + header.BlockDescriptors.Length * 16]
                          : new byte[8 + header.BlockDescriptors.Length * 8];
            }
            else
            {
                hdr = new byte[8];
            }

            hdr[2] = (byte)header.MediumType;

            switch (deviceType)
            {
            case PeripheralDeviceTypes.DirectAccess:
            case PeripheralDeviceTypes.MultiMediaDevice:
                if (header.WriteProtected)
                {
                    hdr[3] += 0x80;
                }
                if (header.DPOFUA)
                {
                    hdr[3] += 0x10;
                }
                break;

            case PeripheralDeviceTypes.SequentialAccess:
                if (header.WriteProtected)
                {
                    hdr[3] += 0x80;
                }
                hdr[3] += (byte)(header.Speed & 0x0F);
                hdr[3] += (byte)((header.BufferedMode << 4) & 0x70);
                break;

            case PeripheralDeviceTypes.PrinterDevice:
                hdr[3] += (byte)((header.BufferedMode << 4) & 0x70);
                break;

            case PeripheralDeviceTypes.OpticalDevice:
                if (header.WriteProtected)
                {
                    hdr[3] += 0x80;
                }
                if (header.EBC)
                {
                    hdr[3] += 0x01;
                }
                if (header.DPOFUA)
                {
                    hdr[3] += 0x10;
                }
                break;
            }

            if (longLBA)
            {
                hdr[4] += 0x01;
            }

            if (header.BlockDescriptors == null)
            {
                return(hdr);
            }

            if (longLBA)
            {
                for (int i = 0; i < header.BlockDescriptors.Length; i++)
                {
                    byte[] temp = BitConverter.GetBytes(header.BlockDescriptors[i].Blocks);
                    hdr[7 + i * 16 + 8]  = temp[0];
                    hdr[6 + i * 16 + 8]  = temp[1];
                    hdr[5 + i * 16 + 8]  = temp[2];
                    hdr[4 + i * 16 + 8]  = temp[3];
                    hdr[3 + i * 16 + 8]  = temp[4];
                    hdr[2 + i * 16 + 8]  = temp[5];
                    hdr[1 + i * 16 + 8]  = temp[6];
                    hdr[0 + i * 16 + 8]  = temp[7];
                    hdr[12 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF000000) >> 24);
                    hdr[13 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16);
                    hdr[14 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8);
                    hdr[15 + i * 16 + 8] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF);
                }
            }
            else
            {
                for (int i = 0; i < header.BlockDescriptors.Length; i++)
                {
                    if (deviceType != PeripheralDeviceTypes.DirectAccess)
                    {
                        hdr[0 + i * 8 + 8] = (byte)header.BlockDescriptors[i].Density;
                    }
                    else
                    {
                        hdr[0 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF000000) >> 24);
                    }
                    hdr[1 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16);
                    hdr[2 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8);
                    hdr[3 + i * 8 + 8] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF);
                    hdr[5 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16);
                    hdr[6 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8);
                    hdr[7 + i * 8 + 8] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF);
                }
            }

            return(hdr);
        }
Esempio n. 6
0
        public static DecodedMode?DecodeMode10(byte[] modeResponse, PeripheralDeviceTypes deviceType)
        {
            ModeHeader?hdr = DecodeModeHeader10(modeResponse, deviceType);

            if (!hdr.HasValue)
            {
                return(null);
            }

            DecodedMode decoded = new DecodedMode {
                Header = hdr.Value
            };
            bool longlba = (modeResponse[4] & 0x01) == 0x01;
            int  offset;
            int  blkDrLength = 0;

            if (decoded.Header.BlockDescriptors != null)
            {
                blkDrLength = decoded.Header.BlockDescriptors.Length;
            }

            if (longlba)
            {
                offset = 8 + blkDrLength * 16;
            }
            else
            {
                offset = 8 + blkDrLength * 8;
            }
            int length = modeResponse[0] << 8;

            length += modeResponse[1];
            length += 2;

            if (length != modeResponse.Length)
            {
                return(decoded);
            }

            List <ModePage> listpages = new List <ModePage>();

            while (offset < modeResponse.Length)
            {
                bool     isSubpage = (modeResponse[offset] & 0x40) == 0x40;
                ModePage pg        = new ModePage();
                byte     pageNo    = (byte)(modeResponse[offset] & 0x3F);

                if (pageNo == 0)
                {
                    pg.PageResponse = new byte[modeResponse.Length - offset];
                    Array.Copy(modeResponse, offset, pg.PageResponse, 0, pg.PageResponse.Length);
                    pg.Page    = 0;
                    pg.Subpage = 0;
                    offset    += pg.PageResponse.Length;
                }
                else
                {
                    if (isSubpage)
                    {
                        pg.PageResponse = new byte[(modeResponse[offset + 2] << 8) + modeResponse[offset + 3] + 4];

                        if (pg.PageResponse.Length + offset > modeResponse.Length)
                        {
                            return(decoded);
                        }

                        Array.Copy(modeResponse, offset, pg.PageResponse, 0, pg.PageResponse.Length);
                        pg.Page    = (byte)(modeResponse[offset] & 0x3F);
                        pg.Subpage = modeResponse[offset + 1];
                        offset    += pg.PageResponse.Length;
                    }
                    else
                    {
                        pg.PageResponse = new byte[modeResponse[offset + 1] + 2];

                        if (pg.PageResponse.Length + offset > modeResponse.Length)
                        {
                            return(decoded);
                        }

                        Array.Copy(modeResponse, offset, pg.PageResponse, 0, pg.PageResponse.Length);
                        pg.Page    = (byte)(modeResponse[offset] & 0x3F);
                        pg.Subpage = 0;
                        offset    += pg.PageResponse.Length;
                    }
                }

                listpages.Add(pg);
            }

            decoded.Pages = listpages.ToArray();

            return(decoded);
        }
Esempio n. 7
0
        internal void LoadData(byte[] scsiInquiryData, CommonTypes.Structs.Devices.SCSI.Inquiry?scsiInquiry,
                               Dictionary <byte, byte[]> scsiEvpdPages, Modes.DecodedMode?scsiMode,
                               PeripheralDeviceTypes scsiType, byte[] scsiModeSense6,
                               byte[] scsiModeSense10,
                               byte[] mmcConfiguration)
        {
            inquiryData   = scsiInquiryData;
            inquiry       = scsiInquiry;
            evpdPages     = scsiEvpdPages;
            mode          = scsiMode;
            type          = scsiType;
            modeSense6    = scsiModeSense6;
            modeSense10   = scsiModeSense10;
            configuration = mmcConfiguration;

            if (inquiryData == null || !inquiry.HasValue)
            {
                return;
            }

            Visible             = true;
            txtScsiInquiry.Text = Inquiry.Prettify(inquiry);

            if (mode.HasValue)
            {
                tabScsiModeSense.Visible = true;

                var modePagesList = new TreeGridItemCollection();

                treeModeSensePages.Columns.Add(new GridColumn {
                    HeaderText = "Page", DataCell = new TextBoxCell(0)
                });

                treeModeSensePages.AllowMultipleSelection = false;
                treeModeSensePages.ShowHeader             = false;
                treeModeSensePages.DataStore = modePagesList;

                modePagesList.Add(new TreeGridItem
                {
                    Values = new object[]
                    {
                        "Header", Modes.PrettifyModeHeader(mode.Value.Header, type)
                    }
                });

                if (mode.Value.Pages != null)
                {
                    foreach (var page in mode.Value.Pages.OrderBy(t => t.Page).ThenBy(t => t.Subpage))
                    {
                        var pageNumberText = page.Subpage == 0
                            ? $"MODE {page.Page:X2}h"
                            : $"MODE {page.Page:X2} Subpage {page.Subpage:X2}";
                        string decodedText;

                        switch (page.Page)
                        {
                        case 0x00:
                        {
                            if (type == PeripheralDeviceTypes.MultiMediaDevice && page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_00_SFF(page.PageResponse);
                            }
                            else
                            {
                                decodedText = "Undecoded";
                            }

                            break;
                        }

                        case 0x01:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = type == PeripheralDeviceTypes.MultiMediaDevice
                                        ? Modes.PrettifyModePage_01_MMC(page.PageResponse)
                                        : Modes.PrettifyModePage_01(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x02:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_02(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x03:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_03(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x04:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_04(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x05:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_05(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x06:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_06(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x07:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = type == PeripheralDeviceTypes.MultiMediaDevice
                                        ? Modes.PrettifyModePage_07_MMC(page.PageResponse)
                                        : Modes.PrettifyModePage_07(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x08:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_08(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0A:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0A(page.PageResponse);
                            }
                            else if (page.Subpage == 1)
                            {
                                decodedText = Modes.PrettifyModePage_0A_S01(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0B:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0B(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0D:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0D(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0E:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0E(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0F:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0F(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x10:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = type == PeripheralDeviceTypes.SequentialAccess
                                        ? Modes.PrettifyModePage_10_SSC(page.PageResponse)
                                        : Modes.PrettifyModePage_10(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x11:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_11(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x12:
                        case 0x13:
                        case 0x14:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_12_13_14(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x1A:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_1A(page.PageResponse);
                            }
                            else if (page.Subpage == 1)
                            {
                                decodedText = Modes.PrettifyModePage_1A_S01(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x1B:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_1B(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x1C:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = type == PeripheralDeviceTypes.MultiMediaDevice
                                        ? Modes.PrettifyModePage_1C_SFF(page.PageResponse)
                                        : Modes.PrettifyModePage_1C(page.PageResponse);
                            }
                            else if (page.Subpage == 1)
                            {
                                decodedText = Modes.PrettifyModePage_1C_S01(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x1D:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_1D(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x21:
                        {
                            if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "CERTANCE")
                            {
                                decodedText = Modes.PrettifyCertanceModePage_21(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x22:
                        {
                            if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "CERTANCE")
                            {
                                decodedText = Modes.PrettifyCertanceModePage_22(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x24:
                        {
                            if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "IBM")
                            {
                                decodedText = Modes.PrettifyIBMModePage_24(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x2A:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_2A(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x2F:
                        {
                            if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "IBM")
                            {
                                decodedText = Modes.PrettifyIBMModePage_2F(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x30:
                        {
                            if (Modes.IsAppleModePage_30(page.PageResponse))
                            {
                                decodedText = "Drive identifies as Apple OEM drive";
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x3B:
                        {
                            if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "HP")
                            {
                                decodedText = Modes.PrettifyHPModePage_3B(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x3C:
                        {
                            if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "HP")
                            {
                                decodedText = Modes.PrettifyHPModePage_3C(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x3D:
                        {
                            if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "IBM")
                            {
                                decodedText = Modes.PrettifyIBMModePage_3D(page.PageResponse);
                            }
                            else if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "HP")
                            {
                                decodedText = Modes.PrettifyHPModePage_3D(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x3E:
                        {
                            if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "FUJITSU")
                            {
                                decodedText = Modes.PrettifyFujitsuModePage_3E(page.PageResponse);
                            }
                            else if (StringHandlers.CToString(inquiry?.VendorIdentification).Trim() == "HP")
                            {
                                decodedText = Modes.PrettifyHPModePage_3E(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        default:
                        {
                            decodedText = "Undecoded";
                            break;
                        }
                        }

                        // TODO: Automatic error reporting
                        if (decodedText == null)
                        {
                            decodedText = "Error decoding page, please open an issue.";
                        }
                        modePagesList.Add(new TreeGridItem {
                            Values = new object[] { pageNumberText, decodedText }
                        });
                    }
                }
            }

            if (evpdPages != null)
            {
                tabScsiEvpd.Visible      = true;
                treeEvpdPages.ShowHeader = false;

                var evpdPagesList = new TreeGridItemCollection();

                treeEvpdPages.Columns.Add(new GridColumn {
                    HeaderText = "Page", DataCell = new TextBoxCell(0)
                });

                treeEvpdPages.AllowMultipleSelection = false;
                treeEvpdPages.ShowHeader             = false;
                treeEvpdPages.DataStore = evpdPagesList;

                foreach (var page in evpdPages.OrderBy(t => t.Key))
                {
                    var evpdPageTitle   = "";
                    var evpdDecodedPage = "";
                    if (page.Key >= 0x01 && page.Key <= 0x7F)
                    {
                        evpdPageTitle   = $"ASCII Page {page.Key:X2}h";
                        evpdDecodedPage = EVPD.DecodeASCIIPage(page.Value);
                    }
                    else if (page.Key == 0x80)
                    {
                        evpdPageTitle   = "Unit Serial Number";
                        evpdDecodedPage = EVPD.DecodePage80(page.Value);
                    }
                    else if (page.Key == 0x81)
                    {
                        evpdPageTitle   = "SCSI Implemented operating definitions";
                        evpdDecodedPage = EVPD.PrettifyPage_81(page.Value);
                    }
                    else if (page.Key == 0x82)
                    {
                        evpdPageTitle   = "ASCII implemented operating definitions";
                        evpdDecodedPage = EVPD.DecodePage82(page.Value);
                    }
                    else if (page.Key == 0x83)
                    {
                        evpdPageTitle   = "SCSI Device identification";
                        evpdDecodedPage = EVPD.PrettifyPage_83(page.Value);
                    }
                    else if (page.Key == 0x84)
                    {
                        evpdPageTitle   = "SCSI Software Interface Identifiers";
                        evpdDecodedPage = EVPD.PrettifyPage_84(page.Value);
                    }
                    else if (page.Key == 0x85)
                    {
                        evpdPageTitle   = "SCSI Management Network Addresses";
                        evpdDecodedPage = EVPD.PrettifyPage_85(page.Value);
                    }
                    else if (page.Key == 0x86)
                    {
                        evpdPageTitle   = "SCSI Extended INQUIRY Data";
                        evpdDecodedPage = EVPD.PrettifyPage_86(page.Value);
                    }
                    else if (page.Key == 0x89)
                    {
                        evpdPageTitle   = "SCSI to ATA Translation Layer Data";
                        evpdDecodedPage = EVPD.PrettifyPage_89(page.Value);
                    }
                    else if (page.Key == 0xB0)
                    {
                        evpdPageTitle   = "SCSI Sequential-access Device Capabilities";
                        evpdDecodedPage = EVPD.PrettifyPage_B0(page.Value);
                    }
                    else if (page.Key == 0xB1)
                    {
                        evpdPageTitle   = "Manufacturer-assigned Serial Number";
                        evpdDecodedPage = EVPD.DecodePageB1(page.Value);
                    }
                    else if (page.Key == 0xB2)
                    {
                        evpdPageTitle   = "TapeAlert Supported Flags Bitmap";
                        evpdDecodedPage = $"0x{EVPD.DecodePageB2(page.Value):X16}";
                    }
                    else if (page.Key == 0xB3)
                    {
                        evpdPageTitle   = "Automation Device Serial Number";
                        evpdDecodedPage = EVPD.DecodePageB3(page.Value);
                    }
                    else if (page.Key == 0xB4)
                    {
                        evpdPageTitle   = "Data Transfer Device Element Address";
                        evpdDecodedPage = EVPD.DecodePageB4(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "quantum")
                    {
                        evpdPageTitle   = "Quantum Firmware Build Information page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_Quantum(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "seagate")
                    {
                        evpdPageTitle   = "Seagate Firmware Numbers page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_Seagate(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "ibm")
                    {
                        evpdPageTitle   = "IBM Drive Component Revision Levels page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_IBM(page.Value);
                    }
                    else if (page.Key == 0xC1 &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "ibm")
                    {
                        evpdPageTitle   = "IBM Drive Serial Numbers page";
                        evpdDecodedPage = EVPD.PrettifyPage_C1_IBM(page.Value);
                    }
                    else if ((page.Key == 0xC0 || page.Key == 0xC1) &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "certance")
                    {
                        evpdPageTitle   = "Certance Drive Component Revision Levels page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_C1_Certance(page.Value);
                    }
                    else if ((page.Key == 0xC2 || page.Key == 0xC3 || page.Key == 0xC4 || page.Key == 0xC5 ||
                              page.Key == 0xC6) &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "certance")
                    {
                        switch (page.Key)
                        {
                        case 0xC2:
                            evpdPageTitle = "Head Assembly Serial Number";
                            break;

                        case 0xC3:
                            evpdPageTitle = "Reel Motor 1 Serial Number";
                            break;

                        case 0xC4:
                            evpdPageTitle = "Reel Motor 2 Serial Number";
                            break;

                        case 0xC5:
                            evpdPageTitle = "Board Serial Number";
                            break;

                        case 0xC6:
                            evpdPageTitle = "Base Mechanical Serial Number";
                            break;
                        }

                        evpdDecodedPage = EVPD.PrettifyPage_C2_C3_C4_C5_C6_Certance(page.Value);
                    }
                    else if ((page.Key == 0xC0 || page.Key == 0xC1 || page.Key == 0xC2 || page.Key == 0xC3 ||
                              page.Key == 0xC4 || page.Key == 0xC5) && StringHandlers
                             .CToString(inquiry.Value.VendorIdentification)
                             .ToLowerInvariant().Trim() == "hp")
                    {
                        switch (page.Key)
                        {
                        case 0xC0:
                            evpdPageTitle = "HP Drive Firmware Revision Levels page:";
                            break;

                        case 0xC1:
                            evpdPageTitle = "HP Drive Hardware Revision Levels page:";
                            break;

                        case 0xC2:
                            evpdPageTitle = "HP Drive PCA Revision Levels page:";
                            break;

                        case 0xC3:
                            evpdPageTitle = "HP Drive Mechanism Revision Levels page:";
                            break;

                        case 0xC4:
                            evpdPageTitle = "HP Drive Head Assembly Revision Levels page:";
                            break;

                        case 0xC5:
                            evpdPageTitle = "HP Drive ACI Revision Levels page:";
                            break;
                        }

                        evpdDecodedPage = EVPD.PrettifyPage_C0_to_C5_HP(page.Value);
                    }
                    else if (page.Key == 0xDF &&
                             StringHandlers.CToString(inquiry.Value.VendorIdentification).ToLowerInvariant().Trim() ==
                             "certance")
                    {
                        evpdPageTitle   = "Certance drive status page";
                        evpdDecodedPage = EVPD.PrettifyPage_DF_Certance(page.Value);
                    }
                    else
                    {
                        if (page.Key == 0x00)
                        {
                            continue;
                        }

                        evpdPageTitle   = $"Page {page.Key:X2}h";
                        evpdDecodedPage = "Undecoded";
                        DicConsole.DebugWriteLine("Device-Info command", "Found undecoded SCSI VPD page 0x{0:X2}",
                                                  page.Key);
                    }

                    evpdPagesList.Add(new TreeGridItem
                    {
                        Values = new object[] { evpdPageTitle, evpdDecodedPage, page.Value }
                    });
                }
            }

            if (configuration != null)
            {
                tabMmcFeatures.Visible = true;

                var featuresList = new TreeGridItemCollection();

                treeMmcFeatures.Columns.Add(new GridColumn {
                    HeaderText = "Feature", DataCell = new TextBoxCell(0)
                });

                treeMmcFeatures.AllowMultipleSelection = false;
                treeMmcFeatures.ShowHeader             = false;
                treeMmcFeatures.DataStore = featuresList;

                var ftr = Features.Separate(configuration);

                DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION length is {0} bytes",
                                          ftr.DataLength);
                DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION current profile is {0:X4}h",
                                          ftr.CurrentProfile);
                if (ftr.Descriptors != null)
                {
                    foreach (var desc in ftr.Descriptors)
                    {
                        var    featureNumber = $"Feature {desc.Code:X4}h";
                        string featureDescription;
                        DicConsole.DebugWriteLine("Device-Info command", "Feature {0:X4}h", desc.Code);

                        switch (desc.Code)
                        {
                        case 0x0000:
                            featureDescription = Features.Prettify_0000(desc.Data);
                            break;

                        case 0x0001:
                            featureDescription = Features.Prettify_0001(desc.Data);
                            break;

                        case 0x0002:
                            featureDescription = Features.Prettify_0002(desc.Data);
                            break;

                        case 0x0003:
                            featureDescription = Features.Prettify_0003(desc.Data);
                            break;

                        case 0x0004:
                            featureDescription = Features.Prettify_0004(desc.Data);
                            break;

                        case 0x0010:
                            featureDescription = Features.Prettify_0010(desc.Data);
                            break;

                        case 0x001D:
                            featureDescription = Features.Prettify_001D(desc.Data);
                            break;

                        case 0x001E:
                            featureDescription = Features.Prettify_001E(desc.Data);
                            break;

                        case 0x001F:
                            featureDescription = Features.Prettify_001F(desc.Data);
                            break;

                        case 0x0020:
                            featureDescription = Features.Prettify_0020(desc.Data);
                            break;

                        case 0x0021:
                            featureDescription = Features.Prettify_0021(desc.Data);
                            break;

                        case 0x0022:
                            featureDescription = Features.Prettify_0022(desc.Data);
                            break;

                        case 0x0023:
                            featureDescription = Features.Prettify_0023(desc.Data);
                            break;

                        case 0x0024:
                            featureDescription = Features.Prettify_0024(desc.Data);
                            break;

                        case 0x0025:
                            featureDescription = Features.Prettify_0025(desc.Data);
                            break;

                        case 0x0026:
                            featureDescription = Features.Prettify_0026(desc.Data);
                            break;

                        case 0x0027:
                            featureDescription = Features.Prettify_0027(desc.Data);
                            break;

                        case 0x0028:
                            featureDescription = Features.Prettify_0028(desc.Data);
                            break;

                        case 0x0029:
                            featureDescription = Features.Prettify_0029(desc.Data);
                            break;

                        case 0x002A:
                            featureDescription = Features.Prettify_002A(desc.Data);
                            break;

                        case 0x002B:
                            featureDescription = Features.Prettify_002B(desc.Data);
                            break;

                        case 0x002C:
                            featureDescription = Features.Prettify_002C(desc.Data);
                            break;

                        case 0x002D:
                            featureDescription = Features.Prettify_002D(desc.Data);
                            break;

                        case 0x002E:
                            featureDescription = Features.Prettify_002E(desc.Data);
                            break;

                        case 0x002F:
                            featureDescription = Features.Prettify_002F(desc.Data);
                            break;

                        case 0x0030:
                            featureDescription = Features.Prettify_0030(desc.Data);
                            break;

                        case 0x0031:
                            featureDescription = Features.Prettify_0031(desc.Data);
                            break;

                        case 0x0032:
                            featureDescription = Features.Prettify_0032(desc.Data);
                            break;

                        case 0x0033:
                            featureDescription = Features.Prettify_0033(desc.Data);
                            break;

                        case 0x0035:
                            featureDescription = Features.Prettify_0035(desc.Data);
                            break;

                        case 0x0037:
                            featureDescription = Features.Prettify_0037(desc.Data);
                            break;

                        case 0x0038:
                            featureDescription = Features.Prettify_0038(desc.Data);
                            break;

                        case 0x003A:
                            featureDescription = Features.Prettify_003A(desc.Data);
                            break;

                        case 0x003B:
                            featureDescription = Features.Prettify_003B(desc.Data);
                            break;

                        case 0x0040:
                            featureDescription = Features.Prettify_0040(desc.Data);
                            break;

                        case 0x0041:
                            featureDescription = Features.Prettify_0041(desc.Data);
                            break;

                        case 0x0042:
                            featureDescription = Features.Prettify_0042(desc.Data);
                            break;

                        case 0x0050:
                            featureDescription = Features.Prettify_0050(desc.Data);
                            break;

                        case 0x0051:
                            featureDescription = Features.Prettify_0051(desc.Data);
                            break;

                        case 0x0080:
                            featureDescription = Features.Prettify_0080(desc.Data);
                            break;

                        case 0x0100:
                            featureDescription = Features.Prettify_0100(desc.Data);
                            break;

                        case 0x0101:
                            featureDescription = Features.Prettify_0101(desc.Data);
                            break;

                        case 0x0102:
                            featureDescription = Features.Prettify_0102(desc.Data);
                            break;

                        case 0x0103:
                            featureDescription = Features.Prettify_0103(desc.Data);
                            break;

                        case 0x0104:
                            featureDescription = Features.Prettify_0104(desc.Data);
                            break;

                        case 0x0105:
                            featureDescription = Features.Prettify_0105(desc.Data);
                            break;

                        case 0x0106:
                            featureDescription = Features.Prettify_0106(desc.Data);
                            break;

                        case 0x0107:
                            featureDescription = Features.Prettify_0107(desc.Data);
                            break;

                        case 0x0108:
                            featureDescription = Features.Prettify_0108(desc.Data);
                            break;

                        case 0x0109:
                            featureDescription = Features.Prettify_0109(desc.Data);
                            break;

                        case 0x010A:
                            featureDescription = Features.Prettify_010A(desc.Data);
                            break;

                        case 0x010B:
                            featureDescription = Features.Prettify_010B(desc.Data);
                            break;

                        case 0x010C:
                            featureDescription = Features.Prettify_010C(desc.Data);
                            break;

                        case 0x010D:
                            featureDescription = Features.Prettify_010D(desc.Data);
                            break;

                        case 0x010E:
                            featureDescription = Features.Prettify_010E(desc.Data);
                            break;

                        case 0x0110:
                            featureDescription = Features.Prettify_0110(desc.Data);
                            break;

                        case 0x0113:
                            featureDescription = Features.Prettify_0113(desc.Data);
                            break;

                        case 0x0142:
                            featureDescription = Features.Prettify_0142(desc.Data);
                            break;

                        default:
                            featureDescription = "Unknown feature";
                            break;
                        }

                        featuresList.Add(new TreeGridItem {
                            Values = new object[] { featureNumber, featureDescription }
                        });
                    }
                }
                else
                {
                    DicConsole.DebugWriteLine("Device-Info command",
                                              "GET CONFIGURATION returned no feature descriptors");
                }
            }

            Invalidate();
        }
        public ActionResult View(int?id)
        {
            if (id == null || id <= 0)
            {
                return(Content("Incorrect device report request"));
            }

            try
            {
                DicServerContext ctx    = new DicServerContext();
                Device           report = ctx.Devices.FirstOrDefault(d => d.Id == id);

                if (report is null)
                {
                    return(Content("Cannot find requested report"));
                }

                ViewBag.lblManufacturer = report.Manufacturer;
                ViewBag.lblModel        = report.Model;
                ViewBag.lblRevision     = report.Revision;

                if (report.USB != null)
                {
                    string usbVendorDescription  = null;
                    string usbProductDescription = null;

                    UsbProduct dbProduct =
                        ctx.UsbProducts.FirstOrDefault(p => p.ProductId == report.USB.ProductID &&
                                                       p.Vendor != null &&
                                                       p.Vendor.VendorId == report.USB.VendorID);

                    if (dbProduct is null)
                    {
                        UsbVendor dbVendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == report.USB.VendorID);

                        if (!(dbVendor is null))
                        {
                            usbVendorDescription = dbVendor.Vendor;
                        }
                    }
                    else
                    {
                        usbProductDescription = dbProduct.Product;
                        usbVendorDescription  = dbProduct.Vendor.Vendor;
                    }

                    ViewBag.UsbItem = new Item
                    {
                        Manufacturer      = report.USB.Manufacturer,
                        Product           = report.USB.Product,
                        VendorDescription =
                            usbVendorDescription != null
                                ? $"0x{report.USB.VendorID:x4} ({usbVendorDescription})"
                                : $"0x{report.USB.VendorID:x4}",
                        ProductDescription = usbProductDescription != null
                                                 ? $"0x{report.USB.ProductID:x4} ({usbProductDescription})"
                                                 : $"0x{report.USB.ProductID:x4}"
                    };
                }

                if (report.FireWire != null)
                {
                    ViewBag.FireWireItem = new Item
                    {
                        Manufacturer       = report.FireWire.Manufacturer,
                        Product            = report.FireWire.Product,
                        VendorDescription  = $"0x{report.FireWire.VendorID:x8}",
                        ProductDescription = $"0x{report.FireWire.ProductID:x8}"
                    }
                }
                ;

                if (report.PCMCIA != null)
                {
                    ViewBag.PcmciaItem = new PcmciaItem
                    {
                        Manufacturer       = report.PCMCIA.Manufacturer,
                        Product            = report.PCMCIA.ProductName,
                        VendorDescription  = $"0x{report.PCMCIA.ManufacturerCode:x4}",
                        ProductDescription = $"0x{report.PCMCIA.CardCode:x4}",
                        Compliance         = report.PCMCIA.Compliance
                    };

                    Tuple[] tuples = CIS.GetTuples(report.PCMCIA.CIS);
                    if (tuples != null)
                    {
                        Dictionary <string, string> decodedTuples = new Dictionary <string, string>();
                        foreach (Tuple tuple in tuples)
                        {
                            switch (tuple.Code)
                            {
                            case TupleCodes.CISTPL_NULL:
                            case TupleCodes.CISTPL_END:
                            case TupleCodes.CISTPL_MANFID:
                            case TupleCodes.CISTPL_VERS_1: break;

                            case TupleCodes.CISTPL_DEVICEGEO:
                            case TupleCodes.CISTPL_DEVICEGEO_A:
                                DeviceGeometryTuple geom = CIS.DecodeDeviceGeometryTuple(tuple.Data);
                                if (geom?.Geometries != null)
                                {
                                    foreach (DeviceGeometry geometry in geom.Geometries)
                                    {
                                        decodedTuples.Add("Device width",
                                                          $"{(1 << (geometry.CardInterface - 1)) * 8} bits");
                                        decodedTuples.Add("Erase block",
                                                          $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Read block",
                                                          $"{(1 << (geometry.ReadBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Write block",
                                                          $"{(1 << (geometry.WriteBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Partition alignment",
                                                          $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1)) * (1 << (geometry.Partitions - 1))} bytes");
                                    }
                                }

                                break;

                            case TupleCodes.CISTPL_ALTSTR:
                            case TupleCodes.CISTPL_BAR:
                            case TupleCodes.CISTPL_BATTERY:
                            case TupleCodes.CISTPL_BYTEORDER:
                            case TupleCodes.CISTPL_CFTABLE_ENTRY:
                            case TupleCodes.CISTPL_CFTABLE_ENTRY_CB:
                            case TupleCodes.CISTPL_CHECKSUM:
                            case TupleCodes.CISTPL_CONFIG:
                            case TupleCodes.CISTPL_CONFIG_CB:
                            case TupleCodes.CISTPL_DATE:
                            case TupleCodes.CISTPL_DEVICE:
                            case TupleCodes.CISTPL_DEVICE_A:
                            case TupleCodes.CISTPL_DEVICE_OA:
                            case TupleCodes.CISTPL_DEVICE_OC:
                            case TupleCodes.CISTPL_EXTDEVIC:
                            case TupleCodes.CISTPL_FORMAT:
                            case TupleCodes.CISTPL_FORMAT_A:
                            case TupleCodes.CISTPL_FUNCE:
                            case TupleCodes.CISTPL_FUNCID:
                            case TupleCodes.CISTPL_GEOMETRY:
                            case TupleCodes.CISTPL_INDIRECT:
                            case TupleCodes.CISTPL_JEDEC_A:
                            case TupleCodes.CISTPL_JEDEC_C:
                            case TupleCodes.CISTPL_LINKTARGET:
                            case TupleCodes.CISTPL_LONGLINK_A:
                            case TupleCodes.CISTPL_LONGLINK_C:
                            case TupleCodes.CISTPL_LONGLINK_CB:
                            case TupleCodes.CISTPL_LONGLINK_MFC:
                            case TupleCodes.CISTPL_NO_LINK:
                            case TupleCodes.CISTPL_ORG:
                            case TupleCodes.CISTPL_PWR_MGMNT:
                            case TupleCodes.CISTPL_SPCL:
                            case TupleCodes.CISTPL_SWIL:
                            case TupleCodes.CISTPL_VERS_2:
                                decodedTuples.Add("Undecoded tuple ID", tuple.Code.ToString());
                                break;

                            default:
                                decodedTuples.Add("Unknown tuple ID", $"0x{(byte)tuple.Code:X2}");
                                break;
                            }
                        }

                        if (decodedTuples.Count > 0)
                        {
                            ViewBag.repPcmciaTuples = decodedTuples;
                        }
                    }
                }

                bool removable = true;
                List <TestedMedia> testedMedia = null;
                bool ata      = false;
                bool atapi    = false;
                bool sscMedia = false;

                if (report.ATA != null || report.ATAPI != null)
                {
                    ata = true;
                    List <string> ataOneValue = new List <string>();
                    Dictionary <string, string> ataTwoValue = new Dictionary <string, string>();
                    CommonTypes.Metadata.Ata    ataReport;

                    if (report.ATAPI != null)
                    {
                        ViewBag.AtaItem = "ATAPI";
                        ataReport       = report.ATAPI;
                        atapi           = true;
                    }
                    else
                    {
                        ViewBag.AtaItem = "ATA";
                        ataReport       = report.ATA;
                    }

                    bool cfa = report.CompactFlash;

                    if (atapi && !cfa)
                    {
                        ViewBag.lblAtaDeviceType = "ATAPI device";
                    }
                    else if (!atapi && cfa)
                    {
                        ViewBag.lblAtaDeviceType = "CompactFlash device";
                    }
                    else
                    {
                        ViewBag.lblAtaDeviceType = "ATA device";
                    }

                    Ata.Report(ataReport, cfa, atapi, ref removable, ref ataOneValue, ref ataTwoValue, ref testedMedia);

                    ViewBag.repAtaOne = ataOneValue;
                    ViewBag.repAtaTwo = ataTwoValue;
                }

                if (report.SCSI != null)
                {
                    List <string> scsiOneValue            = new List <string>();
                    Dictionary <string, string> modePages = new Dictionary <string, string>();
                    Dictionary <string, string> evpdPages = new Dictionary <string, string>();

                    string vendorId = StringHandlers.CToString(report.SCSI.Inquiry?.VendorIdentification);
                    if (report.SCSI.Inquiry != null)
                    {
                        Inquiry.SCSIInquiry inq = report.SCSI.Inquiry.Value;
                        ViewBag.lblScsiVendor = VendorString.Prettify(vendorId) != vendorId
                                                    ? $"{vendorId} ({VendorString.Prettify(vendorId)})"
                                                    : vendorId;
                        ViewBag.lblScsiProduct  = StringHandlers.CToString(inq.ProductIdentification);
                        ViewBag.lblScsiRevision = StringHandlers.CToString(inq.ProductRevisionLevel);
                    }

                    scsiOneValue.AddRange(ScsiInquiry.Report(report.SCSI.Inquiry));

                    if (report.SCSI.SupportsModeSense6)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE (6)");
                    }
                    if (report.SCSI.SupportsModeSense10)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE (10)");
                    }
                    if (report.SCSI.SupportsModeSubpages)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE subpages");
                    }

                    if (report.SCSI.ModeSense != null)
                    {
                        PeripheralDeviceTypes devType = PeripheralDeviceTypes.DirectAccess;
                        if (report.SCSI.Inquiry != null)
                        {
                            devType = (PeripheralDeviceTypes)report.SCSI.Inquiry.Value.PeripheralDeviceType;
                        }
                        ScsiModeSense.Report(report.SCSI.ModeSense, vendorId, devType, ref scsiOneValue, ref modePages);
                    }

                    if (modePages.Count > 0)
                    {
                        ViewBag.repModeSense = modePages;
                    }

                    if (report.SCSI.EVPDPages != null)
                    {
                        ScsiEvpd.Report(report.SCSI.EVPDPages, vendorId, ref evpdPages);
                    }

                    if (evpdPages.Count > 0)
                    {
                        ViewBag.repEvpd = evpdPages;
                    }

                    if (report.SCSI.MultiMediaDevice != null)
                    {
                        testedMedia = report.SCSI.MultiMediaDevice.TestedMedia;

                        if (report.SCSI.MultiMediaDevice.ModeSense2A != null)
                        {
                            List <string> mmcModeOneValue = new List <string>();
                            ScsiMmcMode.Report(report.SCSI.MultiMediaDevice.ModeSense2A, ref mmcModeOneValue);
                            if (mmcModeOneValue.Count > 0)
                            {
                                ViewBag.repScsiMmcMode = mmcModeOneValue;
                            }
                        }

                        if (report.SCSI.MultiMediaDevice.Features != null)
                        {
                            List <string> mmcFeaturesOneValue = new List <string>();
                            ScsiMmcFeatures.Report(report.SCSI.MultiMediaDevice.Features, ref mmcFeaturesOneValue);
                            if (mmcFeaturesOneValue.Count > 0)
                            {
                                ViewBag.repScsiMmcFeatures = mmcFeaturesOneValue;
                            }
                        }
                    }
                    else if (report.SCSI.SequentialDevice != null)
                    {
                        ViewBag.divScsiSscVisible = true;

                        ViewBag.lblScsiSscGranularity =
                            report.SCSI.SequentialDevice.BlockSizeGranularity?.ToString() ?? "Unspecified";

                        ViewBag.lblScsiSscMaxBlock =
                            report.SCSI.SequentialDevice.MaxBlockLength?.ToString() ?? "Unspecified";

                        ViewBag.lblScsiSscMinBlock =
                            report.SCSI.SequentialDevice.MinBlockLength?.ToString() ?? "Unspecified";

                        if (report.SCSI.SequentialDevice.SupportedDensities != null)
                        {
                            ViewBag.repScsiSscDensities = report.SCSI.SequentialDevice.SupportedDensities;
                        }

                        if (report.SCSI.SequentialDevice.SupportedMediaTypes != null)
                        {
                            ViewBag.repScsiSscMedias = report.SCSI.SequentialDevice.SupportedMediaTypes;
                        }

                        if (report.SCSI.SequentialDevice.TestedMedia != null)
                        {
                            List <string> mediaOneValue = new List <string>();
                            SscTestedMedia.Report(report.SCSI.SequentialDevice.TestedMedia, ref mediaOneValue);
                            if (mediaOneValue.Count > 0)
                            {
                                sscMedia = true;
                                ViewBag.repTestedMedia = mediaOneValue;
                            }
                        }
                    }
                    else if (report.SCSI.ReadCapabilities != null)
                    {
                        removable = false;
                        scsiOneValue.Add("");

                        if (report.SCSI.ReadCapabilities.Blocks.HasValue &&
                            report.SCSI.ReadCapabilities.BlockSize.HasValue)
                        {
                            scsiOneValue
                            .Add($"Device has {report.SCSI.ReadCapabilities.Blocks} blocks of {report.SCSI.ReadCapabilities.BlockSize} bytes each");

                            if (report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1024 /
                                1024 > 1000000)
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB");
                            }
                            else if (report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize /
                                     1024 /
                                     1024 > 1000)
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024:F2} GiB");
                            }
                            else
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000} Mb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024:F2} MiB");
                            }
                        }

                        if (report.SCSI.ReadCapabilities.MediumType.HasValue)
                        {
                            scsiOneValue.Add($"Medium type code: {report.SCSI.ReadCapabilities.MediumType:X2}h");
                        }
                        if (report.SCSI.ReadCapabilities.Density.HasValue)
                        {
                            scsiOneValue.Add($"Density code: {report.SCSI.ReadCapabilities.Density:X2}h");
                        }
                        if ((report.SCSI.ReadCapabilities.SupportsReadLong == true ||
                             report.SCSI.ReadCapabilities.SupportsReadLong16 == true) &&
                            report.SCSI.ReadCapabilities.LongBlockSize.HasValue)
                        {
                            scsiOneValue.Add($"Long block size: {report.SCSI.ReadCapabilities.LongBlockSize} bytes");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadCapacity == true)
                        {
                            scsiOneValue.Add("Device supports READ CAPACITY (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadCapacity16 == true)
                        {
                            scsiOneValue.Add("Device supports READ CAPACITY (16) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead6 == true)
                        {
                            scsiOneValue.Add("Device supports READ (6) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead10 == true)
                        {
                            scsiOneValue.Add("Device supports READ (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead12 == true)
                        {
                            scsiOneValue.Add("Device supports READ (12) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead16 == true)
                        {
                            scsiOneValue.Add("Device supports READ (16) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadLong == true)
                        {
                            scsiOneValue.Add("Device supports READ LONG (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadLong16 == true)
                        {
                            scsiOneValue.Add("Device supports READ LONG (16) command.");
                        }
                    }
                    else
                    {
                        testedMedia = report.SCSI.RemovableMedias;
                    }

                    ViewBag.repScsi = scsiOneValue;
                }

                if (report.MultiMediaCard != null)
                {
                    List <string> mmcOneValue = new List <string>();

                    if (report.MultiMediaCard.CID != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCID(report.MultiMediaCard.CID)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.CSD != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.CSD)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.ExtendedCSD != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyExtendedCSD(report.MultiMediaCard.ExtendedCSD)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.OCR != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.OCR)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    ViewBag.repMMC = mmcOneValue;
                }

                if (report.SecureDigital != null)
                {
                    List <string> sdOneValue = new List <string>();

                    if (report.SecureDigital.CID != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCID(report.SecureDigital.CID)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.CSD != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.CSD)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.SCR != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifySCR(report.SecureDigital.SCR)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.OCR != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.OCR)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    ViewBag.repSD = sdOneValue;
                }

                if (removable && !sscMedia && testedMedia != null)
                {
                    List <string> mediaOneValue = new List <string>();
                    App_Start.TestedMedia.Report(testedMedia, ref mediaOneValue);
                    if (mediaOneValue.Count > 0)
                    {
                        ViewBag.repTestedMedia = mediaOneValue;
                    }
                }
            }
            catch (Exception)
            {
                #if DEBUG
                throw;
                #endif
                return(Content("Could not load device report"));
            }

            return(View());
        }
Esempio n. 9
0
        public ScsiInfoViewModel(byte[] scsiInquiryData, Inquiry?scsiInquiry, Dictionary <byte, byte[]> scsiEvpdPages,
                                 Modes.DecodedMode?scsiMode, PeripheralDeviceTypes scsiType, byte[] scsiModeSense6,
                                 byte[] scsiModeSense10, byte[] mmcConfiguration, Window view)
        {
            InquiryData              = scsiInquiryData;
            _scsiModeSense6          = scsiModeSense6;
            _scsiModeSense10         = scsiModeSense10;
            _configuration           = mmcConfiguration;
            _view                    = view;
            ModeSensePages           = new ObservableCollection <ScsiPageModel>();
            EvpdPages                = new ObservableCollection <ScsiPageModel>();
            MmcFeatures              = new ObservableCollection <ScsiPageModel>();
            SaveInquiryBinaryCommand = ReactiveCommand.Create(ExecuteSaveInquiryBinaryCommand);
            SaveInquiryTextCommand   = ReactiveCommand.Create(ExecuteSaveInquiryTextCommand);
            SaveModeSense6Command    = ReactiveCommand.Create(ExecuteSaveModeSense6Command);
            SaveModeSense10Command   = ReactiveCommand.Create(ExecuteSaveModeSense10Command);
            SaveEvpdPageCommand      = ReactiveCommand.Create(ExecuteSaveEvpdPageCommand);
            SaveMmcFeaturesCommand   = ReactiveCommand.Create(ExecuteSaveMmcFeaturesCommand);

            if (InquiryData == null ||
                !scsiInquiry.HasValue)
            {
                return;
            }

            ScsiInquiryText = Decoders.SCSI.Inquiry.Prettify(scsiInquiry);

            if (scsiMode.HasValue)
            {
                ModeSensePages.Add(new ScsiPageModel
                {
                    Page        = "Header",
                    Description = Modes.PrettifyModeHeader(scsiMode.Value.Header, scsiType)
                });

                if (scsiMode.Value.Pages != null)
                {
                    foreach (Modes.ModePage page in scsiMode.Value.Pages.OrderBy(t => t.Page).ThenBy(t => t.Subpage))
                    {
                        string pageNumberText = page.Subpage == 0 ? $"MODE {page.Page:X2}h"
                                                    : $"MODE {page.Page:X2} Subpage {page.Subpage:X2}";

                        string decodedText;

                        switch (page.Page)
                        {
                        case 0x00:
                        {
                            if (scsiType == PeripheralDeviceTypes.MultiMediaDevice &&
                                page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_00_SFF(page.PageResponse);
                            }
                            else
                            {
                                decodedText = "Undecoded";
                            }

                            break;
                        }

                        case 0x01:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = scsiType == PeripheralDeviceTypes.MultiMediaDevice
                                                      ? Modes.PrettifyModePage_01_MMC(page.PageResponse)
                                                      : Modes.PrettifyModePage_01(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x02:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_02(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x03:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_03(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x04:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_04(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x05:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_05(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x06:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_06(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x07:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = scsiType == PeripheralDeviceTypes.MultiMediaDevice
                                                      ? Modes.PrettifyModePage_07_MMC(page.PageResponse)
                                                      : Modes.PrettifyModePage_07(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x08:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_08(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0A:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0A(page.PageResponse);
                            }
                            else if (page.Subpage == 1)
                            {
                                decodedText = Modes.PrettifyModePage_0A_S01(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0B:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0B(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0D:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0D(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0E:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0E(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x0F:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_0F(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x10:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = scsiType == PeripheralDeviceTypes.SequentialAccess
                                                      ? Modes.PrettifyModePage_10_SSC(page.PageResponse)
                                                      : Modes.PrettifyModePage_10(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x11:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_11(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x12:
                        case 0x13:
                        case 0x14:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_12_13_14(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x1A:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_1A(page.PageResponse);
                            }
                            else if (page.Subpage == 1)
                            {
                                decodedText = Modes.PrettifyModePage_1A_S01(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x1B:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_1B(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x1C:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = scsiType == PeripheralDeviceTypes.MultiMediaDevice
                                                      ? Modes.PrettifyModePage_1C_SFF(page.PageResponse)
                                                      : Modes.PrettifyModePage_1C(page.PageResponse);
                            }
                            else if (page.Subpage == 1)
                            {
                                decodedText = Modes.PrettifyModePage_1C_S01(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x1D:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_1D(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x21:
                        {
                            if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() ==
                                "CERTANCE")
                            {
                                decodedText = Modes.PrettifyCertanceModePage_21(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x22:
                        {
                            if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() ==
                                "CERTANCE")
                            {
                                decodedText = Modes.PrettifyCertanceModePage_22(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x24:
                        {
                            if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() == "IBM")
                            {
                                decodedText = Modes.PrettifyIBMModePage_24(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x2A:
                        {
                            if (page.Subpage == 0)
                            {
                                decodedText = Modes.PrettifyModePage_2A(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x2F:
                        {
                            if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() == "IBM")
                            {
                                decodedText = Modes.PrettifyIBMModePage_2F(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x30:
                        {
                            if (Modes.IsAppleModePage_30(page.PageResponse))
                            {
                                decodedText = "Drive identifies as Apple OEM drive";
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x3B:
                        {
                            if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() == "HP")
                            {
                                decodedText = Modes.PrettifyHPModePage_3B(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x3C:
                        {
                            if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() == "HP")
                            {
                                decodedText = Modes.PrettifyHPModePage_3C(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x3D:
                        {
                            if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() == "IBM")
                            {
                                decodedText = Modes.PrettifyIBMModePage_3D(page.PageResponse);
                            }
                            else if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() == "HP")
                            {
                                decodedText = Modes.PrettifyHPModePage_3D(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        case 0x3E:
                        {
                            if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() == "FUJITSU")
                            {
                                decodedText = Modes.PrettifyFujitsuModePage_3E(page.PageResponse);
                            }
                            else if (StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).Trim() == "HP")
                            {
                                decodedText = Modes.PrettifyHPModePage_3E(page.PageResponse);
                            }
                            else
                            {
                                goto default;
                            }

                            break;
                        }

                        default:
                        {
                            decodedText = "Undecoded";

                            break;
                        }
                        }

                        // TODO: Automatic error reporting
                        if (decodedText == null)
                        {
                            decodedText = "Error decoding page, please open an issue.";
                        }

                        ModeSensePages.Add(new ScsiPageModel
                        {
                            Page        = pageNumberText,
                            Description = decodedText
                        });
                    }
                }
            }

            if (scsiEvpdPages != null)
            {
                foreach (KeyValuePair <byte, byte[]> page in scsiEvpdPages.OrderBy(t => t.Key))
                {
                    string evpdPageTitle = "";
                    string evpdDecodedPage;

                    if (page.Key >= 0x01 &&
                        page.Key <= 0x7F)
                    {
                        evpdPageTitle   = $"ASCII Page {page.Key:X2}h";
                        evpdDecodedPage = EVPD.DecodeASCIIPage(page.Value);
                    }
                    else if (page.Key == 0x80)
                    {
                        evpdPageTitle   = "Unit Serial Number";
                        evpdDecodedPage = EVPD.DecodePage80(page.Value);
                    }
                    else if (page.Key == 0x81)
                    {
                        evpdPageTitle   = "SCSI Implemented operating definitions";
                        evpdDecodedPage = EVPD.PrettifyPage_81(page.Value);
                    }
                    else if (page.Key == 0x82)
                    {
                        evpdPageTitle   = "ASCII implemented operating definitions";
                        evpdDecodedPage = EVPD.DecodePage82(page.Value);
                    }
                    else if (page.Key == 0x83)
                    {
                        evpdPageTitle   = "SCSI Device identification";
                        evpdDecodedPage = EVPD.PrettifyPage_83(page.Value);
                    }
                    else if (page.Key == 0x84)
                    {
                        evpdPageTitle   = "SCSI Software Interface Identifiers";
                        evpdDecodedPage = EVPD.PrettifyPage_84(page.Value);
                    }
                    else if (page.Key == 0x85)
                    {
                        evpdPageTitle   = "SCSI Management Network Addresses";
                        evpdDecodedPage = EVPD.PrettifyPage_85(page.Value);
                    }
                    else if (page.Key == 0x86)
                    {
                        evpdPageTitle   = "SCSI Extended INQUIRY Data";
                        evpdDecodedPage = EVPD.PrettifyPage_86(page.Value);
                    }
                    else if (page.Key == 0x89)
                    {
                        evpdPageTitle   = "SCSI to ATA Translation Layer Data";
                        evpdDecodedPage = EVPD.PrettifyPage_89(page.Value);
                    }
                    else if (page.Key == 0xB0)
                    {
                        evpdPageTitle   = "SCSI Sequential-access Device Capabilities";
                        evpdDecodedPage = EVPD.PrettifyPage_B0(page.Value);
                    }
                    else if (page.Key == 0xB1)
                    {
                        evpdPageTitle   = "Manufacturer-assigned Serial Number";
                        evpdDecodedPage = EVPD.DecodePageB1(page.Value);
                    }
                    else if (page.Key == 0xB2)
                    {
                        evpdPageTitle   = "TapeAlert Supported Flags Bitmap";
                        evpdDecodedPage = $"0x{EVPD.DecodePageB2(page.Value):X16}";
                    }
                    else if (page.Key == 0xB3)
                    {
                        evpdPageTitle   = "Automation Device Serial Number";
                        evpdDecodedPage = EVPD.DecodePageB3(page.Value);
                    }
                    else if (page.Key == 0xB4)
                    {
                        evpdPageTitle   = "Data Transfer Device Element Address";
                        evpdDecodedPage = EVPD.DecodePageB4(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).ToLowerInvariant().
                             Trim() == "quantum")
                    {
                        evpdPageTitle   = "Quantum Firmware Build Information page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_Quantum(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).ToLowerInvariant().
                             Trim() == "seagate")
                    {
                        evpdPageTitle   = "Seagate Firmware Numbers page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_Seagate(page.Value);
                    }
                    else if (page.Key == 0xC0 &&
                             StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).ToLowerInvariant().
                             Trim() == "ibm")
                    {
                        evpdPageTitle   = "IBM Drive Component Revision Levels page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_IBM(page.Value);
                    }
                    else if (page.Key == 0xC1 &&
                             StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).ToLowerInvariant().
                             Trim() == "ibm")
                    {
                        evpdPageTitle   = "IBM Drive Serial Numbers page";
                        evpdDecodedPage = EVPD.PrettifyPage_C1_IBM(page.Value);
                    }
                    else if ((page.Key == 0xC0 || page.Key == 0xC1) &&
                             StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).ToLowerInvariant().
                             Trim() == "certance")
                    {
                        evpdPageTitle   = "Certance Drive Component Revision Levels page";
                        evpdDecodedPage = EVPD.PrettifyPage_C0_C1_Certance(page.Value);
                    }
                    else if ((page.Key == 0xC2 || page.Key == 0xC3 || page.Key == 0xC4 || page.Key == 0xC5 ||
                              page.Key == 0xC6) &&
                             StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).ToLowerInvariant().
                             Trim() == "certance")
                    {
                        switch (page.Key)
                        {
                        case 0xC2:
                            evpdPageTitle = "Head Assembly Serial Number";

                            break;

                        case 0xC3:
                            evpdPageTitle = "Reel Motor 1 Serial Number";

                            break;

                        case 0xC4:
                            evpdPageTitle = "Reel Motor 2 Serial Number";

                            break;

                        case 0xC5:
                            evpdPageTitle = "Board Serial Number";

                            break;

                        case 0xC6:
                            evpdPageTitle = "Base Mechanical Serial Number";

                            break;
                        }

                        evpdDecodedPage = EVPD.PrettifyPage_C2_C3_C4_C5_C6_Certance(page.Value);
                    }
                    else if ((page.Key == 0xC0 || page.Key == 0xC1 || page.Key == 0xC2 || page.Key == 0xC3 ||
                              page.Key == 0xC4 || page.Key == 0xC5) &&
                             StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).ToLowerInvariant().
                             Trim() == "hp")
                    {
                        switch (page.Key)
                        {
                        case 0xC0:
                            evpdPageTitle = "HP Drive Firmware Revision Levels page:";

                            break;

                        case 0xC1:
                            evpdPageTitle = "HP Drive Hardware Revision Levels page:";

                            break;

                        case 0xC2:
                            evpdPageTitle = "HP Drive PCA Revision Levels page:";

                            break;

                        case 0xC3:
                            evpdPageTitle = "HP Drive Mechanism Revision Levels page:";

                            break;

                        case 0xC4:
                            evpdPageTitle = "HP Drive Head Assembly Revision Levels page:";

                            break;

                        case 0xC5:
                            evpdPageTitle = "HP Drive ACI Revision Levels page:";

                            break;
                        }

                        evpdDecodedPage = EVPD.PrettifyPage_C0_to_C5_HP(page.Value);
                    }
                    else if (page.Key == 0xDF &&
                             StringHandlers.CToString(scsiInquiry.Value.VendorIdentification).ToLowerInvariant().
                             Trim() == "certance")
                    {
                        evpdPageTitle   = "Certance drive status page";
                        evpdDecodedPage = EVPD.PrettifyPage_DF_Certance(page.Value);
                    }
                    else
                    {
                        if (page.Key == 0x00)
                        {
                            continue;
                        }

                        evpdPageTitle   = $"Page {page.Key:X2}h";
                        evpdDecodedPage = "Undecoded";

                        AaruConsole.DebugWriteLine("Device-Info command", "Found undecoded SCSI VPD page 0x{0:X2}",
                                                   page.Key);
                    }

                    EvpdPages.Add(new ScsiPageModel
                    {
                        Page        = evpdPageTitle,
                        Data        = page.Value,
                        Description = evpdDecodedPage
                    });
                }
            }

            if (_configuration != null)
            {
                Features.SeparatedFeatures ftr = Features.Separate(_configuration);

                AaruConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION length is {0} bytes",
                                           ftr.DataLength);

                AaruConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION current profile is {0:X4}h",
                                           ftr.CurrentProfile);

                if (ftr.Descriptors != null)
                {
                    foreach (Features.FeatureDescriptor desc in ftr.Descriptors)
                    {
                        string featureNumber = $"Feature {desc.Code:X4}h";
                        string featureDescription;
                        AaruConsole.DebugWriteLine("Device-Info command", "Feature {0:X4}h", desc.Code);

                        switch (desc.Code)
                        {
                        case 0x0000:
                            featureDescription = Features.Prettify_0000(desc.Data);

                            break;

                        case 0x0001:
                            featureDescription = Features.Prettify_0001(desc.Data);

                            break;

                        case 0x0002:
                            featureDescription = Features.Prettify_0002(desc.Data);

                            break;

                        case 0x0003:
                            featureDescription = Features.Prettify_0003(desc.Data);

                            break;

                        case 0x0004:
                            featureDescription = Features.Prettify_0004(desc.Data);

                            break;

                        case 0x0010:
                            featureDescription = Features.Prettify_0010(desc.Data);

                            break;

                        case 0x001D:
                            featureDescription = Features.Prettify_001D(desc.Data);

                            break;

                        case 0x001E:
                            featureDescription = Features.Prettify_001E(desc.Data);

                            break;

                        case 0x001F:
                            featureDescription = Features.Prettify_001F(desc.Data);

                            break;

                        case 0x0020:
                            featureDescription = Features.Prettify_0020(desc.Data);

                            break;

                        case 0x0021:
                            featureDescription = Features.Prettify_0021(desc.Data);

                            break;

                        case 0x0022:
                            featureDescription = Features.Prettify_0022(desc.Data);

                            break;

                        case 0x0023:
                            featureDescription = Features.Prettify_0023(desc.Data);

                            break;

                        case 0x0024:
                            featureDescription = Features.Prettify_0024(desc.Data);

                            break;

                        case 0x0025:
                            featureDescription = Features.Prettify_0025(desc.Data);

                            break;

                        case 0x0026:
                            featureDescription = Features.Prettify_0026(desc.Data);

                            break;

                        case 0x0027:
                            featureDescription = Features.Prettify_0027(desc.Data);

                            break;

                        case 0x0028:
                            featureDescription = Features.Prettify_0028(desc.Data);

                            break;

                        case 0x0029:
                            featureDescription = Features.Prettify_0029(desc.Data);

                            break;

                        case 0x002A:
                            featureDescription = Features.Prettify_002A(desc.Data);

                            break;

                        case 0x002B:
                            featureDescription = Features.Prettify_002B(desc.Data);

                            break;

                        case 0x002C:
                            featureDescription = Features.Prettify_002C(desc.Data);

                            break;

                        case 0x002D:
                            featureDescription = Features.Prettify_002D(desc.Data);

                            break;

                        case 0x002E:
                            featureDescription = Features.Prettify_002E(desc.Data);

                            break;

                        case 0x002F:
                            featureDescription = Features.Prettify_002F(desc.Data);

                            break;

                        case 0x0030:
                            featureDescription = Features.Prettify_0030(desc.Data);

                            break;

                        case 0x0031:
                            featureDescription = Features.Prettify_0031(desc.Data);

                            break;

                        case 0x0032:
                            featureDescription = Features.Prettify_0032(desc.Data);

                            break;

                        case 0x0033:
                            featureDescription = Features.Prettify_0033(desc.Data);

                            break;

                        case 0x0035:
                            featureDescription = Features.Prettify_0035(desc.Data);

                            break;

                        case 0x0037:
                            featureDescription = Features.Prettify_0037(desc.Data);

                            break;

                        case 0x0038:
                            featureDescription = Features.Prettify_0038(desc.Data);

                            break;

                        case 0x003A:
                            featureDescription = Features.Prettify_003A(desc.Data);

                            break;

                        case 0x003B:
                            featureDescription = Features.Prettify_003B(desc.Data);

                            break;

                        case 0x0040:
                            featureDescription = Features.Prettify_0040(desc.Data);

                            break;

                        case 0x0041:
                            featureDescription = Features.Prettify_0041(desc.Data);

                            break;

                        case 0x0042:
                            featureDescription = Features.Prettify_0042(desc.Data);

                            break;

                        case 0x0050:
                            featureDescription = Features.Prettify_0050(desc.Data);

                            break;

                        case 0x0051:
                            featureDescription = Features.Prettify_0051(desc.Data);

                            break;

                        case 0x0080:
                            featureDescription = Features.Prettify_0080(desc.Data);

                            break;

                        case 0x0100:
                            featureDescription = Features.Prettify_0100(desc.Data);

                            break;

                        case 0x0101:
                            featureDescription = Features.Prettify_0101(desc.Data);

                            break;

                        case 0x0102:
                            featureDescription = Features.Prettify_0102(desc.Data);

                            break;

                        case 0x0103:
                            featureDescription = Features.Prettify_0103(desc.Data);

                            break;

                        case 0x0104:
                            featureDescription = Features.Prettify_0104(desc.Data);

                            break;

                        case 0x0105:
                            featureDescription = Features.Prettify_0105(desc.Data);

                            break;

                        case 0x0106:
                            featureDescription = Features.Prettify_0106(desc.Data);

                            break;

                        case 0x0107:
                            featureDescription = Features.Prettify_0107(desc.Data);

                            break;

                        case 0x0108:
                            featureDescription = Features.Prettify_0108(desc.Data);

                            break;

                        case 0x0109:
                            featureDescription = Features.Prettify_0109(desc.Data);

                            break;

                        case 0x010A:
                            featureDescription = Features.Prettify_010A(desc.Data);

                            break;

                        case 0x010B:
                            featureDescription = Features.Prettify_010B(desc.Data);

                            break;

                        case 0x010C:
                            featureDescription = Features.Prettify_010C(desc.Data);

                            break;

                        case 0x010D:
                            featureDescription = Features.Prettify_010D(desc.Data);

                            break;

                        case 0x010E:
                            featureDescription = Features.Prettify_010E(desc.Data);

                            break;

                        case 0x0110:
                            featureDescription = Features.Prettify_0110(desc.Data);

                            break;

                        case 0x0113:
                            featureDescription = Features.Prettify_0113(desc.Data);

                            break;

                        case 0x0142:
                            featureDescription = Features.Prettify_0142(desc.Data);

                            break;

                        default:
                            featureDescription = "Unknown feature";

                            break;
                        }

                        MmcFeatures.Add(new ScsiPageModel
                        {
                            Page        = featureNumber,
                            Description = featureDescription
                        });
                    }
                }
                else
                {
                    AaruConsole.DebugWriteLine("Device-Info command",
                                               "GET CONFIGURATION returned no feature descriptors");
                }
            }
        }
Esempio n. 10
0
 public static string PrettifyModeHeader6(byte[] modeResponse, PeripheralDeviceTypes deviceType) =>
 PrettifyModeHeader(DecodeModeHeader6(modeResponse, deviceType), deviceType);
Esempio n. 11
0
        public static byte[] EncodeModeHeader6(ModeHeader header, PeripheralDeviceTypes deviceType)
        {
            byte[] hdr = header.BlockDescriptors != null
                             ? new byte[4 + header.BlockDescriptors.Length * 8]
                             : new byte[4];

            hdr[1] = (byte)header.MediumType;

            switch (deviceType)
            {
            case PeripheralDeviceTypes.DirectAccess:
            case PeripheralDeviceTypes.MultiMediaDevice:
                if (header.WriteProtected)
                {
                    hdr[2] += 0x80;
                }
                if (header.DPOFUA)
                {
                    hdr[2] += 0x10;
                }
                break;

            case PeripheralDeviceTypes.SequentialAccess:
                if (header.WriteProtected)
                {
                    hdr[2] += 0x80;
                }
                hdr[2] += (byte)(header.Speed & 0x0F);
                hdr[2] += (byte)((header.BufferedMode << 4) & 0x70);
                break;

            case PeripheralDeviceTypes.PrinterDevice:
                hdr[2] += (byte)((header.BufferedMode << 4) & 0x70);
                break;

            case PeripheralDeviceTypes.OpticalDevice:
                if (header.WriteProtected)
                {
                    hdr[2] += 0x80;
                }
                if (header.EBC)
                {
                    hdr[2] += 0x01;
                }
                if (header.DPOFUA)
                {
                    hdr[2] += 0x10;
                }
                break;
            }

            if (header.BlockDescriptors == null)
            {
                return(hdr);
            }

            hdr[3] = (byte)(header.BlockDescriptors.Length * 8);

            for (int i = 0; i < header.BlockDescriptors.Length; i++)
            {
                hdr[0 + i * 8 + 4] = (byte)header.BlockDescriptors[i].Density;
                hdr[1 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16);
                hdr[2 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8);
                hdr[3 + i * 8 + 4] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF);
                hdr[5 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16);
                hdr[6 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8);
                hdr[7 + i * 8 + 4] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF);
            }

            return(hdr);
        }
Esempio n. 12
0
        public ImageInfoViewModel(string imagePath, IFilter filter, IMediaImage imageFormat, Window view)

        {
            _imagePath   = imagePath;
            _filter      = filter;
            _imageFormat = imageFormat;
            _view        = view;
            IAssetLoader assets = AvaloniaLocator.Current.GetService <IAssetLoader>();

            MediaTagsList         = new ObservableCollection <string>();
            SectorTagsList        = new ObservableCollection <string>();
            Sessions              = new ObservableCollection <Session>();
            Tracks                = new ObservableCollection <Track>();
            DumpHardwareList      = new ObservableCollection <DumpHardwareModel>();
            EntropyCommand        = ReactiveCommand.Create(ExecuteEntropyCommand);
            VerifyCommand         = ReactiveCommand.Create(ExecuteVerifyCommand);
            ChecksumCommand       = ReactiveCommand.Create(ExecuteChecksumCommand);
            ConvertCommand        = ReactiveCommand.Create(ExecuteConvertCommand);
            CreateSidecarCommand  = ReactiveCommand.Create(ExecuteCreateSidecarCommand);
            ViewSectorsCommand    = ReactiveCommand.Create(ExecuteViewSectorsCommand);
            DecodeMediaTagCommand = ReactiveCommand.Create(ExecuteDecodeMediaTagCommand);

            var genericHddIcon =
                new Bitmap(assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-harddisk.png")));

            var genericOpticalIcon =
                new Bitmap(assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-optical.png")));

            var genericFolderIcon =
                new Bitmap(assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/inode-directory.png")));

            var mediaResource = new Uri($"avares://Aaru.Gui/Assets/Logos/Media/{imageFormat.Info.MediaType}.png");

            MediaLogo = assets.Exists(mediaResource)
                            ? new Bitmap(assets.Open(mediaResource))
                            : imageFormat.Info.XmlMediaType == XmlMediaType.BlockMedia
                                ? genericHddIcon
                                : imageFormat.Info.XmlMediaType == XmlMediaType.OpticalDisc
                                    ? genericOpticalIcon
                                    : genericFolderIcon;

            ImagePathText       = $"Path: {imagePath}";
            FilterText          = $"Filter: {filter.Name}";
            ImageIdentifiedText = $"Image format identified by {imageFormat.Name} ({imageFormat.Id}).";

            ImageFormatText = !string.IsNullOrWhiteSpace(imageFormat.Info.Version)
                                  ? $"Format: {imageFormat.Format} version {imageFormat.Info.Version}"
                                  : $"Format: {imageFormat.Format}";

            ImageSizeText = $"Image without headers is {imageFormat.Info.ImageSize} bytes long";

            SectorsText =
                $"Contains a media of {imageFormat.Info.Sectors} sectors with a maximum sector size of {imageFormat.Info.SectorSize} bytes (if all sectors are of the same size this would be {imageFormat.Info.Sectors * imageFormat.Info.SectorSize} bytes)";

            MediaTypeText =
                $"Contains a media of type {imageFormat.Info.MediaType} and XML type {imageFormat.Info.XmlMediaType}";

            HasPartitionsText = $"{(imageFormat.Info.HasPartitions ? "Has" : "Doesn't have")} partitions";
            HasSessionsText   = $"{(imageFormat.Info.HasSessions ? "Has" : "Doesn't have")} sessions";

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Application))
            {
                ApplicationText = !string.IsNullOrWhiteSpace(imageFormat.Info.ApplicationVersion)
                                      ? $"Was created with {imageFormat.Info.Application} version {imageFormat.Info.ApplicationVersion}"
                                      : $"Was created with {imageFormat.Info.Application}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Creator))
            {
                CreatorText = $"Created by: {imageFormat.Info.Creator}";
            }

            if (imageFormat.Info.CreationTime != DateTime.MinValue)
            {
                CreationTimeText = $"Created on {imageFormat.Info.CreationTime}";
            }

            if (imageFormat.Info.LastModificationTime != DateTime.MinValue)
            {
                LastModificationTimeText = $"Last modified on {imageFormat.Info.LastModificationTime}";
            }

            if (imageFormat.Info.MediaSequence != 0 &&
                imageFormat.Info.LastMediaSequence != 0)
            {
                MediaSequenceText =
                    $"Media is number {imageFormat.Info.MediaSequence} on a set of {imageFormat.Info.LastMediaSequence} medias";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaTitle))
            {
                MediaTitleText = $"Media title: {imageFormat.Info.MediaTitle}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaManufacturer))
            {
                MediaManufacturerText = $"Media manufacturer: {imageFormat.Info.MediaManufacturer}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaModel))
            {
                MediaModelText = $"Media model: {imageFormat.Info.MediaModel}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaSerialNumber))
            {
                MediaSerialNumberText = $"Media serial number: {imageFormat.Info.MediaSerialNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaBarcode))
            {
                MediaBarcodeText = $"Media barcode: {imageFormat.Info.MediaBarcode}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaPartNumber))
            {
                MediaPartNumberText = $"Media part number: {imageFormat.Info.MediaPartNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveManufacturer))
            {
                DriveManufacturerText = $"Drive manufacturer: {imageFormat.Info.DriveManufacturer}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveModel))
            {
                DriveModelText = $"Drive model: {imageFormat.Info.DriveModel}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveSerialNumber))
            {
                DriveSerialNumberText = $"Drive serial number: {imageFormat.Info.DriveSerialNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveFirmwareRevision))
            {
                DriveFirmwareRevisionText = $"Drive firmware info: {imageFormat.Info.DriveFirmwareRevision}";
            }

            if (imageFormat.Info.Cylinders > 0 &&
                imageFormat.Info.Heads > 0 &&
                imageFormat.Info.SectorsPerTrack > 0 &&
                imageFormat.Info.XmlMediaType != XmlMediaType.OpticalDisc &&
                (!(imageFormat is ITapeImage tapeImage) || !tapeImage.IsTape))
            {
                MediaGeometryText =
                    $"Media geometry: {imageFormat.Info.Cylinders} cylinders, {imageFormat.Info.Heads} heads, {imageFormat.Info.SectorsPerTrack} sectors per track";
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Count > 0)
            {
                foreach (MediaTagType tag in imageFormat.Info.ReadableMediaTags.OrderBy(t => t))
                {
                    MediaTagsList.Add(tag.ToString());
                }
            }

            if (imageFormat.Info.ReadableSectorTags != null &&
                imageFormat.Info.ReadableSectorTags.Count > 0)
            {
                foreach (SectorTagType tag in imageFormat.Info.ReadableSectorTags.OrderBy(t => t))
                {
                    SectorTagsList.Add(tag.ToString());
                }
            }

            PeripheralDeviceTypes scsiDeviceType = PeripheralDeviceTypes.DirectAccess;

            byte[]  scsiInquiryData = null;
            Inquiry?scsiInquiry     = null;

            Modes.DecodedMode?scsiMode        = null;
            byte[]            scsiModeSense6  = null;
            byte[]            scsiModeSense10 = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_INQUIRY))
            {
                scsiInquiryData = imageFormat.ReadDiskTag(MediaTagType.SCSI_INQUIRY);

                scsiDeviceType = (PeripheralDeviceTypes)(scsiInquiryData[0] & 0x1F);

                scsiInquiry = Inquiry.Decode(scsiInquiryData);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODESENSE_6))
            {
                scsiModeSense6 = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODESENSE_6);
                scsiMode       = Modes.DecodeMode6(scsiModeSense6, scsiDeviceType);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODESENSE_10))
            {
                scsiModeSense10 = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODESENSE_10);
                scsiMode        = Modes.DecodeMode10(scsiModeSense10, scsiDeviceType);
            }

            ScsiInfo = new ScsiInfo
            {
                DataContext = new ScsiInfoViewModel(scsiInquiryData, scsiInquiry, null, scsiMode, scsiDeviceType,
                                                    scsiModeSense6, scsiModeSense10, null, _view)
            };

            byte[] ataIdentify   = null;
            byte[] atapiIdentify = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATA_IDENTIFY))
            {
                ataIdentify = imageFormat.ReadDiskTag(MediaTagType.ATA_IDENTIFY);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATAPI_IDENTIFY))
            {
                atapiIdentify = imageFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY);
            }

            AtaInfo = new AtaInfo
            {
                DataContext = new AtaInfoViewModel(ataIdentify, atapiIdentify, null, _view)
            };

            byte[]                toc                  = null;
            TOC.CDTOC?            decodedToc           = null;
            byte[]                fullToc              = null;
            FullTOC.CDFullTOC?    decodedFullToc       = null;
            byte[]                pma                  = null;
            byte[]                atip                 = null;
            ATIP.CDATIP?          decodedAtip          = null;
            byte[]                cdtext               = null;
            CDTextOnLeadIn.CDText?decodedCdText        = null;
            string                mediaCatalogueNumber = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_TOC))
            {
                toc = imageFormat.ReadDiskTag(MediaTagType.CD_TOC);

                if (toc.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(toc, 0));

                    if (dataLen + 2 != toc.Length)
                    {
                        byte[] tmp = new byte[toc.Length + 2];
                        Array.Copy(toc, 0, tmp, 2, toc.Length);
                        tmp[0] = (byte)((toc.Length & 0xFF00) >> 8);
                        tmp[1] = (byte)(toc.Length & 0xFF);
                        toc    = tmp;
                    }

                    decodedToc = TOC.Decode(toc);
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_FullTOC))
            {
                fullToc = imageFormat.ReadDiskTag(MediaTagType.CD_FullTOC);

                if (fullToc.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(fullToc, 0));

                    if (dataLen + 2 != fullToc.Length)
                    {
                        byte[] tmp = new byte[fullToc.Length + 2];
                        Array.Copy(fullToc, 0, tmp, 2, fullToc.Length);
                        tmp[0]  = (byte)((fullToc.Length & 0xFF00) >> 8);
                        tmp[1]  = (byte)(fullToc.Length & 0xFF);
                        fullToc = tmp;
                    }

                    decodedFullToc = FullTOC.Decode(fullToc);
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_PMA))
            {
                pma = imageFormat.ReadDiskTag(MediaTagType.CD_PMA);

                if (pma.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(pma, 0));

                    if (dataLen + 2 != pma.Length)
                    {
                        byte[] tmp = new byte[pma.Length + 2];
                        Array.Copy(pma, 0, tmp, 2, pma.Length);
                        tmp[0] = (byte)((pma.Length & 0xFF00) >> 8);
                        tmp[1] = (byte)(pma.Length & 0xFF);
                        pma    = tmp;
                    }
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_ATIP))
            {
                atip = imageFormat.ReadDiskTag(MediaTagType.CD_ATIP);

                uint dataLen = Swapping.Swap(BitConverter.ToUInt32(atip, 0));

                if (dataLen + 4 != atip.Length)
                {
                    byte[] tmp = new byte[atip.Length + 4];
                    Array.Copy(atip, 0, tmp, 4, atip.Length);
                    tmp[0] = (byte)((atip.Length & 0xFF000000) >> 24);
                    tmp[1] = (byte)((atip.Length & 0xFF0000) >> 16);
                    tmp[2] = (byte)((atip.Length & 0xFF00) >> 8);
                    tmp[3] = (byte)(atip.Length & 0xFF);
                    atip   = tmp;
                }

                decodedAtip = ATIP.Decode(atip);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_TEXT))
            {
                cdtext = imageFormat.ReadDiskTag(MediaTagType.CD_TEXT);

                uint dataLen = Swapping.Swap(BitConverter.ToUInt32(cdtext, 0));

                if (dataLen + 4 != cdtext.Length)
                {
                    byte[] tmp = new byte[cdtext.Length + 4];
                    Array.Copy(cdtext, 0, tmp, 4, cdtext.Length);
                    tmp[0] = (byte)((cdtext.Length & 0xFF000000) >> 24);
                    tmp[1] = (byte)((cdtext.Length & 0xFF0000) >> 16);
                    tmp[2] = (byte)((cdtext.Length & 0xFF00) >> 8);
                    tmp[3] = (byte)(cdtext.Length & 0xFF);
                    cdtext = tmp;
                }

                decodedCdText = CDTextOnLeadIn.Decode(cdtext);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_MCN))
            {
                byte[] mcn = imageFormat.ReadDiskTag(MediaTagType.CD_MCN);

                mediaCatalogueNumber = Encoding.UTF8.GetString(mcn);
            }

            CompactDiscInfo = new CompactDiscInfo
            {
                DataContext = new CompactDiscInfoViewModel(toc, atip, null, null, fullToc, pma, cdtext, decodedToc,
                                                           decodedAtip, null, decodedFullToc, decodedCdText, null,
                                                           mediaCatalogueNumber, null, _view)
            };

            byte[] dvdPfi = null;
            byte[] dvdDmi = null;
            byte[] dvdCmi = null;
            byte[] hddvdCopyrightInformation = null;
            byte[] dvdBca = null;
            PFI.PhysicalFormatInformation?decodedPfi = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_PFI))
            {
                dvdPfi     = imageFormat.ReadDiskTag(MediaTagType.DVD_PFI);
                decodedPfi = PFI.Decode(dvdPfi);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_DMI))
            {
                dvdDmi = imageFormat.ReadDiskTag(MediaTagType.DVD_DMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_CMI))
            {
                dvdCmi = imageFormat.ReadDiskTag(MediaTagType.DVD_CMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.HDDVD_CPI))
            {
                hddvdCopyrightInformation = imageFormat.ReadDiskTag(MediaTagType.HDDVD_CPI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_BCA))
            {
                dvdBca = imageFormat.ReadDiskTag(MediaTagType.DVD_BCA);
            }

            DvdInfo = new DvdInfo
            {
                DataContext = new DvdInfoViewModel(imageFormat.Info.MediaType, dvdPfi, dvdDmi, dvdCmi,
                                                   hddvdCopyrightInformation, dvdBca, null, decodedPfi, _view)
            };

            byte[] dvdRamDds                     = null;
            byte[] dvdRamCartridgeStatus         = null;
            byte[] dvdRamSpareArea               = null;
            byte[] lastBorderOutRmd              = null;
            byte[] dvdPreRecordedInfo            = null;
            byte[] dvdrMediaIdentifier           = null;
            byte[] dvdrPhysicalInformation       = null;
            byte[] hddvdrMediumStatus            = null;
            byte[] dvdrLayerCapacity             = null;
            byte[] dvdrDlMiddleZoneStart         = null;
            byte[] dvdrDlJumpIntervalSize        = null;
            byte[] dvdrDlManualLayerJumpStartLba = null;
            byte[] dvdPlusAdip                   = null;
            byte[] dvdPlusDcb                    = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_DDS))
            {
                dvdRamDds = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_DDS);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_MediumStatus))
            {
                dvdRamCartridgeStatus = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_MediumStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_SpareArea))
            {
                dvdRamSpareArea = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_SpareArea);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_RMD))
            {
                lastBorderOutRmd = imageFormat.ReadDiskTag(MediaTagType.DVDR_RMD);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_PreRecordedInfo))
            {
                dvdPreRecordedInfo = imageFormat.ReadDiskTag(MediaTagType.DVDR_PreRecordedInfo);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_MediaIdentifier))
            {
                dvdrMediaIdentifier = imageFormat.ReadDiskTag(MediaTagType.DVDR_MediaIdentifier);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_PFI))
            {
                dvdrPhysicalInformation = imageFormat.ReadDiskTag(MediaTagType.DVDR_PFI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.HDDVD_MediumStatus))
            {
                hddvdrMediumStatus = imageFormat.ReadDiskTag(MediaTagType.HDDVD_MediumStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_LayerCapacity))
            {
                dvdrLayerCapacity = imageFormat.ReadDiskTag(MediaTagType.DVDDL_LayerCapacity);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_MiddleZoneAddress))
            {
                dvdrDlMiddleZoneStart = imageFormat.ReadDiskTag(MediaTagType.DVDDL_MiddleZoneAddress);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_JumpIntervalSize))
            {
                dvdrDlJumpIntervalSize = imageFormat.ReadDiskTag(MediaTagType.DVDDL_JumpIntervalSize);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_ManualLayerJumpLBA))
            {
                dvdrDlManualLayerJumpStartLba = imageFormat.ReadDiskTag(MediaTagType.DVDDL_ManualLayerJumpLBA);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_ADIP))
            {
                dvdPlusAdip = imageFormat.ReadDiskTag(MediaTagType.DVD_ADIP);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DCB))
            {
                dvdPlusDcb = imageFormat.ReadDiskTag(MediaTagType.DCB);
            }

            DvdWritableInfo = new DvdWritableInfo
            {
                DataContext = new DvdWritableInfoViewModel(imageFormat.Info.MediaType, dvdRamDds, dvdRamCartridgeStatus,
                                                           dvdRamSpareArea, lastBorderOutRmd, dvdPreRecordedInfo,
                                                           dvdrMediaIdentifier, dvdrPhysicalInformation,
                                                           hddvdrMediumStatus, null, dvdrLayerCapacity,
                                                           dvdrDlMiddleZoneStart, dvdrDlJumpIntervalSize,
                                                           dvdrDlManualLayerJumpStartLba, null, dvdPlusAdip, dvdPlusDcb,
                                                           _view)
            };

            byte[] blurayBurstCuttingArea = null;
            byte[] blurayCartridgeStatus  = null;
            byte[] blurayDds                  = null;
            byte[] blurayDiscInformation      = null;
            byte[] blurayPowResources         = null;
            byte[] bluraySpareAreaInformation = null;
            byte[] blurayTrackResources       = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_BCA))
            {
                blurayBurstCuttingArea = imageFormat.ReadDiskTag(MediaTagType.BD_BCA);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_CartridgeStatus))
            {
                blurayCartridgeStatus = imageFormat.ReadDiskTag(MediaTagType.BD_CartridgeStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_DDS))
            {
                blurayDds = imageFormat.ReadDiskTag(MediaTagType.BD_DDS);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_DI))
            {
                blurayDiscInformation = imageFormat.ReadDiskTag(MediaTagType.BD_DI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_POWResourcesInformation))
            {
                blurayPowResources = imageFormat.ReadDiskTag(MediaTagType.MMC_POWResourcesInformation);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_SpareArea))
            {
                bluraySpareAreaInformation = imageFormat.ReadDiskTag(MediaTagType.BD_SpareArea);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_TrackResourcesInformation))
            {
                bluraySpareAreaInformation = imageFormat.ReadDiskTag(MediaTagType.MMC_TrackResourcesInformation);
            }

            BlurayInfo = new BlurayInfo
            {
                DataContext = new BlurayInfoViewModel(blurayDiscInformation, blurayBurstCuttingArea, blurayDds,
                                                      blurayCartridgeStatus, bluraySpareAreaInformation,
                                                      blurayPowResources, blurayTrackResources, null, null, _view)
            };

            byte[]            xboxDmi                   = null;
            byte[]            xboxSecuritySector        = null;
            SS.SecuritySector?decodedXboxSecuritySector = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_DMI))
            {
                xboxDmi = imageFormat.ReadDiskTag(MediaTagType.Xbox_DMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_SecuritySector))
            {
                xboxSecuritySector        = imageFormat.ReadDiskTag(MediaTagType.Xbox_SecuritySector);
                decodedXboxSecuritySector = SS.Decode(xboxSecuritySector);
            }

            XboxInfo = new XboxInfo
            {
                DataContext = new XboxInfoViewModel(null, xboxDmi, xboxSecuritySector, decodedXboxSecuritySector, _view)
            };

            byte[] pcmciaCis = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.PCMCIA_CIS))
            {
                pcmciaCis = imageFormat.ReadDiskTag(MediaTagType.PCMCIA_CIS);
            }

            PcmciaInfo = new PcmciaInfo
            {
                DataContext = new PcmciaInfoViewModel(pcmciaCis, _view)
            };

            DeviceType deviceType = DeviceType.Unknown;

            byte[] cid         = null;
            byte[] csd         = null;
            byte[] ocr         = null;
            byte[] extendedCsd = null;
            byte[] scr         = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_CID))
            {
                cid        = imageFormat.ReadDiskTag(MediaTagType.SD_CID);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_CSD))
            {
                csd        = imageFormat.ReadDiskTag(MediaTagType.SD_CSD);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_OCR))
            {
                ocr        = imageFormat.ReadDiskTag(MediaTagType.SD_OCR);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_SCR))
            {
                scr        = imageFormat.ReadDiskTag(MediaTagType.SD_SCR);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_CID))
            {
                cid        = imageFormat.ReadDiskTag(MediaTagType.MMC_CID);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_CSD))
            {
                csd        = imageFormat.ReadDiskTag(MediaTagType.MMC_CSD);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_OCR))
            {
                ocr        = imageFormat.ReadDiskTag(MediaTagType.MMC_OCR);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_ExtendedCSD))
            {
                extendedCsd = imageFormat.ReadDiskTag(MediaTagType.MMC_ExtendedCSD);
                deviceType  = DeviceType.MMC;
            }

            SdMmcInfo = new SdMmcInfo
            {
                DataContext = new SdMmcInfoViewModel(deviceType, cid, csd, ocr, extendedCsd, scr)
            };

            if (imageFormat is IOpticalMediaImage opticalMediaImage)
            {
                try
                {
                    if (opticalMediaImage.Sessions != null &&
                        opticalMediaImage.Sessions.Count > 0)
                    {
                        foreach (Session session in opticalMediaImage.Sessions)
                        {
                            Sessions.Add(session);
                        }
                    }
                }
                catch
                {
                    // ignored
                }

                try
                {
                    if (opticalMediaImage.Tracks != null &&
                        opticalMediaImage.Tracks.Count > 0)
                    {
                        foreach (Track track in opticalMediaImage.Tracks)
                        {
                            Tracks.Add(track);
                        }
                    }
                }
                catch
                {
                    // ignored
                }
            }

            if (imageFormat.DumpHardware is null)
            {
                return;
            }

            foreach (DumpHardwareType dump in imageFormat.DumpHardware)
            {
                foreach (ExtentType extent in dump.Extents)
                {
                    DumpHardwareList.Add(new DumpHardwareModel
                    {
                        Manufacturer    = dump.Manufacturer, Model = dump.Model, Serial = dump.Serial,
                        SoftwareName    = dump.Software.Name, SoftwareVersion = dump.Software.Version,
                        OperatingSystem = dump.Software.OperatingSystem, Start = extent.Start, End = extent.End
                    });
                }
            }
        }
Esempio n. 13
0
        public void ReportScsiModes(ref DeviceReportV2 report, out byte[] cdromMode, out MediumTypes mediumType)
        {
            Modes.DecodedMode?    decMode = null;
            PeripheralDeviceTypes devType = _dev.ScsiType;

            byte[] mode10Buffer;
            byte[] mode6Buffer;
            bool   sense;

            mediumType = 0;

            AaruConsole.WriteLine("Querying all mode pages and subpages using SCSI MODE SENSE (10)...");

            foreach (ScsiModeSensePageControl pageControl in new[]
            {
                ScsiModeSensePageControl.Default, ScsiModeSensePageControl.Current, ScsiModeSensePageControl.Changeable
            })
            {
                bool saveBuffer = false;

                sense = _dev.ModeSense10(out mode10Buffer, out _, false, true, pageControl, 0x3F, 0xFF, _dev.Timeout,
                                         out _);

                if (sense || _dev.Error)
                {
                    sense = _dev.ModeSense10(out mode10Buffer, out _, false, false, pageControl, 0x3F, 0xFF,
                                             _dev.Timeout, out _);

                    if (sense || _dev.Error)
                    {
                        sense = _dev.ModeSense10(out mode10Buffer, out _, false, true, pageControl, 0x3F, 0x00,
                                                 _dev.Timeout, out _);

                        if (sense || _dev.Error)
                        {
                            sense = _dev.ModeSense10(out mode10Buffer, out _, false, false, pageControl, 0x3F, 0x00,
                                                     _dev.Timeout, out _);

                            if (!sense &&
                                !_dev.Error)
                            {
                                report.SCSI.SupportsModeSense10 = true;
                                decMode ??= Modes.DecodeMode10(mode10Buffer, devType);
                                saveBuffer = true;
                            }
                        }
                        else
                        {
                            report.SCSI.SupportsModeSense10 = true;
                            decMode ??= Modes.DecodeMode10(mode10Buffer, devType);
                            saveBuffer = true;
                        }
                    }
                    else
                    {
                        report.SCSI.SupportsModeSense10  = true;
                        report.SCSI.SupportsModeSubpages = true;
                        decMode ??= Modes.DecodeMode10(mode10Buffer, devType);
                        saveBuffer = true;
                    }
                }
                else
                {
                    report.SCSI.SupportsModeSense10  = true;
                    report.SCSI.SupportsModeSubpages = true;
                    decMode ??= Modes.DecodeMode10(mode10Buffer, devType);
                    saveBuffer = true;
                }

                if (!saveBuffer)
                {
                    continue;
                }

                switch (pageControl)
                {
                case ScsiModeSensePageControl.Default:
                    report.SCSI.ModeSense10Data = mode10Buffer;

                    break;

                case ScsiModeSensePageControl.Changeable:
                    report.SCSI.ModeSense10ChangeableData = mode10Buffer;

                    break;

                case ScsiModeSensePageControl.Current:
                    report.SCSI.ModeSense10CurrentData = mode10Buffer;

                    break;
                }
            }

            AaruConsole.WriteLine("Querying all mode pages and subpages using SCSI MODE SENSE (6)...");

            foreach (ScsiModeSensePageControl pageControl in new[]
            {
                ScsiModeSensePageControl.Default, ScsiModeSensePageControl.Current, ScsiModeSensePageControl.Changeable
            })
            {
                bool saveBuffer = false;
                sense = _dev.ModeSense6(out mode6Buffer, out _, true, pageControl, 0x3F, 0xFF, _dev.Timeout, out _);

                if (sense || _dev.Error)
                {
                    sense = _dev.ModeSense6(out mode6Buffer, out _, false, pageControl, 0x3F, 0xFF, _dev.Timeout,
                                            out _);

                    if (sense || _dev.Error)
                    {
                        sense = _dev.ModeSense6(out mode6Buffer, out _, true, pageControl, 0x3F, 0x00, _dev.Timeout,
                                                out _);

                        if (sense || _dev.Error)
                        {
                            sense = _dev.ModeSense6(out mode6Buffer, out _, false, pageControl, 0x3F, 0x00,
                                                    _dev.Timeout, out _);

                            if (sense || _dev.Error)
                            {
                                sense = _dev.ModeSense6(out mode6Buffer, out _, true, pageControl, 0x00, 0x00,
                                                        _dev.Timeout, out _);

                                if (sense || _dev.Error)
                                {
                                    sense = _dev.ModeSense6(out mode6Buffer, out _, false, pageControl, 0x00, 0x00,
                                                            _dev.Timeout, out _);

                                    if (!sense &&
                                        !_dev.Error)
                                    {
                                        report.SCSI.SupportsModeSense6 = true;
                                        decMode ??= Modes.DecodeMode6(mode6Buffer, devType);
                                        saveBuffer = true;
                                    }
                                }
                                else
                                {
                                    report.SCSI.SupportsModeSense6 = true;
                                    decMode ??= Modes.DecodeMode6(mode6Buffer, devType);
                                    saveBuffer = true;
                                }
                            }
                            else
                            {
                                report.SCSI.SupportsModeSense6 = true;
                                decMode ??= Modes.DecodeMode6(mode6Buffer, devType);
                                saveBuffer = true;
                            }
                        }
                        else
                        {
                            report.SCSI.SupportsModeSense6 = true;
                            decMode ??= Modes.DecodeMode6(mode6Buffer, devType);
                            saveBuffer = true;
                        }
                    }
                    else
                    {
                        report.SCSI.SupportsModeSense10  = true;
                        report.SCSI.SupportsModeSubpages = true;
                        decMode ??= Modes.DecodeMode6(mode6Buffer, devType);
                        saveBuffer = true;
                    }
                }
                else
                {
                    report.SCSI.SupportsModeSense6   = true;
                    report.SCSI.SupportsModeSubpages = true;
                    decMode ??= Modes.DecodeMode6(mode6Buffer, devType);
                    saveBuffer = true;
                }

                if (!saveBuffer)
                {
                    continue;
                }

                switch (pageControl)
                {
                case ScsiModeSensePageControl.Default:
                    report.SCSI.ModeSense6Data = mode6Buffer;

                    break;

                case ScsiModeSensePageControl.Changeable:
                    report.SCSI.ModeSense6ChangeableData = mode6Buffer;

                    break;

                case ScsiModeSensePageControl.Current:
                    report.SCSI.ModeSense6CurrentData = mode6Buffer;

                    break;
                }
            }

            cdromMode = null;

            if (!decMode.HasValue)
            {
                return;
            }

            mediumType = decMode.Value.Header.MediumType;

            report.SCSI.ModeSense = new ScsiMode
            {
                BlankCheckEnabled = decMode.Value.Header.EBC,
                DPOandFUA         = decMode.Value.Header.DPOFUA,
                WriteProtected    = decMode.Value.Header.WriteProtected
            };

            if (decMode.Value.Header.BufferedMode > 0)
            {
                report.SCSI.ModeSense.BufferedMode = decMode.Value.Header.BufferedMode;
            }

            if (decMode.Value.Header.Speed > 0)
            {
                report.SCSI.ModeSense.Speed = decMode.Value.Header.Speed;
            }

            if (decMode.Value.Pages == null)
            {
                return;
            }

            List <ScsiPage> modePages = new List <ScsiPage>();

            foreach (Modes.ModePage page in decMode.Value.Pages)
            {
                var modePage = new ScsiPage
                {
                    page    = page.Page,
                    subpage = page.Subpage,
                    value   = page.PageResponse
                };

                modePages.Add(modePage);

                if (modePage.page == 0x2A &&
                    modePage.subpage == 0x00)
                {
                    cdromMode = page.PageResponse;
                }
            }

            if (modePages.Count > 0)
            {
                report.SCSI.ModeSense.ModePages = modePages;
            }
        }
Esempio n. 14
0
        public void ReportScsiModes(ref DeviceReportV2 report, out byte[] cdromMode)
        {
            Modes.DecodedMode?    decMode = null;
            PeripheralDeviceTypes devType = _dev.ScsiType;

            byte[] mode10CurrentBuffer;
            byte[] mode10ChangeableBuffer;
            byte[] mode6CurrentBuffer;
            byte[] mode6ChangeableBuffer;

            DicConsole.WriteLine("Querying all mode pages and subpages using SCSI MODE SENSE (10)...");

            bool sense = _dev.ModeSense10(out byte[] mode10Buffer, out _, false, true, ScsiModeSensePageControl.Default,
                                          0x3F, 0xFF, _dev.Timeout, out _);

            if (sense || _dev.Error)
            {
                DicConsole.WriteLine("Querying all mode pages using SCSI MODE SENSE (10)...");

                sense = _dev.ModeSense10(out mode10Buffer, out _, false, true, ScsiModeSensePageControl.Default, 0x3F,
                                         0x00, _dev.Timeout, out _);

                if (!sense &&
                    !_dev.Error)
                {
                    report.SCSI.SupportsModeSense10  = true;
                    report.SCSI.SupportsModeSubpages = false;
                    decMode = Modes.DecodeMode10(mode10Buffer, devType);

                    {
                        sense = _dev.ModeSense10(out mode10CurrentBuffer, out _, false, true,
                                                 ScsiModeSensePageControl.Current, 0x3F, 0x00, _dev.Timeout, out _);

                        if (!sense &&
                            !_dev.Error)
                        {
                            report.SCSI.ModeSense10CurrentData = mode10CurrentBuffer;
                        }

                        sense = _dev.ModeSense10(out mode10ChangeableBuffer, out _, false, true,
                                                 ScsiModeSensePageControl.Changeable, 0x3F, 0x00, _dev.Timeout, out _);

                        if (!sense &&
                            !_dev.Error)
                        {
                            report.SCSI.ModeSense10ChangeableData = mode10ChangeableBuffer;
                        }
                    }
                }
            }
            else
            {
                report.SCSI.SupportsModeSense10  = true;
                report.SCSI.SupportsModeSubpages = true;
                decMode = Modes.DecodeMode10(mode10Buffer, devType);

                {
                    sense = _dev.ModeSense10(out mode10CurrentBuffer, out _, false, true,
                                             ScsiModeSensePageControl.Current, 0x3F, 0xFF, _dev.Timeout, out _);

                    if (!sense &&
                        !_dev.Error)
                    {
                        report.SCSI.ModeSense10CurrentData = mode10CurrentBuffer;
                    }

                    sense = _dev.ModeSense10(out mode10ChangeableBuffer, out _, false, true,
                                             ScsiModeSensePageControl.Changeable, 0x3F, 0xFF, _dev.Timeout, out _);

                    if (!sense &&
                        !_dev.Error)
                    {
                        report.SCSI.ModeSense10ChangeableData = mode10ChangeableBuffer;
                    }
                }
            }

            DicConsole.WriteLine("Querying all mode pages and subpages using SCSI MODE SENSE (6)...");

            sense = _dev.ModeSense6(out byte[] mode6Buffer, out _, false, ScsiModeSensePageControl.Default, 0x3F, 0xFF,
                                    _dev.Timeout, out _);

            if (sense || _dev.Error)
            {
                DicConsole.WriteLine("Querying all mode pages using SCSI MODE SENSE (6)...");

                sense = _dev.ModeSense6(out mode6Buffer, out _, false, ScsiModeSensePageControl.Default, 0x3F, 0x00,
                                        _dev.Timeout, out _);

                if (sense || _dev.Error)
                {
                    DicConsole.WriteLine("Querying SCSI MODE SENSE (6)...");
                    sense = _dev.ModeSense(out mode6Buffer, out _, _dev.Timeout, out _);
                }
                else
                {
                    sense = _dev.ModeSense6(out mode6CurrentBuffer, out _, false, ScsiModeSensePageControl.Current,
                                            0x3F, 0x00, _dev.Timeout, out _);

                    if (!sense &&
                        !_dev.Error)
                    {
                        report.SCSI.ModeSense6CurrentData = mode6CurrentBuffer;
                    }

                    sense = _dev.ModeSense6(out mode6ChangeableBuffer, out _, false,
                                            ScsiModeSensePageControl.Changeable, 0x3F, 0x00, _dev.Timeout, out _);

                    if (!sense &&
                        !_dev.Error)
                    {
                        report.SCSI.ModeSense6ChangeableData = mode6ChangeableBuffer;
                    }
                }
            }
            else
            {
                report.SCSI.SupportsModeSubpages = true;

                {
                    sense = _dev.ModeSense6(out mode6CurrentBuffer, out _, false, ScsiModeSensePageControl.Current,
                                            0x3F, 0xFF, _dev.Timeout, out _);

                    if (!sense &&
                        !_dev.Error)
                    {
                        report.SCSI.ModeSense6CurrentData = mode6CurrentBuffer;
                    }

                    sense = _dev.ModeSense6(out mode6ChangeableBuffer, out _, false,
                                            ScsiModeSensePageControl.Changeable, 0x3F, 0xFF, _dev.Timeout, out _);

                    if (!sense &&
                        !_dev.Error)
                    {
                        report.SCSI.ModeSense6ChangeableData = mode6ChangeableBuffer;
                    }
                }
            }

            if (!sense &&
                !_dev.Error &&
                !decMode.HasValue)
            {
                decMode = Modes.DecodeMode6(mode6Buffer, devType);
            }

            report.SCSI.SupportsModeSense6 |= !sense && !_dev.Error;

            cdromMode = null;

            if (report.SCSI.SupportsModeSense6)
            {
                report.SCSI.ModeSense6Data = mode6Buffer;
            }

            if (report.SCSI.SupportsModeSense10)
            {
                report.SCSI.ModeSense10Data = mode10Buffer;
            }

            if (!decMode.HasValue)
            {
                return;
            }

            report.SCSI.ModeSense = new ScsiMode
            {
                BlankCheckEnabled = decMode.Value.Header.EBC, DPOandFUA = decMode.Value.Header.DPOFUA,
                WriteProtected    = decMode.Value.Header.WriteProtected
            };

            if (decMode.Value.Header.BufferedMode > 0)
            {
                report.SCSI.ModeSense.BufferedMode = decMode.Value.Header.BufferedMode;
            }

            if (decMode.Value.Header.Speed > 0)
            {
                report.SCSI.ModeSense.Speed = decMode.Value.Header.Speed;
            }

            if (decMode.Value.Pages == null)
            {
                return;
            }

            List <ScsiPage> modePages = new List <ScsiPage>();

            foreach (Modes.ModePage page in decMode.Value.Pages)
            {
                var modePage = new ScsiPage
                {
                    page = page.Page, subpage = page.Subpage, value = page.PageResponse
                };

                modePages.Add(modePage);

                if (modePage.page == 0x2A &&
                    modePage.subpage == 0x00)
                {
                    cdromMode = page.PageResponse;
                }
            }

            if (modePages.Count > 0)
            {
                report.SCSI.ModeSense.ModePages = modePages;
            }
        }
Esempio n. 15
0
        /// <summary>
        ///     Takes the MODE PAGEs part of a device report and prints it as a list of values and another list of key=value pairs
        ///     to be sequenced by ASP.NET in the rendering
        /// </summary>
        /// <param name="modeSense">MODE PAGEs part of a device report</param>
        /// <param name="vendor">SCSI vendor string</param>
        /// <param name="deviceType">SCSI peripheral device type</param>
        /// <param name="scsiOneValue">List to put values on</param>
        /// <param name="modePages">List to put key=value pairs on</param>
        public static void Report(ScsiMode modeSense, string vendor,
                                  PeripheralDeviceTypes deviceType,
                                  ref List <string> scsiOneValue, ref Dictionary <string, string> modePages)
        {
            if (modeSense.MediumType.HasValue)
            {
                scsiOneValue.Add($"Medium type is {modeSense.MediumType:X2}h");
            }
            if (modeSense.WriteProtected)
            {
                scsiOneValue.Add("Device is write protected.");
            }
            if (modeSense.BlockDescriptors != null)
            {
                foreach (BlockDescriptor descriptor in modeSense.BlockDescriptors)
                {
                    if (descriptor.Blocks.HasValue && descriptor.BlockLength.HasValue)
                    {
                        scsiOneValue
                        .Add($"Density code {descriptor.Density:X2}h has {descriptor.Blocks} blocks of {descriptor.BlockLength} bytes each");
                    }
                    else
                    {
                        scsiOneValue.Add($"Density code {descriptor.Density:X2}h");
                    }
                }
            }

            if (modeSense.DPOandFUA)
            {
                scsiOneValue.Add("Drive supports DPO and FUA bits");
            }
            if (modeSense.BlankCheckEnabled)
            {
                scsiOneValue.Add("Blank checking during write is enabled");
            }
            if (modeSense.BufferedMode.HasValue)
            {
                switch (modeSense.BufferedMode)
                {
                case 0:
                    scsiOneValue.Add("Device writes directly to media");
                    break;

                case 1:
                    scsiOneValue.Add("Device uses a write cache");
                    break;

                case 2:
                    scsiOneValue.Add("Device uses a write cache but doesn't return until cache is flushed");
                    break;

                default:
                    scsiOneValue.Add($"Unknown buffered mode code 0x{modeSense.BufferedMode:X2}");
                    break;
                }
            }

            if (modeSense.ModePages == null)
            {
                return;
            }

            foreach (ScsiPage page in modeSense.ModePages)
            {
                switch (page.page)
                {
                case 0x00:
                {
                    if (deviceType == PeripheralDeviceTypes.MultiMediaDevice && page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_00_SFF(page.value));
                    }
                    else
                    {
                        modePages
                        .Add(page.subpage != 0 ? $"MODE page {page.page:X2}h subpage {page.subpage:X2}h" : $"MODE page {page.page:X2}h",
                             "Unknown vendor mode page");
                    }
                    break;
                }

                case 0x01:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h",
                                      deviceType == PeripheralDeviceTypes.MultiMediaDevice
                                              ? Modes.PrettifyModePage_01_MMC(page.value)
                                              : Modes.PrettifyModePage_01(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x02:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_02(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x03:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_03(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x04:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_04(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x05:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_05(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x06:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_06(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x07:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h",
                                      deviceType == PeripheralDeviceTypes.MultiMediaDevice
                                              ? Modes.PrettifyModePage_07_MMC(page.value)
                                              : Modes.PrettifyModePage_07(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x08:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_08(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0A:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0A(page.value));
                    }
                    else if (page.subpage == 1)
                    {
                        modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h",
                                      Modes.PrettifyModePage_0A_S01(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0B:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0B(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0D:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0D(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0E:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0E(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x0F:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0F(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x10:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h",
                                      deviceType == PeripheralDeviceTypes.SequentialAccess
                                              ? Modes.PrettifyModePage_10_SSC(page.value)
                                              : Modes.PrettifyModePage_10(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x11:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_11(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x12:
                case 0x13:
                case 0x14:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_12_13_14(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x1A:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1A(page.value));
                    }
                    else if (page.subpage == 1)
                    {
                        modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h",
                                      Modes.PrettifyModePage_1A_S01(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x1B:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1B(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x1C:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h",
                                      deviceType == PeripheralDeviceTypes.MultiMediaDevice
                                              ? Modes.PrettifyModePage_1C_SFF(page.value)
                                              : Modes.PrettifyModePage_1C(page.value));
                    }
                    else if (page.subpage == 1)
                    {
                        modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h",
                                      Modes.PrettifyModePage_1C_S01(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x1D:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1D(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x21:
                {
                    if (vendor == "CERTANCE")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyCertanceModePage_21(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x22:
                {
                    if (vendor == "CERTANCE")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyCertanceModePage_22(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x24:
                {
                    if (vendor == "IBM")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_24(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x2A:
                {
                    if (page.subpage == 0)
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_2A(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x2F:
                {
                    if (vendor == "IBM")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_2F(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x30:
                {
                    if (Modes.IsAppleModePage_30(page.value))
                    {
                        modePages.Add("MODE page 30h", "Drive identifies as an Apple OEM drive");
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x3B:
                {
                    if (vendor == "HP")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3B(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x3C:
                {
                    if (vendor == "HP")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3C(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x3D:
                {
                    if (vendor == "IBM")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_3D(page.value));
                    }
                    else if (vendor == "HP")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3D(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                case 0x3E:
                {
                    if (vendor == "FUJITSU")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyFujitsuModePage_3E(page.value));
                    }
                    else if (vendor == "HP")
                    {
                        modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3E(page.value));
                    }
                    else
                    {
                        goto default;
                    }

                    break;
                }

                default:
                {
                    modePages.Add(page.subpage != 0 ? $"MODE page {page.page:X2}h subpage {page.subpage:X2}h" : $"MODE page {page.page:X2}h",
                                  "Unknown mode page");
                }
                break;
                }
            }

            Dictionary <string, string> newModePages = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> kvp in modePages)
            {
                newModePages.Add(kvp.Key,
                                 string.IsNullOrWhiteSpace(kvp.Value) ? "Undecoded" : kvp.Value.Replace("\n", "<br/>"));
            }

            modePages = newModePages;
        }
Esempio n. 16
0
        public static void PrintImageInfo(IMediaImage imageFormat)
        {
            DicConsole.WriteLine("Image information:");
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Version))
            {
                DicConsole.WriteLine("Format: {0} version {1}", imageFormat.Format, imageFormat.Info.Version);
            }
            else
            {
                DicConsole.WriteLine("Format: {0}", imageFormat.Format);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Application) &&
                !string.IsNullOrWhiteSpace(imageFormat.Info.ApplicationVersion))
            {
                DicConsole.WriteLine("Was created with {0} version {1}", imageFormat.Info.Application,
                                     imageFormat.Info.ApplicationVersion);
            }
            else if (!string.IsNullOrWhiteSpace(imageFormat.Info.Application))
            {
                DicConsole.WriteLine("Was created with {0}", imageFormat.Info.Application);
            }
            DicConsole.WriteLine("Image without headers is {0} bytes long", imageFormat.Info.ImageSize);
            DicConsole.WriteLine("Contains a media of {0} sectors with a maximum sector size of {1} bytes (if all sectors are of the same size this would be {2} bytes)",
                                 imageFormat.Info.Sectors, imageFormat.Info.SectorSize,
                                 imageFormat.Info.Sectors * imageFormat.Info.SectorSize);
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Creator))
            {
                DicConsole.WriteLine("Created by: {0}", imageFormat.Info.Creator);
            }
            if (imageFormat.Info.CreationTime != DateTime.MinValue)
            {
                DicConsole.WriteLine("Created on {0}", imageFormat.Info.CreationTime);
            }
            if (imageFormat.Info.LastModificationTime != DateTime.MinValue)
            {
                DicConsole.WriteLine("Last modified on {0}", imageFormat.Info.LastModificationTime);
            }
            DicConsole.WriteLine("Contains a media of type {0} and XML type {1}", imageFormat.Info.MediaType,
                                 imageFormat.Info.XmlMediaType);
            DicConsole.WriteLine("{0} partitions", imageFormat.Info.HasPartitions ? "Has" : "Doesn't have");
            DicConsole.WriteLine("{0} sessions", imageFormat.Info.HasSessions ? "Has" : "Doesn't have");
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Comments))
            {
                DicConsole.WriteLine("Comments: {0}", imageFormat.Info.Comments);
            }
            if (imageFormat.Info.MediaSequence != 0 && imageFormat.Info.LastMediaSequence != 0)
            {
                DicConsole.WriteLine("Media is number {0} on a set of {1} medias", imageFormat.Info.MediaSequence,
                                     imageFormat.Info.LastMediaSequence);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaTitle))
            {
                DicConsole.WriteLine("Media title: {0}", imageFormat.Info.MediaTitle);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaManufacturer))
            {
                DicConsole.WriteLine("Media manufacturer: {0}", imageFormat.Info.MediaManufacturer);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaModel))
            {
                DicConsole.WriteLine("Media model: {0}", imageFormat.Info.MediaModel);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaSerialNumber))
            {
                DicConsole.WriteLine("Media serial number: {0}", imageFormat.Info.MediaSerialNumber);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaBarcode))
            {
                DicConsole.WriteLine("Media barcode: {0}", imageFormat.Info.MediaBarcode);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaPartNumber))
            {
                DicConsole.WriteLine("Media part number: {0}", imageFormat.Info.MediaPartNumber);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveManufacturer))
            {
                DicConsole.WriteLine("Drive manufacturer: {0}", imageFormat.Info.DriveManufacturer);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveModel))
            {
                DicConsole.WriteLine("Drive model: {0}", imageFormat.Info.DriveModel);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveSerialNumber))
            {
                DicConsole.WriteLine("Drive serial number: {0}", imageFormat.Info.DriveSerialNumber);
            }
            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveFirmwareRevision))
            {
                DicConsole.WriteLine("Drive firmware info: {0}", imageFormat.Info.DriveFirmwareRevision);
            }
            if (imageFormat.Info.Cylinders > 0 && imageFormat.Info.Heads > 0 &&
                imageFormat.Info.SectorsPerTrack > 0 &&
                imageFormat.Info.XmlMediaType != XmlMediaType.OpticalDisc)
            {
                DicConsole.WriteLine("Media geometry: {0} cylinders, {1} heads, {2} sectors per track",
                                     imageFormat.Info.Cylinders, imageFormat.Info.Heads,
                                     imageFormat.Info.SectorsPerTrack);
            }

            if (imageFormat.Info.ReadableMediaTags != null && imageFormat.Info.ReadableMediaTags.Count > 0)
            {
                DicConsole.WriteLine("Contains {0} readable media tags:", imageFormat.Info.ReadableMediaTags.Count);
                foreach (MediaTagType tag in imageFormat.Info.ReadableMediaTags.OrderBy(t => t))
                {
                    DicConsole.Write("{0} ", tag);
                }
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableSectorTags != null && imageFormat.Info.ReadableSectorTags.Count > 0)
            {
                DicConsole.WriteLine("Contains {0} readable sector tags:", imageFormat.Info.ReadableSectorTags.Count);
                foreach (SectorTagType tag in imageFormat.Info.ReadableSectorTags.OrderBy(t => t))
                {
                    DicConsole.Write("{0} ", tag);
                }
                DicConsole.WriteLine();
            }

            DicConsole.WriteLine();
            PeripheralDeviceTypes scsiDeviceType = PeripheralDeviceTypes.DirectAccess;

            byte[] scsiVendorId = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_INQUIRY))
            {
                byte[] inquiry = imageFormat.ReadDiskTag(MediaTagType.SCSI_INQUIRY);

                scsiDeviceType = (PeripheralDeviceTypes)(inquiry[0] & 0x1F);
                if (inquiry.Length >= 16)
                {
                    scsiVendorId = new byte[8];
                    Array.Copy(inquiry, 8, scsiVendorId, 0, 8);
                }

                DicConsole.WriteLine("SCSI INQUIRY contained in image:");
                DicConsole.Write("{0}", Inquiry.Prettify(inquiry));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATA_IDENTIFY))
            {
                byte[] identify = imageFormat.ReadDiskTag(MediaTagType.ATA_IDENTIFY);

                DicConsole.WriteLine("ATA IDENTIFY contained in image:");
                DicConsole.Write("{0}", Identify.Prettify(identify));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATAPI_IDENTIFY))
            {
                byte[] identify = imageFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY);

                DicConsole.WriteLine("ATAPI IDENTIFY contained in image:");
                DicConsole.Write("{0}", Identify.Prettify(identify));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODESENSE_10))
            {
                byte[]            modeSense10 = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODESENSE_10);
                Modes.DecodedMode?decMode     = Modes.DecodeMode10(modeSense10, scsiDeviceType);

                if (decMode.HasValue)
                {
                    DicConsole.WriteLine("SCSI MODE SENSE (10) contained in image:");
                    PrintScsiModePages.Print(decMode.Value, scsiDeviceType, scsiVendorId);
                    DicConsole.WriteLine();
                }
            }
            else if (imageFormat.Info.ReadableMediaTags != null &&
                     imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODESENSE_6))
            {
                byte[]            modeSense6 = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODESENSE_6);
                Modes.DecodedMode?decMode    = Modes.DecodeMode6(modeSense6, scsiDeviceType);

                if (decMode.HasValue)
                {
                    DicConsole.WriteLine("SCSI MODE SENSE (6) contained in image:");
                    PrintScsiModePages.Print(decMode.Value, scsiDeviceType, scsiVendorId);
                    DicConsole.WriteLine();
                }
            }
            else if (imageFormat.Info.ReadableMediaTags != null &&
                     imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODEPAGE_2A))
            {
                byte[] mode2A = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODEPAGE_2A);

                DicConsole.Write("{0}", Modes.PrettifyModePage_2A(mode2A));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_FullTOC))
            {
                byte[] toc = imageFormat.ReadDiskTag(MediaTagType.CD_FullTOC);

                if (toc.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(toc, 0));
                    if (dataLen + 2 != toc.Length)
                    {
                        byte[] tmp = new byte[toc.Length + 2];
                        Array.Copy(toc, 0, tmp, 2, toc.Length);
                        tmp[0] = (byte)((toc.Length & 0xFF00) >> 8);
                        tmp[1] = (byte)(toc.Length & 0xFF);
                        toc    = tmp;
                    }

                    DicConsole.WriteLine("CompactDisc Table of Contents contained in image:");
                    DicConsole.Write("{0}", FullTOC.Prettify(toc));
                    DicConsole.WriteLine();
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_PMA))
            {
                byte[] pma = imageFormat.ReadDiskTag(MediaTagType.CD_PMA);

                if (pma.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(pma, 0));
                    if (dataLen + 2 != pma.Length)
                    {
                        byte[] tmp = new byte[pma.Length + 2];
                        Array.Copy(pma, 0, tmp, 2, pma.Length);
                        tmp[0] = (byte)((pma.Length & 0xFF00) >> 8);
                        tmp[1] = (byte)(pma.Length & 0xFF);
                        pma    = tmp;
                    }

                    DicConsole.WriteLine("CompactDisc Power Management Area contained in image:");
                    DicConsole.Write("{0}", PMA.Prettify(pma));
                    DicConsole.WriteLine();
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_ATIP))
            {
                byte[] atip = imageFormat.ReadDiskTag(MediaTagType.CD_ATIP);

                uint dataLen = Swapping.Swap(BitConverter.ToUInt32(atip, 0));
                if (dataLen + 4 != atip.Length)
                {
                    byte[] tmp = new byte[atip.Length + 4];
                    Array.Copy(atip, 0, tmp, 4, atip.Length);
                    tmp[0] = (byte)((atip.Length & 0xFF000000) >> 24);
                    tmp[1] = (byte)((atip.Length & 0xFF0000) >> 16);
                    tmp[2] = (byte)((atip.Length & 0xFF00) >> 8);
                    tmp[3] = (byte)(atip.Length & 0xFF);
                    atip   = tmp;
                }

                DicConsole.WriteLine("CompactDisc Absolute Time In Pregroove (ATIP) contained in image:");
                DicConsole.Write("{0}", ATIP.Prettify(atip));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_TEXT))
            {
                byte[] cdtext = imageFormat.ReadDiskTag(MediaTagType.CD_TEXT);

                uint dataLen = Swapping.Swap(BitConverter.ToUInt32(cdtext, 0));
                if (dataLen + 4 != cdtext.Length)
                {
                    byte[] tmp = new byte[cdtext.Length + 4];
                    Array.Copy(cdtext, 0, tmp, 4, cdtext.Length);
                    tmp[0] = (byte)((cdtext.Length & 0xFF000000) >> 24);
                    tmp[1] = (byte)((cdtext.Length & 0xFF0000) >> 16);
                    tmp[2] = (byte)((cdtext.Length & 0xFF00) >> 8);
                    tmp[3] = (byte)(cdtext.Length & 0xFF);
                    cdtext = tmp;
                }

                DicConsole.WriteLine("CompactDisc Lead-in's CD-Text contained in image:");
                DicConsole.Write("{0}", CDTextOnLeadIn.Prettify(cdtext));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_MCN))
            {
                byte[] mcn = imageFormat.ReadDiskTag(MediaTagType.CD_MCN);

                DicConsole.WriteLine("CompactDisc Media Catalogue Number contained in image: {0}",
                                     Encoding.UTF8.GetString(mcn));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_PFI))
            {
                byte[] pfi = imageFormat.ReadDiskTag(MediaTagType.DVD_PFI);

                DicConsole.WriteLine("DVD Physical Format Information contained in image:");
                DicConsole.Write("{0}", PFI.Prettify(pfi));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_DDS))
            {
                byte[] dds = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_DDS);

                DicConsole.WriteLine("DVD-RAM Disc Definition Structure contained in image:");
                DicConsole.Write("{0}", DDS.Prettify(dds));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_PFI))
            {
                byte[] pfi = imageFormat.ReadDiskTag(MediaTagType.DVDR_PFI);

                DicConsole.WriteLine("DVD-R Physical Format Information contained in image:");
                DicConsole.Write("{0}", PFI.Prettify(pfi));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_DI))
            {
                byte[] di = imageFormat.ReadDiskTag(MediaTagType.BD_DI);

                DicConsole.WriteLine("Bluray Disc Information contained in image:");
                DicConsole.Write("{0}", DI.Prettify(di));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_DDS))
            {
                byte[] dds = imageFormat.ReadDiskTag(MediaTagType.BD_DDS);

                DicConsole.WriteLine("Bluray Disc Definition Structure contained in image:");
                DicConsole.Write("{0}", Decoders.Bluray.DDS.Prettify(dds));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.PCMCIA_CIS))
            {
                byte[] cis = imageFormat.ReadDiskTag(MediaTagType.PCMCIA_CIS);

                DicConsole.WriteLine("PCMCIA CIS:");
                Tuple[] tuples = CIS.GetTuples(cis);
                if (tuples != null)
                {
                    foreach (Tuple tuple in tuples)
                    {
                        switch (tuple.Code)
                        {
                        case TupleCodes.CISTPL_NULL:
                        case TupleCodes.CISTPL_END: break;

                        case TupleCodes.CISTPL_DEVICEGEO:
                        case TupleCodes.CISTPL_DEVICEGEO_A:
                            DicConsole.WriteLine("{0}", CIS.PrettifyDeviceGeometryTuple(tuple));
                            break;

                        case TupleCodes.CISTPL_MANFID:
                            DicConsole.WriteLine("{0}", CIS.PrettifyManufacturerIdentificationTuple(tuple));
                            break;

                        case TupleCodes.CISTPL_VERS_1:
                            DicConsole.WriteLine("{0}", CIS.PrettifyLevel1VersionTuple(tuple));
                            break;

                        case TupleCodes.CISTPL_ALTSTR:
                        case TupleCodes.CISTPL_BAR:
                        case TupleCodes.CISTPL_BATTERY:
                        case TupleCodes.CISTPL_BYTEORDER:
                        case TupleCodes.CISTPL_CFTABLE_ENTRY:
                        case TupleCodes.CISTPL_CFTABLE_ENTRY_CB:
                        case TupleCodes.CISTPL_CHECKSUM:
                        case TupleCodes.CISTPL_CONFIG:
                        case TupleCodes.CISTPL_CONFIG_CB:
                        case TupleCodes.CISTPL_DATE:
                        case TupleCodes.CISTPL_DEVICE:
                        case TupleCodes.CISTPL_DEVICE_A:
                        case TupleCodes.CISTPL_DEVICE_OA:
                        case TupleCodes.CISTPL_DEVICE_OC:
                        case TupleCodes.CISTPL_EXTDEVIC:
                        case TupleCodes.CISTPL_FORMAT:
                        case TupleCodes.CISTPL_FORMAT_A:
                        case TupleCodes.CISTPL_FUNCE:
                        case TupleCodes.CISTPL_FUNCID:
                        case TupleCodes.CISTPL_GEOMETRY:
                        case TupleCodes.CISTPL_INDIRECT:
                        case TupleCodes.CISTPL_JEDEC_A:
                        case TupleCodes.CISTPL_JEDEC_C:
                        case TupleCodes.CISTPL_LINKTARGET:
                        case TupleCodes.CISTPL_LONGLINK_A:
                        case TupleCodes.CISTPL_LONGLINK_C:
                        case TupleCodes.CISTPL_LONGLINK_CB:
                        case TupleCodes.CISTPL_LONGLINK_MFC:
                        case TupleCodes.CISTPL_NO_LINK:
                        case TupleCodes.CISTPL_ORG:
                        case TupleCodes.CISTPL_PWR_MGMNT:
                        case TupleCodes.CISTPL_SPCL:
                        case TupleCodes.CISTPL_SWIL:
                        case TupleCodes.CISTPL_VERS_2:
                            DicConsole.DebugWriteLine("Device-Info command", "Found undecoded tuple ID {0}",
                                                      tuple.Code);
                            break;

                        default:
                            DicConsole.DebugWriteLine("Device-Info command", "Found unknown tuple ID 0x{0:X2}",
                                                      (byte)tuple.Code);
                            break;
                        }
                    }
                }
                else
                {
                    DicConsole.DebugWriteLine("Device-Info command", "Could not get tuples");
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_CID))
            {
                byte[] cid = imageFormat.ReadDiskTag(MediaTagType.SD_CID);

                DicConsole.WriteLine("SecureDigital CID contained in image:");
                DicConsole.Write("{0}", Decoders.SecureDigital.Decoders.PrettifyCID(cid));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_CSD))
            {
                byte[] csd = imageFormat.ReadDiskTag(MediaTagType.SD_CSD);

                DicConsole.WriteLine("SecureDigital CSD contained in image:");
                DicConsole.Write("{0}", Decoders.SecureDigital.Decoders.PrettifyCSD(csd));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_SCR))
            {
                byte[] scr = imageFormat.ReadDiskTag(MediaTagType.SD_SCR);

                DicConsole.WriteLine("SecureDigital SCR contained in image:");
                DicConsole.Write("{0}", Decoders.SecureDigital.Decoders.PrettifySCR(scr));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_OCR))
            {
                byte[] ocr = imageFormat.ReadDiskTag(MediaTagType.SD_OCR);

                DicConsole.WriteLine("SecureDigital OCR contained in image:");
                DicConsole.Write("{0}", Decoders.SecureDigital.Decoders.PrettifyOCR(ocr));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_CID))
            {
                byte[] cid = imageFormat.ReadDiskTag(MediaTagType.MMC_CID);

                DicConsole.WriteLine("MultiMediaCard CID contained in image:");
                DicConsole.Write("{0}", Decoders.MMC.Decoders.PrettifyCID(cid));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_CSD))
            {
                byte[] csd = imageFormat.ReadDiskTag(MediaTagType.MMC_CSD);

                DicConsole.WriteLine("MultiMediaCard CSD contained in image:");
                DicConsole.Write("{0}", Decoders.MMC.Decoders.PrettifyCSD(csd));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_ExtendedCSD))
            {
                byte[] ecsd = imageFormat.ReadDiskTag(MediaTagType.MMC_ExtendedCSD);

                DicConsole.WriteLine("MultiMediaCard ExtendedCSD contained in image:");
                DicConsole.Write("{0}", Decoders.MMC.Decoders.PrettifyExtendedCSD(ecsd));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_OCR))
            {
                byte[] ocr = imageFormat.ReadDiskTag(MediaTagType.MMC_OCR);

                DicConsole.WriteLine("MultiMediaCard OCR contained in image:");
                DicConsole.Write("{0}", Decoders.MMC.Decoders.PrettifyOCR(ocr));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_PFI))
            {
                byte[] xpfi = imageFormat.ReadDiskTag(MediaTagType.Xbox_PFI);

                DicConsole.WriteLine("Xbox Physical Format Information contained in image:");
                DicConsole.Write("{0}", PFI.Prettify(xpfi));
                DicConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_DMI))
            {
                byte[] xdmi = imageFormat.ReadDiskTag(MediaTagType.Xbox_DMI);

                if (DMI.IsXbox(xdmi))
                {
                    DMI.XboxDMI?xmi = DMI.DecodeXbox(xdmi);
                    if (xmi.HasValue)
                    {
                        DicConsole.WriteLine("Xbox DMI contained in image:");
                        DicConsole.Write("{0}", DMI.PrettifyXbox(xmi));
                        DicConsole.WriteLine();
                    }
                }

                if (DMI.IsXbox360(xdmi))
                {
                    DMI.Xbox360DMI?xmi = DMI.DecodeXbox360(xdmi);
                    if (xmi.HasValue)
                    {
                        DicConsole.WriteLine("Xbox 360 DMI contained in image:");
                        DicConsole.Write("{0}", DMI.PrettifyXbox360(xmi));
                        DicConsole.WriteLine();
                    }
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_SecuritySector))
            {
                byte[] toc = imageFormat.ReadDiskTag(MediaTagType.Xbox_SecuritySector);

                DicConsole.WriteLine("Xbox Security Sectors contained in image:");
                DicConsole.Write("{0}", SS.Prettify(toc));
                DicConsole.WriteLine();
            }

            try
            {
                if (imageFormat.Sessions != null && imageFormat.Sessions.Count > 0)
                {
                    DicConsole.WriteLine("Image sessions:");
                    DicConsole.WriteLine("{0,-9}{1,-13}{2,-12}{3,-12}{4,-12}", "Session", "First track", "Last track",
                                         "Start", "End");
                    DicConsole.WriteLine("=========================================================");
                    foreach (Session session in imageFormat.Sessions)
                    {
                        DicConsole.WriteLine("{0,-9}{1,-13}{2,-12}{3,-12}{4,-12}", session.SessionSequence,
                                             session.StartTrack, session.EndTrack, session.StartSector,
                                             session.EndSector);
                    }
                    DicConsole.WriteLine();
                }
            }
            catch
            {
                // ignored
            }

            try
            {
                if (imageFormat.Tracks != null && imageFormat.Tracks.Count > 0)
                {
                    DicConsole.WriteLine("Image tracks:");
                    DicConsole.WriteLine("{0,-7}{1,-17}{2,-6}{3,-8}{4,-12}{5,-8}{6,-12}{7,-12}", "Track", "Type", "Bps",
                                         "Raw bps", "Subchannel", "Pregap", "Start", "End");
                    DicConsole
                    .WriteLine("=================================================================================");
                    foreach (Track track in imageFormat.Tracks)
                    {
                        DicConsole.WriteLine("{0,-7}{1,-17}{2,-6}{3,-8}{4,-12}{5,-8}{6,-12}{7,-12}",
                                             track.TrackSequence, track.TrackType, track.TrackBytesPerSector,
                                             track.TrackRawBytesPerSector, track.TrackSubchannelType, track.TrackPregap,
                                             track.TrackStartSector, track.TrackEndSector);
                    }
                    DicConsole.WriteLine();
                }
            }
            catch
            {
                // ignored
            }

            if (imageFormat.DumpHardware == null)
            {
                return;
            }

            const string MANUFACTURER_STRING = "Manufacturer";
            const string MODEL_STRING        = "Model";
            const string SERIAL_STRING       = "Serial";
            const string SOFTWARE_STRING     = "Software";
            const string VERSION_STRING      = "Version";
            const string OS_STRING           = "Operating system";
            const string START_STRING        = "Start";
            const string END_STRING          = "End";
            int          manufacturerLen     = MANUFACTURER_STRING.Length;
            int          modelLen            = MODEL_STRING.Length;
            int          serialLen           = SERIAL_STRING.Length;
            int          softwareLen         = SOFTWARE_STRING.Length;
            int          versionLen          = VERSION_STRING.Length;
            int          osLen     = OS_STRING.Length;
            int          sectorLen = START_STRING.Length;

            foreach (DumpHardwareType dump in imageFormat.DumpHardware)
            {
                if (dump.Manufacturer?.Length > manufacturerLen)
                {
                    manufacturerLen = dump.Manufacturer.Length;
                }
                if (dump.Model?.Length > modelLen)
                {
                    modelLen = dump.Model.Length;
                }
                if (dump.Serial?.Length > serialLen)
                {
                    serialLen = dump.Serial.Length;
                }
                if (dump.Software?.Name?.Length > softwareLen)
                {
                    softwareLen = dump.Software.Name.Length;
                }
                if (dump.Software?.Version?.Length > versionLen)
                {
                    versionLen = dump.Software.Version.Length;
                }
                if (dump.Software?.OperatingSystem?.Length > osLen)
                {
                    osLen = dump.Software.OperatingSystem.Length;
                }
                foreach (ExtentType extent in dump.Extents)
                {
                    if ($"{extent.Start}".Length > sectorLen)
                    {
                        sectorLen = $"{extent.Start}".Length;
                    }
                    if ($"{extent.End}".Length > sectorLen)
                    {
                        sectorLen = $"{extent.End}".Length;
                    }
                }
            }

            manufacturerLen += 2;
            modelLen        += 2;
            serialLen       += 2;
            softwareLen     += 2;
            versionLen      += 2;
            osLen           += 2;
            sectorLen       += 2;
            sectorLen       += 2;

            char[] separator = new char[manufacturerLen + modelLen + serialLen + softwareLen + versionLen + osLen +
                                        sectorLen + sectorLen];
            for (int i = 0; i < separator.Length; i++)
            {
                separator[i] = '=';
            }
            string format =
                $"{{0,-{manufacturerLen}}}{{1,-{modelLen}}}{{2,-{serialLen}}}{{3,-{softwareLen}}}{{4,-{versionLen}}}{{5,-{osLen}}}{{6,-{sectorLen}}}{{7,-{sectorLen}}}";

            DicConsole.WriteLine("Dump hardware information:");
            DicConsole.WriteLine(format, MANUFACTURER_STRING, MODEL_STRING, SERIAL_STRING, SOFTWARE_STRING,
                                 VERSION_STRING, OS_STRING, START_STRING, END_STRING);
            DicConsole.WriteLine(new string(separator));
            foreach (DumpHardwareType dump in imageFormat.DumpHardware)
            {
                foreach (ExtentType extent in dump.Extents)
                {
                    DicConsole.WriteLine(format, dump.Manufacturer, dump.Model, dump.Serial, dump.Software.Name,
                                         dump.Software.Version, dump.Software.OperatingSystem, extent.Start,
                                         extent.End);
                }
            }

            DicConsole.WriteLine();
        }
Esempio n. 17
0
        public pnlImageInfo(string imagePath, IFilter filter, IMediaImage imageFormat)
        {
            this.imagePath   = imagePath;
            this.filter      = filter;
            this.imageFormat = imageFormat;
            XamlReader.Load(this);

            Stream logo =
                ResourceHandler
                .GetResourceStream($"DiscImageChef.Gui.Assets.Logos.Media.{imageFormat.Info.MediaType}.svg");

            /*            if(logo != null)
             *          {
             *              svgMediaLogo.SvgStream = logo;
             *              svgMediaLogo.Visible   = true;
             *          }
             *          else
             *          {*/
            logo =
                ResourceHandler
                .GetResourceStream($"DiscImageChef.Gui.Assets.Logos.Media.{imageFormat.Info.MediaType}.png");
            if (logo != null)
            {
                imgMediaLogo.Image   = new Bitmap(logo);
                imgMediaLogo.Visible = true;
            }
            //}

            lblImagePath.Text   = $"Path: {imagePath}";
            lblFilter.Text      = $"Filter: {filter.Name}";
            lblImageFormat.Text = $"Image format identified by {imageFormat.Name} ({imageFormat.Id}).";
            lblImageFormat.Text = !string.IsNullOrWhiteSpace(imageFormat.Info.Version)
                                      ? $"Format: {imageFormat.Format} version {imageFormat.Info.Version}"
                                      : $"Format: {imageFormat.Format}";
            lblImageSize.Text = $"Image without headers is {imageFormat.Info.ImageSize} bytes long";
            lblSectors.Text   =
                $"Contains a media of {imageFormat.Info.Sectors} sectors with a maximum sector size of {imageFormat.Info.SectorSize} bytes (if all sectors are of the same size this would be {imageFormat.Info.Sectors * imageFormat.Info.SectorSize} bytes)";
            lblMediaType.Text =
                $"Contains a media of type {imageFormat.Info.MediaType} and XML type {imageFormat.Info.XmlMediaType}";
            lblHasPartitions.Text = $"{(imageFormat.Info.HasPartitions ? "Has" : "Doesn't have")} partitions";
            lblHasSessions.Text   = $"{(imageFormat.Info.HasSessions ? "Has" : "Doesn't have")} sessions";

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Application))
            {
                lblApplication.Visible = true;
                lblApplication.Text    = !string.IsNullOrWhiteSpace(imageFormat.Info.ApplicationVersion)
                                          ? $"Was created with {imageFormat.Info.Application} version {imageFormat.Info.ApplicationVersion}"
                                          : $"Was created with {imageFormat.Info.Application}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Creator))
            {
                lblCreator.Visible = true;
                lblCreator.Text    = $"Created by: {imageFormat.Info.Creator}";
            }

            if (imageFormat.Info.CreationTime != DateTime.MinValue)
            {
                lblCreationTime.Visible = true;
                lblCreationTime.Text    = $"Created on {imageFormat.Info.CreationTime}";
            }

            if (imageFormat.Info.LastModificationTime != DateTime.MinValue)
            {
                lblLastModificationTime.Visible = true;
                lblLastModificationTime.Text    = $"Last modified on {imageFormat.Info.LastModificationTime}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Comments))
            {
                grpComments.Visible = true;
                txtComments.Text    = imageFormat.Info.Comments;
            }

            if (imageFormat.Info.MediaSequence != 0 && imageFormat.Info.LastMediaSequence != 0)
            {
                lblMediaSequence.Visible = true;
                lblMediaSequence.Text    =
                    $"Media is number {imageFormat.Info.MediaSequence} on a set of {imageFormat.Info.LastMediaSequence} medias";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaTitle))
            {
                lblMediaTitle.Visible = true;
                lblMediaTitle.Text    = $"Media title: {imageFormat.Info.MediaTitle}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaManufacturer))
            {
                lblMediaManufacturer.Visible = true;
                lblMediaManufacturer.Text    = $"Media manufacturer: {imageFormat.Info.MediaManufacturer}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaModel))
            {
                lblMediaModel.Visible = true;
                lblMediaModel.Text    = $"Media model: {imageFormat.Info.MediaModel}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaSerialNumber))
            {
                lblMediaSerialNumber.Visible = true;
                lblMediaSerialNumber.Text    = $"Media serial number: {imageFormat.Info.MediaSerialNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaBarcode))
            {
                lblMediaBarcode.Visible = true;
                lblMediaBarcode.Text    = $"Media barcode: {imageFormat.Info.MediaBarcode}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaPartNumber))
            {
                lblMediaPartNumber.Visible = true;
                lblMediaPartNumber.Text    = $"Media part number: {imageFormat.Info.MediaPartNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveManufacturer))
            {
                lblDriveManufacturer.Visible = true;
                lblDriveManufacturer.Text    = $"Drive manufacturer: {imageFormat.Info.DriveManufacturer}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveModel))
            {
                lblDriveModel.Visible = true;
                lblDriveModel.Text    = $"Drive model: {imageFormat.Info.DriveModel}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveSerialNumber))
            {
                lblDriveSerialNumber.Visible = true;
                lblDriveSerialNumber.Text    = $"Drive serial number: {imageFormat.Info.DriveSerialNumber}";
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveFirmwareRevision))
            {
                lblDriveFirmwareRevision.Visible = true;
                lblDriveFirmwareRevision.Text    = $"Drive firmware info: {imageFormat.Info.DriveFirmwareRevision}";
            }

            if (imageFormat.Info.Cylinders > 0 && imageFormat.Info.Heads > 0 &&
                imageFormat.Info.SectorsPerTrack > 0 &&
                imageFormat.Info.XmlMediaType != XmlMediaType.OpticalDisc &&
                (!(imageFormat is ITapeImage tapeImage) || !tapeImage.IsTape))
            {
                lblMediaGeometry.Visible = true;
                lblMediaGeometry.Text    =
                    $"Media geometry: {imageFormat.Info.Cylinders} cylinders, {imageFormat.Info.Heads} heads, {imageFormat.Info.SectorsPerTrack} sectors per track";
            }

            grpMediaInfo.Visible = lblMediaSequence.Visible || lblMediaTitle.Visible ||
                                   lblMediaManufacturer.Visible ||
                                   lblMediaModel.Visible || lblMediaSerialNumber.Visible ||
                                   lblMediaBarcode.Visible ||
                                   lblMediaPartNumber.Visible;
            grpDriveInfo.Visible = lblDriveManufacturer.Visible || lblDriveModel.Visible ||
                                   lblDriveSerialNumber.Visible || lblDriveFirmwareRevision.Visible ||
                                   lblMediaGeometry.Visible;

            if (imageFormat.Info.ReadableMediaTags != null && imageFormat.Info.ReadableMediaTags.Count > 0)
            {
                TreeGridItemCollection mediaTagList = new TreeGridItemCollection();

                treeMediaTags.Columns.Add(new GridColumn {
                    HeaderText = "Tag", DataCell = new TextBoxCell(0)
                });

                treeMediaTags.AllowMultipleSelection = false;
                treeMediaTags.ShowHeader             = false;
                treeMediaTags.DataStore = mediaTagList;

                foreach (MediaTagType tag in imageFormat.Info.ReadableMediaTags.OrderBy(t => t))
                {
                    mediaTagList.Add(new TreeGridItem {
                        Values = new object[] { tag.ToString() }
                    });
                }

                grpMediaTags.Visible = true;
            }

            if (imageFormat.Info.ReadableSectorTags != null && imageFormat.Info.ReadableSectorTags.Count > 0)
            {
                TreeGridItemCollection sectorTagList = new TreeGridItemCollection();

                treeSectorTags.Columns.Add(new GridColumn {
                    HeaderText = "Tag", DataCell = new TextBoxCell(0)
                });

                treeSectorTags.AllowMultipleSelection = false;
                treeSectorTags.ShowHeader             = false;
                treeSectorTags.DataStore = sectorTagList;

                foreach (SectorTagType tag in imageFormat.Info.ReadableSectorTags.OrderBy(t => t))
                {
                    sectorTagList.Add(new TreeGridItem {
                        Values = new object[] { tag.ToString() }
                    });
                }

                grpSectorTags.Visible = true;
            }

            PeripheralDeviceTypes scsiDeviceType = PeripheralDeviceTypes.DirectAccess;

            byte[] scsiInquiryData          = null;
            Inquiry.SCSIInquiry?scsiInquiry = null;
            Modes.DecodedMode?  scsiMode    = null;
            byte[] scsiModeSense6           = null;
            byte[] scsiModeSense10          = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_INQUIRY))
            {
                scsiInquiryData = imageFormat.ReadDiskTag(MediaTagType.SCSI_INQUIRY);

                scsiDeviceType = (PeripheralDeviceTypes)(scsiInquiryData[0] & 0x1F);

                scsiInquiry = Inquiry.Decode(scsiInquiryData);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODESENSE_6))
            {
                scsiModeSense6 = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODESENSE_6);
                scsiMode       = Modes.DecodeMode6(scsiModeSense6, scsiDeviceType);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SCSI_MODESENSE_10))
            {
                scsiModeSense10 = imageFormat.ReadDiskTag(MediaTagType.SCSI_MODESENSE_10);
                scsiMode        = Modes.DecodeMode10(scsiModeSense10, scsiDeviceType);
            }

            tabScsiInfo tabScsiInfo = new tabScsiInfo();

            tabScsiInfo.LoadData(scsiInquiryData, scsiInquiry, null, scsiMode, scsiDeviceType, scsiModeSense6,
                                 scsiModeSense10, null);
            tabInfos.Pages.Add(tabScsiInfo);

            byte[] ataIdentify   = null;
            byte[] atapiIdentify = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATA_IDENTIFY))
            {
                ataIdentify = imageFormat.ReadDiskTag(MediaTagType.ATA_IDENTIFY);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.ATAPI_IDENTIFY))
            {
                atapiIdentify = imageFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY);
            }

            tabAtaInfo tabAtaInfo = new tabAtaInfo();

            tabAtaInfo.LoadData(ataIdentify, atapiIdentify, null);
            tabInfos.Pages.Add(tabAtaInfo);

            byte[]                toc                  = null;
            TOC.CDTOC?            decodedToc           = null;
            byte[]                fullToc              = null;
            FullTOC.CDFullTOC?    decodedFullToc       = null;
            byte[]                pma                  = null;
            byte[]                atip                 = null;
            ATIP.CDATIP?          decodedAtip          = null;
            byte[]                cdtext               = null;
            CDTextOnLeadIn.CDText?decodedCdText        = null;
            string                mediaCatalogueNumber = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_TOC))
            {
                toc = imageFormat.ReadDiskTag(MediaTagType.CD_TOC);

                if (toc.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(toc, 0));
                    if (dataLen + 2 != toc.Length)
                    {
                        byte[] tmp = new byte[toc.Length + 2];
                        Array.Copy(toc, 0, tmp, 2, toc.Length);
                        tmp[0] = (byte)((toc.Length & 0xFF00) >> 8);
                        tmp[1] = (byte)(toc.Length & 0xFF);
                        toc    = tmp;
                    }

                    decodedToc = TOC.Decode(toc);
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_FullTOC))
            {
                fullToc = imageFormat.ReadDiskTag(MediaTagType.CD_FullTOC);

                if (fullToc.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(fullToc, 0));
                    if (dataLen + 2 != fullToc.Length)
                    {
                        byte[] tmp = new byte[fullToc.Length + 2];
                        Array.Copy(fullToc, 0, tmp, 2, fullToc.Length);
                        tmp[0]  = (byte)((fullToc.Length & 0xFF00) >> 8);
                        tmp[1]  = (byte)(fullToc.Length & 0xFF);
                        fullToc = tmp;
                    }

                    decodedFullToc = FullTOC.Decode(fullToc);
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_PMA))
            {
                pma = imageFormat.ReadDiskTag(MediaTagType.CD_PMA);

                if (pma.Length > 0)
                {
                    ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(pma, 0));
                    if (dataLen + 2 != pma.Length)
                    {
                        byte[] tmp = new byte[pma.Length + 2];
                        Array.Copy(pma, 0, tmp, 2, pma.Length);
                        tmp[0] = (byte)((pma.Length & 0xFF00) >> 8);
                        tmp[1] = (byte)(pma.Length & 0xFF);
                        pma    = tmp;
                    }
                }
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_ATIP))
            {
                atip = imageFormat.ReadDiskTag(MediaTagType.CD_ATIP);

                uint dataLen = Swapping.Swap(BitConverter.ToUInt32(atip, 0));
                if (dataLen + 4 != atip.Length)
                {
                    byte[] tmp = new byte[atip.Length + 4];
                    Array.Copy(atip, 0, tmp, 4, atip.Length);
                    tmp[0] = (byte)((atip.Length & 0xFF000000) >> 24);
                    tmp[1] = (byte)((atip.Length & 0xFF0000) >> 16);
                    tmp[2] = (byte)((atip.Length & 0xFF00) >> 8);
                    tmp[3] = (byte)(atip.Length & 0xFF);
                    atip   = tmp;
                }

                decodedAtip = ATIP.Decode(atip);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_TEXT))
            {
                cdtext = imageFormat.ReadDiskTag(MediaTagType.CD_TEXT);

                uint dataLen = Swapping.Swap(BitConverter.ToUInt32(cdtext, 0));
                if (dataLen + 4 != cdtext.Length)
                {
                    byte[] tmp = new byte[cdtext.Length + 4];
                    Array.Copy(cdtext, 0, tmp, 4, cdtext.Length);
                    tmp[0] = (byte)((cdtext.Length & 0xFF000000) >> 24);
                    tmp[1] = (byte)((cdtext.Length & 0xFF0000) >> 16);
                    tmp[2] = (byte)((cdtext.Length & 0xFF00) >> 8);
                    tmp[3] = (byte)(cdtext.Length & 0xFF);
                    cdtext = tmp;
                }

                decodedCdText = CDTextOnLeadIn.Decode(cdtext);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.CD_MCN))
            {
                byte[] mcn = imageFormat.ReadDiskTag(MediaTagType.CD_MCN);

                mediaCatalogueNumber = Encoding.UTF8.GetString(mcn);
            }

            tabCompactDiscInfo tabCompactDiscInfo = new tabCompactDiscInfo();

            tabCompactDiscInfo.LoadData(toc, atip, null, null, fullToc, pma, cdtext, decodedToc, decodedAtip, null,
                                        decodedFullToc, decodedCdText, null, mediaCatalogueNumber, null);
            tabInfos.Pages.Add(tabCompactDiscInfo);

            byte[] dvdPfi = null;
            byte[] dvdDmi = null;
            byte[] dvdCmi = null;
            byte[] hddvdCopyrightInformation = null;
            byte[] dvdBca = null;
            PFI.PhysicalFormatInformation?decodedPfi = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_PFI))
            {
                dvdPfi     = imageFormat.ReadDiskTag(MediaTagType.DVD_PFI);
                decodedPfi = PFI.Decode(dvdPfi);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_DMI))
            {
                dvdDmi = imageFormat.ReadDiskTag(MediaTagType.DVD_DMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_CMI))
            {
                dvdCmi = imageFormat.ReadDiskTag(MediaTagType.DVD_CMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.HDDVD_CPI))
            {
                hddvdCopyrightInformation = imageFormat.ReadDiskTag(MediaTagType.HDDVD_CPI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_BCA))
            {
                dvdBca = imageFormat.ReadDiskTag(MediaTagType.DVD_BCA);
            }

            tabDvdInfo tabDvdInfo = new tabDvdInfo();

            tabDvdInfo.LoadData(imageFormat.Info.MediaType, dvdPfi, dvdDmi, dvdCmi, hddvdCopyrightInformation, dvdBca,
                                null, decodedPfi);
            tabInfos.Pages.Add(tabDvdInfo);

            byte[] dvdRamDds                     = null;
            byte[] dvdRamCartridgeStatus         = null;
            byte[] dvdRamSpareArea               = null;
            byte[] lastBorderOutRmd              = null;
            byte[] dvdPreRecordedInfo            = null;
            byte[] dvdrMediaIdentifier           = null;
            byte[] dvdrPhysicalInformation       = null;
            byte[] hddvdrMediumStatus            = null;
            byte[] dvdrLayerCapacity             = null;
            byte[] dvdrDlMiddleZoneStart         = null;
            byte[] dvdrDlJumpIntervalSize        = null;
            byte[] dvdrDlManualLayerJumpStartLba = null;
            byte[] dvdPlusAdip                   = null;
            byte[] dvdPlusDcb                    = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_DDS))
            {
                dvdRamDds = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_DDS);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_MediumStatus))
            {
                dvdRamCartridgeStatus = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_MediumStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDRAM_SpareArea))
            {
                dvdRamSpareArea = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_SpareArea);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_RMD))
            {
                lastBorderOutRmd = imageFormat.ReadDiskTag(MediaTagType.DVDR_RMD);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_PreRecordedInfo))
            {
                dvdPreRecordedInfo = imageFormat.ReadDiskTag(MediaTagType.DVDR_PreRecordedInfo);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_MediaIdentifier))
            {
                dvdrMediaIdentifier = imageFormat.ReadDiskTag(MediaTagType.DVDR_MediaIdentifier);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDR_PFI))
            {
                dvdrPhysicalInformation = imageFormat.ReadDiskTag(MediaTagType.DVDR_PFI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.HDDVD_MediumStatus))
            {
                hddvdrMediumStatus = imageFormat.ReadDiskTag(MediaTagType.HDDVD_MediumStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_LayerCapacity))
            {
                dvdrLayerCapacity = imageFormat.ReadDiskTag(MediaTagType.DVDDL_LayerCapacity);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_MiddleZoneAddress))
            {
                dvdrDlMiddleZoneStart = imageFormat.ReadDiskTag(MediaTagType.DVDDL_MiddleZoneAddress);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_JumpIntervalSize))
            {
                dvdrDlJumpIntervalSize = imageFormat.ReadDiskTag(MediaTagType.DVDDL_JumpIntervalSize);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVDDL_ManualLayerJumpLBA))
            {
                dvdrDlManualLayerJumpStartLba = imageFormat.ReadDiskTag(MediaTagType.DVDDL_ManualLayerJumpLBA);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DVD_ADIP))
            {
                dvdPlusAdip = imageFormat.ReadDiskTag(MediaTagType.DVD_ADIP);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.DCB))
            {
                dvdPlusDcb = imageFormat.ReadDiskTag(MediaTagType.DCB);
            }

            tabDvdWritableInfo tabDvdWritableInfo = new tabDvdWritableInfo();

            tabDvdWritableInfo.LoadData(imageFormat.Info.MediaType, dvdRamDds, dvdRamCartridgeStatus, dvdRamSpareArea,
                                        lastBorderOutRmd, dvdPreRecordedInfo, dvdrMediaIdentifier,
                                        dvdrPhysicalInformation, hddvdrMediumStatus, null, dvdrLayerCapacity,
                                        dvdrDlMiddleZoneStart, dvdrDlJumpIntervalSize, dvdrDlManualLayerJumpStartLba,
                                        null, dvdPlusAdip, dvdPlusDcb);
            tabInfos.Pages.Add(tabDvdWritableInfo);

            byte[] blurayBurstCuttingArea = null;
            byte[] blurayCartridgeStatus  = null;
            byte[] blurayDds                  = null;
            byte[] blurayDiscInformation      = null;
            byte[] blurayPowResources         = null;
            byte[] bluraySpareAreaInformation = null;
            byte[] blurayTrackResources       = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_BCA))
            {
                blurayBurstCuttingArea = imageFormat.ReadDiskTag(MediaTagType.BD_BCA);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_CartridgeStatus))
            {
                blurayCartridgeStatus = imageFormat.ReadDiskTag(MediaTagType.BD_CartridgeStatus);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_DDS))
            {
                blurayDds = imageFormat.ReadDiskTag(MediaTagType.BD_DDS);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_DI))
            {
                blurayDiscInformation = imageFormat.ReadDiskTag(MediaTagType.BD_DI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_POWResourcesInformation))
            {
                blurayPowResources = imageFormat.ReadDiskTag(MediaTagType.MMC_POWResourcesInformation);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.BD_SpareArea))
            {
                bluraySpareAreaInformation = imageFormat.ReadDiskTag(MediaTagType.BD_SpareArea);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_TrackResourcesInformation))
            {
                bluraySpareAreaInformation = imageFormat.ReadDiskTag(MediaTagType.MMC_TrackResourcesInformation);
            }

            tabBlurayInfo tabBlurayInfo = new tabBlurayInfo();

            tabBlurayInfo.LoadData(blurayDiscInformation, blurayBurstCuttingArea, blurayDds, blurayCartridgeStatus,
                                   bluraySpareAreaInformation, blurayPowResources, blurayTrackResources, null, null);
            tabInfos.Pages.Add(tabBlurayInfo);

            byte[]            xboxDmi                   = null;
            byte[]            xboxSecuritySector        = null;
            SS.SecuritySector?decodedXboxSecuritySector = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_DMI))
            {
                xboxDmi = imageFormat.ReadDiskTag(MediaTagType.Xbox_DMI);
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.Xbox_SecuritySector))
            {
                xboxSecuritySector        = imageFormat.ReadDiskTag(MediaTagType.Xbox_SecuritySector);
                decodedXboxSecuritySector = SS.Decode(xboxSecuritySector);
            }

            tabXboxInfo tabXboxInfo = new tabXboxInfo();

            tabXboxInfo.LoadData(null, xboxDmi, xboxSecuritySector, decodedXboxSecuritySector);
            tabInfos.Pages.Add(tabXboxInfo);

            byte[] pcmciaCis = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.PCMCIA_CIS))
            {
                pcmciaCis = imageFormat.ReadDiskTag(MediaTagType.PCMCIA_CIS);
            }

            tabPcmciaInfo tabPcmciaInfo = new tabPcmciaInfo();

            tabPcmciaInfo.LoadData(pcmciaCis);
            tabInfos.Pages.Add(tabPcmciaInfo);

            DeviceType deviceType = DeviceType.Unknown;

            byte[] cid         = null;
            byte[] csd         = null;
            byte[] ocr         = null;
            byte[] extendedCsd = null;
            byte[] scr         = null;

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_CID))
            {
                cid        = imageFormat.ReadDiskTag(MediaTagType.SD_CID);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_CSD))
            {
                csd        = imageFormat.ReadDiskTag(MediaTagType.SD_CSD);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_OCR))
            {
                ocr        = imageFormat.ReadDiskTag(MediaTagType.SD_OCR);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.SD_SCR))
            {
                scr        = imageFormat.ReadDiskTag(MediaTagType.SD_SCR);
                deviceType = DeviceType.SecureDigital;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_CID))
            {
                cid        = imageFormat.ReadDiskTag(MediaTagType.MMC_CID);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_CSD))
            {
                csd        = imageFormat.ReadDiskTag(MediaTagType.MMC_CSD);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_OCR))
            {
                ocr        = imageFormat.ReadDiskTag(MediaTagType.MMC_OCR);
                deviceType = DeviceType.MMC;
            }

            if (imageFormat.Info.ReadableMediaTags != null &&
                imageFormat.Info.ReadableMediaTags.Contains(MediaTagType.MMC_ExtendedCSD))
            {
                extendedCsd = imageFormat.ReadDiskTag(MediaTagType.MMC_ExtendedCSD);
                deviceType  = DeviceType.MMC;
            }

            tabSdMmcInfo tabSdMmcInfo = new tabSdMmcInfo();

            tabSdMmcInfo.LoadData(deviceType, cid, csd, ocr, extendedCsd, scr);
            tabInfos.Pages.Add(tabSdMmcInfo);

            if (imageFormat is IOpticalMediaImage opticalMediaImage)
            {
                try
                {
                    if (opticalMediaImage.Sessions != null && opticalMediaImage.Sessions.Count > 0)
                    {
                        TreeGridItemCollection sessionList = new TreeGridItemCollection();

                        treeSessions.Columns.Add(new GridColumn
                        {
                            HeaderText = "Session", DataCell = new TextBoxCell(0)
                        });
                        treeSessions.Columns.Add(new GridColumn
                        {
                            HeaderText = "First track", DataCell = new TextBoxCell(1)
                        });
                        treeSessions.Columns.Add(new GridColumn
                        {
                            HeaderText = "Last track", DataCell = new TextBoxCell(2)
                        });
                        treeSessions.Columns.Add(new GridColumn {
                            HeaderText = "Start", DataCell = new TextBoxCell(3)
                        });
                        treeSessions.Columns.Add(new GridColumn {
                            HeaderText = "End", DataCell = new TextBoxCell(4)
                        });

                        treeSessions.AllowMultipleSelection = false;
                        treeSessions.ShowHeader             = true;
                        treeSessions.DataStore = sessionList;

                        foreach (Session session in opticalMediaImage.Sessions)
                        {
                            sessionList.Add(new TreeGridItem
                            {
                                Values = new object[]
                                {
                                    session.SessionSequence, session.StartTrack,
                                    session.EndTrack, session.StartSector, session.EndSector
                                }
                            });
                        }

                        tabSessions.Visible = true;
                    }
                }
                catch
                {
                    // ignored
                }

                try
                {
                    if (opticalMediaImage.Tracks != null && opticalMediaImage.Tracks.Count > 0)
                    {
                        TreeGridItemCollection tracksList = new TreeGridItemCollection();

                        treeTracks.Columns.Add(new GridColumn {
                            HeaderText = "Track", DataCell = new TextBoxCell(0)
                        });
                        treeTracks.Columns.Add(new GridColumn {
                            HeaderText = "Type", DataCell = new TextBoxCell(1)
                        });
                        treeTracks.Columns.Add(new GridColumn {
                            HeaderText = "Bps", DataCell = new TextBoxCell(2)
                        });
                        treeTracks.Columns.Add(new GridColumn {
                            HeaderText = "Raw bps", DataCell = new TextBoxCell(3)
                        });
                        treeTracks.Columns.Add(new GridColumn
                        {
                            HeaderText = "Subchannel", DataCell = new TextBoxCell(4)
                        });
                        treeTracks.Columns.Add(new GridColumn {
                            HeaderText = "Pregap", DataCell = new TextBoxCell(5)
                        });
                        treeTracks.Columns.Add(new GridColumn {
                            HeaderText = "Start", DataCell = new TextBoxCell(6)
                        });
                        treeTracks.Columns.Add(new GridColumn {
                            HeaderText = "End", DataCell = new TextBoxCell(7)
                        });

                        treeTracks.AllowMultipleSelection = false;
                        treeTracks.ShowHeader             = true;
                        treeTracks.DataStore = tracksList;

                        foreach (Track track in opticalMediaImage.Tracks)
                        {
                            tracksList.Add(new TreeGridItem
                            {
                                Values = new object[]
                                {
                                    track.TrackSequence, track.TrackType,
                                    track.TrackBytesPerSector, track.TrackRawBytesPerSector,
                                    track.TrackSubchannelType, track.TrackPregap,
                                    track.TrackStartSector, track.TrackEndSector
                                }
                            });
                        }

                        tabTracks.Visible = true;
                    }
                }
                catch
                {
                    // ignored
                }
            }

            if (imageFormat.DumpHardware == null)
            {
                return;
            }

            TreeGridItemCollection dumpHardwareList = new TreeGridItemCollection();

            treeDumpHardware.Columns.Add(new GridColumn {
                HeaderText = "Manufacturer", DataCell = new TextBoxCell(0)
            });
            treeDumpHardware.Columns.Add(new GridColumn {
                HeaderText = "Model", DataCell = new TextBoxCell(1)
            });
            treeDumpHardware.Columns.Add(new GridColumn {
                HeaderText = "Serial", DataCell = new TextBoxCell(2)
            });
            treeDumpHardware.Columns.Add(new GridColumn {
                HeaderText = "Software", DataCell = new TextBoxCell(3)
            });
            treeDumpHardware.Columns.Add(new GridColumn {
                HeaderText = "Version", DataCell = new TextBoxCell(4)
            });
            treeDumpHardware.Columns.Add(new GridColumn
            {
                HeaderText = "Operating system", DataCell = new TextBoxCell(5)
            });
            treeDumpHardware.Columns.Add(new GridColumn {
                HeaderText = "Start", DataCell = new TextBoxCell(6)
            });
            treeDumpHardware.Columns.Add(new GridColumn {
                HeaderText = "End", DataCell = new TextBoxCell(7)
            });

            treeDumpHardware.AllowMultipleSelection = false;
            treeDumpHardware.ShowHeader             = true;
            treeDumpHardware.DataStore = dumpHardwareList;

            foreach (DumpHardwareType dump in imageFormat.DumpHardware)
            {
                foreach (ExtentType extent in dump.Extents)
                {
                    dumpHardwareList.Add(new TreeGridItem
                    {
                        Values = new object[]
                        {
                            dump.Manufacturer, dump.Model, dump.Serial, dump.Software.Name,
                            dump.Software.Version, dump.Software.OperatingSystem,
                            extent.Start, extent.End
                        }
                    });
                }
            }

            tabDumpHardware.Visible = true;
        }
Esempio n. 18
0
 public static string PrettifyModeHeader10(byte[] modeResponse, PeripheralDeviceTypes deviceType)
 {
     return(PrettifyModeHeader(DecodeModeHeader10(modeResponse, deviceType), deviceType));
 }
Esempio n. 19
0
        public DeviceInfo(Device dev)
        {
            Type                  = dev.Type;
            Manufacturer          = dev.Manufacturer;
            Model                 = dev.Model;
            Revision              = dev.Revision;
            Serial                = dev.Serial;
            ScsiType              = dev.ScsiType;
            IsRemovable           = dev.IsRemovable;
            IsUsb                 = dev.IsUsb;
            UsbVendorId           = dev.UsbVendorId;
            UsbProductId          = dev.UsbProductId;
            UsbDescriptors        = dev.UsbDescriptors;
            UsbManufacturerString = dev.UsbManufacturerString;
            UsbProductString      = dev.UsbProductString;
            UsbSerialString       = dev.UsbSerialString;
            IsFireWire            = dev.IsFireWire;
            FireWireGuid          = dev.FireWireGuid;
            FireWireModel         = dev.FireWireModel;
            FireWireModelName     = dev.FireWireModelName;
            FireWireVendor        = dev.FireWireVendor;
            FireWireVendorName    = dev.FireWireVendorName;
            IsCompactFlash        = dev.IsCompactFlash;
            IsPcmcia              = dev.IsPcmcia;
            Cis = dev.Cis;

            switch (dev.Type)
            {
            case DeviceType.ATA:
            {
                bool sense = dev.AtaIdentify(out byte[] ataBuf, out AtaErrorRegistersChs errorRegisters);

                if (sense)
                {
                    DicConsole.DebugWriteLine("Device-Info command", "STATUS = 0x{0:X2}", errorRegisters.Status);
                    DicConsole.DebugWriteLine("Device-Info command", "ERROR = 0x{0:X2}", errorRegisters.Error);
                    DicConsole.DebugWriteLine("Device-Info command", "NSECTOR = 0x{0:X2}",
                                              errorRegisters.SectorCount);
                    DicConsole.DebugWriteLine("Device-Info command", "SECTOR = 0x{0:X2}", errorRegisters.Sector);
                    DicConsole.DebugWriteLine("Device-Info command", "CYLHIGH = 0x{0:X2}",
                                              errorRegisters.CylinderHigh);
                    DicConsole.DebugWriteLine("Device-Info command", "CYLLOW = 0x{0:X2}",
                                              errorRegisters.CylinderLow);
                    DicConsole.DebugWriteLine("Device-Info command", "DEVICE = 0x{0:X2}",
                                              errorRegisters.DeviceHead);
                    DicConsole.DebugWriteLine("Device-Info command", "Error code = {0}", dev.LastError);
                    break;
                }

                if (dev.Error)
                {
                    DicConsole.ErrorWriteLine("Error {0} querying ATA IDENTIFY", dev.LastError);
                    break;
                }

                AtaIdentify = ataBuf;

                dev.EnableMediaCardPassThrough(out errorRegisters, dev.Timeout, out _);

                if (errorRegisters.Sector == 0xAA && errorRegisters.SectorCount == 0x55)
                {
                    AtaMcptError = errorRegisters;
                }

                break;
            }

            case DeviceType.ATAPI:
            {
                bool sense = dev.AtapiIdentify(out byte[] ataBuf, out AtaErrorRegistersChs errorRegisters);

                if (sense)
                {
                    DicConsole.DebugWriteLine("Device-Info command", "STATUS = 0x{0:X2}", errorRegisters.Status);
                    DicConsole.DebugWriteLine("Device-Info command", "ERROR = 0x{0:X2}", errorRegisters.Error);
                    DicConsole.DebugWriteLine("Device-Info command", "NSECTOR = 0x{0:X2}",
                                              errorRegisters.SectorCount);
                    DicConsole.DebugWriteLine("Device-Info command", "SECTOR = 0x{0:X2}", errorRegisters.Sector);
                    DicConsole.DebugWriteLine("Device-Info command", "CYLHIGH = 0x{0:X2}",
                                              errorRegisters.CylinderHigh);
                    DicConsole.DebugWriteLine("Device-Info command", "CYLLOW = 0x{0:X2}",
                                              errorRegisters.CylinderLow);
                    DicConsole.DebugWriteLine("Device-Info command", "DEVICE = 0x{0:X2}",
                                              errorRegisters.DeviceHead);
                    DicConsole.DebugWriteLine("Device-Info command", "Error code = {0}", dev.LastError);
                    break;
                }

                if (!dev.Error)
                {
                    AtapiIdentify = ataBuf;
                }
                else
                {
                    DicConsole.ErrorWriteLine("Error {0} querying ATA PACKET IDENTIFY", dev.LastError);
                }

                // ATAPI devices are also SCSI devices
                goto case DeviceType.SCSI;
            }

            case DeviceType.SCSI:
            {
                bool sense = dev.ScsiInquiry(out byte[] inqBuf, out byte[] senseBuf);

                if (sense)
                {
                    DicConsole.ErrorWriteLine("SCSI error:\n{0}", Sense.PrettifySense(senseBuf));
                    break;
                }

                ScsiInquiryData = inqBuf;
                ScsiInquiry     = Inquiry.Decode(inqBuf);

                sense = dev.ScsiInquiry(out inqBuf, out senseBuf, 0x00);

                if (!sense)
                {
                    ScsiEvpdPages = new Dictionary <byte, byte[]>();

                    byte[] pages = EVPD.DecodePage00(inqBuf);

                    if (pages != null)
                    {
                        foreach (byte page in pages)
                        {
                            sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page);
                            if (sense)
                            {
                                continue;
                            }

                            ScsiEvpdPages.Add(page, inqBuf);
                        }
                    }
                }

                PeripheralDeviceTypes devType = (PeripheralDeviceTypes)ScsiInquiry.Value.PeripheralDeviceType;

                sense = dev.ModeSense10(out byte[] modeBuf, out senseBuf, false, true,
                                        ScsiModeSensePageControl.Current, 0x3F, 0xFF, 5, out _);

                if (!sense && !dev.Error)
                {
                    ScsiModeSense10 = modeBuf;
                }

                if (sense || dev.Error)
                {
                    sense = dev.ModeSense10(out modeBuf, out senseBuf, false, true,
                                            ScsiModeSensePageControl.Current, 0x3F, 0x00, 5, out _);
                    if (!sense && !dev.Error)
                    {
                        ScsiModeSense10 = modeBuf;
                    }
                }

                if (!sense && !dev.Error)
                {
                    ScsiMode = Modes.DecodeMode10(modeBuf, devType);
                }

                bool useMode10 = !(sense || dev.Error || !ScsiMode.HasValue);

                sense = dev.ModeSense6(out modeBuf, out senseBuf, false, ScsiModeSensePageControl.Current, 0x3F,
                                       0xFF, 5, out _);

                if (!sense && !dev.Error)
                {
                    ScsiModeSense6 = modeBuf;
                }

                if (sense || dev.Error)
                {
                    sense = dev.ModeSense6(out modeBuf, out senseBuf, false, ScsiModeSensePageControl.Current, 0x3F,
                                           0x00, 5, out _);

                    if (!sense && !dev.Error)
                    {
                        ScsiModeSense6 = modeBuf;
                    }
                }

                if (sense || dev.Error)
                {
                    sense = dev.ModeSense(out modeBuf, out senseBuf, 5, out _);
                    if (!sense && !dev.Error)
                    {
                        ScsiModeSense6 = modeBuf;
                    }
                }

                if (!sense && !dev.Error && !useMode10)
                {
                    ScsiMode = Modes.DecodeMode6(modeBuf, devType);
                }

                switch (devType)
                {
                case PeripheralDeviceTypes.MultiMediaDevice:
                {
                    sense = dev.GetConfiguration(out byte[] confBuf, out senseBuf, dev.Timeout, out _);

                    if (!sense)
                    {
                        MmcConfiguration = confBuf;
                    }

                    // TODO: DVD drives respond correctly to BD status.
                    // While specification says if no medium is present
                    // it should inform all possible capabilities,
                    // testing drives show only supported media capabilities.

                    /*
                     * byte[] strBuf;
                     * sense = dev.ReadDiscStructure(out strBuf, out senseBuf, MmcDiscStructureMediaType.DVD, 0, 0, MmcDiscStructureFormat.CapabilityList, 0, dev.Timeout, out _);
                     *
                     * if (!sense)
                     * {
                     *  Decoders.SCSI.DiscStructureCapabilities.Capability[] caps = Decoders.SCSI.DiscStructureCapabilities.Decode(strBuf);
                     *  if (caps != null)
                     *  {
                     *      foreach (Decoders.SCSI.DiscStructureCapabilities.Capability cap in caps)
                     *      {
                     *          if (cap.SDS && cap.RDS)
                     *              DicConsole.WriteLine("Drive can READ/SEND DISC STRUCTURE format {0:X2}h", cap.FormatCode);
                     *          else if (cap.SDS)
                     *              DicConsole.WriteLine("Drive can SEND DISC STRUCTURE format {0:X2}h", cap.FormatCode);
                     *          else if (cap.RDS)
                     *              DicConsole.WriteLine("Drive can READ DISC STRUCTURE format {0:X2}h", cap.FormatCode);
                     *      }
                     *  }
                     * }
                     *
                     * sense = dev.ReadDiscStructure(out strBuf, out senseBuf, MmcDiscStructureMediaType.BD, 0, 0, MmcDiscStructureFormat.CapabilityList, 0, dev.Timeout, out _);
                     *
                     * if (!sense)
                     * {
                     *  Decoders.SCSI.DiscStructureCapabilities.Capability[] caps = Decoders.SCSI.DiscStructureCapabilities.Decode(strBuf);
                     *  if (caps != null)
                     *  {
                     *      foreach (Decoders.SCSI.DiscStructureCapabilities.Capability cap in caps)
                     *      {
                     *          if (cap.SDS && cap.RDS)
                     *              DicConsole.WriteLine("Drive can READ/SEND DISC STRUCTURE format {0:X2}h", cap.FormatCode);
                     *          else if (cap.SDS)
                     *              DicConsole.WriteLine("Drive can SEND DISC STRUCTURE format {0:X2}h", cap.FormatCode);
                     *          else if (cap.RDS)
                     *              DicConsole.WriteLine("Drive can READ DISC STRUCTURE format {0:X2}h", cap.FormatCode);
                     *      }
                     *  }
                     * }
                     */

                    #region Plextor
                    if (dev.Manufacturer == "PLEXTOR")
                    {
                        bool   plxtSense = true;
                        bool   plxtDvd   = false;
                        byte[] plxtBuf   = null;

                        switch (dev.Model)
                        {
                        case "DVDR   PX-708A":
                        case "DVDR   PX-708A2":
                        case "DVDR   PX-712A":
                            plxtDvd   = true;
                            plxtSense = dev.PlextorReadEeprom(out plxtBuf, out senseBuf, dev.Timeout,
                                                              out _);
                            break;

                        case "DVDR   PX-714A":
                        case "DVDR   PX-716A":
                        case "DVDR   PX-716AL":
                        case "DVDR   PX-755A":
                        case "DVDR   PX-760A":
                        {
                            plxtBuf = new byte[256 * 4];
                            for (byte i = 0; i < 4; i++)
                            {
                                plxtSense = dev.PlextorReadEepromBlock(out byte[] plxtBufSmall,
                                                                       out senseBuf, i, 256, dev.Timeout,
                                                                       out _);
                                if (plxtSense)
                                {
                                    break;
                                }

                                Array.Copy(plxtBufSmall, 0, plxtBuf, i * 256, 256);
                            }

                            plxtDvd = true;
                            break;
                        }

                        default:
                        {
                            if (dev.Model.StartsWith("CD-R   ", StringComparison.Ordinal))
                            {
                                plxtSense = dev.PlextorReadEepromCdr(out plxtBuf, out senseBuf, dev.Timeout,
                                                                     out _);
                            }
                            break;
                        }
                        }

                        PlextorFeatures = new Plextor {
                            IsDvd = plxtDvd
                        };

                        if (!plxtSense)
                        {
                            PlextorFeatures.Eeprom = plxtBuf;

                            if (plxtDvd)
                            {
                                PlextorFeatures.Discs        = BigEndianBitConverter.ToUInt16(plxtBuf, 0x0120);
                                PlextorFeatures.CdReadTime   = BigEndianBitConverter.ToUInt32(plxtBuf, 0x0122);
                                PlextorFeatures.CdWriteTime  = BigEndianBitConverter.ToUInt32(plxtBuf, 0x0126);
                                PlextorFeatures.DvdReadTime  = BigEndianBitConverter.ToUInt32(plxtBuf, 0x012A);
                                PlextorFeatures.DvdWriteTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x012E);
                            }
                            else
                            {
                                PlextorFeatures.Discs       = BigEndianBitConverter.ToUInt16(plxtBuf, 0x0078);
                                PlextorFeatures.CdReadTime  = BigEndianBitConverter.ToUInt32(plxtBuf, 0x006C);
                                PlextorFeatures.CdWriteTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x007A);
                            }
                        }

                        plxtSense = dev.PlextorGetPoweRec(out senseBuf, out bool plxtPwrRecEnabled,
                                                          out ushort plxtPwrRecSpeed, dev.Timeout, out _);
                        if (!plxtSense)
                        {
                            PlextorFeatures.PoweRec = true;

                            if (plxtPwrRecEnabled)
                            {
                                PlextorFeatures.PoweRecEnabled          = true;
                                PlextorFeatures.PoweRecRecommendedSpeed = plxtPwrRecSpeed;

                                plxtSense = dev.PlextorGetSpeeds(out senseBuf, out ushort plxtPwrRecSelected,
                                                                 out ushort plxtPwrRecMax,
                                                                 out ushort plxtPwrRecLast, dev.Timeout, out _);

                                if (!plxtSense)
                                {
                                    PlextorFeatures.PoweRecSelected = plxtPwrRecSelected;
                                    PlextorFeatures.PoweRecMax      = plxtPwrRecMax;
                                    PlextorFeatures.PoweRecLast     = plxtPwrRecLast;
                                }
                            }
                        }

                        // TODO: Check it with a drive
                        plxtSense = dev.PlextorGetSilentMode(out plxtBuf, out senseBuf, dev.Timeout, out _);
                        if (!plxtSense)
                        {
                            if (plxtBuf[0] == 1)
                            {
                                PlextorFeatures.SilentModeEnabled = true;
                                PlextorFeatures.AccessTimeLimit   = plxtBuf[1];

                                PlextorFeatures.CdReadSpeedLimit  = plxtBuf[2];
                                PlextorFeatures.DvdReadSpeedLimit = plxtBuf[3];
                                PlextorFeatures.CdWriteSpeedLimit = plxtBuf[4];

                                // TODO: Check which one is each one

                                /*
                                 *  if(plxtBuf[6] > 0)
                                 *      DicConsole.WriteLine("\tTray eject speed limited to {0}",
                                 *                           -(plxtBuf[6] + 48));
                                 *  if(plxtBuf[7] > 0)
                                 *      DicConsole.WriteLine("\tTray eject speed limited to {0}",
                                 *                           plxtBuf[7] - 47);
                                 */
                            }
                        }

                        plxtSense = dev.PlextorGetGigaRec(out plxtBuf, out senseBuf, dev.Timeout, out _);
                        if (!plxtSense)
                        {
                            PlextorFeatures.GigaRec = true;
                        }

                        plxtSense = dev.PlextorGetSecuRec(out plxtBuf, out senseBuf, dev.Timeout, out _);
                        if (!plxtSense)
                        {
                            PlextorFeatures.SecuRec = true;
                        }

                        plxtSense = dev.PlextorGetSpeedRead(out plxtBuf, out senseBuf, dev.Timeout, out _);
                        if (!plxtSense)
                        {
                            PlextorFeatures.SpeedRead = true;
                            if ((plxtBuf[2] & 0x01) == 0x01)
                            {
                                PlextorFeatures.SpeedReadEnabled = true;
                            }
                        }

                        plxtSense = dev.PlextorGetHiding(out plxtBuf, out senseBuf, dev.Timeout, out _);
                        if (!plxtSense)
                        {
                            PlextorFeatures.Hiding = true;
                            if ((plxtBuf[2] & 0x02) == 0x02)
                            {
                                PlextorFeatures.HidesRecordables = true;
                            }
                            if ((plxtBuf[2] & 0x01) == 0x01)
                            {
                                PlextorFeatures.HidesSessions = true;
                            }
                        }

                        plxtSense = dev.PlextorGetVariRec(out plxtBuf, out senseBuf, false, dev.Timeout, out _);
                        if (!plxtSense)
                        {
                            PlextorFeatures.VariRec = true;
                        }

                        if (plxtDvd)
                        {
                            plxtSense = dev.PlextorGetVariRec(out plxtBuf, out senseBuf, true, dev.Timeout,
                                                              out _);
                            if (!plxtSense)
                            {
                                PlextorFeatures.VariRecDvd = true;
                            }

                            plxtSense = dev.PlextorGetBitsetting(out plxtBuf, out senseBuf, false, dev.Timeout,
                                                                 out _);
                            if (!plxtSense)
                            {
                                PlextorFeatures.BitSetting = true;
                            }
                            plxtSense = dev.PlextorGetBitsetting(out plxtBuf, out senseBuf, true, dev.Timeout,
                                                                 out _);
                            if (!plxtSense)
                            {
                                PlextorFeatures.BitSettingDl = true;
                            }
                            plxtSense = dev.PlextorGetTestWriteDvdPlus(out plxtBuf, out senseBuf, dev.Timeout,
                                                                       out _);
                            if (!plxtSense)
                            {
                                PlextorFeatures.DvdPlusWriteTest = true;
                            }
                        }
                    }
                    #endregion Plextor

                    if (ScsiInquiry.Value.KreonPresent)
                    {
                        if (!dev.KreonGetFeatureList(out senseBuf, out KreonFeatures krFeatures, dev.Timeout,
                                                     out _))
                        {
                            KreonFeatures = krFeatures;
                        }
                    }
                    break;
                }

                case PeripheralDeviceTypes.SequentialAccess:
                {
                    sense = dev.ReadBlockLimits(out byte[] seqBuf, out senseBuf, dev.Timeout, out _);
                    if (sense)
                    {
                        DicConsole.ErrorWriteLine("READ BLOCK LIMITS:\n{0}", Sense.PrettifySense(senseBuf));
                    }
                    else
                    {
                        BlockLimits = seqBuf;
                    }

                    sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, dev.Timeout, out _);
                    if (sense)
                    {
                        DicConsole.ErrorWriteLine("REPORT DENSITY SUPPORT:\n{0}",
                                                  Sense.PrettifySense(senseBuf));
                    }
                    else
                    {
                        DensitySupport       = seqBuf;
                        DensitySupportHeader = Decoders.SCSI.SSC.DensitySupport.DecodeDensity(seqBuf);
                    }

                    sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, true, false, dev.Timeout, out _);
                    if (sense)
                    {
                        DicConsole.ErrorWriteLine("REPORT DENSITY SUPPORT (MEDIUM):\n{0}",
                                                  Sense.PrettifySense(senseBuf));
                    }
                    else
                    {
                        MediumDensitySupport   = seqBuf;
                        MediaTypeSupportHeader = Decoders.SCSI.SSC.DensitySupport.DecodeMediumType(seqBuf);
                    }

                    break;
                }
                }

                break;
            }

            case DeviceType.MMC:
            {
                bool sense = dev.ReadCid(out byte[] mmcBuf, out _, dev.Timeout, out _);
                if (!sense)
                {
                    CID = mmcBuf;
                }

                sense = dev.ReadCsd(out mmcBuf, out _, dev.Timeout, out _);
                if (!sense)
                {
                    CSD = mmcBuf;
                }

                sense = dev.ReadOcr(out mmcBuf, out _, dev.Timeout, out _);
                if (!sense)
                {
                    OCR = mmcBuf;
                }

                sense = dev.ReadExtendedCsd(out mmcBuf, out _, dev.Timeout, out _);
                if (!sense)
                {
                    ExtendedCSD = mmcBuf;
                }
            }
            break;

            case DeviceType.SecureDigital:
            {
                bool sense = dev.ReadCid(out byte[] sdBuf, out _, dev.Timeout, out _);
                if (!sense)
                {
                    CID = sdBuf;
                }

                sense = dev.ReadCsd(out sdBuf, out _, dev.Timeout, out _);
                if (!sense)
                {
                    CSD = sdBuf;
                }

                sense = dev.ReadSdocr(out sdBuf, out _, dev.Timeout, out _);
                if (!sense)
                {
                    OCR = sdBuf;
                }

                sense = dev.ReadScr(out sdBuf, out _, dev.Timeout, out _);
                if (!sense)
                {
                    SCR = sdBuf;
                }
            }
            break;

            default:
                DicConsole.ErrorWriteLine("Unknown device type {0}, cannot get information.", dev.Type);
                break;
            }
        }
Esempio n. 20
0
        public static DecodedMode?DecodeMode6(byte[] modeResponse, PeripheralDeviceTypes deviceType)
        {
            ModeHeader?hdr = DecodeModeHeader6(modeResponse, deviceType);

            if (!hdr.HasValue)
            {
                return(null);
            }

            var decoded = new DecodedMode
            {
                Header = hdr.Value
            };

            int blkDrLength = 0;

            if (decoded.Header.BlockDescriptors != null)
            {
                blkDrLength = decoded.Header.BlockDescriptors.Length;
            }

            int offset = 4 + (blkDrLength * 8);
            int length = modeResponse[0] + 1;

            if (length != modeResponse.Length)
            {
                return(decoded);
            }

            List <ModePage> listpages = new List <ModePage>();

            while (offset < modeResponse.Length)
            {
                bool isSubpage = (modeResponse[offset] & 0x40) == 0x40;
                var  pg        = new ModePage();
                byte pageNo    = (byte)(modeResponse[offset] & 0x3F);

                if (pageNo == 0)
                {
                    pg.PageResponse = new byte[modeResponse.Length - offset];
                    Array.Copy(modeResponse, offset, pg.PageResponse, 0, pg.PageResponse.Length);
                    pg.Page    = 0;
                    pg.Subpage = 0;
                    offset    += pg.PageResponse.Length;
                }
                else
                {
                    if (isSubpage)
                    {
                        if (offset + 3 >= modeResponse.Length)
                        {
                            break;
                        }

                        pg.PageResponse = new byte[(modeResponse[offset + 2] << 8) + modeResponse[offset + 3] + 4];
                        int copyLen = pg.PageResponse.Length;

                        if (pg.PageResponse.Length + offset > modeResponse.Length)
                        {
                            copyLen = modeResponse.Length - offset;
                        }

                        Array.Copy(modeResponse, offset, pg.PageResponse, 0, copyLen);
                        pg.Page    = (byte)(modeResponse[offset] & 0x3F);
                        pg.Subpage = modeResponse[offset + 1];
                        offset    += pg.PageResponse.Length;
                    }
                    else
                    {
                        if (offset + 1 >= modeResponse.Length)
                        {
                            break;
                        }

                        pg.PageResponse = new byte[modeResponse[offset + 1] + 2];
                        int copyLen = pg.PageResponse.Length;

                        if (pg.PageResponse.Length + offset > modeResponse.Length)
                        {
                            copyLen = modeResponse.Length - offset;
                        }

                        Array.Copy(modeResponse, offset, pg.PageResponse, 0, copyLen);
                        pg.Page    = (byte)(modeResponse[offset] & 0x3F);
                        pg.Subpage = 0;
                        offset    += pg.PageResponse.Length;
                    }
                }

                listpages.Add(pg);
            }

            decoded.Pages = listpages.ToArray();

            return(decoded);
        }