GetDataForTest() public static method

public static GetDataForTest ( IList data ) : string
data IList
return string
Ejemplo n.º 1
0
        private static List <SKUCheckData> GetSKUCheckData(bool reversed, ref byte[] data, ref Common.TypeData checkdata)
        {
            var ret = new List <SKUCheckData>();

            foreach (var skuDataEntry in checkdata.SKUDataList.Value)
            {
                var skuCheckDataEntry = new SKUCheckData
                {
                    Type = skuDataEntry.Type
                };
                var tmpdata = new byte[skuDataEntry.Size];
                Buffer.BlockCopy(data, (int)skuDataEntry.Offset, tmpdata, 0, tmpdata.Length);
                if (reversed)
                {
                    if (skuDataEntry.Size == 1)
                    {
                        if ((skuDataEntry.Offset % 2) == 0)
                        {
                            if (data.Length < skuDataEntry.Offset + 1)
                            {
                                Logger.WriteLine2("FAILED! Offset is at end of image!");
                                tmpdata[0] = 0;
                            }
                            else
                            {
                                tmpdata[0] = data[skuDataEntry.Offset + 1];
                            }
                        }
                        else
                        {
                            tmpdata[0] = data[skuDataEntry.Offset - 1];
                        }
                    }
                    else
                    {
                        Common.SwapBytes(ref tmpdata);
                    }
                }
                if (skuDataEntry.Type.Equals("bootldrsize", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (tmpdata.Length == 2)
                    {
                        skuCheckDataEntry.Size = Common.GetLdrSize(ref tmpdata);
                    }
                    else
                    {
                        throw new ArgumentException("The bootloader argument size should be 2");
                    }
                }
                else
                {
                    skuCheckDataEntry.Data = Common.GetDataForTest(tmpdata);
                }
                ret.Add(skuCheckDataEntry);
            }
            return(ret);
        }
Ejemplo n.º 2
0
        private static bool CheckBinPart(ref byte[] data, string name)
        {
            GC.Collect();
            var datareversed = false;
            var checkdata    = Common.Types[data.Length].Bincheck.Value[name];

            if (checkdata.Value.Offset >= data.Length)
            {
                Logger.WriteLine2("FAILED! Faulty configuration (Bad Offset)!");
                return(false);
            }
            var expmsg = string.Format("{0}{1}Offset: 0x{2:X}{1}", checkdata.Value.Description, Environment.NewLine, checkdata.Value.Offset);
            var length = 0;

            foreach (var d in checkdata.Value.ExpectedList.Value)
            {
                var count  = 0;
                var tmpmsg = Common.GetDataReadable(d.Expected, ref count);
                if (length == 0)
                {
                    length = count;
                }
                if (count != length || (length % 2) != 0)
                {
                    expmsg += string.Format("{0}ERROR: Bad length of the following data!:", Environment.NewLine);
                }
                expmsg += string.Format("{0}{1}", tmpmsg.Trim(), Environment.NewLine);
                if (checkdata.Value.Asciiout)
                {
                    expmsg += string.Format("{0}Ascii Value: {1}", Environment.NewLine, Encoding.ASCII.GetString(Common.HexToArray(d.Expected)));
                }
            }
            if (expmsg.Contains("ERROR"))
            {
                Logger.WriteLine2("FAILED! Faulty configuration!");
                return(false);
            }
            var tmp = new byte[length / 2];

            if (checkdata.Value.Offset >= data.Length + tmp.Length)
            {
                Logger.WriteLine2("FAILED! Faulty configuration (Bad Offset/Data length)!");
                return(false);
            }
            Buffer.BlockCopy(data, (int)checkdata.Value.Offset, tmp, 0, tmp.Length);
            var msg  = Common.GetDataForTest(tmp);
            var isok = false;

            foreach (var d in checkdata.Value.ExpectedList.Value)
            {
                isok = msg.Equals(d.Expected, StringComparison.CurrentCultureIgnoreCase);
                if (!isok)
                {
                    continue;
                }
                break;
            }
            if (!isok)
            {
                if (tmp.Length == 1)
                {
                    if ((checkdata.Value.Offset % 2) == 0)
                    {
                        if (data.Length < checkdata.Value.Offset + 1)
                        {
                            Logger.WriteLine2("FAILED! Offset is at end of image!");
                            return(false);
                        }
                        tmp[0] = data[checkdata.Value.Offset + 1];
                    }
                    else
                    {
                        tmp[0] = data[checkdata.Value.Offset - 1];
                    }
                    msg = tmp[0].ToString("X2");
                }
                else if (Common.SwapBytes(ref tmp))
                {
                    msg = Common.GetDataForTest(tmp);
                }
                foreach (var d in checkdata.Value.ExpectedList.Value)
                {
                    isok = msg.Equals(d.Expected, StringComparison.CurrentCultureIgnoreCase);
                    if (!isok)
                    {
                        continue;
                    }
                    datareversed = true;
                    break;
                }
            }
            Buffer.BlockCopy(data, (int)checkdata.Value.Offset, tmp, 0, tmp.Length);
            msg = Common.GetDataReadable(tmp);
            if (datareversed)
            {
                Common.SwapBytes(ref tmp);
                msg += string.Format("{0}Reversed (checked) data:{0}{1}", Environment.NewLine, Common.GetDataReadable(tmp));
            }
            if (checkdata.Value.Asciiout)
            {
                var asciidata = Encoding.ASCII.GetString(tmp);
                msg += string.Format("{0}Ascii Value: {1}", Environment.NewLine, asciidata);
            }
            AddItem(new Common.PartsObject
            {
                Name           = name.Trim(),
                ActualString   = msg.Trim(),
                ExpectedString = expmsg,
                Result         = isok,
            });
            Logger.WriteLine2(isok ? "OK!" : string.Format("FAILED! {0}{1}Actual data: {2}", expmsg, Environment.NewLine, msg));
            return(isok);
        }
Ejemplo n.º 3
0
        private static bool CheckBinPart(ref byte[] data, string name, ref bool reversed)
        {
            GC.Collect();
            var datareversed = false;
            var checkdata    = Common.Types[data.Length].Bincheck.Value[name];

            if (checkdata.Value.Offset >= data.Length)
            {
                Logger.WriteLine2("FAILED! Faulty configuration (Bad Offset)!");
                return(false);
            }
            var expmsg = string.Format("{0}{1}Offset: 0x{2:X}{1}", checkdata.Value.Description, Environment.NewLine, checkdata.Value.Offset);

            if (!string.IsNullOrEmpty(checkdata.Value.Expected))
            {
                if ((checkdata.Value.Expected.Length % 2) != 0)
                {
                    Logger.WriteLine2("FAILED! Nothing to check! (a.k.a Faulty configuration!)");
                    return(false);
                }
                expmsg += string.Format("Expected data:{0}", Environment.NewLine);
                expmsg += Common.GetDataReadable(checkdata.Value.Expected).Trim();
                if (checkdata.Value.Asciiout)
                {
                    expmsg += string.Format("{0}Ascii Value: {1}", Environment.NewLine, Encoding.ASCII.GetString(Common.HexToArray(checkdata.Value.Expected)));
                }
            }
            else
            {
                Logger.WriteLine2("FAILED! Faulty configuration!");
                return(false);
            }
            var tmp = new byte[checkdata.Value.Expected.Length / 2];

            if (checkdata.Value.Offset >= data.Length + tmp.Length)
            {
                Logger.WriteLine2("FAILED! Faulty configuration (Bad Offset/Data length)!");
                return(false);
            }
            Buffer.BlockCopy(data, (int)checkdata.Value.Offset, tmp, 0, tmp.Length);
            var msg  = Common.GetDataForTest(tmp);
            var isok = msg.Equals(checkdata.Value.Expected, StringComparison.CurrentCultureIgnoreCase);

            if (!isok)
            {
                if (Common.SwapBytes(ref tmp))
                {
                    var swapped = Common.GetDataForTest(tmp);
                    isok = swapped.Equals(checkdata.Value.Expected, StringComparison.CurrentCultureIgnoreCase);
                    if (isok)
                    {
                        reversed     = true;
                        datareversed = true;
                    }
                }
            }
            Buffer.BlockCopy(data, (int)checkdata.Value.Offset, tmp, 0, tmp.Length);
            msg = Common.GetDataReadable(tmp);
            if (datareversed)
            {
                Common.SwapBytes(ref tmp);
                msg += string.Format("{0}Reversed (checked) data:{0}{1}", Environment.NewLine, Common.GetDataReadable(tmp));
            }
            if (checkdata.Value.Asciiout)
            {
                msg += string.Format("{0}Ascii Value: {1}", Environment.NewLine, Encoding.ASCII.GetString(tmp));
            }
            AddItem(new Common.PartsObject
            {
                Name           = name.Trim(),
                ActualString   = msg.Trim(),
                ExpectedString = expmsg,
                Result         = isok
            });
            Logger.WriteLine2(isok ? "OK!" : string.Format("FAILED! {0}{1}Actual data: {2}", expmsg, Environment.NewLine, msg));
            return(isok);
        }