Reputation: 3888
I'm evaluating the many possibilities for a trial protection system and came up with the following question:
If I use my "trial check" class more than once (scattered several times over the application), will it be compiled just once into the exe?
The reason why I'm asking is that if it's only compiled once into the exe, then patching this single class will invalidate all places where it is used.
If it's compiled just once, are there any viable alternatives to prevent this?
Thanks!
EDIT: I'm actually not trying to roll my own protection system, I'm looking at several existing solutions like OnGuard, mxProtector and TRegWare. It was while looking at the various solutions source-code, that I came up with this question.
Upvotes: 4
Views: 327
Reputation: 1174
If you use the inline keyword for functions and methods where possible, the executable code will be "multi-plicated". There are some limitations to the use of inlining, though (see the linked doc).
I agree with Ain and Marco that spending effort on protection schemes may be more bother than benefit, and that it makes more sense to use existing solutions than to roll your own.
Upvotes: 4
Reputation: 47768
Just for the principle: There is actually a possibility to have the "same" class compiled multiple times. If you declare the class with a generic type and later have several instances with different instance types, the class code is compiled for each type. The generic class don't even have to make use of the generic type. If you spread the generic instances over different units, the code will be separated, too.
type
TDummy<T> = class
public
procedure Dummy1;
end;
procedure TDummy<T>.Dummy1;
begin
...
end;
var
FDummy1: TDummy<Integer>;
FDummy2: TDummy<Byte>;
FDummy3: TDummy<TButton>;
FDummy4: TDummy<TLabel>;
Upvotes: 3
Reputation: 22759
Yes, even if you create several instances of the class in different places there is only one copy of the methods (implementation), so if hacker patches the class all instances will be patched.
Do you really want to roll your own protection system? It ain't easy to come up with good system and there are several ready to use solutions around, if youre on budget then perhaps TurboPower OnGuard (which is open source now) will do.
BTW the general wisdom is that if they want to crack your app they will do it, no matter what, so one shouldn't waste too much resources on protection schemes. The only foolproof way is to exclude some of the (key) functionality from trial version, ie
{$IFDEF trial_version}
ShowMessage('Sorry, this function is not available in trial version');
{$ELSE}
// do the thing
{$END}
but of course, if full version gets into wild then it will be cracked...
Upvotes: 13
Reputation: 26376
Yes. The standard workaround is to put the code in an .inc and include that in multiple units.
But that makes less sense in a security setting. Since if sb has learned to search for a pattern, he can simply repeat the search to find the other occurrences, making it a minor nuisance at best.
This is one of the reasons why DIY protection is often a waste of time, and I agree fully with Ain. (both the onguard thing, and the fact that if functionality IS in the exe, it will be unlocked sooner or later, giving sufficient motivation)
Upvotes: 3