Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2025, 16:54
jonwil jonwil is offline
VIP
 
Join Date: Feb 2004
Posts: 399
Rept. Given: 2
Rept. Rcvd 21 Times in 9 Posts
Thanks Given: 2
Thanks Rcvd at 67 Times in 35 Posts
jonwil Reputation: 21
How to add code to dll?

I have a Windows x86 .dll file (specifically its a mixed mode Managed C++ and Native C++ dll if that makes a difference) and I want to add some new code and data
to that dll including adding the necessary entries to the .reloc segment. What's the best way to do that?

The code and data I want to add is already in a different version of the same .dll as binary assembler instructions (obviously I would need to fix up the addresses to point to the right places in the dll I am modifying) and I don't need to touch the managed side of things.
Reply With Quote
  #2  
Old 12-05-2025, 20:51
Jupiter's Avatar
Jupiter Jupiter is offline
Lo*eXeTools*rd
 
Join Date: Jan 2005
Location: Moscow, Russia
Posts: 234
Rept. Given: 43
Rept. Rcvd 62 Times in 37 Posts
Thanks Given: 37
Thanks Rcvd at 191 Times in 57 Posts
Jupiter Reputation: 62
There are many ways to add your own code to a DLL.

I recommend writing your own dynamic library (DLL) and attaching it to the target DLL via the import table.
In your DLL's DllMain, perform the initialization and patch the necessary code sections to link them to your code.
__________________
EnJoy!
Reply With Quote
The Following User Says Thank You to Jupiter For This Useful Post:
niculaita (12-07-2025)
  #3  
Old 12-06-2025, 19:08
WyvernX WyvernX is offline
Friend
 
Join Date: Jul 2016
Posts: 11
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 9
Thanks Rcvd at 10 Times in 5 Posts
WyvernX Reputation: 0
Another way is to just load the dll, add a trampoline to your own code, and return. If its out of process, maybe just create a code section, add code you want, and start a remote thread to run it.

I guess a lot depends on what your ultimate goal is. Just to extend some functionality, or add new functions, etc. Does the old functions need to call the new code etc.
Reply With Quote
  #4  
Old 12-06-2025, 20:58
ZeNiX's Avatar
ZeNiX ZeNiX is offline
Administrator
 
Join Date: Feb 2009
Posts: 735
Rept. Given: 177
Rept. Rcvd 772 Times in 259 Posts
Thanks Given: 226
Thanks Rcvd at 910 Times in 247 Posts
ZeNiX Reputation: 700-899 ZeNiX Reputation: 700-899 ZeNiX Reputation: 700-899 ZeNiX Reputation: 700-899 ZeNiX Reputation: 700-899 ZeNiX Reputation: 700-899 ZeNiX Reputation: 700-899
My suggestion is similar to Jupiter's method, but with a Proxy method.
That is, a Proxy dll.
Reply With Quote
Reply


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



All times are GMT +8. The time now is 05:49.


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