Oct 19

C#学习之应用程序 TrueDeZender 不指定

kcao , 15:25 , 技术 , 评论(0) , 引用(0) , 阅读(1484) , Via 本站原创 | |

帮老婆的弟媳做一个网站,下载了一份现成的PHP代码,不过都是加了密的.有些改动需要对PHP文件进行,可是发现这份东西是用了ZEND加密的,网上现成的DEZENDER的软件不少,绝大多数是基于黑刀改装的,效果不错,可是都不能对目录结构进行原样复制.找到一份梅花三弄版 DEZENDER据说可以保持原目录结构,可是不知是什么原因,居然在我的计算机上运行不起来.于是我就想自己写一个程序来做这事,顺便学习一下C#.

Form上的几个基本控件:

  • txtFolder: PHP文件所在的根目录, 新目录将自动取名为目录名_new
  • button1: txtFolder的browse按钮
  • CheckBox1: With Subfolders 标记, 即操作是否包括各级子目录
  • CheckBox2: Process PHP files only 标记, 即操作是否只针对PHP文件,如果要针对所有文件,则非PHP文件将被复制到指定目录
  • txtLog: 日志框, 输出所有信息
  • stsInfo: StatusBar, 显示一些提示信息
  • btnList: 显示所有文件到txtLog
  • btnbProcess: 对文件进行操作

几个private变量:

 

  • private bool WithSub = true; //对应checkbox1
  • private bool PhpOnly = false; //对应checkbox2
  • private string RootDir; //对应txtFolder

检查运行环境, PHP.EXE是黑刀的执行文件, 必须在当前目录下存在.

C# 代码复制内容到剪贴板
  1. private void Form1_Load(object sender, EventArgs e)    
  2. {    
  3. if (!File.Exists(".php.exe"))    
  4. {    
  5. MessageBox.Show("No php.exe found, the program may not run properly!");    
  6. Application.Exit();    
  7. }    
  8. dlgOpenFld.SelectedPath = "D:temp";    
  9. }    

 

另外, 在PHP.INI文件中, 要确认以下文件的路径名正确, 个人感觉用相对路径会好一些

PHP 代码复制内容到剪贴板
  1. [Zend]    
  2. zend_extension_manager.optimizer_ts="libOptimizer-3.3.0"    
  3. zend_extension_ts="libZendExtensionManager.dll"   

下面, BROWSE文件夹操作.

C# 代码复制内容到剪贴板
  1. private void button1_Click(object sender, EventArgs e)    
  2. {    
  3. if ( dlgOpenFld.ShowDialog() == DialogResult.OK )    
  4. {    
  5. txtFolder.Text = dlgOpenFld.SelectedPath;    
  6. }    
  7. }    

最重要的操作之一, 用递归取得文件列表, 在这一步里,用到了List<>这样的数据类型, 这是用于未知长度数组的, 可以看到, C#对于文件,目录的操作都与DELPHI有了非常大的不同, 这就是FRAMEWORK:

C# 代码复制内容到剪贴板
  1. private List<FileInfo> getFiles(string tDir, bool SubFolder)    
  2. {    
  3. List<FileInfo> FileList = new List<FileInfo>();    
  4. DirectoryInfo fDir = new DirectoryInfo(tDir);    
  5. DirectoryInfo[] subDir = fDir.GetDirectories();    
  6. FileInfo[] sFile = fDir.GetFiles();    
  7. if (SubFolder)    
  8. {    
  9. foreach (DirectoryInfo d in subDir)    
  10. {    
  11. FileList.AddRange(getFiles(tDir + "" + d.Name, SubFolder));    
  12. }    
  13. }    
  14. foreach (FileInfo f in sFile)    
  15. {    
  16. FileList.Add(f);    
  17. }    
  18. return FileList;    
  19. }    

下一步, 就是对取得的文件列表进行操作了,新文件夹自动取名为XXX_NEW, 并且对文件列表按规则进行操作, 即是只解密PHP文件, 还是要同时复制其他非PHP文件:

C# 代码复制内容到剪贴板
  1. private void button1_Click_1(object sender, EventArgs e)    
  2. {    
  3. if (!Directory.Exists(txtFolder.Text)||(txtFolder.Text.IndexOf(" ")>0))    
  4. {    
  5. MessageBox.Show("Directory "" + txtFolder.Text + "" is invalid! (No space allowed)""Invalid folder selection", MessageBoxButtons.OK,MessageBoxIcon.Error);    
  6. return;    
  7. }    
  8. RootDir = txtFolder.Text;    
  9. string newDir=RootDir + "_new";    
  10. List<FileInfo> FileList = new List<FileInfo>();    
  11. FileList = getFiles(txtFolder.Text, WithSub);    
  12.   
  13. for (int i = 0; i < FileList.Count; i++)    
  14. {    
  15. string tNewDir = FileList[i].DirectoryName.Replace(RootDir, newDir);    
  16. if (!Directory.Exists(tNewDir))    
  17. {    
  18. Directory.CreateDirectory(tNewDir);    
  19. }    
  20. if (FileList[i].Extension != ".php")//&&(FileList[i].    
  21. {    
  22. File.Copy(FileList[i].DirectoryName + "" + FileList[i].Name, tNewDir + "" + FileList[i].Name);    
  23. txtLog.AppendText("COPIED! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");    
  24. }    
  25. else    
  26. {    
  27. if (runphp(FileList[i].DirectoryName + "" + FileList[i].Name, tNewDir))    
  28. {    
  29. txtLog.AppendText("DECRYPTED! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");    
  30. }    
  31. else    
  32. {    
  33. txtLog.AppendText("FAILED TO DECRYPT! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");    
  34. }    
  35. }    
  36. }    
  37. }   

这是解码PHP文件, 通过建立新进程来调用外部EXE文件:

C# 代码复制内容到剪贴板
  1. private bool runphp(string filename, string NewFolder)    
  2. {    
  3. try    
  4. {    
  5. string EXE_PATH = @".";    
  6. System.Diagnostics.Process process = new System.Diagnostics.Process();    
  7. process.StartInfo.FileName = "php.exe";    
  8. process.StartInfo.WorkingDirectory = EXE_PATH;    
  9. process.StartInfo.CreateNoWindow = true;    
  10. process.StartInfo.Arguments = filename + " /tab /indent:1 /path:" + NewFolder + " /ext:* /noexpire";    
  11. process.Start();    
  12. if (process.HasExited)    
  13. {    
  14. //txtLog.AppendText("finished!nn");    
  15. //return true;    
  16. }    
  17. return true;    
  18. }    
  19. catch (Exception e)    
  20. {    
  21. throw e;    
  22. //return false;    
  23. }    
  24.   
  25. }    

其他的代码就不一一罗列了. 只是临时使用的代码, 功能还非常简单.

 

Tags: , ,
发表评论
Please log on to continue. Thanks!
打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]