Exemplo n.º 1
0
        internal static void deletionOccured(FileSystemEventArgs e)
        {
            string[] filesInDirectory = null;

            filesInDirectory = Directory.GetFiles(returnFilePath(e.FullPath));

            Boolean newSimilarFileIsCreated = false;

            ShannonEntropy entropyCreator = new ShannonEntropy();

            string fileName = returnFileName(e.FullPath);

            double oldEntropy = ShannonEntropy.getSavedEntropies()[e.FullPath];

            foreach (string s in filesInDirectory)
            {
                if (s.Contains(fileName))
                {
                    newSimilarFileIsCreated = true;
                    FileInfo newFileInfo = new FileInfo(s);
                    double   newEntropy  = entropyCreator.CalculateEntropy(newFileInfo);

                    //TODO  react if needed
                    entropyHandler(e, oldEntropy, newEntropy);
                }
            }

            ShannonEntropy.removeKeyFromSavedEntropies(e.FullPath);
        }
Exemplo n.º 2
0
        public static void renameDetectedInFile(string pathOld, string pathNew)
        {
            ShannonEntropy tempEntropyCalculator = new ShannonEntropy();
            //Hvad gør vi hvis filen ikke eksisterer længere?


            FileInfo tempFileInf = new FileInfo(pathNew);

            double changedFileEntropy = tempEntropyCalculator.CalculateEntropy(tempFileInf);


            List <DateTime> temp = new List <DateTime>();

            if ((changedFileEntropy - entropiesOfFiles[pathOld]) > shannonThreshold)
            {
                DateTime now = DateTime.Now;
                foreach (DateTime t in threshold)
                {
                    if (600 < now.Subtract(t).Seconds)
                    {
                        temp.Add(t);
                    }
                }

                foreach (DateTime t in temp)
                {
                    threshold.Remove(t);
                }

                if (threshold.Count > thresholdNum)
                {
                    //ALERT!
                }
            }
        }
Exemplo n.º 3
0
        internal static void changeOccured(FileSystemEventArgs e)
        {
            //Kig på entropien før og efter
            Dictionary <string, double> savedEntropies = ShannonEntropy.getSavedEntropies();
            FileInfo       changedFile         = new FileInfo(e.FullPath);
            ShannonEntropy entropyCalculator   = new ShannonEntropy();
            Double         changedFileEntropy  = entropyCalculator.CalculateEntropy(changedFile);
            Double         originalFileEntropy = 0.0;

            Console.WriteLine("File " + e.FullPath + " has been changed to and has now an entropy of " + changedFileEntropy);
            if (changedFileEntropy == -1)
            {
                return;
            }

            try
            {
                originalFileEntropy = savedEntropies[e.FullPath];
            }
            catch (Exception)
            {
            }

            entropyHandler(e, originalFileEntropy, changedFileEntropy);
        }
Exemplo n.º 4
0
        internal static void creationOccured(FileSystemEventArgs e)
        {
            //Er der en fil i directoriet der har samme entropi som denne er den blot rykket
            //Løb listen af keys igennem, se value, nogen ens? Godt
            //add til databasen den nye fil, slet den gamle

            Dictionary <string, double> savedEntropies = new Dictionary <string, double>();

            savedEntropies = ShannonEntropy.getSavedEntropies();

            FileInfo createdFileInfo = new FileInfo(e.FullPath);

            ShannonEntropy entropyCreator     = new ShannonEntropy();
            double         createdFileEntropy = entropyCreator.CalculateEntropy(createdFileInfo);


            Console.WriteLine("File " + e.FullPath + " has been created and entropy is now " + createdFileEntropy);
            if (createdFileEntropy == -1)
            {
                return;
            }

            Boolean fileHasBeenMoved = false;
            string  oldFilePath      = "";

            foreach (var item in savedEntropies)
            {
                if (item.Value == createdFileEntropy)
                {
                    //File has been moved
                    fileHasBeenMoved = true;
                    oldFilePath      = item.Key;
                }
            }

            if (fileHasBeenMoved)
            {
                ShannonEntropy.removeKeyFromSavedEntropies(oldFilePath);
                ShannonEntropy.addKeyAndDoubleToSavedEntropies(e.FullPath, createdFileEntropy);
            }
            else
            {
                //TODO find threshold på nye filer og om entropien er for høj
                ShannonEntropy.removeKeyFromSavedEntropies(oldFilePath);
                ShannonEntropy.addKeyAndDoubleToSavedEntropies(e.FullPath, createdFileEntropy);
                if (createdFileEntropy > entropyThreshold)
                {
                    react(e);
                }
            }
        }
Exemplo n.º 5
0
        public static void changeDetectedInFile(string path)
        {
            ShannonEntropy tempEntropyCalculator = new ShannonEntropy();
            //TODO what if the file doesn't exists anymore

            FileInfo tempFileInf = new FileInfo(path);

            double changedFileEntropy = tempEntropyCalculator.CalculateEntropy(tempFileInf);

            Console.WriteLine("File " + path + " has been changed to and has now and entropy of " + changedFileEntropy);
            if (changedFileEntropy == -1)
            {
                return;
            }

            List <DateTime> temp = new List <DateTime>();

            if ((changedFileEntropy - entropiesOfFiles[path]) > shannonThreshold)
            {
                DateTime now = DateTime.Now;
                foreach (DateTime t in threshold)
                {
                    if (600 < now.Subtract(t).Seconds)
                    {
                        temp.Add(t);
                    }
                }

                foreach (DateTime t in temp)
                {
                    threshold.Remove(t);
                }

                if (threshold.Count > thresholdNum)
                {
                    //ALERT!
                }
            }
        }