Rework metadata struct loading to use new struct versioning
This commit is contained in:
@@ -94,6 +94,9 @@ namespace Il2CppInspector
|
|||||||
long[] ReadMappedWordArray(ulong uiAddr, int count);
|
long[] ReadMappedWordArray(ulong uiAddr, int count);
|
||||||
List<U> ReadMappedObjectPointerArray<U>(ulong uiAddr, int count) where U : new();
|
List<U> ReadMappedObjectPointerArray<U>(ulong uiAddr, int count) where U : new();
|
||||||
|
|
||||||
|
ulong ReadMappedUWord(ulong uiAddr);
|
||||||
|
ulong[] ReadMappedUWordArray(ulong uiAddr, int count);
|
||||||
|
|
||||||
void WriteEndianBytes(byte[] bytes);
|
void WriteEndianBytes(byte[] bytes);
|
||||||
void Write(long int64);
|
void Write(long int64);
|
||||||
void Write(ulong uint64);
|
void Write(ulong uint64);
|
||||||
@@ -144,6 +147,9 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
public ImmutableArray<TType> ReadVersionedObjectArray<TType>(long count)
|
public ImmutableArray<TType> ReadVersionedObjectArray<TType>(long count)
|
||||||
where TType : IReadable, new();
|
where TType : IReadable, new();
|
||||||
|
|
||||||
|
public ImmutableArray<TType> ReadMappedVersionedObjectPointerArray<TType>(ulong addr, int count)
|
||||||
|
where TType : IReadable, new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FileFormatStream
|
public class FileFormatStream
|
||||||
@@ -356,5 +362,32 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
public ImmutableArray<TType> ReadMappedVersionedObjectArray<TType>(ulong addr, long count) where TType : IReadable, new()
|
public ImmutableArray<TType> ReadMappedVersionedObjectArray<TType>(ulong addr, long count) where TType : IReadable, new()
|
||||||
=> ReadVersionedObjectArray<TType>(MapVATR(addr), count);
|
=> ReadVersionedObjectArray<TType>(MapVATR(addr), count);
|
||||||
|
|
||||||
|
public ImmutableArray<TType> ReadMappedVersionedObjectPointerArray<TType>(ulong addr, int count)
|
||||||
|
where TType : IReadable, new()
|
||||||
|
{
|
||||||
|
var pointers = ReadMappedUWordArray(addr, count);
|
||||||
|
var builder = ImmutableArray.CreateBuilder<TType>((int)count);
|
||||||
|
for (long i = 0; i < count; i++)
|
||||||
|
builder.Add(ReadMappedVersionedObject<TType>(pointers[i]));
|
||||||
|
|
||||||
|
return builder.MoveToImmutable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong ReadMappedUWord(ulong uiAddr)
|
||||||
|
{
|
||||||
|
Position = MapVATR(uiAddr);
|
||||||
|
return ReadNUInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong[] ReadMappedUWordArray(ulong uiAddr, int count)
|
||||||
|
{
|
||||||
|
Position = MapVATR(uiAddr);
|
||||||
|
var arr = new ulong[count];
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
arr[i] = ReadNUInt();
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,11 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
using Il2CppInspector.Next;
|
||||||
using Il2CppInspector.Next.BinaryMetadata;
|
using Il2CppInspector.Next.BinaryMetadata;
|
||||||
using Il2CppInspector.Next.Metadata;
|
using Il2CppInspector.Next.Metadata;
|
||||||
using Il2CppInspector.Reflection;
|
using Il2CppInspector.Reflection;
|
||||||
using Il2CppInspector.Utils;
|
using Il2CppInspector.Utils;
|
||||||
using NoisyCowStudios.Bin2Object;
|
|
||||||
|
|
||||||
namespace Il2CppInspector
|
namespace Il2CppInspector
|
||||||
{
|
{
|
||||||
@@ -16,7 +16,7 @@ namespace Il2CppInspector
|
|||||||
{
|
{
|
||||||
private readonly Il2CppInspector _inspector;
|
private readonly Il2CppInspector _inspector;
|
||||||
private readonly Assembly _assembly;
|
private readonly Assembly _assembly;
|
||||||
private readonly BinaryObjectStream _data;
|
private readonly BinaryObjectStreamReader _data;
|
||||||
|
|
||||||
private readonly uint _start;
|
private readonly uint _start;
|
||||||
private readonly uint _end;
|
private readonly uint _end;
|
||||||
@@ -26,7 +26,7 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
public uint Count { get; }
|
public uint Count { get; }
|
||||||
|
|
||||||
public CustomAttributeDataReader(Il2CppInspector inspector, Assembly assembly, BinaryObjectStream data, uint startOffset, uint endOffset)
|
public CustomAttributeDataReader(Il2CppInspector inspector, Assembly assembly, BinaryObjectStreamReader data, uint startOffset, uint endOffset)
|
||||||
{
|
{
|
||||||
_inspector = inspector;
|
_inspector = inspector;
|
||||||
_assembly = assembly;
|
_assembly = assembly;
|
||||||
@@ -146,8 +146,8 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
private TypeInfo ConvertTypeDef(Il2CppTypeDefinition typeDef, Il2CppTypeEnum type)
|
private TypeInfo ConvertTypeDef(Il2CppTypeDefinition typeDef, Il2CppTypeEnum type)
|
||||||
=> typeDef.IsValid
|
=> typeDef.IsValid
|
||||||
? _assembly.Model.GetTypeDefinitionFromTypeEnum(type)
|
? _assembly.Model.TypesByDefinitionIndex[_inspector.TypeDefinitions.IndexOf(typeDef)]
|
||||||
: _assembly.Model.TypesByDefinitionIndex[Array.IndexOf(_inspector.TypeDefinitions, typeDef)];
|
: _assembly.Model.GetTypeDefinitionFromTypeEnum(type);
|
||||||
|
|
||||||
private (TypeInfo, int) ReadCustomAttributeNamedArgumentClassAndIndex(TypeInfo attrInfo)
|
private (TypeInfo, int) ReadCustomAttributeNamedArgumentClassAndIndex(TypeInfo attrInfo)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
using Il2CppInspector.Next;
|
using Il2CppInspector.Next;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -37,16 +38,16 @@ namespace Il2CppInspector
|
|||||||
public ulong CodeRegistrationPointer { get; private set; }
|
public ulong CodeRegistrationPointer { get; private set; }
|
||||||
public ulong MetadataRegistrationPointer { get; private set; }
|
public ulong MetadataRegistrationPointer { get; private set; }
|
||||||
public ulong RegistrationFunctionPointer { get; private set; }
|
public ulong RegistrationFunctionPointer { get; private set; }
|
||||||
public Dictionary<string, ulong> CodeGenModulePointers { get; } = new Dictionary<string, ulong>();
|
public Dictionary<string, ulong> CodeGenModulePointers { get; } = new();
|
||||||
|
|
||||||
// Only for <=v24.1
|
// Only for <=v24.1
|
||||||
public ulong[] GlobalMethodPointers { get; set; }
|
public ulong[] GlobalMethodPointers { get; set; }
|
||||||
|
|
||||||
// Only for >=v24.2
|
// Only for >=v24.2
|
||||||
public Dictionary<Il2CppCodeGenModule, ulong[]> ModuleMethodPointers { get; set; } = new Dictionary<Il2CppCodeGenModule, ulong[]>();
|
public Dictionary<Il2CppCodeGenModule, ulong[]> ModuleMethodPointers { get; set; } = new();
|
||||||
|
|
||||||
// Only for >=v24.2. In earlier versions, invoker indices are stored in Il2CppMethodDefinition in the metadata file
|
// Only for >=v24.2. In earlier versions, invoker indices are stored in Il2CppMethodDefinition in the metadata file
|
||||||
public Dictionary<Il2CppCodeGenModule, int[]> MethodInvokerIndices { get; set; } = new Dictionary<Il2CppCodeGenModule, int[]>();
|
public Dictionary<Il2CppCodeGenModule, ImmutableArray<int>> MethodInvokerIndices { get; set; } = new();
|
||||||
|
|
||||||
// NOTE: In versions <21 and earlier releases of v21, use FieldOffsets:
|
// NOTE: In versions <21 and earlier releases of v21, use FieldOffsets:
|
||||||
// global field index => field offset
|
// global field index => field offset
|
||||||
@@ -54,7 +55,7 @@ namespace Il2CppInspector
|
|||||||
// type index => RVA in image where the list of field offsets for the type start (4 bytes per field)
|
// type index => RVA in image where the list of field offsets for the type start (4 bytes per field)
|
||||||
|
|
||||||
// Negative field offsets from start of each function
|
// Negative field offsets from start of each function
|
||||||
public uint[] FieldOffsets { get; private set; }
|
public ImmutableArray<uint> FieldOffsets { get; private set; }
|
||||||
|
|
||||||
// Pointers to field offsets
|
// Pointers to field offsets
|
||||||
public long[] FieldOffsetPointers { get; private set; }
|
public long[] FieldOffsetPointers { get; private set; }
|
||||||
@@ -68,13 +69,13 @@ namespace Il2CppInspector
|
|||||||
public ulong[] MethodInvokePointers { get; private set; }
|
public ulong[] MethodInvokePointers { get; private set; }
|
||||||
|
|
||||||
// Version 16 and below: method references for vtable
|
// Version 16 and below: method references for vtable
|
||||||
public uint[] VTableMethodReferences { get; private set; }
|
public ImmutableArray<uint> VTableMethodReferences { get; private set; }
|
||||||
|
|
||||||
// Generic method specs for vtables
|
// Generic method specs for vtables
|
||||||
public Il2CppMethodSpec[] MethodSpecs { get; private set; }
|
public ImmutableArray<Il2CppMethodSpec> MethodSpecs { get; private set; }
|
||||||
|
|
||||||
// List of run-time concrete generic class and method signatures
|
// List of run-time concrete generic class and method signatures
|
||||||
public List<Il2CppGenericInst> GenericInstances { get; private set; }
|
public ImmutableArray<Il2CppGenericInst> GenericInstances { get; private set; }
|
||||||
|
|
||||||
// List of constructed generic method function pointers corresponding to each possible method instantiation
|
// List of constructed generic method function pointers corresponding to each possible method instantiation
|
||||||
public Dictionary<Il2CppMethodSpec, ulong> GenericMethodPointers { get; } = new Dictionary<Il2CppMethodSpec, ulong>();
|
public Dictionary<Il2CppMethodSpec, ulong> GenericMethodPointers { get; } = new Dictionary<Il2CppMethodSpec, ulong>();
|
||||||
@@ -83,7 +84,7 @@ namespace Il2CppInspector
|
|||||||
public Dictionary<Il2CppMethodSpec, int> GenericMethodInvokerIndices { get; } = new Dictionary<Il2CppMethodSpec, int>();
|
public Dictionary<Il2CppMethodSpec, int> GenericMethodInvokerIndices { get; } = new Dictionary<Il2CppMethodSpec, int>();
|
||||||
|
|
||||||
// Every type reference (TypeRef) sorted by index
|
// Every type reference (TypeRef) sorted by index
|
||||||
public List<Il2CppType> TypeReferences { get; private set; }
|
public ImmutableArray<Il2CppType> TypeReferences { get; private set; }
|
||||||
|
|
||||||
// Every type reference index sorted by virtual address
|
// Every type reference index sorted by virtual address
|
||||||
public Dictionary<ulong, int> TypeReferenceIndicesByAddress { get; private set; }
|
public Dictionary<ulong, int> TypeReferenceIndicesByAddress { get; private set; }
|
||||||
@@ -92,7 +93,7 @@ namespace Il2CppInspector
|
|||||||
// One assembly may contain multiple modules
|
// One assembly may contain multiple modules
|
||||||
public Dictionary<string, Il2CppCodeGenModule> Modules { get; private set; }
|
public Dictionary<string, Il2CppCodeGenModule> Modules { get; private set; }
|
||||||
|
|
||||||
public List<Il2CppTypeDefinitionSizes> TypeDefinitionSizes { get; private set; }
|
public ImmutableArray<Il2CppTypeDefinitionSizes> TypeDefinitionSizes { get; private set; }
|
||||||
|
|
||||||
// Status update callback
|
// Status update callback
|
||||||
private EventHandler<string> OnStatusUpdate { get; set; }
|
private EventHandler<string> OnStatusUpdate { get; set; }
|
||||||
@@ -280,30 +281,8 @@ namespace Il2CppInspector
|
|||||||
Console.WriteLine("MetadataRegistration struct found at 0x{0:X16} (file offset 0x{1:X8})", Image.Bits == 32 ? metadataRegistration & 0xffff_ffff : metadataRegistration, Image.MapVATR(metadataRegistration));
|
Console.WriteLine("MetadataRegistration struct found at 0x{0:X16} (file offset 0x{1:X8})", Image.Bits == 32 ? metadataRegistration & 0xffff_ffff : metadataRegistration, Image.MapVATR(metadataRegistration));
|
||||||
|
|
||||||
// Root structures from which we find everything else
|
// Root structures from which we find everything else
|
||||||
CodeRegistration = Image.ReadMappedObject<Il2CppCodeRegistration>(codeRegistration);
|
CodeRegistration = Image.ReadMappedVersionedObject<Il2CppCodeRegistration>(codeRegistration);
|
||||||
MetadataRegistration = Image.ReadMappedObject<Il2CppMetadataRegistration>(metadataRegistration);
|
MetadataRegistration = Image.ReadMappedVersionedObject<Il2CppMetadataRegistration>(metadataRegistration);
|
||||||
|
|
||||||
// genericAdjustorThunks was inserted before invokerPointersCount in 24.5 and 27.1
|
|
||||||
// pointer expected if we need to bump version
|
|
||||||
if (Image.Version == MetadataVersions.V244 && CodeRegistration.InvokerPointersCount > 0x50000)
|
|
||||||
{
|
|
||||||
Image.Version = MetadataVersions.V245;
|
|
||||||
CodeRegistration = Image.ReadMappedObject<Il2CppCodeRegistration>(codeRegistration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Image.Version == MetadataVersions.V244 && CodeRegistration.ReversePInvokeWrapperCount > 0x50000) {
|
|
||||||
Image.Version = MetadataVersions.V245;
|
|
||||||
codeRegistration -= 1 * pointerSize;
|
|
||||||
CodeRegistration = Image.ReadMappedObject<Il2CppCodeRegistration>(codeRegistration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((Image.Version == MetadataVersions.V290 || Image.Version == MetadataVersions.V310) &&
|
|
||||||
(long)CodeRegistration.GenericMethodPointersCount - MetadataRegistration.GenericMethodTableCount > 0x10000)
|
|
||||||
{
|
|
||||||
Image.Version = new StructVersion(Image.Version.Major, 1, Image.Version.Tag);
|
|
||||||
codeRegistration -= 2 * pointerSize;
|
|
||||||
CodeRegistration = Image.ReadMappedObject<Il2CppCodeRegistration>(codeRegistration);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plugin hook to pre-process binary
|
// Plugin hook to pre-process binary
|
||||||
isModified |= PluginHooks.PreProcessBinary(this).IsStreamModified;
|
isModified |= PluginHooks.PreProcessBinary(this).IsStreamModified;
|
||||||
@@ -326,7 +305,7 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
// The global method pointer list was deprecated in v24.2 in favour of Il2CppCodeGenModule
|
// The global method pointer list was deprecated in v24.2 in favour of Il2CppCodeGenModule
|
||||||
if (Image.Version <= MetadataVersions.V241)
|
if (Image.Version <= MetadataVersions.V241)
|
||||||
GlobalMethodPointers = Image.ReadMappedArray<ulong>(CodeRegistration.MethodPointers, (int) CodeRegistration.MethodPointersCount);
|
GlobalMethodPointers = Image.ReadMappedUWordArray(CodeRegistration.MethodPointers, (int) CodeRegistration.MethodPointersCount);
|
||||||
|
|
||||||
// After v24 method pointers and RGCTX data were stored in Il2CppCodeGenModules
|
// After v24 method pointers and RGCTX data were stored in Il2CppCodeGenModules
|
||||||
if (Image.Version >= MetadataVersions.V242) {
|
if (Image.Version >= MetadataVersions.V242) {
|
||||||
@@ -336,12 +315,12 @@ namespace Il2CppInspector
|
|||||||
// if this changes we'll have to get smarter about disambiguating these two.
|
// if this changes we'll have to get smarter about disambiguating these two.
|
||||||
if (CodeRegistration.CodeGenModulesCount == 0) {
|
if (CodeRegistration.CodeGenModulesCount == 0) {
|
||||||
Image.Version = MetadataVersions.V243;
|
Image.Version = MetadataVersions.V243;
|
||||||
CodeRegistration = Image.ReadMappedObject<Il2CppCodeRegistration>(codeRegistration);
|
CodeRegistration = Image.ReadMappedVersionedObject<Il2CppCodeRegistration>(codeRegistration);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array of pointers to Il2CppCodeGenModule
|
// Array of pointers to Il2CppCodeGenModule
|
||||||
var codeGenModulePointers = Image.ReadMappedArray<ulong>(CodeRegistration.CodeGenModules, (int) CodeRegistration.CodeGenModulesCount);
|
var codeGenModulePointers = Image.ReadMappedUWordArray(CodeRegistration.CodeGenModules, (int) CodeRegistration.CodeGenModulesCount);
|
||||||
var modules = Image.ReadMappedObjectPointerArray<Il2CppCodeGenModule>(CodeRegistration.CodeGenModules, (int) CodeRegistration.CodeGenModulesCount);
|
var modules = Image.ReadMappedVersionedObjectPointerArray<Il2CppCodeGenModule>(CodeRegistration.CodeGenModules, (int) CodeRegistration.CodeGenModulesCount);
|
||||||
|
|
||||||
foreach (var mp in modules.Zip(codeGenModulePointers, (m, p) => new { Module = m, Pointer = p })) {
|
foreach (var mp in modules.Zip(codeGenModulePointers, (m, p) => new { Module = m, Pointer = p })) {
|
||||||
var module = mp.Module;
|
var module = mp.Module;
|
||||||
@@ -355,13 +334,13 @@ namespace Il2CppInspector
|
|||||||
// the entire method pointer array will be NULL values, causing the methodPointer to be mapped to .bss
|
// the entire method pointer array will be NULL values, causing the methodPointer to be mapped to .bss
|
||||||
// and therefore out of scope of the binary image
|
// and therefore out of scope of the binary image
|
||||||
try {
|
try {
|
||||||
ModuleMethodPointers.Add(module, Image.ReadMappedArray<ulong>(module.MethodPointers, (int) module.MethodPointerCount));
|
ModuleMethodPointers.Add(module, Image.ReadMappedUWordArray(module.MethodPointers, (int) module.MethodPointerCount));
|
||||||
} catch (InvalidOperationException) {
|
} catch (InvalidOperationException) {
|
||||||
ModuleMethodPointers.Add(module, new ulong[module.MethodPointerCount]);
|
ModuleMethodPointers.Add(module, new ulong[module.MethodPointerCount]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read method invoker pointer indices - one per method
|
// Read method invoker pointer indices - one per method
|
||||||
MethodInvokerIndices.Add(module, Image.ReadMappedArray<int>(module.InvokerIndices, (int) module.MethodPointerCount));
|
MethodInvokerIndices.Add(module, Image.ReadMappedPrimitiveArray<int>(module.InvokerIndices, (int) module.MethodPointerCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,24 +360,24 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
// All older versions use values directly in the array
|
// All older versions use values directly in the array
|
||||||
if (!fieldOffsetsArePointers)
|
if (!fieldOffsetsArePointers)
|
||||||
FieldOffsets = Image.ReadMappedArray<uint>(MetadataRegistration.FieldOffsets, (int)MetadataRegistration.FieldOffsetsCount);
|
FieldOffsets = Image.ReadMappedPrimitiveArray<uint>(MetadataRegistration.FieldOffsets, (int)MetadataRegistration.FieldOffsetsCount);
|
||||||
else
|
else
|
||||||
FieldOffsetPointers = Image.ReadMappedWordArray(MetadataRegistration.FieldOffsets, (int)MetadataRegistration.FieldOffsetsCount);
|
FieldOffsetPointers = Image.ReadMappedWordArray(MetadataRegistration.FieldOffsets, (int)MetadataRegistration.FieldOffsetsCount);
|
||||||
|
|
||||||
// Type references (pointer array)
|
// Type references (pointer array)
|
||||||
var typeRefPointers = Image.ReadMappedArray<ulong>(MetadataRegistration.Types, (int) MetadataRegistration.TypesCount);
|
var typeRefPointers = Image.ReadMappedUWordArray(MetadataRegistration.Types, (int) MetadataRegistration.TypesCount);
|
||||||
TypeReferenceIndicesByAddress = typeRefPointers.Zip(Enumerable.Range(0, typeRefPointers.Length), (a, i) => new { a, i }).ToDictionary(x => x.a, x => x.i);
|
TypeReferenceIndicesByAddress = typeRefPointers.Zip(Enumerable.Range(0, typeRefPointers.Length), (a, i) => new { a, i }).ToDictionary(x => x.a, x => x.i);
|
||||||
|
|
||||||
TypeReferences = Image.ReadMappedObjectPointerArray<Il2CppType>(MetadataRegistration.Types, (int)MetadataRegistration.TypesCount);
|
TypeReferences = Image.ReadMappedVersionedObjectPointerArray<Il2CppType>(MetadataRegistration.Types, (int)MetadataRegistration.TypesCount);
|
||||||
|
|
||||||
// Custom attribute constructors (function pointers)
|
// Custom attribute constructors (function pointers)
|
||||||
// This is managed in Il2CppInspector for metadata >= 27
|
// This is managed in Il2CppInspector for metadata >= 27
|
||||||
if (Image.Version < MetadataVersions.V270) {
|
if (Image.Version < MetadataVersions.V270) {
|
||||||
CustomAttributeGenerators = Image.ReadMappedArray<ulong>(CodeRegistration.CustomAttributeGenerators, (int) CodeRegistration.CustomAttributeCount);
|
CustomAttributeGenerators = Image.ReadMappedUWordArray(CodeRegistration.CustomAttributeGenerators, (int) CodeRegistration.CustomAttributeCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method.Invoke function pointers
|
// Method.Invoke function pointers
|
||||||
MethodInvokePointers = Image.ReadMappedArray<ulong>(CodeRegistration.InvokerPointers, (int) CodeRegistration.InvokerPointersCount);
|
MethodInvokePointers = Image.ReadMappedUWordArray(CodeRegistration.InvokerPointers, (int) CodeRegistration.InvokerPointersCount);
|
||||||
|
|
||||||
// TODO: Function pointers as shown below
|
// TODO: Function pointers as shown below
|
||||||
// reversePInvokeWrappers
|
// reversePInvokeWrappers
|
||||||
@@ -408,24 +387,24 @@ namespace Il2CppInspector
|
|||||||
// >=23: interopData
|
// >=23: interopData
|
||||||
|
|
||||||
if (Image.Version < MetadataVersions.V190) {
|
if (Image.Version < MetadataVersions.V190) {
|
||||||
VTableMethodReferences = Image.ReadMappedArray<uint>(MetadataRegistration.MethodReferences, (int)MetadataRegistration.MethodReferencesCount);
|
VTableMethodReferences = Image.ReadMappedPrimitiveArray<uint>(MetadataRegistration.MethodReferences, (int)MetadataRegistration.MethodReferencesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic type and method specs (open and closed constructed types)
|
// Generic type and method specs (open and closed constructed types)
|
||||||
MethodSpecs = Image.ReadMappedArray<Il2CppMethodSpec>(MetadataRegistration.MethodSpecs, (int) MetadataRegistration.MethodSpecsCount);
|
MethodSpecs = Image.ReadMappedVersionedObjectArray<Il2CppMethodSpec>(MetadataRegistration.MethodSpecs, (int) MetadataRegistration.MethodSpecsCount);
|
||||||
|
|
||||||
// Concrete generic class and method signatures
|
// Concrete generic class and method signatures
|
||||||
GenericInstances = Image.ReadMappedObjectPointerArray<Il2CppGenericInst>(MetadataRegistration.GenericInsts, (int) MetadataRegistration.GenericInstsCount);
|
GenericInstances = Image.ReadMappedVersionedObjectPointerArray<Il2CppGenericInst>(MetadataRegistration.GenericInsts, (int) MetadataRegistration.GenericInstsCount);
|
||||||
|
|
||||||
// Concrete generic method pointers
|
// Concrete generic method pointers
|
||||||
var genericMethodPointers = Image.ReadMappedArray<ulong>(CodeRegistration.GenericMethodPointers, (int) CodeRegistration.GenericMethodPointersCount);
|
var genericMethodPointers = Image.ReadMappedUWordArray(CodeRegistration.GenericMethodPointers, (int) CodeRegistration.GenericMethodPointersCount);
|
||||||
var genericMethodTable = Image.ReadMappedArray<Il2CppGenericMethodFunctionsDefinitions>(MetadataRegistration.GenericMethodTable, (int) MetadataRegistration.GenericMethodTableCount);
|
var genericMethodTable = Image.ReadMappedVersionedObjectArray<Il2CppGenericMethodFunctionsDefinitions>(MetadataRegistration.GenericMethodTable, (int) MetadataRegistration.GenericMethodTableCount);
|
||||||
foreach (var tableEntry in genericMethodTable) {
|
foreach (var tableEntry in genericMethodTable) {
|
||||||
GenericMethodPointers.Add(MethodSpecs[tableEntry.GenericMethodIndex], genericMethodPointers[tableEntry.Indices.MethodIndex]);
|
GenericMethodPointers.Add(MethodSpecs[tableEntry.GenericMethodIndex], genericMethodPointers[tableEntry.Indices.MethodIndex]);
|
||||||
GenericMethodInvokerIndices.Add(MethodSpecs[tableEntry.GenericMethodIndex], tableEntry.Indices.InvokerIndex);
|
GenericMethodInvokerIndices.Add(MethodSpecs[tableEntry.GenericMethodIndex], tableEntry.Indices.InvokerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeDefinitionSizes = Image.ReadMappedObjectPointerArray<Il2CppTypeDefinitionSizes>(
|
TypeDefinitionSizes = Image.ReadMappedVersionedObjectPointerArray<Il2CppTypeDefinitionSizes>(
|
||||||
MetadataRegistration.TypeDefinitionsSizes, (int) MetadataRegistration.TypeDefinitionsSizesCount);
|
MetadataRegistration.TypeDefinitionsSizes, (int) MetadataRegistration.TypeDefinitionsSizesCount);
|
||||||
|
|
||||||
// Plugin hook to pre-process binary
|
// Plugin hook to pre-process binary
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Il2CppInspector.Utils;
|
|||||||
using NoisyCowStudios.Bin2Object;
|
using NoisyCowStudios.Bin2Object;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -41,38 +42,38 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
public Dictionary<int, string> Strings => Metadata.Strings;
|
public Dictionary<int, string> Strings => Metadata.Strings;
|
||||||
public string[] StringLiterals => Metadata.StringLiterals;
|
public string[] StringLiterals => Metadata.StringLiterals;
|
||||||
public Il2CppTypeDefinition[] TypeDefinitions => Metadata.Types;
|
public ImmutableArray<Il2CppTypeDefinition> TypeDefinitions => Metadata.Types;
|
||||||
public Il2CppAssemblyDefinition[] Assemblies => Metadata.Assemblies;
|
public ImmutableArray<Il2CppAssemblyDefinition> Assemblies => Metadata.Assemblies;
|
||||||
public Il2CppImageDefinition[] Images => Metadata.Images;
|
public ImmutableArray<Il2CppImageDefinition> Images => Metadata.Images;
|
||||||
public Il2CppMethodDefinition[] Methods => Metadata.Methods;
|
public ImmutableArray<Il2CppMethodDefinition> Methods => Metadata.Methods;
|
||||||
public Il2CppParameterDefinition[] Params => Metadata.Params;
|
public ImmutableArray<Il2CppParameterDefinition> Params => Metadata.Params;
|
||||||
public Il2CppFieldDefinition[] Fields => Metadata.Fields;
|
public ImmutableArray<Il2CppFieldDefinition> Fields => Metadata.Fields;
|
||||||
public Il2CppPropertyDefinition[] Properties => Metadata.Properties;
|
public ImmutableArray<Il2CppPropertyDefinition> Properties => Metadata.Properties;
|
||||||
public Il2CppEventDefinition[] Events => Metadata.Events;
|
public ImmutableArray<Il2CppEventDefinition> Events => Metadata.Events;
|
||||||
public Il2CppGenericContainer[] GenericContainers => Metadata.GenericContainers;
|
public ImmutableArray<Il2CppGenericContainer> GenericContainers => Metadata.GenericContainers;
|
||||||
public Il2CppGenericParameter[] GenericParameters => Metadata.GenericParameters;
|
public ImmutableArray<Il2CppGenericParameter> GenericParameters => Metadata.GenericParameters;
|
||||||
public int[] GenericConstraintIndices => Metadata.GenericConstraintIndices;
|
public ImmutableArray<int> GenericConstraintIndices => Metadata.GenericConstraintIndices;
|
||||||
public Il2CppCustomAttributeTypeRange[] AttributeTypeRanges => Metadata.AttributeTypeRanges;
|
public ImmutableArray<Il2CppCustomAttributeTypeRange> AttributeTypeRanges => Metadata.AttributeTypeRanges;
|
||||||
public Il2CppCustomAttributeDataRange[] AttributeDataRanges => Metadata.AttributeDataRanges;
|
public ImmutableArray<Il2CppCustomAttributeDataRange> AttributeDataRanges => Metadata.AttributeDataRanges;
|
||||||
public Il2CppInterfaceOffsetPair[] InterfaceOffsets => Metadata.InterfaceOffsets;
|
public ImmutableArray<Il2CppInterfaceOffsetPair> InterfaceOffsets => Metadata.InterfaceOffsets;
|
||||||
public int[] InterfaceUsageIndices => Metadata.InterfaceUsageIndices;
|
public ImmutableArray<int> InterfaceUsageIndices => Metadata.InterfaceUsageIndices;
|
||||||
public int[] NestedTypeIndices => Metadata.NestedTypeIndices;
|
public ImmutableArray<int> NestedTypeIndices => Metadata.NestedTypeIndices;
|
||||||
public int[] AttributeTypeIndices => Metadata.AttributeTypeIndices;
|
public ImmutableArray<int> AttributeTypeIndices => Metadata.AttributeTypeIndices;
|
||||||
public uint[] VTableMethodIndices => Metadata.VTableMethodIndices;
|
public ImmutableArray<uint> VTableMethodIndices => Metadata.VTableMethodIndices;
|
||||||
public Il2CppFieldRef[] FieldRefs => Metadata.FieldRefs;
|
public ImmutableArray<Il2CppFieldRef> FieldRefs => Metadata.FieldRefs;
|
||||||
public Dictionary<int, (ulong, object)> FieldDefaultValue { get; } = new Dictionary<int, (ulong, object)>();
|
public Dictionary<int, (ulong, object)> FieldDefaultValue { get; } = new Dictionary<int, (ulong, object)>();
|
||||||
public Dictionary<int, (ulong, object)> ParameterDefaultValue { get; } = new Dictionary<int, (ulong, object)>();
|
public Dictionary<int, (ulong, object)> ParameterDefaultValue { get; } = new Dictionary<int, (ulong, object)>();
|
||||||
public List<long> FieldOffsets { get; }
|
public List<long> FieldOffsets { get; }
|
||||||
public List<Il2CppType> TypeReferences => Binary.TypeReferences;
|
public ImmutableArray<Il2CppType> TypeReferences => Binary.TypeReferences;
|
||||||
public Dictionary<ulong, int> TypeReferenceIndicesByAddress => Binary.TypeReferenceIndicesByAddress;
|
public Dictionary<ulong, int> TypeReferenceIndicesByAddress => Binary.TypeReferenceIndicesByAddress;
|
||||||
public List<Il2CppGenericInst> GenericInstances => Binary.GenericInstances;
|
public ImmutableArray<Il2CppGenericInst> GenericInstances => Binary.GenericInstances;
|
||||||
public Dictionary<string, Il2CppCodeGenModule> Modules => Binary.Modules;
|
public Dictionary<string, Il2CppCodeGenModule> Modules => Binary.Modules;
|
||||||
public ulong[] CustomAttributeGenerators { get; }
|
public ulong[] CustomAttributeGenerators { get; }
|
||||||
public ulong[] MethodInvokePointers { get; }
|
public ulong[] MethodInvokePointers { get; }
|
||||||
public Il2CppMethodSpec[] MethodSpecs => Binary.MethodSpecs;
|
public ImmutableArray<Il2CppMethodSpec> MethodSpecs => Binary.MethodSpecs;
|
||||||
public Dictionary<Il2CppMethodSpec, ulong> GenericMethodPointers { get; }
|
public Dictionary<Il2CppMethodSpec, ulong> GenericMethodPointers { get; }
|
||||||
public Dictionary<Il2CppMethodSpec, int> GenericMethodInvokerIndices => Binary.GenericMethodInvokerIndices;
|
public Dictionary<Il2CppMethodSpec, int> GenericMethodInvokerIndices => Binary.GenericMethodInvokerIndices;
|
||||||
public List<Il2CppTypeDefinitionSizes> TypeDefinitionSizes => Binary.TypeDefinitionSizes;
|
public ImmutableArray<Il2CppTypeDefinitionSizes> TypeDefinitionSizes => Binary.TypeDefinitionSizes;
|
||||||
|
|
||||||
// TODO: Finish all file access in the constructor and eliminate the need for this
|
// TODO: Finish all file access in the constructor and eliminate the need for this
|
||||||
public IFileFormatStream BinaryImage => Binary.Image;
|
public IFileFormatStream BinaryImage => Binary.Image;
|
||||||
@@ -121,7 +122,7 @@ namespace Il2CppInspector
|
|||||||
// Unfortunately the value supplied in MetadataRegistration.matadataUsagesCount seems to be incorrect,
|
// Unfortunately the value supplied in MetadataRegistration.matadataUsagesCount seems to be incorrect,
|
||||||
// so we have to calculate the correct number of usages above before reading the usage address list from the binary
|
// so we have to calculate the correct number of usages above before reading the usage address list from the binary
|
||||||
var count = usages.Keys.Max() + 1;
|
var count = usages.Keys.Max() + 1;
|
||||||
var addresses = Binary.Image.ReadMappedArray<ulong>(Binary.MetadataRegistration.MetadataUsages, (int) count);
|
var addresses = Binary.Image.ReadMappedUWordArray(Binary.MetadataRegistration.MetadataUsages, (int) count);
|
||||||
foreach (var usage in usages)
|
foreach (var usage in usages)
|
||||||
usage.Value.SetAddress(addresses[usage.Key]);
|
usage.Value.SetAddress(addresses[usage.Key]);
|
||||||
|
|
||||||
@@ -161,7 +162,7 @@ namespace Il2CppInspector
|
|||||||
{
|
{
|
||||||
return usage.Type switch
|
return usage.Type switch
|
||||||
{
|
{
|
||||||
MetadataUsageType.TypeInfo or MetadataUsageType.Type => TypeReferences.Count > usage.SourceIndex,
|
MetadataUsageType.TypeInfo or MetadataUsageType.Type => TypeReferences.Length > usage.SourceIndex,
|
||||||
MetadataUsageType.MethodDef => Methods.Length > usage.SourceIndex,
|
MetadataUsageType.MethodDef => Methods.Length > usage.SourceIndex,
|
||||||
MetadataUsageType.FieldInfo or MetadataUsageType.FieldRva => FieldRefs.Length > usage.SourceIndex,
|
MetadataUsageType.FieldInfo or MetadataUsageType.FieldRva => FieldRefs.Length > usage.SourceIndex,
|
||||||
MetadataUsageType.StringLiteral => StringLiterals.Length > usage.SourceIndex,
|
MetadataUsageType.StringLiteral => StringLiterals.Length > usage.SourceIndex,
|
||||||
@@ -347,7 +348,7 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
// Version >= 24.2
|
// Version >= 24.2
|
||||||
var methodInModule = (methodDef.Token & 0xffffff);
|
var methodInModule = (methodDef.Token & 0xffffff);
|
||||||
return Binary.MethodInvokerIndices[module][methodInModule - 1];
|
return Binary.MethodInvokerIndices[module][(int)methodInModule - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetadataUsage[] GetVTable(Il2CppTypeDefinition definition) {
|
public MetadataUsage[] GetVTable(Il2CppTypeDefinition definition) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Il2CppInspector.Next;
|
using Il2CppInspector.Next;
|
||||||
using Il2CppInspector.Next.BinaryMetadata;
|
using Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
using VersionedSerialization;
|
||||||
|
|
||||||
namespace Il2CppInspector
|
namespace Il2CppInspector
|
||||||
{
|
{
|
||||||
@@ -147,7 +148,7 @@ namespace Il2CppInspector
|
|||||||
potentialCodeGenModules - (ulong) i * ptrSize, 1))
|
potentialCodeGenModules - (ulong) i * ptrSize, 1))
|
||||||
{
|
{
|
||||||
var expectedImageCountPtr = potentialCodeRegistrationPtr - ptrSize;
|
var expectedImageCountPtr = potentialCodeRegistrationPtr - ptrSize;
|
||||||
var expectedImageCount = ptrSize == 4 ? Image.ReadMappedInt32(expectedImageCountPtr) : Image.ReadMappedInt64(expectedImageCountPtr);
|
var expectedImageCount = Image.ReadMappedWord(expectedImageCountPtr);
|
||||||
if (expectedImageCount == imagesCount)
|
if (expectedImageCount == imagesCount)
|
||||||
return potentialCodeRegistrationPtr;
|
return potentialCodeRegistrationPtr;
|
||||||
}
|
}
|
||||||
@@ -206,11 +207,12 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
|
|
||||||
// pCodeGenModules is the last field in CodeRegistration so we subtract the size of one pointer from the struct size
|
// pCodeGenModules is the last field in CodeRegistration so we subtract the size of one pointer from the struct size
|
||||||
codeRegistration = codeRegVa - ((ulong) metadata.Sizeof(typeof(Il2CppCodeRegistration), Image.Version, Image.Bits / 8) - ptrSize);
|
var codeRegSize = (ulong)Il2CppCodeRegistration.Size(Image.Version, Image.Bits == 32);
|
||||||
|
codeRegistration = codeRegVa - codeRegSize - ptrSize;
|
||||||
|
|
||||||
// In v24.3, windowsRuntimeFactoryTable collides with codeGenModules. So far no samples have had windowsRuntimeFactoryCount > 0;
|
// In v24.3, windowsRuntimeFactoryTable collides with codeGenModules. So far no samples have had windowsRuntimeFactoryCount > 0;
|
||||||
// if this changes we'll have to get smarter about disambiguating these two.
|
// if this changes we'll have to get smarter about disambiguating these two.
|
||||||
var cr = Image.ReadMappedObject<Il2CppCodeRegistration>(codeRegistration);
|
var cr = Image.ReadMappedVersionedObject<Il2CppCodeRegistration>(codeRegistration);
|
||||||
|
|
||||||
if (Image.Version == MetadataVersions.V242 && cr.InteropDataCount == 0) {
|
if (Image.Version == MetadataVersions.V242 && cr.InteropDataCount == 0) {
|
||||||
Image.Version = MetadataVersions.V243;
|
Image.Version = MetadataVersions.V243;
|
||||||
@@ -224,6 +226,22 @@ namespace Il2CppInspector
|
|||||||
Image.Version = MetadataVersions.V271;
|
Image.Version = MetadataVersions.V271;
|
||||||
codeRegistration -= ptrSize;
|
codeRegistration -= ptrSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// genericAdjustorThunks was inserted before invokerPointersCount in 24.5 and 27.1
|
||||||
|
// pointer expected if we need to bump version
|
||||||
|
if (Image.Version == MetadataVersions.V244 && cr.InvokerPointersCount > 0x50000)
|
||||||
|
{
|
||||||
|
Image.Version = MetadataVersions.V245;
|
||||||
|
codeRegistration += 1 * ptrSize;
|
||||||
|
cr = Image.ReadMappedVersionedObject<Il2CppCodeRegistration>(codeRegistration);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((Image.Version == MetadataVersions.V290 || Image.Version == MetadataVersions.V310) &&
|
||||||
|
cr.InteropData + cr.InteropDataCount >= (ulong)Image.Length)
|
||||||
|
{
|
||||||
|
Image.Version = new StructVersion(Image.Version.Major, 1, Image.Version.Tag);
|
||||||
|
cr = Image.ReadMappedVersionedObject<Il2CppCodeRegistration>(codeRegistration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find CodeRegistration
|
// Find CodeRegistration
|
||||||
@@ -239,7 +257,7 @@ namespace Il2CppInspector
|
|||||||
// the count of custom attribute generators; the distance between them
|
// the count of custom attribute generators; the distance between them
|
||||||
// depends on the il2cpp version so we just use ReadMappedObject to simplify the math
|
// depends on the il2cpp version so we just use ReadMappedObject to simplify the math
|
||||||
foreach (var va in vas) {
|
foreach (var va in vas) {
|
||||||
var cr = Image.ReadMappedObject<Il2CppCodeRegistration>(va);
|
var cr = Image.ReadMappedVersionedObject<Il2CppCodeRegistration>(va);
|
||||||
|
|
||||||
if (cr.CustomAttributeCount == metadata.AttributeTypeRanges.Length)
|
if (cr.CustomAttributeCount == metadata.AttributeTypeRanges.Length)
|
||||||
codeRegistration = va;
|
codeRegistration = va;
|
||||||
@@ -255,15 +273,16 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
// Find TypeDefinitionsSizesCount (4th last field) then work back to the start of the struct
|
// Find TypeDefinitionsSizesCount (4th last field) then work back to the start of the struct
|
||||||
// This saves us from guessing where metadataUsagesCount is later
|
// This saves us from guessing where metadataUsagesCount is later
|
||||||
var mrSize = (ulong) metadata.Sizeof(typeof(Il2CppMetadataRegistration), Image.Version, Image.Bits / 8);
|
var mrSize = (ulong)Il2CppMetadataRegistration.Size(Image.Version, Image.Bits == 32);
|
||||||
var typesLength = (ulong) metadata.Types.Length;
|
var typesLength = (ulong) metadata.Types.Length;
|
||||||
|
|
||||||
vas = FindAllMappedWords(imageBytes, typesLength).Select(a => a - mrSize + ptrSize * 4);
|
vas = FindAllMappedWords(imageBytes, typesLength).Select(a => a - mrSize + ptrSize * 4);
|
||||||
|
|
||||||
// >= 19 && < 27
|
// >= 19 && < 27
|
||||||
if (Image.Version < MetadataVersions.V270)
|
if (Image.Version < MetadataVersions.V270)
|
||||||
foreach (var va in vas) {
|
foreach (var va in vas)
|
||||||
var mr = Image.ReadMappedObject<Il2CppMetadataRegistration>(va);
|
{
|
||||||
|
var mr = Image.ReadMappedVersionedObject<Il2CppMetadataRegistration>(va);
|
||||||
if (mr.MetadataUsagesCount == (ulong) metadata.MetadataUsageLists.Length)
|
if (mr.MetadataUsagesCount == (ulong) metadata.MetadataUsageLists.Length)
|
||||||
metadataRegistration = va;
|
metadataRegistration = va;
|
||||||
}
|
}
|
||||||
@@ -273,22 +292,17 @@ namespace Il2CppInspector
|
|||||||
// Synonyms: copying, piracy, theft, strealing, infringement of copyright
|
// Synonyms: copying, piracy, theft, strealing, infringement of copyright
|
||||||
|
|
||||||
// >= 27
|
// >= 27
|
||||||
else {
|
else
|
||||||
// We're going to just sanity check all of the fields
|
{
|
||||||
// All counts should be under a certain threshold
|
foreach (var va in vas)
|
||||||
// All pointers should be mappable to the binary
|
{
|
||||||
|
var mr = Image.ReadMappedVersionedObject<Il2CppMetadataRegistration>(va);
|
||||||
var mrFieldCount = mrSize / (ulong) (Image.Bits / 8);
|
if (mr.TypeDefinitionsSizesCount == metadata.Types.Length
|
||||||
foreach (var va in vas) {
|
&& mr.FieldOffsetsCount == metadata.Types.Length)
|
||||||
var mrWords = Image.ReadMappedWordArray(va, (int) mrFieldCount);
|
{
|
||||||
|
|
||||||
// Even field indices are counts, odd field indices are pointers
|
|
||||||
bool ok = true;
|
|
||||||
for (var i = 0; i < mrWords.Length && ok; i++) {
|
|
||||||
ok = i % 2 == 0 || Image.TryMapVATR((ulong) mrWords[i], out _);
|
|
||||||
}
|
|
||||||
if (ok)
|
|
||||||
metadataRegistration = va;
|
metadataRegistration = va;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (metadataRegistration == 0)
|
if (metadataRegistration == 0)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -21,30 +22,30 @@ namespace Il2CppInspector
|
|||||||
{
|
{
|
||||||
public Il2CppGlobalMetadataHeader Header { get; set; }
|
public Il2CppGlobalMetadataHeader Header { get; set; }
|
||||||
|
|
||||||
public Il2CppAssemblyDefinition[] Assemblies { get; set; }
|
public ImmutableArray<Il2CppAssemblyDefinition> Assemblies { get; set; }
|
||||||
public Il2CppImageDefinition[] Images { get; set; }
|
public ImmutableArray<Il2CppImageDefinition> Images { get; set; }
|
||||||
public Il2CppTypeDefinition[] Types { get; set; }
|
public ImmutableArray<Il2CppTypeDefinition> Types { get; set; }
|
||||||
public Il2CppMethodDefinition[] Methods { get; set; }
|
public ImmutableArray<Il2CppMethodDefinition> Methods { get; set; }
|
||||||
public Il2CppParameterDefinition[] Params { get; set; }
|
public ImmutableArray<Il2CppParameterDefinition> Params { get; set; }
|
||||||
public Il2CppFieldDefinition[] Fields { get; set; }
|
public ImmutableArray<Il2CppFieldDefinition> Fields { get; set; }
|
||||||
public Il2CppFieldDefaultValue[] FieldDefaultValues { get; set; }
|
public ImmutableArray<Il2CppFieldDefaultValue> FieldDefaultValues { get; set; }
|
||||||
public Il2CppParameterDefaultValue[] ParameterDefaultValues { get; set; }
|
public ImmutableArray<Il2CppParameterDefaultValue> ParameterDefaultValues { get; set; }
|
||||||
public Il2CppPropertyDefinition[] Properties { get; set; }
|
public ImmutableArray<Il2CppPropertyDefinition> Properties { get; set; }
|
||||||
public Il2CppEventDefinition[] Events { get; set; }
|
public ImmutableArray<Il2CppEventDefinition> Events { get; set; }
|
||||||
public Il2CppGenericContainer[] GenericContainers { get; set; }
|
public ImmutableArray<Il2CppGenericContainer> GenericContainers { get; set; }
|
||||||
public Il2CppGenericParameter[] GenericParameters { get; set; }
|
public ImmutableArray<Il2CppGenericParameter> GenericParameters { get; set; }
|
||||||
public Il2CppCustomAttributeTypeRange[] AttributeTypeRanges { get; set; }
|
public ImmutableArray<Il2CppCustomAttributeTypeRange> AttributeTypeRanges { get; set; }
|
||||||
public Il2CppCustomAttributeDataRange[] AttributeDataRanges { get; set; }
|
public ImmutableArray<Il2CppCustomAttributeDataRange> AttributeDataRanges { get; set; }
|
||||||
public Il2CppInterfaceOffsetPair[] InterfaceOffsets { get; set; }
|
public ImmutableArray<Il2CppInterfaceOffsetPair> InterfaceOffsets { get; set; }
|
||||||
public Il2CppMetadataUsageList[] MetadataUsageLists { get; set; }
|
public ImmutableArray<Il2CppMetadataUsageList> MetadataUsageLists { get; set; }
|
||||||
public Il2CppMetadataUsagePair[] MetadataUsagePairs { get; set; }
|
public ImmutableArray<Il2CppMetadataUsagePair> MetadataUsagePairs { get; set; }
|
||||||
public Il2CppFieldRef[] FieldRefs { get; set; }
|
public ImmutableArray<Il2CppFieldRef> FieldRefs { get; set; }
|
||||||
|
|
||||||
public int[] InterfaceUsageIndices { get; set; }
|
public ImmutableArray<int> InterfaceUsageIndices { get; set; }
|
||||||
public int[] NestedTypeIndices { get; set; }
|
public ImmutableArray<int> NestedTypeIndices { get; set; }
|
||||||
public int[] AttributeTypeIndices { get; set; }
|
public ImmutableArray<int> AttributeTypeIndices { get; set; }
|
||||||
public int[] GenericConstraintIndices { get; set; }
|
public ImmutableArray<int> GenericConstraintIndices { get; set; }
|
||||||
public uint[] VTableMethodIndices { get; set; }
|
public ImmutableArray<uint> VTableMethodIndices { get; set; }
|
||||||
public string[] StringLiterals { get; set; }
|
public string[] StringLiterals { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, string> Strings { get; private set; } = new Dictionary<int, string>();
|
public Dictionary<int, string> Strings { get; private set; } = new Dictionary<int, string>();
|
||||||
@@ -81,7 +82,7 @@ namespace Il2CppInspector
|
|||||||
StatusUpdate("Processing metadata");
|
StatusUpdate("Processing metadata");
|
||||||
|
|
||||||
// Read metadata header
|
// Read metadata header
|
||||||
Header = ReadObject<Il2CppGlobalMetadataHeader>(0);
|
Header = ReadVersionedObject<Il2CppGlobalMetadataHeader>(0);
|
||||||
|
|
||||||
// Check for correct magic bytes
|
// Check for correct magic bytes
|
||||||
if (!Header.SanityValid) {
|
if (!Header.SanityValid) {
|
||||||
@@ -96,7 +97,7 @@ namespace Il2CppInspector
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rewind and read metadata header with the correct version settings
|
// Rewind and read metadata header with the correct version settings
|
||||||
Header = ReadObject<Il2CppGlobalMetadataHeader>(0);
|
Header = ReadVersionedObject<Il2CppGlobalMetadataHeader>(0);
|
||||||
|
|
||||||
// Sanity checking
|
// Sanity checking
|
||||||
// Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata always writes the metadata information in the same order it appears in the header,
|
// Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata always writes the metadata information in the same order it appears in the header,
|
||||||
@@ -110,21 +111,21 @@ namespace Il2CppInspector
|
|||||||
if (!pluginResult.SkipValidation) {
|
if (!pluginResult.SkipValidation) {
|
||||||
var realHeaderLength = Header.StringLiteralOffset;
|
var realHeaderLength = Header.StringLiteralOffset;
|
||||||
|
|
||||||
if (realHeaderLength != Sizeof(typeof(Il2CppGlobalMetadataHeader))) {
|
if (realHeaderLength != Sizeof<Il2CppGlobalMetadataHeader>()) {
|
||||||
if (Version == MetadataVersions.V240) {
|
if (Version == MetadataVersions.V240) {
|
||||||
Version = MetadataVersions.V242;
|
Version = MetadataVersions.V242;
|
||||||
Header = ReadObject<Il2CppGlobalMetadataHeader>(0);
|
Header = ReadVersionedObject<Il2CppGlobalMetadataHeader>(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (realHeaderLength != Sizeof(typeof(Il2CppGlobalMetadataHeader))) {
|
if (realHeaderLength != Sizeof<Il2CppGlobalMetadataHeader>()) {
|
||||||
throw new InvalidOperationException("Could not verify the integrity of the metadata file or accurately identify the metadata sub-version");
|
throw new InvalidOperationException("Could not verify the integrity of the metadata file or accurately identify the metadata sub-version");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load all the relevant metadata using offsets provided in the header
|
// Load all the relevant metadata using offsets provided in the header
|
||||||
if (Version >= MetadataVersions.V160)
|
if (Version >= MetadataVersions.V160)
|
||||||
Images = ReadArray<Il2CppImageDefinition>(Header.ImagesOffset, Header.ImagesSize / Sizeof(typeof(Il2CppImageDefinition)));
|
Images = ReadVersionedObjectArray<Il2CppImageDefinition>(Header.ImagesOffset, Header.ImagesSize / Sizeof<Il2CppImageDefinition>());
|
||||||
|
|
||||||
// As an additional sanity check, all images in the metadata should have Mono.Cecil.MetadataToken == 1
|
// As an additional sanity check, all images in the metadata should have Mono.Cecil.MetadataToken == 1
|
||||||
// In metadata v24.1, two extra fields were added which will cause the below test to fail.
|
// In metadata v24.1, two extra fields were added which will cause the below test to fail.
|
||||||
@@ -135,32 +136,32 @@ namespace Il2CppInspector
|
|||||||
Version = MetadataVersions.V241;
|
Version = MetadataVersions.V241;
|
||||||
|
|
||||||
// No need to re-read the header, it's the same for both sub-versions
|
// No need to re-read the header, it's the same for both sub-versions
|
||||||
Images = ReadArray<Il2CppImageDefinition>(Header.ImagesOffset, Header.ImagesSize / Sizeof(typeof(Il2CppImageDefinition)));
|
Images = ReadVersionedObjectArray<Il2CppImageDefinition>(Header.ImagesOffset, Header.ImagesSize / Sizeof<Il2CppImageDefinition>());
|
||||||
|
|
||||||
if (Images.Any(x => x.Token != 1))
|
if (Images.Any(x => x.Token != 1))
|
||||||
throw new InvalidOperationException("Could not verify the integrity of the metadata file image list");
|
throw new InvalidOperationException("Could not verify the integrity of the metadata file image list");
|
||||||
}
|
}
|
||||||
|
|
||||||
Types = ReadArray<Il2CppTypeDefinition>(Header.TypeDefinitionsOffset, Header.TypeDefinitionsSize / Sizeof(typeof(Il2CppTypeDefinition)));
|
Types = ReadVersionedObjectArray<Il2CppTypeDefinition>(Header.TypeDefinitionsOffset, Header.TypeDefinitionsSize / Sizeof<Il2CppTypeDefinition>());
|
||||||
Methods = ReadArray<Il2CppMethodDefinition>(Header.MethodsOffset, Header.MethodsSize / Sizeof(typeof(Il2CppMethodDefinition)));
|
Methods = ReadVersionedObjectArray<Il2CppMethodDefinition>(Header.MethodsOffset, Header.MethodsSize / Sizeof<Il2CppMethodDefinition>());
|
||||||
Params = ReadArray<Il2CppParameterDefinition>(Header.ParametersOffset, Header.ParametersSize / Sizeof(typeof(Il2CppParameterDefinition)));
|
Params = ReadVersionedObjectArray<Il2CppParameterDefinition>(Header.ParametersOffset, Header.ParametersSize / Sizeof<Il2CppParameterDefinition>());
|
||||||
Fields = ReadArray<Il2CppFieldDefinition>(Header.FieldsOffset, Header.FieldsSize / Sizeof(typeof(Il2CppFieldDefinition)));
|
Fields = ReadVersionedObjectArray<Il2CppFieldDefinition>(Header.FieldsOffset, Header.FieldsSize / Sizeof<Il2CppFieldDefinition>());
|
||||||
FieldDefaultValues = ReadArray<Il2CppFieldDefaultValue>(Header.FieldDefaultValuesOffset, Header.FieldDefaultValuesSize / Sizeof(typeof(Il2CppFieldDefaultValue)));
|
FieldDefaultValues = ReadVersionedObjectArray<Il2CppFieldDefaultValue>(Header.FieldDefaultValuesOffset, Header.FieldDefaultValuesSize / Sizeof<Il2CppFieldDefaultValue>());
|
||||||
Properties = ReadArray<Il2CppPropertyDefinition>(Header.PropertiesOffset, Header.PropertiesSize / Sizeof(typeof(Il2CppPropertyDefinition)));
|
Properties = ReadVersionedObjectArray<Il2CppPropertyDefinition>(Header.PropertiesOffset, Header.PropertiesSize / Sizeof<Il2CppPropertyDefinition>());
|
||||||
Events = ReadArray<Il2CppEventDefinition>(Header.EventsOffset, Header.EventsSize / Sizeof(typeof(Il2CppEventDefinition)));
|
Events = ReadVersionedObjectArray<Il2CppEventDefinition>(Header.EventsOffset, Header.EventsSize / Sizeof<Il2CppEventDefinition>());
|
||||||
InterfaceUsageIndices = ReadArray<int>(Header.InterfacesOffset, Header.InterfacesSize / sizeof(int));
|
InterfaceUsageIndices = ReadPrimitiveArray<int>(Header.InterfacesOffset, Header.InterfacesSize / sizeof(int));
|
||||||
NestedTypeIndices = ReadArray<int>(Header.NestedTypesOffset, Header.NestedTypesSize / sizeof(int));
|
NestedTypeIndices = ReadPrimitiveArray<int>(Header.NestedTypesOffset, Header.NestedTypesSize / sizeof(int));
|
||||||
GenericContainers = ReadArray<Il2CppGenericContainer>(Header.GenericContainersOffset, Header.GenericContainersSize / Sizeof(typeof(Il2CppGenericContainer)));
|
GenericContainers = ReadVersionedObjectArray<Il2CppGenericContainer>(Header.GenericContainersOffset, Header.GenericContainersSize / Sizeof<Il2CppGenericContainer>());
|
||||||
GenericParameters = ReadArray<Il2CppGenericParameter>(Header.GenericParametersOffset, Header.GenericParametersSize / Sizeof(typeof(Il2CppGenericParameter)));
|
GenericParameters = ReadVersionedObjectArray<Il2CppGenericParameter>(Header.GenericParametersOffset, Header.GenericParametersSize / Sizeof<Il2CppGenericParameter>());
|
||||||
GenericConstraintIndices = ReadArray<int>(Header.GenericParameterConstraintsOffset, Header.GenericParameterConstraintsSize / sizeof(int));
|
GenericConstraintIndices = ReadPrimitiveArray<int>(Header.GenericParameterConstraintsOffset, Header.GenericParameterConstraintsSize / sizeof(int));
|
||||||
InterfaceOffsets = ReadArray<Il2CppInterfaceOffsetPair>(Header.InterfaceOffsetsOffset, Header.InterfaceOffsetsSize / Sizeof(typeof(Il2CppInterfaceOffsetPair)));
|
InterfaceOffsets = ReadVersionedObjectArray<Il2CppInterfaceOffsetPair>(Header.InterfaceOffsetsOffset, Header.InterfaceOffsetsSize / Sizeof<Il2CppInterfaceOffsetPair>());
|
||||||
VTableMethodIndices = ReadArray<uint>(Header.VTableMethodsOffset, Header.VTableMethodsSize / sizeof(uint));
|
VTableMethodIndices = ReadPrimitiveArray<uint>(Header.VTableMethodsOffset, Header.VTableMethodsSize / sizeof(uint));
|
||||||
|
|
||||||
if (Version >= MetadataVersions.V160) {
|
if (Version >= MetadataVersions.V160) {
|
||||||
// In v24.4 hashValueIndex was removed from Il2CppAssemblyNameDefinition, which is a field in Il2CppAssemblyDefinition
|
// In v24.4 hashValueIndex was removed from Il2CppAssemblyNameDefinition, which is a field in Il2CppAssemblyDefinition
|
||||||
// The number of images and assemblies should be the same. If they are not, we deduce that we are using v24.4
|
// The number of images and assemblies should be the same. If they are not, we deduce that we are using v24.4
|
||||||
// Note the version comparison matches both 24.2 and 24.3 here since 24.3 is tested for during binary loading
|
// Note the version comparison matches both 24.2 and 24.3 here since 24.3 is tested for during binary loading
|
||||||
var assemblyCount = Header.AssembliesSize / Sizeof(typeof(Il2CppAssemblyDefinition));
|
var assemblyCount = Header.AssembliesSize / Sizeof<Il2CppAssemblyDefinition>();
|
||||||
var changedAssemblyDefStruct = false;
|
var changedAssemblyDefStruct = false;
|
||||||
if ((Version == MetadataVersions.V241 || Version == MetadataVersions.V242 || Version == MetadataVersions.V243) && assemblyCount < Images.Length)
|
if ((Version == MetadataVersions.V241 || Version == MetadataVersions.V242 || Version == MetadataVersions.V243) && assemblyCount < Images.Length)
|
||||||
{
|
{
|
||||||
@@ -169,29 +170,29 @@ namespace Il2CppInspector
|
|||||||
Version = MetadataVersions.V244;
|
Version = MetadataVersions.V244;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assemblies = ReadArray<Il2CppAssemblyDefinition>(Header.AssembliesOffset, Images.Length);
|
Assemblies = ReadVersionedObjectArray<Il2CppAssemblyDefinition>(Header.AssembliesOffset, Images.Length);
|
||||||
|
|
||||||
if (changedAssemblyDefStruct)
|
if (changedAssemblyDefStruct)
|
||||||
Version = MetadataVersions.V241;
|
Version = MetadataVersions.V241;
|
||||||
|
|
||||||
ParameterDefaultValues = ReadArray<Il2CppParameterDefaultValue>(Header.ParameterDefaultValuesOffset, Header.ParameterDefaultValuesSize / Sizeof(typeof(Il2CppParameterDefaultValue)));
|
ParameterDefaultValues = ReadVersionedObjectArray<Il2CppParameterDefaultValue>(Header.ParameterDefaultValuesOffset, Header.ParameterDefaultValuesSize / Sizeof<Il2CppParameterDefaultValue>());
|
||||||
}
|
}
|
||||||
if (Version >= MetadataVersions.V190 && Version < MetadataVersions.V270) {
|
if (Version >= MetadataVersions.V190 && Version < MetadataVersions.V270) {
|
||||||
MetadataUsageLists = ReadArray<Il2CppMetadataUsageList>(Header.MetadataUsageListsOffset, Header.MetadataUsageListsCount / Sizeof(typeof(Il2CppMetadataUsageList)));
|
MetadataUsageLists = ReadVersionedObjectArray<Il2CppMetadataUsageList>(Header.MetadataUsageListsOffset, Header.MetadataUsageListsCount / Sizeof<Il2CppMetadataUsageList>());
|
||||||
MetadataUsagePairs = ReadArray<Il2CppMetadataUsagePair>(Header.MetadataUsagePairsOffset, Header.MetadataUsagePairsCount / Sizeof(typeof(Il2CppMetadataUsagePair)));
|
MetadataUsagePairs = ReadVersionedObjectArray<Il2CppMetadataUsagePair>(Header.MetadataUsagePairsOffset, Header.MetadataUsagePairsCount / Sizeof<Il2CppMetadataUsagePair>());
|
||||||
}
|
}
|
||||||
if (Version >= MetadataVersions.V190) {
|
if (Version >= MetadataVersions.V190) {
|
||||||
FieldRefs = ReadArray<Il2CppFieldRef>(Header.FieldRefsOffset, Header.FieldRefsSize / Sizeof(typeof(Il2CppFieldRef)));
|
FieldRefs = ReadVersionedObjectArray<Il2CppFieldRef>(Header.FieldRefsOffset, Header.FieldRefsSize / Sizeof<Il2CppFieldRef>());
|
||||||
}
|
}
|
||||||
if (Version >= MetadataVersions.V210 && Version < MetadataVersions.V290) {
|
if (Version >= MetadataVersions.V210 && Version < MetadataVersions.V290) {
|
||||||
AttributeTypeIndices = ReadArray<int>(Header.AttributesTypesOffset, Header.AttributesTypesCount / sizeof(int));
|
AttributeTypeIndices = ReadPrimitiveArray<int>(Header.AttributesTypesOffset, Header.AttributesTypesCount / sizeof(int));
|
||||||
AttributeTypeRanges = ReadArray<Il2CppCustomAttributeTypeRange>(Header.AttributesInfoOffset, Header.AttributesInfoCount / Sizeof(typeof(Il2CppCustomAttributeTypeRange)));
|
AttributeTypeRanges = ReadVersionedObjectArray<Il2CppCustomAttributeTypeRange>(Header.AttributesInfoOffset, Header.AttributesInfoCount / Sizeof<Il2CppCustomAttributeTypeRange>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Version >= MetadataVersions.V290)
|
if (Version >= MetadataVersions.V290)
|
||||||
{
|
{
|
||||||
AttributeDataRanges = ReadArray<Il2CppCustomAttributeDataRange>(Header.AttributeDataRangeOffset,
|
AttributeDataRanges = ReadVersionedObjectArray<Il2CppCustomAttributeDataRange>(Header.AttributeDataRangeOffset,
|
||||||
Header.AttributeDataRangeSize / Sizeof(typeof(Il2CppCustomAttributeDataRange)));
|
Header.AttributeDataRangeSize / Sizeof<Il2CppCustomAttributeDataRange>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Version == MetadataVersions.V290 || Version == MetadataVersions.V310)
|
if (Version == MetadataVersions.V290 || Version == MetadataVersions.V310)
|
||||||
@@ -207,8 +208,8 @@ namespace Il2CppInspector
|
|||||||
{
|
{
|
||||||
Version = new StructVersion(Version.Major, 1, Version.Tag);
|
Version = new StructVersion(Version.Major, 1, Version.Tag);
|
||||||
|
|
||||||
Methods = ReadArray<Il2CppMethodDefinition>(Header.MethodsOffset,
|
Methods = ReadVersionedObjectArray<Il2CppMethodDefinition>(Header.MethodsOffset,
|
||||||
Header.MethodsSize / Sizeof(typeof(Il2CppMethodDefinition)));
|
Header.MethodsSize / Sizeof<Il2CppMethodDefinition>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,7 +232,7 @@ namespace Il2CppInspector
|
|||||||
StringLiterals = pluginGetStringLiteralsResult.StringLiterals.ToArray();
|
StringLiterals = pluginGetStringLiteralsResult.StringLiterals.ToArray();
|
||||||
|
|
||||||
else {
|
else {
|
||||||
var stringLiteralList = ReadArray<Il2CppStringLiteral>(Header.StringLiteralOffset, Header.StringLiteralSize / Sizeof(typeof(Il2CppStringLiteral)));
|
var stringLiteralList = ReadVersionedObjectArray<Il2CppStringLiteral>(Header.StringLiteralOffset, Header.StringLiteralSize / Sizeof<Il2CppStringLiteral>());
|
||||||
|
|
||||||
StringLiterals = new string[stringLiteralList.Length];
|
StringLiterals = new string[stringLiteralList.Length];
|
||||||
for (var i = 0; i < stringLiteralList.Length; i++)
|
for (var i = 0; i < stringLiteralList.Length; i++)
|
||||||
@@ -249,42 +250,6 @@ namespace Il2CppInspector
|
|||||||
CopyTo(outFile);
|
CopyTo(outFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Sizeof(Type type) => Sizeof(type, Version);
|
public int Sizeof<T>() where T : IReadable => T.Size(Version, Is32Bit);
|
||||||
|
|
||||||
public int Sizeof(Type type, StructVersion metadataVersion, int longSizeBytes = 8)
|
|
||||||
{
|
|
||||||
var doubleRepresentation = metadataVersion.AsDouble;
|
|
||||||
|
|
||||||
if (Reader.ObjectMappings.TryGetValue(type, out var streamType))
|
|
||||||
type = streamType;
|
|
||||||
|
|
||||||
int size = 0;
|
|
||||||
foreach (var i in type.GetTypeInfo().GetFields())
|
|
||||||
{
|
|
||||||
// Only process fields for our selected object versioning (always process if none supplied)
|
|
||||||
var versions = i.GetCustomAttributes<VersionAttribute>(false).Select(v => (v.Min, v.Max)).ToList();
|
|
||||||
if (versions.Any() && !versions.Any(v => (v.Min <= doubleRepresentation || v.Min == -1) && (v.Max >= doubleRepresentation || v.Max == -1)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (i.FieldType == typeof(long) || i.FieldType == typeof(ulong))
|
|
||||||
size += longSizeBytes;
|
|
||||||
else if (i.FieldType == typeof(int) || i.FieldType == typeof(uint))
|
|
||||||
size += 4;
|
|
||||||
else if (i.FieldType == typeof(short) || i.FieldType == typeof(ushort))
|
|
||||||
size += 2;
|
|
||||||
|
|
||||||
// Fixed-length array
|
|
||||||
else if (i.FieldType.IsArray) {
|
|
||||||
var attr = i.GetCustomAttribute<ArrayLengthAttribute>(false) ??
|
|
||||||
throw new InvalidOperationException("Array field " + i.Name + " must have ArrayLength attribute");
|
|
||||||
size += attr.FixedSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Embedded object
|
|
||||||
else
|
|
||||||
size += Sizeof(i.FieldType, metadataVersion);
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Il2CppInspector
|
|||||||
FieldRva = 7
|
FieldRva = 7
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MetadataUsage
|
public record struct MetadataUsage
|
||||||
{
|
{
|
||||||
public MetadataUsageType Type { get; }
|
public MetadataUsageType Type { get; }
|
||||||
public int SourceIndex { get; }
|
public int SourceIndex { get; }
|
||||||
@@ -39,7 +39,7 @@ namespace Il2CppInspector
|
|||||||
if (package.Version < MetadataVersions.V190) {
|
if (package.Version < MetadataVersions.V190) {
|
||||||
/* These encoded indices appear only in vtables, and are decoded by IsGenericMethodIndex/GetDecodedMethodIndex */
|
/* These encoded indices appear only in vtables, and are decoded by IsGenericMethodIndex/GetDecodedMethodIndex */
|
||||||
var isGeneric = encodedIndex & 0x80000000;
|
var isGeneric = encodedIndex & 0x80000000;
|
||||||
index = package.Binary.VTableMethodReferences[encodedIndex & 0x7FFFFFFF];
|
index = package.Binary.VTableMethodReferences[(int)(encodedIndex & 0x7FFFFFFF)];
|
||||||
usageType = (isGeneric != 0) ? MetadataUsageType.MethodRef : MetadataUsageType.MethodDef;
|
usageType = (isGeneric != 0) ? MetadataUsageType.MethodRef : MetadataUsageType.MethodDef;
|
||||||
} else {
|
} else {
|
||||||
/* These encoded indices appear in metadata usages, and are decoded by GetEncodedIndexType/GetDecodedMethodIndex */
|
/* These encoded indices appear in metadata usages, and are decoded by GetEncodedIndexType/GetDecodedMethodIndex */
|
||||||
|
|||||||
@@ -3,16 +3,13 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppArrayType
|
public partial record struct Il2CppArrayType
|
||||||
{
|
{
|
||||||
public Pointer<Il2CppType> ElementType;
|
public Pointer<Il2CppType> ElementType;
|
||||||
public byte Rank;
|
public byte Rank;
|
||||||
public byte NumSizes;
|
public byte NumSizes;
|
||||||
public byte NumLowerBound;
|
public byte NumLowerBound;
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<int> Sizes;
|
||||||
public ulong Sizes; // int*
|
public PrimitivePointer<int> LoBounds;
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
|
||||||
public ulong LoBounds; // int*
|
|
||||||
}
|
}
|
||||||
@@ -3,17 +3,16 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppCodeGenModule
|
public partial record struct Il2CppCodeGenModule
|
||||||
{
|
{
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<byte> ModuleName; // const char*
|
||||||
public ulong ModuleName; // const char*
|
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint MethodPointerCount;
|
public uint MethodPointerCount;
|
||||||
|
|
||||||
public Pointer<Il2CppMethodPointer> MethodPointers;
|
public Pointer<Il2CppMethodPointer> MethodPointers;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
[VersionCondition(EqualTo = "24.5")]
|
[VersionCondition(EqualTo = "24.5")]
|
||||||
[VersionCondition(GreaterThan = "27.1")]
|
[VersionCondition(GreaterThan = "27.1")]
|
||||||
public uint AdjustorThunksCount;
|
public uint AdjustorThunksCount;
|
||||||
@@ -22,24 +21,22 @@ public partial struct Il2CppCodeGenModule
|
|||||||
[VersionCondition(GreaterThan = "27.1")]
|
[VersionCondition(GreaterThan = "27.1")]
|
||||||
public Pointer<Il2CppTokenAdjustorThunkPair> AdjustorThunks;
|
public Pointer<Il2CppTokenAdjustorThunkPair> AdjustorThunks;
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<int> InvokerIndices; // int*
|
||||||
public ulong InvokerIndices; // int*
|
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint ReversePInvokeWrapperCount;
|
public uint ReversePInvokeWrapperCount;
|
||||||
|
|
||||||
public Pointer<Il2CppTokenIndexMethodTuple> ReversePInvokeWrapperIndices;
|
public Pointer<Il2CppTokenIndexMethodTuple> ReversePInvokeWrapperIndices;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint RgctxRangesCount;
|
public uint RgctxRangesCount;
|
||||||
public Pointer<Il2CppTokenRangePair> RgctxRanges;
|
public Pointer<Il2CppTokenRangePair> RgctxRanges;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint RgctxsCount;
|
public uint RgctxsCount;
|
||||||
public Pointer<Il2CppRgctxDefinition> Rgctxs;
|
public Pointer<Il2CppRgctxDefinition> Rgctxs;
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<byte> DebuggerMetadata; // Pointer<Il2CppDebuggerMetadataRegistration> DebuggerMetadata;
|
||||||
public ulong DebuggerMetadata; // Pointer<Il2CppDebuggerMetadataRegistration> DebuggerMetadata;
|
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "27.0", LessThan = "27.2")]
|
[VersionCondition(GreaterThan = "27.0", LessThan = "27.2")]
|
||||||
public Pointer<Il2CppMethodPointer> CustomAttributeCacheGenerator;
|
public Pointer<Il2CppMethodPointer> CustomAttributeCacheGenerator;
|
||||||
@@ -48,14 +45,11 @@ public partial struct Il2CppCodeGenModule
|
|||||||
public Il2CppMethodPointer ModuleInitializer;
|
public Il2CppMethodPointer ModuleInitializer;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "27.0")]
|
[VersionCondition(GreaterThan = "27.0")]
|
||||||
[Aligned(0)]
|
public PrimitivePointer<int> StaticConstructorTypeIndices; // TypeDefinitionIndex*
|
||||||
public ulong StaticConstructorTypeIndices; // TypeDefinitionIndex*
|
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "27.0")]
|
[VersionCondition(GreaterThan = "27.0")]
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<byte> MetadataRegistration; // Pointer<Il2CppMetadataRegistration>
|
||||||
public ulong MetadataRegistration; // Pointer<Il2CppMetadataRegistration>
|
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "27.0")]
|
[VersionCondition(GreaterThan = "27.0")]
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<byte> CodeRegistration; // Pointer<Il2CppCodeRegistration>
|
||||||
public ulong CodeRegistration; // Pointer<Il2CppCodeRegistration>
|
|
||||||
}
|
}
|
||||||
@@ -5,38 +5,42 @@ namespace Il2CppInspector.Next.BinaryMetadata;
|
|||||||
using InvokerMethod = Il2CppMethodPointer;
|
using InvokerMethod = Il2CppMethodPointer;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppCodeRegistration
|
public partial record struct Il2CppCodeRegistration
|
||||||
{
|
{
|
||||||
[VersionCondition(LessThan = "24.1"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(LessThan = "24.1")]
|
||||||
public uint MethodPointersCount;
|
public uint MethodPointersCount;
|
||||||
|
|
||||||
[VersionCondition(LessThan = "24.1")]
|
[VersionCondition(LessThan = "24.1")]
|
||||||
public Pointer<Il2CppMethodPointer> MethodPointers;
|
public Pointer<Il2CppMethodPointer> MethodPointers;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint ReversePInvokeWrapperCount;
|
public uint ReversePInvokeWrapperCount;
|
||||||
|
|
||||||
public Pointer<Il2CppMethodPointer> ReversePInvokeWrappers;
|
public Pointer<Il2CppMethodPointer> ReversePInvokeWrappers;
|
||||||
|
|
||||||
[VersionCondition(LessThan = "22.0"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(LessThan = "22.0")]
|
||||||
public uint DelegateWrappersFromManagedToNativeCount;
|
public uint DelegateWrappersFromManagedToNativeCount;
|
||||||
|
|
||||||
[VersionCondition(LessThan = "22.0")]
|
[VersionCondition(LessThan = "22.0")]
|
||||||
public Pointer<Il2CppMethodPointer> DelegateWrappersFromManagedToNative;
|
public Pointer<Il2CppMethodPointer> DelegateWrappersFromManagedToNative;
|
||||||
|
|
||||||
[VersionCondition(LessThan = "22.0"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(LessThan = "22.0")]
|
||||||
public uint MarshalingFunctionsCount;
|
public uint MarshalingFunctionsCount;
|
||||||
|
|
||||||
[VersionCondition(LessThan = "22.0")]
|
[VersionCondition(LessThan = "22.0")]
|
||||||
public Pointer<Il2CppMethodPointer> MarshalingFunctions;
|
public Pointer<Il2CppMethodPointer> MarshalingFunctions;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||||
public uint CcwMarshalingFunctionsCount;
|
public uint CcwMarshalingFunctionsCount;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||||
public Pointer<Il2CppMethodPointer> CcwMarshalingFunctions;
|
public Pointer<Il2CppMethodPointer> CcwMarshalingFunctions;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint GenericMethodPointersCount;
|
public uint GenericMethodPointersCount;
|
||||||
|
|
||||||
public Pointer<Il2CppMethodPointer> GenericMethodPointers;
|
public Pointer<Il2CppMethodPointer> GenericMethodPointers;
|
||||||
@@ -45,29 +49,32 @@ public partial struct Il2CppCodeRegistration
|
|||||||
[VersionCondition(GreaterThan = "27.1")]
|
[VersionCondition(GreaterThan = "27.1")]
|
||||||
public Pointer<Il2CppMethodPointer> GenericAdjustorThunks;
|
public Pointer<Il2CppMethodPointer> GenericAdjustorThunks;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint InvokerPointersCount;
|
public uint InvokerPointersCount;
|
||||||
|
|
||||||
public Pointer<InvokerMethod> InvokerPointers;
|
public Pointer<InvokerMethod> InvokerPointers;
|
||||||
|
|
||||||
[VersionCondition(LessThan = "24.5"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(LessThan = "24.5")]
|
||||||
public int CustomAttributeCount;
|
public int CustomAttributeCount;
|
||||||
|
|
||||||
[VersionCondition(LessThan = "24.5")]
|
[VersionCondition(LessThan = "24.5")]
|
||||||
public Pointer<Il2CppMethodPointer> CustomAttributeGenerators;
|
public Pointer<Il2CppMethodPointer> CustomAttributeGenerators;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||||
public int GuidCount;
|
public int GuidCount;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||||
public Pointer<Il2CppGuid> Guids;
|
public Pointer<Il2CppGuid> Guids;
|
||||||
|
|
||||||
|
[NativeInteger]
|
||||||
[VersionCondition(GreaterThan = "22.0", LessThan = "29.0")]
|
[VersionCondition(GreaterThan = "22.0", LessThan = "29.0")]
|
||||||
public int UnresolvedVirtualCallCount;
|
public int UnresolvedVirtualCallCount;
|
||||||
|
|
||||||
|
[NativeInteger]
|
||||||
[VersionCondition(EqualTo = "29.1"), VersionCondition(EqualTo = "31.1")]
|
[VersionCondition(EqualTo = "29.1"), VersionCondition(EqualTo = "31.1")]
|
||||||
[VersionCondition(EqualTo = "29.2"), VersionCondition(EqualTo = "31.2")]
|
[VersionCondition(EqualTo = "29.2"), VersionCondition(EqualTo = "31.2")]
|
||||||
[Aligned(0)]
|
|
||||||
public uint UnresolvedIndirectCallCount; // UnresolvedVirtualCallCount pre 29.1
|
public uint UnresolvedIndirectCallCount; // UnresolvedVirtualCallCount pre 29.1
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "22.0")]
|
[VersionCondition(GreaterThan = "22.0")]
|
||||||
@@ -81,19 +88,22 @@ public partial struct Il2CppCodeRegistration
|
|||||||
[VersionCondition(EqualTo = "29.2"), VersionCondition(EqualTo = "31.2")]
|
[VersionCondition(EqualTo = "29.2"), VersionCondition(EqualTo = "31.2")]
|
||||||
public Pointer<Il2CppMethodPointer> UnresolvedStaticCallPointers;
|
public Pointer<Il2CppMethodPointer> UnresolvedStaticCallPointers;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "23.0"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(GreaterThan = "23.0")]
|
||||||
public uint InteropDataCount;
|
public uint InteropDataCount;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "23.0")]
|
[VersionCondition(GreaterThan = "23.0")]
|
||||||
public Pointer<Il2CppInteropData> InteropData;
|
public Pointer<Il2CppInteropData> InteropData;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "24.3"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(GreaterThan = "24.3")]
|
||||||
public uint WindowsRuntimeFactoryCount;
|
public uint WindowsRuntimeFactoryCount;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "24.3")]
|
[VersionCondition(GreaterThan = "24.3")]
|
||||||
public Pointer<Il2CppWindowsRuntimeFactoryTableEntry> WindowsRuntimeFactoryTable;
|
public Pointer<Il2CppWindowsRuntimeFactoryTableEntry> WindowsRuntimeFactoryTable;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "24.2"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(GreaterThan = "24.2")]
|
||||||
public uint CodeGenModulesCount;
|
public uint CodeGenModulesCount;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "24.2")]
|
[VersionCondition(GreaterThan = "24.2")]
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppGenericClass
|
public partial record struct Il2CppGenericClass
|
||||||
{
|
{
|
||||||
[VersionCondition(LessThan = "24.5"), Aligned(0)]
|
[NativeInteger]
|
||||||
|
[VersionCondition(LessThan = "24.5")]
|
||||||
public int TypeDefinitionIndex;
|
public int TypeDefinitionIndex;
|
||||||
|
|
||||||
[VersionCondition(GreaterThan = "27.0")]
|
[VersionCondition(GreaterThan = "27.0")]
|
||||||
@@ -13,6 +14,5 @@ public partial struct Il2CppGenericClass
|
|||||||
|
|
||||||
public Il2CppGenericContext Context;
|
public Il2CppGenericContext Context;
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<byte> CachedClass; // Il2CppClass*, optional
|
||||||
public ulong CachedClass; // Il2CppClass*, optional
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppGenericContext
|
public partial record struct Il2CppGenericContext
|
||||||
{
|
{
|
||||||
public Pointer<Il2CppGenericInst> ClassInst;
|
public Pointer<Il2CppGenericInst> ClassInst;
|
||||||
public Pointer<Il2CppGenericInst> MethodInst;
|
public Pointer<Il2CppGenericInst> MethodInst;
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppGenericInst
|
public partial record struct Il2CppGenericInst
|
||||||
{
|
{
|
||||||
public readonly bool Valid => TypeArgc > 0;
|
public readonly bool Valid => TypeArgc > 0;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint TypeArgc;
|
public uint TypeArgc;
|
||||||
|
|
||||||
public Pointer<Pointer<Il2CppType>> TypeArgv;
|
public Pointer<Pointer<Il2CppType>> TypeArgv;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Il2CppInspector.Next.BinaryMetadata;
|
|||||||
using GenericMethodIndex = int;
|
using GenericMethodIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppGenericMethodFunctionsDefinitions
|
public partial record struct Il2CppGenericMethodFunctionsDefinitions
|
||||||
{
|
{
|
||||||
public GenericMethodIndex GenericMethodIndex;
|
public GenericMethodIndex GenericMethodIndex;
|
||||||
public Il2CppGenericMethodIndices Indices;
|
public Il2CppGenericMethodIndices Indices;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Il2CppInspector.Next.BinaryMetadata;
|
|||||||
using MethodIndex = int;
|
using MethodIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppGenericMethodIndices
|
public partial record struct Il2CppGenericMethodIndices
|
||||||
{
|
{
|
||||||
public MethodIndex MethodIndex;
|
public MethodIndex MethodIndex;
|
||||||
public MethodIndex InvokerIndex;
|
public MethodIndex InvokerIndex;
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
|
public record struct Il2CppGuid : IReadable
|
||||||
public struct Il2CppGuid : IReadable
|
|
||||||
{
|
{
|
||||||
public Guid Value;
|
public Guid Value;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using PInvokeMarshalCleanupFunc = Il2CppMethodPointer;
|
|||||||
using CreateCCWFunc = Il2CppMethodPointer;
|
using CreateCCWFunc = Il2CppMethodPointer;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppInteropData
|
public partial record struct Il2CppInteropData
|
||||||
{
|
{
|
||||||
public Il2CppMethodPointer DelegatePInvokeWrapperFunction;
|
public Il2CppMethodPointer DelegatePInvokeWrapperFunction;
|
||||||
public PInvokeMarshalToNativeFunc PInvokeMarshalToNativeFunction;
|
public PInvokeMarshalToNativeFunc PInvokeMarshalToNativeFunction;
|
||||||
|
|||||||
@@ -7,51 +7,50 @@ using FieldIndex = int;
|
|||||||
using TypeDefinitionIndex = int;
|
using TypeDefinitionIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppMetadataRegistration
|
public partial record struct Il2CppMetadataRegistration
|
||||||
{
|
{
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public int GenericClassesCount;
|
public int GenericClassesCount;
|
||||||
|
|
||||||
public Pointer<Pointer<Il2CppGenericClass>> GenericClasses;
|
public Pointer<Pointer<Il2CppGenericClass>> GenericClasses;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public int GenericInstsCount;
|
public int GenericInstsCount;
|
||||||
|
|
||||||
public Pointer<Pointer<Il2CppGenericInst>> GenericInsts;
|
public Pointer<Pointer<Il2CppGenericInst>> GenericInsts;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public int GenericMethodTableCount;
|
public int GenericMethodTableCount;
|
||||||
|
|
||||||
public Pointer<Il2CppGenericMethodFunctionsDefinitions> GenericMethodTable;
|
public Pointer<Il2CppGenericMethodFunctionsDefinitions> GenericMethodTable;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public int TypesCount;
|
public int TypesCount;
|
||||||
|
|
||||||
public Pointer<Pointer<Il2CppType>> Types;
|
public Pointer<Pointer<Il2CppType>> Types;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public int MethodSpecsCount;
|
public int MethodSpecsCount;
|
||||||
|
|
||||||
public Pointer<Il2CppMethodSpec> MethodSpecs;
|
public Pointer<Il2CppMethodSpec> MethodSpecs;
|
||||||
|
|
||||||
|
[NativeInteger]
|
||||||
[VersionCondition(LessThan = "16.0")]
|
[VersionCondition(LessThan = "16.0")]
|
||||||
public int MethodReferencesCount;
|
public int MethodReferencesCount;
|
||||||
|
|
||||||
[VersionCondition(LessThan = "16.0")]
|
[VersionCondition(LessThan = "16.0")]
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<PrimitivePointer<uint>> MethodReferences; // uint**
|
||||||
public ulong MethodReferences; // uint**
|
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public FieldIndex FieldOffsetsCount;
|
public FieldIndex FieldOffsetsCount;
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<PrimitivePointer<int>> FieldOffsets; // int**
|
||||||
public ulong FieldOffsets; // int**
|
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public TypeDefinitionIndex TypeDefinitionsSizesCount;
|
public TypeDefinitionIndex TypeDefinitionsSizesCount;
|
||||||
public Pointer<Pointer<Il2CppTypeDefinitionSizes>> TypeDefinitionsSizes;
|
public Pointer<Pointer<Il2CppTypeDefinitionSizes>> TypeDefinitionsSizes;
|
||||||
|
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
[VersionCondition(GreaterThan = "19.0")]
|
[VersionCondition(GreaterThan = "19.0")]
|
||||||
public ulong MetadataUsagesCount;
|
public ulong MetadataUsagesCount;
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppMethodPointer(ulong addr = 0)
|
public partial record struct Il2CppMethodPointer(ulong addr = 0)
|
||||||
{
|
{
|
||||||
public static readonly Il2CppMethodPointer Null = new();
|
public static readonly Il2CppMethodPointer Null = new();
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
[NativeInteger]
|
||||||
public ulong Value { get; set; } = addr;
|
public ulong Value { get; set; } = addr;
|
||||||
|
|
||||||
public readonly bool IsNull => Value == 0;
|
public readonly bool IsNull => Value == 0;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using MethodIndex = int;
|
|||||||
using GenericInstIndex = int;
|
using GenericInstIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppMethodSpec
|
public partial record struct Il2CppMethodSpec
|
||||||
{
|
{
|
||||||
public MethodIndex MethodDefinitionIndex;
|
public MethodIndex MethodDefinitionIndex;
|
||||||
public GenericInstIndex ClassIndexIndex;
|
public GenericInstIndex ClassIndexIndex;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppRange
|
public partial record struct Il2CppRange
|
||||||
{
|
{
|
||||||
public int Start;
|
public int Start;
|
||||||
public int Length;
|
public int Length;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace Il2CppInspector.Next.BinaryMetadata;
|
|||||||
using TypeIndex = int;
|
using TypeIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppRgctxConstrainedData
|
public partial record struct Il2CppRgctxConstrainedData
|
||||||
{
|
{
|
||||||
public TypeIndex TypeIndex;
|
public TypeIndex TypeIndex;
|
||||||
public Il2CppMetadataUsage EncodedMethodIndex;
|
public Il2CppMetadataUsage EncodedMethodIndex;
|
||||||
|
|||||||
@@ -3,14 +3,13 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppRgctxDefinition
|
public partial record struct Il2CppRgctxDefinition
|
||||||
{
|
{
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public Il2CppRgctxDataType Type;
|
public Il2CppRgctxDataType Type;
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<byte> Data; // void*
|
||||||
public ulong Data; // void*
|
|
||||||
|
|
||||||
public readonly Pointer<Il2CppRgctxDefinitionData> Definition => Data;
|
public readonly Pointer<Il2CppRgctxDefinitionData> Definition => Data.PointerValue;
|
||||||
public readonly Pointer<Il2CppRgctxConstrainedData> Constrained => Data;
|
public readonly Pointer<Il2CppRgctxConstrainedData> Constrained => Data.PointerValue;
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ using MethodIndex = int;
|
|||||||
using TypeIndex = int;
|
using TypeIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppRgctxDefinitionData
|
public partial record struct Il2CppRgctxDefinitionData
|
||||||
{
|
{
|
||||||
public int Value;
|
public int Value;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppTokenAdjustorThunkPair
|
public partial record struct Il2CppTokenAdjustorThunkPair
|
||||||
{
|
{
|
||||||
[Aligned(0)]
|
[NativeInteger]
|
||||||
public uint Token;
|
public uint Token;
|
||||||
|
|
||||||
public Il2CppMethodPointer AdjustorThunk;
|
public Il2CppMethodPointer AdjustorThunk;
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppTokenIndexMethodTuple
|
public partial record struct Il2CppTokenIndexMethodTuple
|
||||||
{
|
{
|
||||||
public uint Token;
|
public uint Token;
|
||||||
public int Index;
|
public int Index;
|
||||||
|
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
public PrimitivePointer<Il2CppMethodPointer> Method; // void**
|
||||||
public ulong Method; // void**
|
|
||||||
|
|
||||||
public uint GenericMethodIndex;
|
public uint GenericMethodIndex;
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppTokenRangePair
|
public partial record struct Il2CppTokenRangePair
|
||||||
{
|
{
|
||||||
public uint Token;
|
public uint Token;
|
||||||
public Il2CppRange Range;
|
public Il2CppRange Range;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppTypeDefinitionSizes
|
public partial record struct Il2CppTypeDefinitionSizes
|
||||||
{
|
{
|
||||||
public uint InstanceSize;
|
public uint InstanceSize;
|
||||||
public int NativeSize;
|
public int NativeSize;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppWindowsRuntimeFactoryTableEntry
|
public partial record struct Il2CppWindowsRuntimeFactoryTableEntry
|
||||||
{
|
{
|
||||||
public Pointer<Il2CppType> Type;
|
public Pointer<Il2CppType> Type;
|
||||||
public Il2CppMethodPointer CreateFactoryFunction;
|
public Il2CppMethodPointer CreateFactoryFunction;
|
||||||
|
|||||||
@@ -8,6 +8,18 @@ namespace Il2CppInspector.Next;
|
|||||||
|
|
||||||
public class BinaryObjectStreamReader : BinaryObjectStream, IReader
|
public class BinaryObjectStreamReader : BinaryObjectStream, IReader
|
||||||
{
|
{
|
||||||
|
public new StructVersion Version
|
||||||
|
{
|
||||||
|
get => _version;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_version = value;
|
||||||
|
base.Version = _version.AsDouble;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StructVersion _version;
|
||||||
|
|
||||||
public virtual int Bits { get; set; }
|
public virtual int Bits { get; set; }
|
||||||
public bool Is32Bit => Bits == 32;
|
public bool Is32Bit => Bits == 32;
|
||||||
|
|
||||||
@@ -127,4 +139,9 @@ public class BinaryObjectStreamReader : BinaryObjectStream, IReader
|
|||||||
Position = addr;
|
Position = addr;
|
||||||
return ReadVersionedObjectArray<TType>(count, Version);
|
return ReadVersionedObjectArray<TType>(count, Version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Skip(int count)
|
||||||
|
{
|
||||||
|
Position += count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ using ImageIndex = int;
|
|||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
public partial struct Il2CppAssemblyDefinition
|
public partial record struct Il2CppAssemblyDefinition
|
||||||
{
|
{
|
||||||
[FieldOffset(20)]
|
[FieldOffset(20)]
|
||||||
[VersionCondition(LessThan = "15.0")]
|
[VersionCondition(LessThan = "15.0")]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public struct PublicKeyToken
|
|||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
public partial struct Il2CppAssemblyNameDefinition
|
public partial record struct Il2CppAssemblyNameDefinition
|
||||||
{
|
{
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
public StringIndex NameIndex;
|
public StringIndex NameIndex;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.Metadata;
|
namespace Il2CppInspector.Next.Metadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppCustomAttributeDataRange
|
public partial record struct Il2CppCustomAttributeDataRange
|
||||||
{
|
{
|
||||||
public uint Token { get; private set; }
|
public uint Token { get; private set; }
|
||||||
public uint StartOffset { get; private set; }
|
public uint StartOffset { get; private set; }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.Metadata;
|
namespace Il2CppInspector.Next.Metadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppCustomAttributeTypeRange
|
public partial record struct Il2CppCustomAttributeTypeRange
|
||||||
{
|
{
|
||||||
[VersionCondition(GreaterThan = "24.1")]
|
[VersionCondition(GreaterThan = "24.1")]
|
||||||
public uint Token { get; private set; }
|
public uint Token { get; private set; }
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using MethodIndex = int;
|
|||||||
using VersionedSerialization.Attributes;
|
using VersionedSerialization.Attributes;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppEventDefinition
|
public partial record struct Il2CppEventDefinition
|
||||||
{
|
{
|
||||||
public StringIndex NameIndex { get; private set; }
|
public StringIndex NameIndex { get; private set; }
|
||||||
public TypeIndex TypeIndex { get; private set; }
|
public TypeIndex TypeIndex { get; private set; }
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using TypeIndex = int;
|
|||||||
using DefaultValueDataIndex = int;
|
using DefaultValueDataIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppFieldDefaultValue
|
public partial record struct Il2CppFieldDefaultValue
|
||||||
{
|
{
|
||||||
public FieldIndex FieldIndex { get; private set; }
|
public FieldIndex FieldIndex { get; private set; }
|
||||||
public TypeIndex TypeIndex { get; private set; }
|
public TypeIndex TypeIndex { get; private set; }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using StringIndex = int;
|
|||||||
using TypeIndex = int;
|
using TypeIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppFieldDefinition
|
public partial record struct Il2CppFieldDefinition
|
||||||
{
|
{
|
||||||
public StringIndex NameIndex { get; private set; }
|
public StringIndex NameIndex { get; private set; }
|
||||||
public TypeIndex TypeIndex { get; private set; }
|
public TypeIndex TypeIndex { get; private set; }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using FieldIndex = int;
|
|||||||
using TypeIndex = int;
|
using TypeIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppFieldMarshaledSize
|
public partial record struct Il2CppFieldMarshaledSize
|
||||||
{
|
{
|
||||||
public FieldIndex FieldIndex { get; private set; }
|
public FieldIndex FieldIndex { get; private set; }
|
||||||
public TypeIndex TypeIndex { get; private set; }
|
public TypeIndex TypeIndex { get; private set; }
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using FieldIndex = int;
|
|||||||
using TypeIndex = int;
|
using TypeIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppFieldRef
|
public partial record struct Il2CppFieldRef
|
||||||
{
|
{
|
||||||
public TypeIndex TypeIndex { get; private set; }
|
public TypeIndex TypeIndex { get; private set; }
|
||||||
public FieldIndex FieldIndex { get; private set; }
|
public FieldIndex FieldIndex { get; private set; }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using VersionedSerialization.Attributes;
|
|||||||
using GenericParameterIndex = int;
|
using GenericParameterIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppGenericContainer
|
public partial record struct Il2CppGenericContainer
|
||||||
{
|
{
|
||||||
public int OwnerIndex { get; private set; }
|
public int OwnerIndex { get; private set; }
|
||||||
public int TypeArgc { get; private set; }
|
public int TypeArgc { get; private set; }
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using StringIndex = int;
|
|||||||
using GenericParameterConstraintIndex = short;
|
using GenericParameterConstraintIndex = short;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppGenericParameter
|
public partial record struct Il2CppGenericParameter
|
||||||
{
|
{
|
||||||
public GenericContainerIndex OwnerIndex { get; private set; }
|
public GenericContainerIndex OwnerIndex { get; private set; }
|
||||||
public StringIndex NameIndex { get; private set; }
|
public StringIndex NameIndex { get; private set; }
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace Il2CppInspector.Next.Metadata;
|
|||||||
// Metadata version is written at the end of Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata or WriteMetadata (Unity.IL2CPP.dll)
|
// Metadata version is written at the end of Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata or WriteMetadata (Unity.IL2CPP.dll)
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppGlobalMetadataHeader
|
public partial record struct Il2CppGlobalMetadataHeader
|
||||||
{
|
{
|
||||||
public int Sanity { get; private set; }
|
public int Sanity { get; private set; }
|
||||||
public int Version { get; private set; }
|
public int Version { get; private set; }
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using CustomAttributeIndex = int;
|
|||||||
using VersionedSerialization.Attributes;
|
using VersionedSerialization.Attributes;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppImageDefinition
|
public partial record struct Il2CppImageDefinition
|
||||||
{
|
{
|
||||||
public StringIndex NameIndex { get; private set; }
|
public StringIndex NameIndex { get; private set; }
|
||||||
public AssemblyIndex AssemblyIndex { get; private set; }
|
public AssemblyIndex AssemblyIndex { get; private set; }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Il2CppInspector.Next.Metadata;
|
|||||||
using TypeIndex = int;
|
using TypeIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppInterfaceOffsetPair
|
public partial record struct Il2CppInterfaceOffsetPair
|
||||||
{
|
{
|
||||||
public TypeIndex InterfaceTypeIndex { get; private set; }
|
public TypeIndex InterfaceTypeIndex { get; private set; }
|
||||||
public int Offset { get; private set; }
|
public int Offset { get; private set; }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.Metadata;
|
namespace Il2CppInspector.Next.Metadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppMetadataRange
|
public partial record struct Il2CppMetadataRange
|
||||||
{
|
{
|
||||||
public int Start { get; private set; }
|
public int Start { get; private set; }
|
||||||
public int Length { get; private set; }
|
public int Length { get; private set; }
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using VersionedSerialization.Attributes;
|
|||||||
using EncodedMethodIndex = uint;
|
using EncodedMethodIndex = uint;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppMetadataUsage
|
public partial record struct Il2CppMetadataUsage
|
||||||
{
|
{
|
||||||
private const uint TypeMask = 0b111u << 29;
|
private const uint TypeMask = 0b111u << 29;
|
||||||
private const uint InflatedMask = 0b1;
|
private const uint InflatedMask = 0b1;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.Metadata;
|
namespace Il2CppInspector.Next.Metadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppMetadataUsageList
|
public partial record struct Il2CppMetadataUsageList
|
||||||
{
|
{
|
||||||
public int Start { get; private set; }
|
public int Start { get; private set; }
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.Metadata;
|
namespace Il2CppInspector.Next.Metadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppMetadataUsagePair
|
public partial record struct Il2CppMetadataUsagePair
|
||||||
{
|
{
|
||||||
public uint DestinationIndex { get; private set; }
|
public uint DestinationIndex { get; private set; }
|
||||||
public uint EncodedSourceIndex { get; private set; }
|
public uint EncodedSourceIndex { get; private set; }
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using ParameterIndex = int;
|
|||||||
using GenericContainerIndex = int;
|
using GenericContainerIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppMethodDefinition
|
public partial record struct Il2CppMethodDefinition
|
||||||
{
|
{
|
||||||
public StringIndex NameIndex { get; private set; }
|
public StringIndex NameIndex { get; private set; }
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using DefaultValueDataIndex = int;
|
|||||||
using VersionedSerialization.Attributes;
|
using VersionedSerialization.Attributes;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppParameterDefaultValue
|
public partial record struct Il2CppParameterDefaultValue
|
||||||
{
|
{
|
||||||
public ParameterIndex ParameterIndex { get; private set; }
|
public ParameterIndex ParameterIndex { get; private set; }
|
||||||
public TypeIndex TypeIndex { get; private set; }
|
public TypeIndex TypeIndex { get; private set; }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using StringIndex = int;
|
|||||||
using TypeIndex = int;
|
using TypeIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppParameterDefinition
|
public partial record struct Il2CppParameterDefinition
|
||||||
{
|
{
|
||||||
public StringIndex NameIndex { get; private set; }
|
public StringIndex NameIndex { get; private set; }
|
||||||
public uint Token { get; private set; }
|
public uint Token { get; private set; }
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using StringIndex = int;
|
|||||||
using MethodIndex = int;
|
using MethodIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppPropertyDefinition
|
public partial record struct Il2CppPropertyDefinition
|
||||||
{
|
{
|
||||||
public StringIndex NameIndex { get; private set; }
|
public StringIndex NameIndex { get; private set; }
|
||||||
public MethodIndex Get { get; private set; }
|
public MethodIndex Get { get; private set; }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using VersionedSerialization.Attributes;
|
|||||||
using StringLiteralIndex = int;
|
using StringLiteralIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppStringLiteral
|
public partial record struct Il2CppStringLiteral
|
||||||
{
|
{
|
||||||
public uint Length { get; private set; }
|
public uint Length { get; private set; }
|
||||||
public StringLiteralIndex DataIndex { get; private set; }
|
public StringLiteralIndex DataIndex { get; private set; }
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ using InterfacesIndex = int;
|
|||||||
using VTableIndex = int;
|
using VTableIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppTypeDefinition
|
public partial record struct Il2CppTypeDefinition
|
||||||
{
|
{
|
||||||
public const TypeIndex InvalidTypeIndex = -1;
|
public const TypeIndex InvalidTypeIndex = -1;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Il2CppInspector.Next.Metadata;
|
namespace Il2CppInspector.Next.Metadata;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppTypeDefinitionBitfield
|
public partial record struct Il2CppTypeDefinitionBitfield
|
||||||
{
|
{
|
||||||
private uint _value;
|
private uint _value;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using StringIndex = int;
|
|||||||
using TypeIndex = int;
|
using TypeIndex = int;
|
||||||
|
|
||||||
[VersionedStruct]
|
[VersionedStruct]
|
||||||
public partial struct Il2CppWindowsRuntimeTypeNamePair
|
public partial record struct Il2CppWindowsRuntimeTypeNamePair
|
||||||
{
|
{
|
||||||
public StringIndex NameIndex { get; private set; }
|
public StringIndex NameIndex { get; private set; }
|
||||||
public TypeIndex TypeIndex { get; private set; }
|
public TypeIndex TypeIndex { get; private set; }
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ using VersionedSerialization.Attributes;
|
|||||||
|
|
||||||
namespace Il2CppInspector.Next;
|
namespace Il2CppInspector.Next;
|
||||||
|
|
||||||
public struct Pointer<T>(ulong value = 0) : IReadable, IEquatable<Pointer<T>> where T : IReadable, new()
|
public struct Pointer<T>(ulong value = 0) : IReadable, IEquatable<Pointer<T>> where T : struct, IReadable
|
||||||
{
|
{
|
||||||
[CustomSerialization("reader.ReadNUInt();", "is32Bit ? 4 : 8")]
|
[NativeInteger]
|
||||||
private ulong _value = value;
|
private ulong _value = value;
|
||||||
|
|
||||||
public readonly ulong PointerValue => _value;
|
public readonly ulong PointerValue => _value;
|
||||||
|
|||||||
60
Il2CppInspector.Common/Next/PrimitivePointer.cs
Normal file
60
Il2CppInspector.Common/Next/PrimitivePointer.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using VersionedSerialization;
|
||||||
|
using VersionedSerialization.Attributes;
|
||||||
|
|
||||||
|
namespace Il2CppInspector.Next;
|
||||||
|
|
||||||
|
public struct PrimitivePointer<T>(ulong value = 0) : IReadable, IEquatable<PrimitivePointer<T>> where T : unmanaged
|
||||||
|
{
|
||||||
|
[NativeInteger]
|
||||||
|
private ulong _value = value;
|
||||||
|
|
||||||
|
public readonly ulong PointerValue => _value;
|
||||||
|
public readonly bool Null => _value == 0;
|
||||||
|
|
||||||
|
public void Read<TReader>(ref TReader reader, in StructVersion version = default) where TReader : IReader, allows ref struct
|
||||||
|
{
|
||||||
|
_value = reader.ReadNUInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Size(in StructVersion version = default, bool is32Bit = false)
|
||||||
|
{
|
||||||
|
return is32Bit ? 4 : 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly T Read(ref SpanReader reader)
|
||||||
|
{
|
||||||
|
reader.Offset = (int)PointerValue;
|
||||||
|
return reader.ReadPrimitive<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly ImmutableArray<T> ReadArray(ref SpanReader reader, long count)
|
||||||
|
{
|
||||||
|
reader.Offset = (int)PointerValue;
|
||||||
|
return reader.ReadPrimitiveArray<T>(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator PrimitivePointer<T>(ulong value) => new(value);
|
||||||
|
public static implicit operator ulong(PrimitivePointer<T> ptr) => ptr.PointerValue;
|
||||||
|
|
||||||
|
#region Equality operators + ToString
|
||||||
|
|
||||||
|
public static bool operator ==(PrimitivePointer<T> left, PrimitivePointer<T> right)
|
||||||
|
=> left._value == right._value;
|
||||||
|
|
||||||
|
public static bool operator !=(PrimitivePointer<T> left, PrimitivePointer<T> right)
|
||||||
|
=> !(left == right);
|
||||||
|
|
||||||
|
public readonly override bool Equals(object? obj)
|
||||||
|
=> obj is PrimitivePointer<T> other && Equals(other);
|
||||||
|
|
||||||
|
public readonly bool Equals(PrimitivePointer<T> other)
|
||||||
|
=> this == other;
|
||||||
|
|
||||||
|
public readonly override int GetHashCode()
|
||||||
|
=> HashCode.Combine(_value);
|
||||||
|
|
||||||
|
public readonly override string ToString() => $"0x{_value:X} <{typeof(T).Name}>";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -87,7 +87,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
public TypeModel(Il2CppInspector package) {
|
public TypeModel(Il2CppInspector package) {
|
||||||
Package = package;
|
Package = package;
|
||||||
TypesByDefinitionIndex = new TypeInfo[package.TypeDefinitions.Length];
|
TypesByDefinitionIndex = new TypeInfo[package.TypeDefinitions.Length];
|
||||||
TypesByReferenceIndex = new TypeInfo[package.TypeReferences.Count];
|
TypesByReferenceIndex = new TypeInfo[package.TypeReferences.Length];
|
||||||
GenericParameterTypes = new TypeInfo[package.GenericParameters.Length];
|
GenericParameterTypes = new TypeInfo[package.GenericParameters.Length];
|
||||||
MethodsByDefinitionIndex = new MethodBase[package.Methods.Length];
|
MethodsByDefinitionIndex = new MethodBase[package.Methods.Length];
|
||||||
MethodInvokers = new MethodInvoker[package.MethodInvokePointers.Length];
|
MethodInvokers = new MethodInvoker[package.MethodInvokePointers.Length];
|
||||||
@@ -99,7 +99,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
|
|
||||||
// Create and reference types from TypeRefs
|
// Create and reference types from TypeRefs
|
||||||
// Note that you can't resolve any TypeRefs until all the TypeDefs have been processed
|
// Note that you can't resolve any TypeRefs until all the TypeDefs have been processed
|
||||||
for (int typeRefIndex = 0; typeRefIndex < package.TypeReferences.Count; typeRefIndex++) {
|
for (int typeRefIndex = 0; typeRefIndex < package.TypeReferences.Length; typeRefIndex++) {
|
||||||
if(TypesByReferenceIndex[typeRefIndex] != null) {
|
if(TypesByReferenceIndex[typeRefIndex] != null) {
|
||||||
/* type already generated - probably by forward reference through GetTypeFromVirtualAddress */
|
/* type already generated - probably by forward reference through GetTypeFromVirtualAddress */
|
||||||
continue;
|
continue;
|
||||||
@@ -191,7 +191,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
public TypeInfo[] ResolveGenericArguments(Il2CppGenericInst inst) {
|
public TypeInfo[] ResolveGenericArguments(Il2CppGenericInst inst) {
|
||||||
|
|
||||||
// Get list of pointers to type parameters (both unresolved and concrete)
|
// Get list of pointers to type parameters (both unresolved and concrete)
|
||||||
var genericTypeArguments = Package.BinaryImage.ReadMappedArray<ulong>(inst.TypeArgv, (int)inst.TypeArgc);
|
var genericTypeArguments = Package.BinaryImage.ReadMappedUWordArray(inst.TypeArgv, (int)inst.TypeArgc);
|
||||||
|
|
||||||
return genericTypeArguments.Select(a => GetTypeFromVirtualAddress(a)).ToArray();
|
return genericTypeArguments.Select(a => GetTypeFromVirtualAddress(a)).ToArray();
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
// Constructed types
|
// Constructed types
|
||||||
case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
|
case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
|
||||||
// TODO: Replace with array load from Il2CppMetadataRegistration.genericClasses
|
// TODO: Replace with array load from Il2CppMetadataRegistration.genericClasses
|
||||||
var generic = image.ReadMappedObject<Il2CppGenericClass>(typeRef.Data.GenericClass); // Il2CppGenericClass *
|
var generic = image.ReadMappedVersionedObject<Il2CppGenericClass>(typeRef.Data.GenericClass); // Il2CppGenericClass *
|
||||||
|
|
||||||
// Get generic type definition
|
// Get generic type definition
|
||||||
TypeInfo genericTypeDef;
|
TypeInfo genericTypeDef;
|
||||||
@@ -230,13 +230,13 @@ namespace Il2CppInspector.Reflection
|
|||||||
|
|
||||||
// Get the instantiation
|
// Get the instantiation
|
||||||
// TODO: Replace with array load from Il2CppMetadataRegistration.genericInsts
|
// TODO: Replace with array load from Il2CppMetadataRegistration.genericInsts
|
||||||
var genericInstance = image.ReadMappedObject<Il2CppGenericInst>(generic.Context.ClassInst);
|
var genericInstance = image.ReadMappedVersionedObject<Il2CppGenericInst>(generic.Context.ClassInst);
|
||||||
var genericArguments = ResolveGenericArguments(genericInstance);
|
var genericArguments = ResolveGenericArguments(genericInstance);
|
||||||
|
|
||||||
underlyingType = genericTypeDef.MakeGenericType(genericArguments);
|
underlyingType = genericTypeDef.MakeGenericType(genericArguments);
|
||||||
break;
|
break;
|
||||||
case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
|
case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
|
||||||
var descriptor = image.ReadMappedObject<Il2CppArrayType>(typeRef.Data.ArrayType);
|
var descriptor = image.ReadMappedVersionedObject<Il2CppArrayType>(typeRef.Data.ArrayType);
|
||||||
var elementType = GetTypeFromVirtualAddress(descriptor.ElementType);
|
var elementType = GetTypeFromVirtualAddress(descriptor.ElementType);
|
||||||
underlyingType = elementType.MakeArrayType(descriptor.Rank);
|
underlyingType = elementType.MakeArrayType(descriptor.Rank);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using NoisyCowStudios.Bin2Object;
|
using NoisyCowStudios.Bin2Object;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
|
||||||
using Il2CppInspector.Next;
|
using Il2CppInspector.Next;
|
||||||
using Il2CppInspector.Next.BinaryMetadata;
|
using Il2CppInspector.Next.BinaryMetadata;
|
||||||
using Il2CppInspector.Next.Metadata;
|
using Il2CppInspector.Next.Metadata;
|
||||||
@@ -11,7 +9,7 @@ namespace Il2CppInspector.Utils;
|
|||||||
|
|
||||||
public static class BlobReader
|
public static class BlobReader
|
||||||
{
|
{
|
||||||
public static object GetConstantValueFromBlob(Il2CppInspector inspector, Il2CppTypeEnum type, BinaryObjectStream blob)
|
public static object GetConstantValueFromBlob(Il2CppInspector inspector, Il2CppTypeEnum type, BinaryObjectStreamReader blob)
|
||||||
{
|
{
|
||||||
const byte kArrayTypeWithDifferentElements = 1;
|
const byte kArrayTypeWithDifferentElements = 1;
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ public static class BlobReader
|
|||||||
break;
|
break;
|
||||||
case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
|
case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
|
||||||
// UTF-8 character assumed
|
// UTF-8 character assumed
|
||||||
value = BitConverter.ToChar(blob.ReadBytes(2), 0);
|
value = (char)blob.ReadPrimitive<short>();
|
||||||
break;
|
break;
|
||||||
case Il2CppTypeEnum.IL2CPP_TYPE_U2:
|
case Il2CppTypeEnum.IL2CPP_TYPE_U2:
|
||||||
value = blob.ReadUInt16();
|
value = blob.ReadUInt16();
|
||||||
@@ -162,7 +160,7 @@ public static class BlobReader
|
|||||||
if (typeEnum == Il2CppTypeEnum.IL2CPP_TYPE_ENUM)
|
if (typeEnum == Il2CppTypeEnum.IL2CPP_TYPE_ENUM)
|
||||||
{
|
{
|
||||||
var typeIndex = blob.ReadCompressedInt32();
|
var typeIndex = blob.ReadCompressedInt32();
|
||||||
var typeHandle = (uint)inspector.TypeReferences[typeIndex].Data.KlassIndex;
|
var typeHandle = inspector.TypeReferences[typeIndex].Data.KlassIndex;
|
||||||
enumType = inspector.TypeDefinitions[typeHandle];
|
enumType = inspector.TypeDefinitions[typeHandle];
|
||||||
|
|
||||||
var elementTypeHandle = inspector.TypeReferences[enumType.ElementTypeIndex].Data.KlassIndex;
|
var elementTypeHandle = inspector.TypeReferences[enumType.ElementTypeIndex].Data.KlassIndex;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using VersionedSerialization.Generator.Utils;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
|
using VersionedSerialization.Generator.Utils;
|
||||||
|
|
||||||
namespace VersionedSerialization.Generator.Models;
|
namespace VersionedSerialization.Generator.Models;
|
||||||
|
|
||||||
@@ -6,8 +7,7 @@ public sealed record ObjectSerializationInfo(
|
|||||||
string Namespace,
|
string Namespace,
|
||||||
string Name,
|
string Name,
|
||||||
bool HasBaseType,
|
bool HasBaseType,
|
||||||
bool IsStruct,
|
SyntaxKind DefinitionType,
|
||||||
bool ShouldGenerateSizeMethod,
|
|
||||||
bool CanGenerateSizeMethod,
|
bool CanGenerateSizeMethod,
|
||||||
ImmutableEquatableArray<PropertySerializationInfo> Properties
|
ImmutableEquatableArray<PropertySerializationInfo> Properties
|
||||||
);
|
);
|
||||||
@@ -6,6 +6,6 @@ public sealed record PropertySerializationInfo(
|
|||||||
string Name,
|
string Name,
|
||||||
string ReadMethod,
|
string ReadMethod,
|
||||||
string SizeExpression,
|
string SizeExpression,
|
||||||
int Alignment,
|
PropertyType Type,
|
||||||
ImmutableEquatableArray<VersionCondition> VersionConditions
|
ImmutableEquatableArray<VersionCondition> VersionConditions
|
||||||
);
|
);
|
||||||
@@ -16,6 +16,9 @@ public enum PropertyType
|
|||||||
Int32,
|
Int32,
|
||||||
Int64,
|
Int64,
|
||||||
String,
|
String,
|
||||||
|
Custom,
|
||||||
|
NativeInteger,
|
||||||
|
UNativeInteger,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PropertyTypeExtensions
|
public static class PropertyTypeExtensions
|
||||||
@@ -35,6 +38,9 @@ public static class PropertyTypeExtensions
|
|||||||
PropertyType.Int32 => nameof(PropertyType.Int32),
|
PropertyType.Int32 => nameof(PropertyType.Int32),
|
||||||
PropertyType.Int64 => nameof(PropertyType.Int64),
|
PropertyType.Int64 => nameof(PropertyType.Int64),
|
||||||
PropertyType.String => nameof(String),
|
PropertyType.String => nameof(String),
|
||||||
|
PropertyType.Custom => "",
|
||||||
|
PropertyType.NativeInteger => "NInt",
|
||||||
|
PropertyType.UNativeInteger => "NUInt",
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,6 +49,40 @@ public static class PropertyTypeExtensions
|
|||||||
{
|
{
|
||||||
PropertyType.Boolean => true,
|
PropertyType.Boolean => true,
|
||||||
PropertyType.String => true,
|
PropertyType.String => true,
|
||||||
|
PropertyType.Custom => true,
|
||||||
|
PropertyType.NativeInteger => true,
|
||||||
|
PropertyType.UNativeInteger => true,
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
|
||||||
|
public static int GetTypeSize(this PropertyType type)
|
||||||
|
=> type switch
|
||||||
|
{
|
||||||
|
PropertyType.Unsupported => -1,
|
||||||
|
PropertyType.None => 0,
|
||||||
|
PropertyType.UInt8 => 1,
|
||||||
|
PropertyType.Int8 => 1,
|
||||||
|
PropertyType.Boolean => 1,
|
||||||
|
PropertyType.UInt16 => 2,
|
||||||
|
PropertyType.UInt32 => 4,
|
||||||
|
PropertyType.UInt64 => 8,
|
||||||
|
PropertyType.Int16 => 2,
|
||||||
|
PropertyType.Int32 => 4,
|
||||||
|
PropertyType.Int64 => 8,
|
||||||
|
PropertyType.String => -1,
|
||||||
|
PropertyType.Custom => -1,
|
||||||
|
PropertyType.NativeInteger => -1,
|
||||||
|
PropertyType.UNativeInteger => -1,
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool IsUnsignedType(this PropertyType type)
|
||||||
|
=> type switch
|
||||||
|
{
|
||||||
|
PropertyType.UInt8
|
||||||
|
or PropertyType.UInt16
|
||||||
|
or PropertyType.UInt32
|
||||||
|
or PropertyType.UInt64 => true,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
@@ -20,7 +19,7 @@ namespace VersionedSerialization.Generator
|
|||||||
|
|
||||||
var valueProvider = context.SyntaxProvider
|
var valueProvider = context.SyntaxProvider
|
||||||
.ForAttributeWithMetadataName(Constants.VersionedStructAttribute,
|
.ForAttributeWithMetadataName(Constants.VersionedStructAttribute,
|
||||||
static (node, _) => node is ClassDeclarationSyntax or StructDeclarationSyntax,
|
static (node, _) => node is ClassDeclarationSyntax or StructDeclarationSyntax or RecordDeclarationSyntax,
|
||||||
static (context, _) => (ContextClass: (TypeDeclarationSyntax)context.TargetNode, context.SemanticModel))
|
static (context, _) => (ContextClass: (TypeDeclarationSyntax)context.TargetNode, context.SemanticModel))
|
||||||
.Combine(context.CompilationProvider)
|
.Combine(context.CompilationProvider)
|
||||||
.Select(static (tuple, cancellationToken) => ParseSerializationInfo(tuple.Left.ContextClass, tuple.Left.SemanticModel, tuple.Right, cancellationToken))
|
.Select(static (tuple, cancellationToken) => ParseSerializationInfo(tuple.Left.ContextClass, tuple.Left.SemanticModel, tuple.Right, cancellationToken))
|
||||||
@@ -63,7 +62,16 @@ namespace VersionedSerialization.Generator
|
|||||||
generator.LeaveScope();
|
generator.LeaveScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.EnterScope($"public partial {(info.IsStruct ? "struct" : "class")} {info.Name} : IReadable");
|
var definitionType = info.DefinitionType switch
|
||||||
|
{
|
||||||
|
SyntaxKind.ClassDeclaration => "class",
|
||||||
|
SyntaxKind.StructDeclaration => "struct",
|
||||||
|
SyntaxKind.RecordDeclaration => "record",
|
||||||
|
SyntaxKind.RecordStructDeclaration => "record struct",
|
||||||
|
_ => throw new IndexOutOfRangeException()
|
||||||
|
};
|
||||||
|
|
||||||
|
generator.EnterScope($"public partial {definitionType} {info.Name} : IReadable");
|
||||||
GenerateReadMethod(generator, info);
|
GenerateReadMethod(generator, info);
|
||||||
generator.AppendLine();
|
generator.AppendLine();
|
||||||
GenerateSizeMethod(generator, info);
|
GenerateSizeMethod(generator, info);
|
||||||
@@ -92,12 +100,7 @@ namespace VersionedSerialization.Generator
|
|||||||
GenerateVersionCondition(property.VersionConditions, generator);
|
GenerateVersionCondition(property.VersionConditions, generator);
|
||||||
|
|
||||||
generator.EnterScope();
|
generator.EnterScope();
|
||||||
|
|
||||||
generator.AppendLine($"size += {property.SizeExpression};");
|
generator.AppendLine($"size += {property.SizeExpression};");
|
||||||
|
|
||||||
if (property.Alignment != 0)
|
|
||||||
generator.AppendLine($"size += size % {property.Alignment} == 0 ? 0 : {property.Alignment} - (size % {property.Alignment});");
|
|
||||||
|
|
||||||
generator.LeaveScope();
|
generator.LeaveScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,10 +124,6 @@ namespace VersionedSerialization.Generator
|
|||||||
|
|
||||||
generator.EnterScope();
|
generator.EnterScope();
|
||||||
generator.AppendLine($"this.{property.Name} = {property.ReadMethod}");
|
generator.AppendLine($"this.{property.Name} = {property.ReadMethod}");
|
||||||
|
|
||||||
if (property.Alignment != 0)
|
|
||||||
generator.AppendLine($"reader.Align({property.Alignment});");
|
|
||||||
|
|
||||||
generator.LeaveScope();
|
generator.LeaveScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,9 +175,10 @@ namespace VersionedSerialization.Generator
|
|||||||
{
|
{
|
||||||
var classSymbol = model.GetDeclaredSymbol(contextClass, cancellationToken) ?? throw new InvalidOperationException();
|
var classSymbol = model.GetDeclaredSymbol(contextClass, cancellationToken) ?? throw new InvalidOperationException();
|
||||||
|
|
||||||
var alignedAttribute = compilation.GetTypeByMetadataName(Constants.AlignedAttribute);
|
//var versionedStructAttribute = compilation.GetTypeByMetadataName(Constants.VersionedStructAttribute);
|
||||||
var versionConditionAttribute = compilation.GetTypeByMetadataName(Constants.VersionConditionAttribute);
|
var versionConditionAttribute = compilation.GetTypeByMetadataName(Constants.VersionConditionAttribute);
|
||||||
var customSerializationAttribute = compilation.GetTypeByMetadataName(Constants.CustomSerializationAttribute);
|
var customSerializationAttribute = compilation.GetTypeByMetadataName(Constants.CustomSerializationAttribute);
|
||||||
|
var nativeIntegerAttribute = compilation.GetTypeByMetadataName(Constants.NativeIntegerAttribute);
|
||||||
|
|
||||||
var canGenerateSizeMethod = true;
|
var canGenerateSizeMethod = true;
|
||||||
|
|
||||||
@@ -190,7 +190,6 @@ namespace VersionedSerialization.Generator
|
|||||||
|| member is IPropertySymbol { SetMethod: null })
|
|| member is IPropertySymbol { SetMethod: null })
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var alignment = 0;
|
|
||||||
var versionConditions = new List<VersionCondition>();
|
var versionConditions = new List<VersionCondition>();
|
||||||
|
|
||||||
ITypeSymbol type;
|
ITypeSymbol type;
|
||||||
@@ -207,41 +206,12 @@ namespace VersionedSerialization.Generator
|
|||||||
}
|
}
|
||||||
|
|
||||||
var typeInfo = ParseType(type);
|
var typeInfo = ParseType(type);
|
||||||
|
string? readMethod = null;
|
||||||
canGenerateSizeMethod &= typeInfo.Type != PropertyType.String;
|
string? sizeExpression = null;
|
||||||
|
|
||||||
string readMethod;
|
|
||||||
if (typeInfo.Type == PropertyType.None)
|
|
||||||
{
|
|
||||||
readMethod = $"reader.ReadVersionedObject<{typeInfo.ComplexTypeName}>(in version);";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
readMethod = typeInfo.Type.IsSeperateMethod()
|
|
||||||
? $"reader.Read{typeInfo.Type.GetTypeName()}();"
|
|
||||||
: $"reader.ReadPrimitive<{typeInfo.Type.GetTypeName()}>();";
|
|
||||||
|
|
||||||
if (typeInfo.ComplexTypeName != "")
|
|
||||||
readMethod = $"({typeInfo.ComplexTypeName}){readMethod}";
|
|
||||||
}
|
|
||||||
|
|
||||||
string sizeExpression;
|
|
||||||
if (typeInfo.Type == PropertyType.None)
|
|
||||||
{
|
|
||||||
sizeExpression = $"{typeInfo.ComplexTypeName}.Size(in version, is32Bit)";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sizeExpression = $"sizeof({typeInfo.Type.GetTypeName()})";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var attribute in member.GetAttributes())
|
foreach (var attribute in member.GetAttributes())
|
||||||
{
|
{
|
||||||
if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, alignedAttribute))
|
if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, versionConditionAttribute))
|
||||||
{
|
|
||||||
alignment = (int)attribute.ConstructorArguments[0].Value!;
|
|
||||||
}
|
|
||||||
else if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, versionConditionAttribute))
|
|
||||||
{
|
{
|
||||||
StructVersion? lessThan = null,
|
StructVersion? lessThan = null,
|
||||||
moreThan = null,
|
moreThan = null,
|
||||||
@@ -278,16 +248,54 @@ namespace VersionedSerialization.Generator
|
|||||||
}
|
}
|
||||||
else if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, customSerializationAttribute))
|
else if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, customSerializationAttribute))
|
||||||
{
|
{
|
||||||
|
typeInfo = (PropertyType.Custom, "", typeInfo.IsArray);
|
||||||
readMethod = (string)attribute.ConstructorArguments[0].Value!;
|
readMethod = (string)attribute.ConstructorArguments[0].Value!;
|
||||||
sizeExpression = (string)attribute.ConstructorArguments[1].Value!;
|
sizeExpression = (string)attribute.ConstructorArguments[1].Value!;
|
||||||
}
|
}
|
||||||
|
else if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, nativeIntegerAttribute))
|
||||||
|
{
|
||||||
|
typeInfo = (typeInfo.Type.IsUnsignedType()
|
||||||
|
? PropertyType.UNativeInteger
|
||||||
|
: PropertyType.NativeInteger,
|
||||||
|
typeInfo.ComplexTypeName == ""
|
||||||
|
? typeInfo.Type.GetTypeName()
|
||||||
|
: typeInfo.ComplexTypeName,
|
||||||
|
typeInfo.IsArray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canGenerateSizeMethod &= typeInfo.Type != PropertyType.String;
|
||||||
|
|
||||||
|
if (readMethod == null)
|
||||||
|
{
|
||||||
|
if (typeInfo.Type == PropertyType.None)
|
||||||
|
{
|
||||||
|
readMethod = $"reader.ReadVersionedObject<{typeInfo.ComplexTypeName}>(in version);";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
readMethod = typeInfo.Type.IsSeperateMethod()
|
||||||
|
? $"reader.Read{typeInfo.Type.GetTypeName()}();"
|
||||||
|
: $"reader.ReadPrimitive<{typeInfo.Type.GetTypeName()}>();";
|
||||||
|
|
||||||
|
if (typeInfo.ComplexTypeName != "")
|
||||||
|
readMethod = $"({typeInfo.ComplexTypeName}){readMethod}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sizeExpression ??= typeInfo.Type switch
|
||||||
|
{
|
||||||
|
PropertyType.None => $"{typeInfo.ComplexTypeName}.Size(in version, is32Bit)",
|
||||||
|
PropertyType.NativeInteger or PropertyType.UNativeInteger =>
|
||||||
|
"is32Bit ? sizeof(uint) : sizeof(ulong)",
|
||||||
|
_ => $"sizeof({typeInfo.Type.GetTypeName()})"
|
||||||
|
};
|
||||||
|
|
||||||
properties.Add(new PropertySerializationInfo(
|
properties.Add(new PropertySerializationInfo(
|
||||||
member.Name,
|
member.Name,
|
||||||
readMethod,
|
readMethod,
|
||||||
sizeExpression,
|
sizeExpression,
|
||||||
alignment,
|
typeInfo.Type,
|
||||||
versionConditions.ToImmutableEquatableArray()
|
versionConditions.ToImmutableEquatableArray()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -307,8 +315,7 @@ namespace VersionedSerialization.Generator
|
|||||||
classSymbol.ContainingNamespace.ToDisplayString(),
|
classSymbol.ContainingNamespace.ToDisplayString(),
|
||||||
classSymbol.Name,
|
classSymbol.Name,
|
||||||
hasBaseType,
|
hasBaseType,
|
||||||
contextClass.Kind() == SyntaxKind.StructDeclaration,
|
contextClass.Kind(),
|
||||||
true,
|
|
||||||
canGenerateSizeMethod,
|
canGenerateSizeMethod,
|
||||||
properties.ToImmutableEquatableArray()
|
properties.ToImmutableEquatableArray()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ public static class Constants
|
|||||||
private const string AttributeNamespace = "VersionedSerialization.Attributes";
|
private const string AttributeNamespace = "VersionedSerialization.Attributes";
|
||||||
|
|
||||||
public const string VersionedStructAttribute = $"{AttributeNamespace}.{nameof(VersionedStructAttribute)}";
|
public const string VersionedStructAttribute = $"{AttributeNamespace}.{nameof(VersionedStructAttribute)}";
|
||||||
public const string AlignedAttribute = $"{AttributeNamespace}.{nameof(AlignedAttribute)}";
|
|
||||||
public const string VersionConditionAttribute = $"{AttributeNamespace}.{nameof(VersionConditionAttribute)}";
|
public const string VersionConditionAttribute = $"{AttributeNamespace}.{nameof(VersionConditionAttribute)}";
|
||||||
public const string CustomSerializationAttribute = $"{AttributeNamespace}.{nameof(CustomSerializationAttribute)}";
|
public const string CustomSerializationAttribute = $"{AttributeNamespace}.{nameof(CustomSerializationAttribute)}";
|
||||||
|
public const string NativeIntegerAttribute = $"{AttributeNamespace}.{nameof(NativeIntegerAttribute)}";
|
||||||
|
|
||||||
public const string LessThan = nameof(LessThan);
|
public const string LessThan = nameof(LessThan);
|
||||||
public const string GreaterThan = nameof(GreaterThan);
|
public const string GreaterThan = nameof(GreaterThan);
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace VersionedSerialization.Attributes;
|
|
||||||
|
|
||||||
#pragma warning disable CS9113 // Parameter is unread.
|
|
||||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
|
|
||||||
public class AlignedAttribute(int alignment) : Attribute;
|
|
||||||
#pragma warning restore CS9113 // Parameter is unread.
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace VersionedSerialization.Attributes;
|
||||||
|
|
||||||
|
public class NativeIntegerAttribute : Attribute;
|
||||||
@@ -18,5 +18,6 @@ public interface IReader
|
|||||||
T ReadVersionedObject<T>(in StructVersion version = default) where T : IReadable, new();
|
T ReadVersionedObject<T>(in StructVersion version = default) where T : IReadable, new();
|
||||||
ImmutableArray<T> ReadVersionedObjectArray<T>(long count, in StructVersion version = default) where T : IReadable, new();
|
ImmutableArray<T> ReadVersionedObjectArray<T>(long count, in StructVersion version = default) where T : IReadable, new();
|
||||||
|
|
||||||
public void Align(int alignment = 0);
|
void Align(int alignment = 0);
|
||||||
|
void Skip(int count);
|
||||||
}
|
}
|
||||||
@@ -143,4 +143,9 @@ public ref struct SpanReader(ReadOnlySpan<byte> data, int offset = 0, bool littl
|
|||||||
if (rem != 0)
|
if (rem != 0)
|
||||||
Offset += alignment - rem;
|
Offset += alignment - rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Skip(int count)
|
||||||
|
{
|
||||||
|
Offset += count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user