private void obfuscateButton_Click(object sender, EventArgs e) { string strSource = sourceDirectory.Text; string strTarget = targetDirectory.Text; // strip off any ending slashes char[] slashes = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; strSource = strSource.TrimEnd(slashes); strTarget = strTarget.TrimEnd(slashes); Properties.Settings settings = Properties.Settings.Default; settings["lastTargetDir"] = strTarget; settings["lastSourceDir"] = strSource; settings.Save(); ObfuscationConfig config = GenerateConfig(); if (sourceDirectory.Text != "" && targetDirectory.Text != "") { // make sure the target and source directories are not the same if (strSource.ToLower() == strTarget.ToLower()) { MessageBox.Show("Target directory can not be the same as the source directory", "Problem with target", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // make sure the target is not a parent of the source else if (strSource.ToLower().Contains(strTarget.ToLower())) { MessageBox.Show("Target directory can not be a parent of the source directory", "Problem with target", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (Directory.Exists(strTarget)) { if (DialogResult.Yes == MessageBox.Show("Target Directory exists. All files and directories in the target directory will be removed. Are you sure you want to do this?", "Delete Target?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)) { Enable(false); //_ob.Start(sourceDirectory.Text, targetDirectory.Text, filesToObfuscate); _ob.Start(config, true); } } else { Enable(false); //_ob.Start(sourceDirectory.Text, targetDirectory.Text, filesToObfuscate); _ob.Start(config, true); } } }
/// <summary> /// Loads a previously saved project and restores its settings to the screen. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loadProjectToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = "xml"; dlg.Filter = "PHP Obfuscator XML (*.obxml)|*.obxml"; //dlg.InitialDirectory = "c:\\"; if (dlg.ShowDialog() == DialogResult.OK) { string filename = dlg.FileName; ObfuscationConfig config = ObfuscationConfig.Open(filename); if (null == config) { MessageBox.Show("There was an error opening the selected project.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } sourceDirectory.Text = config.SourceDir; targetDirectory.Text = config.TargetDir; // clear the exclude functions excludeFunctionsList.Items.Clear(); excludeFunctionsList.Items.AddRange(config.ExcludeFunctions); for (int idx = 0; idx < excludeFunctionsList.Items.Count; idx++) { excludeFunctionsList.SetItemChecked(idx, true); } // clear the exclude variables excludeVariablesList.Items.Clear(); excludeVariablesList.Items.AddRange(config.ExcludeVariables); for (int idx = 0; idx < excludeVariablesList.Items.Count; idx++) { excludeVariablesList.SetItemChecked(idx, true); } List <string> itemsToCheck = new List <string>(config.FilesToObfuscate); for (int idx = 0; idx < obfuscateList.Items.Count; idx++) { obfuscateList.SetItemChecked(idx, itemsToCheck.Contains((string)obfuscateList.Items[idx])); } } }
/// <summary> /// Saves the current project settings to an XML file that can be reloaded later or used /// to run the command line version of this tool. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveProjectToolStripMenuItem_Click(object sender, EventArgs e) { ObfuscationConfig config = GenerateConfig(); SaveFileDialog dlg = new SaveFileDialog(); dlg.DefaultExt = "obxml"; dlg.Filter = "PHP Obfuscator XML (*.obxml)|*.obxml"; //dlg.InitialDirectory = "c:\\"; dlg.FileName = "New Project"; if (DialogResult.OK == dlg.ShowDialog()) { string filename = dlg.FileName; config.Save(filename); } }
static void Main(string[] args) { if (args.Length != 1 || args[0] == "/?") { OutputUsage(); return; } if (!File.Exists(args[0])) { Console.WriteLine("Can not find the specified PHP Obfustator Project File: " + args[0]); return; } ObfuscationConfig config = null; try { config = ObfuscationConfig.Open(args[0]); } catch (Exception) { Console.WriteLine("Could not open the specified PHP Obfuscator Project File: " + args[0]); return; } if (null == config) { Console.WriteLine("Could not open the specified PHP Obfuscator Project File: " + args[0]); return; } try { ObfuscatorUI ui = new ObfuscatorUI(); Obfuscator obfuscator = new Obfuscator(ui); obfuscator.OutputPatterns(); obfuscator.Start(config, false); } catch (Exception exp) { Console.WriteLine("There was an error obfuscating your project: " + exp.Message); return; } }
/// <summary> /// Generates a configuation file that can be reloaded in subsequent executions of this tool, or /// can be used to run the command line version of this tool. /// </summary> /// <returns></returns> private Obfuscation.ObfuscationConfig GenerateConfig() { Obfuscation.ObfuscationConfig config = new ObfuscationConfig(); config.SourceDir = sourceDirectory.Text; config.TargetDir = targetDirectory.Text; config.RemoveWhitespace = removeWhitespace.Checked; config.RenameVariables = obfuscateVariableNames.Checked; config.RenameFunctions = obfuscateFunctionNames.Checked; List <string> excludeFunctions = new List <string>(excludeFunctionsList.CheckedItems.Count); foreach (string item in excludeFunctionsList.CheckedItems) { excludeFunctions.Add(item); } config.ExcludeFunctions = excludeFunctions.ToArray(); List <string> excludeVariables = new List <string>(excludeVariablesList.CheckedItems.Count); foreach (string item in excludeVariablesList.CheckedItems) { excludeVariables.Add(item); } config.ExcludeVariables = excludeVariables.ToArray(); List <string> filesToObfuscate = new List <string>(obfuscateList.CheckedItems.Count); foreach (string file in obfuscateList.CheckedItems) { filesToObfuscate.Add(file); } config.FilesToObfuscate = filesToObfuscate.ToArray(); return(config); }