Exetools

Exetools (https://forum.exetools.com/index.php)
-   General Discussion (https://forum.exetools.com/forumdisplay.php?f=2)
-   -   Modifying Assembly Attributes (.NET) (https://forum.exetools.com/showthread.php?t=16815)

The Old Pirate 05-06-2015 22:11

Modifying Assembly Attributes (.NET)
 
Is there a way to modify Assembly Attributes of existing assembly?
What I want to achieve is to add InternalsVisibleTo attribute to expose assembly's internals to my library.

atom0s 05-07-2015 02:44

You can use something like Mono.Cecil to rewrite parts of the file and then save the changed file. Check out Mono.Cecil here:
http://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cecil/

dnlib is another similar library:
https://github.com/0xd4d/dnlib

You should be able to alter the attributes of classes and such to your needs to make it work as desired.

The Old Pirate 05-07-2015 17:02

I accomplished the task with Mono.Cecil, thanks.

By the way, I guess it's not possible to import .NET 4.0 module into .NET 2.0 assembly?

atom0s 05-08-2015 08:58

You can if the 4.0 module exposes what you need via COM. The 2.0 assembly can then use the object(s) via COM. A straight import is not possible though because of the .NET version mis-match though.

You can see more info on how to accomplish this here:
http://www.codeproject.com/Articles/204406/How-To-Use-a-NET-Based-DLL-From-NET-Based-Appl

The Old Pirate 05-09-2015 22:34

Thank you very much atom0s. Very useful.

Sorry to bother you, but I have one last problem. The app stores resources in separate .dll file. I had to remove Strong Name from the .exe, but then I noticed that it won't load strong-named .dll. Why? What am I missing here?

atom0s 05-10-2015 09:05

These links may help some:
https://msdn.microsoft.com/en-us/library/s1sx4kfb(v=vs.100).aspx
https://msdn.microsoft.com/en-us/library/xwb8f617(v=vs.110).aspx

As MSDN states as well:
Quote:

When you reference a strong-named assembly, you expect to get certain benefits, such as versioning and naming protection. If the strong-named assembly then references an assembly with a simple name, which does not have these benefits, you lose the benefits you would derive from using a strong-named assembly and revert to DLL conflicts. Therefore, strong-named assemblies can only reference other strong-named assemblies.
So from the look of things you are required to keep the strong-name on your exe in order for it to load those modules. Bypassing though, I am not sure. I tend to not ever really use strong names on anything I make so I've never personally had to deal with it.

mr.exodia 05-10-2015 11:04

Sounds weird to me. An exe without strong name should be able to load a dll with strong name. Anyways, strong name doesn't work as far as I know. You could just modify things and maybe hook StrongNameSignatureVerification if the program checks the strong name.

An alternative solution is to simply re-sign everything using your own strong name :)

The Old Pirate 05-11-2015 00:15

I have read that paragraph, but as mr.exodia points out - the .exe has been stripped out of Strong Name, hence the question. Shouldn't it be able to load any strong-named .dll? Nonetheless, if I remove the Strong Name from resource .dll, it loads correctly then.


All times are GMT +8. The time now is 10:02.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX