示例#1
0
 public Il2CppRGCTXDefinition[] GetRGCTXDefinition(string imageName, Il2CppMethodDefinition methodDef)
 {
     Il2CppRGCTXDefinition[] collection = null;
     if (il2Cpp.Version >= 24.2)
     {
         il2Cpp.rgctxsDictionary[imageName].TryGetValue(methodDef.token, out collection);
     }
     else
     {
         if (methodDef.rgctxCount > 0)
         {
             collection = new Il2CppRGCTXDefinition[methodDef.rgctxCount];
             Array.Copy(metadata.rgctxEntries, methodDef.rgctxStartIndex, collection, 0, methodDef.rgctxCount);
         }
     }
     return(collection);
 }
示例#2
0
 public Il2CppRGCTXDefinition[] GetTypeRGCTXDefinition(Il2CppTypeDefinition typeDef, int imageIndex)
 {
     Il2CppRGCTXDefinition[] collection = null;
     if (il2Cpp.Version >= 24.2f)
     {
         il2Cpp.rgctxsDictionary[imageIndex].TryGetValue(typeDef.token, out collection);
     }
     else
     {
         if (typeDef.rgctxCount > 0)
         {
             collection = new Il2CppRGCTXDefinition[typeDef.rgctxCount];
             Array.Copy(metadata.rgctxEntries, typeDef.rgctxStartIndex, collection, 0, typeDef.rgctxCount);
         }
     }
     return(collection);
 }
示例#3
0
        public virtual void Init(ulong codeRegistration, ulong metadataRegistration)
        {
            pCodeRegistration = MapVATR <Il2CppCodeRegistration>(codeRegistration);
            if (Version == 27)
            {
                if (pCodeRegistration.reversePInvokeWrapperCount > 0x30000) //TODO
                {
                    Version           = 27.1;
                    codeRegistration -= PointerSize;
                    Console.WriteLine($"Change il2cpp version to: {Version}");
                    Console.WriteLine("CodeRegistration : {0:x}", codeRegistration);
                    pCodeRegistration = MapVATR <Il2CppCodeRegistration>(codeRegistration);
                }
            }
            if (Version == 24.2)
            {
                if (pCodeRegistration.reversePInvokeWrapperCount > 0x30000) //TODO
                {
                    Version           = 24.4;
                    codeRegistration -= PointerSize * 3;
                    Console.WriteLine($"Change il2cpp version to: {Version}");
                    Console.WriteLine("CodeRegistration : {0:x}", codeRegistration);
                    pCodeRegistration = MapVATR <Il2CppCodeRegistration>(codeRegistration);
                }
                else
                {
                    if (pCodeRegistration.codeGenModules == 0) //TODO
                    {
                        Version = 24.3;
                        Console.WriteLine($"Change il2cpp version to: {Version}");
                        pCodeRegistration = MapVATR <Il2CppCodeRegistration>(codeRegistration);
                    }
                }
            }
            pMetadataRegistration = MapVATR <Il2CppMetadataRegistration>(metadataRegistration);
            genericMethodPointers = MapVATR <ulong>(pCodeRegistration.genericMethodPointers, pCodeRegistration.genericMethodPointersCount);
            invokerPointers       = MapVATR <ulong>(pCodeRegistration.invokerPointers, pCodeRegistration.invokerPointersCount);
            if (Version < 27)
            {
                customAttributeGenerators = MapVATR <ulong>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount);
            }
            if (Version > 16 && Version < 27)
            {
                metadataUsages = MapVATR <ulong>(pMetadataRegistration.metadataUsages, maxMetadataUsages);
            }
            if (Version >= 22)
            {
                if (pCodeRegistration.reversePInvokeWrapperCount != 0)
                {
                    reversePInvokeWrappers = MapVATR <ulong>(pCodeRegistration.reversePInvokeWrappers, pCodeRegistration.reversePInvokeWrapperCount);
                }
                if (pCodeRegistration.unresolvedVirtualCallCount != 0)
                {
                    unresolvedVirtualCallPointers = MapVATR <ulong>(pCodeRegistration.unresolvedVirtualCallPointers, pCodeRegistration.unresolvedVirtualCallCount);
                }
            }
            genericInstPointers     = MapVATR <ulong>(pMetadataRegistration.genericInsts, pMetadataRegistration.genericInstsCount);
            genericInsts            = Array.ConvertAll(genericInstPointers, MapVATR <Il2CppGenericInst>);
            fieldOffsetsArePointers = Version > 21;
            if (Version == 21)
            {
                var fieldTest = MapVATR <uint>(pMetadataRegistration.fieldOffsets, 6);
                fieldOffsetsArePointers = fieldTest[0] == 0 && fieldTest[1] == 0 && fieldTest[2] == 0 && fieldTest[3] == 0 && fieldTest[4] == 0 && fieldTest[5] > 0;
            }
            if (fieldOffsetsArePointers)
            {
                fieldOffsets = MapVATR <ulong>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount);
            }
            else
            {
                fieldOffsets = Array.ConvertAll(MapVATR <uint>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount), x => (ulong)x);
            }
            var pTypes = MapVATR <ulong>(pMetadataRegistration.types, pMetadataRegistration.typesCount);

            types = new Il2CppType[pMetadataRegistration.typesCount];
            for (var i = 0; i < pMetadataRegistration.typesCount; ++i)
            {
                types[i] = MapVATR <Il2CppType>(pTypes[i]);
                types[i].Init();
                typeDic.Add(pTypes[i], types[i]);
            }
            if (Version >= 24.2)
            {
                var pCodeGenModules = MapVATR <ulong>(pCodeRegistration.codeGenModules, pCodeRegistration.codeGenModulesCount);
                codeGenModules = new Dictionary <string, Il2CppCodeGenModule>(pCodeGenModules.Length, StringComparer.Ordinal);
                codeGenModuleMethodPointers = new Dictionary <string, ulong[]>(pCodeGenModules.Length, StringComparer.Ordinal);
                rgctxsDictionary            = new Dictionary <string, Dictionary <uint, Il2CppRGCTXDefinition[]> >(pCodeGenModules.Length, StringComparer.Ordinal);
                foreach (var pCodeGenModule in pCodeGenModules)
                {
                    var codeGenModule = MapVATR <Il2CppCodeGenModule>(pCodeGenModule);
                    var moduleName    = ReadStringToNull(MapVATR(codeGenModule.moduleName));
                    codeGenModules.Add(moduleName, codeGenModule);
                    ulong[] methodPointers;
                    try
                    {
                        methodPointers = MapVATR <ulong>(codeGenModule.methodPointers, codeGenModule.methodPointerCount);
                    }
                    catch
                    {
                        methodPointers = new ulong[codeGenModule.methodPointerCount];
                    }
                    codeGenModuleMethodPointers.Add(moduleName, methodPointers);

                    var rgctxsDefDictionary = new Dictionary <uint, Il2CppRGCTXDefinition[]>();
                    rgctxsDictionary.Add(moduleName, rgctxsDefDictionary);
                    if (codeGenModule.rgctxsCount > 0)
                    {
                        var rgctxs      = MapVATR <Il2CppRGCTXDefinition>(codeGenModule.rgctxs, codeGenModule.rgctxsCount);
                        var rgctxRanges = MapVATR <Il2CppTokenRangePair>(codeGenModule.rgctxRanges, codeGenModule.rgctxRangesCount);
                        foreach (var rgctxRange in rgctxRanges)
                        {
                            var rgctxDefs = new Il2CppRGCTXDefinition[rgctxRange.range.length];
                            Array.Copy(rgctxs, rgctxRange.range.start, rgctxDefs, 0, rgctxRange.range.length);
                            rgctxsDefDictionary.Add(rgctxRange.token, rgctxDefs);
                        }
                    }
                }
            }
            else
            {
                methodPointers = MapVATR <ulong>(pCodeRegistration.methodPointers, pCodeRegistration.methodPointersCount);
            }
            genericMethodTable = MapVATR <Il2CppGenericMethodFunctionsDefinitions>(pMetadataRegistration.genericMethodTable, pMetadataRegistration.genericMethodTableCount);
            methodSpecs        = MapVATR <Il2CppMethodSpec>(pMetadataRegistration.methodSpecs, pMetadataRegistration.methodSpecsCount);
            foreach (var table in genericMethodTable)
            {
                var methodSpec            = methodSpecs[table.genericMethodIndex];
                var methodDefinitionIndex = methodSpec.methodDefinitionIndex;
                if (!methodDefinitionMethodSpecs.TryGetValue(methodDefinitionIndex, out var list))
                {
                    list = new List <Il2CppMethodSpec>();
                    methodDefinitionMethodSpecs.Add(methodDefinitionIndex, list);
                }
                list.Add(methodSpec);
                methodSpecGenericMethodPointers.Add(methodSpec, genericMethodPointers[table.indices.methodIndex]);
            }
        }