コード例 #1
0
ファイル: Scan.cs プロジェクト: imxingquan/FileStrRep
        private void _run(object f)
        {
            //if (RunStartEvent != null)
            //    RunStartEvent("开始.....");

            try
            {
                ScanParam p          = _param;
                string[]  files      = (string[])f;// EnumerateFiles(p.path, p.pattern);
                Encoding  srcEncode  = Encoding.GetEncoding(p.SRC_ENCODING);
                Encoding  destEncode = Encoding.GetEncoding(p.DEST_ENCODING);

                foreach (var item in files)
                {
                    filenums++;
                    ScanEventArgs args = new ScanEventArgs();
                    StreamReader  sr   = new StreamReader(item, srcEncode);
                    string        c    = sr.ReadToEnd();
                    sr.Close();
                    if (c.IndexOf(p.oldstr) > 0)
                    {
                        args.trojanfile = string.Format("找到特征文件 {0}", item);
                        if (p.shift) //替换
                        {
                            c = c.Replace(p.oldstr, p.newstr);
                            StreamWriter sw = new StreamWriter(item, false, destEncode);
                            sw.Write(c);
                            sw.Close();
                        }
                        trojan_filenums++;
                    }
                    if (this.OnRunningEvent != null)
                    {
                        args.currentfile = string.Format("扫描文件: {0}", item);
                        OnRunningEvent(args);
                    }
                }
            }
            catch (Exception ex)
            {
                if (this.OnRunningEvent != null)
                {
                    string msg = ex.Message + "\r\n" + ex.StackTrace;
                    //OnRunningEvent(new ScanEventArgs() { message = msg });
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: imxingquan/FileStrRep
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (0 == (int)btnStart.Tag)
            {
                btnStart.Tag  = 1;
                btnStart.Text = "停止";

                textBox1.Text = "";

                string path = textBox_DestDir.Text.Trim();
                if (!Directory.Exists(path))
                {
                    ErrorTips(textBox_DestDir, "目录不存在");
                    textBox_DestDir.Focus();
                    return;
                }
                string pattern = textBox_Pattern.Text.Trim();
                if (pattern.Length == 0)
                {
                    ErrorTips(textBox_Pattern, "文件名模式不能为空啊啊!");
                    return;
                }


                string src_str = textBox_SrcStr.Text;
                if (src_str.Length == 0)
                {
                    ErrorTips(textBox_SrcStr, "查找的字符串不能为空啊!!");
                    return;
                }

                if ("" == comboBox_SrcEncode.Text)
                {
                    ErrorTips(textBox_Pattern, "原文件编码不能为空啊啊!");
                    return;
                }
                if ("" == comboBox_DescEncode.Text)
                {
                    ErrorTips(textBox_Pattern, "目标文件编码不能为空啊啊!");
                    return;
                }

                ScanParam p = new ScanParam();
                p.path          = path;
                p.oldstr        = src_str;
                p.newstr        = textBox_DestStr.Text;
                p.pattern       = textBox_Pattern.Text.Trim();
                p.SRC_ENCODING  = comboBox_SrcEncode.Text;
                p.DEST_ENCODING = comboBox_DescEncode.Text;
                p.shift         = !checkBox_OnlyScan.Checked;

                Scan scan = new Scan(p);
                scan.OnRunningEvent += new Scan.ScanDelegate(scan_RunningEvent);
                scan.OnStopEvent    += new Scan.ScanDelegate(scan_OnStopEvent);

                thread = new Thread(scan.scanning);
                thread.Start(path);
            }
            else
            {
                if (thread != null)
                {
                    btnStart.Text = "开始";
                    btnStart.Tag  = 0;
                    if (thread.ThreadState == ThreadState.Running)
                    {
                        thread.Abort();
                    }
                }
            }
        }
コード例 #3
0
ファイル: Scan.cs プロジェクト: imxingquan/FileStrRep
 public Scan(ScanParam param)
 {
     _param = param;
 }