让程序自动加载资源中的目标文件并运行

时间:2021-05-02

(1)我们有一个test.exe的WinForm程序,这是我们要加壳的目标程序。

(2)新建一个WinForm工程,删除Form1,然后新建一个类。如下。

(3)将test.exe 拷贝到该工程目录,作为嵌入式资源。

using System; using System.Windows.Forms; using System.Resources; using System.Reflection; using System.IO;

namespace MyNamespace { public class Program { [STAThread] static void Main(string[] args) { Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNamespace.test.exe"); byte[] bs = new byte[stream.Length]; stream.Read(bs, 0, (int)stream.Length); Assembly asm = Assembly.Load(bs);

MethodInfo info = asm.EntryPoint; ParameterInfo[] parameters = info.GetParameters(); if ((parameters != null) && (parameters.Length > 0)) info.Invoke(null, (object[])args); else info.Invoke(null, null);

} } }

本文源自:翔宇亭——IT乐园(http://),转载请保留此信息!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章