Пример #1
0
        public ClamResult ScanFile(string filepath, uint options = (uint)ClamScanOptions.CL_SCAN_STDOPT)
        {
            ulong          scanned = 0;
            IntPtr         vname   = (IntPtr)null;
            ClamReturnCode ret     = ClamBindings.cl_scanfile(filepath, ref vname, ref scanned, engine, options);

            if (ret == ClamReturnCode.CL_VIRUS)
            {
                string virus = Marshal.PtrToStringAnsi(vname);

                ClamResult result = new ClamResult();
                result.ReturnCode = ret;
                result.VirusName  = virus;
                result.FullPath   = filepath;

                return(result);
            }
            else if (ret == ClamReturnCode.CL_CLEAN)
            {
                return new ClamResult()
                       {
                           ReturnCode = ret, FullPath = filepath
                       }
            }
            ;
            else
            {
                throw new Exception("Expected either CL_CLEAN or CL_VIRUS, got: " + ret);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            // ClamAV Automator
            using (ClamEngine e = new ClamEngine())
            {
                foreach (string file in args)
                {
                    ClamResult result = e.ScanFile(file);

                    if (result != null && result.ReturnCode == ClamReturnCode.CL_VIRUS)
                    {
                        Console.WriteLine("Found: " + result.VirusName);
                    }
                    else
                    {
                        Console.WriteLine("File Clean!");
                    }
                }
            }   // engine is disposed of here and the allocated engine freed automatically
        }