Question

We need to patch an assembly and we can't rebuild from source code at the moment. I can dump the IL using ildasm mydll.dll /all /out=mydll.il and then I can rebuild it with ilasm /dll mydll.il and it's all good except that things like file version, public key, etc are all missing from the new binary. How can I tell ilasm to add these in? I've tried the /mdv switch with no luck.

Was it helpful?

Solution

The key won't round trip - otherwise you would be able to hack anyone's assembly and pass it off as an original.

In order to sign the assembly in your situation you'll need the key. Once you have decompiled your assembly, patched it - its easiest if you go ahead and add the following line in the area where the other Assmbly attributes are:

.custom instance void [mscorlib]System.Reflection.AssemblyDelaySignAttribute::.ctor(bool) = ( 01 00 00 00 00 ) 

That attribute tells ilasm to leave room for the key. Once you've added that attribute and reassembled your code using ilasm, you then need to use the sn utility to delay sign it. The syntax should be something like this:

sn /R myreassembled.dll originalassemblykey.snk

That should resign the assembly.

Which file version are you refering to? It should be an assembly attribute in the IL, but if not you may need the al.exe utility to do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top