Search code examples
.netsilverlightlocalization.net-assemblysatellite-assembly

What tool can change properties of existing assembly (assembly name in particular)?


I am trying to obfuscate my silverlight application. It contains two assemblies and I am using a 'merge assemblies' feature of obfuscator. Assembly (A2) that is being merged with main assembly (A1) has resources, and it is a localized assembly so theres a corresponding localized assembly (A2loc) named according to satellite culture specific assembly names.

However during merge A2 (assembly with resources) becomes M(A1+A2) and A2localized can no longer be satellite assembly for M cause it has old A2 name.. Im pretty sure if I change A2loc assembly attributes to match new assembly name M it will be working.

Question: Which tool can be used to take existing assembly and modify its assembly name for example?

When I simply rename satellite assembly A2loc to match M assembly name app begins to crash on load.

I describe whole process cause maybe someone can suggest a better approach.


Solution

  • I was able to solve this following solution from here hacking assembly manifest

    using ildasm -> dump -> edit IL code -> ilasm -> generate new assembly from edited IL code

    Heres link contents in case it goes down:

    I was debugging a particularly nasty problem and found myself wanting to edit the manifest of a compiled .NET assembly, to change the version number of the assemblies it was referencing. Not necessarily best practice, but in this case it would enable me to confirm the exact issue without a two-hour build-and-deploy cycle. Turns out that nasty hacks like this are very straightforward:

    Run ILDASM, open the assembly and choose File…Dump to extract the IL Open the IL file in Visual Studio and edit the manifest – in this case, the version numbers of the referenced assemblies are easily found at the top of the file:

    // Metadata version: v2.0.50727
    .assembly extern mscorlib
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
      .ver 2:0:0:0
    }
    .assembly extern x.y.z
    {
      .publickeytoken = (E4 21 0D 54 23 66 A2 B4 )                         // . .D'f..
      .ver 1:0:9:12
    }
    

    Save the IL and reassemble it with ILASM – if the assembly was signed, re-sign it using ilasm /DLL x.y.z.il /KEY=x.y.z.snk Ensure the new assembly has the same name as the original, and it will operate as an exact replacement, only now its dependencies will be for the modified versions. Simon McEnlly's article on CodeProject describes going further with the manifest to change the visibility of methods, and generally modifying and rebuilding assemblies where you don't have the source code. Note that if the assembly is signed and you don't have the strong name key to re-sign it, the modified assembly will warn about being tampered with and won't load.