public static void Go(string[] targetPaths) { foreach (string targetPath in targetPaths) { OPInject.AddTarget(targetPath); } OPInject.InstrumentTargets(); }
static void InstrumentTarget(AssemblyDefinition targetAsmDef) { ModuleDefinition targetModDef = targetAsmDef.MainModule; TypeReference tmpTR; if (!targetModDef.TryGetTypeReference("MInt.MStats", out tmpTR)) { throw new SystemException("{0} does not reference MInt.MStats"); } TypeDefinition mstatsTD = tmpTR.Resolve(); TypeReference mstatsTR = targetModDef.ImportReference(mstatsTD); MethodDefinition setupMD = ResolveMethod(mstatsTD, "Setup"); MethodDefinition startSpanMD = ResolveMethod(mstatsTD, "StartSpan"); MethodDefinition endSpanMD = ResolveMethod(mstatsTD, "EndSpan"); MethodReference setupMR = targetModDef.ImportReference(setupMD); MethodReference startSpanMR = targetModDef.ImportReference(startSpanMD); MethodReference endSpanMR = targetModDef.ImportReference(endSpanMD); foreach (TypeDefinition td in targetModDef.Types) { if (td.Methods.Count == 0) { continue; } Console.WriteLine("--------------------------------------------------------------------"); foreach (MethodDefinition md in td.Methods) { //string methodSig = md.FullName; string methodSig = MethodSignature(md); if (OPInject.ILMethodHasCall(md, setupMR)) { Console.WriteLine("{0} -- skipping intrumentation (setup call)", methodSig); continue; } long methodID = MethodSignatures.Count; MethodSignatures.Add(methodSig); OPInject.ILMethodIntrument(md, methodID, startSpanMR, endSpanMR); Console.WriteLine("{0} -- instrumentation ID: {1}", methodSig, methodID); } Console.Write("\n"); } }