Files
Cpp2IL/Cpp2IL.Core/Il2CppMethodInfoUsefulOffsets.cs

41 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using LibCpp2IL;
namespace Cpp2IL.Core;
public static class Il2CppMethodInfoUsefulOffsets
{
public const int X86_KLASS_OFFSET = 0x00; //TODO
public const int X86_64_KLASS_OFFSET = 0x18;
public static readonly List<UsefulOffset> UsefulOffsets =
[
new UsefulOffset("klass", X86_KLASS_OFFSET, typeof(ushort), true),
//64-bit offsets:
new UsefulOffset("klass", X86_64_KLASS_OFFSET, typeof(IntPtr), false)
];
public static bool IsKlassPtr(uint offset, Il2CppBinary binary)
{
return GetOffsetName(offset, binary) == "klass";
}
public static string? GetOffsetName(uint offset, Il2CppBinary binary)
{
var is32Bit = binary.is32Bit;
return UsefulOffsets.FirstOrDefault(o => o.is32Bit == is32Bit && o.offset == offset)?.name;
}
public class UsefulOffset(string name, uint offset, Type type, bool is32Bit)
{
public string name = name;
public uint offset = offset;
public Type type = type;
public bool is32Bit = is32Bit;
}
}