コード例 #1
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
        public static Common.ImgInfo StartCheck(string file, ref Stopwatch sw)
        {
            _checkId = 0;
            var fi = new FileInfo(file);
            _checkckount = 0;
            _ret = new Common.ImgInfo {
                FileName = file
            };
            _checkdata = Common.Types[fi.Length];
            var data = new byte[fi.Length];

            #region Statistics check

            if(_checkdata.Statlist.Value.Count > 0) {
                Logger.WriteLine(string.Format("{0,92}", "Statistics check started..."));
                _checkckount++;
                if(!CheckStatisticsList(GetStatisticsAndFillData(fi, ref data), data.Length))
                    Common.AddBad(ref _ret);
                Common.SendStatus("Statistics check Done!");
            }
            else {
                Common.SendStatus("Skipping Statistics check (nothing to check) Instead: Reading image into memory...");
                data = File.ReadAllBytes(fi.FullName);
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "Statistics check skipped!"));
            }

            #endregion Statistics check

            #region Binary check

            if(_checkdata.Bincheck.Value.Count > 0) {
                Logger.WriteLine(string.Format("{0,92}", "Binary check Started!"));
                foreach(var key in _checkdata.Bincheck.Value.Keys) {
                    _checkckount++;
                    Common.SendStatus(string.Format("Parsing Image... Checking Binary for: {0}", key));
                    var bintmp = string.Format("Binary check for {0} Started...", key);
                    Logger.Write(string.Format("{0,-70} Result: ", bintmp));
                    if(!_checkdata.Bincheck.Value[key].Value.IsMulti) {
                        if(!CheckBinPart(ref data, key, ref _ret.Reversed))
                            Common.AddBad(ref _ret);
                    }
                    else if(!CheckBinPart(ref data, key))
                        Common.AddBad(ref _ret);
                }
            }
            else
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "Binary check skipped!"));
            Common.SendStatus("Binary check(s) Done!");

            #endregion Binary check

            #region Data check

            if(_checkdata.DataCheckList.Value.Count > 0) {
                Logger.WriteLine(string.Format("{0,90}", "Data check Started!"));
                foreach(var key in _checkdata.DataCheckList.Value) {
                    _checkckount++;
                    Common.SendStatus(string.Format("Parsing Image... Checking Data Statistics for: {0}", key.Name));
                    var datatmp = string.Format("Data Statistics check for {0} Started...", key.Name);
                    Logger.Write(string.Format("{0,-70} Result: ", datatmp));
                    if(!CheckDataPart(ref data, key, _ret.Reversed))
                        Common.AddBad(ref _ret);
                }
            }
            else
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "Data check skipped!"));
            Common.SendStatus("Data check(s) Done!");

            #endregion Data check

            #region Hash check

            _dohash = Program.GetRegSetting("dohashcheck", true);
            if(_dohash && Common.Hashes != null && Common.Hashes.Offsets.ContainsKey(data.Length) && Common.Hashes.Offsets[data.Length].Value.Count > 0) {
                Logger.WriteLine(string.Format("{0,90}", "Hash check Started!"));
                foreach(var check in Common.Hashes.Offsets[data.Length].Value) {
                    _checkckount++;
                    Common.SendStatus(string.Format("Parsing Image... Checking Hash for: {0}", check.Name));
                    var hashtmp = string.Format("Hash check for {0} Started...", check.Name);
                    Logger.Write(string.Format("{0,-70} Result: ", hashtmp));
                    if(!CheckHash(_ret.Reversed, ref data, check))
                        Common.AddBad(ref _ret);
                    if (HashCheck.LastIsPatched)
                        _ret.IsPatched = true;
                }
            }
            else if (_dohash)
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "Hash check skipped!"));
            else
                Logger.WriteLine(string.Format("{0,-70} (disabled)", "Hash check skipped!"));
            Common.SendStatus("Hash check(s) Done!");

            #endregion Hash check

            #region ROSVersion check

            if(Program.GetRegSetting("dorosvercheck", true) && _checkdata.ROS0Offset > 0 && _checkdata.ROS1Offset > 0) {
                Logger.WriteLine(string.Format("{0,97}", "ROS Version check Started!"));
                _checkckount++;
                Common.SendStatus("Parsing Image... Checking ROS0 Version");
                Logger.Write(string.Format("{0,-70} Result: ", "ROS Version check for ROS0 Started..."));
                var ret = CheckROSVersion(ref data, _checkdata.ROS0Offset, out _ret.ROS0Version);
                if (!ret)
                    Common.AddBad(ref _ret);
                Logger.WriteLine2(!ret ? "FAILED!" : string.Format("OK! ({0})", _ret.ROS0Version));
                AddItem(new Common.PartsObject { ActualString = _ret.ROS0Version, ExpectedString = "ROS0 version in the format: ###.###", Name = "009.03   ROS0 Version", Result = ret });
                _checkckount++;
                Common.SendStatus("Parsing Image... Checking ROS0 Version");
                Logger.Write(string.Format("{0,-70} Result: ", "ROS Version check for ROS1 Started..."));
                ret = CheckROSVersion(ref data, _checkdata.ROS1Offset, out _ret.ROS1Version);
                if (!ret)
                    Common.AddBad(ref _ret);
                Logger.WriteLine2(!ret ? "FAILED!" : string.Format("OK! ({0})", _ret.ROS1Version));
                AddItem(new Common.PartsObject { ActualString = _ret.ROS1Version, ExpectedString = "ROS1 version in the format: ###.###", Name = "009.06   ROS1 Version", Result = ret });
            }
            else if (Program.GetRegSetting("dorosvercheck", true))
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "ROS Version check skipped!"));
            else
                Logger.WriteLine(string.Format("{0,-70} (disabled)", "ROS Version check skipped!"));
            Common.SendStatus("ROS Version checks Done!");

            #endregion Hash check

            #region Repetitions Check

            if(Program.GetRegSetting("dorepcheck", true) && _checkdata.RepCheck.Value.Count > 0) {
                Logger.WriteLine(string.Format("{0,97}", "Repetitions check Started!"));
                Common.SendStatus("Parsing Image... Checking Binary for: Repetitions");
                if(!Repetitions(_ret.Reversed, ref data, ref _checkdata))
                    Common.AddBad(ref _ret);
            }
            else if (Program.GetRegSetting("dorepcheck", true))
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "Repetitions check skipped!"));
            else
                Logger.WriteLine(string.Format("{0,-70} (disabled)", "Repetitions check skipped!"));
            Common.SendStatus("Repetitions check(s) Done!");

            #endregion

            #region DataMatch Check

            if(_checkdata.DataMatchList.Value.Count > 0) {
                Logger.WriteLine(string.Format("{0,96}", "Data Match check Started!"));
                Common.SendStatus("Parsing Image... Checking Binary for: Data Matches");
                if (!CheckDataMatches(ref data, ref _checkdata))
                    Common.AddBad(ref _ret);
                else
                    Logger.WriteLine("All is OK!");
            }
            else
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "Data Match check skipped!"));
            Common.SendStatus("Data Match check(s) Done!");

            #endregion

            #region DataFill Check

            if (_checkdata.DataFillEntries.Value.Count > 0) {
                Logger.WriteLine(string.Format("{0,95}", "Data Fill check Started!"));
                foreach (var dataFillEntry in _checkdata.DataFillEntries.Value) {
                    _checkckount++;
                    Common.SendStatus(string.Format("Parsing Image... Checking Data Fill for: {0}", dataFillEntry.Name));
                    Logger.Write(string.Format("{0,-70} Result: ", string.Format("Data Fill check for: {0} Started!", dataFillEntry.Name)));
                    if (!CheckDataFill(ref data, dataFillEntry, _ret.Reversed))
                        Common.AddBad(ref _ret);
                }
            }
            else
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "Data Fill check skipped!"));
            Common.SendStatus("Data Fill check(s) Done!");

            #endregion

            //New checks goes here

            #region SKU List check

            if (_checkdata.SKUList.Value.Count > 0)
            {
                Logger.WriteLine(string.Format("{0,94}", "SKU List check Started!"));
                Common.SendStatus("Checking SKU List...");
                var skuCheckDataList = GetSkuCheckData(_ret.Reversed, ref data, ref _checkdata);

                var skuEntryList = new List<Common.SKUEntry>(_checkdata.SKUList.Value);
                foreach (var entry in skuCheckDataList)
                {
                    if (skuEntryList.Count < skuCheckDataList.Count)
                        break;
                    var tmplist = GetFilterList(skuEntryList, entry);
                    var tmplist2 = new List<Common.SKUEntry>(skuEntryList);
                    skuEntryList.Clear();
                    foreach (var skuEntry in tmplist2)
                    {
                        foreach (var tmpentry in tmplist)
                        {
                            if (skuEntry.SKUKey == tmpentry.SKUKey)
                                skuEntryList.Add(skuEntry);
                        }
                    }
                }
                var datamsg = "";
                foreach (var entry in skuCheckDataList)
                    datamsg += entry.Type.Equals("bootldrsize", StringComparison.CurrentCultureIgnoreCase) ? string.Format("{0} = {1:X4}{2}", entry.Type, entry.Size, Environment.NewLine) : string.Format("{0} = {1}{2}", entry.Type, entry.Data, Environment.NewLine);
                if (skuEntryList.Count == skuCheckDataList.Count)
                {
                    _ret.SKUModel = skuEntryList[0].Name;
                    _ret.MinVer = skuEntryList[0].MinVer;
                    Logger.WriteLine(string.Format("SKU Model: {0}", _ret.SKUModel));
                    var msg = "";
                    if (skuEntryList[0].Warn)
                    {
                        foreach (var entry in skuEntryList)
                        {
                            if (string.IsNullOrEmpty(entry.WarnMsg))
                                continue;
                            msg = entry.WarnMsg;
                            break;
                        }
                        MessageBox.Show(msg, Resources.WARNING, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        Logger.WriteLine(msg);
                        Logger.WriteLine("");
                        datamsg += string.Format("{0}{1}", Environment.NewLine, msg);
                    }
                }
                else
                {
                    Common.AddBad(ref _ret);
                    _ret.SKUModel = null;
                    _ret.MinVer = null;
                    Logger.WriteLine("No matching SKU model found!");
                    foreach (var entry in skuCheckDataList)
                        Logger.WriteLine(entry.Type.Equals("bootldrsize", StringComparison.CurrentCultureIgnoreCase) ? string.Format("{0} = {1:X4}", entry.Type, entry.Size) : string.Format("{0} = {1}", entry.Type, entry.Data));
                }
                AddItem(new Common.PartsObject
                {
                    Name = "SKUIdentity Data",
                    ActualString = datamsg.Trim(),
                    ExpectedString = "",
                    Result = (skuEntryList.Count == skuCheckDataList.Count),
                });
            }
            else
                Logger.WriteLine(string.Format("{0,-70} (nothing to check)", "SKU List check skipped!"));

            #endregion SKU List check

            #region Final Output

            var outstring = string.Format("All checks ({2} Checks) have been completed after {0} Second(s) and {1} Millisecond(s)", (int)sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds, _checkckount);
            Common.SendStatus(outstring);
            Logger.WriteLine(outstring);
            _ret.IsOk = _ret.BadCount == 0;
            _ret.Status = _ret.IsOk ? "Dump has been validated!" : "Dump is bad!";
            if(!_ret.IsOk)
                MessageBox.Show(string.Format("ERROR: Your dump failed on {0} of {1} Checks\nPlease check the log for more information!", _ret.BadCount, _checkckount), Resources.Checks_StartCheck_ERROR___Bad_dump, MessageBoxButtons.OK, MessageBoxIcon.Error);
            var tmp = _ret.IsOk ? "Pass!" : "Failed!";
            var outtmp = _ret.IsOk ? string.Format("Tests done: {0}", _checkckount) : string.Format("Bad count: {0} of {1} Tests", _ret.BadCount, _checkckount);
            Logger.WriteLine2(string.Format("{0,-81} Result: {1}", outtmp, tmp));
            sw.Stop();

            #endregion Final Output

            return _ret;
        }
コード例 #2
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);
        }