- ·上一篇内容:word中的惊天秘密
- ·下一篇内容:Windows 7一些你不知道但很实用的快捷键
让程序自动加载资源中的目标文件并运行
(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://www.biye5u.com),转载请保留此信息!
微信搜索“优雅的代码”关注本站的公众号,或直接使用微信扫描下面二维码关注本站公众号,以获取最新内容。
个人成长离不开各位的关注,你的关注就是我继续前行的动力。