예제 #1
0
        public ResultScan scan(string path_db, string path)
        {
            List <Virus> listVirus = databaseHelper.GetListViruses(path_db);

            binarySearch.SetLists(listVirus);

            string hashValue = hashHelper.HashFile(path);

            Console.WriteLine("Hash value : " + hashValue);

            ResultScan ans = binarySearch.Search(hashValue);

            return(ans);
        }
예제 #2
0
        public ResultScan Search(string hashValue)
        {
            ResultScan ans = new ResultScan()
            {
                IsEmpty = true, VirusName = ""
            };

            int low  = 0;
            int high = viruses.Count;

            while (high > low + 1)
            {
                int mid   = (high + low) / 2;
                var virus = viruses[mid];
                if (virus.HashValue == hashValue)
                {
                    ans.IsEmpty   = false;
                    ans.VirusName = virus.Name;
                    return(ans);
                }

                if (hashValue.CompareTo(virus.HashValue) > 0)
                {
                    low = mid + 1;
                }
                else
                {
                    high = mid - 1;
                }
            }

            if (low < viruses.Count && viruses[low].HashValue == hashValue)
            {
                ans.IsEmpty   = false;
                ans.VirusName = viruses[low].Name;
                return(ans);
            }

            if (high < viruses.Count && viruses[high].HashValue == hashValue)
            {
                ans.IsEmpty   = false;
                ans.VirusName = viruses[high].Name;
                return(ans);
            }

            return(ans);
        }