您的位置:首页 > 其它

使用Xenocode加壳混淆后,无法“自杀覆盖”的自动更新

2012-02-18 17:29 435 查看
这个难题可是整整搞了我2天时候。

直至目前,才算有一个解决方案。

经过 Xenocode 的 WinForm 程序,如果你想实现一键式自动更新(就是不需要客户点一下点一下),那是相当困难的。

原因是 Xenocode 不但混淆了代码,还进行“加壳”保护了!至于什么是加壳,我个人理解是:在一个程序里运行另外一个程序(没有看过相关的知识,见笑了)。

我来说说我的自动升级构思:




代码

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> ProcessStartInfo info = new ProcessStartInfo();

info.WorkingDirectory = Application.StartupPath;

info.FileName = "AutoUpdater.exe";

info.Arguments = string.Format("\"{0}\" \"{1}\" \"{2}\"",

Process.GetCurrentProcess().Id,

StaticModel.GetServerUrl() + versionAndFilename[1],

versionAndFilename[2]);

// ProgramEx.Mutex.TryDispose();

info.UseShellExecute = false;

Process.Start(info);

Application.ExitThread();

而 AutoUpdater.exe 很简单,到指定网址下载一个 rar,删除当前文件夹里的所有文件并解压。

这里涉及到一个问题:如果不使用混淆加壳,这一段代码,是完全行得通的。

可是一旦保护了,问题就来了,使用 Process.Start 后仍处于Xenocode 加壳进程中。

通俗的说:在加壳混淆后的程序(程序A)里,调用了任何外部程序(程序B)以后,都无法删除源程序(程序A)。

这可忙得我焦头烂额。到网上搜罗无数办法,包括是CreateProcess API,什么拷贝到临时文件,然后再返回来,等等等等……神啊,救救我吧!


其实缓解方案还是有的,就是雷同 ClickOnce ,建立一个“版本文件夹”。但是这个方法比较麻烦,因为我在安装包的时候,就已经创建桌面快捷键,如此一改,将会涉及到更多的问题。

琢磨了2天,直到今晚,无意中想起,Xenocode加壳了,我自己就不能“加壳”?

说干就干,程序很简单,建立一个新的WinForm应用程序:




代码

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> /// <summary>

/// 应用程序的主入口点。

/// </summary>

[STAThread]

static void Main()

{

Process p = new Process();

p.StartInfo.FileName = "AthleticPos2011.Views.exe";

p.StartInfo.Arguments = "1";

p.Start();

p.WaitForExit();

if (File.Exists("update.ath"))

{

Thread.Sleep(1000);

var args = File.ReadAllText("update.ath");

File.Delete("update.ath");

ProcessStartInfo info = new ProcessStartInfo();

info.WorkingDirectory = Application.StartupPath;

info.FileName = "AutoUpdater.exe";

info.Arguments = args;

info.UseShellExecute = false;

Process.Start(info);

Application.ExitThread();

}

}

而源程序的发现需要更新后的操作变成如下:




代码

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->File.WriteAllText("update.ath", string.Format("\"{0}\" \"{1}\" \"{2}\"",

Process.GetCurrentProcess().Id,

StaticModel.GetServerUrl() + versionAndFilename[1],

versionAndFilename[2]));

this.Close();

// ProgramEx.Mutex.TryDispose();

//ProcessStartInfo info = new ProcessStartInfo();

//info.WorkingDirectory = Application.StartupPath;

//info.FileName = "AutoUpdater.exe";

//info.Arguments = string.Format("\"{0}\" \"{1}\" \"{2}\"",

// Process.GetCurrentProcess().Id,

// StaticModel.GetServerUrl() + versionAndFilename[1],

// versionAndFilename[2]);

//// ProgramEx.Mutex.TryDispose();

//info.UseShellExecute = false;

//Process.Start(info);

//Application.ExitThread();

好了!!搞定!明天优化一下!大家早点休息吧!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: