Example #1
0
    internal static void twoways(Ice.Communicator communicator, Test.MyClassPrx p)
    {
        {
            Dictionary<int, int> i = new Dictionary<int, int>();
            i[0] = 1;
            i[1] = 0;

            Dictionary<int, int> o;
            Dictionary<int, int> r;
            r = p.opNV(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            Dictionary<string, string> i = new Dictionary<string, string>();
            i["a"] = "b";
            i["b"] = "a";

            Dictionary<string, string> o;
            Dictionary<string, string> r;
            r = p.opNR(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            Dictionary<string, Dictionary<int, int>> i = new Dictionary<string, Dictionary<int, int>>();
            Dictionary<int, int> id = new Dictionary<int, int>();
            id[0] = 1;
            id[1] = 0;
            i["a"] = id;
            i["b"] = id;

            Dictionary<string, Dictionary<int, int>> o;
            Dictionary<string, Dictionary<int, int>> r;
            r = p.opNDV(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            Dictionary<string, Dictionary<string, string>> i = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> id = new Dictionary<string, string>();
            id["a"] = "b";
            id["b"] = "a";
            i["a"] = id;
            i["b"] = id;

            Dictionary<string, Dictionary<string, string>> o;
            Dictionary<string, Dictionary<string, string>> r;
            r = p.opNDR(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            OV i = new OV();
            i[0] = 1;
            i[1] = 0;

            OV o;
            OV r;
            r = p.opOV(i, out o);

            test(OV.Equals(i, o));
            test(OV.Equals(i, r));
        }

        {
            OR i = new OR();
            i["a"] = "b";
            i["b"] = "a";

            OR o;
            OR r;
            r = p.opOR(i, out o);

            test(OR.Equals(i, o));
            test(OR.Equals(i, r));
        }

        {
            ODV i = new ODV();
            OV id = new OV();
            id[0] = 1;
            id[1] = 0;
            i["a"] = id;
            i["b"] = id;

            ODV o;
            ODV r;
            r = p.opODV(i, out o);

            test(ODV.Equals(i, o));
            test(ODV.Equals(i, r));
        }

        {
            ODR i = new ODR();
            OR id = new OR();
            id["a"] = "b";
            id["b"] = "a";
            i["a"] = id;
            i["b"] = id;

            ODR o;
            ODR r;
            r = p.opODR(i, out o);

            test(ODR.Equals(i, o));
            test(ODR.Equals(i, r));
        }

        {
            Dictionary<string, ODV> i = new Dictionary<string, ODV>();
            OV iid = new OV();
            iid[0] = 1;
            iid[1] = 0;
            ODV id = new ODV();
            id["a"] = iid;
            id["b"] = iid;
            i["a"] = id;
            i["b"] = id;

            Dictionary<string, ODV> o;
            Dictionary<string, ODV> r;
            r = p.opNODV(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            Dictionary<string, ODR> i = new Dictionary<string, ODR>();
            OR iid = new OR();
            iid["a"] = "b";
            iid["a"] = "b";
            ODR id = new ODR();
            id["a"] = iid;
            id["b"] = iid;
            i["a"] = id;
            i["b"] = id;

            Dictionary<string, ODR> o;
            Dictionary<string, ODR> r;
            r = p.opNODR(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            ONDV i = new ONDV();
            Dictionary<int, int> iid = new Dictionary<int, int>();
            iid[0] = 1;
            iid[1] = 0;
            Dictionary<string, Dictionary<int, int>> id
                = new Dictionary<string, Dictionary<int, int>>();
            id["a"] = iid;
            id["b"] = iid;
            i["a"] = id;
            i["b"] = id;

            ONDV o;
            ONDV r;
            r = p.opONDV(i, out o);

            foreach(string key in i.Keys)
            {
                foreach(string s in i[key].Keys)
                {
                    test(Ice.CollectionComparer.Equals(i[key][s], o[key][s]));
                    test(Ice.CollectionComparer.Equals(i[key][s], r[key][s]));
                }
            }
        }

        {
            ONDR i = new ONDR();
            Dictionary<string, string> iid = new Dictionary<string, string>();
            iid["a"] = "b";
            iid["b"] = "a";
            Dictionary<string, Dictionary<string, string>> id
                = new Dictionary<string, Dictionary<string, string>>();
            id["a"] = iid;
            id["b"] = iid;
            i["a"] = id;
            i["b"] = id;

            ONDR o;
            ONDR r;
            r = p.opONDR(i, out o);

            foreach(string key in i.Keys)
            {
                foreach(string s in i[key].Keys)
                {
                    test(Ice.CollectionComparer.Equals(i[key][s], o[key][s]));
                    test(Ice.CollectionComparer.Equals(i[key][s], r[key][s]));
                }
            }
        }

        {
            int[] ii = new int[] { 1, 2 };
            Dictionary<string, int[]> i = new Dictionary<string, int[]>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary<string, int[]> o;
            Dictionary<string, int[]> r;
            r = p.opNDAIS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            CIS ii = new CIS();
            ii.Add(1);
            ii.Add(2);
            Dictionary<string, CIS> i = new Dictionary<string, CIS>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary<string, CIS> o;
            Dictionary<string, CIS> r;
            r = p.opNDCIS(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            List<int> ii = new List<int>();
            ii.Add(1);
            ii.Add(2);
            Dictionary<string, List<int>> i = new Dictionary<string, List<int>>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary<string, List<int>> o;
            Dictionary<string, List<int>> r;
            r = p.opNDGIS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            string[] ii = new string[] { "a", "b" };
            Dictionary<string, string[]> i = new Dictionary<string, string[]>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary<string, string[]> o;
            Dictionary<string, string[]> r;
            r = p.opNDASS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            CSS ii = new CSS();
            ii.Add("a");
            ii.Add("b");
            Dictionary<string, CSS> i = new Dictionary<string, CSS>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary<string, CSS> o;
            Dictionary<string, CSS> r;
            r = p.opNDCSS(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            List<string> ii = new List<string>();
            ii.Add("a");
            ii.Add("b");
            Dictionary<string, List<string>> i = new Dictionary<string, List<string>>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary<string, List<string>> o;
            Dictionary<string, List<string>> r;
            r = p.opNDGSS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            int[] ii = new int[] { 1, 2 };
            ODAIS i = new ODAIS();
            i["a"] = ii;
            i["b"] = ii;

            ODAIS o;
            ODAIS r;
            r = p.opODAIS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            CIS ii = new CIS();
            ii.Add(1);
            ii.Add(2);
            ODCIS i = new ODCIS();
            i["a"] = ii;
            i["b"] = ii;

            ODCIS o;
            ODCIS r;
            r = p.opODCIS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            List<int> ii = new List<int>();
            ii.Add(1);
            ii.Add(2);
            ODGIS i = new ODGIS();
            i["a"] = ii;
            i["b"] = ii;

            ODGIS o;
            ODGIS r;
            r = p.opODGIS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            string[] ii = new string[] { "a", "b" };
            ODASS i = new ODASS();
            i["a"] = ii;
            i["b"] = ii;

            ODASS o;
            ODASS r;
            r = p.opODASS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            CSS ii = new CSS();
            ii.Add("a");
            ii.Add("b");
            ODCSS i = new ODCSS();
            i["a"] = ii;
            i["b"] = ii;

            ODCSS o;
            ODCSS r;
            r = p.opODCSS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            List<string> ii = new List<string>();
            ii.Add("a");
            ii.Add("b");
            ODGSS i = new ODGSS();
            i["a"] = ii;
            i["b"] = ii;

            ODGSS o;
            ODGSS r;
            r = p.opODGSS(i, out o);

            foreach(string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }
    }
Example #2
0
    internal static void twowaysAMI(Ice.Communicator communicator, Test.MyClassPrx p)
    {
        {
            Dictionary<int, int> i = new Dictionary<int, int>();
            i[0] = 1;
            i[1] = 0;

            AMI_MyClass_opNVI cb = new AMI_MyClass_opNVI(i);
            p.opNV_async(cb, i);
            cb.check();
        }

        {
            Dictionary<string, string> i = new Dictionary<string, string>();
            i["a"] = "b";
            i["b"] = "a";

            AMI_MyClass_opNRI cb = new AMI_MyClass_opNRI(i);
            p.opNR_async(cb, i);
            cb.check();
        }

        {
            Dictionary<string, Dictionary<int, int>> i = new Dictionary<string, Dictionary<int, int>>();
            Dictionary<int, int> id = new Dictionary<int, int>();
            id[0] = 1;
            id[1] = 0;
            i["a"] = id;
            i["b"] = id;

            AMI_MyClass_opNDVI cb = new AMI_MyClass_opNDVI(i);
            p.opNDV_async(cb, i);
            cb.check();
        }

        {
            Dictionary<string, Dictionary<string, string>> i = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> id = new Dictionary<string, string>();
            id["a"] = "b";
            id["b"] = "a";
            i["a"] = id;
            i["b"] = id;

            AMI_MyClass_opNDRI cb = new AMI_MyClass_opNDRI(i);
            p.opNDR_async(cb, i);
            cb.check();
        }

        {
            OV i = new OV();
            i[0] = 1;
            i[1] = 0;

            AMI_MyClass_opOVI cb = new AMI_MyClass_opOVI(i);
            p.opOV_async(cb, i);
            cb.check();
        }

        {
            OR i = new OR();
            i["a"] = "b";
            i["b"] = "a";

            AMI_MyClass_opORI cb = new AMI_MyClass_opORI(i);
            p.opOR_async(cb, i);
            cb.check();
        }

        {
            ODV i = new ODV();
            OV id = new OV();
            id[0] = 1;
            id[1] = 0;
            i["a"] = id;
            i["b"] = id;

            AMI_MyClass_opODVI cb = new AMI_MyClass_opODVI(i);
            p.opODV_async(cb, i);
            cb.check();
        }

        {
            ODR i = new ODR();
            OR id = new OR();
            id["a"] = "b";
            id["b"] = "a";
            i["a"] = id;
            i["b"] = id;

            AMI_MyClass_opODRI cb = new AMI_MyClass_opODRI(i);
            p.opODR_async(cb, i);
            cb.check();
        }

        {
            Dictionary<string, ODV> i = new Dictionary<string, ODV>();
            OV iid = new OV();
            iid[0] = 1;
            iid[1] = 0;
            ODV id = new ODV();
            id["a"] = iid;
            id["b"] = iid;
            i["a"] = id;
            i["b"] = id;

            AMI_MyClass_opNODVI cb = new AMI_MyClass_opNODVI(i);
            p.opNODV_async(cb, i);
            cb.check();
        }

        {
            Dictionary<string, ODR> i = new Dictionary<string, ODR>();
            OR iid = new OR();
            iid["a"] = "b";
            iid["b"] = "a";
            ODR id = new ODR();
            id["a"] = iid;
            id["b"] = iid;
            i["a"] = id;
            i["b"] = id;

            AMI_MyClass_opNODRI cb = new AMI_MyClass_opNODRI(i);
            p.opNODR_async(cb, i);
            cb.check();
        }

        {
            ONDV i = new ONDV();
            Dictionary<int, int> iid = new Dictionary<int, int>();
            iid[0] = 1;
            iid[1] = 0;
            Dictionary<string, Dictionary<int, int>> id
                = new Dictionary<string, Dictionary<int, int>>();
            id["a"] = iid;
            id["b"] = iid;
            i["a"] = id;
            i["b"] = id;

            AMI_MyClass_opONDVI cb = new AMI_MyClass_opONDVI(i);
            p.opONDV_async(cb, i);
            cb.check();
        }

        {
            ONDR i = new ONDR();
            Dictionary<string, string> iid = new Dictionary<string, string>();
            iid["a"] = "b";
            iid["b"] = "a";
            Dictionary<string, Dictionary<string, string>> id
                = new Dictionary<string, Dictionary<string, string>>();
            id["a"] = iid;
            id["b"] = iid;
            i["a"] = id;
            i["b"] = id;

            AMI_MyClass_opONDRI cb = new AMI_MyClass_opONDRI(i);
            p.opONDR_async(cb, i);
            cb.check();
        }

        {
            int[] ii = new int[] { 1, 2 };
            Dictionary<string, int[]> i = new Dictionary<string, int[]>();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opNDAISI cb = new AMI_MyClass_opNDAISI(i);
            p.opNDAIS_async(cb, i);
            cb.check();
        }

        {
            CIS ii = new CIS();
            ii.Add(1);
            ii.Add(2);
            Dictionary<string, CIS> i = new Dictionary<string, CIS>();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opNDCISI cb = new AMI_MyClass_opNDCISI(i);
            p.opNDCIS_async(cb, i);
            cb.check();
        }

        {
            List<int> ii = new List<int>();
            ii.Add(1);
            ii.Add(2);
            Dictionary<string, List<int>> i = new Dictionary<string, List<int>>();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opNDGISI cb = new AMI_MyClass_opNDGISI(i);
            p.opNDGIS_async(cb, i);
            cb.check();
        }

        {
            string[] ii = new string[] { "a", "b" };
            Dictionary<string, string[]> i = new Dictionary<string, string[]>();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opNDASSI cb = new AMI_MyClass_opNDASSI(i);
            p.opNDASS_async(cb, i);
            cb.check();
        }

        {
            CSS ii = new CSS();
            ii.Add("a");
            ii.Add("b");
            Dictionary<string, CSS> i = new Dictionary<string, CSS>();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opNDCSSI cb = new AMI_MyClass_opNDCSSI(i);
            p.opNDCSS_async(cb, i);
            cb.check();
        }

        {
            List<string> ii = new List<string>();
            ii.Add("a");
            ii.Add("b");
            Dictionary<string, List<string>> i = new Dictionary<string, List<string>>();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opNDGSSI cb = new AMI_MyClass_opNDGSSI(i);
            p.opNDGSS_async(cb, i);
            cb.check();
        }

        {
            int[] ii = new int[] { 1, 2 };
            ODAIS i = new ODAIS();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opODAISI cb = new AMI_MyClass_opODAISI(i);
            p.opODAIS_async(cb, i);
            cb.check();
        }

        {
            CIS ii = new CIS();
            ii.Add(1);
            ii.Add(2);
            ODCIS i = new ODCIS();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opODCISI cb = new AMI_MyClass_opODCISI(i);
            p.opODCIS_async(cb, i);
            cb.check();
        }

        {
            List<int> ii = new List<int>();
            ii.Add(1);
            ii.Add(2);
            ODGIS i = new ODGIS();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opODGISI cb = new AMI_MyClass_opODGISI(i);
            p.opODGIS_async(cb, i);
            cb.check();
        }

        {
            string[] ii = new string[] { "a", "b" };
            ODASS i = new ODASS();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opODASSI cb = new AMI_MyClass_opODASSI(i);
            p.opODASS_async(cb, i);
            cb.check();
        }

        {
            CSS ii = new CSS();
            ii.Add("a");
            ii.Add("b");
            ODCSS i = new ODCSS();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opODCSSI cb = new AMI_MyClass_opODCSSI(i);
            p.opODCSS_async(cb, i);
            cb.check();
        }

        {
            List<string> ii = new List<string>();
            ii.Add("a");
            ii.Add("b");
            ODGSS i = new ODGSS();
            i["a"] = ii;
            i["b"] = ii;

            AMI_MyClass_opODGSSI cb = new AMI_MyClass_opODGSSI(i);
            p.opODGSS_async(cb, i);
            cb.check();
        }
    }
Example #3
0
        internal PcmciaInfoViewModel([CanBeNull] byte[] pcmciaCis, Window view)
        {
            if (pcmciaCis == null)
            {
                return;
            }

            _cis    = pcmciaCis;
            CisList = new ObservableCollection <PcmciaCisModel>();
            SavePcmciaCisCommand = ReactiveCommand.Create(ExecuteSavePcmciaCisCommand);

            _view = view;

            Tuple[] tuples = CIS.GetTuples(_cis);

            if (tuples != null)
            {
                foreach (Tuple tuple in tuples)
                {
                    string tupleCode;
                    string tupleDescription;

                    switch (tuple.Code)
                    {
                    case TupleCodes.CISTPL_NULL:
                    case TupleCodes.CISTPL_END: continue;

                    case TupleCodes.CISTPL_DEVICEGEO:
                    case TupleCodes.CISTPL_DEVICEGEO_A:
                        tupleCode        = "Device Geometry Tuples";
                        tupleDescription = CIS.PrettifyDeviceGeometryTuple(tuple);

                        break;

                    case TupleCodes.CISTPL_MANFID:
                        tupleCode        = "Manufacturer Identification Tuple";
                        tupleDescription = CIS.PrettifyManufacturerIdentificationTuple(tuple);

                        break;

                    case TupleCodes.CISTPL_VERS_1:
                        tupleCode        = "Level 1 Version / Product Information Tuple";
                        tupleDescription = 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:
                        tupleCode        = $"Undecoded tuple ID {tuple.Code}";
                        tupleDescription = $"Undecoded tuple ID {tuple.Code}";

                        break;

                    default:
                        tupleCode        = $"0x{(byte)tuple.Code:X2}";
                        tupleDescription = $"Found unknown tuple ID 0x{(byte)tuple.Code:X2}";

                        break;
                    }

                    CisList.Add(new PcmciaCisModel
                    {
                        Code        = tupleCode,
                        Description = tupleDescription
                    });
                }
            }
            else
            {
                AaruConsole.DebugWriteLine("Device-Info command", "PCMCIA CIS returned no tuples");
            }
        }
Example #4
0
    internal static void twoways(Ice.Communicator communicator, Test.MyClassPrx p)
    {
        {
            Dictionary <int, int> i = new Dictionary <int, int>();
            i[0] = 1;
            i[1] = 0;

            Dictionary <int, int> o;
            Dictionary <int, int> r;
            r = p.opNV(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            Dictionary <string, string> i = new Dictionary <string, string>();
            i["a"] = "b";
            i["b"] = "a";

            Dictionary <string, string> o;
            Dictionary <string, string> r;
            r = p.opNR(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            Dictionary <string, Dictionary <int, int> > i = new Dictionary <string, Dictionary <int, int> >();
            Dictionary <int, int> id = new Dictionary <int, int>();
            id[0]  = 1;
            id[1]  = 0;
            i["a"] = id;
            i["b"] = id;

            Dictionary <string, Dictionary <int, int> > o;
            Dictionary <string, Dictionary <int, int> > r;
            r = p.opNDV(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            Dictionary <string, Dictionary <string, string> > i = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, string> id = new Dictionary <string, string>();
            id["a"] = "b";
            id["b"] = "a";
            i["a"]  = id;
            i["b"]  = id;

            Dictionary <string, Dictionary <string, string> > o;
            Dictionary <string, Dictionary <string, string> > r;
            r = p.opNDR(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            OV i = new OV();
            i[0] = 1;
            i[1] = 0;

            OV o;
            OV r;
            r = p.opOV(i, out o);

            test(OV.Equals(i, o));
            test(OV.Equals(i, r));
        }

        {
            OR i = new OR();
            i["a"] = "b";
            i["b"] = "a";

            OR o;
            OR r;
            r = p.opOR(i, out o);

            test(OR.Equals(i, o));
            test(OR.Equals(i, r));
        }

        {
            ODV i  = new ODV();
            OV  id = new OV();
            id[0]  = 1;
            id[1]  = 0;
            i["a"] = id;
            i["b"] = id;

            ODV o;
            ODV r;
            r = p.opODV(i, out o);

            test(ODV.Equals(i, o));
            test(ODV.Equals(i, r));
        }

        {
            ODR i  = new ODR();
            OR  id = new OR();
            id["a"] = "b";
            id["b"] = "a";
            i["a"]  = id;
            i["b"]  = id;

            ODR o;
            ODR r;
            r = p.opODR(i, out o);

            test(ODR.Equals(i, o));
            test(ODR.Equals(i, r));
        }

        {
            Dictionary <string, ODV> i = new Dictionary <string, ODV>();
            OV iid = new OV();
            iid[0] = 1;
            iid[1] = 0;
            ODV id = new ODV();
            id["a"] = iid;
            id["b"] = iid;
            i["a"]  = id;
            i["b"]  = id;

            Dictionary <string, ODV> o;
            Dictionary <string, ODV> r;
            r = p.opNODV(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            Dictionary <string, ODR> i = new Dictionary <string, ODR>();
            OR iid = new OR();
            iid["a"] = "b";
            iid["a"] = "b";
            ODR id = new ODR();
            id["a"] = iid;
            id["b"] = iid;
            i["a"]  = id;
            i["b"]  = id;

            Dictionary <string, ODR> o;
            Dictionary <string, ODR> r;
            r = p.opNODR(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            ONDV i = new ONDV();
            Dictionary <int, int> iid = new Dictionary <int, int>();
            iid[0] = 1;
            iid[1] = 0;
            Dictionary <string, Dictionary <int, int> > id
                    = new Dictionary <string, Dictionary <int, int> >();
            id["a"] = iid;
            id["b"] = iid;
            i["a"]  = id;
            i["b"]  = id;

            ONDV o;
            ONDV r;
            r = p.opONDV(i, out o);

            foreach (string key in i.Keys)
            {
                foreach (string s in i[key].Keys)
                {
                    test(Ice.CollectionComparer.Equals(i[key][s], o[key][s]));
                    test(Ice.CollectionComparer.Equals(i[key][s], r[key][s]));
                }
            }
        }

        {
            ONDR i = new ONDR();
            Dictionary <string, string> iid = new Dictionary <string, string>();
            iid["a"] = "b";
            iid["b"] = "a";
            Dictionary <string, Dictionary <string, string> > id
                    = new Dictionary <string, Dictionary <string, string> >();
            id["a"] = iid;
            id["b"] = iid;
            i["a"]  = id;
            i["b"]  = id;

            ONDR o;
            ONDR r;
            r = p.opONDR(i, out o);

            foreach (string key in i.Keys)
            {
                foreach (string s in i[key].Keys)
                {
                    test(Ice.CollectionComparer.Equals(i[key][s], o[key][s]));
                    test(Ice.CollectionComparer.Equals(i[key][s], r[key][s]));
                }
            }
        }

        {
            int[] ii = new int[] { 1, 2 };
            Dictionary <string, int[]> i = new Dictionary <string, int[]>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary <string, int[]> o;
            Dictionary <string, int[]> r;
            r = p.opNDAIS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            CIS ii = new CIS();
            ii.Add(1);
            ii.Add(2);
            Dictionary <string, CIS> i = new Dictionary <string, CIS>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary <string, CIS> o;
            Dictionary <string, CIS> r;
            r = p.opNDCIS(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            List <int> ii = new List <int>();
            ii.Add(1);
            ii.Add(2);
            Dictionary <string, List <int> > i = new Dictionary <string, List <int> >();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary <string, List <int> > o;
            Dictionary <string, List <int> > r;
            r = p.opNDGIS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            string[] ii = new string[] { "a", "b" };
            Dictionary <string, string[]> i = new Dictionary <string, string[]>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary <string, string[]> o;
            Dictionary <string, string[]> r;
            r = p.opNDASS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            CSS ii = new CSS();
            ii.Add("a");
            ii.Add("b");
            Dictionary <string, CSS> i = new Dictionary <string, CSS>();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary <string, CSS> o;
            Dictionary <string, CSS> r;
            r = p.opNDCSS(i, out o);

            test(Ice.CollectionComparer.Equals(i, o));
            test(Ice.CollectionComparer.Equals(i, r));
        }

        {
            List <string> ii = new List <string>();
            ii.Add("a");
            ii.Add("b");
            Dictionary <string, List <string> > i = new Dictionary <string, List <string> >();
            i["a"] = ii;
            i["b"] = ii;

            Dictionary <string, List <string> > o;
            Dictionary <string, List <string> > r;
            r = p.opNDGSS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            int[] ii = new int[] { 1, 2 };
            ODAIS i  = new ODAIS();
            i["a"] = ii;
            i["b"] = ii;

            ODAIS o;
            ODAIS r;
            r = p.opODAIS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            CIS ii = new CIS();
            ii.Add(1);
            ii.Add(2);
            ODCIS i = new ODCIS();
            i["a"] = ii;
            i["b"] = ii;

            ODCIS o;
            ODCIS r;
            r = p.opODCIS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            List <int> ii = new List <int>();
            ii.Add(1);
            ii.Add(2);
            ODGIS i = new ODGIS();
            i["a"] = ii;
            i["b"] = ii;

            ODGIS o;
            ODGIS r;
            r = p.opODGIS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            string[] ii = new string[] { "a", "b" };
            ODASS    i  = new ODASS();
            i["a"] = ii;
            i["b"] = ii;

            ODASS o;
            ODASS r;
            r = p.opODASS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            CSS ii = new CSS();
            ii.Add("a");
            ii.Add("b");
            ODCSS i = new ODCSS();
            i["a"] = ii;
            i["b"] = ii;

            ODCSS o;
            ODCSS r;
            r = p.opODCSS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }

        {
            List <string> ii = new List <string>();
            ii.Add("a");
            ii.Add("b");
            ODGSS i = new ODGSS();
            i["a"] = ii;
            i["b"] = ii;

            ODGSS o;
            ODGSS r;
            r = p.opODGSS(i, out o);

            foreach (string key in i.Keys)
            {
                test(Ice.CollectionComparer.Equals(i[key], o[key]));
                test(Ice.CollectionComparer.Equals(i[key], r[key]));
            }
        }
    }
Example #5
0
        /// <summary>Dumps an ATA device</summary>
        public void Ata()
        {
            if (_dumpRaw)
            {
                if (_force)
                {
                    ErrorMessage?.Invoke("Raw dumping not yet supported in ATA devices, continuing...");
                }
                else
                {
                    StoppingErrorMessage?.Invoke("Raw dumping not yet supported in ATA devices, aborting...");

                    return;
                }
            }

            const ushort ATA_PROFILE        = 0x0001;
            const uint   TIMEOUT            = 5;
            double       imageWriteDuration = 0;
            MediaType    mediaType          = MediaType.Unknown;

            UpdateStatus?.Invoke("Requesting ATA IDENTIFY DEVICE.");
            _dumpLog.WriteLine("Requesting ATA IDENTIFY DEVICE.");
            bool sense = _dev.AtaIdentify(out byte[] cmdBuf, out _);

            if (!sense &&
                Identify.Decode(cmdBuf).HasValue)
            {
                Identify.IdentifyDevice?ataIdNullable = Identify.Decode(cmdBuf);

                if (ataIdNullable != null)
                {
                    Identify.IdentifyDevice ataId = ataIdNullable.Value;
                    byte[] ataIdentify            = cmdBuf;
                    cmdBuf = new byte[0];

                    DateTime start;
                    DateTime end;
                    double   totalDuration = 0;
                    double   currentSpeed  = 0;
                    double   maxSpeed      = double.MinValue;
                    double   minSpeed      = double.MaxValue;

                    // Initializate reader
                    UpdateStatus?.Invoke("Initializing reader.");
                    _dumpLog.WriteLine("Initializing reader.");
                    var ataReader = new Reader(_dev, TIMEOUT, ataIdentify);

                    // Fill reader blocks
                    ulong blocks = ataReader.GetDeviceBlocks();

                    // Check block sizes
                    if (ataReader.GetBlockSize())
                    {
                        _dumpLog.WriteLine("ERROR: Cannot get block size: {0}.", ataReader.ErrorMessage);
                        ErrorMessage(ataReader.ErrorMessage);

                        return;
                    }

                    uint blockSize          = ataReader.LogicalBlockSize;
                    uint physicalsectorsize = ataReader.PhysicalBlockSize;

                    if (ataReader.FindReadCommand())
                    {
                        _dumpLog.WriteLine("ERROR: Cannot find correct read command: {0}.", ataReader.ErrorMessage);
                        ErrorMessage(ataReader.ErrorMessage);

                        return;
                    }

                    // Check how many blocks to read, if error show and return
                    if (ataReader.GetBlocksToRead(_maximumReadable))
                    {
                        _dumpLog.WriteLine("ERROR: Cannot get blocks to read: {0}.", ataReader.ErrorMessage);
                        ErrorMessage(ataReader.ErrorMessage);

                        return;
                    }

                    uint   blocksToRead = ataReader.BlocksToRead;
                    ushort cylinders    = ataReader.Cylinders;
                    byte   heads        = ataReader.Heads;
                    byte   sectors      = ataReader.Sectors;

                    UpdateStatus?.Invoke($"Device reports {blocks} blocks ({blocks * blockSize} bytes).");

                    UpdateStatus?.
                    Invoke($"Device reports {cylinders} cylinders {heads} heads {sectors} sectors per track.");

                    UpdateStatus?.Invoke($"Device can read {blocksToRead} blocks at a time.");
                    UpdateStatus?.Invoke($"Device reports {blockSize} bytes per logical block.");
                    UpdateStatus?.Invoke($"Device reports {physicalsectorsize} bytes per physical block.");
                    _dumpLog.WriteLine("Device reports {0} blocks ({1} bytes).", blocks, blocks * blockSize);

                    _dumpLog.WriteLine("Device reports {0} cylinders {1} heads {2} sectors per track.", cylinders,
                                       heads, sectors);

                    _dumpLog.WriteLine("Device can read {0} blocks at a time.", blocksToRead);
                    _dumpLog.WriteLine("Device reports {0} bytes per logical block.", blockSize);
                    _dumpLog.WriteLine("Device reports {0} bytes per physical block.", physicalsectorsize);

                    bool removable = !_dev.IsCompactFlash &&
                                     ataId.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.Removable);

                    DumpHardwareType currentTry = null;
                    ExtentsULong     extents    = null;

                    ResumeSupport.Process(ataReader.IsLba, removable, blocks, _dev.Manufacturer, _dev.Model,
                                          _dev.Serial, _dev.PlatformId, ref _resume, ref currentTry, ref extents,
                                          _dev.FirmwareRevision, _private);

                    if (currentTry == null ||
                        extents == null)
                    {
                        StoppingErrorMessage?.Invoke("Could not process resume file, not continuing...");

                        return;
                    }

                    MhddLog mhddLog;
                    IbgLog  ibgLog;
                    double  duration;

                    bool ret = true;

                    if (_dev.IsUsb &&
                        _dev.UsbDescriptors != null &&
                        !_outputPlugin.SupportedMediaTags.Contains(MediaTagType.USB_Descriptors))
                    {
                        ret = false;
                        _dumpLog.WriteLine("Output format does not support USB descriptors.");
                        ErrorMessage("Output format does not support USB descriptors.");
                    }

                    if (_dev.IsPcmcia &&
                        _dev.Cis != null &&
                        !_outputPlugin.SupportedMediaTags.Contains(MediaTagType.PCMCIA_CIS))
                    {
                        ret = false;
                        _dumpLog.WriteLine("Output format does not support PCMCIA CIS descriptors.");
                        ErrorMessage("Output format does not support PCMCIA CIS descriptors.");
                    }

                    if (!_outputPlugin.SupportedMediaTags.Contains(MediaTagType.ATA_IDENTIFY))
                    {
                        ret = false;
                        _dumpLog.WriteLine("Output format does not support ATA IDENTIFY.");
                        ErrorMessage("Output format does not support ATA IDENTIFY.");
                    }

                    if (!ret)
                    {
                        _dumpLog.WriteLine("Several media tags not supported, {0}continuing...", _force ? "" : "not ");

                        if (_force)
                        {
                            ErrorMessage("Several media tags not supported, continuing...");
                        }
                        else
                        {
                            StoppingErrorMessage?.Invoke("Several media tags not supported, not continuing...");

                            return;
                        }
                    }

                    mediaType = MediaTypeFromDevice.GetFromAta(_dev.Manufacturer, _dev.Model, _dev.IsRemovable,
                                                               _dev.IsCompactFlash, _dev.IsPcmcia, blocks, blockSize);

                    ret = _outputPlugin.Create(_outputPath, mediaType, _formatOptions, blocks, blockSize);

                    // Cannot create image
                    if (!ret)
                    {
                        _dumpLog.WriteLine("Error creating output image, not continuing.");
                        _dumpLog.WriteLine(_outputPlugin.ErrorMessage);

                        StoppingErrorMessage?.Invoke("Error creating output image, not continuing." +
                                                     Environment.NewLine + _outputPlugin.ErrorMessage);

                        return;
                    }

                    // Setting geometry
                    _outputPlugin.SetGeometry(cylinders, heads, sectors);

                    if (ataReader.IsLba)
                    {
                        UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");

                        if (_skip < blocksToRead)
                        {
                            _skip = blocksToRead;
                        }

                        mhddLog = new MhddLog(_outputPrefix + ".mhddlog.bin", _dev, blocks, blockSize, blocksToRead,
                                              _private);

                        ibgLog = new IbgLog(_outputPrefix + ".ibg", ATA_PROFILE);

                        if (_resume.NextBlock > 0)
                        {
                            UpdateStatus?.Invoke($"Resuming from block {_resume.NextBlock}.");
                            _dumpLog.WriteLine("Resuming from block {0}.", _resume.NextBlock);
                        }

                        bool newTrim = false;

                        start = DateTime.UtcNow;
                        DateTime timeSpeedStart   = DateTime.UtcNow;
                        ulong    sectorSpeedStart = 0;
                        InitProgress?.Invoke();

                        for (ulong i = _resume.NextBlock; i < blocks; i += blocksToRead)
                        {
                            if (_aborted)
                            {
                                currentTry.Extents = ExtentsConverter.ToMetadata(extents);
                                UpdateStatus?.Invoke("Aborted!");
                                _dumpLog.WriteLine("Aborted!");

                                break;
                            }

                            if (blocks - i < blocksToRead)
                            {
                                blocksToRead = (byte)(blocks - i);
                            }

                            #pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
                            if (currentSpeed > maxSpeed &&
                                currentSpeed != 0)
                            {
                                maxSpeed = currentSpeed;
                            }

                            if (currentSpeed < minSpeed &&
                                currentSpeed != 0)
                            {
                                minSpeed = currentSpeed;
                            }
                            #pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator

                            UpdateProgress?.Invoke($"Reading sector {i} of {blocks} ({currentSpeed:F3} MiB/sec.)",
                                                   (long)i, (long)blocks);

                            bool error = ataReader.ReadBlocks(out cmdBuf, i, blocksToRead, out duration);

                            if (!error)
                            {
                                mhddLog.Write(i, duration);
                                ibgLog.Write(i, currentSpeed * 1024);
                                DateTime writeStart = DateTime.Now;
                                _outputPlugin.WriteSectors(cmdBuf, i, blocksToRead);
                                imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
                                extents.Add(i, blocksToRead, true);
                            }
                            else
                            {
                                if (i + _skip > blocks)
                                {
                                    _skip = (uint)(blocks - i);
                                }

                                for (ulong b = i; b < i + _skip; b++)
                                {
                                    _resume.BadBlocks.Add(b);
                                }

                                mhddLog.Write(i, duration < 500 ? 65535 : duration);

                                ibgLog.Write(i, 0);
                                DateTime writeStart = DateTime.Now;
                                _outputPlugin.WriteSectors(new byte[blockSize * _skip], i, _skip);
                                imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
                                _dumpLog.WriteLine("Skipping {0} blocks from errored block {1}.", _skip, i);
                                i      += _skip - blocksToRead;
                                newTrim = true;
                            }

                            sectorSpeedStart += blocksToRead;
                            _resume.NextBlock = i + blocksToRead;

                            double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;

                            if (elapsed < 1)
                            {
                                continue;
                            }

                            currentSpeed     = (sectorSpeedStart * blockSize) / (1048576 * elapsed);
                            sectorSpeedStart = 0;
                            timeSpeedStart   = DateTime.UtcNow;
                        }

                        end = DateTime.Now;
                        EndProgress?.Invoke();
                        mhddLog.Close();

                        ibgLog.Close(_dev, blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
                                     (blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000), _devicePath);

                        UpdateStatus?.Invoke($"Dump finished in {(end - start).TotalSeconds} seconds.");

                        UpdateStatus?.
                        Invoke($"Average dump speed {((double)blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000):F3} KiB/sec.");

                        UpdateStatus?.
                        Invoke($"Average write speed {((double)blockSize * (double)(blocks + 1)) / 1024 / imageWriteDuration:F3} KiB/sec.");

                        _dumpLog.WriteLine("Dump finished in {0} seconds.", (end - start).TotalSeconds);

                        _dumpLog.WriteLine("Average dump speed {0:F3} KiB/sec.",
                                           ((double)blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000));

                        _dumpLog.WriteLine("Average write speed {0:F3} KiB/sec.",
                                           ((double)blockSize * (double)(blocks + 1)) / 1024 / imageWriteDuration);

                        #region Trimming
                        if (_resume.BadBlocks.Count > 0 &&
                            !_aborted &&
                            _trim &&
                            newTrim)
                        {
                            start = DateTime.UtcNow;
                            UpdateStatus?.Invoke("Trimming skipped sectors");
                            _dumpLog.WriteLine("Trimming skipped sectors");

                            ulong[] tmpArray = _resume.BadBlocks.ToArray();
                            InitProgress?.Invoke();

                            foreach (ulong badSector in tmpArray)
                            {
                                if (_aborted)
                                {
                                    currentTry.Extents = ExtentsConverter.ToMetadata(extents);
                                    UpdateStatus?.Invoke("Aborted!");
                                    _dumpLog.WriteLine("Aborted!");

                                    break;
                                }

                                PulseProgress?.Invoke($"Trimming sector {badSector}");

                                bool error = ataReader.ReadBlock(out cmdBuf, badSector, out duration);

                                totalDuration += duration;

                                if (error)
                                {
                                    continue;
                                }

                                _resume.BadBlocks.Remove(badSector);
                                extents.Add(badSector);
                                _outputPlugin.WriteSector(cmdBuf, badSector);
                            }

                            EndProgress?.Invoke();
                            end = DateTime.UtcNow;
                            UpdateStatus?.Invoke($"Trimmming finished in {(end - start).TotalSeconds} seconds.");
                            _dumpLog.WriteLine("Trimmming finished in {0} seconds.", (end - start).TotalSeconds);
                        }
                        #endregion Trimming

                        #region Error handling
                        if (_resume.BadBlocks.Count > 0 &&
                            !_aborted &&
                            _retryPasses > 0)
                        {
                            int  pass    = 1;
                            bool forward = true;

                            InitProgress?.Invoke();
repeatRetryLba:
                            ulong[] tmpArray = _resume.BadBlocks.ToArray();

                            foreach (ulong badSector in tmpArray)
                            {
                                if (_aborted)
                                {
                                    currentTry.Extents = ExtentsConverter.ToMetadata(extents);
                                    UpdateStatus?.Invoke("Aborted!");
                                    _dumpLog.WriteLine("Aborted!");

                                    break;
                                }

                                PulseProgress?.Invoke(string.Format("Retrying sector {0}, pass {1}, {3}{2}", badSector,
                                                                    pass, forward ? "forward" : "reverse",
                                                                    _persistent ? "recovering partial data, " : ""));

                                bool error = ataReader.ReadBlock(out cmdBuf, badSector, out duration);

                                totalDuration += duration;

                                if (!error)
                                {
                                    _resume.BadBlocks.Remove(badSector);
                                    extents.Add(badSector);
                                    _outputPlugin.WriteSector(cmdBuf, badSector);
                                    UpdateStatus?.Invoke($"Correctly retried block {badSector} in pass {pass}.");
                                    _dumpLog.WriteLine("Correctly retried block {0} in pass {1}.", badSector, pass);
                                }
                                else if (_persistent)
                                {
                                    _outputPlugin.WriteSector(cmdBuf, badSector);
                                }
                            }

                            if (pass < _retryPasses &&
                                !_aborted &&
                                _resume.BadBlocks.Count > 0)
                            {
                                pass++;
                                forward = !forward;
                                _resume.BadBlocks.Sort();

                                if (!forward)
                                {
                                    _resume.BadBlocks.Reverse();
                                }

                                goto repeatRetryLba;
                            }

                            EndProgress?.Invoke();
                        }
                        #endregion Error handling LBA

                        currentTry.Extents = ExtentsConverter.ToMetadata(extents);
                    }
                    else
                    {
                        mhddLog = new MhddLog(_outputPrefix + ".mhddlog.bin", _dev, blocks, blockSize, blocksToRead,
                                              _private);

                        ibgLog = new IbgLog(_outputPrefix + ".ibg", ATA_PROFILE);

                        ulong currentBlock = 0;
                        blocks = (ulong)(cylinders * heads * sectors);
                        start  = DateTime.UtcNow;
                        DateTime timeSpeedStart   = DateTime.UtcNow;
                        ulong    sectorSpeedStart = 0;
                        InitProgress?.Invoke();

                        for (ushort cy = 0; cy < cylinders; cy++)
                        {
                            for (byte hd = 0; hd < heads; hd++)
                            {
                                for (byte sc = 1; sc < sectors; sc++)
                                {
                                    if (_aborted)
                                    {
                                        currentTry.Extents = ExtentsConverter.ToMetadata(extents);
                                        UpdateStatus?.Invoke("Aborted!");
                                        _dumpLog.WriteLine("Aborted!");

                                        break;
                                    }

                                    #pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
                                    if (currentSpeed > maxSpeed &&
                                        currentSpeed != 0)
                                    {
                                        maxSpeed = currentSpeed;
                                    }

                                    if (currentSpeed < minSpeed &&
                                        currentSpeed != 0)
                                    {
                                        minSpeed = currentSpeed;
                                    }
                                    #pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator

                                    PulseProgress?.
                                    Invoke($"Reading cylinder {cy} head {hd} sector {sc} ({currentSpeed:F3} MiB/sec.)");

                                    bool error = ataReader.ReadChs(out cmdBuf, cy, hd, sc, out duration);

                                    totalDuration += duration;

                                    if (!error)
                                    {
                                        mhddLog.Write(currentBlock, duration);
                                        ibgLog.Write(currentBlock, currentSpeed * 1024);
                                        DateTime writeStart = DateTime.Now;

                                        _outputPlugin.WriteSector(cmdBuf,
                                                                  (ulong)((((cy * heads) + hd) * sectors) + (sc - 1)));

                                        imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
                                        extents.Add(currentBlock);

                                        _dumpLog.WriteLine("Error reading cylinder {0} head {1} sector {2}.", cy, hd,
                                                           sc);
                                    }
                                    else
                                    {
                                        _resume.BadBlocks.Add(currentBlock);
                                        mhddLog.Write(currentBlock, duration < 500 ? 65535 : duration);

                                        ibgLog.Write(currentBlock, 0);
                                        DateTime writeStart = DateTime.Now;

                                        _outputPlugin.WriteSector(new byte[blockSize],
                                                                  (ulong)((((cy * heads) + hd) * sectors) + (sc - 1)));

                                        imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
                                    }

                                    sectorSpeedStart++;
                                    currentBlock++;

                                    double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;

                                    if (elapsed < 1)
                                    {
                                        continue;
                                    }

                                    currentSpeed     = (sectorSpeedStart * blockSize) / (1048576 * elapsed);
                                    sectorSpeedStart = 0;
                                    timeSpeedStart   = DateTime.UtcNow;
                                }
                            }
                        }

                        end = DateTime.Now;
                        EndProgress?.Invoke();
                        mhddLog.Close();

                        ibgLog.Close(_dev, blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
                                     (blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000), _devicePath);

                        UpdateStatus?.Invoke($"Dump finished in {(end - start).TotalSeconds} seconds.");

                        UpdateStatus?.
                        Invoke($"Average dump speed {((double)blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000):F3} KiB/sec.");

                        UpdateStatus?.
                        Invoke($"Average write speed {((double)blockSize * (double)(blocks + 1)) / 1024 / (imageWriteDuration / 1000):F3} KiB/sec.");

                        _dumpLog.WriteLine("Dump finished in {0} seconds.", (end - start).TotalSeconds);

                        _dumpLog.WriteLine("Average dump speed {0:F3} KiB/sec.",
                                           ((double)blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000));

                        _dumpLog.WriteLine("Average write speed {0:F3} KiB/sec.",
                                           ((double)blockSize * (double)(blocks + 1)) / 1024 /
                                           (imageWriteDuration / 1000));
                    }

                    foreach (ulong bad in _resume.BadBlocks)
                    {
                        _dumpLog.WriteLine("Sector {0} could not be read.", bad);
                    }

                    _outputPlugin.SetDumpHardware(_resume.Tries);

                    // TODO: Non-removable
                    var metadata = new CommonTypes.Structs.ImageInfo
                    {
                        Application = "Aaru", ApplicationVersion = Version.GetVersion()
                    };

                    if (!_outputPlugin.SetMetadata(metadata))
                    {
                        ErrorMessage?.Invoke("Error {0} setting metadata, continuing..." + Environment.NewLine +
                                             _outputPlugin.ErrorMessage);
                    }

                    if (_preSidecar != null)
                    {
                        _outputPlugin.SetCicmMetadata(_preSidecar);
                    }

                    _dumpLog.WriteLine("Closing output file.");
                    UpdateStatus?.Invoke("Closing output file.");
                    DateTime closeStart = DateTime.Now;
                    _outputPlugin.Close();
                    DateTime closeEnd = DateTime.Now;
                    UpdateStatus?.Invoke($"Closed in {(closeEnd - closeStart).TotalSeconds} seconds.");
                    _dumpLog.WriteLine("Closed in {0} seconds.", (closeEnd - closeStart).TotalSeconds);

                    if (_aborted)
                    {
                        _dumpLog.WriteLine("Aborted!");
                        UpdateStatus?.Invoke("Aborted!");

                        return;
                    }

                    double totalChkDuration = 0;

                    if (_metadata)
                    {
                        _dumpLog.WriteLine("Creating sidecar.");
                        UpdateStatus?.Invoke("Creating sidecar.");
                        var         filters     = new FiltersList();
                        IFilter     filter      = filters.GetFilter(_outputPath);
                        IMediaImage inputPlugin = ImageFormat.Detect(filter);

                        if (!inputPlugin.Open(filter))
                        {
                            StoppingErrorMessage?.Invoke("Could not open created image.");

                            return;
                        }

                        DateTime chkStart = DateTime.UtcNow;

                        _sidecarClass = new Sidecar(inputPlugin, _outputPath, filter.Id, _encoding);

                        _sidecarClass.InitProgressEvent    += InitProgress;
                        _sidecarClass.UpdateProgressEvent  += UpdateProgress;
                        _sidecarClass.EndProgressEvent     += EndProgress;
                        _sidecarClass.InitProgressEvent2   += InitProgress2;
                        _sidecarClass.UpdateProgressEvent2 += UpdateProgress2;
                        _sidecarClass.EndProgressEvent2    += EndProgress2;
                        _sidecarClass.UpdateStatusEvent    += UpdateStatus;
                        CICMMetadataType sidecar = _sidecarClass.Create();

                        if (_preSidecar != null)
                        {
                            _preSidecar.BlockMedia = sidecar.BlockMedia;
                            sidecar = _preSidecar;
                        }

                        if (_dev.IsUsb &&
                            _dev.UsbDescriptors != null)
                        {
                            _dumpLog.WriteLine("Reading USB descriptors.");
                            UpdateStatus?.Invoke("Reading USB descriptors.");
                            ret = _outputPlugin.WriteMediaTag(_dev.UsbDescriptors, MediaTagType.USB_Descriptors);

                            if (ret)
                            {
                                sidecar.BlockMedia[0].USB = new USBType
                                {
                                    ProductID = _dev.UsbProductId, VendorID = _dev.UsbVendorId, Descriptors =
                                        new DumpType
                                    {
                                        Image     = _outputPath, Size = (ulong)_dev.UsbDescriptors.Length,
                                        Checksums = Checksum.GetChecksums(_dev.UsbDescriptors).ToArray()
                                    }
                                }
                            }
                            ;
                        }

                        if (_dev.IsPcmcia &&
                            _dev.Cis != null)
                        {
                            _dumpLog.WriteLine("Reading PCMCIA CIS.");
                            UpdateStatus?.Invoke("Reading PCMCIA CIS.");
                            ret = _outputPlugin.WriteMediaTag(_dev.Cis, MediaTagType.PCMCIA_CIS);

                            if (ret)
                            {
                                sidecar.BlockMedia[0].PCMCIA = new PCMCIAType
                                {
                                    CIS = new DumpType
                                    {
                                        Image     = _outputPath, Size = (ulong)_dev.Cis.Length,
                                        Checksums = Checksum.GetChecksums(_dev.Cis).ToArray()
                                    }
                                }
                            }
                            ;

                            _dumpLog.WriteLine("Decoding PCMCIA CIS.");
                            UpdateStatus?.Invoke("Decoding PCMCIA CIS.");
                            Tuple[] tuples = CIS.GetTuples(_dev.Cis);

                            if (tuples != null)
                            {
                                foreach (Tuple tuple in tuples)
                                {
                                    switch (tuple.Code)
                                    {
                                    case TupleCodes.CISTPL_MANFID:
                                        ManufacturerIdentificationTuple manfid =
                                            CIS.DecodeManufacturerIdentificationTuple(tuple);

                                        if (manfid != null)
                                        {
                                            sidecar.BlockMedia[0].PCMCIA.ManufacturerCode = manfid.ManufacturerID;

                                            sidecar.BlockMedia[0].PCMCIA.CardCode = manfid.CardID;
                                            sidecar.BlockMedia[0].PCMCIA.ManufacturerCodeSpecified = true;
                                            sidecar.BlockMedia[0].PCMCIA.CardCodeSpecified         = true;
                                        }

                                        break;

                                    case TupleCodes.CISTPL_VERS_1:
                                        Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple);

                                        if (vers != null)
                                        {
                                            sidecar.BlockMedia[0].PCMCIA.Manufacturer = vers.Manufacturer;
                                            sidecar.BlockMedia[0].PCMCIA.ProductName  = vers.Product;

                                            sidecar.BlockMedia[0].PCMCIA.Compliance =
                                                $"{vers.MajorVersion}.{vers.MinorVersion}";

                                            sidecar.BlockMedia[0].PCMCIA.AdditionalInformation =
                                                vers.AdditionalInformation;
                                        }

                                        break;
                                    }
                                }
                            }
                        }

                        if (!_private)
                        {
                            DeviceReport.ClearIdentify(ataIdentify);
                        }

                        ret = _outputPlugin.WriteMediaTag(ataIdentify, MediaTagType.ATA_IDENTIFY);

                        if (ret)
                        {
                            sidecar.BlockMedia[0].ATA = new ATAType
                            {
                                Identify = new DumpType
                                {
                                    Image     = _outputPath, Size = (ulong)cmdBuf.Length,
                                    Checksums = Checksum.GetChecksums(cmdBuf).ToArray()
                                }
                            }
                        }
                        ;

                        DateTime chkEnd = DateTime.UtcNow;

                        totalChkDuration = (chkEnd - chkStart).TotalMilliseconds;
                        UpdateStatus?.Invoke($"Sidecar created in {(chkEnd - chkStart).TotalSeconds} seconds.");

                        UpdateStatus?.
                        Invoke($"Average checksum speed {((double)blockSize * (double)(blocks + 1)) / 1024 / (totalChkDuration / 1000):F3} KiB/sec.");

                        _dumpLog.WriteLine("Sidecar created in {0} seconds.", (chkEnd - chkStart).TotalSeconds);

                        _dumpLog.WriteLine("Average checksum speed {0:F3} KiB/sec.",
                                           ((double)blockSize * (double)(blocks + 1)) / 1024 /
                                           (totalChkDuration / 1000));

                        List <(ulong start, string type)> filesystems = new List <(ulong start, string type)>();

                        if (sidecar.BlockMedia[0].FileSystemInformation != null)
                        {
                            filesystems.AddRange(from partition in sidecar.BlockMedia[0].FileSystemInformation
                                                 where partition.FileSystems != null
                                                 from fileSystem in partition.FileSystems
                                                 select(partition.StartSector, fileSystem.Type));
                        }

                        if (filesystems.Count > 0)
                        {
                            foreach (var filesystem in filesystems.Select(o => new
                            {
                                o.start, o.type
                            }).Distinct())
                            {
                                UpdateStatus?.
                                Invoke($"Found filesystem {filesystem.type} at sector {filesystem.start}");

                                _dumpLog.WriteLine("Found filesystem {0} at sector {1}", filesystem.type,
                                                   filesystem.start);
                            }
                        }

                        (string type, string subType) = CommonTypes.Metadata.MediaType.MediaTypeToString(mediaType);

                        sidecar.BlockMedia[0].DiskType          = type;
                        sidecar.BlockMedia[0].DiskSubType       = subType;
                        sidecar.BlockMedia[0].Interface         = "ATA";
                        sidecar.BlockMedia[0].LogicalBlocks     = blocks;
                        sidecar.BlockMedia[0].PhysicalBlockSize = physicalsectorsize;
                        sidecar.BlockMedia[0].LogicalBlockSize  = blockSize;
                        sidecar.BlockMedia[0].Manufacturer      = _dev.Manufacturer;
                        sidecar.BlockMedia[0].Model             = _dev.Model;

                        if (!_private)
                        {
                            sidecar.BlockMedia[0].Serial = _dev.Serial;
                        }

                        sidecar.BlockMedia[0].Size = blocks * blockSize;

                        if (cylinders > 0 &&
                            heads > 0 &&
                            sectors > 0)
                        {
                            sidecar.BlockMedia[0].Cylinders          = cylinders;
                            sidecar.BlockMedia[0].CylindersSpecified = true;
                            sidecar.BlockMedia[0].Heads                    = heads;
                            sidecar.BlockMedia[0].HeadsSpecified           = true;
                            sidecar.BlockMedia[0].SectorsPerTrack          = sectors;
                            sidecar.BlockMedia[0].SectorsPerTrackSpecified = true;
                        }

                        UpdateStatus?.Invoke("Writing metadata sidecar");

                        var xmlFs = new FileStream(_outputPrefix + ".cicm.xml", FileMode.Create);

                        var xmlSer = new XmlSerializer(typeof(CICMMetadataType));
                        xmlSer.Serialize(xmlFs, sidecar);
                        xmlFs.Close();
                    }

                    UpdateStatus?.Invoke("");

                    UpdateStatus?.
                    Invoke($"Took a total of {(end - start).TotalSeconds:F3} seconds ({totalDuration / 1000:F3} processing commands, {totalChkDuration / 1000:F3} checksumming, {imageWriteDuration:F3} writing, {(closeEnd - closeStart).TotalSeconds:F3} closing).");

                    UpdateStatus?.
                    Invoke($"Average speed: {((double)blockSize * (double)(blocks + 1)) / 1048576 / (totalDuration / 1000):F3} MiB/sec.");

                    if (maxSpeed > 0)
                    {
                        UpdateStatus?.Invoke($"Fastest speed burst: {maxSpeed:F3} MiB/sec.");
                    }

                    if (minSpeed > 0 &&
                        minSpeed < double.MaxValue)
                    {
                        UpdateStatus?.Invoke($"Slowest speed burst: {minSpeed:F3} MiB/sec.");
                    }

                    UpdateStatus?.Invoke($"{_resume.BadBlocks.Count} sectors could not be read.");

                    if (_resume.BadBlocks.Count > 0)
                    {
                        _resume.BadBlocks.Sort();
                    }

                    UpdateStatus?.Invoke("");
                }

                Statistics.AddMedia(mediaType, true);
            }
            else
            {
                StoppingErrorMessage?.Invoke("Unable to communicate with ATA device.");
            }
        }
    }
}
Example #6
0
        public static void PrintImageInfo(IMediaImage imageFormat)
        {
            AaruConsole.WriteLine("Image information:");

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Version))
            {
                AaruConsole.WriteLine("Format: {0} version {1}", imageFormat.Format, imageFormat.Info.Version);
            }
            else
            {
                AaruConsole.WriteLine("Format: {0}", imageFormat.Format);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Application) &&
                !string.IsNullOrWhiteSpace(imageFormat.Info.ApplicationVersion))
            {
                AaruConsole.WriteLine("Was created with {0} version {1}", imageFormat.Info.Application,
                                      imageFormat.Info.ApplicationVersion);
            }
            else if (!string.IsNullOrWhiteSpace(imageFormat.Info.Application))
            {
                AaruConsole.WriteLine("Was created with {0}", imageFormat.Info.Application);
            }

            AaruConsole.WriteLine("Image without headers is {0} bytes long", imageFormat.Info.ImageSize);

            AaruConsole.
            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))
            {
                AaruConsole.WriteLine("Created by: {0}", imageFormat.Info.Creator);
            }

            if (imageFormat.Info.CreationTime != DateTime.MinValue)
            {
                AaruConsole.WriteLine("Created on {0}", imageFormat.Info.CreationTime);
            }

            if (imageFormat.Info.LastModificationTime != DateTime.MinValue)
            {
                AaruConsole.WriteLine("Last modified on {0}", imageFormat.Info.LastModificationTime);
            }

            AaruConsole.WriteLine("Contains a media of type {0} and XML type {1}", imageFormat.Info.MediaType,
                                  imageFormat.Info.XmlMediaType);

            AaruConsole.WriteLine("{0} partitions", imageFormat.Info.HasPartitions ? "Has" : "Doesn't have");
            AaruConsole.WriteLine("{0} sessions", imageFormat.Info.HasSessions ? "Has" : "Doesn't have");

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.Comments))
            {
                AaruConsole.WriteLine("Comments: {0}", imageFormat.Info.Comments);
            }

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

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaTitle))
            {
                AaruConsole.WriteLine("Media title: {0}", imageFormat.Info.MediaTitle);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaManufacturer))
            {
                AaruConsole.WriteLine("Media manufacturer: {0}", imageFormat.Info.MediaManufacturer);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaModel))
            {
                AaruConsole.WriteLine("Media model: {0}", imageFormat.Info.MediaModel);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaSerialNumber))
            {
                AaruConsole.WriteLine("Media serial number: {0}", imageFormat.Info.MediaSerialNumber);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaBarcode))
            {
                AaruConsole.WriteLine("Media barcode: {0}", imageFormat.Info.MediaBarcode);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.MediaPartNumber))
            {
                AaruConsole.WriteLine("Media part number: {0}", imageFormat.Info.MediaPartNumber);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveManufacturer))
            {
                AaruConsole.WriteLine("Drive manufacturer: {0}", imageFormat.Info.DriveManufacturer);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveModel))
            {
                AaruConsole.WriteLine("Drive model: {0}", imageFormat.Info.DriveModel);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveSerialNumber))
            {
                AaruConsole.WriteLine("Drive serial number: {0}", imageFormat.Info.DriveSerialNumber);
            }

            if (!string.IsNullOrWhiteSpace(imageFormat.Info.DriveFirmwareRevision))
            {
                AaruConsole.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 &&
                (!(imageFormat is ITapeImage tapeImage) || !tapeImage.IsTape))
            {
                AaruConsole.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)
            {
                AaruConsole.WriteLine("Contains {0} readable media tags:", imageFormat.Info.ReadableMediaTags.Count);

                foreach (MediaTagType tag in imageFormat.Info.ReadableMediaTags.OrderBy(t => t))
                {
                    AaruConsole.Write("{0} ", tag);
                }

                AaruConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableSectorTags != null &&
                imageFormat.Info.ReadableSectorTags.Count > 0)
            {
                AaruConsole.WriteLine("Contains {0} readable sector tags:", imageFormat.Info.ReadableSectorTags.Count);

                foreach (SectorTagType tag in imageFormat.Info.ReadableSectorTags.OrderBy(t => t))
                {
                    AaruConsole.Write("{0} ", tag);
                }

                AaruConsole.WriteLine();
            }

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

            byte[] scsiVendorId = null;

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.SCSI_INQUIRY) == true)
            {
                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);
                }

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.ATA_IDENTIFY) == true)
            {
                byte[] identify = imageFormat.ReadDiskTag(MediaTagType.ATA_IDENTIFY);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.ATAPI_IDENTIFY) == true)
            {
                byte[] identify = imageFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY);

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

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

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

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

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.CD_FullTOC) == true)
            {
                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;
                    }

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.CD_PMA) == true)
            {
                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;
                    }

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.CD_ATIP) == true)
            {
                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;
                }

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.CD_TEXT) == true)
            {
                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;
                }

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.CD_MCN) == true)
            {
                byte[] mcn = imageFormat.ReadDiskTag(MediaTagType.CD_MCN);

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

                AaruConsole.WriteLine();
            }

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.DVD_PFI) == true)
            {
                byte[] pfi = imageFormat.ReadDiskTag(MediaTagType.DVD_PFI);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.DVDRAM_DDS) == true)
            {
                byte[] dds = imageFormat.ReadDiskTag(MediaTagType.DVDRAM_DDS);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.DVDR_PFI) == true)
            {
                byte[] pfi = imageFormat.ReadDiskTag(MediaTagType.DVDR_PFI);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.BD_DI) == true)
            {
                byte[] di = imageFormat.ReadDiskTag(MediaTagType.BD_DI);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.BD_DDS) == true)
            {
                byte[] dds = imageFormat.ReadDiskTag(MediaTagType.BD_DDS);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.PCMCIA_CIS) == true)
            {
                byte[] cis = imageFormat.ReadDiskTag(MediaTagType.PCMCIA_CIS);

                AaruConsole.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:
                            AaruConsole.WriteLine("{0}", CIS.PrettifyDeviceGeometryTuple(tuple));

                            break;

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

                            break;

                        case TupleCodes.CISTPL_VERS_1:
                            AaruConsole.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:
                            AaruConsole.DebugWriteLine("Device-Info command", "Found undecoded tuple ID {0}",
                                                       tuple.Code);

                            break;

                        default:
                            AaruConsole.DebugWriteLine("Device-Info command", "Found unknown tuple ID 0x{0:X2}",
                                                       (byte)tuple.Code);

                            break;
                        }
                    }
                }
                else
                {
                    AaruConsole.DebugWriteLine("Device-Info command", "Could not get tuples");
                }
            }

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.SD_CID) == true)
            {
                byte[] cid = imageFormat.ReadDiskTag(MediaTagType.SD_CID);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.SD_CSD) == true)
            {
                byte[] csd = imageFormat.ReadDiskTag(MediaTagType.SD_CSD);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.SD_SCR) == true)
            {
                byte[] scr = imageFormat.ReadDiskTag(MediaTagType.SD_SCR);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.SD_OCR) == true)
            {
                byte[] ocr = imageFormat.ReadDiskTag(MediaTagType.SD_OCR);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.MMC_CID) == true)
            {
                byte[] cid = imageFormat.ReadDiskTag(MediaTagType.MMC_CID);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.MMC_CSD) == true)
            {
                byte[] csd = imageFormat.ReadDiskTag(MediaTagType.MMC_CSD);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.MMC_ExtendedCSD) == true)
            {
                byte[] ecsd = imageFormat.ReadDiskTag(MediaTagType.MMC_ExtendedCSD);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.MMC_OCR) == true)
            {
                byte[] ocr = imageFormat.ReadDiskTag(MediaTagType.MMC_OCR);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.Xbox_PFI) == true)
            {
                byte[] xpfi = imageFormat.ReadDiskTag(MediaTagType.Xbox_PFI);

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

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.Xbox_DMI) == true)
            {
                byte[] xdmi = imageFormat.ReadDiskTag(MediaTagType.Xbox_DMI);

                if (DMI.IsXbox(xdmi))
                {
                    DMI.XboxDMI?xmi = DMI.DecodeXbox(xdmi);

                    if (xmi.HasValue)
                    {
                        AaruConsole.WriteLine("Xbox DMI contained in image:");
                        AaruConsole.Write("{0}", DMI.PrettifyXbox(xmi));
                        AaruConsole.WriteLine();
                    }
                }

                if (DMI.IsXbox360(xdmi))
                {
                    DMI.Xbox360DMI?xmi = DMI.DecodeXbox360(xdmi);

                    if (xmi.HasValue)
                    {
                        AaruConsole.WriteLine("Xbox 360 DMI contained in image:");
                        AaruConsole.Write("{0}", DMI.PrettifyXbox360(xmi));
                        AaruConsole.WriteLine();
                    }
                }
            }

            if (imageFormat.Info.ReadableMediaTags?.Contains(MediaTagType.Xbox_SecuritySector) == true)
            {
                byte[] toc = imageFormat.ReadDiskTag(MediaTagType.Xbox_SecuritySector);

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

            if (imageFormat is IOpticalMediaImage opticalImage)
            {
                try
                {
                    if (opticalImage.Sessions != null &&
                        opticalImage.Sessions.Count > 0)
                    {
                        AaruConsole.WriteLine("Image sessions:");

                        AaruConsole.WriteLine("{0,-9}{1,-13}{2,-12}{3,-12}{4,-12}", "Session", "First track",
                                              "Last track", "Start", "End");

                        AaruConsole.WriteLine("=========================================================");

                        foreach (Session session in opticalImage.Sessions)
                        {
                            AaruConsole.WriteLine("{0,-9}{1,-13}{2,-12}{3,-12}{4,-12}", session.SessionSequence,
                                                  session.StartTrack, session.EndTrack, session.StartSector,
                                                  session.EndSector);
                        }

                        AaruConsole.WriteLine();
                    }
                }
                catch
                {
                    // ignored
                }

                try
                {
                    if (opticalImage.Tracks != null &&
                        opticalImage.Tracks.Count > 0)
                    {
                        AaruConsole.WriteLine("Image tracks:");

                        AaruConsole.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");

                        AaruConsole.
                        WriteLine("=================================================================================");

                        foreach (Track track in opticalImage.Tracks)
                        {
                            AaruConsole.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);
                        }

                        AaruConsole.WriteLine();

                        AaruConsole.WriteLine("Track indexes:");

                        AaruConsole.WriteLine("{0,-7}{1,-7}{2,-12}", "Track", "Index", "Start");

                        AaruConsole.WriteLine("=======================");

                        foreach (Track track in opticalImage.Tracks)
                        {
                            foreach (KeyValuePair <ushort, int> index in track.Indexes)
                            {
                                AaruConsole.WriteLine("{0,-7}{1,-7}{2,-12}", track.TrackSequence, index.Key,
                                                      index.Value);
                            }
                        }
                    }
                }
                catch
                {
                    // ignored
                }
                finally
                {
                    AaruConsole.WriteLine();
                }
            }

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

            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}}}";

            AaruConsole.WriteLine("Dump hardware information:");

            AaruConsole.WriteLine(format, MANUFACTURER_STRING, MODEL_STRING, SERIAL_STRING, SOFTWARE_STRING,
                                  VERSION_STRING, OS_STRING, START_STRING, END_STRING);

            AaruConsole.WriteLine(new string(separator));

            foreach (DumpHardwareType dump in imageFormat.DumpHardware)
            {
                foreach (ExtentType extent in dump.Extents)
                {
                    AaruConsole.WriteLine(format, dump.Manufacturer, dump.Model, dump.Serial, dump.Software.Name,
                                          dump.Software.Version, dump.Software.OperatingSystem, extent.Start,
                                          extent.End);
                }
            }

            AaruConsole.WriteLine();
        }
Example #7
0
    internal static void twowaysAMI(Ice.Communicator communicator, Test.MyClassPrx p)
    {
        {
            Dictionary <int, int> i = new Dictionary <int, int>();
            i[0] = 1;
            i[1] = 0;

            Callback cb = new Callback();
            p.begin_opNV(i, null, cb.opNVI, i);
            cb.check();
        }

        {
            Dictionary <string, string> i = new Dictionary <string, string>();
            i["a"] = "b";
            i["b"] = "a";

            Callback cb = new Callback();
            p.begin_opNR(i, null, cb.opNRI, i);
            cb.check();
        }

        {
            Dictionary <string, Dictionary <int, int> > i = new Dictionary <string, Dictionary <int, int> >();
            Dictionary <int, int> id = new Dictionary <int, int>();
            id[0]  = 1;
            id[1]  = 0;
            i["a"] = id;
            i["b"] = id;

            Callback cb = new Callback();
            p.begin_opNDV(i, null, cb.opNDVI, i);
            cb.check();
        }

        {
            Dictionary <string, Dictionary <string, string> > i = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, string> id = new Dictionary <string, string>();
            id["a"] = "b";
            id["b"] = "a";
            i["a"]  = id;
            i["b"]  = id;

            Callback cb = new Callback();
            p.begin_opNDR(i, null, cb.opNDRI, i);
            cb.check();
        }

        {
            OV i = new OV();
            i[0] = 1;
            i[1] = 0;

            Callback cb = new Callback();
            p.begin_opOV(i, null, cb.opOVI, i);
            cb.check();
        }

        {
            OR i = new OR();
            i["a"] = "b";
            i["b"] = "a";

            Callback cb = new Callback();
            p.begin_opOR(i, null, cb.opORI, i);
            cb.check();
        }

        {
            ODV i  = new ODV();
            OV  id = new OV();
            id[0]  = 1;
            id[1]  = 0;
            i["a"] = id;
            i["b"] = id;

            Callback cb = new Callback();
            p.begin_opODV(i, null, cb.opODVI, i);
            cb.check();
        }

        {
            ODR i  = new ODR();
            OR  id = new OR();
            id["a"] = "b";
            id["b"] = "a";
            i["a"]  = id;
            i["b"]  = id;

            Callback cb = new Callback();
            p.begin_opODR(i, null, cb.opODRI, i);
            cb.check();
        }

        {
            Dictionary <string, ODV> i = new Dictionary <string, ODV>();
            OV iid = new OV();
            iid[0] = 1;
            iid[1] = 0;
            ODV id = new ODV();
            id["a"] = iid;
            id["b"] = iid;
            i["a"]  = id;
            i["b"]  = id;

            Callback cb = new Callback();
            p.begin_opNODV(i, null, cb.opNODVI, i);
            cb.check();
        }

        {
            Dictionary <string, ODR> i = new Dictionary <string, ODR>();
            OR iid = new OR();
            iid["a"] = "b";
            iid["b"] = "a";
            ODR id = new ODR();
            id["a"] = iid;
            id["b"] = iid;
            i["a"]  = id;
            i["b"]  = id;

            Callback cb = new Callback();
            p.begin_opNODR(i, null, cb.opNODRI, i);
            cb.check();
        }

        {
            ONDV i = new ONDV();
            Dictionary <int, int> iid = new Dictionary <int, int>();
            iid[0] = 1;
            iid[1] = 0;
            Dictionary <string, Dictionary <int, int> > id
                    = new Dictionary <string, Dictionary <int, int> >();
            id["a"] = iid;
            id["b"] = iid;
            i["a"]  = id;
            i["b"]  = id;

            Callback cb = new Callback();
            p.begin_opONDV(i, null, cb.opONDVI, i);
            cb.check();
        }

        {
            ONDR i = new ONDR();
            Dictionary <string, string> iid = new Dictionary <string, string>();
            iid["a"] = "b";
            iid["b"] = "a";
            Dictionary <string, Dictionary <string, string> > id
                    = new Dictionary <string, Dictionary <string, string> >();
            id["a"] = iid;
            id["b"] = iid;
            i["a"]  = id;
            i["b"]  = id;

            Callback cb = new Callback();
            p.begin_opONDR(i, null, cb.opONDRI, i);
            cb.check();
        }

        {
            int[] ii = new int[] { 1, 2 };
            Dictionary <string, int[]> i = new Dictionary <string, int[]>();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opNDAIS(i, null, cb.opNDAISI, i);
            cb.check();
        }

        {
            CIS ii = new CIS();
            ii.Add(1);
            ii.Add(2);
            Dictionary <string, CIS> i = new Dictionary <string, CIS>();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opNDCIS(i, null, cb.opNDCISI, i);
            cb.check();
        }

        {
            List <int> ii = new List <int>();
            ii.Add(1);
            ii.Add(2);
            Dictionary <string, List <int> > i = new Dictionary <string, List <int> >();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opNDGIS(i, null, cb.opNDGISI, i);
            cb.check();
        }

        {
            string[] ii = new string[] { "a", "b" };
            Dictionary <string, string[]> i = new Dictionary <string, string[]>();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opNDASS(i, null, cb.opNDASSI, i);
            cb.check();
        }

        {
            CSS ii = new CSS();
            ii.Add("a");
            ii.Add("b");
            Dictionary <string, CSS> i = new Dictionary <string, CSS>();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opNDCSS(i, null, cb.opNDCSSI, i);
            cb.check();
        }

        {
            List <string> ii = new List <string>();
            ii.Add("a");
            ii.Add("b");
            Dictionary <string, List <string> > i = new Dictionary <string, List <string> >();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opNDGSS(i, null, cb.opNDGSSI, i);
            cb.check();
        }

        {
            int[] ii = new int[] { 1, 2 };
            ODAIS i  = new ODAIS();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opODAIS(i, null, cb.opODAISI, i);
            cb.check();
        }

        {
            CIS ii = new CIS();
            ii.Add(1);
            ii.Add(2);
            ODCIS i = new ODCIS();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opODCIS(i, null, cb.opODCISI, i);
            cb.check();
        }

        {
            List <int> ii = new List <int>();
            ii.Add(1);
            ii.Add(2);
            ODGIS i = new ODGIS();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opODGIS(i, null, cb.opODGISI, i);
            cb.check();
        }

        {
            string[] ii = new string[] { "a", "b" };
            ODASS    i  = new ODASS();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opODASS(i, null, cb.opODASSI, i);
            cb.check();
        }

        {
            CSS ii = new CSS();
            ii.Add("a");
            ii.Add("b");
            ODCSS i = new ODCSS();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opODCSS(i, null, cb.opODCSSI, i);
            cb.check();
        }

        {
            List <string> ii = new List <string>();
            ii.Add("a");
            ii.Add("b");
            ODGSS i = new ODGSS();
            i["a"] = ii;
            i["b"] = ii;

            Callback cb = new Callback();
            p.begin_opODGSS(i, null, cb.opODGSSI, i);
            cb.check();
        }
    }
Example #8
0
        internal void LoadData(byte[] pcmciaCis)
        {
            if (pcmciaCis == null)
            {
                return;
            }

            cis     = pcmciaCis;
            Visible = true;

            TreeGridItemCollection cisList = new TreeGridItemCollection();

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

            treePcmcia.AllowMultipleSelection = false;
            treePcmcia.ShowHeader             = false;
            treePcmcia.DataStore = cisList;

            Tuple[] tuples = CIS.GetTuples(cis);
            if (tuples != null)
            {
                foreach (Tuple tuple in tuples)
                {
                    string tupleCode;
                    string tupleDescription;

                    switch (tuple.Code)
                    {
                    case TupleCodes.CISTPL_NULL:
                    case TupleCodes.CISTPL_END: continue;

                    case TupleCodes.CISTPL_DEVICEGEO:
                    case TupleCodes.CISTPL_DEVICEGEO_A:
                        tupleCode        = "Device Geometry Tuples";
                        tupleDescription = CIS.PrettifyDeviceGeometryTuple(tuple);
                        break;

                    case TupleCodes.CISTPL_MANFID:
                        tupleCode        = "Manufacturer Identification Tuple";
                        tupleDescription = CIS.PrettifyManufacturerIdentificationTuple(tuple);
                        break;

                    case TupleCodes.CISTPL_VERS_1:
                        tupleCode        = "Level 1 Version / Product Information Tuple";
                        tupleDescription = 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:
                        tupleCode        = $"Undecoded tuple ID {tuple.Code}";
                        tupleDescription = $"Undecoded tuple ID {tuple.Code}";
                        break;

                    default:
                        tupleCode        = $"0x{(byte)tuple.Code:X2}";
                        tupleDescription = $"Found unknown tuple ID 0x{(byte)tuple.Code:X2}";
                        break;
                    }

                    cisList.Add(new TreeGridItem {
                        Values = new object[] { tupleCode, tupleDescription }
                    });
                }
            }
            else
            {
                DicConsole.DebugWriteLine("Device-Info command", "PCMCIA CIS returned no tuples");
            }
        }
Example #9
0
        /// <summary>
        ///     Creates a metadata sidecar for a block media (e.g. floppy, hard disk, flash card, usb stick)
        /// </summary>
        /// <param name="image">Image</param>
        /// <param name="filterId">Filter uuid</param>
        /// <param name="imagePath">Image path</param>
        /// <param name="fi">Image file information</param>
        /// <param name="plugins">Image plugins</param>
        /// <param name="imgChecksums">List of image checksums</param>
        /// <param name="sidecar">Metadata sidecar</param>
        static void BlockMedia(IMediaImage image, Guid filterId, string imagePath,
                               FileInfo fi, PluginBase plugins,
                               List <ChecksumType> imgChecksums, ref CICMMetadataType sidecar, Encoding encoding)
        {
            sidecar.BlockMedia = new[]
            {
                new BlockMediaType
                {
                    Checksums = imgChecksums.ToArray(),
                    Image     = new ImageType
                    {
                        format          = image.Format,
                        offset          = 0,
                        offsetSpecified = true,
                        Value           = Path.GetFileName(imagePath)
                    },
                    Size     = fi.Length,
                    Sequence = new SequenceType {
                        MediaTitle = image.Info.MediaTitle
                    }
                }
            };

            if (image.Info.MediaSequence != 0 && image.Info.LastMediaSequence != 0)
            {
                sidecar.BlockMedia[0].Sequence.MediaSequence = image.Info.MediaSequence;
                sidecar.BlockMedia[0].Sequence.TotalMedia    = image.Info.LastMediaSequence;
            }
            else
            {
                sidecar.BlockMedia[0].Sequence.MediaSequence = 1;
                sidecar.BlockMedia[0].Sequence.TotalMedia    = 1;
            }

            foreach (MediaTagType tagType in image.Info.ReadableMediaTags)
            {
                switch (tagType)
                {
                case MediaTagType.ATAPI_IDENTIFY:
                    sidecar.BlockMedia[0].ATA = new ATAType
                    {
                        Identify = new DumpType
                        {
                            Checksums =
                                Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY)).ToArray(),
                            Size = image.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY).Length
                        }
                    };
                    break;

                case MediaTagType.ATA_IDENTIFY:
                    sidecar.BlockMedia[0].ATA = new ATAType
                    {
                        Identify = new DumpType
                        {
                            Checksums =
                                Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.ATA_IDENTIFY)).ToArray(),
                            Size = image.ReadDiskTag(MediaTagType.ATA_IDENTIFY).Length
                        }
                    };
                    break;

                case MediaTagType.PCMCIA_CIS:
                    byte[] cis = image.ReadDiskTag(MediaTagType.PCMCIA_CIS);
                    sidecar.BlockMedia[0].PCMCIA = new PCMCIAType
                    {
                        CIS = new DumpType {
                            Checksums = Checksum.GetChecksums(cis).ToArray(), Size = cis.Length
                        }
                    };
                    Tuple[] tuples = CIS.GetTuples(cis);
                    if (tuples != null)
                    {
                        foreach (Tuple tuple in tuples)
                        {
                            switch (tuple.Code)
                            {
                            case TupleCodes.CISTPL_MANFID:
                                ManufacturerIdentificationTuple manfid =
                                    CIS.DecodeManufacturerIdentificationTuple(tuple);

                                if (manfid != null)
                                {
                                    sidecar.BlockMedia[0].PCMCIA.ManufacturerCode =
                                        manfid.ManufacturerID;
                                    sidecar.BlockMedia[0].PCMCIA.CardCode = manfid.CardID;
                                    sidecar.BlockMedia[0].PCMCIA.ManufacturerCodeSpecified = true;
                                    sidecar.BlockMedia[0].PCMCIA.CardCodeSpecified         = true;
                                }

                                break;

                            case TupleCodes.CISTPL_VERS_1:
                                Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple);

                                if (vers != null)
                                {
                                    sidecar.BlockMedia[0].PCMCIA.Manufacturer = vers.Manufacturer;
                                    sidecar.BlockMedia[0].PCMCIA.ProductName  = vers.Product;
                                    sidecar.BlockMedia[0].PCMCIA.Compliance   =
                                        $"{vers.MajorVersion}.{vers.MinorVersion}";
                                    sidecar.BlockMedia[0].PCMCIA.AdditionalInformation =
                                        vers.AdditionalInformation;
                                }

                                break;
                            }
                        }
                    }

                    break;

                case MediaTagType.SCSI_INQUIRY:
                    sidecar.BlockMedia[0].SCSI = new SCSIType
                    {
                        Inquiry = new DumpType
                        {
                            Checksums =
                                Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SCSI_INQUIRY)).ToArray(),
                            Size = image.ReadDiskTag(MediaTagType.SCSI_INQUIRY).Length
                        }
                    };
                    break;

                case MediaTagType.SD_CID:
                    if (sidecar.BlockMedia[0].SecureDigital == null)
                    {
                        sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType();
                    }
                    sidecar.BlockMedia[0].SecureDigital.CID = new DumpType
                    {
                        Checksums = Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SD_CID)).ToArray(),
                        Size      = image.ReadDiskTag(MediaTagType.SD_CID).Length
                    };
                    break;

                case MediaTagType.SD_CSD:
                    if (sidecar.BlockMedia[0].SecureDigital == null)
                    {
                        sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType();
                    }
                    sidecar.BlockMedia[0].SecureDigital.CSD = new DumpType
                    {
                        Checksums = Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SD_CSD)).ToArray(),
                        Size      = image.ReadDiskTag(MediaTagType.SD_CSD).Length
                    };
                    break;

                case MediaTagType.SD_SCR:
                    if (sidecar.BlockMedia[0].SecureDigital == null)
                    {
                        sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType();
                    }
                    sidecar.BlockMedia[0].SecureDigital.SCR = new DumpType
                    {
                        Checksums = Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SD_SCR)).ToArray(),
                        Size      = image.ReadDiskTag(MediaTagType.SD_SCR).Length
                    };
                    break;

                case MediaTagType.SD_OCR:
                    if (sidecar.BlockMedia[0].SecureDigital == null)
                    {
                        sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType();
                    }
                    sidecar.BlockMedia[0].SecureDigital.OCR = new DumpType
                    {
                        Checksums = Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SD_OCR)).ToArray(),
                        Size      = image.ReadDiskTag(MediaTagType.SD_OCR).Length
                    };
                    break;

                case MediaTagType.MMC_CID:
                    if (sidecar.BlockMedia[0].MultiMediaCard == null)
                    {
                        sidecar.BlockMedia[0].MultiMediaCard = new MultiMediaCardType();
                    }
                    sidecar.BlockMedia[0].MultiMediaCard.CID = new DumpType
                    {
                        Checksums = Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SD_CID)).ToArray(),
                        Size      = image.ReadDiskTag(MediaTagType.SD_CID).Length
                    };
                    break;

                case MediaTagType.MMC_CSD:
                    if (sidecar.BlockMedia[0].MultiMediaCard == null)
                    {
                        sidecar.BlockMedia[0].MultiMediaCard = new MultiMediaCardType();
                    }
                    sidecar.BlockMedia[0].MultiMediaCard.CSD = new DumpType
                    {
                        Checksums = Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SD_CSD)).ToArray(),
                        Size      = image.ReadDiskTag(MediaTagType.SD_CSD).Length
                    };
                    break;

                case MediaTagType.MMC_OCR:
                    if (sidecar.BlockMedia[0].MultiMediaCard == null)
                    {
                        sidecar.BlockMedia[0].MultiMediaCard = new MultiMediaCardType();
                    }
                    sidecar.BlockMedia[0].MultiMediaCard.OCR = new DumpType
                    {
                        Checksums = Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SD_OCR)).ToArray(),
                        Size      = image.ReadDiskTag(MediaTagType.SD_OCR).Length
                    };
                    break;

                case MediaTagType.MMC_ExtendedCSD:
                    if (sidecar.BlockMedia[0].MultiMediaCard == null)
                    {
                        sidecar.BlockMedia[0].MultiMediaCard = new MultiMediaCardType();
                    }
                    sidecar.BlockMedia[0].MultiMediaCard.ExtendedCSD = new DumpType
                    {
                        Checksums =
                            Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.MMC_ExtendedCSD)).ToArray(),
                        Size = image.ReadDiskTag(MediaTagType.MMC_ExtendedCSD).Length
                    };
                    break;

                case MediaTagType.USB_Descriptors:
                    if (sidecar.BlockMedia[0].USB == null)
                    {
                        sidecar.BlockMedia[0].USB = new USBType();
                    }
                    sidecar.BlockMedia[0].USB.Descriptors = new DumpType
                    {
                        Checksums =
                            Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.USB_Descriptors)).ToArray(),
                        Size = image.ReadDiskTag(MediaTagType.USB_Descriptors).Length
                    };
                    break;

                case MediaTagType.SCSI_MODESENSE_6:
                    if (sidecar.BlockMedia[0].SCSI == null)
                    {
                        sidecar.BlockMedia[0].SCSI = new SCSIType();
                    }
                    sidecar.BlockMedia[0].SCSI.ModeSense = new DumpType
                    {
                        Checksums =
                            Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SCSI_MODESENSE_6)).ToArray(),
                        Size = image.ReadDiskTag(MediaTagType.SCSI_MODESENSE_6).Length
                    };
                    break;

                case MediaTagType.SCSI_MODESENSE_10:
                    if (sidecar.BlockMedia[0].SCSI == null)
                    {
                        sidecar.BlockMedia[0].SCSI = new SCSIType();
                    }
                    sidecar.BlockMedia[0].SCSI.ModeSense10 = new DumpType
                    {
                        Checksums =
                            Checksum.GetChecksums(image.ReadDiskTag(MediaTagType.SCSI_MODESENSE_10)).ToArray(),
                        Size = image.ReadDiskTag(MediaTagType.SCSI_MODESENSE_10).Length
                    };
                    break;
                }
            }

            // If there is only one track, and it's the same as the image file (e.g. ".iso" files), don't re-checksum.
            if (image.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000") &&
                filterId == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
            {
                sidecar.BlockMedia[0].ContentChecksums = sidecar.BlockMedia[0].Checksums;
            }
            else
            {
                Checksum contentChkWorker = new Checksum();

                // For fast debugging, skip checksum
                //goto skipImageChecksum;

                uint  sectorsToRead = 512;
                ulong sectors       = image.Info.Sectors;
                ulong doneSectors   = 0;

                InitProgress2();
                while (doneSectors < sectors)
                {
                    byte[] sector;

                    if (sectors - doneSectors >= sectorsToRead)
                    {
                        sector = image.ReadSectors(doneSectors, sectorsToRead);
                        UpdateProgress2("Hashings sector {0} of {1}", (long)doneSectors, (long)sectors);
                        doneSectors += sectorsToRead;
                    }
                    else
                    {
                        sector = image.ReadSectors(doneSectors, (uint)(sectors - doneSectors));
                        UpdateProgress2("Hashings sector {0} of {1}", (long)doneSectors, (long)sectors);
                        doneSectors += sectors - doneSectors;
                    }

                    contentChkWorker.Update(sector);
                }

                // For fast debugging, skip checksum
                //skipImageChecksum:

                List <ChecksumType> cntChecksums = contentChkWorker.End();

                sidecar.BlockMedia[0].ContentChecksums = cntChecksums.ToArray();

                EndProgress2();
            }

            MediaType.MediaTypeToString(image.Info.MediaType, out string dskType, out string dskSubType);
            sidecar.BlockMedia[0].DiskType    = dskType;
            sidecar.BlockMedia[0].DiskSubType = dskSubType;
            Statistics.AddMedia(image.Info.MediaType, false);

            sidecar.BlockMedia[0].Dimensions = Dimensions.DimensionsFromMediaType(image.Info.MediaType);

            sidecar.BlockMedia[0].LogicalBlocks    = (long)image.Info.Sectors;
            sidecar.BlockMedia[0].LogicalBlockSize = (int)image.Info.SectorSize;
            // TODO: Detect it
            sidecar.BlockMedia[0].PhysicalBlockSize = (int)image.Info.SectorSize;

            UpdateStatus("Checking filesystems...");

            List <Partition> partitions = Partitions.GetAll(image);

            Partitions.AddSchemesToStats(partitions);

            sidecar.BlockMedia[0].FileSystemInformation = new PartitionType[1];
            if (partitions.Count > 0)
            {
                sidecar.BlockMedia[0].FileSystemInformation = new PartitionType[partitions.Count];
                for (int i = 0; i < partitions.Count; i++)
                {
                    sidecar.BlockMedia[0].FileSystemInformation[i] = new PartitionType
                    {
                        Description = partitions[i].Description,
                        EndSector   = (int)partitions[i].End,
                        Name        = partitions[i].Name,
                        Sequence    = (int)partitions[i].Sequence,
                        StartSector = (int)partitions[i].Start,
                        Type        = partitions[i].Type
                    };
                    List <FileSystemType> lstFs = new List <FileSystemType>();

                    foreach (IFilesystem plugin in plugins.PluginsList.Values)
                    {
                        try
                        {
                            if (!plugin.Identify(image, partitions[i]))
                            {
                                continue;
                            }

                            plugin.GetInformation(image, partitions[i], out _, encoding);
                            lstFs.Add(plugin.XmlFsType);
                            Statistics.AddFilesystem(plugin.XmlFsType.Type);
                        }
                    }