Little joys about Cecil 4
Few times ago, Miguel asked me a little tool, which basically round-trip an assembly using Cecil. It’s sole purpose is to test the ability of Cecil to read and write without errors any assembly. I’ll use it here to demonstrate the results of today’s work. If ever you want to have a look at it, you’ll find it in svn here: /trunk/cecil/tools
C:\cecil›dir
Volume in drive C has no label.
Volume Serial Number is 50F3-EB89
Directory of C:\cecil
03/27/2006 06:12 PM ‹DIR› .
03/27/2006 06:12 PM ‹DIR› ..
01/30/2006 12:20 PM 311,296 C5.dll
03/27/2006 06:10 PM 3,584 cecil-roundtrip.exe
03/27/2006 06:03 PM 382,464 Mono.Cecil.dll
3 File(s) 697,344 bytes
2 Dir(s) 10,192,011,264 bytes free
C:\cecil›cecil-roundtrip.exe C5.dll C5.rt.dll
Assembly C5, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
successfully roundtripped to C5.rt.dll
C:\cecil›peverify C5.rt.dll
Microsoft (R) .NET Framework PE Verifier. Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
All Classes and Methods in C5.rt.dll Verified.
C:\cecil›
Sorry for the Windows output but heh, their peverify and ildasm are much better than ours.
So, what can we see here? The point is that Cecil (SVN HEAD) is now able to round-trip without any error the most terrifying assembly for generics stuff: the great C5 library. There is now very few things missing inside Cecil to reach the 2.0 ready status.
You know what? I’m happy!
Trackbacks
Use the following link to trackback from your own site:
http://evain.net/blog/articles/trackback/47
Tried it on one of my Assemblies, this is what I got:
F:\downld\dotnet\Mono\cecil-0.3-bin>cecil-roundtrip.exe XDed.exe XDed.rt.exe
Failed to roundtrip assembly XDed.exe
System.NullReferenceException: Object reference not set to an instance of an obj
ect.
at Mono.Cecil.ReflectionWriter.GetSigType(ITypeReference type)
at Mono.Cecil.Cil.CodeWriter.GetLocalVarSig(VariableDefinitionCollection vars)
at Mono.Cecil.Cil.CodeWriter.VisitVariableDefinitionCollection(VariableDefinitionCollection variables)
at Mono.Cecil.Cil.MethodBody.Accept(ICodeVisitor visitor)
at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition meth)
at Mono.Cecil.ReflectionWriter.TerminateModuleDefinition(ModuleDefinition module)
at Mono.Cecil.StructureWriter.TerminateAssemblyDefinition(AssemblyDefinitionasm)
at Mono.Cecil.AssemblyDefinition.Accept(IReflectionStructureVisitor visitor)
at Mono.Cecil.AssemblyFactory.SaveAssembly(AssemblyDefinition asm, String file)
at Cecil.Tools.Roundtrip.Main(String[] args)
F:\downld\dotnet\Mono\cecil-0.3-bin>
This assembly is compiled with Delphi 8.0 for .NET 1.1. Unfortunately, I am not at liberty to make this library available to you for testing.
We are really interested in being able to extract the Main Module from the assembly and save it to a .netmodule file. Can Cecil do that??
Did you try Cecil from SVN ?
Without any test case, I can’t do anything.
Cecil have no facilities for emitting .netmodule files, and is not likely to have before a while as it’s not a very used feature.
But why would extract the main module into another if you can modify this module and others ?
Thanks for your feedback.
I tried version 0.3 from www.mono-project.com/Ceci… is that the latest? If not can you update the page with the latest version.
The reason I ask about emitting .netmodule is because Delphi for .NET framework cannot produce .netmodules, it can only produce .DLL or .EXE assemblies. Having a .netmodule would be handy under C++/CLI because it can merge many .netmodules into 1 assembly. Anyway, I was just wondering.
Cecil 0.3 is the last release, I’ll update the page when I’ll release another version of Cecil. Expect Cecil 0.4 within a month. By now, you can checkout Mono’s SVN to have the last revision.
I’m adding the .netmodule thing in my todo list.