【问题标题】:How do you extract classes' source code from a dll file?如何从 dll 文件中提取类的源代码?
【发布时间】:2011-06-10 00:48:51
【问题描述】:

有没有软件可以做到这一点?我在互联网上没有找到任何有用的信息,所以我在这里问。

【问题讨论】:

  • 编译出来的原始源代码?根本不可能。功能上等价的东西?是的。
  • @delnan - 功能等效是什么意思?对不起,这一切都是新手。我没明白。我想从 dll 文件中提取类的(用 c#.net 编写的)代码。 dll 文件的类太多了。有什么方法可以从该 dll 中获取该代码?
  • @ILoveMusic 您可以提取类似于原始代码的内容,但不是确切的代码。使用 .NET 反射器。
  • 答案中的工具可以为您提供源代码,当再次编译时,它会提供一个执行相同操作的 DLL。但是它只能尝试从字节码中推断出原始源代码的样子(当然,这是更底层的代码),它不能神奇地恢复创建 DLL 的确切代码 - 很像格式化, 某些标识符等在编译过程中丢失。
  • okk..所以我无法提取 EXACT 代码,对吧?

标签: c# asp.net dll reverse-engineering source-code-protection


【解决方案1】:

使用.NET reflector

【讨论】:

    【解决方案2】:

    你无法得到确切的代码,但你可以得到它的反编译版本。

    最流行(也是最好的)工具是Reflector,但也有其他的.Net 反编译器(例如Dis#)。您还可以使用 ILDASM 反编译 IL,它与 .Net Framework SDK 工具捆绑在一起。

    【讨论】:

    • 现在你可能应该使用 ILSpy 或 dotPeek。两者都是免费并且做得很好。由于导航,我发现 dotPeek 更好,而且 ILSpy 需要很长时间才能启动。此外,我曾经反编译了一个我混淆过的程序集(用于测试工具),Redgate 的 .NET 反射器会立即从最简单的混淆中崩溃。 ILSpy 和 dotPeek 没有问题,并立即加载。它们还突出显示选择,以便您可以以某种方式管理混淆。
    • 我只想说,您可能应该编辑它并包含 DnSpy 而不是 ilspy、ildasm 或反射器。老实说,如今的反射器是所有反射器中最差的。 DnSpy 似乎是最容易设置的,最小的,并且具有所有其他程序的所有功能。 @adrianbanks
    【解决方案3】:

    您可以使用Reflector 也可以使用Add-In FileGenerator 将源代码提取到项目中。

    【讨论】:

      【解决方案4】:

      只有像c#Java这样的托管语言可以被完全反编译。您可以查看完整的源代码。 对于Win32 dll,您无法获取源代码。

      对于 CSharp dll 使用DotPeek 因为它是免费的,并且与ReDgate .Net Compiler 一样工作

      玩得开心。

      【讨论】:

        【解决方案5】:

        使用dotPeek

        选择.dll进行反编译

        就是这样

        【讨论】:

          【解决方案6】:

          如果您只想了解 dll 程序集中的一些基础知识,例如类、方法等,动态加载它们

          您可以使用微软提供的 IL Disassembler 工具。

          一般位于:“C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin”

          【讨论】:

            【解决方案7】:

            我使用Refractor 从 dll 文件中恢复我的脚本/代码。

            【讨论】:

              【解决方案8】:

              您可以使用dotPeek 唯一要说的是,在使用的时候,右键类选择Decompiled Source而不是双击,否则dotpeek只会显示本地cs文件的内容,不会显示反编译后的内容。

              【讨论】:

                【解决方案9】:
                 public async void Decompile(string DllName)
                 {
                     string destinationfilename = "";
                
                     if (System.IO.File.Exists(DllName))
                     {
                         destinationfilename = (@helperRoot + System.IO.Path.GetFileName(medRuleBook.Schemapath)).ToLower();
                         if (System.IO.File.Exists(destinationfilename))
                         { 
                             System.IO.File.Delete(destinationfilename);
                         }
                
                         System.IO.File.Copy(DllName, @destinationfilename);
                     }
                        // use dll-> XSD
                     var returnVal = await DoProcess(
                            @helperRoot + "xsd.exe", "\"" + @destinationfilename + "\"");
                
                     destinationfilename = destinationfilename.Replace(".dll", ".xsd");
                
                     if (System.IO.File.Exists(@destinationfilename))
                     {
                          // now use XSD
                          returnVal =
                            await DoProcess(
                              @helperRoot + "xsd.exe", "/c /namespace:RuleBook /language:CS " + "\"" + @destinationfilename + "\"");
                
                            if (System.IO.File.Exists(@destinationfilename.Replace(".xsd", ".cs")))
                            {
                                string getXSD = System.IO.File.ReadAllText(@destinationfilename.Replace(".xsd", ".cs"));
                           
                            }
                        }
                }
                

                【讨论】:

                • 有些问题,什么是DoProcess方法,什么是@helperRoot,并为代码添加解释。
                【解决方案10】:

                使用折射。 从here下载。

                1. 安装后打开软件。
                2. 按 Ctrl + O 并选择您的 DLL 文件。
                3. Dll 将显示在左窗格中。
                4. 右键单击 Dll 并选择导出源代码。
                5. 选择要导出文件的文件夹
                6. 稍等片刻,可能需要 2-3 分钟

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 2011-08-21
                  • 2011-07-03
                  • 2017-01-26
                  • 2011-06-29
                  • 1970-01-01
                  • 1970-01-01
                  • 2015-07-02
                  相关资源
                  最近更新 更多