>
> Yes, of course, this is my current code:
>

using Mono.Cecil;
using Mono.Cecil.Cil;
using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Contexts;
using System.Text;

namespace ProxyCalling
{
    class ProxyOutlining
    {

        public static void Process(AssemblyDefinition AssemblyDef)
        {
            FindReferences(AssemblyDef);
        }

        private static List<MethodReference> ReferenceList = new 
List<MethodReference>();

        private static void FindReferences(AssemblyDefinition AssemblyDef)
        {
            foreach (TypeDefinition TypeDef in 
AssemblyDef.MainModule.GetTypes())
            {
                for (int i = 0; i < TypeDef.Methods.Count; i++)
                {
                    MethodDefinition MethodDef = TypeDef.Methods[i];

                    if (!MethodDef.IsConstructor)
                    {
                        foreach (Instruction InstructionDef in 
MethodDef.Body.Instructions)
                        {
                            if (InstructionDef.OpCode == OpCodes.Call)
                            {
                                if (InstructionDef.Operand is 
MethodReference)
                                {
                                    MethodReference MethodRef = 
(MethodReference)InstructionDef.Operand;
                                    if (!ReferenceList.Contains(MethodRef))
                                    {
                                        Console.WriteLine("Name : " + 
MethodDef.Name);
                                        CreateMethod(TypeDef, 
MethodRef.Parameters.ToArray(), MethodRef.ReturnType, MethodRef);
                                        ReferenceList.Add(MethodRef);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }


        private static Random rnd = new Random();

        private static string RandomName()
        {
            StringBuilder StrBuilder = new StringBuilder();
            char[] charset = "abcdefg123".ToCharArray();

            for (int i = 0; i < charset.Length; i++)
            {
                int rndindex = rnd.Next(charset.Length);
                StrBuilder.Append(charset[rndindex]);
            }
            return StrBuilder.ToString();
        }


        private static void CreateMethod(TypeDefinition TypeDef, 
ParameterDefinition[] Params, TypeReference MethodDefRetType, 
MethodReference MethodRef)
        {
            Console.WriteLine("DeclaringType : " + 
MethodRef.DeclaringType.ToString());
            Console.WriteLine("MethodName : " + MethodRef.Name);

            if (MethodDefRetType != null)
            {
                MethodDefinition NewMethod = new 
MethodDefinition(RandomName(), MethodAttributes.Static, MethodDefRetType);
                if (Params.Length > 0)
                {
                    for (int i = 1; i < MethodRef.Parameters.Count; i++)
                    {
                        ParameterDefinition parameter = new 
ParameterDefinition(MethodRef.Parameters[i].ParameterType);
                        NewMethod.Parameters.Add(parameter);
                        
NewMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg, 
parameter));
                        i++;
                    }
                }

                
NewMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Call, 
TypeDef.Module.Import(MethodRef)));
                
NewMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));

                TypeDef.Methods.Add(NewMethod);
                Console.WriteLine("Added a new method...");
            }
        }
    }
}


 And as testapp i just use a little consoleapplication printing a few 
strings and showing some messageboxes...
So it is still not adding the arguments correctly, and i dont know why :/

-- 
-- 
--
mono-cecil
--- 
You received this message because you are subscribed to the Google Groups 
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to