Exemple #1
0
        private void runScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // This is exposed to the scripts
            IScriptableComponent component = new DummyComponent();

            component.Parent = this;

            //var compiledAssemblyPath = Path.Combine(Environment.CurrentDirectory, ScriptsDirectory, CompiledScriptsAssemblyName);
            //var scriptFiles = Directory.EnumerateFiles(ScriptsDirectory, "*.cs", SearchOption.AllDirectories).ToArray();

            dlg.Filter   = "CSharp Script files (*.cs)|*.cs";
            dlg.FileName = "";// System.Diagnostics.Debugger.IsAttached ? "test.pcap" : "";

            string scriptDir = Application.StartupPath;

            if (Directory.Exists(scriptDir + "\\Visual_TCPRecon\\Scripts\\"))
            {
                scriptDir += "\\Visual_TCPRecon\\Scripts\\";
            }
            else
            {
                for (int i = 0; i < 5; i++)
                {
                    if (!Directory.Exists(scriptDir + "\\Scripts"))
                    {
                        scriptDir = Path.GetDirectoryName(scriptDir);
                    }
                }
                if (Directory.Exists(scriptDir + "\\Scripts"))
                {
                    scriptDir = scriptDir + "\\scripts";
                }
            }

            dlg.InitialDirectory = scriptDir;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            System.Reflection.Assembly scriptAssembly;
            try
            {
                scriptAssembly = Helper.CompileAssembly(dlg.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error compiling script: " + ex.Message);
                return;
            }

            try
            {
                // Find all types that implement the IScript interface in the compiled assembly
                var scriptTypes = Helper.GetTypesImplementingInterface(scriptAssembly, typeof(IScript));

                foreach (var scriptType in scriptTypes)
                {
                    // Creates instances of type and pass component to the constructor
                    var script = (IScript)Activator.CreateInstance(scriptType);
                    script.Run(component);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error executing script: " + ex.Message);
                return;
            }
        }
Exemple #2
0
        private void runScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // This is exposed to the scripts
            IScriptableComponent component = new DummyComponent();
            component.Parent = this;

            //var compiledAssemblyPath = Path.Combine(Environment.CurrentDirectory, ScriptsDirectory, CompiledScriptsAssemblyName);
            //var scriptFiles = Directory.EnumerateFiles(ScriptsDirectory, "*.cs", SearchOption.AllDirectories).ToArray();

            dlg.Filter = "CSharp Script files (*.cs)|*.cs";
            dlg.FileName = "";// System.Diagnostics.Debugger.IsAttached ? "test.pcap" : "";

            string scriptDir = Application.StartupPath;

            if(Directory.Exists(scriptDir + "\\Visual_TCPRecon\\Scripts\\")){
                scriptDir += "\\Visual_TCPRecon\\Scripts\\";
            }else{
                for (int i = 0; i < 5; i++)
                {
                    if (!Directory.Exists(scriptDir + "\\Scripts")) scriptDir = Path.GetDirectoryName(scriptDir);
                }
                if (Directory.Exists(scriptDir + "\\Scripts")) scriptDir = scriptDir + "\\scripts";
            }

            dlg.InitialDirectory = scriptDir;
            if (dlg.ShowDialog() != DialogResult.OK) return;

            System.Reflection.Assembly scriptAssembly;
            try
            {
                scriptAssembly = Helper.CompileAssembly(dlg.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error compiling script: " + ex.Message);
                return;
            }

            try
            {
                // Find all types that implement the IScript interface in the compiled assembly
                var scriptTypes = Helper.GetTypesImplementingInterface(scriptAssembly, typeof(IScript));

                foreach (var scriptType in scriptTypes)
                {
                    // Creates instances of type and pass component to the constructor
                    var script = (IScript)Activator.CreateInstance(scriptType);
                    script.Run(component);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error executing script: " + ex.Message);
                return;
            }
        }