コード例 #1
0
        public static IntPtr GetIl2CppClass(string assemblyName, string namespaze, string className)
        {
            if (!ourImagesMap.TryGetValue(assemblyName, out var image))
            {
                LogSupport.Log($"Assembly {assemblyName} is not registered in il2cpp");
                return(IntPtr.Zero);
            }

            var clazz = il2cpp_class_from_name(image, namespaze, className);

            return(clazz);
        }
コード例 #2
0
        static IL2CPP()
        {
            var domain = il2cpp_domain_get();

            if (domain == IntPtr.Zero)
            {
                LogSupport.Log("No il2cpp domain found; sad!");
                return;
            }
            uint assembliesCount = 0;
            var  assemblies      = il2cpp_domain_get_assemblies(domain, ref assembliesCount);

            for (var i = 0; i < assembliesCount; i++)
            {
                var image = il2cpp_assembly_get_image(assemblies[i]);
                var name  = Marshal.PtrToStringAnsi(il2cpp_image_get_name(image));
                ourImagesMap[name] = image;
            }
        }
コード例 #3
0
        public static IntPtr GetIl2CppMethod(IntPtr clazz, string methodName, params string[] argTypes)
        {
            if (clazz == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            for (var index = 0; index < argTypes.Length; index++)
            {
                var argType = argTypes[index];
                argTypes[index] = Regex.Replace(argType, "\\`\\d+", "").Replace('/', '.');
            }

            var    methodsSeen = 0;
            var    lastMethod  = IntPtr.Zero;
            IntPtr iter        = IntPtr.Zero;
            IntPtr method;

            while ((method = il2cpp_class_get_methods(clazz, ref iter)) != IntPtr.Zero)
            {
                if (Marshal.PtrToStringAnsi(il2cpp_method_get_name(method)) != methodName)
                {
                    continue;
                }

                if (il2cpp_method_get_param_count(method) != argTypes.Length)
                {
                    continue;
                }

                methodsSeen++;
                lastMethod = method;

                var badType = false;
                for (var i = 0; i < argTypes.Length; i++)
                {
                    var paramType = il2cpp_method_get_param(method, (uint)i);
                    var typeName  = Marshal.PtrToStringAnsi(il2cpp_type_get_name(paramType));
                    if (typeName != argTypes[i])
                    {
                        badType = true;
                        break;
                    }
                }

                if (badType)
                {
                    continue;
                }

                return(method);
            }

            if (methodsSeen == 1)
            {
                return(lastMethod);
            }

            LogSupport.Log($"Unable to find method {Marshal.PtrToStringAnsi(il2cpp_class_get_name(clazz))}::{methodName}; signature follows");
            foreach (var argType in argTypes)
            {
                LogSupport.Log($"    {argType}");
            }
            LogSupport.Log("Available methods of this name follow:");
            iter = IntPtr.Zero;
            while ((method = il2cpp_class_get_methods(clazz, ref iter)) != IntPtr.Zero)
            {
                if (Marshal.PtrToStringAnsi(il2cpp_method_get_name(method)) != methodName)
                {
                    continue;
                }

                // if(il2cpp_method_get_param_count(method) != argTypes.Length)
                // continue;

                var nParams = il2cpp_method_get_param_count(method);
                LogSupport.Log("Method starts");
                for (var i = 0; i < nParams; i++)
                {
                    var paramType = il2cpp_method_get_param(method, (uint)i);
                    var typeName  = Marshal.PtrToStringAnsi(il2cpp_type_get_name(paramType));
                    LogSupport.Log($"    {typeName}");
                }

                return(method);
            }

            return(IntPtr.Zero);
        }