如何保护我的 C# 代码不被反编译?
可能的重复:
.Net 混淆
.NET 世界中的混淆替代方案
就在几分钟前,我读到有很多工具(很多是免费的)可以让您将 C# .exe 转换回 VB 解决方案。这意味着我的专有代码可以被查看、编辑和重新编译/重新分发。有办法防止这种情况吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
简而言之,您需要使用混淆。仅举几例。
您可以阅读这篇 MSDN 文章,其中提供了有关如何混淆代码的建议。
In short you need to use Obfuscation. To name a few.
You can read this MSDN article that has advice on how to obfuscate your code.
您可以使用 Obfuscator.. Salamander 就是这样一种 .NET 工具...
< a href="http://confuser.codeplex.com/" rel="nofollow">Confuser 是另一个免费的 .NET 混淆器。它是用 C# 开发并使用 Mono
You can use an Obfuscator.. Salamander is one such tool for .NET...
Confuser is another free obfuscator for .NET. It is developed in C# and using Mono
您可以使用 mono 将其编译为本机二进制文件,只需 google 即可。
You can use mono to compile it to a native binary, just google it up.
除了混淆 .NET 程序集之外,您还可以将敏感函数/组件编码为本机 C++,将其包装在 C++/CLI 中并与 .NET 一起使用。
即使进行了混淆,JIT 编译器最终也需要查看 IL 代码,但这只会让反编译变得更加困难。
You could also code the sensitive functions/components into native C++, wrap it in C++/CLI and use with .NET in addition to obfuscating your .NET assemblies.
Even with obfuscation the JIT compiler will need to see the IL code eventually, you are just making it more difficult to decompile.
混淆器是一个不错的选择,因为它增加了人们查看、编辑、重新分发代码等的工作量。
虽然这些不能从物理上保护您的代码,但它们可以防止反编译代码的行为:专利、版权和许可证等法律机制。
反编译或逆向工程是一场经济努力的战斗。你是否值得混淆你的代码(可能会与反射“陷阱”发生冲突),而对于某人来说是否值得进行逆向工程(几乎没有上下文)而不是模拟或重写?
对此答案的评论,https://stackoverflow.com/a/1988467/64348,几个人都同意,表明混淆不会阻止返回到原始代码(或原始代码的一些足够接近的版本)。混淆只是可逆翻译的替代,除了一些有用的上下文之外不需要真正的密钥。
An obfuscator is a good bet, as it increases a person's effort to view, edit, redistribute, etc. the code.
While these don't protect your code physically they could prevent the behavior of decompiling your code: legal mechanisms such as patents, copyrights, and licenses.
Decompiling or reverse engineering is a battle of economic efforts. Is it worth it for you to obfuscate your code (potentially running afoul of reflection "gotchas") vs. is it worth it for someone to reverse engineer (with little context) instead of emulating or rewriting?
A comment on this answer, https://stackoverflow.com/a/1988467/64348, with which several agree, indicates that obfuscation does not prevent getting back to the original (or some close enough version of the original) code. Obfuscation is just a stand-in to a reversible translation with no real key needed except some useful context.