rss resume / curriculum vitae linkedin linkedin gitlab github twitter mastodon instagram
Cecil, 2
Nov 26, 2006

If you are trying to get Mono.Cecil.TypeDefinition from a Mono.Cecil.TypeReference (like I was) you can start by trying the following code, just an idea:

DefaultAssemblyResolver resolver = new DefaultAssemblyResolver ();
AssemblyNameReference assem = new AssemblyNameReference ();
assem.Name = "mscorlib";
assem.Version = new Version (2, 0); //Try 1.0 also
AssemblyDefinition assemDef = resolver.Resolve (assem);
foreach (TypeReference typeReference in _library.MainModule.TypeReferences) {
TypeDefinition definition = assemDef.MainModule.Types [typeReference.FullName];
Console.WriteLine (definition.FullName);

Don't forget to add using Mono.Cecil. Above code solve my problems to get those DataType-like structures, such as System.Int32, System.Int16 and so on, which aren't loaded when you are doing reverse engineering.

Back to posts