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)); }
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)); }
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) }
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) }
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; } } }
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); }
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); }
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); }