Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine($"{AppDomain.CurrentDomain.FriendlyName} ruleFileName fileMaskToScan");
                return;
            }

            string ruleFileName   = args[0];
            string fileMaskToScan = args[1];

            string ruleContent = File.ReadAllText(ruleFileName);

            SingaError compilerResult = SingaRule.Compile(ruleContent);

            Directory.GetFiles(Directory.GetCurrentDirectory(), fileMaskToScan).ToList().ForEach(f =>
            {
                string normalizedPath    = Path.GetFullPath(f);
                byte[] fileToScanContent = File.ReadAllBytes(normalizedPath);

                if (compilerResult.rule.Scan(fileToScanContent))
                {
                    Console.WriteLine($"`{compilerResult.rule.name}` {Localization.ResourceManager.GetString("TriggeredOn", CultureInfo.GetCultureInfo("en"))} `{normalizedPath}`");
                }
            });
        }
Exemplo n.º 2
0
        private void btnCompile_Click(object sender, EventArgs e)
        {
            ResetCodeFont();

            txtOut.ResetText();

            SingaError compilerResult = SingaRule.Compile(rtxtCode.Text);

            if (compilerResult.rule is null)
            {
                txtOut.Text = compilerResult.ErrorMessage;

                var wordSkipper = new CRegexSkipper(@"\w");
                var ww          = compilerResult.ww;

                int errorStartPos = ww.GetCurrentPosition();
                wordSkipper.ExpectIt(ref ww);
                int errorEndPos = ww.GetCurrentPosition();

                HighLigthError(errorStartPos, errorEndPos);

                return;
            }

            StringBuilder output = new StringBuilder("");

            Directory.GetFiles(Directory.GetCurrentDirectory(), txtFileMask.Text).ToList().ForEach(f =>
            {
                string normalizedPath    = Path.GetFullPath(f);
                byte[] fileToScanContent = File.ReadAllBytes(normalizedPath);

                if (compilerResult.rule.Scan(fileToScanContent))
                {
                    var temp = $"`{compilerResult.rule.name}` {Localization.ResourceManager.GetString("TriggeredOn", _cultureInfo).ToLower()} `{normalizedPath}`";
                    output.Append(temp);
                    output.Append(Environment.NewLine);
                }
            });

            txtOut.Text = output.ToString();
        }