Struct reading and disassembly script overhaul, various misc. loading fixes, bump to .NET 9 (#13)
* Bump projects to .net 9 and update nugets * add VersionedSerialization + source generator * migrate versioning to StructVersion class, add handling/detection for 29.2/31.2 * add new struct definitions * rename serialization methods and add BinaryObjectStreamReader for interop * Rework metadata struct loading to use new struct versioning * move 29/31.1/.2 to use tags (-2022,-2023) instead of minor versions * fix metadata usage validity checks * rework code registration offsetting a bit and add second 29/31.1 condition * tweak .1 condition (again) * 29/31.2 was a psyop * also remove 29.2 from the readme * remove loading of packed dlls - this was a very unsafe feature * support auto-recovering type indices from type handles fixes loading of memory-dumped v29+ libraries since those replacee their class indices on load with a pointer to the corresponding type * support loading PEs without an export table * also read UnresolvedVirtualCallCount on regular v31 * Disable plugin loading for now * Overhaul disassembler script + add Binary Ninja target (#12) * Overhaul diassembler scripts: - No longer defines top level functions - Split into three classes: StatusHandler (like before), DisassemblerInterface (for interfacing with the used program API), ScriptContext (for definiting general functions that use the disassembler interface) - Add type annotations to all class methods and remove 2.7 compatibility stuff (Ghidra now supports Python 3 so this is unnecessary anymore) - Disassembler backends are now responsible for launching metadata/script processing, to better support disassembler differences - String handling is back in the base ScriptContext class, disassembler interfaces opt into the fake string segment creation and fall back to the old method if it isn't supported * Add Binary Ninja disassembler script backend This uses the new backend-controlled execution to launch metadata processing on a background thread to keep the ui responsive * make binary ninja script use own _BINARYNINJA_ define and add define helpers to header * Update README to account for new script and binary ninja backend * implement fake string segment functions for binary ninja but don't advertise support * also cache API function types in binary ninja backend * fix ida script and disable folders again * Fix metadata usage issues caused by it being a value type now * make TryMapVATR overrideable and implement it for ELFs * Make field offset reading use TryMapVATR to reduce exceptions * Fix NRE in Assembly ctor on < v24.2 * Update actions workflow to produce cross-platform CLI binaries, update readme to reflect .net 9 changes * workflow: only restore packages for projects that are being built * workflow: tweak caching and fix gui compilation * workflow: remove double .zip in CLI artifact name * 29/31.2 don't actually exist, this logic is not needed
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppArrayType
|
||||
{
|
||||
public Pointer<Il2CppType> ElementType;
|
||||
public byte Rank;
|
||||
public byte NumSizes;
|
||||
public byte NumLowerBound;
|
||||
|
||||
public PrimitivePointer<int> Sizes;
|
||||
public PrimitivePointer<int> LoBounds;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppCodeGenModule
|
||||
{
|
||||
public PrimitivePointer<byte> ModuleName; // const char*
|
||||
|
||||
[NativeInteger]
|
||||
public uint MethodPointerCount;
|
||||
|
||||
public Pointer<Il2CppMethodPointer> MethodPointers;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(EqualTo = "24.5")]
|
||||
[VersionCondition(GreaterThan = "27.1")]
|
||||
public uint AdjustorThunksCount;
|
||||
|
||||
[VersionCondition(EqualTo = "24.5")]
|
||||
[VersionCondition(GreaterThan = "27.1")]
|
||||
public Pointer<Il2CppTokenAdjustorThunkPair> AdjustorThunks;
|
||||
|
||||
public PrimitivePointer<int> InvokerIndices; // int*
|
||||
|
||||
[NativeInteger]
|
||||
public uint ReversePInvokeWrapperCount;
|
||||
|
||||
public Pointer<Il2CppTokenIndexMethodTuple> ReversePInvokeWrapperIndices;
|
||||
|
||||
[NativeInteger]
|
||||
public uint RgctxRangesCount;
|
||||
public Pointer<Il2CppTokenRangePair> RgctxRanges;
|
||||
|
||||
[NativeInteger]
|
||||
public uint RgctxsCount;
|
||||
public Pointer<Il2CppRgctxDefinition> Rgctxs;
|
||||
|
||||
public PrimitivePointer<byte> DebuggerMetadata; // Pointer<Il2CppDebuggerMetadataRegistration> DebuggerMetadata;
|
||||
|
||||
[VersionCondition(GreaterThan = "27.0", LessThan = "27.2")]
|
||||
public Pointer<Il2CppMethodPointer> CustomAttributeCacheGenerator;
|
||||
|
||||
[VersionCondition(GreaterThan = "27.0")]
|
||||
public Il2CppMethodPointer ModuleInitializer;
|
||||
|
||||
[VersionCondition(GreaterThan = "27.0")]
|
||||
public PrimitivePointer<int> StaticConstructorTypeIndices; // TypeDefinitionIndex*
|
||||
|
||||
[VersionCondition(GreaterThan = "27.0")]
|
||||
public PrimitivePointer<byte> MetadataRegistration; // Pointer<Il2CppMetadataRegistration>
|
||||
|
||||
[VersionCondition(GreaterThan = "27.0")]
|
||||
public PrimitivePointer<byte> CodeRegistration; // Pointer<Il2CppCodeRegistration>
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using InvokerMethod = Il2CppMethodPointer;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppCodeRegistration
|
||||
{
|
||||
[NativeInteger]
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public uint MethodPointersCount;
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public Pointer<Il2CppMethodPointer> MethodPointers;
|
||||
|
||||
[NativeInteger]
|
||||
public uint ReversePInvokeWrapperCount;
|
||||
|
||||
public Pointer<Il2CppMethodPointer> ReversePInvokeWrappers;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(LessThan = "22.0")]
|
||||
public uint DelegateWrappersFromManagedToNativeCount;
|
||||
|
||||
[VersionCondition(LessThan = "22.0")]
|
||||
public Pointer<Il2CppMethodPointer> DelegateWrappersFromManagedToNative;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(LessThan = "22.0")]
|
||||
public uint MarshalingFunctionsCount;
|
||||
|
||||
[VersionCondition(LessThan = "22.0")]
|
||||
public Pointer<Il2CppMethodPointer> MarshalingFunctions;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||
public uint CcwMarshalingFunctionsCount;
|
||||
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||
public Pointer<Il2CppMethodPointer> CcwMarshalingFunctions;
|
||||
|
||||
[NativeInteger]
|
||||
public uint GenericMethodPointersCount;
|
||||
|
||||
public Pointer<Il2CppMethodPointer> GenericMethodPointers;
|
||||
|
||||
[VersionCondition(EqualTo = "24.5")]
|
||||
[VersionCondition(GreaterThan = "27.1")]
|
||||
public Pointer<Il2CppMethodPointer> GenericAdjustorThunks;
|
||||
|
||||
[NativeInteger]
|
||||
public uint InvokerPointersCount;
|
||||
|
||||
public Pointer<InvokerMethod> InvokerPointers;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(LessThan = "24.5")]
|
||||
public int CustomAttributeCount;
|
||||
|
||||
[VersionCondition(LessThan = "24.5")]
|
||||
public Pointer<Il2CppMethodPointer> CustomAttributeGenerators;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||
public int GuidCount;
|
||||
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||
public Pointer<Il2CppGuid> Guids;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(GreaterThan = "22.0", LessThan = "27.2")]
|
||||
[VersionCondition(EqualTo = "29.0", IncludingTag = "")]
|
||||
[VersionCondition(EqualTo = "31.0", IncludingTag = "")]
|
||||
public int UnresolvedVirtualCallCount;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(EqualTo = "29.0", IncludingTag = "2022"), VersionCondition(EqualTo = "31.0", IncludingTag = "2022")]
|
||||
[VersionCondition(EqualTo = "29.0", IncludingTag = "2023"), VersionCondition(EqualTo = "31.0", IncludingTag = "2023")]
|
||||
public uint UnresolvedIndirectCallCount; // UnresolvedVirtualCallCount pre 29.1
|
||||
|
||||
[VersionCondition(GreaterThan = "22.0")]
|
||||
public Pointer<Il2CppMethodPointer> UnresolvedVirtualCallPointers;
|
||||
|
||||
[VersionCondition(EqualTo = "29.0", IncludingTag = "2022"), VersionCondition(EqualTo = "31.0", IncludingTag = "2022")]
|
||||
[VersionCondition(EqualTo = "29.0", IncludingTag = "2023"), VersionCondition(EqualTo = "31.0", IncludingTag = "2023")]
|
||||
public Pointer<Il2CppMethodPointer> UnresolvedInstanceCallWrappers;
|
||||
|
||||
[VersionCondition(EqualTo = "29.0", IncludingTag = "2022"), VersionCondition(EqualTo = "31.0", IncludingTag = "2022")]
|
||||
[VersionCondition(EqualTo = "29.0", IncludingTag = "2023"), VersionCondition(EqualTo = "31.0", IncludingTag = "2023")]
|
||||
public Pointer<Il2CppMethodPointer> UnresolvedStaticCallPointers;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(GreaterThan = "23.0")]
|
||||
public uint InteropDataCount;
|
||||
|
||||
[VersionCondition(GreaterThan = "23.0")]
|
||||
public Pointer<Il2CppInteropData> InteropData;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(GreaterThan = "24.3")]
|
||||
public uint WindowsRuntimeFactoryCount;
|
||||
|
||||
[VersionCondition(GreaterThan = "24.3")]
|
||||
public Pointer<Il2CppWindowsRuntimeFactoryTableEntry> WindowsRuntimeFactoryTable;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(GreaterThan = "24.2")]
|
||||
public uint CodeGenModulesCount;
|
||||
|
||||
[VersionCondition(GreaterThan = "24.2")]
|
||||
public Pointer<Pointer<Il2CppCodeGenModule>> CodeGenModules;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppGenericClass
|
||||
{
|
||||
[NativeInteger]
|
||||
[VersionCondition(LessThan = "24.5")]
|
||||
public int TypeDefinitionIndex;
|
||||
|
||||
[VersionCondition(GreaterThan = "27.0")]
|
||||
public Pointer<Il2CppType> Type;
|
||||
|
||||
public Il2CppGenericContext Context;
|
||||
|
||||
public PrimitivePointer<byte> CachedClass; // Il2CppClass*, optional
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppGenericContext
|
||||
{
|
||||
public Pointer<Il2CppGenericInst> ClassInst;
|
||||
public Pointer<Il2CppGenericInst> MethodInst;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppGenericInst
|
||||
{
|
||||
public readonly bool Valid => TypeArgc > 0;
|
||||
|
||||
[NativeInteger]
|
||||
public uint TypeArgc;
|
||||
|
||||
public Pointer<Pointer<Il2CppType>> TypeArgv;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using GenericMethodIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppGenericMethodFunctionsDefinitions
|
||||
{
|
||||
public GenericMethodIndex GenericMethodIndex;
|
||||
public Il2CppGenericMethodIndices Indices;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using MethodIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppGenericMethodIndices
|
||||
{
|
||||
public MethodIndex MethodIndex;
|
||||
public MethodIndex InvokerIndex;
|
||||
|
||||
[VersionCondition(EqualTo = "24.5")]
|
||||
[VersionCondition(GreaterThan = "27.1")]
|
||||
public MethodIndex AdjustorThunkIndex;
|
||||
}
|
||||
21
Il2CppInspector.Common/Next/BinaryMetadata/Il2CppGuid.cs
Normal file
21
Il2CppInspector.Common/Next/BinaryMetadata/Il2CppGuid.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using VersionedSerialization;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
public record struct Il2CppGuid : IReadable
|
||||
{
|
||||
public Guid Value;
|
||||
|
||||
public void Read<TReader>(ref TReader reader, in StructVersion version = default) where TReader : IReader, allows ref struct
|
||||
{
|
||||
var guid = reader.ReadBytes(16);
|
||||
Value = new Guid(guid, false);
|
||||
}
|
||||
|
||||
public static int Size(in StructVersion version = default, bool is32Bit = false)
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
public static implicit operator Guid(Il2CppGuid value) => value.Value;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using PInvokeMarshalToNativeFunc = Il2CppMethodPointer;
|
||||
using PInvokeMarshalFromNativeFunc = Il2CppMethodPointer;
|
||||
using PInvokeMarshalCleanupFunc = Il2CppMethodPointer;
|
||||
using CreateCCWFunc = Il2CppMethodPointer;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppInteropData
|
||||
{
|
||||
public Il2CppMethodPointer DelegatePInvokeWrapperFunction;
|
||||
public PInvokeMarshalToNativeFunc PInvokeMarshalToNativeFunction;
|
||||
public PInvokeMarshalFromNativeFunc PInvokeMarshalFromNativeFunction;
|
||||
public PInvokeMarshalCleanupFunc PInvokeMarshalCleanupFunction;
|
||||
public CreateCCWFunc CreateCCWFunction;
|
||||
public Pointer<Il2CppGuid> Guid;
|
||||
public Pointer<Il2CppType> Type;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Il2CppInspector.Next.Metadata;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using FieldIndex = int;
|
||||
using TypeDefinitionIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppMetadataRegistration
|
||||
{
|
||||
[NativeInteger]
|
||||
public int GenericClassesCount;
|
||||
|
||||
public Pointer<Pointer<Il2CppGenericClass>> GenericClasses;
|
||||
|
||||
[NativeInteger]
|
||||
public int GenericInstsCount;
|
||||
|
||||
public Pointer<Pointer<Il2CppGenericInst>> GenericInsts;
|
||||
|
||||
[NativeInteger]
|
||||
public int GenericMethodTableCount;
|
||||
|
||||
public Pointer<Il2CppGenericMethodFunctionsDefinitions> GenericMethodTable;
|
||||
|
||||
[NativeInteger]
|
||||
public int TypesCount;
|
||||
|
||||
public Pointer<Pointer<Il2CppType>> Types;
|
||||
|
||||
[NativeInteger]
|
||||
public int MethodSpecsCount;
|
||||
|
||||
public Pointer<Il2CppMethodSpec> MethodSpecs;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(LessThan = "16.0")]
|
||||
public int MethodReferencesCount;
|
||||
|
||||
[VersionCondition(LessThan = "16.0")]
|
||||
public PrimitivePointer<PrimitivePointer<uint>> MethodReferences; // uint**
|
||||
|
||||
[NativeInteger]
|
||||
public FieldIndex FieldOffsetsCount;
|
||||
|
||||
public PrimitivePointer<PrimitivePointer<int>> FieldOffsets; // int**
|
||||
|
||||
[NativeInteger]
|
||||
public TypeDefinitionIndex TypeDefinitionsSizesCount;
|
||||
public Pointer<Pointer<Il2CppTypeDefinitionSizes>> TypeDefinitionsSizes;
|
||||
|
||||
[NativeInteger]
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public ulong MetadataUsagesCount;
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public Pointer<Pointer<Il2CppMetadataUsage>> MetadataUsages;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppMethodPointer(ulong addr = 0)
|
||||
{
|
||||
public static readonly Il2CppMethodPointer Null = new();
|
||||
|
||||
[NativeInteger]
|
||||
public ulong Value { get; set; } = addr;
|
||||
|
||||
public readonly bool IsNull => Value == 0;
|
||||
|
||||
public readonly override string ToString() => $"0x{Value:X}";
|
||||
|
||||
public static implicit operator ulong(Il2CppMethodPointer ptr) => ptr.Value;
|
||||
public static implicit operator Il2CppMethodPointer(ulong ptr) => new(ptr);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using MethodIndex = int;
|
||||
using GenericInstIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppMethodSpec
|
||||
{
|
||||
public MethodIndex MethodDefinitionIndex;
|
||||
public GenericInstIndex ClassIndexIndex;
|
||||
public GenericInstIndex MethodIndexIndex;
|
||||
}
|
||||
10
Il2CppInspector.Common/Next/BinaryMetadata/Il2CppRange.cs
Normal file
10
Il2CppInspector.Common/Next/BinaryMetadata/Il2CppRange.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppRange
|
||||
{
|
||||
public int Start;
|
||||
public int Length;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Il2CppInspector.Next.Metadata;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using TypeIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppRgctxConstrainedData
|
||||
{
|
||||
public TypeIndex TypeIndex;
|
||||
public Il2CppMetadataUsage EncodedMethodIndex;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
public enum Il2CppRgctxDataType
|
||||
{
|
||||
IL2CPP_RGCTX_DATA_INVALID,
|
||||
IL2CPP_RGCTX_DATA_TYPE,
|
||||
IL2CPP_RGCTX_DATA_CLASS,
|
||||
IL2CPP_RGCTX_DATA_METHOD,
|
||||
IL2CPP_RGCTX_DATA_ARRAY,
|
||||
IL2CPP_RGCTX_DATA_CONSTRAINED,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppRgctxDefinition
|
||||
{
|
||||
[NativeInteger]
|
||||
public Il2CppRgctxDataType Type;
|
||||
|
||||
public PrimitivePointer<byte> Data; // void*
|
||||
|
||||
public readonly Pointer<Il2CppRgctxDefinitionData> Definition => Data.PointerValue;
|
||||
public readonly Pointer<Il2CppRgctxConstrainedData> Constrained => Data.PointerValue;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using MethodIndex = int;
|
||||
using TypeIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppRgctxDefinitionData
|
||||
{
|
||||
public int Value;
|
||||
|
||||
public readonly MethodIndex MethodIndex => Value;
|
||||
public readonly TypeIndex TypeIndex => Value;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppTokenAdjustorThunkPair
|
||||
{
|
||||
[NativeInteger]
|
||||
public uint Token;
|
||||
|
||||
public Il2CppMethodPointer AdjustorThunk;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppTokenIndexMethodTuple
|
||||
{
|
||||
public uint Token;
|
||||
public int Index;
|
||||
|
||||
public PrimitivePointer<Il2CppMethodPointer> Method; // void**
|
||||
|
||||
public uint GenericMethodIndex;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppTokenRangePair
|
||||
{
|
||||
public uint Token;
|
||||
public Il2CppRange Range;
|
||||
}
|
||||
111
Il2CppInspector.Common/Next/BinaryMetadata/Il2CppType.cs
Normal file
111
Il2CppInspector.Common/Next/BinaryMetadata/Il2CppType.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using Il2CppInspector.Next.Metadata;
|
||||
using System.Reflection;
|
||||
using VersionedSerialization;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
using TypeDefinitionIndex = int;
|
||||
using GenericParameterIndex = int;
|
||||
using Il2CppMetadataTypeHandle = Pointer<Il2CppTypeDefinition>;
|
||||
using Il2CppMetadataGenericParameterHandle = Pointer<Il2CppGenericParameter>;
|
||||
|
||||
public record struct Il2CppType : IReadable
|
||||
{
|
||||
public record struct DataUnion : IReadable
|
||||
{
|
||||
public ulong Value;
|
||||
|
||||
public readonly TypeDefinitionIndex KlassIndex => (int)Value;
|
||||
public readonly Il2CppMetadataTypeHandle TypeHandle => Value;
|
||||
public readonly Pointer<Il2CppType> Type => Value;
|
||||
public readonly Pointer<Il2CppArrayType> ArrayType => Value;
|
||||
public readonly GenericParameterIndex GenericParameterIndex => (int)Value;
|
||||
public readonly Il2CppMetadataGenericParameterHandle GenericParameterHandle => Value;
|
||||
public readonly Pointer<Il2CppGenericClass> GenericClass => Value;
|
||||
|
||||
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 DataUnion Data;
|
||||
public uint Value;
|
||||
|
||||
public TypeAttributes Attrs
|
||||
{
|
||||
readonly get => (TypeAttributes)(Value & 0xFFFF);
|
||||
set => Value = (Value & 0xFFFF0000) | (uint)value;
|
||||
}
|
||||
|
||||
public Il2CppTypeEnum Type
|
||||
{
|
||||
readonly get => (Il2CppTypeEnum)((Value >> 16) & 0b11111111);
|
||||
set => Value = (Value & 0xFF00FFFF) | ((uint)value) << 16;
|
||||
}
|
||||
|
||||
public uint NumModifiers
|
||||
{
|
||||
readonly get => (Value >> 24) & 0b11111;
|
||||
set => Value = (Value & 0xE0FFFFFF) | value << 24;
|
||||
}
|
||||
|
||||
public bool ByRef
|
||||
{
|
||||
readonly get => ((Value >> 29) & 1) == 1;
|
||||
set => Value = (Value & 0xDFFFFFFF) | (value ? 1u : 0u) << 29;
|
||||
}
|
||||
|
||||
public bool Pinned
|
||||
{
|
||||
readonly get => ((Value >> 30) & 1) == 1;
|
||||
set => Value = (Value & 0xBFFFFFFF) | (value ? 1u : 0u) << 30;
|
||||
}
|
||||
|
||||
public bool ValueType
|
||||
{
|
||||
readonly get => ((Value >> 31) & 1) == 1;
|
||||
set => Value = (Value & 0x7FFFFFFF) | (value ? 1u : 0u) << 31;
|
||||
}
|
||||
|
||||
public void Read<TReader>(ref TReader reader, in StructVersion version = default) where TReader : IReader, allows ref struct
|
||||
{
|
||||
Data.Read(ref reader, version);
|
||||
Value = reader.ReadPrimitive<uint>();
|
||||
|
||||
if (MetadataVersions.V272 > version)
|
||||
{
|
||||
// Versions pre-27.2 had NumModifiers at 6 bits and no ValueType bit
|
||||
var numModifiers = (Value >> 24) & 0b111111;
|
||||
|
||||
// If NumModifiers > 31, we throw here (as the old behavior isn't implemented
|
||||
if (numModifiers > 31)
|
||||
throw new InvalidOperationException(
|
||||
"Versions pre-27.2 with a type having more than 31 modifiers are not supported yet");
|
||||
|
||||
// Else, we do some bit-juggling to convert the old value into the new format:
|
||||
Value =
|
||||
(Value & 0xFFFFFF) | // Attributes + Type
|
||||
(((Value >> 24) & 0b111111) << 24) | // 5 Bits for the modifiers
|
||||
(((Value >> 30) & 1) << 29) | // Shifted ByRef
|
||||
(((Value >> 31) & 1) << 30) | // Shifted Pinned
|
||||
0; // 0 ValueType
|
||||
}
|
||||
}
|
||||
|
||||
public static int Size(in StructVersion version = default, bool is32Bit = false)
|
||||
{
|
||||
return DataUnion.Size(version, is32Bit) + sizeof(uint);
|
||||
}
|
||||
|
||||
public static Il2CppType FromTypeEnum(Il2CppTypeEnum type)
|
||||
=> new()
|
||||
{
|
||||
Value = (uint)type << 16
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppTypeDefinitionSizes
|
||||
{
|
||||
public uint InstanceSize;
|
||||
public int NativeSize;
|
||||
public uint StaticFieldsSize;
|
||||
public uint ThreadStaticFieldsSize;
|
||||
}
|
||||
76
Il2CppInspector.Common/Next/BinaryMetadata/Il2CppTypeEnum.cs
Normal file
76
Il2CppInspector.Common/Next/BinaryMetadata/Il2CppTypeEnum.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
public enum Il2CppTypeEnum : byte
|
||||
{
|
||||
Il2CPP_TYPE_END,
|
||||
IL2CPP_TYPE_VOID,
|
||||
IL2CPP_TYPE_BOOLEAN,
|
||||
IL2CPP_TYPE_CHAR,
|
||||
IL2CPP_TYPE_I1,
|
||||
IL2CPP_TYPE_U1,
|
||||
IL2CPP_TYPE_I2,
|
||||
IL2CPP_TYPE_U2,
|
||||
IL2CPP_TYPE_I4,
|
||||
IL2CPP_TYPE_U4,
|
||||
IL2CPP_TYPE_I8,
|
||||
IL2CPP_TYPE_U8,
|
||||
IL2CPP_TYPE_R4,
|
||||
IL2CPP_TYPE_R8,
|
||||
IL2CPP_TYPE_STRING,
|
||||
IL2CPP_TYPE_PTR,
|
||||
IL2CPP_TYPE_BYREF,
|
||||
IL2CPP_TYPE_VALUETYPE,
|
||||
IL2CPP_TYPE_CLASS,
|
||||
IL2CPP_TYPE_VAR,
|
||||
IL2CPP_TYPE_ARRAY,
|
||||
IL2CPP_TYPE_GENERICINST,
|
||||
IL2CPP_TYPE_TYPEDBYREF,
|
||||
IL2CPP_TYPE_I = 0x18,
|
||||
IL2CPP_TYPE_U,
|
||||
IL2CPP_TYPE_FNPTR = 0x1b,
|
||||
IL2CPP_TYPE_OBJECT,
|
||||
IL2CPP_TYPE_SZARRAY,
|
||||
IL2CPP_TYPE_MVAR,
|
||||
IL2CPP_TYPE_CMOD_REQD,
|
||||
IL2CPP_TYPE_CMOD_OPT,
|
||||
IL2CPP_TYPE_INTERNAL,
|
||||
|
||||
IL2CPP_TYPE_MODIFIER = 0x40,
|
||||
IL2CPP_TYPE_SENTINEL = 0x41,
|
||||
IL2CPP_TYPE_PINNED = 0x45,
|
||||
|
||||
IL2CPP_TYPE_ENUM = 0x55,
|
||||
IL2CPP_TYPE_IL2CPP_TYPE_INDEX = 0xff
|
||||
}
|
||||
|
||||
public static class Il2CppTypeEnumExtensions
|
||||
{
|
||||
public static bool IsTypeDefinitionEnum(this Il2CppTypeEnum value)
|
||||
=> value
|
||||
is Il2CppTypeEnum.IL2CPP_TYPE_VOID
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_CHAR
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_I1
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_U1
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_I2
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_U2
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_I4
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_U4
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_I8
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_U8
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_R4
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_R8
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_STRING
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_CLASS
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_I
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_U
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_OBJECT
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF;
|
||||
|
||||
public static bool IsGenericParameterEnum(this Il2CppTypeEnum value)
|
||||
=> value
|
||||
is Il2CppTypeEnum.IL2CPP_TYPE_VAR
|
||||
or Il2CppTypeEnum.IL2CPP_TYPE_MVAR;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.BinaryMetadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppWindowsRuntimeFactoryTableEntry
|
||||
{
|
||||
public Pointer<Il2CppType> Type;
|
||||
public Il2CppMethodPointer CreateFactoryFunction;
|
||||
}
|
||||
147
Il2CppInspector.Common/Next/BinaryObjectStreamReader.cs
Normal file
147
Il2CppInspector.Common/Next/BinaryObjectStreamReader.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using NoisyCowStudios.Bin2Object;
|
||||
using VersionedSerialization;
|
||||
|
||||
namespace Il2CppInspector.Next;
|
||||
|
||||
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 bool Is32Bit => Bits == 32;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static TTo Cast<TFrom, TTo>(in TFrom from) => Unsafe.As<TFrom, TTo>(ref Unsafe.AsRef(in from));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private T ReadInternal<T>() where T : unmanaged
|
||||
{
|
||||
var size = Unsafe.SizeOf<T>();
|
||||
var value = MemoryMarshal.Read<T>(ReadBytes(size));
|
||||
return value;
|
||||
}
|
||||
|
||||
public T ReadPrimitive<T>() where T : unmanaged
|
||||
{
|
||||
if (typeof(T) == typeof(sbyte))
|
||||
return Cast<byte, T>(ReadByte());
|
||||
|
||||
if (typeof(T) == typeof(short))
|
||||
return Cast<short, T>(ReadInt16());
|
||||
|
||||
if (typeof(T) == typeof(int))
|
||||
return Cast<int, T>(ReadInt32());
|
||||
|
||||
if (typeof(T) == typeof(long))
|
||||
return Cast<long, T>(ReadInt64());
|
||||
|
||||
if (typeof(T) == typeof(byte))
|
||||
return Cast<byte, T>(ReadByte());
|
||||
|
||||
if (typeof(T) == typeof(ushort))
|
||||
return Cast<ushort, T>(ReadUInt16());
|
||||
|
||||
if (typeof(T) == typeof(uint))
|
||||
return Cast<uint, T>(ReadUInt32());
|
||||
|
||||
if (typeof(T) == typeof(ulong))
|
||||
return Cast<ulong, T>(ReadUInt64());
|
||||
|
||||
return ReadInternal<T>();
|
||||
}
|
||||
|
||||
public ImmutableArray<T> ReadPrimitiveArray<T>(long count) where T : unmanaged
|
||||
{
|
||||
var array = ImmutableArray.CreateBuilder<T>(checked((int)count));
|
||||
for (long i = 0; i < count; i++)
|
||||
array.Add(ReadPrimitive<T>());
|
||||
|
||||
return array.MoveToImmutable();
|
||||
}
|
||||
|
||||
public T ReadVersionedObject<T>() where T : IReadable, new() => ReadVersionedObject<T>(Version);
|
||||
|
||||
public T ReadVersionedObject<T>(in StructVersion version = default) where T : IReadable, new()
|
||||
{
|
||||
var obj = new T();
|
||||
var a = this;
|
||||
obj.Read(ref a, in version);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public ImmutableArray<T> ReadVersionedObjectArray<T>(long count) where T : IReadable, new() => ReadVersionedObjectArray<T>(count, Version);
|
||||
|
||||
public ImmutableArray<T> ReadVersionedObjectArray<T>(long count, in StructVersion version = default) where T : IReadable, new()
|
||||
{
|
||||
var array = ImmutableArray.CreateBuilder<T>(checked((int)count));
|
||||
for (long i = 0; i < count; i++)
|
||||
array.Add(ReadVersionedObject<T>(in version));
|
||||
|
||||
return array.MoveToImmutable();
|
||||
}
|
||||
|
||||
public long ReadNInt()
|
||||
=> Is32Bit ? ReadPrimitive<int>() : ReadPrimitive<long>();
|
||||
|
||||
public ulong ReadNUInt()
|
||||
=> Is32Bit ? ReadPrimitive<uint>() : ReadPrimitive<ulong>();
|
||||
|
||||
public string ReadString() => ReadNullTerminatedString();
|
||||
|
||||
public new ReadOnlySpan<byte> ReadBytes(int length)
|
||||
{
|
||||
return base.ReadBytes(length);
|
||||
}
|
||||
|
||||
public void Align(int alignment = 0)
|
||||
{
|
||||
if (alignment == 0)
|
||||
alignment = Is32Bit ? 4 : 8;
|
||||
|
||||
var rem = Position % alignment;
|
||||
if (rem != 0)
|
||||
Position += alignment - rem;
|
||||
}
|
||||
|
||||
public TType ReadPrimitive<TType>(long addr) where TType : unmanaged
|
||||
{
|
||||
Position = addr;
|
||||
return ReadPrimitive<TType>();
|
||||
}
|
||||
|
||||
public ImmutableArray<TType> ReadPrimitiveArray<TType>(long addr, long count) where TType : unmanaged
|
||||
{
|
||||
Position = addr;
|
||||
return ReadPrimitiveArray<TType>(count);
|
||||
}
|
||||
|
||||
public TType ReadVersionedObject<TType>(long addr) where TType : IReadable, new()
|
||||
{
|
||||
Position = addr;
|
||||
return ReadVersionedObject<TType>(Version);
|
||||
}
|
||||
|
||||
public ImmutableArray<TType> ReadVersionedObjectArray<TType>(long addr, long count) where TType : IReadable, new()
|
||||
{
|
||||
Position = addr;
|
||||
return ReadVersionedObjectArray<TType>(count, Version);
|
||||
}
|
||||
|
||||
public void Skip(int count)
|
||||
{
|
||||
Position += count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using ImageIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public partial record struct Il2CppAssemblyDefinition
|
||||
{
|
||||
[FieldOffset(20)]
|
||||
[VersionCondition(LessThan = "15.0")]
|
||||
public Il2CppAssemblyNameDefinition LegacyAname;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public ImageIndex ImageIndex;
|
||||
|
||||
[FieldOffset(4)]
|
||||
[VersionCondition(GreaterThan = "24.1")]
|
||||
public uint Token;
|
||||
|
||||
[FieldOffset(8)]
|
||||
[VersionCondition(LessThan = "24.0")]
|
||||
public int CustomAttributeIndex;
|
||||
|
||||
[FieldOffset(12)]
|
||||
[VersionCondition(GreaterThan = "20.0")]
|
||||
public int ReferencedAssemblyStart;
|
||||
|
||||
[FieldOffset(16)]
|
||||
[VersionCondition(GreaterThan = "20.0")]
|
||||
public int ReferencedAssemblyCount;
|
||||
|
||||
[FieldOffset(20)]
|
||||
public Il2CppAssemblyNameDefinition Aname;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using StringIndex = int;
|
||||
|
||||
[InlineArray(PublicKeyLength)]
|
||||
public struct PublicKeyToken
|
||||
{
|
||||
private const int PublicKeyLength = 8;
|
||||
|
||||
private byte _value;
|
||||
}
|
||||
|
||||
[VersionedStruct]
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public partial record struct Il2CppAssemblyNameDefinition
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public StringIndex NameIndex;
|
||||
|
||||
[FieldOffset(4)]
|
||||
public StringIndex CultureIndex;
|
||||
|
||||
[FieldOffset(8)]
|
||||
[VersionCondition(LessThan = "24.3")]
|
||||
public int HashValueIndex;
|
||||
|
||||
[FieldOffset(12)]
|
||||
public StringIndex PublicKeyIndex;
|
||||
|
||||
[FieldOffset(44)]
|
||||
[VersionCondition(LessThan = "15.0")]
|
||||
[CustomSerialization("reader.ReadPrimitive<PublicKeyToken>();", "8")]
|
||||
private PublicKeyToken _legacyPublicKeyToken;
|
||||
|
||||
[FieldOffset(16)]
|
||||
public AssemblyHashAlgorithm HashAlg;
|
||||
|
||||
[FieldOffset(20)]
|
||||
public int HashLen;
|
||||
|
||||
[FieldOffset(24)]
|
||||
public AssemblyNameFlags Flags;
|
||||
|
||||
[FieldOffset(28)]
|
||||
public int Major;
|
||||
|
||||
[FieldOffset(32)]
|
||||
public int Minor;
|
||||
|
||||
[FieldOffset(36)]
|
||||
public int Build;
|
||||
|
||||
[FieldOffset(40)]
|
||||
public int Revision;
|
||||
|
||||
[FieldOffset(44)]
|
||||
[CustomSerialization("reader.ReadPrimitive<PublicKeyToken>();", "8")]
|
||||
public PublicKeyToken PublicKeyToken;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppCustomAttributeDataRange
|
||||
{
|
||||
public uint Token { get; private set; }
|
||||
public uint StartOffset { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppCustomAttributeTypeRange
|
||||
{
|
||||
[VersionCondition(GreaterThan = "24.1")]
|
||||
public uint Token { get; private set; }
|
||||
|
||||
public int Start { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using StringIndex = int;
|
||||
using TypeIndex = int;
|
||||
using MethodIndex = int;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppEventDefinition
|
||||
{
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
public TypeIndex TypeIndex { get; private set; }
|
||||
public MethodIndex Add { get; private set; }
|
||||
public MethodIndex Remove { get; private set; }
|
||||
public MethodIndex Raise { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.0")]
|
||||
public int CustomAttributeIndex { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public uint Token { get; private set; }
|
||||
|
||||
public readonly bool IsValid => NameIndex != 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using FieldIndex = int;
|
||||
using TypeIndex = int;
|
||||
using DefaultValueDataIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppFieldDefaultValue
|
||||
{
|
||||
public FieldIndex FieldIndex { get; private set; }
|
||||
public TypeIndex TypeIndex { get; private set; }
|
||||
public DefaultValueDataIndex DataIndex { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using VersionedSerialization.Attributes;
|
||||
using StringIndex = int;
|
||||
using TypeIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppFieldDefinition
|
||||
{
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
public TypeIndex TypeIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.0")]
|
||||
public int CustomAttributeIndex { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public uint Token { get; private set; }
|
||||
|
||||
public readonly bool IsValid => NameIndex != 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using VersionedSerialization.Attributes;
|
||||
using FieldIndex = int;
|
||||
using TypeIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppFieldMarshaledSize
|
||||
{
|
||||
public FieldIndex FieldIndex { get; private set; }
|
||||
public TypeIndex TypeIndex { get; private set; }
|
||||
public int MarshaledSize { get; private set; }
|
||||
}
|
||||
13
Il2CppInspector.Common/Next/Metadata/Il2CppFieldRef.cs
Normal file
13
Il2CppInspector.Common/Next/Metadata/Il2CppFieldRef.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using FieldIndex = int;
|
||||
using TypeIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppFieldRef
|
||||
{
|
||||
public TypeIndex TypeIndex { get; private set; }
|
||||
public FieldIndex FieldIndex { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using VersionedSerialization.Attributes;
|
||||
using GenericParameterIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppGenericContainer
|
||||
{
|
||||
public int OwnerIndex { get; private set; }
|
||||
public int TypeArgc { get; private set; }
|
||||
public int IsMethod { get; private set; }
|
||||
public GenericParameterIndex GenericParameterStart { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Reflection;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using GenericContainerIndex = int;
|
||||
using StringIndex = int;
|
||||
using GenericParameterConstraintIndex = short;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppGenericParameter
|
||||
{
|
||||
public GenericContainerIndex OwnerIndex { get; private set; }
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
public GenericParameterConstraintIndex ConstraintsStart { get; private set; }
|
||||
public short ConstraintsCount { get; private set; }
|
||||
public ushort Num { get; private set; }
|
||||
public ushort Flags { get; private set; }
|
||||
|
||||
public readonly GenericParameterAttributes Attributes => (GenericParameterAttributes)Flags;
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
// Unity 4.6.1p5 - first release, no global-metadata.dat
|
||||
// Unity 5.2.0f3 -> v15
|
||||
// Unity 5.3.0f4 -> v16
|
||||
// Unity 5.3.2f1 -> v19
|
||||
// Unity 5.3.3f1 -> v20
|
||||
// Unity 5.3.5f1 -> v21
|
||||
// Unity 5.5.0f3 -> v22
|
||||
// Unity 5.6.0f3 -> v23
|
||||
// Unity 2017.1.0f3 -> v24
|
||||
// Unity 2018.3.0f2 -> v24.1
|
||||
// Unity 2019.1.0f2 -> v24.2
|
||||
// Unity 2019.3.7f1 -> v24.3
|
||||
// Unity 2019.4.15f1 -> v24.4
|
||||
// Unity 2019.4.21f1 -> v24.5
|
||||
// Unity 2020.1.0f1 -> v24.3
|
||||
// Unity 2020.1.11f1 -> v24.4
|
||||
// Unity 2020.2.0f1 -> v27
|
||||
// Unity 2020.2.4f1 -> v27.1
|
||||
// Unity 2021.1.0f1 -> v27.2
|
||||
// https://unity3d.com/get-unity/download/archive
|
||||
// Metadata version is written at the end of Unity.IL2CPP.MetadataCacheWriter.WriteLibIl2CppMetadata or WriteMetadata (Unity.IL2CPP.dll)
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppGlobalMetadataHeader
|
||||
{
|
||||
public int Sanity { get; private set; }
|
||||
public int Version { get; private set; }
|
||||
public int StringLiteralOffset { get; private set; }
|
||||
public int StringLiteralSize { get; private set; }
|
||||
public int StringLiteralDataOffset { get; private set; }
|
||||
public int StringLiteralDataSize { get; private set; }
|
||||
public int StringOffset { get; private set; }
|
||||
public int StringSize { get; private set; }
|
||||
public int EventsOffset { get; private set; }
|
||||
public int EventsSize { get; private set; }
|
||||
public int PropertiesOffset { get; private set; }
|
||||
public int PropertiesSize { get; private set; }
|
||||
public int MethodsOffset { get; private set; }
|
||||
public int MethodsSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
[VersionCondition(EqualTo = "16.0")]
|
||||
public int ParameterDefaultValuesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
[VersionCondition(EqualTo = "16.0")]
|
||||
public int ParameterDefaultValuesSize { get; private set; }
|
||||
public int FieldDefaultValuesOffset { get; private set; }
|
||||
public int FieldDefaultValuesSize { get; private set; }
|
||||
public int FieldAndParameterDefaultValueDataOffset { get; private set; }
|
||||
public int FieldAndParameterDefaultValueDataSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
public int FieldMarshaledSizesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
public int FieldMarshaledSizesSize { get; private set; }
|
||||
public int ParametersOffset { get; private set; }
|
||||
public int ParametersSize { get; private set; }
|
||||
public int FieldsOffset { get; private set; }
|
||||
public int FieldsSize { get; private set; }
|
||||
public int GenericParametersOffset { get; private set; }
|
||||
public int GenericParametersSize { get; private set; }
|
||||
public int GenericParameterConstraintsOffset { get; private set; }
|
||||
public int GenericParameterConstraintsSize { get; private set; }
|
||||
public int GenericContainersOffset { get; private set; }
|
||||
public int GenericContainersSize { get; private set; }
|
||||
public int NestedTypesOffset { get; private set; }
|
||||
public int NestedTypesSize { get; private set; }
|
||||
public int InterfacesOffset { get; private set; }
|
||||
public int InterfacesSize { get; private set; }
|
||||
public int VTableMethodsOffset { get; private set; }
|
||||
public int VTableMethodsSize { get; private set; }
|
||||
public int InterfaceOffsetsOffset { get; private set; }
|
||||
public int InterfaceOffsetsSize { get; private set; }
|
||||
public int TypeDefinitionsOffset { get; private set; }
|
||||
public int TypeDefinitionsSize { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int RgctxEntriesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int RgctxEntriesCount { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
public int ImagesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
public int ImagesSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
public int AssembliesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
public int AssembliesSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0", LessThan = "24.5")]
|
||||
public int MetadataUsageListsOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0", LessThan = "24.5")]
|
||||
public int MetadataUsageListsCount { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0", LessThan = "24.5")]
|
||||
public int MetadataUsagePairsOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0", LessThan = "24.5")]
|
||||
public int MetadataUsagePairsCount { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public int FieldRefsOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public int FieldRefsSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "20.0")]
|
||||
public int ReferencedAssembliesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "20.0")]
|
||||
public int ReferencedAssembliesSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "27.2")]
|
||||
public int AttributesInfoOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "27.2")]
|
||||
public int AttributesInfoCount { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "27.2")]
|
||||
public int AttributesTypesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "27.2")]
|
||||
public int AttributesTypesCount { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "29.0")]
|
||||
public int AttributeDataOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "29.0")]
|
||||
public int AttributeDataSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "29.0")]
|
||||
public int AttributeDataRangeOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "29.0")]
|
||||
public int AttributeDataRangeSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "22.0")]
|
||||
public int UnresolvedIndirectCallParameterTypesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "22.0")]
|
||||
public int UnresolvedIndirectCallParameterTypesSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "22.0")]
|
||||
public int UnresolvedIndirectCallParameterRangesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "22.0")]
|
||||
public int UnresolvedIndirectCallParameterRangesSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "23.0")]
|
||||
public int WindowsRuntimeTypeNamesOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "23.0")]
|
||||
public int WindowsRuntimeTypeNamesSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "27.0")]
|
||||
public int WindowsRuntimeStringsOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "27.0")]
|
||||
public int WindowsRuntimeStringsSize { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "24.0")]
|
||||
public int ExportedTypeDefinitionsOffset { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "24.0")]
|
||||
public int ExportedTypeDefinitionsSize { get; private set; }
|
||||
|
||||
|
||||
public const int ExpectedSanity = unchecked((int)0xFAB11BAF);
|
||||
public readonly bool SanityValid => Sanity == ExpectedSanity;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using StringIndex = int;
|
||||
using AssemblyIndex = int;
|
||||
using TypeDefinitionIndex = int;
|
||||
using MethodIndex = int;
|
||||
using CustomAttributeIndex = int;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppImageDefinition
|
||||
{
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
public AssemblyIndex AssemblyIndex { get; private set; }
|
||||
|
||||
public TypeDefinitionIndex TypeStart { get; private set; }
|
||||
public uint TypeCount { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "24.0")]
|
||||
public TypeDefinitionIndex ExportedTypeStart { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "24.0")]
|
||||
public uint ExportedTypeCount { get; private set; }
|
||||
|
||||
public MethodIndex EntryPointIndex { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public uint Token { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "24.1")]
|
||||
public CustomAttributeIndex CustomAttributeStart { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "24.1")]
|
||||
public uint CustomAttributeCount { get; private set; }
|
||||
|
||||
public readonly bool IsValid => NameIndex != 0;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using TypeIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppInterfaceOffsetPair
|
||||
{
|
||||
public TypeIndex InterfaceTypeIndex { get; private set; }
|
||||
public int Offset { get; private set; }
|
||||
}
|
||||
10
Il2CppInspector.Common/Next/Metadata/Il2CppMetadataRange.cs
Normal file
10
Il2CppInspector.Common/Next/Metadata/Il2CppMetadataRange.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppMetadataRange
|
||||
{
|
||||
public int Start { get; private set; }
|
||||
public int Length { get; private set; }
|
||||
}
|
||||
64
Il2CppInspector.Common/Next/Metadata/Il2CppMetadataUsage.cs
Normal file
64
Il2CppInspector.Common/Next/Metadata/Il2CppMetadataUsage.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Diagnostics;
|
||||
using VersionedSerialization;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using VersionedSerialization.Attributes;
|
||||
using EncodedMethodIndex = uint;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppMetadataUsage
|
||||
{
|
||||
private const uint TypeMask = 0b111u << 29;
|
||||
private const uint InflatedMask = 0b1;
|
||||
private const uint IndexMask = ~(TypeMask | InflatedMask);
|
||||
|
||||
public readonly Il2CppMetadataUsageType Type => (Il2CppMetadataUsageType)((EncodedValue & TypeMask) >> 29);
|
||||
public readonly uint Index => (EncodedValue & IndexMask) >> 1;
|
||||
public readonly bool Inflated => (EncodedValue & InflatedMask) == 1;
|
||||
|
||||
public EncodedMethodIndex EncodedValue;
|
||||
|
||||
public static Il2CppMetadataUsage FromValue(in StructVersion version, uint encodedValue)
|
||||
{
|
||||
if (version >= MetadataVersions.V270)
|
||||
{
|
||||
return new Il2CppMetadataUsage
|
||||
{
|
||||
EncodedValue = encodedValue
|
||||
};
|
||||
}
|
||||
|
||||
if (version >= MetadataVersions.V190)
|
||||
{
|
||||
// Below v27 we need to fake the 'inflated' flag, so shift the value by one
|
||||
|
||||
var type = (encodedValue & TypeMask) >> 29;
|
||||
var value = encodedValue & (IndexMask | 1);
|
||||
Debug.Assert((value & 0x10000000) == 0);
|
||||
|
||||
return new Il2CppMetadataUsage
|
||||
{
|
||||
EncodedValue = (type << 29) | (value << 1)
|
||||
};
|
||||
}
|
||||
|
||||
/* These encoded indices appear only in vtables, and are decoded by IsGenericMethodIndex/GetDecodedMethodIndex */
|
||||
var methodType = (encodedValue >> 31) != 0
|
||||
? Il2CppMetadataUsageType.MethodRef
|
||||
: Il2CppMetadataUsageType.MethodDef;
|
||||
|
||||
var index = encodedValue & 0x7FFFFFFF;
|
||||
Debug.Assert((index & 0x60000000) == 0);
|
||||
|
||||
return new Il2CppMetadataUsage
|
||||
{
|
||||
EncodedValue = ((uint)methodType << 29) | (index << 1)
|
||||
};
|
||||
}
|
||||
|
||||
public readonly override string ToString()
|
||||
{
|
||||
return $"{Type} @ 0x{Index:X}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppMetadataUsageList
|
||||
{
|
||||
public int Start { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppMetadataUsagePair
|
||||
{
|
||||
public uint DestinationIndex { get; private set; }
|
||||
public uint EncodedSourceIndex { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
public enum Il2CppMetadataUsageType
|
||||
{
|
||||
Invalid = 0b000,
|
||||
TypeInfo = 0b001,
|
||||
Il2CppType = 0b010,
|
||||
MethodDef = 0b011,
|
||||
FieldInfo = 0b100,
|
||||
StringLiteral = 0b101,
|
||||
MethodRef = 0b110,
|
||||
FieldRva = 0b111,
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Reflection;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using StringIndex = int;
|
||||
using TypeDefinitionIndex = int;
|
||||
using TypeIndex = int;
|
||||
using ParameterIndex = int;
|
||||
using GenericContainerIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppMethodDefinition
|
||||
{
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "16.0")]
|
||||
public TypeDefinitionIndex DeclaringType { get; private set; }
|
||||
public TypeIndex ReturnType { get; private set; }
|
||||
|
||||
[VersionCondition(EqualTo = "31.0")]
|
||||
public uint ReturnParameterToken { get; private set; }
|
||||
|
||||
public ParameterIndex ParameterStart { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.0")]
|
||||
public int CustomAttributeIndex { get; private set; }
|
||||
|
||||
public GenericContainerIndex GenericContainerIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int MethodIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int InvokerIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int ReversePInvokeWrapperIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int RgctxStartIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int RgctxCount { get; private set; }
|
||||
|
||||
public uint Token { get; private set; }
|
||||
public ushort Flags { get; private set; }
|
||||
public ushort ImplFlags { get; private set; }
|
||||
public ushort Slot { get; private set; }
|
||||
public ushort ParameterCount { get; private set; }
|
||||
|
||||
public readonly MethodAttributes Attributes => (MethodAttributes)Flags;
|
||||
public readonly MethodImplAttributes ImplAttributes => (MethodImplAttributes)ImplFlags;
|
||||
|
||||
public readonly bool IsValid => NameIndex != 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using ParameterIndex = int;
|
||||
using TypeIndex = int;
|
||||
using DefaultValueDataIndex = int;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppParameterDefaultValue
|
||||
{
|
||||
public ParameterIndex ParameterIndex { get; private set; }
|
||||
public TypeIndex TypeIndex { get; private set; }
|
||||
public DefaultValueDataIndex DataIndex { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using VersionedSerialization.Attributes;
|
||||
using StringIndex = int;
|
||||
using TypeIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppParameterDefinition
|
||||
{
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
public uint Token { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.0")]
|
||||
public int CustomAttributeIndex { get; private set; }
|
||||
|
||||
public TypeIndex TypeIndex { get; private set; }
|
||||
|
||||
public readonly bool IsValid => NameIndex != 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Reflection;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using StringIndex = int;
|
||||
using MethodIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppPropertyDefinition
|
||||
{
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
public MethodIndex Get { get; private set; }
|
||||
public MethodIndex Set { get; private set; }
|
||||
public PropertyAttributes Attrs { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.0")]
|
||||
public int CustomAttributeIndex { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public uint Token { get; private set; }
|
||||
|
||||
public readonly bool IsValid => NameIndex != 0;
|
||||
}
|
||||
11
Il2CppInspector.Common/Next/Metadata/Il2CppStringLiteral.cs
Normal file
11
Il2CppInspector.Common/Next/Metadata/Il2CppStringLiteral.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using VersionedSerialization.Attributes;
|
||||
using StringLiteralIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppStringLiteral
|
||||
{
|
||||
public uint Length { get; private set; }
|
||||
public StringLiteralIndex DataIndex { get; private set; }
|
||||
}
|
||||
83
Il2CppInspector.Common/Next/Metadata/Il2CppTypeDefinition.cs
Normal file
83
Il2CppInspector.Common/Next/Metadata/Il2CppTypeDefinition.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System.Reflection;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using StringIndex = int;
|
||||
using TypeIndex = int;
|
||||
using GenericContainerIndex = int;
|
||||
using FieldIndex = int;
|
||||
using MethodIndex = int;
|
||||
using EventIndex = int;
|
||||
using PropertyIndex = int;
|
||||
using NestedTypeIndex = int;
|
||||
using InterfacesIndex = int;
|
||||
using VTableIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppTypeDefinition
|
||||
{
|
||||
public const TypeIndex InvalidTypeIndex = -1;
|
||||
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
public StringIndex NamespaceIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.0")]
|
||||
public int CustomAttributeIndex { get; private set; }
|
||||
|
||||
public TypeIndex ByValTypeIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.5")]
|
||||
public TypeIndex ByRefTypeIndex { get; private set; }
|
||||
|
||||
public TypeIndex DeclaringTypeIndex { get; private set; }
|
||||
public TypeIndex ParentIndex { get; private set; }
|
||||
public TypeIndex ElementTypeIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int RgctxStartIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "24.1")]
|
||||
public int RgctxCount { get; private set; }
|
||||
|
||||
public GenericContainerIndex GenericContainerIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "22.0")]
|
||||
public int ReversePInvokeWrapperIndex { get; private set; }
|
||||
|
||||
[VersionCondition(LessThan = "22.0")]
|
||||
public int MarshalingFunctionsIndex { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||
public int CcwFunctionIndex { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "21.0", LessThan = "22.0")]
|
||||
public int GuidIndex { get; private set; }
|
||||
|
||||
public TypeAttributes Flags { get; private set; }
|
||||
|
||||
public FieldIndex FieldIndex { get; private set; }
|
||||
public MethodIndex MethodIndex { get; private set; }
|
||||
public EventIndex EventIndex { get; private set; }
|
||||
public PropertyIndex PropertyIndex { get; private set; }
|
||||
public NestedTypeIndex NestedTypeIndex { get; private set; }
|
||||
public InterfacesIndex InterfacesIndex { get; private set; }
|
||||
public VTableIndex VTableIndex { get; private set; }
|
||||
public InterfacesIndex InterfaceOffsetsStart { get; private set; }
|
||||
|
||||
public ushort MethodCount { get; private set; }
|
||||
public ushort PropertyCount { get; private set; }
|
||||
public ushort FieldCount { get; private set; }
|
||||
public ushort EventCount { get; private set; }
|
||||
public ushort NestedTypeCount { get; private set; }
|
||||
public ushort VTableCount { get; private set; }
|
||||
public ushort InterfacesCount { get; private set; }
|
||||
public ushort InterfaceOffsetsCount { get; private set; }
|
||||
|
||||
public Il2CppTypeDefinitionBitfield Bitfield { get; private set; }
|
||||
|
||||
[VersionCondition(GreaterThan = "19.0")]
|
||||
public uint Token { get; private set; }
|
||||
|
||||
public readonly bool IsValid => NameIndex != 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppTypeDefinitionBitfield
|
||||
{
|
||||
private uint _value;
|
||||
|
||||
public bool ValueType => ((_value >> 0) & 1) == 1;
|
||||
public bool EnumType => ((_value >> 1) & 1) == 1;
|
||||
public bool HasFinalize => ((_value >> 2) & 1) == 1;
|
||||
public bool HasCctor => ((_value >> 3) & 1) == 1;
|
||||
public bool IsBlittable => ((_value >> 4) & 1) == 1;
|
||||
public bool IsImportOrWindowsRuntime => ((_value >> 5) & 1) == 1;
|
||||
public PackingSize PackingSize => (PackingSize)((_value >> 6) & 0b1111);
|
||||
public bool DefaultPackingSize => ((_value >> 10) & 1) == 1;
|
||||
public bool DefaultClassSize => ((_value >> 11) & 1) == 1;
|
||||
public PackingSize ClassSize => (PackingSize)((_value >> 12) & 0b1111);
|
||||
public bool IsByRefLike => ((_value >> 13) & 1) == 1;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
using VersionedSerialization.Attributes;
|
||||
using StringIndex = int;
|
||||
using TypeIndex = int;
|
||||
|
||||
[VersionedStruct]
|
||||
public partial record struct Il2CppWindowsRuntimeTypeNamePair
|
||||
{
|
||||
public StringIndex NameIndex { get; private set; }
|
||||
public TypeIndex TypeIndex { get; private set; }
|
||||
}
|
||||
14
Il2CppInspector.Common/Next/Metadata/PackingSize.cs
Normal file
14
Il2CppInspector.Common/Next/Metadata/PackingSize.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Il2CppInspector.Next.Metadata;
|
||||
|
||||
public enum PackingSize
|
||||
{
|
||||
Zero,
|
||||
One,
|
||||
Two,
|
||||
Four,
|
||||
Eight,
|
||||
Sixteen,
|
||||
ThirtyTwo,
|
||||
SixtyFour,
|
||||
OneHundredTwentyEight
|
||||
}
|
||||
31
Il2CppInspector.Common/Next/MetadataVersions.cs
Normal file
31
Il2CppInspector.Common/Next/MetadataVersions.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using VersionedSerialization;
|
||||
|
||||
namespace Il2CppInspector.Next;
|
||||
|
||||
public static class MetadataVersions
|
||||
{
|
||||
public static readonly StructVersion V160 = new(16);
|
||||
|
||||
public static readonly StructVersion V190 = new(19);
|
||||
|
||||
public static readonly StructVersion V210 = new(21);
|
||||
public static readonly StructVersion V220 = new(22);
|
||||
|
||||
public static readonly StructVersion V240 = new(24);
|
||||
public static readonly StructVersion V241 = new(24, 1);
|
||||
public static readonly StructVersion V242 = new(24, 2);
|
||||
public static readonly StructVersion V243 = new(24, 3);
|
||||
public static readonly StructVersion V244 = new(24, 4);
|
||||
public static readonly StructVersion V245 = new(24, 5);
|
||||
|
||||
public static readonly StructVersion V270 = new(27);
|
||||
public static readonly StructVersion V271 = new(27, 1);
|
||||
public static readonly StructVersion V272 = new(27, 2);
|
||||
|
||||
// These two versions have two variations:
|
||||
public static readonly StructVersion V290 = new(29);
|
||||
public static readonly StructVersion V310 = new(31);
|
||||
|
||||
// No tag - 29.0/31.0
|
||||
public static readonly string Tag2022 = "2022"; // 29.1/31.1
|
||||
}
|
||||
60
Il2CppInspector.Common/Next/Pointer.cs
Normal file
60
Il2CppInspector.Common/Next/Pointer.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Immutable;
|
||||
using VersionedSerialization;
|
||||
using VersionedSerialization.Attributes;
|
||||
|
||||
namespace Il2CppInspector.Next;
|
||||
|
||||
public struct Pointer<T>(ulong value = 0) : IReadable, IEquatable<Pointer<T>> where T : struct, IReadable
|
||||
{
|
||||
[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, in StructVersion version)
|
||||
{
|
||||
reader.Offset = (int)PointerValue;
|
||||
return reader.ReadVersionedObject<T>(version);
|
||||
}
|
||||
|
||||
public readonly ImmutableArray<T> ReadArray(ref SpanReader reader, long count, in StructVersion version)
|
||||
{
|
||||
reader.Offset = (int)PointerValue;
|
||||
return reader.ReadVersionedObjectArray<T>(count, version);
|
||||
}
|
||||
|
||||
public static implicit operator Pointer<T>(ulong value) => new(value);
|
||||
public static implicit operator ulong(Pointer<T> ptr) => ptr.PointerValue;
|
||||
|
||||
#region Equality operators + ToString
|
||||
|
||||
public static bool operator ==(Pointer<T> left, Pointer<T> right)
|
||||
=> left._value == right._value;
|
||||
|
||||
public static bool operator !=(Pointer<T> left, Pointer<T> right)
|
||||
=> !(left == right);
|
||||
|
||||
public readonly override bool Equals(object? obj)
|
||||
=> obj is Pointer<T> other && Equals(other);
|
||||
|
||||
public readonly bool Equals(Pointer<T> other)
|
||||
=> this == other;
|
||||
|
||||
public readonly override int GetHashCode()
|
||||
=> HashCode.Combine(_value);
|
||||
|
||||
public readonly override string ToString() => $"0x{_value:X} <{typeof(T).Name}>";
|
||||
|
||||
#endregion
|
||||
}
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user