【问题标题】:Read .Exe file Using c# [closed]使用c#读取.exe文件[关闭]
【发布时间】:2017-08-17 07:34:54
【问题描述】:

在c#中有多少种方式打开文件?哪个最好?以及如何打开.exe文件?很抱歉这个愚蠢的问题,但我是 C# 的新手。

using (StreamReader srStreamReader = new StreamReader(sString))
      {
        while ((sline = srStreamReader.ReadLine()) != null)
         {
            Console.WriteLine(sline);
         }
     }

我为此使用此代码,但我不能。所以请帮忙

【问题讨论】:

  • 以加载其内容到缓冲区的方式打开还是以执行方式打开? - 如果是前者 File.ReadAllBytes() 如果后者是 Process.Start()
  • 检查this answer

标签: c# file-io io


【解决方案1】:

打开文件是指执行还是逐行读取?

如果执行,那么答案可能是这样的:

    Process.Start("C:\\");

【讨论】:

  • 是的..!! open 表示读取..但我无法使用 StreamReader 打开 .exe 文件。
【解决方案2】:

如果我正确理解了问题

你可以这样使用

string path;
byte[] bufferArray = File.ReadAllBytes(path);
string base64EncodedString = Convert.ToBase64String(bufferArray );


bufferArray = Convert.FromBase64String(base64EncodedString );
File.WriteAllBytes(path, bufferArray );

【讨论】:

  • - 我有一个更简单的解决方案,在这里:using (var sw = new StreamReader(ofd.FileName, Encoding.GetEncoding("windows-1252"))) { var s = sw.ReadToEnd(); s = s.Replace('\x0', ' '); // replace NUL bytes with spaces richTextBox1.Text = s; }
【解决方案3】:

根据您提供的代码,您似乎希望能够查看.exe 的来源。如果不使用反编译器并知道应用程序是用什么编译的,就无法做到这一点。

如果您尝试执行 .exe 文件,请查看静态方法 System.Diagnostics.Process.Start(filePath)

如果您想真正阅读内容,您可以使用ILSpy 或其他类似软件来反编译应用程序以查看源代码。 ILSpy 在 GitHub 上有可用的源代码,因此您可以使用它来获取所需的内容。

【讨论】:

    猜你喜欢
    • 2020-09-15
    • 1970-01-01
    • 2017-05-24
    • 2019-08-16
    • 2018-05-17
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多