/// <summary> /// This takes the types loaded in LoadTypes and try to map them /// in the target module using a fuzzy search. /// </summary> /// <param name="currentModule"></param> /// <returns></returns> public double MapSourceInDestination(ModuleDef currentModule) { Contract.Ensures(typesLoadedCorrectly); double step = 1.0 / sourceMap.Count; double returnValue = 0.0; foreach (var v in sourceMap) { Debug.Assert(v.matchingMethods.Count == 1); var currentSimilarMethods = BodyComparison.GetSimilarMethods(currentModule, v.matchingMethods[0], true, fuzzyThreshold); if (currentSimilarMethods.Any()) { returnValue += step; PatternMatchingInfo pmToAdd = new PatternMatchingInfo() { @namespace = v.@namespace, name = v.name, module = v.module, matchingMethods = currentSimilarMethods.ToList() }; destinationMap.Add(pmToAdd); } } return(returnValue); }
static public void FindAndReplaceWithResult(List <MethodDef> toFind, ModuleDefMD whereToFind, Dictionary <string, MethodInfo> usableType, object instance) { List <MethodDef> methodsToCopy = new List <MethodDef>(); toFind.ForEach(x => methodsToCopy.AddRange(BodyComparison.GetSimilarMethods(whereToFind, x, true, 0.70).ToList())); foreach (var v in toFind) { foreach (var toReplace in BodyComparison.GetSimilarMethods(whereToFind, v, true, 0.70)) { foreach (var currentType in AllTypesHelper.Types(whereToFind.Types)) { foreach (var currentMethod in currentType.Methods) { if (!currentMethod.HasBody) { continue; } for (var i = 0; i < currentMethod.Body.Instructions.Count; ++i) { if (currentMethod.Body.Instructions[i].Operand == null) { continue; } if (currentMethod.Body.Instructions[i].Operand is MethodDef && currentMethod.Body.Instructions[i].Operand == toReplace) { if (toReplace.Body.Instructions[i].OpCode == OpCodes.Call) { } } } } } } } }