Abstract binary file format detection into FileFormatReader.Load
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NoisyCowStudios.Bin2Object;
|
||||
|
||||
namespace Il2CppInspector
|
||||
@@ -35,6 +37,22 @@ namespace Il2CppInspector
|
||||
List<U> ReadMappedObjectPointerArray<U>(uint uiAddr, int count) where U : new();
|
||||
}
|
||||
|
||||
internal class FileFormatReader
|
||||
{
|
||||
// Helper method to try all defined file formats when the contents of the binary is unknown
|
||||
public static IFileFormatReader Load(Stream stream) {
|
||||
var types = Assembly.GetExecutingAssembly().DefinedTypes
|
||||
.Where(x => x.ImplementedInterfaces.Contains(typeof(IFileFormatReader)) && !x.IsGenericTypeDefinition);
|
||||
|
||||
foreach (var type in types) {
|
||||
if (type.BaseType.GetMethod("Load", new [] {typeof(Stream)})
|
||||
.Invoke(null, new object[] { stream }) is IFileFormatReader loaded)
|
||||
return loaded;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal class FileFormatReader<T> : BinaryObjectReader, IFileFormatReader where T : FileFormatReader<T>
|
||||
{
|
||||
public FileFormatReader(Stream stream) : base(stream) { }
|
||||
|
||||
Reference in New Issue
Block a user