开发者

How to prevent a dll from being loaded in other apps

currently I develop a C#.Net application in which I'm using a custom control I developed some time ago. I need the dll to be shipped within the new application - but understandably I do not want the dll file to be used for foreign apps.

That's why I need t开发者_运维百科he custom dll to be somehow compiled within the new application. Currently the dll is copied into the application directory.

Any ideas? Should be trivial imho.

Thanks & regards, Daniel


I think you need to be looking into licensing your control(s): http://msdn.microsoft.com/en-us/library/fe8b1eh9.aspx


Look into IL Merge. This utility allows you to combine multiple .NET assemblies into a single assembly.

I quote:

ILMerge is a utility that can be used to merge multiple .NET assemblies into a single assembly. ILMerge takes a set of input assemblies and merges them into one target assembly. The first assembly in the list of input assemblies is the primary assembly. When the primary assembly is an executable, then the target assembly is created as an executable with the same entry point as the primary assembly. Also, if the primary assembly has a strong name, and a .snk file is provided, then the target assembly is re-signed with the specified key so that it also has a strong name.

Something to take into consideration however, is that people can still use the created assembly. Look into obfuscation and licensing to keep the easy-going at bay, but remember that if someone wants your code badly enough they will get it.

Certain things make it a lot harder, such as having a Web Service, but even then this is not full proof.


If you can change the DLL with the proprietary control, you can...

  1. Mark everything in the control DLL internal.
  2. Compile your assembly so that your calling DLL has access to the internal members of your control DLL.
  3. Sign the calling DLL.

See this MSDN page for the details on how to do this.


There's a number of different hacks you can do to make this harder for folks to use. All of them can be circumvented, but such is life.

You can look at this response here for disallowing an unknown assembly to reference your assembly: Secure C# Assemblies from unauthorized Callers

You should obfuscate your assembly if you are really nervous about it. This will make it harder to decompile. Something like Babel works great: http://babelobfuscator.blogspot.com/

You can also use ILMerge to store the assembly in another assembly. However, this assembly will be extracted and exposed at run-time. You can do something along these lines to extract a binary resource from one assembly and create a temporary assembly that gets used at runtime. If someone is really motivated, they can find the temporary assembly as well...

The real question is how far do you want to go!? At some point it won't be worth it. That's where you stop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜