C# 仅使用代码添加引用(没有 IDE“添加引用”功能)
我正在为一个程序编写一个插件,我想将我的代码放入 DLL 中,这样我就可以自由地共享该插件,而无需暴露(泄露)我的代码。
这是我可以访问的基本结构:
using System;
public class Plugin
{
public void Initialize()
{
//do stuff here
doWork();
}
}
然后我只需引用我的代码所在的 .cs 文件,程序就会“吃掉”这个插件。现在,我在那里放置了几个逻辑,主要由不直接与“Initialize()”绑定的函数组成,仅在启动整个系统的 doWork() 函数上。
现在,我想将所有代码放入 DLL 中,然后从 Initialize()、myDll.doWork() (或类似的东西)内部调用。
PS:这个 dll 将是一个已编译的 C# 库(可以称为动态程序集导入吗?它不会真正是动态的,因为无论如何它都会在执行前进行编译,对吧?)
PS2:这样我还可以添加自定义资源,例如表单、图像等没有太大困难吧?
PS3:有没有免费的工具来保护此类DLL中的代码? (即防止被轻易地重新设计)
提前致谢=)
I am writting a plugin for a program, and I want to put my code inside a DLL so I can share the plugin freely without exposing (giving away) my code.
Here is the basic structure i have access to :
using System;
public class Plugin
{
public void Initialize()
{
//do stuff here
doWork();
}
}
Then i just reference the .cs file my code is at and the program "eats" up this Plugin. Now, i have put several logic in there, consisting mostly of functions that arent tied directly to "Initialize()", only on the doWork() function, that starts the whole system.
Now, I want to put all my code inside a DLL, and then just call from inside Initialize(), myDll.doWork() (or something like that).
PS: This dll would ofc be a compiled C# library (could it be called dynamic assembly import? it wouldnt really be dynamic since it would be compiled pre-execution anyways, right?)
PS2: This way I can also add custom resources like forms, images and such without much difficulty right?
PS3: Is there a free tool for protecting the code inside such DLL? (ie protect from beeing easily re engineered)
Thanks in advance =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
找到了我正在寻找的东西,这里是:
Found exactly what I was looking for, here it is:
最好的选择是使用框架来创建可扩展应用程序:
如果你想手动执行,可以使用 Assembly.Load*() 加载程序集的方法在运行时。您可以在程序集中搜索实现特定接口的类型,然后使用 Activator.CreateInstance。程序集可以单独编译,您只需引用包含应用程序和插件共享的接口的程序集即可。
对于混淆,有一些混淆工具可用。
The best option would be to use a framework for creating extensible applications:
If you want to do it manually, you can use the Assembly.Load*() methods to load an assembly at runtime. You can search the assembly for types that implement a specific interface and then create instances using Activator.CreateInstance. The assemblies can be compiled separately, you just have to reference an assembly that contains the interface shared by application and plugin.
For obfuscation, there are a couple of obfuscation tools available.
使用静态 Assembly.Load() / Assembly.LoadFile() / Assembly.LoadFrom() 方法动态加载程序集。
Use the static Assembly.Load() / Assembly.LoadFile() / Assembly.LoadFrom() methods to dynamically load assemblies.
仅供参考,请记住使用 Red-Gate 的 .Net Reflector 等工具来检查您的DLL 以确保它被正确混淆。这个免费的可视化工具可让您像用户一样查看 DLL,以便您知道您的代码是否暴露
替代文本 http://img149.imageshack.us/img149/2025/screenshotfullscreen.gif
.Net 附带 Dotfuscator Community Edition 可用于混淆您的代码。无需编码,请参阅他们的用户指南来了解 GUI 的使用方法如果您需要帮助。
FYI, remember to use a tool like Red-Gate's .Net Reflector to inspect your DLL to make sure it is properly obfuscated. This free, visual tool lets you see the DLL as your users will see it so you'll know if your code is exposed
alt text http://img149.imageshack.us/img149/2025/screenshotfullscreen.gif
.Net comes with Dotfuscator Community Edition which can be used to obfuscate your code. No coding is required, see their user guide to learn your way around the GUI if you need help.