今天在看到 一个小软件,考勤用的 AttendanceSheet_V_1_2,只有一个EXE文件,绿色的随便考到哪里都可以运行。
顺手反编译后发现,他将需要的DLL也放入到资源文件了,在启动的时候自动加载:
代码如下:
internal static class Program
{
// Methods
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppDomain.CurrentDomain.AssemblyResolve += delegate (object sender, ResolveEventArgs senderArgs) {
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string name = new AssemblyName(executingAssembly.FullName).Name;
string str2 = new AssemblyName(senderArgs.Name).Name;
string str3 = name + "." + str2 + ".dll";
using (Stream stream = executingAssembly.GetManifestResourceStream(str3))
{
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, , buffer.Length);
return Assembly.Load(buffer);
}
};
Application.Run(new 考勤表生成工具());
}
} Collapse Methods
这里收藏一下。回头可能用得到