cl_scanfile() private method

private cl_scanfile ( [ filename, IntPtr &virname, ulong &scanned, IntPtr engine, uint scanoptions ) : int
filename [
virname IntPtr
scanned ulong
engine IntPtr
scanoptions uint
return int
Exemplo n.º 1
0
        /// <summary>
        /// Scans a file for viruses.
        /// </summary>
        /// <param name="filePath">Path to the file to be scanned.</param>
        /// <param name="scanOptions">Scan options.</param>
        /// <param name="virusName">Output variable for the virus name, if detected.</param>
        /// <returns>File status.</returns>
        public ScanResult ScanFile(string filePath, ScanOptions scanOptions, out string virusName)
        {
            // Validate arguments.
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            IntPtr virusNamePtr = IntPtr.Zero;

            ulong scanned = 0;
            uint  options = 0;

            // Convert ScanOptions parameter.
            options = (uint)scanOptions;

            // Perform scan
            var result = (UnsafeNativeMethods.cl_error_t)UnsafeNativeMethods.cl_scanfile(filePath, ref virusNamePtr, ref scanned, _engine, options);

            if (result == UnsafeNativeMethods.cl_error_t.CL_CLEAN)
            {
                // File is clean.
                virusName = string.Empty;

                return(ScanResult.Clean);
            }
            else if (result == UnsafeNativeMethods.cl_error_t.CL_VIRUS)
            {
                // We've detected a virus.
                virusName = Marshal.PtrToStringAnsi(virusNamePtr);

                return(ScanResult.Virus);
            }
            else
            {
                // Probably an error condition.
                throw new ClamException((int)result, ErrorString((int)result));
            }
        }