Exemple #1
0
            /// <summary>
            /// スクリプトで参照するアセンブリを追加する
            /// </summary>
            /// <remarks>
            /// アセンブリの参照はコンパイル前に追加してください。
            /// </remarks>
            /// <param name="assemblyName">スクリプトで参照するアセンブリ名</param>
            public void AddReference(string assemblyName)
            {
                IVsaReferenceItem refItem = (IVsaReferenceItem)vsaEngine.Items.CreateItem
                                                (assemblyName, VsaItemType.Reference, VsaItemFlag.None);

                refItem.AssemblyName = assemblyName;
            }
Exemple #2
0
        // inititalize engine
        public void createVsaEngine()
        {
            vsaEngine             = new VsaEngine();
            vsaEngine.RootMoniker = "ScriptGlobals://JScript";
            vsaEngine.Site        = this;
            vsaEngine.InitNew();
            vsaEngine.RootNamespace = "emu";

            // add system references
            IVsaReferenceItem refItem = (IVsaReferenceItem)vsaEngine.Items.CreateItem("mscorlib", VsaItemType.Reference, VsaItemFlag.None);

            refItem.AssemblyName = "mscorlib.dll";
            refItem = (IVsaReferenceItem)vsaEngine.Items.CreateItem("system", VsaItemType.Reference, VsaItemFlag.None);
            refItem.AssemblyName = "System.dll";


            //// add propertybag for script variables
            //IVsaGlobalItem item = (IVsaGlobalItem)vsaEngine.Items.CreateItem("oldvars", VsaItemType.AppGlobal, VsaItemFlag.None);
            //item.TypeString = "System.Collections.HashTable";
            //globalItemLookupTable["oldvars"] = scriptVariables;

            // add object for eval results
            IVsaGlobalItem item = (IVsaGlobalItem)vsaEngine.Items.CreateItem("scrEvalResult", VsaItemType.AppGlobal, VsaItemFlag.None);

            item.TypeString = evalResult.GetType().FullName;
            globalItemLookupTable["scrEvalResult"] = evalResult;

            vsaEngine.GenerateDebugInfo = false;

            VSAEngineCreated = true;
        }
Exemple #3
0
        /// <summary>
        /// Adds the reference item to the engine.
        /// </summary>
        /// <param name="path">Path to reference.</param>
        /// <param name="assemblyName">AssemblyName of reference.</param>
        private void InternalAddReference(string path, string assemblyName)
        {
            if (path.Trim().Length > 0 && !path.EndsWith(@"\"))
            {
                path += @"\";
            }
            path += assemblyName;
            Debug.Assert(_engine != null, "You cannot add references until a script has been set or loaded.");
            IVsaReferenceItem item = _engine.Items.CreateItem(path, VsaItemType.Reference, VsaItemFlag.None) as IVsaReferenceItem;

            item.AssemblyName = assemblyName;
        }
Exemple #4
0
        public JScriptEngine(object scriptGlobal) : base(scriptGlobal)
        {
            engine             = new Microsoft.JScript.Vsa.VsaEngine();
            engine.RootMoniker = "sharpvectors://jsengine/" + counter++;
            engine.Site        = this;
            engine.InitNew();
            engine.RootNamespace     = "SharpVectors.Scripting";
            engine.GenerateDebugInfo = false;
            engine.RevokeCache();
            engine.SetOption("Fast", false);

            items = engine.Items;
            Assembly          asm     = typeof(SharpVectors.Scripting.JScriptEngine).Assembly;
            IVsaReferenceItem refItem = (IVsaReferenceItem)items.CreateItem(asm.Location, VsaItemType.Reference, VsaItemFlag.None);

            refItem.AssemblyName = asm.Location;
        }
Exemple #5
0
        //
        // Entry point
        //
        private static void Main(string [] args)
        {
            if (args.Length < 1)
            {
                Usage();
                Environment.Exit(0);
            }
            MainDriver(args);
            VsaEngine engine = new VsaEngine();

            engine.InitVsaEngine("mjs:com.mono-project", new MonoEngineSite());

            foreach (string asm in references)
            {
                IVsaReferenceItem item = (IVsaReferenceItem)engine.Items.CreateItem(asm, VsaItemType.Reference, VsaItemFlag.None);
                item.AssemblyName = asm;
            }

            string asm_name = String.Empty;

            foreach (Assembly assembly in assemblies)
            {
                asm_name = assembly.GetName().FullName;
                IVsaReferenceItem item = (IVsaReferenceItem)engine.Items.CreateItem(asm_name, VsaItemType.Reference, VsaItemFlag.None);
                item.AssemblyName = asm_name;
            }

            foreach (string file in files)
            {
                IVsaCodeItem item = (IVsaCodeItem)engine.Items.CreateItem(file, VsaItemType.Code, VsaItemFlag.None);
                item.SourceText = GetCodeFromFile(file);
            }
            engine.SetOption("debug", want_debugging_support);
            engine.SetOption("link_path", link_paths);
            engine.SetOption("first_source", first_source);
            engine.SetOption("assemblies", assemblies);
            engine.SetOption("out", output_file);
            if (warning_level != -1)
            {
                engine.SetOption("WarningLevel", warning_level);
            }
            engine.Compile();
        }
        /// <summary>
        /// This method loads the import dlls that a script needs to run.
        /// </summary>
        /// <param name="IVsaItems">Reference items added to the .NET script engine.</param>
        public override void LoadAssemblies(IVsaItems items)
        {
            string assemblyName;

            // system.dll
            assemblyName = "system.dll";
            IVsaReferenceItem refItem = (IVsaReferenceItem)items.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);

            refItem.AssemblyName = assemblyName;

            // mscorlib.dll
            assemblyName         = "mscorlib.dll";
            refItem              = (IVsaReferenceItem)items.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
            refItem.AssemblyName = assemblyName;

            // system.windows.forms.dll
            assemblyName         = "system.windows.forms.dll";
            refItem              = (IVsaReferenceItem)items.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
            refItem.AssemblyName = assemblyName;
        }
Exemple #7
0
        private bool _LoadScript(string sScriptFilename)
        {
            if (!CONFIG.bLoadScript)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(sScriptFilename))
            {
                return(false);
            }
            if (!File.Exists(sScriptFilename))
            {
                return(false);
            }
            _scriptCount++;
            if (this._BeforeRulesCompile != null)
            {
                this._BeforeRulesCompile(sScriptFilename);
            }
            foreach (object obj2 in htMenuScripts.Keys)
            {
                ((MenuItem)obj2).Parent.MenuItems.RemoveAt(((MenuItem)obj2).Index);
            }
            htMenuScripts.Clear();
            foreach (PreferenceBag.PrefWatcher watcher in this.listWeaklyHeldWatchers)
            {
                FiddlerApplication.Prefs.RemoveWatcher(watcher);
            }
            this.listWeaklyHeldWatchers.Clear();
            StreamReader reader = new StreamReader(new FileStream(sScriptFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8, true);
            string       str    = reader.ReadToEnd();

            reader.Close();
            try
            {
                this._engine             = new VsaEngine();
                this._engine.RootMoniker = "fiddler://script/" + _scriptCount;
                this._engine.Site        = this.objVSASite;
                this._engine.InitNew();
                this._engine.RootNamespace     = "Fiddler.ScriptNamespace";
                this._engine.GenerateDebugInfo = false;
            }
            catch (EntryPointNotFoundException)
            {
                FiddlerApplication.DoNotifyUser("Unable to initialize FiddlerScript. This typically indicates that you are attempting to run Fiddler on .NET Framework v4.\n\nYour machine may have the unsupported OnlyUseLatestCLR registry key set.", "Unsupported configuration", MessageBoxIcon.Hand);
                this.Ready = false;
                return(false);
            }
            IVsaItems items = this._engine.Items;

            foreach (string str2 in CONFIG.sScriptReferences.Split(new char[] { ';' }))
            {
                if (str2.Trim().Length > 0)
                {
                    IVsaReferenceItem item = (IVsaReferenceItem)items.CreateItem(str2, VsaItemType.Reference, VsaItemFlag.None);
                    item.AssemblyName = str2;
                }
            }
            IVsaGlobalItem item2 = (IVsaGlobalItem)items.CreateItem("FiddlerObject", VsaItemType.AppGlobal, VsaItemFlag.None);

            item2.TypeString = "Fiddler.FiddlerScript";
            item2            = (IVsaGlobalItem)items.CreateItem("FiddlerScript", VsaItemType.AppGlobal, VsaItemFlag.None);
            item2.TypeString = "Fiddler.FiddlerScript";
            IVsaCodeItem item3 = (IVsaCodeItem)items.CreateItem("Handlers", VsaItemType.Code, VsaItemFlag.None);

            item3.SourceText = str;
            if (!this._engine.Compile())
            {
                this.Ready = false;
                return(false);
            }
            this._engine.Run();
            this.Ready = true;
            this._typeScriptHandlers = this._engine.Assembly.GetType("Fiddler.ScriptNamespace.Handlers");
            if (this._typeScriptHandlers == null)
            {
                this._ClearCachedMethodPointers();
            }
            else
            {
                this._ExtractMethodPointersFromScript();
                foreach (FieldInfo info in this._typeScriptHandlers.GetFields(BindingFlags.Public | BindingFlags.Static))
                {
                    if (info.FieldType == typeof(bool))
                    {
                        RulesOption customAttribute = (RulesOption)Attribute.GetCustomAttribute(info, typeof(RulesOption));
                        if (customAttribute != null)
                        {
                            this.CreateRulesMenuItem(info, customAttribute);
                        }
                    }
                    else if (info.FieldType == typeof(string))
                    {
                        RulesString oRule = (RulesString)Attribute.GetCustomAttribute(info, typeof(RulesString));
                        if (oRule != null)
                        {
                            RulesStringValue[] customAttributes = (RulesStringValue[])Attribute.GetCustomAttributes(info, typeof(RulesStringValue));
                            if ((customAttributes != null) && (customAttributes.Length > 0))
                            {
                                Array.Sort <RulesStringValue>(customAttributes);
                                this.CreateRulesMenuForStrings(info, oRule, customAttributes);
                            }
                        }
                    }
                }
                bool flag = true;
                foreach (MethodInfo info2 in this._typeScriptHandlers.GetMethods())
                {
                    MenuItem    item4;
                    ToolsAction action = (ToolsAction)Attribute.GetCustomAttribute(info2, typeof(ToolsAction));
                    if (action != null)
                    {
                        item4 = new MenuItem(action.Name);
                        htMenuScripts.Add(item4, info2);
                        item4.Click += new EventHandler(this.HandleScriptToolsClick);
                        FiddlerApplication._frmMain.mnuTools.MenuItems.Add(item4);
                    }
                    ContextAction action2 = (ContextAction)Attribute.GetCustomAttribute(info2, typeof(ContextAction));
                    if (action2 != null)
                    {
                        if (flag)
                        {
                            item4 = new MenuItem("-");
                            htMenuScripts.Add(item4, null);
                            FiddlerApplication._frmMain.mnuSessionContext.MenuItems.Add(0, item4);
                            flag = false;
                        }
                        item4 = new MenuItem(action2.Name);
                        htMenuScripts.Add(item4, info2);
                        item4.Click += new EventHandler(this.HandleScriptToolsClick);
                        FiddlerApplication._frmMain.mnuSessionContext.MenuItems.Add(0, item4);
                    }
                    BindUIColumn column = (BindUIColumn)Attribute.GetCustomAttribute(info2, typeof(BindUIColumn));
                    if (column != null)
                    {
                        getColumnStringDelegate delFn = (getColumnStringDelegate)Delegate.CreateDelegate(typeof(getColumnStringDelegate), info2);
                        FiddlerApplication._frmMain.lvSessions.AddBoundColumn(column._colName, column._iColWidth, delFn);
                    }
                    QuickLinkMenu menu = (QuickLinkMenu)Attribute.GetCustomAttribute(info2, typeof(QuickLinkMenu));
                    if (menu != null)
                    {
                        QuickLinkItem[] array = (QuickLinkItem[])Attribute.GetCustomAttributes(info2, typeof(QuickLinkItem));
                        if ((array != null) && (array.Length > 0))
                        {
                            Array.Sort <QuickLinkItem>(array);
                            this.CreateQuickLinkMenu(menu.Name, info2, menu.Name, array);
                        }
                    }
                }
                MenuExt.ReadRegistry(FiddlerApplication._frmMain.mnuTools, htMenuScripts);
                try
                {
                    MethodInfo method = this._typeScriptHandlers.GetMethod("Main");
                    if (method != null)
                    {
                        method.Invoke(null, null);
                    }
                }
                catch (Exception exception)
                {
                    FiddlerApplication.DoNotifyUser(string.Concat(new object[] { "There was a problem with your FiddlerScript.\n\n", exception.Message, "\n", exception.StackTrace, "\n\n", exception.InnerException }), "JScript main() failed.");
                }
            }
            if (this._AfterRulesCompile != null)
            {
                this._AfterRulesCompile();
            }
            return(true);
        }