Skip to content

Instantly share code, notes, and snippets.

@sir-wabbit
Created November 26, 2014 05:03
Show Gist options
  • Select an option

  • Save sir-wabbit/6d75832449bf742dffd1 to your computer and use it in GitHub Desktop.

Select an option

Save sir-wabbit/6d75832449bf742dffd1 to your computer and use it in GitHub Desktop.
public void Match(AssemblyDefinition first, AssemblyDefinition second)
{
Contract.Requires<ArgumentNullException>(first != null);
Contract.Requires<ArgumentNullException>(second != null);
if (first.Modules.Count > 1 || second.Modules.Count > 1)
throw new NotImplementedException("Assemblies with more than one module are not supported yet.");
Match(first.MainModule, second.MainModule);
}
private void Match(ModuleDefinition first, ModuleDefinition second)
{
Contract.Requires<ArgumentNullException>(first != null);
Contract.Requires<ArgumentNullException>(second != null);
var typeMap = new Dictionary<TypeDefinition, TypeDefinition>();
var stack = new Stack<Tuple<List<TypeDefinition>, List<TypeDefinition>>>();
stack.Push(Tuple.Create(first.Types.ToList(), second.Types.ToList()));
while (stack.Count > 0)
{
var q = stack.Pop();
foreach(var t1 in q.Item1)
foreach (var t2 in q.Item2)
if (t1.FullName == t2.FullName)
{
typeMap[t2] = t1;
Match(t1, t2);
stack.Push(Tuple.Create(t1.NestedTypes.ToList(), t2.NestedTypes.ToList()));
}
}
}
private IEnumerable<IMemberDefinition> GetMembers(TypeDefinition t)
{
return t.Methods.Cast<IMemberDefinition>()
.Concat(t.Events)
.Concat(t.Fields)
.Concat(t.Properties);
}
private void Match(TypeDefinition t1, TypeDefinition t2)
{
foreach(var m1 in GetMembers(t1))
foreach (var m2 in GetMembers(t2))
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment