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: 387
Rept. Given: 2
Rept. Rcvd 21 Times in 9 Posts
Thanks Given: 2
Thanks Rcvd at 65 Times in 34 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 offline
Co-Administrator
 
Join Date: Jan 2011
Location: United States
Posts: 535
Rept. Given: 2,218
Rept. Rcvd 691 Times in 219 Posts
Thanks Given: 700
Thanks Rcvd at 939 Times in 186 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
__________________
"As the island of our knowledge grows, so does the shore of our ignorance." John Wheeler
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: 47
Rept. Given: 28
Rept. Rcvd 2 Times in 2 Posts
Thanks Given: 104
Thanks Rcvd at 30 Times in 17 Posts
val2032 Reputation: 2
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: 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
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,342
Rept. Given: 947
Rept. Rcvd 89 Times in 61 Posts
Thanks Given: 4,282
Thanks Rcvd at 479 Times in 338 Posts
niculaita Reputation: 89
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: 36
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 8
Thanks Rcvd at 18 Times in 12 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,342
Rept. Given: 947
Rept. Rcvd 89 Times in 61 Posts
Thanks Given: 4,282
Thanks Rcvd at 479 Times in 338 Posts
niculaita Reputation: 89
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 online now
VIP
 
Join Date: Oct 2010
Posts: 1,066
Rept. Given: 332
Rept. Rcvd 223 Times in 115 Posts
Thanks Given: 234
Thanks Rcvd at 512 Times in 288 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: 39
Rept. Given: 2
Rept. Rcvd 8 Times in 2 Posts
Thanks Given: 8
Thanks Rcvd at 34 Times in 17 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: 7
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 0
Thanks Rcvd at 5 Times in 1 Post
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 resources of self-checking exe c4p0ne General Discussion 8 09-17-2004 21:32


All times are GMT +8. The time now is 17:01.


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