Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I use a class more than once in an application, will it be compiled just once into the exe?

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.

like image 708
smartins Avatar asked Nov 29 '22 18:11

smartins


2 Answers

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.

like image 40
Lars Fosdal Avatar answered Dec 20 '22 02:12

Lars Fosdal


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...

like image 124
ain Avatar answered Dec 20 '22 03:12

ain