Exemplo n.º 1
0
        public void Start(Writefile writeFile, string binaryPath)
        {
            List <SerializedProcess> readProcesses = new List <SerializedProcess>();

            readProcesses = writeFile.ReadFromBinaryFile <List <SerializedProcess> >(binaryPath);
            Process[]          processlist = Process.GetProcesses();
            byte[]             result;
            Encryption         encryptionManager = new Encryption();
            StringManipulation stringManipulator = new StringManipulation();

            foreach (Process process in processlist)
            {
                Boolean found = false;
                result = encryptionManager.generateHash(process.ProcessName);
                string            processName       = stringManipulator.ByteArrayToString(result);
                SerializedProcess serializedProcess = new SerializedProcess();
                serializedProcess.Name = processName;
                int index = readProcesses.FindIndex(processList => processList.Name == serializedProcess.Name);
                if (index > -1)
                {
                    found = true;
                }
                if (!found)
                {
                    process.Kill();
                }
            }
        }
Exemplo n.º 2
0
        public void Test_ReadAndWriteToBinaryFile()
        {
            SHA256                   shaM        = new SHA256Managed();
            StringManipulation       stringManip = new StringManipulation();
            List <SerializedProcess> processes   = new List <SerializedProcess>();
            SerializedProcess        sprocess    = new SerializedProcess();

            byte[] result;
            result = shaM.ComputeHash(stringManip.ToByteArray("Test 3"));
            Debug.WriteLine(result);
            Debug.WriteLine(stringManip.ByteArrayToString(result));
            sprocess.Name = stringManip.ByteArrayToString(result);
            processes.Add(sprocess);
            sprocess      = new SerializedProcess();
            result        = shaM.ComputeHash(stringManip.ToByteArray("Test 4"));
            sprocess.Name = stringManip.ByteArrayToString(result);
            processes.Add(sprocess);
            String binaryPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\ProcessesBinary.bin";

            writeFile.WriteToBinaryFile <List <SerializedProcess> >(binaryPath, processes, false);
            List <SerializedProcess> readProcesses = new List <SerializedProcess>();

            readProcesses = writeFile.ReadFromBinaryFile <List <SerializedProcess> >(binaryPath);
            CollectionAssert.AreEqual(processes, readProcesses, new SerializedProcess_Comparer());
        }