Beispiel #1
0
 public void AddScript(int script_id, DateTime start, DateTime end, TimeSpan recurrance, int count)
 {
     if (script_id < 0)
     {
         return;
     }
     foreach (Script script in scripts)
     {
         string name = dal.GetScriptNameById(script_id);
         if ((name != null) && (name == script.Name))
         {
             return;//script exists
         }
     }
     try
     {
         Script newScript = new Script(this.ie, dal, script_id);
         newScript.IsRunning = false;
         newScript.Activated = false;
         scripts.Add(newScript);
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(e.Message);
     }
 }
Beispiel #2
0
        protected override void ProcessResource(ScriptCollection aScripts)
        {
            var files = GetXmlFiles(Directories.Scripts);

            if (files.Any())
            {
                OnCategoryProcessing(ResourceTypes.Scripts);
                var previous = SetCurrentDirectory(Directories.Scripts);

                foreach (var file in files)
                {
                    var document = LoadXml(file);

                    if (document != null)
                    {
                        aScripts.Add(new Script()
                        {
                            Name = GetElement(document, "Name").Value,
                            ID   = GetElementValue <int>(document, "ID"),
                            Code = GetElement(document, "Code").Value
                        });
                    }

                    OnAbortProcessingCallback();
                }

                OnCategoryProcessed(ResourceTypes.Scripts);
                SetCurrentDirectory(previous);
            }
        }
 public static ScriptCollection ParseScripts(string fullScriptText)
 {
     ScriptCollection scripts = new ScriptCollection(fullScriptText);
     ScriptSplitter splitter = new ScriptSplitter(fullScriptText);
     foreach (string str in splitter)
     {
         scripts.Add(new Script(str));
     }
     return scripts;
 }
Beispiel #4
0
        public void PowershellScript_ResultFail()
        {
            Script script = new Script();

            script.Name = "Powershell test script.";

            // The powershell script.
            script.Executable = new Executable()
            {
                Path = Utilities.GetIncludedFile("Scripts/PowershellTest_ScriptFail.ps1")
            };

            // Exit Codes
            ExitCodeCollection exitCollection = new ExitCodeCollection();

            exitCollection.Add(new ExitCode()
            {
                Value = 0, Message = "Success", IsSuccess = true
            });
            exitCollection.Add(new ExitCode()
            {
                Value = 1, Message = "Failure"
            });

            // Add all elements into the single script file.
            script.ExitCodes = exitCollection;

            // Add the single script above into a collection of scripts.
            ScriptCollection scriptCollection = new ScriptCollection();

            scriptCollection.Add(script);

            // No Downloads.
            DownloadCollection downloadCollection = new DownloadCollection();

            // Add the 2 main elements, the scripts to run and the downloads to download.
            Setup setup = new Setup();

            setup.Scripts   = scriptCollection;
            setup.Downloads = downloadCollection;


            int exitCode = -1;

            if (setup.Initalize())
            {
                exitCode = setup.Execute();
            }

            // The exit code should be 1, since the script did not match IsSuccess ExitCode.
            Assert.IsTrue(exitCode == 1);
        }
        protected virtual Script DeserializeScript(ReloadedScriptEntry reloadedScript)
        {
            var eventReader      = new EventReader(new MemoryParser(reloadedScript.YamlEvents));
            var scriptCollection = new ScriptCollection();

            // Use the newly created script during second pass for proper cycle deserialization
            var newScript = ((ReloadedScriptEntryLive)reloadedScript).NewScript;

            if (newScript != null)
            {
                scriptCollection.Add(newScript);
            }

            // Try to create script first
            YamlSerializer.Deserialize(eventReader, scriptCollection, typeof(ScriptCollection));
            var script = scriptCollection.Count == 1 ? scriptCollection[0] : null;

            return(script);
        }
Beispiel #6
0
        void ParseScript(byte[] Data, String[] Scripts, int Index)
        {
            //Log(LogLevel.Info, "Parsing script [{0}/{1}].", Index + 1, Count);
            MemoryStream Stream = new MemoryStream(Data);
            BinaryReader Reader = new BinaryReader(Stream);

            if (Reader.ReadUInt32() != 0x54504353)
            {
                Log(LogLevel.Warning, "Invalid script file!");
                return;
            }

            Int16 SmallVer = Reader.ReadInt16();
            Int16 BigVer   = Reader.ReadInt16();

            Reader.ReadUInt64(); // 0x01
            byte[] CheckSum = Reader.ReadBytes(6);

            Log(LogLevel.Debug, "Loaded SCTP File version {0} and checksum 0x{1}.", BigVer, CheckSum.GetHEX());

            Reader.ReadBytes(2);

            if (SmallVer == 0x05 && BigVer == 0x05)
            {
                v5Count++;
                bool IsEncrypted = Reader.ReadBoolean();
                Reader.ReadUInt64();

                Int32  DataLength = Reader.ReadInt32();
                byte[] pData      = Reader.ReadBytes(DataLength);

                if (IsEncrypted)
                {
                    EncCount++;
                    byte[] DecData = new Byte[pData.Length];

                    uint Unk = 0x35;
                    for (int i = 0; i < pData.Length; i++)
                    {
                        DecData[i] = (byte)(pData[i] ^ Unk);
                        Unk       += 0x36;
                    }
                    pData = DecData;
                }

                File.WriteAllBytes(DecryptPath + "\\" + System.IO.Path.GetFileName(Scripts[Index]), pData);

                return;
            }

            Int32  NameLength = Reader.ReadInt32();
            String FileName   = Encoding.ASCII.GetString(Reader.ReadBytes(NameLength));

            Log(LogLevel.Debug, "Got File Name: {0}.", FileName);

            HeroScript Script = new HeroScript(FileName, SmallVer, BigVer);

            Reader.ReadUInt64();
            Int32 FileSize = Reader.ReadInt32();


            int StringCount = (int)Reader.ReadVarNumeric();

            Log(LogLevel.Debug, "Found {0} Strings.", StringCount);
            for (int i = 0; i < StringCount; i++)
            {
                String TempString = Encoding.ASCII.GetString(Reader.ReadBytes((int)Reader.ReadVarNumeric()));
                Log(LogLevel.Debug, "Found String: {0}", TempString);
                Script.AddString(TempString);
            }

            long ELFLength = Reader.ReadVarNumeric();

            Script.ELF = Reader.ReadBytes((int)ELFLength);

            Log(LogLevel.Debug, "Saving ELF file '{0}.elf'.", Script.Name);

            if (Script.ELF[0] != 0x7F && Script.ELF[1] != 'E' && Script.ELF[2] != 'L')
            {
                Log(LogLevel.Error, "Invalid ELF file '{0}'.", Path.GetFileName(Scripts[Index]));
                throw new Exception(String.Format("Invalid ELF file '{0}'.", Path.GetFileName(Scripts[Index])));
            }

            Script.Save(ExtractPath);

            this.scriptBox.Dispatcher.Invoke(
                System.Windows.Threading.DispatcherPriority.Normal,
                new Action(
                    delegate()
            {
                ScriptList.Add(Script);
            }
                    ));
        }
Beispiel #7
0
        public void PowershellScript_Both()
        {
            #region Script 1
            Script script1 = new Script();
            script1.Name       = "Powershell test script 1.";
            script1.Executable = new Executable()
            {
                Path = Utilities.GetIncludedFile("Scripts/PowershellTest_ScriptPass.ps1")
            };

            // Exit Codes
            ExitCodeCollection exitCollection1 = new ExitCodeCollection();
            exitCollection1.Add(new ExitCode()
            {
                Value = 0, Message = "Success", IsSuccess = true
            });
            exitCollection1.Add(new ExitCode()
            {
                Value = 1, Message = "Failure"
            });

            // Add all elements into the script1
            script1.ExitCodes = exitCollection1;
            #endregion

            #region Script 2
            Script script2 = new Script();
            script2.Name       = "Powershell test script 2.";
            script2.Executable = new Executable()
            {
                Path = Utilities.GetIncludedFile("Scripts/PowershellTest_ScriptFail.ps1")
            };

            // Exit Codes
            ExitCodeCollection exitCollection2 = new ExitCodeCollection();
            exitCollection2.Add(new ExitCode()
            {
                Value = 0, Message = "Success", IsSuccess = true
            });
            exitCollection2.Add(new ExitCode()
            {
                Value = 1, Message = "Failure"
            });

            // Add all elements into the script1
            script2.ExitCodes = exitCollection2;
            #endregion

            // Add the single script above into a collection of scripts.
            ScriptCollection scriptCollection = new ScriptCollection();
            scriptCollection.Add(script1);
            scriptCollection.Add(script2);

            // No Downloads.
            DownloadCollection downloadCollection = new DownloadCollection();

            // Add the 2 main elements, the scripts to run and the downloads to download.
            Setup setup = new Setup();
            setup.Scripts   = scriptCollection;
            setup.Downloads = downloadCollection;


            int exitCode = -1;
            if (setup.Initalize())
            {
                exitCode = setup.Execute();
            }

            // Exit code should be 1 as 1 of the 2 scripts didn't have the expected result.
            Assert.IsTrue(exitCode == 1);
        }
        protected virtual Script DeserializeScript(ReloadedScriptEntry reloadedScript)
        {
            var eventReader = new EventReader(new MemoryParser(reloadedScript.YamlEvents));
            var scriptCollection = new ScriptCollection();

            // Use the newly created script during second pass for proper cycle deserialization
            var newScript = ((ReloadedScriptEntryLive)reloadedScript).NewScript;
            if (newScript != null)
                scriptCollection.Add(newScript);

            // Try to create script first
            YamlSerializer.Deserialize(eventReader, scriptCollection, typeof(ScriptCollection));
            var script = scriptCollection.Count == 1 ? scriptCollection[0] : null;
            return script;
        }
Beispiel #9
0
        /// <summary>
        /// Generates a template xml to base custom scripts off of.
        /// </summary>
        /// <param name="savePath">The location the template will be saved.</param>
        public void GenerateXmlTemplate(string savePath)
        {
            ServiceManager.Services.LogService.WriteHeader("Generating Xml Template...");

            #region Script 1
            Script script = new Script();
            script.Name        = "Script 1";
            script.Description = "Does nothing";

            Executable executable = new Executable();
            executable.Path = "C:/Temp/nothing.ps1";

            ArgumentCollection argCollection = new ArgumentCollection();
            argCollection.Add(new Argument()
            {
                Key = "-i", Value = "C:/Temp/something.bin"
            });
            argCollection.Add(new Argument()
            {
                Key = "-x", Value = ""
            });

            ExitCodeCollection exitCollection = new ExitCodeCollection();
            exitCollection.Add(new ExitCode()
            {
                Value = 0, Message = "Files deleted", IsSuccess = true
            });
            exitCollection.Add(new ExitCode()
            {
                Value = 1, Message = "Files failed to delete"
            });
            exitCollection.Add(new ExitCode()
            {
                Value = 2, Message = "Couldn't find any files"
            });

            // Add all elements into the single script file.
            script.Arguments  = argCollection;
            script.ExitCodes  = exitCollection;
            script.Executable = executable;
            #endregion

            #region Script 2
            Script script2 = new Script();
            script2.Name        = "Script 2";
            script2.Description = "Does nothing";

            Executable executable2 = new Executable();
            executable2.Path = "C:/Temp/Downloads/Extracted/SomethingThatWasInAZip.exe";

            ArgumentCollection argCollection2 = new ArgumentCollection();
            argCollection2.Add(new Argument()
            {
                Key = "-install"
            });
            argCollection2.Add(new Argument()
            {
                Key = "-silent"
            });

            ExitCodeCollection exitCollection2 = new ExitCodeCollection();
            exitCollection2.Add(new ExitCode()
            {
                Value = 0, Message = "Script 2 has installed", IsSuccess = true
            });
            exitCollection2.Add(new ExitCode()
            {
                Value = 1, Message = "Failed to install."
            });
            exitCollection2.Add(new ExitCode()
            {
                Value = 2, Message = "Installed but limited."
            });

            // Add all elements into the single script file.
            script2.Arguments  = argCollection;
            script2.ExitCodes  = exitCollection;
            script2.Executable = executable;

            // Add the single script above into a collection of scripts.
            ScriptCollection scriptCollection = new ScriptCollection();
            scriptCollection.Add(script);
            scriptCollection.Add(script2);
            #endregion

            ServiceManager.Services.LogService.WriteLine("Generating Download Collection...");
            DownloadCollection downloadCollection = new DownloadCollection();
            downloadCollection.TimeOut     = 60;
            downloadCollection.RefreshRate = 10;
            downloadCollection.Add(new Download()
            {
                Name = "Nothing Powershell Script", Description = "This script does nothing", DownloadUrl = "www.blank.com/nothing.ps1", DestinationPath = "C:/Temp/Downloads/nothing.ps1"
            });
            downloadCollection.Add(new Download()
            {
                Name = "Test Zip File", Description = "This zip has nothing", DownloadUrl = "www.blank.com/nothing.zip", DestinationPath = "C:/Temp/Downloads", ExtractionPath = "C:/Temp/Downloads/Extracted"
            });

            // Add the 2 main elements, the scripts to run and the downloads to download.
            Setup setup = new Setup();
            setup.Scripts   = scriptCollection;
            setup.Downloads = downloadCollection;

            ServiceManager.Services.LogService.WriteLine("Saving file to: \"{0}\"", savePath);
            setup.Serialize(savePath);
        }