Hook dll and Objects

c++ / delphi package - dll injection and api hooking
Post Reply
Davita
Posts: 163
Joined: Tue Sep 13, 2005 7:31 pm

Hook dll and Objects

Post by Davita »

Hello

Anyone knows if it can cause some kind of problems? For example, if I inject the dll in a program compiled with C, what will happen? Does it have any other drawbacks?
Actually I need to use THashedStringList to store all opened handles and handle information as custom classes.

Thanks
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Objects are not a problem. Using VCL units with big initialization sections can be a problem. I recommend to stay away from SysUtils, Classes and Forms. If you must use some objects defined in some of those units, just copy the source code into your project file (*.dpr). You can check the size of your hook dll. Adding any of the mentioned units - without even using them - already increases the size of your hook dll. That is a sign of some code being executed during initialization of your dll which is not necessary and which can even be bad...
Davita
Posts: 163
Joined: Tue Sep 13, 2005 7:31 pm

Post by Davita »

probably you are right, but how can I define my classes without using Classes unit, or how can I use functions such as IntToStr etc without SysUtils :(
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

As I said, simply copy the code you need from Classes.pas/SysUtils.pas to your project file (*.dpr).
Davita
Posts: 163
Joined: Tue Sep 13, 2005 7:31 pm

Post by Davita »

ok thanks madshi :)
But still, I don't get what I should copy from classes.pas in order to create classes :(
mikec
Posts: 166
Joined: Sun Jul 16, 2006 9:01 pm
Location: UK

Post by mikec »

What he means is that if you use or need a function (say FunctionX) and it lives in SysUtils.pas, instead of including SysUtils.pas, simpley open up SysUtils.pas, find FunctionX code and copy and paste it into your applications .dpr file.

By doing this, your getting a copy of the required code. This is a common hack for functions like StrToIntDef() to avoid having to include SysUtils :wink:

Mike C
Davita
Posts: 163
Joined: Tue Sep 13, 2005 7:31 pm

Post by Davita »

thanks guys, but I need to use Classes.pas unit anyway. is this a huge drawback? what problems I will face?
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Davita wrote:I need to use Classes.pas unit anyway.
Why?
Davita wrote:is this a huge drawback? what problems I will face?
It has a big initialization section and includes further units with more initialization sections. That means loads of code is executed in every process when your hook dll is injected. That's bad and can eventually even lead to stability problems with some specific processes.
Post Reply