Example #1
0
        public AssemblyDump()
        {
            // Initialize local variables
            uint size = 0;

            // Setup variables
            _index      = 0;
            _assemblies = NativeSDK.PtrToArry <IntPtr>(il2cpp_domain_get_assemblies(NativeSDK.atironya_get_il2cpp_domain(), ref size), size);
        }
Example #2
0
    private static TypeReference GetTypeReference(MemberReference member, IntPtr target)
    {
        ModuleDefinition module     = member.Module;
        IL2CPPType       il2cppType = (IL2CPPType)Marshal.PtrToStructure(target, typeof(IL2CPPType));

        switch ((IL2CPPTypes)il2cppType.type)
        {
        case IL2CPPTypes.IL2CPP_TYPE_OBJECT:
            return(module.ImportReference(typeof(object)));

        case IL2CPPTypes.IL2CPP_TYPE_VOID:
            return(module.ImportReference(typeof(void)));

        case IL2CPPTypes.IL2CPP_TYPE_BOOLEAN:
            return(module.ImportReference(typeof(bool)));

        case IL2CPPTypes.IL2CPP_TYPE_CHAR:
            return(module.ImportReference(typeof(char)));

        case IL2CPPTypes.IL2CPP_TYPE_I1:
            return(module.ImportReference(typeof(sbyte)));

        case IL2CPPTypes.IL2CPP_TYPE_U1:
            return(module.ImportReference(typeof(byte)));

        case IL2CPPTypes.IL2CPP_TYPE_I2:
            return(module.ImportReference(typeof(short)));

        case IL2CPPTypes.IL2CPP_TYPE_U2:
            return(module.ImportReference(typeof(ushort)));

        case IL2CPPTypes.IL2CPP_TYPE_I4:
            return(module.ImportReference(typeof(int)));

        case IL2CPPTypes.IL2CPP_TYPE_U4:
            return(module.ImportReference(typeof(uint)));

        case IL2CPPTypes.IL2CPP_TYPE_I:
            return(module.ImportReference(typeof(IntPtr)));

        case IL2CPPTypes.IL2CPP_TYPE_U:
            return(module.ImportReference(typeof(UIntPtr)));

        case IL2CPPTypes.IL2CPP_TYPE_I8:
            return(module.ImportReference(typeof(long)));

        case IL2CPPTypes.IL2CPP_TYPE_U8:
            return(module.ImportReference(typeof(ulong)));

        case IL2CPPTypes.IL2CPP_TYPE_R4:
            return(module.ImportReference(typeof(float)));

        case IL2CPPTypes.IL2CPP_TYPE_R8:
            return(module.ImportReference(typeof(double)));

        case IL2CPPTypes.IL2CPP_TYPE_STRING:
            return(module.ImportReference(typeof(string)));

        case IL2CPPTypes.IL2CPP_TYPE_TYPEDBYREF:
            return(module.ImportReference(typeof(TypedReference)));

        case IL2CPPTypes.IL2CPP_TYPE_CLASS:
        case IL2CPPTypes.IL2CPP_TYPE_VALUETYPE:
            TypeDefinition type = GetOrDumpType(NativeSDK.il2cpp_class_from_il2cpp_type(target));
            if (type == null)
            {
                return(null);
            }

            return(module.ImportReference(type));

        case IL2CPPTypes.IL2CPP_TYPE_ARRAY:
            IL2CPPArrayType arrayType = (IL2CPPArrayType)Marshal.PtrToStructure(il2cppType.value, typeof(IL2CPPArrayType));

            return(new ArrayType(GetTypeReference(member, arrayType.type), arrayType.rank));

        case IL2CPPTypes.IL2CPP_TYPE_SZARRAY:
            return(new ArrayType(GetTypeReference(member, il2cppType.value)));

        case IL2CPPTypes.IL2CPP_TYPE_GENERICINST:
            IL2CPPGenericClass genericClass = (IL2CPPGenericClass)Marshal.PtrToStructure(il2cppType.value, (typeof(IL2CPPGenericClass)));

            TypeDefinition genericType = GetOrDumpType(genericClass.cached_class);
            if (genericType == null)
            {
                return(null);
            }

            GenericInstanceType genericInstanceType = new GenericInstanceType(module.ImportReference(genericType));
            IL2CPPGenericInst   genericInst         = (IL2CPPGenericInst)Marshal.PtrToStructure(genericClass.context.class_inst, typeof(IL2CPPGenericInst));
            IntPtr[]            ptrArray            = NativeSDK.PtrToArry <IntPtr>(genericInst.type_argv, genericInst.type_argc);

            foreach (IntPtr ptr in ptrArray)
            {
                genericInstanceType.GenericArguments.Add(GetTypeReference(member, ptr));
            }
            return(genericInstanceType);

        case IL2CPPTypes.IL2CPP_TYPE_PTR:
            return(new PointerType(GetTypeReference(member, il2cppType.value)));

        default:
            return(module.ImportReference(typeof(void)));
        }
    }