文件的 readbytes 和 运行 它
readbytes of a file and running it
我有 2 个 .net 文件!一次使用 c#.net,另一个使用 vb.net :)
现在我想读取它的字节和运行它:)
Dim mybyte As Byte() = System.IO.File.ReadAllBytes("E:\Projects\Expired.exe")
System.Reflection.Assembly.load(mybyte)
Could not load file or assembly '8192 bytes loaded from mybyte
您可以检查是否:
- 您要加载的*.exe是.NET/managed代码
- 您的 *.exe 所需的所有依赖项都存在
- 您的应用程序是针对相同(或更新)版本的
.NET 您要加载的 *.exe
你必须读取文件,做你的事情(解密?),然后将内容写入新文件并 运行 它。
类似的东西(如果你愿意,你可以将你的文件嵌入到项目资源中):
// 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));
我有 2 个 .net 文件!一次使用 c#.net,另一个使用 vb.net :)
现在我想读取它的字节和运行它:)
Dim mybyte As Byte() = System.IO.File.ReadAllBytes("E:\Projects\Expired.exe")
System.Reflection.Assembly.load(mybyte)
Could not load file or assembly '8192 bytes loaded from mybyte
您可以检查是否:
- 您要加载的*.exe是.NET/managed代码
- 您的 *.exe 所需的所有依赖项都存在
- 您的应用程序是针对相同(或更新)版本的 .NET 您要加载的 *.exe
你必须读取文件,做你的事情(解密?),然后将内容写入新文件并 运行 它。 类似的东西(如果你愿意,你可以将你的文件嵌入到项目资源中):
// 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));