public bool Load(int sc) { if (!_vlib.lame_open_vdb(null)) { return(false); } _DirTravelWorker = new DirTravelWorker(_scan_obj_queue); for (var i = 0; i < sc; i++) { var s = new ScanWorker(_params, _scan_obj_queue); if (!s.Load(_vlib)) { continue; } _scanners.Add(s); } if (_scanners.Count == 0) { _vlib.lame_close_vdb(); _vlib = null; return(false); } return(true); }
public bool Load() { try { if (!_lib.lame_open_vdb(null)) { return(false); } if (!_lame.Load(_lib)) { _lib.lame_close_vdb(); _lib = null; _lame = null; return(false); } _lame.OnExtractEnterFileEvent = ExtractEnterFileEventHandle; _lame.OnExtractLeaveFileEvent = ExtractLeaveFileEventHandle; _dump_path = Path.Combine(Directory.GetCurrentDirectory(), "bin"); Directory.CreateDirectory(_dump_path); return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(false); }
public Scanner(Lame lame, VirusLib vdb) { if (lame == null || vdb == null) { throw new Exception("Unknown Excepiton"); } this.lame = lame; this.vdb = vdb; }
public bool Load(VirusLib vdb) { if (vdb == null || !_lame.Load(vdb)) { return(false); } return(true); }
private static void LameWithEventTest(VirusLib vdb, string path) { if (vdb == null) { return; } // 1. load var _lame = new LameWithEvent(); _lame.EnterFileEvent = EnterFileEventHandle; _lame.LeaveFileEvent = LeaveFileEventHandle; _lame.AlarmEvent = AlarmEventHandle; if (!_lame.Load(vdb)) { return; } //2. scan if (File.Exists(path)) { _lame.ScanFile(path); } else if (Directory.Exists(path)) { var files = Directory.GetFiles(path); foreach (var f in files) { _lame.ScanFile(f); } //travel dir...... } //3. _lame.Unload(); }
static void Main(string[] args) { if (args.Length == 0) { return; } VirusLib vdb = new VirusLib(); if (!vdb.lame_open_vdb(null)) { Console.WriteLine("Faild to load virus lib."); return; } LameTest(vdb, args[0]); LameWithEventTest(vdb, args[0]); vdb.lame_close_vdb(); }
static void LameWithEventTest(VirusLib vdb, string path) { if (vdb == null) { return; } // 1. load LameWithEvent _lame = new LameWithEvent(); _lame.SetEventHandle(PrintScanResult); if (!_lame.Load(vdb)) { return; } //2. scan if (File.Exists(path)) { _lame.ScanFile(path); } else if (Directory.Exists(path)) { string[] files = Directory.GetFiles(path); foreach (string f in files) { _lame.ScanFile(f); } //travel dir...... } //3. _lame.Unload(); }
static void LameTest(VirusLib vdb, string path) { if (vdb == null) { return; } // 1. load Lame _lame = new Lame(); if (!_lame.Load(vdb)) { return; } //2. scan if (File.Exists(path)) { LameScanResult _result = _lame.ScanFile(path); PrintScanResult(path, _result); } else if (Directory.Exists(path)) { string[] files = Directory.GetFiles(path); foreach (string f in files) { LameScanResult _result = _lame.ScanFile(f); PrintScanResult(f, _result); } //travel dir...... } //3. _lame.Unload(); }
public void Unload() { long _total_files = 0; long _total_virus = 0; long _elapse_minisecod = 0; foreach (var s in _scanners) { s.Unload(); _total_files += s.ScanFileCount; _total_virus += s.VirusCount; if (s.ElapsedMilliseconds > _elapse_minisecod) { _elapse_minisecod = s.ElapsedMilliseconds; } } if (_vlib != null) { _vlib.lame_close_vdb(); _vlib = null; } Console.WriteLine(""); Console.WriteLine("Virus/Files: " + _total_virus + "/" + _total_files + " = {0:0.0000}" + "%", _total_virus / (double)_total_files); var second = _elapse_minisecod / 1000; var min = second / 60 % 60; var hour = second / 60 / 60; second = second % 60; Console.WriteLine("Elapse: " + hour + ":" + min + ":" + second + "." + _elapse_minisecod % 1000); }
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(); } } }
public Scanner(VirusLib vdb) { this.vdb = vdb; }
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(); } } }