Oct
19
帮老婆的弟媳做一个网站,下载了一份现成的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# 代码复制内容到剪贴板
- private void Form1_Load(object sender, EventArgs e)
- {
- if (!File.Exists(".php.exe"))
- {
- MessageBox.Show("No php.exe found, the program may not run properly!");
- Application.Exit();
- }
- dlgOpenFld.SelectedPath = "D:temp";
- }
另外, 在PHP.INI文件中, 要确认以下文件的路径名正确, 个人感觉用相对路径会好一些
PHP 代码复制内容到剪贴板
- [Zend]
- zend_extension_manager.optimizer_ts="libOptimizer-3.3.0"
- zend_extension_ts="libZendExtensionManager.dll"
下面, BROWSE文件夹操作.
C# 代码复制内容到剪贴板
- private void button1_Click(object sender, EventArgs e)
- {
- if ( dlgOpenFld.ShowDialog() == DialogResult.OK )
- {
- txtFolder.Text = dlgOpenFld.SelectedPath;
- }
- }
最重要的操作之一, 用递归取得文件列表, 在这一步里,用到了List<>这样的数据类型, 这是用于未知长度数组的, 可以看到, C#对于文件,目录的操作都与DELPHI有了非常大的不同, 这就是FRAMEWORK:
C# 代码复制内容到剪贴板
- private List<FileInfo> getFiles(string tDir, bool SubFolder)
- {
- List<FileInfo> FileList = new List<FileInfo>();
- DirectoryInfo fDir = new DirectoryInfo(tDir);
- DirectoryInfo[] subDir = fDir.GetDirectories();
- FileInfo[] sFile = fDir.GetFiles();
- if (SubFolder)
- {
- foreach (DirectoryInfo d in subDir)
- {
- FileList.AddRange(getFiles(tDir + "" + d.Name, SubFolder));
- }
- }
- foreach (FileInfo f in sFile)
- {
- FileList.Add(f);
- }
- return FileList;
- }
下一步, 就是对取得的文件列表进行操作了,新文件夹自动取名为XXX_NEW, 并且对文件列表按规则进行操作, 即是只解密PHP文件, 还是要同时复制其他非PHP文件:
C# 代码复制内容到剪贴板
- private void button1_Click_1(object sender, EventArgs e)
- {
- if (!Directory.Exists(txtFolder.Text)||(txtFolder.Text.IndexOf(" ")>0))
- {
- MessageBox.Show("Directory "" + txtFolder.Text + "" is invalid! (No space allowed)", "Invalid folder selection", MessageBoxButtons.OK,MessageBoxIcon.Error);
- return;
- }
- RootDir = txtFolder.Text;
- string newDir=RootDir + "_new";
- List<FileInfo> FileList = new List<FileInfo>();
- FileList = getFiles(txtFolder.Text, WithSub);
- for (int i = 0; i < FileList.Count; i++)
- {
- string tNewDir = FileList[i].DirectoryName.Replace(RootDir, newDir);
- if (!Directory.Exists(tNewDir))
- {
- Directory.CreateDirectory(tNewDir);
- }
- if (FileList[i].Extension != ".php")//&&(FileList[i].
- {
- File.Copy(FileList[i].DirectoryName + "" + FileList[i].Name, tNewDir + "" + FileList[i].Name);
- txtLog.AppendText("COPIED! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");
- }
- else
- {
- if (runphp(FileList[i].DirectoryName + "" + FileList[i].Name, tNewDir))
- {
- txtLog.AppendText("DECRYPTED! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");
- }
- else
- {
- txtLog.AppendText("FAILED TO DECRYPT! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");
- }
- }
- }
- }
这是解码PHP文件, 通过建立新进程来调用外部EXE文件:
C# 代码复制内容到剪贴板
- private bool runphp(string filename, string NewFolder)
- {
- try
- {
- string EXE_PATH = @".";
- System.Diagnostics.Process process = new System.Diagnostics.Process();
- process.StartInfo.FileName = "php.exe";
- process.StartInfo.WorkingDirectory = EXE_PATH;
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.Arguments = filename + " /tab /indent:1 /path:" + NewFolder + " /ext:* /noexpire";
- process.Start();
- if (process.HasExited)
- {
- //txtLog.AppendText("finished!nn");
- //return true;
- }
- return true;
- }
- catch (Exception e)
- {
- throw e;
- //return false;
- }
- }
其他的代码就不一一罗列了. 只是临时使用的代码, 功能还非常简单.
闲说几个BLOG系统的选
APACHE里的几个基本


