Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2020, 09:57
jonwil jonwil is offline
VIP
 
Join Date: Feb 2004
Posts: 372
Rept. Given: 2
Rept. Rcvd 21 Times in 9 Posts
Thanks Given: 2
Thanks Rcvd at 57 Times in 32 Posts
jonwil Reputation: 21
Modifying/replacing class in .NET binary

I have a .NET binary (.NET only, no native code). Short of decompiling the entire binary, changing it and recompiling it (not really an option for my particular target), is there a way to take the decompiled code for the one class I am interested in, modify it and either A.Stick it back in the original binary somehow or B.Stick it into a dll file and make the binary use the dll instead of the original code?

Or any other way to modify the code?
Reply With Quote
  #2  
Old 06-06-2020, 11:28
chessgod101's Avatar
chessgod101 chessgod101 is online now
Co-Administrator
 
Join Date: Jan 2011
Location: United States
Posts: 517
Rept. Given: 2,150
Rept. Rcvd 677 Times in 213 Posts
Thanks Given: 604
Thanks Rcvd at 814 Times in 163 Posts
chessgod101 Reputation: 500-699 chessgod101 Reputation: 500-699 chessgod101 Reputation: 500-699 chessgod101 Reputation: 500-699 chessgod101 Reputation: 500-699 chessgod101 Reputation: 500-699
You should be able to directly replace or modify the decompiled class with dnSpy rather seamlessly, depending on how drastic the changes are:
Code:
https://github.com/0xd4d/dnSpy/releases
__________________
"Real knowledge is to know the extent of one's ignorance." Confucius
Reply With Quote
The Following User Gave Reputation+1 to chessgod101 For This Useful Post:
user1 (06-06-2020)
The Following 3 Users Say Thank You to chessgod101 For This Useful Post:
user1 (06-06-2020), wilson bibe (06-06-2020), Youtoo (08-20-2020)
  #3  
Old 06-06-2020, 16:46
val2032 val2032 is offline
Friend
 
Join Date: Apr 2010
Posts: 37
Rept. Given: 26
Rept. Rcvd 1 Time in 1 Post
Thanks Given: 76
Thanks Rcvd at 16 Times in 11 Posts
val2032 Reputation: 1
Also you can export project from dnspy and load it in VS.
Reply With Quote
  #4  
Old 06-07-2020, 03:59
atom0s's Avatar
atom0s atom0s is offline
Family
 
Join Date: Jan 2015
Location: 127.0.0.1
Posts: 345
Rept. Given: 25
Rept. Rcvd 110 Times in 54 Posts
Thanks Given: 49
Thanks Rcvd at 584 Times in 233 Posts
atom0s Reputation: 100-199 atom0s Reputation: 100-199
Projects like dnlib, Mono.Cecil, and Harmony are usable for things like this:

https://github.com/0xd4d/dnlib
https://github.com/jbevain/cecil
https://github.com/pardeike/Harmony
__________________
Personal Projects Site: https://atom0s.com
Reply With Quote
The Following 2 Users Say Thank You to atom0s For This Useful Post:
niculaita (06-07-2020), val2032 (06-07-2020)
  #5  
Old 06-07-2020, 16:56
niculaita's Avatar
niculaita niculaita is offline
Family
 
Join Date: Jun 2011
Location: here
Posts: 1,259
Rept. Given: 909
Rept. Rcvd 87 Times in 59 Posts
Thanks Given: 3,354
Thanks Rcvd at 465 Times in 329 Posts
niculaita Reputation: 87
also net reflector with reflexil 2.3 plugin
__________________
Decode and Conquer
Reply With Quote
The Following User Says Thank You to niculaita For This Useful Post:
val2032 (06-07-2020)
  #6  
Old 06-22-2020, 00:25
tusk tusk is offline
Friend
 
Join Date: Jun 2016
Posts: 27
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 5
Thanks Rcvd at 12 Times in 8 Posts
tusk Reputation: 0
Quote:
Originally Posted by jonwil View Post
Or any other way to modify the code?
Using some of the the above tools (dnSpy for exemple), you can directly change the code in the binary.
This might be in IL, but it is not too complicated to learn (for small patches it is usually ok)

I wonder if new versions are able to change in .net directly (thus builing the IL code automatically. Last time i tried, dnSpy had some issues with this and changing the IL code directly was the way to go...
Reply With Quote
The Following User Says Thank You to tusk For This Useful Post:
niculaita (06-22-2020)
  #7  
Old 06-22-2020, 04:54
niculaita's Avatar
niculaita niculaita is offline
Family
 
Join Date: Jun 2011
Location: here
Posts: 1,259
Rept. Given: 909
Rept. Rcvd 87 Times in 59 Posts
Thanks Given: 3,354
Thanks Rcvd at 465 Times in 329 Posts
niculaita Reputation: 87
also, in some cases, the name of patched file have to be same as original one
__________________
Decode and Conquer
Reply With Quote
  #8  
Old 06-23-2020, 19:53
sendersu sendersu is offline
VIP
 
Join Date: Oct 2010
Posts: 866
Rept. Given: 325
Rept. Rcvd 217 Times in 111 Posts
Thanks Given: 168
Thanks Rcvd at 373 Times in 209 Posts
sendersu Reputation: 200-299 sendersu Reputation: 200-299 sendersu Reputation: 200-299
Quote:
Originally Posted by tusk View Post
Using some of the the above tools (dnSpy for exemple), you can directly change the code in the binary.
This might be in IL, but it is not too complicated to learn (for small patches it is usually ok)

I wonder if new versions are able to change in .net directly (thus builing the IL code automatically. Last time i tried, dnSpy had some issues with this and changing the IL code directly was the way to go...
I'd recommend opening up an issue in dnSpy github tracker
author is responsive and is interested in in keeping his great product up to date and bugless
Reply With Quote
The Following User Says Thank You to sendersu For This Useful Post:
tusk (06-27-2020)
  #9  
Old 08-22-2020, 09:23
chicknsoup chicknsoup is offline
Friend
 
Join Date: Sep 2013
Posts: 33
Rept. Given: 2
Rept. Rcvd 8 Times in 2 Posts
Thanks Given: 7
Thanks Rcvd at 28 Times in 14 Posts
chicknsoup Reputation: 8
For small binary files, you can dump the file with dnSpy, load it with Visual Studio, patch then rebuild.
Reply With Quote
  #10  
Old 08-22-2020, 12:49
Tamrwa Tamrwa is offline
Friend
 
Join Date: Jul 2019
Posts: 6
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 0
Thanks Rcvd at 0 Times in 0 Posts
Tamrwa Reputation: 0
Why VS? Can patch directly in dnspy.
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
Replacing ECDSA in Target (arma) Mynotos General Discussion 3 11-22-2019 00:49
Highly self modifying code chants General Discussion 1 09-21-2016 17:46
Modifying Assembly Attributes (.NET) The Old Pirate General Discussion 7 05-11-2015 00:15
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 02:44.


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