Esempio n. 1
0
        /// <summary>
        /// The scan file.
        /// </summary>
        /// <param name="hash"></param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool ScanFile(string hash)
        {
            // If caching is activated, look in cache before scanning
            if (Properties.Settings.Default.UseCashing)
            {
                // If hash is in the clean MD5 cache, then return false
                if (ScannerCaching.IsFileInCache(hash))
                {
                    return(false);
                }
            }


            if (Properties.Settings.Default.UseRAMOnly)
            {
                // All files are cached in memory, and can be accessed
                // without loading any files from HHD
                if (ScannerCaching.IsFileInCache(hash))
                {
                    return(false);
                }
            }

            // Else check the file against the database
            var databaseDirectory = Thread.GetDomain().BaseDirectory + "SuffixArrays\\";
            var suffixArray       = this.DeserializeArray(databaseDirectory + hash.Substring(0, Properties.Settings.Default.SplitOption) + ".data");
            var completeString    =
                this.DeserializeString(databaseDirectory + ScannerConst.StringIdentificationName + hash.Substring(0, Properties.Settings.Default.SplitOption) + ".data");

            if (suffixArray == null && completeString == string.Empty)
            {
                return(false);
            }
            var result = !this.IndexOf(hash, suffixArray, completeString).Equals(-1);

            // If the result is false, then the file is clean
            // and can be added to the cache
            if (!result)
            {
                ScannerCaching.UpdateCache(hash);
            }
            // Report back with findings
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// The scan file.
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool ScanFile(string pattern)
        {
            var prefix    = Convert.ToChar(pattern.Substring(0, Properties.Settings.Default.SplitOption));
            var directory = Thread.GetDomain().BaseDirectory + "\\SuffixArrays\\";

            // If SQL has the database
            if (Properties.Settings.Default.UseHDDOnly)
            {
                if (Properties.Settings.Default.UseCashing)
                {
                    if (ScannerCaching.IsFileInCache(pattern))
                    {
                        // If value is in cache, just return false,
                        // since pattern is clean
                        return(false);
                    }
                }

                var suffixArray = FileUtil.DeserializeArray(directory + "sa_" + prefix);
                var txt         = FileUtil.DeserializeString(directory + "string_" + prefix);
                // TODO: Load files from HDD
                var lcp         = Database.GetLcpTableByPrefix(prefix);
                var suffixarray = Database.GetSuffixArrayTableByPrefix(prefix);
                var text        = Database.GetTextFromDatabase(Convert.ToChar(prefix));

                // If its not in the cache we will use another method
                if (Properties.Settings.Default.UseBinary)
                {
                    var result = !IndexOf(suffixarray, text, pattern).Equals(-1);
                    if (!result)
                    {
                        ScannerCaching.UpdateCache(pattern);
                    }
                    return(result);
                }
                if (Properties.Settings.Default.UseBinaryWLcp)
                {
                    var result = BinarySearchUsingLcp.BinarySearchLcp(text, suffixarray, lcp, pattern);
                    if (!result)
                    {
                        ScannerCaching.UpdateCache(pattern);
                    }
                    return(result);
                }
                if (Properties.Settings.Default.UseSQL)
                {
                    var result = Database.SearchByPattern(pattern);
                    if (!result)
                    {
                        ScannerCaching.UpdateCache(pattern);
                    }
                    return(result);
                }
            }

            // Use memory database
            else if (Properties.Settings.Default.UseRAMOnly)
            {
                // Use caching if activated
                if (Properties.Settings.Default.UseCashing)
                {
                    if (ScannerCaching.CleanCache == null)
                    {
                        ScannerCaching.LoadCashedValues();
                    }
                    // All files are cached in memory, and can be accessed
                    // without loading any files from HHD (they are preloaded)
                    if (ScannerCaching.IsFileInCache(pattern))
                    {
                        return(false);
                    }
                }

                var suffixArray = FileUtil.DeserializeArray(directory + "sa_" + prefix);
                var txt         = FileUtil.DeserializeString(directory + "string_" + prefix);

                // If its not in the cache we will use another method
                if (Properties.Settings.Default.UseBinary)
                {
                    var result = !IndexOf(suffixArray, txt, pattern).Equals(-1);
                    if (!result)
                    {
                        ScannerCaching.UpdateCache(pattern);
                    }
                    return(result);
                }

                //if (Properties.Settings.Default.UseBinaryWLcp)
                //{
                //    var result = !BinarySearchUsingLcp.BinarySearchLcp(txt, suffixArray, pattern);
                //    if (!result) ScannerCaching.UpdateCache(pattern);
                //    return result;
                //}

                if (Properties.Settings.Default.UseSQL)
                {
                    var result = Database.SearchByPattern(pattern);
                    if (!result)
                    {
                        ScannerCaching.UpdateCache(pattern);
                    }
                    return(result);
                }
            }
            return(false);
        }