Пример #1
0
 private void Scaning(string fileName, string _params, Action <VirInfo> reCallAction, Action <ResUsageInfo> reCallAction2)
 {
     Task.Run(() =>
     {
         _isStop      = false;
         _scanProcess = new Process
         {
             StartInfo =
             {
                 Arguments = "\"" + fileName + "\"" + " -output-json" + _params,
                 FileName  = "ramecl.exe",
                 RedirectStandardOutput = true,
                 CreateNoWindow         = true,
                 WindowStyle            = ProcessWindowStyle.Hidden,
                 UseShellExecute        = false
             }
         };
         _scanProcess.Start();
         _scanProcess.BeginOutputReadLine();
         _scanProcess.OutputDataReceived += (o, args) =>
         {
             if (!string.IsNullOrEmpty(args.Data))
             {
                 var objvirInfo = new VirInfo();
                 ParseJsonResult(args.Data, ref objvirInfo);
                 if (!string.IsNullOrEmpty(objvirInfo.FileName))
                 {
                     reCallAction(objvirInfo);
                 }
             }
         };
         reCallAction2(new ResUsageInfo(-10, 0));
         while (!_isStop)
         {
             try
             {
                 if (!_scanProcess.WaitForExit(1000))
                 {
                     var objResUsageInfo = new ResUsageInfo();
                     GetCpuAndRamUsagePercent(ref objResUsageInfo);
                     reCallAction2(objResUsageInfo);
                 }
                 else
                 {
                     _isStop = true;
                 }
             }
             catch
             {
                 _isStop = true;
             }
         }
         reCallAction(new VirInfo("", "", "", true, false, "尚未处理"));
     });
 }
 private void UpdateVirInfoListView(VirInfo content)
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         if (content.FinishFlag)
         {
             ButtonStart.Content  = "开始";
             TbCurrentTarget.Text = "扫描完毕";
             try
             {
                 _watcher.EnableRaisingEvents = false;
                 _watcher.Dispose();
             }
             catch
             {
                 //ignored
             }
             ProcessMetro.Visibility = Visibility.Hidden;
             MetroProcessbar.Stop();
             ScanProcessBar.Visibility  = Visibility.Hidden;
             FileNameTextBox.Visibility = Visibility.Visible;
             SpeedLabel.Content         = (long)(_lastcount / (Math.Abs((DateTime.Now - _startDateTime).TotalSeconds) < 0.5 ? 1 : (DateTime.Now - _startDateTime).TotalSeconds)) + " 个/s";
             EnableAllFuncBtn();
             _isfinished = true;
         }
         else
         {
             if (_lastcount++ == 0)
             {
                 _watcher.EnableRaisingEvents = false;
                 _watcher.Dispose();
                 _startDateTime          = DateTime.Now;
                 ProcessMetro.Visibility = Visibility.Hidden;
                 MetroProcessbar.Stop();
                 ScanProcessBar.Visibility = Visibility.Visible;
                 ScanRunning();
             }
             FileCountLabel.Content = _lastcount.ToString();
             if (string.IsNullOrEmpty(content.VirName) || string.IsNullOrEmpty(content.DetectEngine))
             {
                 TbCurrentTarget.Text = content.FileName;
             }
             else
             {
                 VirInfoList.Add(new VirInfo(content.FileName, content.VirName, content.DetectEngine, content.FinishFlag, content.IsSelected, "尚未处理"));
                 ThreatLabel.Content  = ++_threat;
                 TbCurrentTarget.Text = content.FileName;
             }
         }
     }));
 }
Пример #3
0
        private void ParseJsonResult(string strResultJson, ref VirInfo obj)
        {
            var temp = _last + strResultJson;

            if (temp.IndexOf("{", StringComparison.Ordinal) >= 0)
            {
                _flag          = true;
                obj.FinishFlag = false;
                obj.IsSelected = false;
                try
                {
                    _objJsonResult   = JObject.Parse(temp);
                    obj.FileName     = _objJsonResult["filename"].ToString();
                    obj.VirName      = _objJsonResult["infect"]["threat"].ToString();
                    obj.DetectEngine = _objJsonResult["infect"]["engine"].ToString();
                }
                catch
                {
                    try
                    {
                        obj.FileName = _objJsonResult["filename"].ToString();
                        obj.VirName  = obj.DetectEngine = "";
                    }
                    catch
                    {
                        obj.FileName = "";
                        _last        = temp;
                    }
                }
            }
            else if (_flag)
            {
                obj.FinishFlag = true;
                obj.FileName   = "查杀完毕";
            }
        }