读取文件并运行它

时间:2015-04-29 13:20:03

标签: c# .net vb.net byte

我有2个.net文件!一次使用c#.net,另一次使用vb.net:)

现在我想读取它的字节并运行它:)

Dim mybyte As Byte() = System.IO.File.ReadAllBytes("E:\Projects\Expired.exe") 
System.Reflection.Assembly.load(mybyte)
  

无法加载从mybyte

加载的文件或程序集'8192字节

2 个答案:

答案 0 :(得分:0)

您可以查看是否:

  • 您要加载的* .exe是.NET /托管代码
  • 您的* .exe所需的所有依赖项都存在
  • 您的应用程序是针对相同(或更新)的版本构建的 .NET要加载* .exe

您还可以阅读fiddle

答案 1 :(得分:0)

你必须阅读文件,做你的东西(解密?),然后将内容写入新文件并运行它。 类似的东西(如果需要,可以将文件嵌入项目资源中):

// Read file content from project resources
byte[] fileContent = MyProject.Properties.Resources.MyFile;

// <Do your stuffs with file content here>

// Write new file content to a temp file
string tempFile = "yourfile.exe";
File.WriteAllBytes(tempFile , fileContent );

// Run the app
Process proc = Process.Start(new ProcessStartInfo(tempFile));
相关问题