Ejemplo n.º 1
0
        public AsyncMethodProcessor(MethodDefinition method, TracerFunctions funcs)
        {
            this.method = method;
            asyncIndex  = Count++;

            name = method.FullName;

            tracerFunctions = funcs;
        }
Ejemplo n.º 2
0
        public void Implant(string path)
        {
            var dir     = Path.GetDirectoryName(path);
            var name    = Path.GetFileName(path);
            var pdb     = Path.Join(dir, $"{name}.pdb");
            var mdb     = Path.Join(dir, $"{name}.mdb");
            var IsDebug = File.Exists(pdb) || File.Exists(mdb);

            Resolver.AddSearchDirectory(dir);

            var rParam = new ReaderParameters
            {
                AssemblyResolver = Resolver,
                ReadWrite        = true,
                ReadSymbols      = IsDebug
            };

            using (var asmDef = AssemblyDefinition.ReadAssembly(path, rParam))
            {
                var funcs = new TracerFunctions
                {
                    Begin      = asmDef.MainModule.ImportReference(TTBeginDef),
                    End        = asmDef.MainModule.ImportReference(TTEndDef),
                    BeginAsync = asmDef.MainModule.ImportReference(TTBeginAsyncDef),
                    EndAsync   = asmDef.MainModule.ImportReference(TTEndAsyncDef)
                };
                foreach (var module in asmDef.Modules)
                {
                    foreach (var type in module.Types)
                    {
                        if (!FilterNamespace(type.Namespace) || !FilterType(type.Name))
                        {
                            continue;
                        }
                        foreach (var method in type.ConcreteMethods())
                        {
                            if (!FilterMethod(method.Name))
                            {
                                continue;
                            }

                            Implant(method, funcs);
                        }
                    }
                }

                asmDef.Write(new WriterParameters {
                    WriteSymbols = IsDebug
                });
            }
        }
Ejemplo n.º 3
0
        void Implant(MethodDefinition md, TracerFunctions funcs)
        {
            Console.WriteLine($"Process.... [{md.Module.Assembly.Name.Name}] {md.DeclaringType.Namespace}::{md.DeclaringType.Name}.{md.Name}");

            if (md.IsYield())
            {
                Console.WriteLine($"           Skipping '{md.FullName}' since methods that yield are not supported.");
            }

            if (md.IsAsync())
            {
                new AsyncMethodProcessor(md, funcs).Process();
            }
            else
            {
                new MethodProcessor(md, funcs).Process();
            }
        }
Ejemplo n.º 4
0
 public MethodProcessor(MethodDefinition method, TracerFunctions funcs)
 {
     this.method     = method;
     name            = method.FullName;
     tracerFunctions = funcs;
 }