Esempio n. 1
0
        public static DiscDefinitionStructure?Decode(byte[] DDSResponse)
        {
            if (DDSResponse == null)
            {
                return(null);
            }

            var decoded = new DiscDefinitionStructure
            {
                DataLength = BigEndianBitConverter.ToUInt16(DDSResponse, 0),
                Reserved1  = DDSResponse[2],
                Reserved2  = DDSResponse[3],
                Signature  = BigEndianBitConverter.ToUInt16(DDSResponse, 4)
            };

            if (decoded.Signature != DDSIdentifier)
            {
                AaruConsole.DebugWriteLine("BD DDS decoder", "Found incorrect DDS signature (0x{0:X4})",
                                           decoded.Signature);

                return(null);
            }

            decoded.Format                 = DDSResponse[6];
            decoded.Reserved3              = DDSResponse[7];
            decoded.UpdateCount            = BigEndianBitConverter.ToUInt32(DDSResponse, 8);
            decoded.Reserved4              = BigEndianBitConverter.ToUInt64(DDSResponse, 12);
            decoded.DriveAreaPSN           = BigEndianBitConverter.ToUInt32(DDSResponse, 20);
            decoded.Reserved5              = BigEndianBitConverter.ToUInt32(DDSResponse, 24);
            decoded.DefectListPSN          = BigEndianBitConverter.ToUInt32(DDSResponse, 28);
            decoded.Reserved6              = BigEndianBitConverter.ToUInt32(DDSResponse, 32);
            decoded.PSNofLSNZero           = BigEndianBitConverter.ToUInt32(DDSResponse, 36);
            decoded.LastUserAreaLSN        = BigEndianBitConverter.ToUInt32(DDSResponse, 40);
            decoded.ISA0                   = BigEndianBitConverter.ToUInt32(DDSResponse, 44);
            decoded.OSA                    = BigEndianBitConverter.ToUInt32(DDSResponse, 48);
            decoded.ISA1                   = BigEndianBitConverter.ToUInt32(DDSResponse, 52);
            decoded.SpareAreaFullFlags     = DDSResponse[56];
            decoded.Reserved7              = DDSResponse[57];
            decoded.DiscTypeSpecificField1 = DDSResponse[58];
            decoded.Reserved8              = DDSResponse[59];
            decoded.DiscTypeSpecificField2 = BigEndianBitConverter.ToUInt32(DDSResponse, 60);
            decoded.Reserved9              = BigEndianBitConverter.ToUInt32(DDSResponse, 64);
            decoded.StatusBits             = new byte[32];
            Array.Copy(DDSResponse, 68, decoded.StatusBits, 0, 32);
            decoded.DiscTypeSpecificData = new byte[DDSResponse.Length - 100];
            Array.Copy(DDSResponse, 100, decoded.DiscTypeSpecificData, 0, DDSResponse.Length - 100);

            return(decoded);
        }
Esempio n. 2
0
        public static string Prettify(DiscDefinitionStructure? DDSResponse)
        {
            if(DDSResponse == null) return null;

            DiscDefinitionStructure response = DDSResponse.Value;

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("DDS Format: 0x{0:X2}", response.Format).AppendLine();
            sb.AppendFormat("DDS has ben updated {0} times", response.UpdateCount).AppendLine();
            sb.AppendFormat("First PSN of Drive Area: 0x{0:X8}", response.DriveAreaPSN).AppendLine();
            sb.AppendFormat("First PSN of Defect List: 0x{0:X8}", response.DefectListPSN).AppendLine();
            sb.AppendFormat("PSN of User Data Area's LSN 0: 0x{0:X8}", response.PSNofLSNZero).AppendLine();
            sb.AppendFormat("Last User Data Area's LSN 0: 0x{0:X8}", response.LastUserAreaLSN).AppendLine();
            sb.AppendFormat("ISA0 size: {0}", response.ISA0).AppendLine();
            sb.AppendFormat("OSA size: {0}", response.OSA).AppendLine();
            sb.AppendFormat("ISA1 size: {0}", response.ISA1).AppendLine();
            sb.AppendFormat("Spare Area Full Flags: 0x{0:X2}", response.SpareAreaFullFlags).AppendLine();
            sb.AppendFormat("Disc Type Specific Field 1: 0x{0:X2}", response.DiscTypeSpecificField1).AppendLine();
            sb.AppendFormat("Disc Type Specific Field 2: 0x{0:X8}", response.DiscTypeSpecificField2).AppendLine();
            sb.AppendFormat("Blu-ray DDS Status Bits in hex follows:");
            sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.StatusBits, 80));
            sb.AppendFormat("Blu-ray DDS Disc Type Specific Data in hex follows:");
            sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.DiscTypeSpecificData, 80));

#if DEBUG
            if(response.Reserved1 != 0) sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
            if(response.Reserved2 != 0) sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
            if(response.Reserved3 != 0) sb.AppendFormat("Reserved3 = 0x{0:X2}", response.Reserved3).AppendLine();
            if(response.Reserved4 != 0) sb.AppendFormat("Reserved4 = 0x{0:X16}", response.Reserved4).AppendLine();
            if(response.Reserved5 != 0) sb.AppendFormat("Reserved5 = 0x{0:X8}", response.Reserved5).AppendLine();
            if(response.Reserved6 != 0) sb.AppendFormat("Reserved6 = 0x{0:X8}", response.Reserved6).AppendLine();
            if(response.Reserved7 != 0) sb.AppendFormat("Reserved7 = 0x{0:X2}", response.Reserved7).AppendLine();
            if(response.Reserved8 != 0) sb.AppendFormat("Reserved8 = 0x{0:X2}", response.Reserved8).AppendLine();
            if(response.Reserved9 != 0) sb.AppendFormat("Reserved9 = 0x{0:X8}", response.Reserved9).AppendLine();
#endif

            return sb.ToString();
        }
Esempio n. 3
0
        public static string Prettify(DiscDefinitionStructure?dds)
        {
            if (dds == null)
            {
                return(null);
            }

            DiscDefinitionStructure decoded = dds.Value;
            StringBuilder           sb      = new StringBuilder();

            if (decoded.InProcess)
            {
                sb.AppendLine("Formatting in progress.");
                if (decoded.Groups == 24)
                {
                    if (decoded.PartialCertification)
                    {
                        sb.AppendLine("Formatting is only using partial certification");
                    }
                    if (decoded.FormattingOnlyAGroup)
                    {
                        sb.AppendLine("Only a group is being formatted");
                    }
                }
            }

            if (decoded.UserCertification)
            {
                sb.AppendLine("Disc has been certified by an user");
            }
            if (decoded.ManufacturerCertification)
            {
                sb.AppendLine("Disc has been certified by a manufacturer");
            }

            sb.AppendFormat("DDS has been updated {0} times", decoded.UpdateCount).AppendLine();

            if (decoded.Groups == 24)
            {
                for (int i = 0; i < decoded.GroupCertificationFlags.Length; i++)
                {
                    if (decoded.GroupCertificationFlags[i].InProcess)
                    {
                        sb.AppendFormat("Group {0} is being formatted", i).AppendLine();
                        if (decoded.GroupCertificationFlags[i].PartialCertification)
                        {
                            sb.AppendFormat("Group {0} is being certified partially", i).AppendLine();
                        }
                    }

                    if (decoded.GroupCertificationFlags[i].UserCertification)
                    {
                        sb.AppendFormat("Group {0} has been certified by an user", i).AppendLine();
                    }
                }
            }

            if (decoded.Groups != 1)
            {
                return(sb.ToString());
            }

            {
                sb.AppendFormat("Disc has {0} zones", decoded.Zones).AppendLine();
                sb.AppendFormat("Primary Spare Area stats at PSN {0:X}h and ends at PSN {1:X}h, inclusively",
                                decoded.SpareAreaFirstPSN, decoded.SpareAreaLastPSN).AppendLine();
                sb.AppendFormat("LSN 0 is at PSN {0:X}h", decoded.LSN0Location).AppendLine();

                for (int i = 0; i < decoded.StartLSNForZone.Length; i++)
                {
                    sb.AppendFormat("Zone {0} starts at LSN {1}", i, decoded.StartLSNForZone[i]).AppendLine();
                }
            }

            return(sb.ToString());
        }
Esempio n. 4
0
        public static DiscDefinitionStructure?Decode(byte[] response)
        {
            if (response?.Length != 2052)
            {
                return(null);
            }

            DiscDefinitionStructure dds =
                new DiscDefinitionStructure {
                Identifier = (ushort)((response[4] << 8) + response[5])
            };

            if (dds.Identifier != 0x0A0A)
            {
                return(null);
            }

            // Common to both DVD-RAM versions
            dds.DataLength                 = (ushort)((response[0] << 8) + response[1]);
            dds.Reserved1                  = response[2];
            dds.Reserved2                  = response[3];
            dds.Reserved3                  = response[6];
            dds.InProcess                 |= (response[7] & 0x80) == 0x80;
            dds.UserCertification         |= (response[7] & 0x02) == 0x02;
            dds.ManufacturerCertification |= (response[7] & 0x01) == 0x01;
            dds.UpdateCount                =
                (uint)((response[8] << 24) + (response[9] << 16) + (response[10] << 8) + response[11]);
            dds.Groups =
                (ushort)((response[12] << 8) + response[13]);

            // ECMA-272
            if (dds.Groups == 24)
            {
                dds.PartialCertification |= (response[7] & 0x40) == 0x40;
                dds.FormattingOnlyAGroup |= (response[7] & 0x20) == 0x20;
                dds.Reserved4             = (byte)((response[7] & 0x1C) >> 2);
                dds.Reserved              = new byte[6];
                Array.Copy(response, 14, dds.Reserved, 0, 6);
                dds.GroupCertificationFlags = new GroupCertificationFlag[24];
                for (int i = 0; i < 24; i++)
                {
                    dds.GroupCertificationFlags[i].InProcess            |= (response[20 + i] & 0x80) == 0x80;
                    dds.GroupCertificationFlags[i].PartialCertification |= (response[20 + i] & 0x40) == 0x40;
                    dds.GroupCertificationFlags[i].Reserved1             = (byte)((response[20 + i] & 0x3C) >> 2);
                    dds.GroupCertificationFlags[i].UserCertification    |= (response[20 + i] & 0x02) == 0x02;
                    dds.GroupCertificationFlags[i].Reserved2            |= (response[20 + i] & 0x01) == 0x01;
                }
            }

            // ECMA-330
            if (dds.Groups != 1)
            {
                return(dds);
            }

            {
                dds.Reserved4 = (byte)((response[7] & 0x7C) >> 2);
                dds.Reserved  = new byte[68];
                Array.Copy(response, 16, dds.Reserved, 0, 68);
                dds.Zones             = (ushort)((response[14] << 8) + response[15]);
                dds.SpareAreaFirstPSN = (uint)((response[85] << 16) + (response[86] << 8) + response[87]);
                dds.SpareAreaLastPSN  = (uint)((response[89] << 16) + (response[90] << 8) + response[91]);
                dds.LSN0Location      = (uint)((response[93] << 16) + (response[94] << 8) + response[95]);
                dds.StartLSNForZone   = new uint[dds.Zones];

                for (int i = 0; i < dds.Zones; i++)
                {
                    dds.StartLSNForZone[i] = (uint)((response[260 + i * 4 + 1] << 16) +
                                                    (response[260 + i * 4 + 2] << 8) + response[260 + i * 4 + 3]);
                }
            }

            return(dds);
        }