簡易掃描工具快速開發

來源:互聯網
上載者:User

win
grep:

簡介摘自:http://gnuwin32.sourceforge.net/packages/grep.htm
Description
Grep
searches one or more input files for lines containing a match to a specified
pattern. By default, grep prints the matching lines.
感謝luoluo同學介紹的工具。

ps:直接下載的binary檔案缺少好幾個DLL下面這個是已經補充好直接能用的
grep-2.5.4-bin.rar

使用方法:

開啟cmd進入grep工具所在目錄

輸入grep命令例如:grep -i -R -E “document/.write|innerHTML” D:/Work/javaprojests/et
> et-dom.txt

grep就會去找D:/Work/javaprojests/et
下掃描所有檔案中是否有包含document.write或者innerHTML的並產生結果et-dom.txt

至此我們知道了如何利用grep進行掃描,但是每次都這麼敲命令有點累,我們用C#Win App封裝下。

Win App封裝

設計win App介面如下:

添加代碼實現掃描:

1.新增Class scanJS添加調用Grep進行掃描的代碼

        private string CheckAll(string folderName, string
fileName)
        {
            Process cmd = new
Process();
            cmd.StartInfo.FileName = “cmd.exe”;
           
cmd.StartInfo.RedirectStandardOutput = true;
           
cmd.StartInfo.RedirectStandardInput = true;
           
cmd.StartInfo.UseShellExecute = false;
           
cmd.StartInfo.CreateNoWindow = false;
            cmd.Start();
           
cmd.StandardInput.WriteLine(”grep -i -R -E -n –include=’*.vm|*.js’
/”document//.write|innerHTML /” ” + folderName + ” > ” +
fileName);
            cmd.StandardInput.WriteLine(”exit”);
           
string info = cmd.StandardOutput.ReadToEnd();
           
cmd.WaitForExit();
            cmd.Close();
            return
info;
        }

2. 在介面Check按鈕Click事件中調用scanJS

            if (!String.IsNullOrEmpty(this.textBoxFile.Text) &&
!String.IsNullOrEmpty(this.textBoxFolder.Text))
           
{
                if (this.checkBoxDom.Checked)
               
{
                    this.richTextBox.Text = “Start to
check:/r/n”;
                    scanJS sj = new
scanJS();
                   
this.richTextBox.AppendText(sj.check(this.textBoxFolder.Text,
this.textBoxFile.Text));
                    this.richTextBox.Text +=
“/r/ncheck Finished!”;
                   
               
}
            }

至此我們完成了一個簡易的掃描JS的工具。

3. 後期改進和缺陷

    1)  如果對產生的txt檔案報告不滿意可再對txt進行解析整理成html檔案。

     2) grep雖然快但是也有缺陷,不能組合多種查詢條件排除。(適合查詢大量檔案時使用效率高)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.