简体   繁体   English

反编译的 с# 代码显示错误

[英]Decompiled с# code shows errors

I have decompiled C# dll and now can not compile it.我已经反编译了 C# dll,现在无法编译它。 It shows strange errors, for example in some switch blocks some case blocks havent their break statements, or errors like "Can not cast int to bool" are shown.它显示奇怪的错误,例如在某些 switch 块中,某些 case 块没有 break 语句,或者显示诸如“无法将 int 转换为 bool”之类的错误。 But the amount of errors is not very large for dll of that size, so I think it is not the problem of decompiler.但是这个大小的dll错误量并不是很大,所以我认为不是反编译器的问题。

Is there some derective for compiler (for example, smthing life unsafe) that will solve this problem?编译器是否有一些指令(例如,生命不安全)可以解决这个问题? Or why is there such strange errors?或者为什么会出现这种奇怪的错误?

PS The dll is not broken - the application is using it right now. PS dll 没有损坏 - 应用程序现在正在使用它。 I'm using dotPeek to decompile and Visual Studio 15 to compile the result code.我正在使用 dotPeek 进行反编译,并使用 Visual Studio 15 来编译结果代码。

For such an error like :对于这样的错误:

"Can not cast int to bool"

There is absolutely no compiler directive that will allow your compiler to go ahead, I think that your decompiler messed up something decompiling ... You could simply try with another decompiler and see if you get another results, valid alternatives are : ILSpy , JustDecompile and Dotnet IL Editor .绝对没有任何编译器指令,让你的编译器继续前进,我认为你的反编译搞砸了反编译的东西......你可以简单地与其他反编译尝试,看看你得到另一个结果,有效的替代品: ILSpyJustDecompile点网IL编辑器

Be aware that some commercial DLL is obfuscated just to try to make life difficult to the decompiler and to who decompile ...请注意,一些商业 DLL 被混淆只是为了试图让反编译器和反编译器变得困难......

Be careful to avoid breaking some copyright .小心避免破坏某些版权。

It's quite hard to decompile IL to C# and decompiler has probably done something wrong.将 IL 反编译为 C# 非常困难,而且反编译器可能做错了什么。 In my experience, decompiled and compiled code can also behave differently than original assembly, so be aware.根据我的经验,反编译和编译代码的行为也可能与原始程序集不同,因此请注意。 And such compile error can be indocation that dotPeek was not sure, so think about it what it should do or look in IL.而这样的编译错误可能是 dotPeek 不确定的指示,所以想想它应该做什么或在 IL 中查找。

If you are willing to make really small edits to the assembly (inject method calls, make something public) it may be safer to do it directly in IL obtained by ildasm .如果您愿意对程序集进行非常小的编辑(注入方法调用,公开某些内容),直接在ildasm获得的 IL 中进行可能更安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM