Skip to content

Instantly share code, notes, and snippets.

@ioncodes
Created February 5, 2017 13:37
Show Gist options
  • Save ioncodes/66ef855e5719373a7c22c2cf84b9e8cb to your computer and use it in GitHub Desktop.
Save ioncodes/66ef855e5719373a7c22c2cf84b9e8cb to your computer and use it in GitHub Desktop.
Get's the calls in a method and adds them to a list. Uses dnlib.
private static List<string[]> GetReferences(ModuleDef module)
{
var typeSet = new HashSet<string>();
foreach (var type in module.Types)
{
typeSet.Add(type.Name);
}
var refs = (from type in module.Types from method in type.Methods where method.HasBody from instruction in method.Body.Instructions where instruction.OpCode == OpCodes.Call from set in typeSet where type.Name != set where instruction.Operand.ToString().Contains(set) select new string[] {type.Name, set}).ToList();
return refs.GroupBy(strArr => string.Join("|", strArr))
.Select(g => g.First())
.ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment