views:

46

answers:

2

I create a .NET (WPF) Application, and compile it to .EXE. Then I create a second project, and add a reference to the compiled .exe, I can see all the classes and forms, and can use them for automation, etc.

I want to prevent other people from using my compiled .exe as a .dll, so I changed all my classes to 'Friend' instead of 'Public', but this doesn't work for the (wpf) forms. And every time I create a new class, I must remember to change it to 'Friend'.

So, is there a better solution for preventing your app to be used as a DLL?

UPDATE: I am aware that .NET is easily decompilable, and that the access modifiers can be modified by a determined 'cracker'. But I only want to make it a little harder, than just adding a reference.

Maybe i should have stated my question differently: How can I make all forms/classes in my project 'Friend', without specifying it for every item.

+3  A: 

There's little you can do, ultimately; reflection will let you get around any access declarations you make.

You could obfuscate your code to make it more difficult to understand and therefore use, but it won't protect against a determined intrusion.

Randolpho
Are you 100% sure?, I just stumbled upon http://msdn.microsoft.com/en-us/library/wd40t7ad.aspx. Strong named assemblies. Prior to .Net 4.0 they were easily bypassed, but from 4.0 they should be reliable. I will read more about them, and if it's no solution I'll accept your answer. Thanks.
Joshua
@Drazic: Strong named assemblies only guarantee that they and their references have not been altered. Anyone can reference a strongly named assembly and use its declared types.
Randolpho
Thanks Randolpho, but if I make everything 'Friend' and then strongname my assembly, wouldn't it solve the problem?
Joshua
@Drazic: Nope. Even if they're internal, or even if they're outright private, you cannot keep reflection from instantiating the types.
Randolpho
+2  A: 

The best way to do this is to put something in the end-user license agreement saying that its not allowed.

Changing a class to friend will not prevent someone using it if they really want to. All they have to do is to modify the DLL to make the class public and your protection system has failed.

Mark Byers
Ordinarily I hate EULAs and everything they stand for so I can't believe I'm agreeing here, but... a EULA may be a good precaution, legally speaking. +1
Randolpho
Thanks Mark, but if someone is really determined, they can even extract the code. The only thing I want is to make it harder, than just adding a reference.
Joshua