Beispiel #1
0
 public bool DeleteVirus(Task task, Virus virus)
 {
     task = context.GetTaskById(task.Id);
     if (!Scanner.DeleteVirus(virus))
     {
         return(false);
     }
     task.RemoveVirus(virus);
     context.UpdateTask(task);
     return(context.DeleteVirusFound(virus));
 }
Beispiel #2
0
 public bool MoveToQuarantineVirus(Task task, Virus virus, bool MoveBack = false)
 {
     task = context.GetTaskById(task.Id);
     if (!Scanner.MoveToQuarantine(virus, MoveBack))
     {
         return(false);
     }
     task.UpdateVirus(virus);
     context.UpdateTask(task);
     virus.InQuarantine = !MoveBack;
     return(context.UpdateVirusFound(virus));
 }
Beispiel #3
0
        public bool DeleteVirusFound(Virus virus)
        {
            SqliteConnection connection = GetConnection();

            connection.Open();
            try
            {
                var command = connection.CreateCommand();
                command.CommandText = $@"DELETE FROM viruses_found WHERE path = '{virus.Path}'";
                command.ExecuteScalar();
            }
            catch (Exception) { connection.Close(); return(false); }

            connection.Close();
            return(true);
            //connections.Enqueue(connection)
        }
Beispiel #4
0
        public bool UpdateVirusFound(Virus virus)
        {
            SqliteConnection connection = GetConnection();

            connection.Open();

            try
            {
                var command = connection.CreateCommand();
                command.CommandText = $@"UPDATE viruses_found SET inQuarantine = {virus.InQuarantine} WHERE path = '{virus.Path}'";
                command.ExecuteScalar();
            }
            catch (Exception) { connection.Close(); return(false); }

            connection.Close();
            return(true);
            //connections.Enqueue(connection)
        }
Beispiel #5
0
        protected virtual void CheckFileStream(Stream stream, string path)
        {
            int   offset       = 0;
            bool  malwareFound = false;
            Virus virusFound   = new Virus();

            byte[] data = GetFileCode(stream, ref offset);
            for (int i = 0; i < data.Length - 4 && !malwareFound; i++)
            {
                string sign = GetStringOfBytes(data, i, 4);
                List <VirusDataSet> viruses = context.GetViruses(sign, offset + i);
                foreach (VirusDataSet virus in viruses)
                {
                    if (CheckSignatureFullMatch(virus, data, i))
                    {
                        virusFound = new Virus(path, virus.Name);
                        virusFound.InQuarantine = task.Option == TaskOption.Quarntine;
                        DangerFound(virusFound);
                        malwareFound = true;
                        break;
                    }
                }
            }

            if (malwareFound)
            {
                switch (task.Option)
                {
                case TaskOption.Nothing:
                    break;

                case TaskOption.Quarntine:
                    MoveToQuarantine(virusFound);
                    break;

                case TaskOption.Delete:
                    DeleteVirus(virusFound);
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #6
0
        public bool AddVirusFound(Task task, Virus virus)
        {
            //TODO
            SqliteConnection connection = GetConnection();

            connection.Open();

            var command = connection.CreateCommand();

            try
            {
                command.CommandText = $"INSERT INTO viruses_found (taskId, path, name, inQuarantine) VALUES ({task.Id}, '{virus.Path}', '{virus.Name}', {virus.InQuarantine})";

                command.ExecuteScalar();
            }
            catch (Exception) { connection.Close(); return(false); }
            connection.Close();
            return(true);
            //connections.Enqueue(connection);
        }
Beispiel #7
0
 public static bool MoveToQuarantine(Virus virus, bool MoveBack = false)
 {
     try
     {
         using (var stream = File.Open(virus.Path, FileMode.Open))
         {
             stream.Position = 0;
             if (MoveBack)
             {
                 stream.WriteByte(0x4D);
             }
             else
             {
                 stream.WriteByte(0x51);
             }
             stream.Close();
         }
     }
     catch (Exception) { return(false); }
     return(true);
 }
Beispiel #8
0
        public List <Virus> GetVirusesFound(Task task)
        {
            List <Virus>     viruses    = new List <Virus>();
            SqliteConnection connection = GetConnection();

            connection.Open();
            var command = connection.CreateCommand();

            command.CommandText = $"SELECT path, name, inQuarantine FROM viruses_found WHERE taskId = {task.Id}";
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    Virus virus = new Virus(reader.GetString(0), reader.GetString(1), reader.GetString(2) == "1");
                    viruses.Add(virus);
                }
            }

            connection.Close();
            //connections.Enqueue(connection);
            return(viruses);
        }