Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions Il2CppDumper/IO/BinaryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,144 @@ private object ReadPrimitive(Type type)
return ReadClass<T>();
}

public TypeIndex ReadTypeIndex()
{
if (Version < 35)
{
// Before Version 35, these were always Int32
int value = ReadInt32();
return new TypeIndex(value);
}
else
{
switch (Metadata.typeIndexSize)
{
case 1:
{
uint value = ReadByte();
if (value == Byte.MaxValue) return new TypeIndex(-1);
return new TypeIndex((int)value);
}
case 2:
{
uint value = ReadUInt16();
if (value == UInt16.MaxValue) return new TypeIndex(-1);
return new TypeIndex((int)value);
}
case 4:
default:
{
uint value = ReadUInt32();
if (value == UInt32.MaxValue) return new TypeIndex(-1);
return new TypeIndex((int)value);
}
}
}
}

public TypeDefinitionIndex ReadTypeDefinitionIndex()
{
if (Version < 35)
{
// Before Version 35, these were always Int32
int value = ReadInt32();
return new TypeDefinitionIndex(value);
}
else
{
switch (Metadata.typeDefinitionIndexSize)
{
case 1:
{
uint value = ReadByte();
if (value == Byte.MaxValue) return new TypeDefinitionIndex(-1);
return new TypeDefinitionIndex((int)value);
}
case 2:
{
uint value = ReadUInt16();
if (value == UInt16.MaxValue) return new TypeDefinitionIndex(-1);
return new TypeDefinitionIndex((int)value);
}
case 4:
default:
{
uint value = ReadUInt32();
if (value == UInt32.MaxValue) return new TypeDefinitionIndex(-1);
return new TypeDefinitionIndex((int)value);
}
}
}
}
public GenericContainerIndex ReadGenericContainerIndex()
{
if (Version < 35)
{
// Before Version 35, these were always Int32
int value = ReadInt32();
return new GenericContainerIndex(value);
}
else
{
switch (Metadata.genericContainerIndexSize)
{
case 1:
{
uint value = ReadByte();
if (value == Byte.MaxValue) return new GenericContainerIndex(-1);
return new GenericContainerIndex((int)value);
}
case 2:
{
uint value = ReadUInt16();
if (value == UInt16.MaxValue) return new GenericContainerIndex(-1);
return new GenericContainerIndex((int)value);
}
case 4:
default:
{
uint value = ReadUInt32();
if (value == UInt32.MaxValue) return new GenericContainerIndex(-1);
return new GenericContainerIndex((int)value);
}
}
}
}
public ParameterIndex ReadParameterIndex()
{
if (Version < 39)
{
// Before Version 39, these were always Int32
int value = ReadInt32();
return new ParameterIndex(value);
}
else
{
switch (Metadata.parameterIndexSize)
{
case 1:
{
uint value = ReadByte();
if (value == Byte.MaxValue) return new ParameterIndex(-1);
return new ParameterIndex((int)value);
}
case 2:
{
uint value = ReadUInt16();
if (value == UInt16.MaxValue) return new ParameterIndex(-1);
return new ParameterIndex((int)value);
}
case 4:
default:
{
uint value = ReadUInt32();
if (value == UInt32.MaxValue) return new ParameterIndex(-1);
return new ParameterIndex((int)value);
}
}
}
}

public T ReadClass<T>() where T : new()
{
var type = typeof(T);
Expand Down Expand Up @@ -168,6 +306,26 @@ private object ReadPrimitive(Type type)
}
i.SetValue(t, methodInfo.Invoke(this, new object[] { arrayLengthAttribute.Length }));
}
else if (fieldType == typeof(TypeIndex))
{
i.SetValue(t, ReadTypeIndex());
}
else if (fieldType == typeof(TypeDefinitionIndex))
{
i.SetValue(t, ReadTypeDefinitionIndex());
}
else if (fieldType == typeof(GenericContainerIndex))
{
i.SetValue(t, ReadGenericContainerIndex());
}
else if (fieldType == typeof(ParameterIndex))
{
i.SetValue(t, ReadParameterIndex());
}
else if (fieldType == typeof(Il2CppSectionMetadata))
{
i.SetValue(t, ReadClass<Il2CppSectionMetadata>());
}
else
{
if (!genericMethodCache.TryGetValue(fieldType, out var methodInfo))
Expand Down
2 changes: 1 addition & 1 deletion Il2CppDumper/Il2Cpp/Il2Cpp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Il2CppDumper
{
public abstract class Il2Cpp : BinaryStream
{
private Il2CppMetadataRegistration pMetadataRegistration;
public Il2CppMetadataRegistration pMetadataRegistration;
private Il2CppCodeRegistration pCodeRegistration;
public ulong[] methodPointers;
public ulong[] genericMethodPointers;
Expand Down
37 changes: 37 additions & 0 deletions Il2CppDumper/Il2Cpp/Il2CppClass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Linq;
using System.Reflection;

namespace Il2CppDumper
{
Expand Down Expand Up @@ -63,6 +65,41 @@ public class Il2CppCodeRegistration
public ulong codeGenModulesCount;
[Version(Min = 24.2)]
public ulong codeGenModules;

public static ulong Size(double version)
{
ulong size = 0;
foreach (var field in typeof(Il2CppCodeRegistration).GetFields()) {
// Check if the field exists in our version
var versionAttributes = field.GetCustomAttributes<VersionAttribute>().ToArray();
if (versionAttributes?.Length > 0)
{
var isInVersionRange = false;
foreach (var versionAttribute in versionAttributes)
{
if (versionAttribute.Min <= version && version <= versionAttribute.Max)
{
isInVersionRange = true;
break;
}
}
if (!isInVersionRange)
{
continue;
}
}

if (field.FieldType == typeof(byte) || field.FieldType == typeof(sbyte))
size += sizeof(byte);
if (field.FieldType == typeof(long) || field.FieldType == typeof(ulong))
size += sizeof(ulong);
if (field.FieldType == typeof(int) || field.FieldType == typeof(uint))
size += sizeof(uint);
if (field.FieldType == typeof(short) || field.FieldType == typeof(ushort))
size += sizeof(ushort);
}
return size;
}
}

public class Il2CppMetadataRegistration
Expand Down
Loading