mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Prep Skippers for XML serialization
This commit is contained in:
@@ -12,18 +12,6 @@
|
|||||||
WordByteswap,
|
WordByteswap,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines the type of test to be done
|
|
||||||
/// </summary>
|
|
||||||
public enum HeaderSkipTest
|
|
||||||
{
|
|
||||||
Data = 0,
|
|
||||||
Or,
|
|
||||||
Xor,
|
|
||||||
And,
|
|
||||||
File,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines the operator to be used in a file test
|
/// Determines the operator to be used in a file test
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Schema;
|
using System.Xml.Schema;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace SabreTools.Skippers
|
namespace SabreTools.Skippers
|
||||||
{
|
{
|
||||||
@@ -20,26 +21,31 @@ namespace SabreTools.Skippers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Skipper name
|
/// Skipper name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlElement("name")]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Author names
|
/// Author names
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlElement("author")]
|
||||||
public string Author { get; set; } = string.Empty;
|
public string Author { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// File version
|
/// File version
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlElement("version")]
|
||||||
public string Version { get; set; } = string.Empty;
|
public string Version { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set of all rules in the skipper
|
/// Set of all rules in the skipper
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlArray("rule")]
|
||||||
public List<SkipperRule> Rules { get; set; } = new List<SkipperRule>();
|
public List<SkipperRule> Rules { get; set; } = new List<SkipperRule>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Filename the skipper lives in
|
/// Filename the skipper lives in
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlIgnore]
|
||||||
public string SourceFile { get; set; } = string.Empty;
|
public string SourceFile { get; set; } = string.Empty;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -129,7 +135,7 @@ namespace SabreTools.Skippers
|
|||||||
SkipperRule rule = ParseRule(xtr);
|
SkipperRule rule = ParseRule(xtr);
|
||||||
if (rule != null)
|
if (rule != null)
|
||||||
Rules.Add(rule);
|
Rules.Add(rule);
|
||||||
|
|
||||||
xtr.Read();
|
xtr.Read();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -227,7 +233,7 @@ namespace SabreTools.Skippers
|
|||||||
|
|
||||||
subreader.Read();
|
subreader.Read();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
subreader.Read();
|
subreader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -256,41 +262,27 @@ namespace SabreTools.Skippers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get the test type
|
// Get the test type
|
||||||
SkipperTest test = new SkipperTest
|
SkipperTest test = xtr.Name.ToLowerInvariant() switch
|
||||||
{
|
{
|
||||||
Offset = 0,
|
"and" => new AndSkipperTest(),
|
||||||
Value = new byte[0],
|
"data" => new DataSkipperTest(),
|
||||||
Result = true,
|
"file" => new FileSkipperTest(),
|
||||||
Mask = new byte[0],
|
"or" => new OrSkipperTest(),
|
||||||
Size = 0,
|
"xor" => new XorSkipperTest(),
|
||||||
Operator = HeaderSkipTestFileOperator.Equal,
|
_ => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (xtr.Name.ToLowerInvariant())
|
// If we had an invalid test type
|
||||||
{
|
if (test == null)
|
||||||
case "data":
|
return null;
|
||||||
test.Type = HeaderSkipTest.Data;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "or":
|
// Set the default values
|
||||||
test.Type = HeaderSkipTest.Or;
|
test.Offset = 0;
|
||||||
break;
|
test.Value = Array.Empty<byte>();
|
||||||
|
test.Result = true;
|
||||||
case "xor":
|
test.Mask = Array.Empty<byte>();
|
||||||
test.Type = HeaderSkipTest.Xor;
|
test.Size = 0;
|
||||||
break;
|
test.Operator = HeaderSkipTestFileOperator.Equal;
|
||||||
|
|
||||||
case "and":
|
|
||||||
test.Type = HeaderSkipTest.And;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "file":
|
|
||||||
test.Type = HeaderSkipTest.File;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now populate all the parts that we can
|
// Now populate all the parts that we can
|
||||||
if (xtr.GetAttribute("offset") != null)
|
if (xtr.GetAttribute("offset") != null)
|
||||||
|
|||||||
@@ -11,17 +11,15 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public Atari7800()
|
public Atari7800()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x01,
|
Offset = 0x01,
|
||||||
Value = new byte[] { 0x41, 0x54, 0x41, 0x52, 0x49, 0x37, 0x38, 0x30, 0x30 },
|
Value = new byte[] { 0x41, 0x54, 0x41, 0x52, 0x49, 0x37, 0x38, 0x30, 0x30 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule2Test1 = new SkipperTest
|
var rule2Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x64,
|
Offset = 0x64,
|
||||||
Value = new byte[] { 0x41, 0x43, 0x54, 0x55, 0x41, 0x4C, 0x20, 0x43, 0x41, 0x52, 0x54, 0x20, 0x44, 0x41, 0x54, 0x41, 0x20, 0x53, 0x54, 0x41, 0x52, 0x54, 0x53, 0x20, 0x48, 0x45, 0x52, 0x45 },
|
Value = new byte[] { 0x41, 0x43, 0x54, 0x55, 0x41, 0x4C, 0x20, 0x43, 0x41, 0x52, 0x54, 0x20, 0x44, 0x41, 0x54, 0x41, 0x20, 0x53, 0x54, 0x41, 0x52, 0x54, 0x53, 0x20, 0x48, 0x45, 0x52, 0x45 },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -11,17 +11,15 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public AtariLynx()
|
public AtariLynx()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x4C, 0x59, 0x4E, 0x58 },
|
Value = new byte[] { 0x4C, 0x59, 0x4E, 0x58 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule2Test1 = new SkipperTest
|
var rule2Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x06,
|
Offset = 0x06,
|
||||||
Value = new byte[] { 0x42, 0x53, 0x39 },
|
Value = new byte[] { 0x42, 0x53, 0x39 },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -11,41 +11,36 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public CommodorePSID()
|
public CommodorePSID()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x50, 0x53, 0x49, 0x44, 0x00, 0x01, 0x00, 0x76 },
|
Value = new byte[] { 0x50, 0x53, 0x49, 0x44, 0x00, 0x01, 0x00, 0x76 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule2Test1 = new SkipperTest
|
var rule2Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x50, 0x53, 0x49, 0x44, 0x00, 0x03, 0x00, 0x7c },
|
Value = new byte[] { 0x50, 0x53, 0x49, 0x44, 0x00, 0x03, 0x00, 0x7c },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule3Test1 = new SkipperTest
|
var rule3Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x50, 0x53, 0x49, 0x44, 0x00, 0x02, 0x00, 0x7c },
|
Value = new byte[] { 0x50, 0x53, 0x49, 0x44, 0x00, 0x02, 0x00, 0x7c },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule4Test1 = new SkipperTest
|
var rule4Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x50, 0x53, 0x49, 0x44, 0x00, 0x01, 0x00, 0x7c },
|
Value = new byte[] { 0x50, 0x53, 0x49, 0x44, 0x00, 0x01, 0x00, 0x7c },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule5Test1 = new SkipperTest
|
var rule5Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x52, 0x53, 0x49, 0x44, 0x00, 0x02, 0x00, 0x7c },
|
Value = new byte[] { 0x52, 0x53, 0x49, 0x44, 0x00, 0x02, 0x00, 0x7c },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public NECPCEngine()
|
public NECPCEngine()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xBB, 0x02 },
|
Value = new byte[] { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xBB, 0x02 },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -11,25 +11,22 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public Nintendo64()
|
public Nintendo64()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x80, 0x37, 0x12, 0x40 },
|
Value = new byte[] { 0x80, 0x37, 0x12, 0x40 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule2Test1 = new SkipperTest
|
var rule2Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x37, 0x80, 0x40, 0x12 },
|
Value = new byte[] { 0x37, 0x80, 0x40, 0x12 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule3Test1 = new SkipperTest
|
var rule3Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x40, 0x12, 0x37, 0x80 },
|
Value = new byte[] { 0x40, 0x12, 0x37, 0x80 },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public NintendoEntertainmentSystem()
|
public NintendoEntertainmentSystem()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x4E, 0x45, 0x53, 0x1A },
|
Value = new byte[] { 0x4E, 0x45, 0x53, 0x1A },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -11,33 +11,29 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public NintendoFamicomDiskSystem()
|
public NintendoFamicomDiskSystem()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x46, 0x44, 0x53, 0x1A, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
Value = new byte[] { 0x46, 0x44, 0x53, 0x1A, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule2Test1 = new SkipperTest
|
var rule2Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x46, 0x44, 0x53, 0x1A, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
Value = new byte[] { 0x46, 0x44, 0x53, 0x1A, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule3Test1 = new SkipperTest
|
var rule3Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x46, 0x44, 0x53, 0x1A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
Value = new byte[] { 0x46, 0x44, 0x53, 0x1A, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule4Test1 = new SkipperTest
|
var rule4Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x46, 0x44, 0x53, 0x1A, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
Value = new byte[] { 0x46, 0x44, 0x53, 0x1A, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public SuperFamicomSPC()
|
public SuperFamicomSPC()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x00,
|
Offset = 0x00,
|
||||||
Value = new byte[] { 0x53, 0x4E, 0x45, 0x53, 0x2D, 0x53, 0x50, 0x43 },
|
Value = new byte[] { 0x53, 0x4E, 0x45, 0x53, 0x2D, 0x53, 0x50, 0x43 },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -11,25 +11,22 @@ namespace SabreTools.Skippers.SkipperFiles
|
|||||||
public SuperNintendoEntertainmentSystem()
|
public SuperNintendoEntertainmentSystem()
|
||||||
{
|
{
|
||||||
// Create tests
|
// Create tests
|
||||||
var rule1Test1 = new SkipperTest
|
var rule1Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x16,
|
Offset = 0x16,
|
||||||
Value = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
Value = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule2Test1 = new SkipperTest
|
var rule2Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x16,
|
Offset = 0x16,
|
||||||
Value = new byte[] { 0xAA, 0xBB, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
Value = new byte[] { 0xAA, 0xBB, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||||
Result = true,
|
Result = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var rule3Test1 = new SkipperTest
|
var rule3Test1 = new DataSkipperTest
|
||||||
{
|
{
|
||||||
Type = HeaderSkipTest.Data,
|
|
||||||
Offset = 0x16,
|
Offset = 0x16,
|
||||||
Value = new byte[] { 0x53, 0x55, 0x50, 0x45, 0x52, 0x55, 0x46, 0x4F },
|
Value = new byte[] { 0x53, 0x55, 0x50, 0x45, 0x52, 0x55, 0x46, 0x4F },
|
||||||
Result = true,
|
Result = true,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
using SabreTools.Logging;
|
using SabreTools.Logging;
|
||||||
|
|
||||||
@@ -13,26 +14,36 @@ namespace SabreTools.Skippers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starting offset for applying rule
|
/// Starting offset for applying rule
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlAttribute("start_offset")]
|
||||||
public long? StartOffset { get; set; } // null is EOF
|
public long? StartOffset { get; set; } // null is EOF
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ending offset for applying rule
|
/// Ending offset for applying rule
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlAttribute("end_offset")]
|
||||||
public long? EndOffset { get; set; } // null if EOF
|
public long? EndOffset { get; set; } // null if EOF
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Byte manipulation operation
|
/// Byte manipulation operation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlAttribute("operation")]
|
||||||
public HeaderSkipOperation Operation { get; set; }
|
public HeaderSkipOperation Operation { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of matching tests in a rule
|
/// List of matching tests in a rule
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlArray]
|
||||||
|
[XmlArrayItem("data")]
|
||||||
|
[XmlArrayItem("or")]
|
||||||
|
[XmlArrayItem("xor")]
|
||||||
|
[XmlArrayItem("and")]
|
||||||
|
[XmlArrayItem("file")]
|
||||||
public List<SkipperTest> Tests { get; set; }
|
public List<SkipperTest> Tests { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Filename the skipper rule lives in
|
/// Filename the skipper rule lives in
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlIgnore]
|
||||||
public string SourceFile { get; set; }
|
public string SourceFile { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,49 +1,52 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace SabreTools.Skippers
|
namespace SabreTools.Skippers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Individual test that applies to a SkipperRule
|
/// Individual test that applies to a SkipperRule
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SkipperTest
|
public abstract class SkipperTest
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Type of test to be run
|
|
||||||
/// </summary>
|
|
||||||
public HeaderSkipTest Type { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// File offset to run the test
|
/// File offset to run the test
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>null is EOF</remarks>
|
/// <remarks>null is EOF</remarks>
|
||||||
|
[XmlAttribute("offset")]
|
||||||
public long? Offset { get; set; }
|
public long? Offset { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Static value to be checked at the offset
|
/// Static value to be checked at the offset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlAttribute("value")]
|
||||||
public byte[] Value { get; set; }
|
public byte[] Value { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether a pass or failure is expected
|
/// Determines whether a pass or failure is expected
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlAttribute("result")]
|
||||||
public bool Result { get; set; }
|
public bool Result { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Byte mask to be applied to the tested bytes
|
/// Byte mask to be applied to the tested bytes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlAttribute("mask")]
|
||||||
public byte[] Mask { get; set; }
|
public byte[] Mask { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Expected size of the input byte array, used with the Operator
|
/// Expected size of the input byte array, used with the Operator
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlAttribute("size")]
|
||||||
public long? Size { get; set; } // null is PO2, "power of 2" filesize
|
public long? Size { get; set; } // null is PO2, "power of 2" filesize
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Expected range value for the input byte array size, used with Size
|
/// Expected range value for the input byte array size, used with Size
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[XmlAttribute("operator")]
|
||||||
public HeaderSkipTestFileOperator Operator { get; set; }
|
public HeaderSkipTestFileOperator Operator { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -53,27 +56,50 @@ namespace SabreTools.Skippers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Stream to check rule against</param>
|
/// <param name="input">Stream to check rule against</param>
|
||||||
/// <remarks>The Stream is assumed to be in the proper position for a given test</remarks>
|
/// <remarks>The Stream is assumed to be in the proper position for a given test</remarks>
|
||||||
public bool Passes(Stream input)
|
public abstract bool Passes(Stream input);
|
||||||
{
|
|
||||||
return Type switch
|
|
||||||
{
|
|
||||||
HeaderSkipTest.And => CheckAnd(input),
|
|
||||||
HeaderSkipTest.Data => CheckData(input),
|
|
||||||
HeaderSkipTest.File => CheckFile(input),
|
|
||||||
HeaderSkipTest.Or => CheckOr(input),
|
|
||||||
HeaderSkipTest.Xor => CheckXor(input),
|
|
||||||
_ => true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Checking Helpers
|
#region Checking Helpers
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run an And test against an input stream
|
/// Seek an input stream based on the test value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Stream to check rule against</param>
|
/// <param name="input">Stream to seek</param>
|
||||||
/// <returns>True if the stream passed, false otherwise</returns>
|
/// <returns>True if the stream could seek, false on error</returns>
|
||||||
private bool CheckAnd(Stream input)
|
protected bool Seek(Stream input)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Null offset means EOF
|
||||||
|
if (Offset == null)
|
||||||
|
input.Seek(0, SeekOrigin.End);
|
||||||
|
|
||||||
|
// Positive offset means from beginning
|
||||||
|
else if (Offset >= 0 && Offset <= input.Length)
|
||||||
|
input.Seek(Offset.Value, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
// Negative offset means from end
|
||||||
|
else if (Offset < 0 && Math.Abs(Offset.Value) <= input.Length)
|
||||||
|
input.Seek(Offset.Value, SeekOrigin.End);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Skipper test using AND
|
||||||
|
/// </summary>
|
||||||
|
[XmlRoot("and")]
|
||||||
|
public class AndSkipperTest : SkipperTest
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool Passes(Stream input)
|
||||||
{
|
{
|
||||||
// First seek to the correct position
|
// First seek to the correct position
|
||||||
Seek(input);
|
Seek(input);
|
||||||
@@ -109,13 +135,16 @@ namespace SabreTools.Skippers
|
|||||||
// Return if the expected and actual results match
|
// Return if the expected and actual results match
|
||||||
return result == Result;
|
return result == Result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run a Data test against an input stream
|
/// Skipper test using DATA
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Stream to check rule against</param>
|
[XmlRoot("data")]
|
||||||
/// <returns>True if the stream passed, false otherwise</returns>
|
public class DataSkipperTest : SkipperTest
|
||||||
private bool CheckData(Stream input)
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool Passes(Stream input)
|
||||||
{
|
{
|
||||||
// First seek to the correct position
|
// First seek to the correct position
|
||||||
if (!Seek(input))
|
if (!Seek(input))
|
||||||
@@ -143,13 +172,16 @@ namespace SabreTools.Skippers
|
|||||||
// Return if the expected and actual results match
|
// Return if the expected and actual results match
|
||||||
return result == Result;
|
return result == Result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run a File test against an input stream
|
/// Skipper test using FILE
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Stream to check rule against</param>
|
[XmlRoot("file")]
|
||||||
/// <returns>True if the stream passed, false otherwise</returns>
|
public class FileSkipperTest : SkipperTest
|
||||||
private bool CheckFile(Stream input)
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool Passes(Stream input)
|
||||||
{
|
{
|
||||||
// First get the file size from stream
|
// First get the file size from stream
|
||||||
long size = input.Length;
|
long size = input.Length;
|
||||||
@@ -177,13 +209,16 @@ namespace SabreTools.Skippers
|
|||||||
// Return if the expected and actual results match
|
// Return if the expected and actual results match
|
||||||
return result == Result;
|
return result == Result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run an Or test against an input stream
|
/// Skipper test using OR
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Stream to check rule against</param>
|
[XmlRoot("or")]
|
||||||
/// <returns>True if the stream passed, false otherwise</returns>
|
public class OrSkipperTest : SkipperTest
|
||||||
private bool CheckOr(Stream input)
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool Passes(Stream input)
|
||||||
{
|
{
|
||||||
// First seek to the correct position
|
// First seek to the correct position
|
||||||
Seek(input);
|
Seek(input);
|
||||||
@@ -219,13 +254,16 @@ namespace SabreTools.Skippers
|
|||||||
// Return if the expected and actual results match
|
// Return if the expected and actual results match
|
||||||
return result == Result;
|
return result == Result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run an Xor test against an input stream
|
/// Skipper test using XOR
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Stream to check rule against</param>
|
[XmlRoot("xor")]
|
||||||
/// <returns>True if the stream passed, false otherwise</returns>
|
public class XorSkipperTest : SkipperTest
|
||||||
private bool CheckXor(Stream input)
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool Passes(Stream input)
|
||||||
{
|
{
|
||||||
// First seek to the correct position
|
// First seek to the correct position
|
||||||
Seek(input);
|
Seek(input);
|
||||||
@@ -261,36 +299,5 @@ namespace SabreTools.Skippers
|
|||||||
// Return if the expected and actual results match
|
// Return if the expected and actual results match
|
||||||
return result == Result;
|
return result == Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Seek an input stream based on the test value
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">Stream to seek</param>
|
|
||||||
/// <returns>True if the stream could seek, false on error</returns>
|
|
||||||
private bool Seek(Stream input)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Null offset means EOF
|
|
||||||
if (Offset == null)
|
|
||||||
input.Seek(0, SeekOrigin.End);
|
|
||||||
|
|
||||||
// Positive offset means from beginning
|
|
||||||
else if (Offset >= 0 && Offset <= input.Length)
|
|
||||||
input.Seek(Offset.Value, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
// Negative offset means from end
|
|
||||||
else if (Offset < 0 && Math.Abs(Offset.Value) <= input.Length)
|
|
||||||
input.Seek(Offset.Value, SeekOrigin.End);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user