Start making Detectable a bit better

This commit is contained in:
Matt Nadareski
2025-09-06 10:01:09 -04:00
parent 43b3c72a02
commit 821b91a555
9 changed files with 61 additions and 90 deletions

View File

@@ -1,26 +1,15 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// AACS media key block
/// </summary>
public class AACSMediaKeyBlock : IDetectable<SabreTools.Serialization.Wrappers.AACSMediaKeyBlock>
public class AACSMediaKeyBlock : DetectableBase<SabreTools.Serialization.Wrappers.AACSMediaKeyBlock>
{
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public string? Detect(Stream stream, string file, bool includeDebug)
public override string? Detect(Stream stream, string file, bool includeDebug)
{
// Create the wrapper
var mkb = SabreTools.Serialization.Wrappers.AACSMediaKeyBlock.Create(stream);

View File

@@ -0,0 +1,34 @@
using System.IO;
using BinaryObjectScanner.Interfaces;
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// Base class for all standard detectable types
/// </summary>
public abstract class DetectableBase : IDetectable
{
#region Constructors
public DetectableBase() { }
#endregion
#region IDetectable Implementations
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public abstract string? Detect(Stream stream, string file, bool includeDebug);
#endregion
}
}

View File

@@ -0,0 +1,13 @@
using BinaryObjectScanner.Interfaces;
using SabreTools.Serialization.Interfaces;
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// Base class for all standard detectable types with a wrapper
/// </summary>
public abstract class DetectableBase<T> : DetectableBase, IDetectable<T> where T : IWrapper
{
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -8,20 +7,10 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// Link Data Security encrypted file
/// </summary>
public class LDSCRYPT : IDetectable
public class LDSCRYPT : DetectableBase
{
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public string? Detect(Stream stream, string file, bool includeDebug)
public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{

View File

@@ -1,6 +1,5 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -8,20 +7,10 @@ namespace BinaryObjectScanner.FileType
/// <summary>
/// PlayJ audio file
/// </summary>
public class PLJ : IDetectable<SabreTools.Serialization.Wrappers.PlayJAudioFile>
public class PLJ : DetectableBase<SabreTools.Serialization.Wrappers.PlayJAudioFile>
{
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public string? Detect(Stream stream, string file, bool includeDebug)
public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{

View File

@@ -1,6 +1,5 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -10,20 +9,10 @@ namespace BinaryObjectScanner.FileType
///
/// TODO: Add further parsing, game ID and name should be possible to parse.
/// </summary>
public class RealArcadeInstaller : IDetectable
public class RealArcadeInstaller : DetectableBase
{
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public string? Detect(Stream stream, string file, bool includeDebug)
public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{

View File

@@ -1,6 +1,5 @@
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -10,20 +9,10 @@ namespace BinaryObjectScanner.FileType
///
/// TODO: Add further parsing, game ID should be possible to parse.
/// </summary>
public class RealArcadeMezzanine : IDetectable
public class RealArcadeMezzanine : DetectableBase
{
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public string? Detect(Stream stream, string file, bool includeDebug)
public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{

View File

@@ -9,20 +9,10 @@ namespace BinaryObjectScanner.FileType
/// StarForce Filesystem file
/// </summary>
/// <see href="https://forum.xentax.com/viewtopic.php?f=21&t=2084"/>
public class SFFS : IExtractable, IDetectable
public class SFFS : DetectableBase, IExtractable
{
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public string? Detect(Stream stream, string file, bool includeDebug)
public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{

View File

@@ -2,27 +2,16 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using BinaryObjectScanner.Interfaces;
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// Various generic textfile formats
/// </summary>
public class Textfile : IDetectable
public class Textfile : DetectableBase
{
/// <inheritdoc/>
public string? Detect(string file, bool includeDebug)
{
if (!File.Exists(file))
return null;
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return Detect(fs, file, includeDebug);
}
/// <inheritdoc/>
public string? Detect(Stream stream, string file, bool includeDebug)
public override string? Detect(Stream stream, string file, bool includeDebug)
{
// Files can be protected in multiple ways
var protections = new List<string>();