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

 

这个难题可是整整搞了我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();

 

 

 好了!!搞定!明天优化一下!大家早点休息吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值