示例#1
0
        private static IAttack SamplesOutputExample()
        {
            var samplesOutput = new SamplesOutput();
            var attackName    = "SamplesOutput";
            var attack        = new Attack(new IOutput[] {
                samplesOutput,
            }, name: attackName);

            // To bookkeep a Sample file, call the .Add method with the sample's filename and bytes
            var sampleAFilename = "SamplesOutputExampleA" + MyWarez.Core.Utils.RandomString(10) + ".bin";
            var sampleABytes    = new byte[] { 0xde, 0xad, 0xbe, 0xef };

            samplesOutput.Add(sampleAFilename, sampleABytes);

            // Theres an overload that accepts string instead of byte[]
            var sampleBFilename = "SamplesOutputExampleB" + MyWarez.Core.Utils.RandomString(10) + ".txt";
            var sampleBText     = "Winner Winner";

            samplesOutput.Add(sampleBFilename, sampleBText);

            // There's also an overload .Add method that accepts an object that implements IFile
            var vbscript        = new VBScript("MsgBox 8675309"); // VBScript implemented IFile, as do most of the classes in MyWarez.Core
            var sampleCFilename = "SamplesOutputExampleC" + MyWarez.Core.Utils.RandomString(10) + ".vbs";

            samplesOutput.Add(sampleCFilename, vbscript);

            attack.Generate();
            // 3 files should now be in $(ProjectDir)\bin\$(Configuration)\$(TargetFramework)\Output\Samples
            return(attack);
        }
 public VBScriptCode(
     VBScript vbscript, Microsoft.Scripting.Utils.Action <VBScript, IDynamicMetaObjectProvider> lambda,
     SourceUnit sourceUnit)
     : base(sourceUnit)
 {
     _compiledLambda = lambda;
     _vbscript       = vbscript;
 }
示例#3
0
        public VBScriptContext(ScriptDomainManager manager,
                               IDictionary <string, object> options)
            : base(manager)
        {
            // TODO: parse options
            // TODO: register event  manager.AssemblyLoaded
            _vbscript = new VBScript(manager.GetLoadedAssemblyList(), manager.Globals);

            if (options.ContainsKey("Trace") && options["Trace"].Equals(true))
            {
                _vbscript.Trace = true;
            }
        }
        public AnalysisScope(AnalysisScope parent,
                             string name,
                             VBScript runtime,
                             ParameterExpression runtimeParam,
                             ParameterExpression moduleParam,
                             ISourceMapper mapper)
        {
            _parent       = parent;
            _name         = name;
            _runtime      = runtime;
            _runtimeParam = runtimeParam;
            _moduleParam  = moduleParam;
            _mapper       = mapper;

            if (_moduleParam != null)
            {
                _functionTable = new Set <string>(StringComparer.InvariantCultureIgnoreCase);
                _errors        = new List <VBScriptSyntaxError>();
                _docInfos      = new Dictionary <string, SymbolDocumentInfo>();
            }

            _names = new Dictionary <string, ParameterExpression>();
        }
示例#5
0
        // VBScriptImport takes the runtime and module as context for the import.
        // It takes a list of names, what, that either identify a (possibly dotted
        // sequence) of names to fetch from Globals or a file name to load.  Names
        // is a list of names to fetch from the final object that what indicates
        // and then set each name in module.  Renames is a list of names to add to
        // module instead of names.  If names is empty, then the name set in
        // module is the last name in what.  If renames is not empty, it must have
        // the same cardinality as names.
        //
        public static object VBScriptImport(VBScript runtime, IDynamicMetaObjectProvider module,
                                            string[] what, string[] names,
                                            string[] renames)
        {
            // Get object or file scope.
            object value = null;

            if (what.Length == 1)
            {
                string name = what[0];
                if (DynamicObjectHelpers.HasMember(runtime.Globals, name))
                {
                    value = DynamicObjectHelpers.GetMember(runtime.Globals, name);
                    // Since runtime.Globals has Sympl's reflection of namespaces and
                    // types, we pick those up first above and don't risk hitting a
                    // NamespaceTracker for assemblies added when we initialized Sympl.
                    // The next check will correctly look up case-INsensitively for
                    // globals the host adds to ScriptRuntime.Globals.
                }
                else if (DynamicObjectHelpers.HasMember(runtime.DlrGlobals, name))
                {
                    value = DynamicObjectHelpers.GetMember(runtime.DlrGlobals, name);
                }
                else
                {
                    throw new ArgumentException(
                              "Import: can't find name in globals -- " + name);
                }
            }
            else
            {
                // What has more than one name, must be Globals access.
                value = runtime.Globals;
                // For more correctness and generality, shouldn't assume all
                // globals are dynamic objects, or that a look up like foo.bar.baz
                // cascades through all dynamic objects.
                // Would need to manually create a CallSite here with Sympl's
                // GetMemberBinder, and think about a caching strategy per name.
                foreach (string name in what)
                {
                    value = DynamicObjectHelpers.GetMember(
                        (IDynamicMetaObjectProvider)value, name);
                }
            }
            // Assign variables in module.
            if (names.Length == 0)
            {
                if (renames.Length == 0)
                {
                    DynamicObjectHelpers.SetMember((IDynamicMetaObjectProvider)module,
                                                   what[what.Length - 1], value);
                }
                else
                {
                    DynamicObjectHelpers.SetMember((IDynamicMetaObjectProvider)module,
                                                   renames[0], value);
                }
            }
            else
            {
                if (renames.Length == 0)
                {
                    renames = names;
                }
                for (int i = 0; i < names.Length; i++)
                {
                    string name   = names[i];
                    string rename = renames[i];
                    DynamicObjectHelpers.SetMember(
                        (IDynamicMetaObjectProvider)module, rename,
                        DynamicObjectHelpers.GetMember(
                            (IDynamicMetaObjectProvider)value, name));
                }
            }
            return(null);
        } // SymplImport
示例#6
0
        public void Run()
        {
            try {
                switch(scriptLanguage) {
                    case ScriptLanguage.JScript:
                        scriptEngine = new JScript();
                        break;
                    case ScriptLanguage.VBScript:
                        scriptEngine = new VBScript();
                        break;
                    default:
                        throw new CoAppException("Invalid Script Language");
                }
                EXCEPINFO info;
                ActiveScriptParse.InitNew();
                ActiveScript.SetScriptSite(this);

                // add this object in
                GlobalMembers.Add("WScript", this);

                foreach(string key in GlobalMembers.Keys)
                    ActiveScript.AddNamedItem(key, ScriptItem.IsVisible | ScriptItem.GlobalMembers);

                ActiveScriptParse.ParseScriptText(ScriptText, null, IntPtr.Zero, null, 0, 0, 0, IntPtr.Zero, out info);
                ActiveScript.SetScriptState((uint) ScriptState.Connected);
            }
            catch(Exception e) {
                Console.WriteLine(e.Message);
            }
        }