Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Invalid Param.");
                Help();
                return;
            }


            VirusLib vdb      = null;
            IScan    _Scanner = null;

            try
            {
                vdb = new VirusLib();
                if (!vdb.lame_open_vdb(null))
                {
                    Console.WriteLine("Faild to load virus lib.");
                    return;
                }

                List <string> path_list  = new List <string>();
                List <string> param_list = new List <string>();

                int scan_thread_count = 2;
                int down_thread_count = 1;

                bool bShowVerion   = false;
                bool bShowLicense  = false;
                bool bShowFileList = false;
                bool bHold         = false;
                bool bMd5List      = false;
                foreach (string s in args)
                {
                    string vl = s.ToLower();
                    if (s.StartsWith("-"))
                    {
                        if (vl == "-version")
                        {
                            bShowVerion = true;
                        }
                        else if (vl == "-license")
                        {
                            bShowLicense = true;
                        }
                        else if (vl == "-hold")
                        {
                            bHold = true;
                        }
                        else if (vl == "-show-file-list")
                        {
                            bShowFileList = true;
                        }
                        else if (vl == "-md5-list")
                        {
                            bMd5List = true;
                        }
                        else if (s.StartsWith("-workers="))
                        {
                            string[] v1 = s.Split('=');
                            if (v1.Length == 2)
                            {
                                string[] v2 = v1[1].Split(',');
                                if (v2.Length > 0)
                                {
                                    int value = 0;
                                    if (int.TryParse(v2[0], out value))
                                    {
                                        scan_thread_count = value;
                                    }

                                    if (v2.Length > 1)
                                    {
                                        if (int.TryParse(v2[1], out value))
                                        {
                                            down_thread_count = value;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            param_list.Add(s.Substring(1));
                        }
                    }
                    else
                    {
                        path_list.Add(s);
                    }
                }


                if (bShowFileList)
                {
                    _Scanner = new ScannerEx(vdb);
                }
                else
                {
                    _Scanner = new Scanner(vdb);
                }


                if (bShowVerion)
                {
                    _Scanner.ShowVersion();
                }

                if (bShowLicense)
                {
                    _Scanner.ShowLicense();
                }


                foreach (string s in param_list)
                {
                    _Scanner.SetParam(s);
                }

                if (!_Scanner.Load())
                {
                    return;
                }

                if (bMd5List)
                {
                    TaskScanner task = new TaskScanner(_Scanner, path_list);
                    task.Run(scan_thread_count, down_thread_count);
                }
                else
                {
                    foreach (string s in path_list)
                    {
                        _Scanner.Scan(s);
                    }
                }



                if (bHold)
                {
                    Console.Read();
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (_Scanner != null)
                {
                    _Scanner.UnLoad();
                }

                if (vdb != null)
                {
                    vdb.lame_close_vdb();
                }
            }
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Invalid Param.");
                Help();
                return;
            }

            VirusLib vdb      = null;
            IScan    _Scanner = null;

            try
            {
                vdb = new VirusLib();
                if (!vdb.lame_open_vdb(null))
                {
                    Console.WriteLine("Faild to load virus lib.");
                    return;
                }

                var path_list  = new List <string>();
                var param_list = new List <string>();

                var bShowVerion   = false;
                var bShowLicense  = false;
                var bShowFileList = false;
                var bHold         = false;
                var bMd5List      = false;
                foreach (var s in args)
                {
                    var vl = s.ToLower();
                    if (s.StartsWith("-"))
                    {
                        if (vl == "-version")
                        {
                            bShowVerion = true;
                        }
                        else if (vl == "-license")
                        {
                            bShowLicense = true;
                        }
                        else if (vl == "-hold")
                        {
                            bHold = true;
                        }
                        else if (vl == "-show-file-list")
                        {
                            bShowFileList = true;
                        }
                        else if (vl == "-md5-list")
                        {
                            bMd5List = true;
                        }
                        else
                        {
                            param_list.Add(s.Substring(1));
                        }
                    }
                    else
                    {
                        path_list.Add(s);
                    }
                }

                if (bShowFileList)
                {
                    _Scanner = new ScannerEx(vdb);
                }
                else
                {
                    _Scanner = new Scanner(vdb);
                }


                if (bShowVerion)
                {
                    _Scanner.ShowVersion();
                }
                if (bShowLicense)
                {
                    _Scanner.ShowLicense();
                }


                foreach (var s in param_list)
                {
                    _Scanner.SetParam(s);
                }

                if (!_Scanner.Load())
                {
                    return;
                }


                foreach (var s in path_list)
                {
                    _Scanner.Scan(s);
                }

                if (bHold)
                {
                    Console.Read();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (_Scanner != null)
                {
                    _Scanner.UnLoad();
                }

                if (vdb != null)
                {
                    vdb.lame_close_vdb();
                }
            }
        }