Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2015, 22:11
The Old Pirate The Old Pirate is offline
Family
 
Join Date: Sep 2005
Posts: 120
Rept. Given: 51
Rept. Rcvd 73 Times in 22 Posts
Thanks Given: 9
Thanks Rcvd at 18 Times in 10 Posts
The Old Pirate Reputation: 73
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.
__________________

http://youtu.be/H0QfVDebLFg
Reply With Quote
  #2  
Old 05-07-2015, 02:44
atom0s's Avatar
atom0s atom0s is offline
Family
 
Join Date: Jan 2015
Location: 127.0.0.1
Posts: 396
Rept. Given: 26
Rept. Rcvd 126 Times in 63 Posts
Thanks Given: 54
Thanks Rcvd at 730 Times in 279 Posts
atom0s Reputation: 100-199 atom0s Reputation: 100-199
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.
Reply With Quote
The Following 2 Users Gave Reputation+1 to atom0s For This Useful Post:
Dreamer (05-07-2015), The Old Pirate (05-09-2015)
  #3  
Old 05-07-2015, 17:02
The Old Pirate The Old Pirate is offline
Family
 
Join Date: Sep 2005
Posts: 120
Rept. Given: 51
Rept. Rcvd 73 Times in 22 Posts
Thanks Given: 9
Thanks Rcvd at 18 Times in 10 Posts
The Old Pirate Reputation: 73
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?
__________________

http://youtu.be/H0QfVDebLFg
Reply With Quote
  #4  
Old 05-08-2015, 08:58
atom0s's Avatar
atom0s atom0s is offline
Family
 
Join Date: Jan 2015
Location: 127.0.0.1
Posts: 396
Rept. Given: 26
Rept. Rcvd 126 Times in 63 Posts
Thanks Given: 54
Thanks Rcvd at 730 Times in 279 Posts
atom0s Reputation: 100-199 atom0s Reputation: 100-199
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
Reply With Quote
The Following User Gave Reputation+1 to atom0s For This Useful Post:
The Old Pirate (05-09-2015)
  #5  
Old 05-09-2015, 22:34
The Old Pirate The Old Pirate is offline
Family
 
Join Date: Sep 2005
Posts: 120
Rept. Given: 51
Rept. Rcvd 73 Times in 22 Posts
Thanks Given: 9
Thanks Rcvd at 18 Times in 10 Posts
The Old Pirate Reputation: 73
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?
__________________

http://youtu.be/H0QfVDebLFg
Reply With Quote
  #6  
Old 05-10-2015, 09:05
atom0s's Avatar
atom0s atom0s is offline
Family
 
Join Date: Jan 2015
Location: 127.0.0.1
Posts: 396
Rept. Given: 26
Rept. Rcvd 126 Times in 63 Posts
Thanks Given: 54
Thanks Rcvd at 730 Times in 279 Posts
atom0s Reputation: 100-199 atom0s Reputation: 100-199
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.
Reply With Quote
  #7  
Old 05-10-2015, 11:04
mr.exodia mr.exodia is offline
Retired Moderator
 
Join Date: Nov 2011
Posts: 784
Rept. Given: 492
Rept. Rcvd 1,122 Times in 305 Posts
Thanks Given: 90
Thanks Rcvd at 711 Times in 333 Posts
mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299 mr.exodia Reputation: 1100-1299
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
Reply With Quote
The Following User Gave Reputation+1 to mr.exodia For This Useful Post:
The Old Pirate (05-11-2015)
  #8  
Old 05-11-2015, 00:15
The Old Pirate The Old Pirate is offline
Family
 
Join Date: Sep 2005
Posts: 120
Rept. Given: 51
Rept. Rcvd 73 Times in 22 Posts
Thanks Given: 9
Thanks Rcvd at 18 Times in 10 Posts
The Old Pirate Reputation: 73
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.
__________________

http://youtu.be/H0QfVDebLFg
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modifying/replacing class in .NET binary jonwil General Discussion 9 08-22-2020 12:49
HexRaysAST Matcher - PoC of Modifying HexRays AST TechLord Source Code 0 08-31-2018 15:47
Highly self modifying code chants General Discussion 1 09-21-2016 17:46
Modifying programs to use more than one copy at a time. Fade General Discussion 7 05-13-2006 14:12
Modifying resources of self-checking exe c4p0ne General Discussion 8 09-17-2004 21:32


All times are GMT +8. The time now is 09:25.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )