Beispiel #1
0
    public static Delegate CreateDelegate(Type type, MonoMethod monoMethod)
    {
        if (monoMethod.target == null || string.IsNullOrEmpty(monoMethod.method))
        {
            return(null);
        }

        return(Delegate.CreateDelegate(type, monoMethod.target, monoMethod.method, false, false));
    }
Beispiel #2
0
        /*
         * public override object Invoke (object obj, object[] parameters) {
         *      CreateDynMethod ();
         *      if (method == null)
         *              method = new MonoMethod (mhandle);
         *      return method.Invoke (obj, parameters);
         * }
         */

        public override object Invoke(object obj, BindingFlags invokeAttr,
                                      Binder binder, object[] parameters,
                                      CultureInfo culture)
        {
            CreateDynMethod();
            if (method == null)
            {
                method = new MonoMethod(mhandle);
            }
            return(method.Invoke(obj, parameters));
        }
Beispiel #3
0
        private RuntimeMethodHandle(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            MonoMethod monoMethod = (MonoMethod)info.GetValue("MethodObj", typeof(MonoMethod));

            this.value = monoMethod.MethodHandle.Value;
            if (this.value == IntPtr.Zero)
            {
                throw new SerializationException(Locale.GetText("Insufficient state."));
            }
        }
Beispiel #4
0
        RuntimeMethodHandle(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            MonoMethod mm = ((MonoMethod)info.GetValue("MethodObj", typeof(MonoMethod)));

            value = mm.MethodHandle.Value;
            if (value == IntPtr.Zero)
            {
                throw new SerializationException("Insufficient state.");
            }
        }
Beispiel #5
0
        /*
         * public override object Invoke (object obj, object[] parameters) {
         *      CreateDynMethod ();
         *      if (method == null)
         *              method = new MonoMethod (mhandle);
         *      return method.Invoke (obj, parameters);
         * }
         */

        public override object Invoke(object obj, BindingFlags invokeAttr,
                                      Binder binder, object[] parameters,
                                      CultureInfo culture)
        {
            try {
                CreateDynMethod();
                if (method == null)
                {
                    method = new MonoMethod(mhandle);
                }

                return(method.Invoke(obj, parameters));
            }
            catch (MethodAccessException mae) {
                throw new TargetInvocationException("Method cannot be invoked.", mae);
            }
        }
Beispiel #6
0
        internal void InitMessage(MonoMethod method, object [] out_args)
        {
            this.method = method;
            ParameterInfo[] paramInfo   = method.GetParametersInternal();
            int             param_count = paramInfo.Length;

            args        = new object[param_count];
            arg_types   = new byte[param_count];
            asyncResult = null;
            call_type   = CallType.Sync;
            names       = new string[param_count];
            for (int i = 0; i < param_count; i++)
            {
                names[i] = paramInfo[i].Name;
            }
            bool hasOutArgs = out_args != null;
            int  j          = 0;

            for (int i = 0; i < param_count; i++)
            {
                byte arg_type;
                bool isOut = paramInfo[i].IsOut;
                if (paramInfo[i].ParameterType.IsByRef)
                {
                    if (hasOutArgs)
                    {
                        args[i] = out_args[j++];
                    }
                    arg_type = 2;                     // OUT
                    if (!isOut)
                    {
                        arg_type |= 1;                         // INOUT
                    }
                }
                else
                {
                    arg_type = 1;                     // IN
                    if (isOut)
                    {
                        arg_type |= 4;                         // IN, COPY OUT
                    }
                }
                arg_types[i] = arg_type;
            }
        }
        /// <summary>Invokes the dynamic method using the specified parameters, under the constraints of the specified binder, with the specified culture information.</summary>
        /// <returns>A <see cref="T:System.Object" /> containing the return value of the invoked method.</returns>
        /// <param name="obj">This parameter is ignored for dynamic methods, because they are static. Specify null. </param>
        /// <param name="invokeAttr">A bitwise combination of <see cref="T:System.Reflection.BindingFlags" /> values.</param>
        /// <param name="binder">A <see cref="T:System.Reflection.Binder" /> object that enables the binding, coercion of argument types, invocation of members, and retrieval of <see cref="T:System.Reflection.MemberInfo" /> objects through reflection. If <paramref name="binder" /> is null, the default binder is used. For more details, see <see cref="T:System.Reflection.Binder" />. </param>
        /// <param name="parameters">An argument list. This is an array of arguments with the same number, order, and type as the parameters of the method to be invoked. If there are no parameters this parameter should be null. </param>
        /// <param name="culture">An instance of <see cref="T:System.Globalization.CultureInfo" /> used to govern the coercion of types. If this is null, the <see cref="T:System.Globalization.CultureInfo" /> for the current thread is used. For example, this information is needed to correctly convert a <see cref="T:System.String" /> that represents 1000 to a <see cref="T:System.Double" /> value, because 1000 is represented differently by different cultures. </param>
        /// <exception cref="T:System.NotSupportedException">The <see cref="F:System.Reflection.CallingConventions.VarArgs" /> calling convention is not supported.</exception>
        /// <exception cref="T:System.Reflection.TargetParameterCountException">The number of elements in <paramref name="parameters" /> does not match the number of parameters in the dynamic method.</exception>
        /// <exception cref="T:System.ArgumentException">The type of one or more elements of <paramref name="parameters" /> does not match the type of the corresponding parameter of the dynamic method.</exception>
        /// <exception cref="T:System.Reflection.TargetInvocationException">The dynamic method is associated with a module, is not anonymously hosted, and was constructed with <paramref name="skipVisibility" /> set to false, but the dynamic method accesses members that are not public or internal (Friend in Visual Basic).-or-The dynamic method is anonymously hosted and was constructed with <paramref name="skipVisibility" /> set to false, but it accesses members that are not public.</exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="MemberAccess" />
        /// </PermissionSet>
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            object result;

            try
            {
                this.CreateDynMethod();
                if (this.method == null)
                {
                    this.method = new MonoMethod(this.mhandle);
                }
                result = this.method.Invoke(obj, parameters);
            }
            catch (MethodAccessException inner)
            {
                throw new TargetInvocationException("Method cannot be invoked.", inner);
            }
            return(result);
        }
Beispiel #8
0
 internal extern void InitMessage(MonoMethod method, object [] out_args);
Beispiel #9
0
            private void worker_DoWork(object sender, DoWorkEventArgs e)
            {
                MainForm.RtbILSpy.BeginInvoke(new MethodInvoker(() =>
                {
                    ILSpyHandler.Clear();
                    MainForm.RtbILSpy.Text = Environment.NewLine + "Decompiling..." + Environment.NewLine +
                                             "First time might take a while.";
                }));

                try
                {
                    AssemblyDefinition assembly = Translate(MainForm.CurrentAssembly.ManifestModule);

                    if (assembly == null)
                        throw new Exception("Could not write assembly to stream!");

                    var dnMethod = new MonoMethod(MainForm.CurrentAssembly.Method);
                    object method = dnMethod.Method(assembly);

                    if (method == null)
                        return;

                    var mtp = (IMetadataTokenProvider) method;
                    method = assembly.MainModule.LookupToken(mtp.MetadataToken);

                    if (method == null || string.IsNullOrEmpty(method.ToString()))
                    {
                        MainForm.RtbILSpy.BeginInvoke(new MethodInvoker(
                            () =>
                            {
                                ILSpyHandler.Clear();
                                MainForm.RtbILSpy.Text = Environment.NewLine +
                                                         "Could not find member by Metadata Token!";
                            }));

                        return;
                    }

                    DefaultAssemblyResolver bar = GlobalAssemblyResolver.Instance;
                    bool savedRaiseResolveException = true;
                    try
                    {
                        if (bar != null)
                        {
                            savedRaiseResolveException = bar.RaiseResolveException;
                            bar.RaiseResolveException = false;
                        }

                        var il = new ILSpyDecompiler();
                        string source = il.Decompile(method);

                        MainForm.RtbILSpy.BeginInvoke(new MethodInvoker(() =>
                        {
                            ILSpyHandler.Clear();
                            MainForm.RtbILSpy.Rtf = source;
                        }));
                    }
                    finally
                    {
                        if (bar != null)
                            bar.RaiseResolveException = savedRaiseResolveException;
                    }
                }
                catch (Exception o)
                {
                    MainForm.RtbILSpy.BeginInvoke(new MethodInvoker(
                        () =>
                        {
                            ILSpyHandler.Clear();
                            MainForm.RtbILSpy.Text = Environment.NewLine + "Decompilation unsuccessful!" +
                                                     Environment.NewLine +
                                                     Environment.NewLine + o.Message;
                        }));
                }
            }
Beispiel #10
0
 internal void InitMessage(MonoMethod method, object [] out_args)
 {
     throw new System.NotImplementedException();
 }
Beispiel #11
0
            private void worker_DoWork(object sender, DoWorkEventArgs e)
            {
                MainForm.RtbILSpy.BeginInvoke(new MethodInvoker(() =>
                {
                    ILSpyHandler.Clear();
                    MainForm.RtbILSpy.Text = Environment.NewLine + "Decompiling..." + Environment.NewLine +
                                             "First time might take a while.";
                }));

                try
                {
                    AssemblyDefinition assembly = Translate(MainForm.CurrentAssembly.ManifestModule);

                    if (assembly == null)
                    {
                        throw new Exception("Could not write assembly to stream!");
                    }

                    var    dnMethod = new MonoMethod(MainForm.CurrentAssembly.Method);
                    object method   = dnMethod.Method(assembly);

                    if (method == null)
                    {
                        return;
                    }

                    var mtp = (IMetadataTokenProvider)method;
                    method = assembly.MainModule.LookupToken(mtp.MetadataToken);

                    if (method == null || string.IsNullOrEmpty(method.ToString()))
                    {
                        MainForm.RtbILSpy.BeginInvoke(new MethodInvoker(
                                                          () =>
                        {
                            ILSpyHandler.Clear();
                            MainForm.RtbILSpy.Text = Environment.NewLine +
                                                     "Could not find member by Metadata Token!";
                        }));

                        return;
                    }

                    DefaultAssemblyResolver bar     = GlobalAssemblyResolver.Instance;
                    bool savedRaiseResolveException = true;
                    try
                    {
                        if (bar != null)
                        {
                            savedRaiseResolveException = bar.RaiseResolveException;
                            bar.RaiseResolveException  = false;
                        }

                        var    il     = new ILSpyDecompiler();
                        string source = il.Decompile(method);

                        MainForm.RtbILSpy.BeginInvoke(new MethodInvoker(() =>
                        {
                            ILSpyHandler.Clear();
                            MainForm.RtbILSpy.Rtf = source;
                        }));
                    }
                    finally
                    {
                        if (bar != null)
                        {
                            bar.RaiseResolveException = savedRaiseResolveException;
                        }
                    }
                }
                catch (Exception o)
                {
                    MainForm.RtbILSpy.BeginInvoke(new MethodInvoker(
                                                      () =>
                    {
                        ILSpyHandler.Clear();
                        MainForm.RtbILSpy.Text = Environment.NewLine + "Decompilation unsuccessful!" +
                                                 Environment.NewLine +
                                                 Environment.NewLine + o.Message;
                    }));
                }
            }
Beispiel #12
0
        protected MonoMethod GetMonoMethod(MethodHashEntry hash, int index, byte[] contents)
        {
            ensure_sources ();
            if (File == null)
                return null;
            MonoMethod method = (MonoMethod) method_hash [hash];
            if (method == null) {
                MonoMethodSource source = GetMethodSource (index);
                method = new MonoMethod (
                    this, source, hash.Domain, source.Entry, source.Method);
                method_hash.Add (hash, method);
            }

            if (!method.IsLoaded) {
                TargetBinaryReader reader = new TargetBinaryReader (contents, TargetMemoryInfo);
                method.Load (reader, TargetMemoryInfo.AddressDomain);
            }

            return method;
        }
Beispiel #13
0
            public MonoMethodLineNumberTable(MonoSymbolFile file, MonoMethod method,
							  MethodSource source, C.MethodEntry entry,
							  JitLineNumberEntry[] jit_lnt)
                : base(file, method)
            {
                this.method = method;
                this.entry = entry;
                this.line_numbers = jit_lnt;
            }
Beispiel #14
0
            public static MonoCodeBlock[] CreateBlocks(MonoMethod method,
								    MethodAddress address,
								    C.CodeBlockEntry[] the_blocks,
								    out List<MonoCodeBlock> root_blocks)
            {
                MonoCodeBlock[] blocks = new MonoCodeBlock [the_blocks.Length];
                for (int i = 0; i < blocks.Length; i++) {
                    Block.Type type = (Block.Type) the_blocks [i].BlockType;
                    int start = find_address (address, the_blocks [i].StartOffset);
                    int end = find_address (address, the_blocks [i].EndOffset);
                    blocks [i] = new MonoCodeBlock (i, type, start, end);
                }

                root_blocks = new List<MonoCodeBlock> ();

                for (int i = 0; i < blocks.Length; i++) {
                    if (the_blocks [i].Parent < 0)
                        root_blocks.Add (blocks [i]);
                    else {
                        MonoCodeBlock parent = blocks [the_blocks [i].Parent - 1];
                        blocks [i].Parent = parent;
                        parent.AddChildBlock (blocks [i]);
                    }
                }

                return blocks;
            }
Beispiel #15
0
 public static Delegate CreateDelegate <T>(MonoMethod monoMethod)
 {
     return(CreateDelegate(typeof(T), monoMethod));
 }