Exemplo n.º 1
0
        private void Init(uint codeRegistration, uint metadataRegistration)
        {
            pCodeRegistration                  = MapVATR <Il2CppCodeRegistration>(codeRegistration);
            pMetadataRegistration              = MapVATR <Il2CppMetadataRegistration>(metadataRegistration);
            pCodeRegistration.methodPointers   = MapVATR <uint>(pCodeRegistration.pmethodPointers, (int)pCodeRegistration.methodPointersCount);
            pMetadataRegistration.fieldOffsets = MapVATR <int>(pMetadataRegistration.pfieldOffsets, pMetadataRegistration.fieldOffsetsCount);
            var types = MapVATR <uint>(pMetadataRegistration.ptypes, pMetadataRegistration.typesCount);

            pMetadataRegistration.types = new Il2CppType[pMetadataRegistration.typesCount];
            for (int i = 0; i < pMetadataRegistration.typesCount; ++i)
            {
                pMetadataRegistration.types[i] = MapVATR <Il2CppType>(types[i]);
                pMetadataRegistration.types[i].Init();
            }
        }
Exemplo n.º 2
0
        protected void Init(uint codeRegistration, uint metadataRegistration)
        {
            pCodeRegistration         = MapVATR <Il2CppCodeRegistration>(codeRegistration);
            pMetadataRegistration     = MapVATR <Il2CppMetadataRegistration>(metadataRegistration);
            methodPointers            = MapVATR <uint>(pCodeRegistration.methodPointers, (int)pCodeRegistration.methodPointersCount);
            customAttributeGenerators = MapVATR <uint>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount);
            fieldOffsets = MapVATR <int>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount);
            var ptypes = MapVATR <uint>(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();
            }
        }
Exemplo n.º 3
0
        protected virtual void Init(ulong codeRegistration, ulong metadataRegistration)
        {
            pCodeRegistration         = MapVATR <Il2CppCodeRegistration>(codeRegistration);
            pMetadataRegistration     = MapVATR <Il2CppMetadataRegistration>(metadataRegistration);
            methodPointers            = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.methodPointers, (long)pCodeRegistration.methodPointersCount), x => (ulong)x);
            customAttributeGenerators = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount), x => (ulong)x);
            fieldOffsets = Array.ConvertAll(MapVATR <int>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount), x => (long)x);
            //TODO 在21版本中存在两种FieldOffset,通过判断前5个数值是否为0确认是指针还是int
            isNew21 = version > 21 || (version == 21 && fieldOffsets.ToList().FindIndex(x => x > 0) == 5);
            var ptypes = MapVATR <uint>(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();
                typesdic.Add(ptypes[i], types[i]);
            }
            if (version > 16)
            {
                metadataUsages = Array.ConvertAll(MapVATR <uint>(pMetadataRegistration.metadataUsages, maxmetadataUsages), x => (ulong)x);
            }
        }
Exemplo n.º 4
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]);
            }
        }
Exemplo n.º 5
0
 public virtual void Init(ulong codeRegistration, ulong metadataRegistration)
 {
     pCodeRegistration     = MapVATR <Il2CppCodeRegistration>(codeRegistration);
     pMetadataRegistration = MapVATR <Il2CppMetadataRegistration>(metadataRegistration);
     if (is32Bit)
     {
         genericInsts              = Array.ConvertAll(MapVATR <uint>(pMetadataRegistration.genericInsts, pMetadataRegistration.genericInstsCount), x => MapVATR <Il2CppGenericInst>(x));
         genericMethodPointers     = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.genericMethodPointers, (long)pCodeRegistration.genericMethodPointersCount), x => (ulong)x);
         invokerPointers           = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.invokerPointers, (long)pCodeRegistration.invokerPointersCount), x => (ulong)x);
         customAttributeGenerators = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount), x => (ulong)x);
         fieldOffsets              = Array.ConvertAll(MapVATR <int>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount), x => (long)x);
         //在21版本中存在两种FieldOffset,通过判断前5个数值是否为0确认是指针还是int
         isNew21 = version > 21 || (version == 21 && fieldOffsets.ToList().FindIndex(x => x > 0) == 5);
         var pTypes = MapVATR <uint>(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();
             typesdic.Add(pTypes[i], types[i]);
         }
         if (version > 16)
         {
             metadataUsages = Array.ConvertAll(MapVATR <uint>(pMetadataRegistration.metadataUsages, maxMetadataUsages), x => (ulong)x);
         }
         if (version >= 24.2f)
         {
             var pCodeGenModules = MapVATR <uint>(pCodeRegistration.codeGenModules, (long)pCodeRegistration.codeGenModulesCount);
             codeGenModules = new Il2CppCodeGenModule[pCodeGenModules.Length];
             codeGenModuleMethodPointers = new ulong[pCodeGenModules.Length][];
             for (int i = 0; i < pCodeGenModules.Length; i++)
             {
                 var codeGenModule = MapVATR <Il2CppCodeGenModule>(pCodeGenModules[i]);
                 codeGenModules[i] = codeGenModule;
                 try
                 {
                     var ptrs = Array.ConvertAll(MapVATR <uint>(codeGenModule.methodPointers, (long)codeGenModule.methodPointerCount), x => (ulong)x);
                     codeGenModuleMethodPointers[i] = ptrs;
                 }
                 catch
                 {
                     //当整个DLL只有泛型函数时就会出现这种情况
                     Console.WriteLine($"WARNING: Unable to get function pointers for {ReadStringToNull(MapVATR(codeGenModule.moduleName))}");
                     codeGenModuleMethodPointers[i] = new ulong[codeGenModule.methodPointerCount];
                 }
             }
         }
         else
         {
             methodPointers = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.methodPointers, (long)pCodeRegistration.methodPointersCount), x => (ulong)x);
         }
     }
     else
     {
         genericInsts              = Array.ConvertAll(MapVATR <ulong>(pMetadataRegistration.genericInsts, pMetadataRegistration.genericInstsCount), x => MapVATR <Il2CppGenericInst>(x));
         genericMethodPointers     = MapVATR <ulong>(pCodeRegistration.genericMethodPointers, (long)pCodeRegistration.genericMethodPointersCount);
         invokerPointers           = MapVATR <ulong>(pCodeRegistration.invokerPointers, (long)pCodeRegistration.invokerPointersCount);
         customAttributeGenerators = MapVATR <ulong>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount);
         fieldOffsets              = MapVATR <long>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount);
         //在21版本中存在两种FieldOffset,通过判断前5个数值是否为0确认是指针还是int
         isNew21 = version > 21 || (version == 21 && fieldOffsets.ToList().FindIndex(x => x > 0) == 5);
         if (!isNew21)
         {
             fieldOffsets = Array.ConvertAll(MapVATR <int>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount), x => (long)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();
             typesdic.Add(pTypes[i], types[i]);
         }
         if (version > 16)
         {
             metadataUsages = MapVATR <ulong>(pMetadataRegistration.metadataUsages, maxMetadataUsages);
         }
         if (version >= 24.2f)
         {
             var pCodeGenModules = MapVATR <ulong>(pCodeRegistration.codeGenModules, (long)pCodeRegistration.codeGenModulesCount);
             codeGenModules = new Il2CppCodeGenModule[pCodeGenModules.Length];
             codeGenModuleMethodPointers = new ulong[pCodeGenModules.Length][];
             for (int i = 0; i < pCodeGenModules.Length; i++)
             {
                 var codeGenModule = MapVATR <Il2CppCodeGenModule>(pCodeGenModules[i]);
                 codeGenModules[i] = codeGenModule;
                 try
                 {
                     var ptrs = MapVATR <ulong>(codeGenModule.methodPointers, (long)codeGenModule.methodPointerCount);
                     codeGenModuleMethodPointers[i] = ptrs;
                 }
                 catch
                 {
                     //当整个DLL只有泛型函数时就会出现这种情况
                     Console.WriteLine($"WARNING: Unable to get function pointers for {ReadStringToNull(MapVATR(codeGenModule.moduleName))}");
                     codeGenModuleMethodPointers[i] = new ulong[codeGenModule.methodPointerCount];
                 }
             }
         }
         else
         {
             methodPointers = MapVATR <ulong>(pCodeRegistration.methodPointers, (long)pCodeRegistration.methodPointersCount);
         }
     }
     //处理泛型
     genericMethodTable       = MapVATR <Il2CppGenericMethodFunctionsDefinitions>(pMetadataRegistration.genericMethodTable, pMetadataRegistration.genericMethodTableCount);
     methodSpecs              = MapVATR <Il2CppMethodSpec>(pMetadataRegistration.methodSpecs, pMetadataRegistration.methodSpecsCount);
     genericMethoddDictionary = new Dictionary <int, ulong>(genericMethodTable.Length);
     foreach (var table in genericMethodTable)
     {
         var index = methodSpecs[table.genericMethodIndex].methodDefinitionIndex;
         if (!genericMethoddDictionary.ContainsKey(index))
         {
             genericMethoddDictionary.Add(index, genericMethodPointers[table.indices.methodIndex]);
         }
     }
 }
Exemplo n.º 6
0
        public virtual void Init(ulong codeRegistration, ulong metadataRegistration)
        {
            pCodeRegistration     = MapVATR <Il2CppCodeRegistration>(codeRegistration);
            pMetadataRegistration = MapVATR <Il2CppMetadataRegistration>(metadataRegistration);
            if (Version == 24.2f)
            {
                genericMethodTable = MapVATR <Il2CppGenericMethodFunctionsDefinitions>(pMetadataRegistration.genericMethodTable, pMetadataRegistration.genericMethodTableCount);
                var genericMethodPointersCount = genericMethodTable.Max(x => x.indices.methodIndex) + 1;
                if (pCodeRegistration.reversePInvokeWrapperCount == genericMethodPointersCount)
                {
                    Version           = 24.3f;
                    codeRegistration -= Is32Bit ? 8u : 16u;
                    Console.WriteLine($"Change il2cpp version to: {Version}");
                    Console.WriteLine("Actual CodeRegistration : {0:x}", codeRegistration);
                    pCodeRegistration = MapVATR <Il2CppCodeRegistration>(codeRegistration);
                }
            }
            genericMethodPointers     = MapVATR <ulong>(pCodeRegistration.genericMethodPointers, pCodeRegistration.genericMethodPointersCount);
            invokerPointers           = MapVATR <ulong>(pCodeRegistration.invokerPointers, pCodeRegistration.invokerPointersCount);
            customAttributeGenerators = MapVATR <ulong>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount);
            if (Version > 16)
            {
                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);
                }
            }
            genericInsts            = Array.ConvertAll(MapVATR <ulong>(pMetadataRegistration.genericInsts, pMetadataRegistration.genericInstsCount), x => MapVATR <Il2CppGenericInst>(x));
            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.2f)
            {
                var pCodeGenModules = MapVATR <ulong>(pCodeRegistration.codeGenModules, pCodeRegistration.codeGenModulesCount);
                codeGenModules = new Il2CppCodeGenModule[pCodeGenModules.Length];
                codeGenModuleMethodPointers = new ulong[pCodeGenModules.Length][];
                for (int i = 0; i < pCodeGenModules.Length; i++)
                {
                    var codeGenModule = MapVATR <Il2CppCodeGenModule>(pCodeGenModules[i]);
                    codeGenModules[i] = codeGenModule;
                    try
                    {
                        var name = ReadStringToNull(MapVATR(codeGenModule.moduleName));
                        codeGenModuleMethodPointers[i] = MapVATR <ulong>(codeGenModule.methodPointers, codeGenModule.methodPointerCount);
                    }
                    catch
                    {
                        codeGenModuleMethodPointers[i] = new ulong[codeGenModule.methodPointerCount];
                    }
                }
            }
            else
            {
                methodPointers = MapVATR <ulong>(pCodeRegistration.methodPointers, pCodeRegistration.methodPointersCount);
            }
            genericMethodTable       = MapVATR <Il2CppGenericMethodFunctionsDefinitions>(pMetadataRegistration.genericMethodTable, pMetadataRegistration.genericMethodTableCount);
            methodSpecs              = MapVATR <Il2CppMethodSpec>(pMetadataRegistration.methodSpecs, pMetadataRegistration.methodSpecsCount);
            genericMethoddDictionary = new Dictionary <int, ulong>(genericMethodTable.Length);
            foreach (var table in genericMethodTable)
            {
                var index = methodSpecs[table.genericMethodIndex].methodDefinitionIndex;
                if (!genericMethoddDictionary.ContainsKey(index))
                {
                    genericMethoddDictionary.Add(index, genericMethodPointers[table.indices.methodIndex]);
                }
            }
        }
Exemplo n.º 7
0
 public virtual void Init(ulong codeRegistration, ulong metadataRegistration)
 {
     if (is32Bit)
     {
         pCodeRegistration         = MapVATR <Il2CppCodeRegistration>(codeRegistration);
         pMetadataRegistration     = MapVATR <Il2CppMetadataRegistration>(metadataRegistration);
         methodPointers            = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.methodPointers, (long)pCodeRegistration.methodPointersCount), x => (ulong)x);
         genericMethodPointers     = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.genericMethodPointers, (long)pCodeRegistration.genericMethodPointersCount), x => (ulong)x);
         invokerPointers           = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.invokerPointers, (long)pCodeRegistration.invokerPointersCount), x => (ulong)x);
         customAttributeGenerators = Array.ConvertAll(MapVATR <uint>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount), x => (ulong)x);
         fieldOffsets = Array.ConvertAll(MapVATR <int>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount), x => (long)x);
         //TODO 在21版本中存在两种FieldOffset,通过判断前5个数值是否为0确认是指针还是int
         isNew21 = version > 21 || (version == 21 && fieldOffsets.ToList().FindIndex(x => x > 0) == 5);
         var ptypes = MapVATR <uint>(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();
             typesdic.Add(ptypes[i], types[i]);
         }
         if (version > 16)
         {
             metadataUsages = Array.ConvertAll(MapVATR <uint>(pMetadataRegistration.metadataUsages, maxMetadataUsages), x => (ulong)x);
         }
         //处理泛型
         genericMethodTable       = MapVATR <Il2CppGenericMethodFunctionsDefinitions>(pMetadataRegistration.genericMethodTable, pMetadataRegistration.genericMethodTableCount);
         methodSpecs              = MapVATR <Il2CppMethodSpec>(pMetadataRegistration.methodSpecs, pMetadataRegistration.methodSpecsCount);
         genericMethoddDictionary = new Dictionary <int, ulong>(genericMethodTable.Length);
         foreach (var table in genericMethodTable)
         {
             var index = methodSpecs[table.genericMethodIndex].methodDefinitionIndex;
             if (!genericMethoddDictionary.ContainsKey(index))
             {
                 genericMethoddDictionary.Add(index, genericMethodPointers[table.indices.methodIndex]);
             }
         }
     }
     else
     {
         pCodeRegistration         = MapVATR <Il2CppCodeRegistration>(codeRegistration);
         pMetadataRegistration     = MapVATR <Il2CppMetadataRegistration>(metadataRegistration);
         methodPointers            = MapVATR <ulong>(pCodeRegistration.methodPointers, (long)pCodeRegistration.methodPointersCount);
         genericMethodPointers     = MapVATR <ulong>(pCodeRegistration.genericMethodPointers, (long)pCodeRegistration.genericMethodPointersCount);
         invokerPointers           = MapVATR <ulong>(pCodeRegistration.invokerPointers, (long)pCodeRegistration.invokerPointersCount);
         customAttributeGenerators = MapVATR <ulong>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount);
         fieldOffsets = MapVATR <long>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount);
         //TODO 在21版本中存在两种FieldOffset,通过判断前5个数值是否为0确认是指针还是int
         isNew21 = version > 21 || (version == 21 && fieldOffsets.ToList().FindIndex(x => x > 0) == 5);
         if (!isNew21)
         {
             fieldOffsets = Array.ConvertAll(MapVATR <int>(pMetadataRegistration.fieldOffsets, pMetadataRegistration.fieldOffsetsCount), x => (long)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();
             typesdic.Add(ptypes[i], types[i]);
         }
         if (version > 16)
         {
             metadataUsages = MapVATR <ulong>(pMetadataRegistration.metadataUsages, maxMetadataUsages);
         }
         //处理泛型
         genericMethodTable       = MapVATR <Il2CppGenericMethodFunctionsDefinitions>(pMetadataRegistration.genericMethodTable, pMetadataRegistration.genericMethodTableCount);
         methodSpecs              = MapVATR <Il2CppMethodSpec>(pMetadataRegistration.methodSpecs, pMetadataRegistration.methodSpecsCount);
         genericMethoddDictionary = new Dictionary <int, ulong>(genericMethodTable.Length);
         foreach (var table in genericMethodTable)
         {
             var index = methodSpecs[table.genericMethodIndex].methodDefinitionIndex;
             if (!genericMethoddDictionary.ContainsKey(index))
             {
                 genericMethoddDictionary.Add(index, genericMethodPointers[table.indices.methodIndex]);
             }
         }
     }
 }
Exemplo n.º 8
0
        public virtual void Init(ulong codeRegistration, ulong metadataRegistration)
        {
            pCodeRegistration = MapVATR <Il2CppCodeRegistration>(codeRegistration);
            if (Version == 24.2f)
            {
                if (pCodeRegistration.codeGenModules == 0) //TODO
                {
                    Version = 24.3f;
                    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);
            customAttributeGenerators = MapVATR <ulong>(pCodeRegistration.customAttributeGenerators, pCodeRegistration.customAttributeCount);
            if (Version > 16)
            {
                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.2f)
            {
                var pCodeGenModules = MapVATR <ulong>(pCodeRegistration.codeGenModules, pCodeRegistration.codeGenModulesCount);
                codeGenModules = new Il2CppCodeGenModule[pCodeGenModules.Length];
                codeGenModuleMethodPointers = new ulong[pCodeGenModules.Length][];
                for (int i = 0; i < pCodeGenModules.Length; i++)
                {
                    var codeGenModule = MapVATR <Il2CppCodeGenModule>(pCodeGenModules[i]);
                    codeGenModules[i] = codeGenModule;
                    try
                    {
                        var name = ReadStringToNull(MapVATR(codeGenModule.moduleName));
                        codeGenModuleMethodPointers[i] = MapVATR <ulong>(codeGenModule.methodPointers, codeGenModule.methodPointerCount);
                    }
                    catch
                    {
                        codeGenModuleMethodPointers[i] = new ulong[codeGenModule.methodPointerCount];
                    }
                }
            }
            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]);
            }
        }