コード例 #1
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
 private static bool Repetitions(bool reversed, ref byte[] data, ref Common.TypeData checkData)
 {
     var ret = true;
     var tmp = reversed ? Encoding.BigEndianUnicode.GetString(data) : Encoding.Unicode.GetString(data);
     var bigbuilder = new StringBuilder();
     var checkLines = 0;
     foreach(var key in checkData.RepCheck.Value.Keys) {
         _checkckount++;
         var rep = checkData.RepCheck.Value[key].Value;
         rep.FoundAt.Clear();
         Logger.Write(string.Format("{0,-70} Result: ", string.Format("Repetitions check for {0} Started...", rep.Name)));
         foreach(Match match in Regex.Matches(tmp, Regex.Escape(key))) {
             var index = match.Index * 2;
             if(index == rep.Offset)
                 continue;
             rep.FoundAt.Add(index);
             checkLines |= (index - rep.Offset) / 2;
             ret = false;
         }
         if(rep.FoundAt.Count <= 0) {
             Logger.WriteLine2("OK!");
             continue;
         }
         Logger.WriteLine2(string.Format("FAILED! {0}Actual data:", Environment.NewLine));
         var builder = new StringBuilder();
         foreach(var offset in rep.FoundAt)
             builder.Append(string.Format(" 0x{0:X}", offset));
         Logger.WriteLine2(string.Format("{0} Found at {1} offset(s):{2}", rep.Name, rep.FoundAt.Count, builder));
         Logger.WriteLine2(string.Format("{0} Expected at: 0x{1:X}", rep.Name, rep.Offset));
         bigbuilder.AppendLine(string.Format("{0} Found at {1} offsets:{2}", rep.Name, rep.FoundAt.Count, builder));
         bigbuilder.AppendLine(string.Format("{0} Expected at: 0x{1:X}", rep.Name, rep.Offset));
     }
     if(ret)
         bigbuilder.AppendLine("No Repetitions found!");
     else {
         var s = bigbuilder.ToString(); // Save current data
         bigbuilder.Length = 0; // Reset it so we can start fresh
         bigbuilder.Append("You should check address line(s): ");
         for(var i = 0; i < 30; i++) {
             if((checkLines & (1 << i)) > 0)
                 bigbuilder.AppendFormat("{0} ", (AddressLines) (1 << i));
         }
         bigbuilder.AppendLine(); // Make sure the rest of it ends up on a new line...
         bigbuilder.Append(s); // Add the saved data back
     }
     AddItem(new Common.PartsObject {
         Name = "Repetitions Check",
         ActualString = bigbuilder.ToString(),
         ExpectedString = "No Repetitions are supposed to be listed!",
         Result = ret
     });
     return ret;
 }
コード例 #2
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
 private static string DoCheckDataMatch(ref byte[] data, int offset, ref StringBuilder smallbuilder, ref Dictionary<string, string> testlist, ref bool islastok, Common.DataMatch testdata)
 {
     var name = testdata.Name;
     if(testdata.SequenceRepetitions > 1)
         name = string.Format(testdata.Name, offset);
     var tmp = Common.GetDataForTest(ref data, offset, testdata.Length);
     if (!testlist.ContainsKey(tmp) && testlist.Count > 0)
         islastok = false;
     if (!testlist.ContainsKey(tmp))
         testlist.Add(tmp, name);
     smallbuilder.AppendLine(!testdata.DisableDisplay ? string.Format("{0} :\r\n{1}", name, Common.GetDataReadable(tmp).Trim()) : string.Format("{0} : Too long to display", name));
     return testdata.DisableDisplay ? "Too long to display" : tmp;
 }
コード例 #3
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
 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;
 }
コード例 #4
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
 private static bool CheckDataPart(ref byte[] srcdata, Common.DataCheck checkdata, bool reversed)
 {
     if(checkdata.Offset >= srcdata.Length || checkdata.LdrSize > srcdata.Length - 2) {
         Logger.WriteLine2("FAILED! Faulty configuration (Bad Offset/Ldrsize)!");
         return false;
     }
     long size;
     if(checkdata.LdrSize != 0) {
         var tmpdata = new byte[2];
         Buffer.BlockCopy(srcdata, (int) checkdata.LdrSize, tmpdata, 0, tmpdata.Length);
         if(reversed)
             Common.SwapBytes(ref tmpdata);
         size = Common.GetLdrSize(ref tmpdata);
     }
     else
         size = checkdata.Size;
     var tmp = new byte[size];
     if(checkdata.Offset >= srcdata.Length - tmp.Length) {
         Logger.WriteLine2(checkdata.LdrSize == 0 ? "FAILED! Faulty configuration (Bad Offset/Data length)!" : "FAILED! (Bad size data)");
         return false;
     }
     Buffer.BlockCopy(srcdata, (int) checkdata.Offset, tmp, 0, tmp.Length);
     var statlist = GetStatistics(ref tmp);
     var isok = CheckStatistics(statlist, checkdata, tmp.Length);
     return isok;
 }
コード例 #5
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
 private static bool CheckStatistics(Dictionary<byte, double> inputList, Common.DataCheck checkdata, int length)
 {
     var statlist = checkdata.ThresholdList;
     var isok = !(statlist == null || statlist.Count == 0);
     if(isok) {
         foreach(var d in inputList.Keys) {
             var val = inputList[d];
             val = double.Parse(val.ToString("F2"));
             double maxpercentage = 100;
             if(statlist.ContainsKey(d.ToString("X2")))
                 maxpercentage = statlist[d.ToString("X2")];
             else if(statlist.ContainsKey("*"))
                 maxpercentage = statlist["*"];
             if(maxpercentage >= val)
                 continue;
             Logger.WriteLine(string.Format("Statistics check Failed! 0x{0:X2} doesn't match expected percentage: lower then {1}% Actual value: {2:F2}%", d, maxpercentage, val));
             isok = false;
         }
         var list = new List<byte>(inputList.Keys);
         list.Sort();
         var actmsg = "";
         foreach(var key in list)
             actmsg += String.Format("0x{0:X2} : {1:F2}%{2}", key, inputList[key], Environment.NewLine);
         var expmsg = string.Format("Offset checked: 0x{1:X}{0}Length checked: 0x{2:X}", Environment.NewLine, checkdata.Offset, length);
         foreach(var key in checkdata.ThresholdList.Keys) {
             var val = checkdata.ThresholdList[key];
             if(!key.Equals("*"))
                 expmsg += string.Format("{0}{1} Should be less then {2:F2}%", Environment.NewLine, key, val);
             else if(checkdata.ThresholdList.Count > 1)
                 expmsg += string.Format("{0}Everything else should be less then {1:F2}%", Environment.NewLine, val);
             else
                 expmsg += string.Format("{0}Everything should be less then {1:F2}%", Environment.NewLine, val);
         }
         AddItem(new Common.PartsObject {
             Name = checkdata.Name.Trim(),
             ActualString = actmsg.Trim(),
             ExpectedString = expmsg.Trim(),
             Result = isok
         });
         Logger.WriteLine2(isok ? "OK!" : string.Format("FAILED! {0}{1}Actual data: {2}", expmsg, Environment.NewLine, actmsg));
     }
     else
         Logger.WriteLine2("FAILED! (Bad configuration)");
     return isok;
 }
コード例 #6
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
 private static bool CheckDataMatches(ref byte[] data, ref Common.TypeData checkdata)
 {
     var bigbuilder = new StringBuilder();
     var ret = true;
     foreach(var key in checkdata.DataMatchList.Value.Keys) {
         int cnt = 0, loffset = 0;
         Logger.Write(string.Format("{0,-70} Result: ", string.Format("Datamatch for: {0} Started", checkdata.DataMatchList.Value[key].Value.Name)));
         _checkckount++;
         var smallbuilder = new StringBuilder();
         var islastok = true;
         var testlist = new Dictionary<string, string>();
         var laststring = "";
         bigbuilder.AppendLine(string.Format("Check name: {0}", checkdata.DataMatchList.Value[key].Value.Name));
         foreach(var testdata in checkdata.DataMatchList.Value[key].Value.Data) {
             if(testdata.SequenceRepetitions <= 0)
                 laststring = DoCheckDataMatch(ref data, testdata.Offset, ref smallbuilder, ref testlist, ref islastok, testdata);
             else {
                 for(var i = testdata.Offset; i < testdata.Offset + (testdata.Length * testdata.SequenceRepetitions); i += testdata.Length) {
                     laststring = DoCheckDataMatch(ref data, i, ref smallbuilder, ref testlist, ref islastok, testdata);
                     loffset = i;
                     cnt++;
                 }
             }
             if(cnt <= 0 || loffset <= 0)
                 continue;
             Console.WriteLine("Count checked: 0x{0:X}", cnt);
             Console.WriteLine("End offset: 0x{0:X}", loffset);
         }
         if(!islastok) {
             ret = false;
             bigbuilder.Append("Failed!\r\n" + smallbuilder + "\r\n"); // Add to the big one
             Logger.WriteLine2("Failed!");
             Logger.WriteLine2(smallbuilder.ToString());
         }
         else {
             bigbuilder.AppendLine(string.Format("All data matching:\r\n{0}\r\n", Common.GetDataReadable(laststring).Trim()));
             Logger.WriteLine2("OK!");
         }
     }
     if(ret)
         bigbuilder.Append("All match checks are OK!");
     AddItem(new Common.PartsObject {
         Name = "Data Match Check",
         ActualString = bigbuilder.ToString(),
         ExpectedString = "No Failed matches are supposed to be listed!",
         Result = ret
     });
     return ret;
 }
コード例 #7
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
 private static bool CheckDataFill(ref byte[] data, Common.DataFillEntry dataFillEntry, bool reversed)
 {
     long Offset;
     long Length;
     if (dataFillEntry.LdrSize != 0 )
     {
         var tmpdata = new byte[2];
         Buffer.BlockCopy(data, (int)dataFillEntry.LdrSize, tmpdata, 0, tmpdata.Length);
         if (reversed)
             Common.SwapBytes(ref tmpdata);
         long ldrlength = Common.GetLdrSize(ref tmpdata);
         Offset = dataFillEntry.RegionStart + ldrlength;
         Length = dataFillEntry.RegionSize - ldrlength;
     }
     else if (dataFillEntry.vtrmentrycount_offset != 0)
     {
         var vtrmentrycount = new byte[2];
         Buffer.BlockCopy(data, (int)dataFillEntry.vtrmentrycount_offset, vtrmentrycount, 0, vtrmentrycount.Length);
         if (reversed == false)
             Common.SwapBytes(ref vtrmentrycount);
         var count = BitConverter.ToUInt16(vtrmentrycount, 0);
         var entrieslength = count * 0x60;
         Offset = dataFillEntry.RegionStart + entrieslength;
         Length = dataFillEntry.RegionSize - entrieslength;
     }
     else
     {
         Length = dataFillEntry.Length;
         Offset = dataFillEntry.Offset;
     }
     for (var i = Offset; i < Offset + Length; i++) {
         if (data[i] == dataFillEntry.Data)
             continue;
         AddItem(new Common.PartsObject {
             Name = dataFillEntry.Name,
             ActualString = string.Format("The byte @ offset: 0x{0:X}\r\nhas the value: 0x{1:X2}\r\nPlease check the data further down the line manually...", i, data[i]),
             ExpectedString = string.Format("The data between offset: 0x{0:X} and 0x{1:X} should be: {2:X2}", Offset, Offset + Length, dataFillEntry.Data),
             Result = false
         });
         Logger.WriteLine2(string.Format("FAILED!\r\nThe byte @ offset: 0x{0:X}\r\nhas the value: 0x{1:X2}\r\nPlease check the data further down the line manually...", i, data[i]));
         return false;
     }
     AddItem(new Common.PartsObject
     {
         Name = dataFillEntry.Name,
         ActualString = "All is OK!",
         ExpectedString = string.Format("The data between offset: 0x{0:X} and 0x{1:X} should be: {2:X2}", Offset, Offset + Length, dataFillEntry.Data),
         Result = true
     });
     Logger.WriteLine2("OK!");
     return true;
 }
コード例 #8
0
ファイル: Checks.cs プロジェクト: nerirififi/PS3DumpChecker
 private static void AddItem(Common.PartsObject data)
 {
     Common.AddItem(_checkId, data);
     _checkId++;
 }
コード例 #9
0
ファイル: Checks.cs プロジェクト: NiceShot/PS3DumpChecker
 private static bool CheckDataMatches(ref byte[] data, ref Common.TypeData checkdata)
 {
     var bigbuilder = new StringBuilder();
     var ret = true;
     foreach(var key in checkdata.DataMatchList.Value.Keys) {
         _checkckount++;
         var smallbuilder = new StringBuilder();
         var islastok = true;
         var testlist = new Dictionary<string, string>();
         var laststring = "";
         bigbuilder.AppendLine(string.Format("Check name: {0}", checkdata.DataMatchList.Value[key].Value.Name));
         foreach(var testdata in checkdata.DataMatchList.Value[key].Value.Data) {
             var tmp = Common.GetDataForTest(ref data, testdata.Offset, testdata.Length);
             if(!testlist.ContainsKey(tmp) && testlist.Count != 0)
                 islastok = false;
             if(!testlist.ContainsKey(tmp))
                 testlist.Add(tmp, testdata.Name);
             smallbuilder.AppendLine(string.Format("{0} : {1}", testdata.Name, tmp));
             laststring = tmp;
         }
         if(!islastok) {
             ret = false;
             bigbuilder.Append(smallbuilder); // Add to the big one
         }
         else
             bigbuilder.AppendLine(string.Format("All data matching: {0}", laststring));
     }
     if(ret)
         bigbuilder.Append("All match checks are OK!");
     AddItem(new Common.PartsObject {
         Name = "Data Match Check",
         ActualString = bigbuilder.ToString(),
         ExpectedString = "No Failed matches are supposed to be listed!",
         Result = ret
     });
     return ret;
 }
コード例 #10
0
ファイル: Checks.cs プロジェクト: NiceShot/PS3DumpChecker
 private static bool CheckDataFill(ref byte[] data, Common.DataFillEntry dataFillEntry)
 {
     for (var i = dataFillEntry.Offset; i < dataFillEntry.Offset + dataFillEntry.Length; i++) {
         if (data[i] == dataFillEntry.Data)
             continue;
         AddItem(new Common.PartsObject {
             Name = dataFillEntry.Name,
             ActualString = string.Format("The byte @ offset: 0x{0:X}\r\nhas the value: 0x{1:X2}\r\nPlease check the data further down the line manually...", i, data[i]),
             ExpectedString = string.Format("The data between offset: 0x{0:X} and 0x{1:X} should be: {2:X2}", dataFillEntry.Offset, dataFillEntry.Offset + dataFillEntry.Length, dataFillEntry.Data),
             Result = false
         });
         Logger.WriteLine2(string.Format("FAILED!\r\nThe byte @ offset: 0x{0:X}\r\nhas the value: 0x{1:X2}\r\nPlease check the data further down the line manually...", i, data[i]));
         return false;
     }
     AddItem(new Common.PartsObject
     {
         Name = dataFillEntry.Name,
         ActualString = "All is OK!",
         ExpectedString = string.Format("The data between offset: 0x{0:X} and 0x{1:X} should be: {2:X2}", dataFillEntry.Offset, dataFillEntry.Offset + dataFillEntry.Length, dataFillEntry.Data),
         Result = true
     });
     Logger.WriteLine2("OK!");
     return true;
 }