反射调用方法解密
try
{
Assembly assembly = Assembly.LoadFile(txtAssemblyPath.Text);//加载指定程序集
if (assembly != null)
{
if (assembly.FullName.Contains("actmp,"))//看看是不是Sixxpack压缩过的程序集
{
Type compressorClass = assembly.GetType("Sixxpack.Compressor");//得到Compressor方法的类型
MethodInfo DecompressInfo = compressorClass.GetMethod("Decompress");//Decompress方法,供后面使用
int orig = Convert.ToInt32(assembly.GetType("Sixxpack.stub").GetField("orig", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null));//压缩后的程序集的偏移量,我虽然强烈怀疑就是0x8000,为了保险起见,还是反射出来吧。
#region 这段照抄Main方法的内容
MemoryStream inStream = new MemoryStream();
Stream stream2 = assembly.GetFiles()[0];//这么写就可以了
stream2.Position = orig;
byte[] buffer = new byte[stream2.Length - orig];
stream2.Read(buffer, 0, Convert.ToInt32(buffer.Length));
inStream.Write(buffer, 0, buffer.Length);
inStream.Seek(0L, SeekOrigin.Begin);
#endregion
byte[] data = (byte[])DecompressInfo.Invoke(Activator.CreateInstance(compressorClass), new object[] { inStream });//调用Decompress方法,获得原始程序集的数据
if (sfdAssembly.ShowDialog() == DialogResult.OK)
{
sfdAssembly.OpenFile().Write(data, 0, data.Length);//把数据保存到指定文件,OK,完工!
}
MessageBox.Show("文件解压成功!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("未找到正确的程序集!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
else
{
MessageBox.Show("该文件没有程序集!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
浙公网安备 33010602011771号