复制一个病毒文件导致我的程序终止



我制作了一个工具,可以将文件从源复制到目标。然而,在复制过程中,该软件遇到了一种被反病毒软件(赛门铁克)标记的病毒。

反病毒病毒导致我的软件关闭,并将该程序隔离为"滴管"。

我有没有办法优雅地处理这种情况,而不是完全关闭我的程序?

我很感激这次行动是反病毒的结果,但我能做些什么来帮助这种情况吗?例如,Robocopy不仅仅是在遇到病毒时终止。

这是我的副本代码;

void CopyFileExactly(CopyParameterBundle cpb, bool overwrite)
{
    string CTP = "", CFP = "";
    CFP = cpb.SourcePath;
    if (cpb.RenameFile)
        CTP = cpb.DestPath ;
    else
        CTP = cpb.DestPath;
    //Check firstly if the file to copy exists
    if (!File.Exists(CFP))
    {
        throw new FileNotFoundException();
    }
    //Check if destination file exists
    //If it does, make it not read only so we can update MAC times
    if (File.Exists(CTP))
    {
        var target = GetFile(CTP);//new FileInfo(CTP);
        if (target.IsReadOnly)
            target.IsReadOnly = false;
    }
    var origin = GetFile(CFP);//new FileInfo(CFP);
    GetFile(CTP).Directory.Create();
    //(new FileInfo(CTP)).Directory.Create();
    origin.CopyTo(CTP, (overwrite ? true : false));
    if (!File.Exists(CTP))
    {
        throw new FileNotFoundException("Destination file not found!");
    }
    var destination = GetFile(CTP);//new FileInfo(CTP);
    if (destination.IsReadOnly)
    {
        destination.IsReadOnly = false;
        destination.CreationTime = origin.CreationTime;
        destination.LastWriteTime = origin.LastWriteTime;
        destination.LastAccessTime = origin.LastAccessTime;
        destination.IsReadOnly = true;
    }
    else
    {
        destination.CreationTime = origin.CreationTime;
        destination.LastWriteTime = origin.LastWriteTime;
        destination.LastAccessTime = origin.LastAccessTime;
    }
    if (performMD5Check)
    {
        var md5Check = compareFileMD5(CFP, CTP);
        cpb.srcMD5Hash = md5Check.Item2;
        cpb.dstMD5Hash = md5Check.Item3;
        if (!md5Check.Item1)
            throw new MD5MismatchException("MD5 Hashes do NOT match!");
    }
}

呼叫代码;

        void BeginCopy(int DegreeOfParallelism, int retryCount, int retryDelay)
    {
        object _lock;
        //Setup cancellation token
        po.CancellationToken = cts.Token;
        //Set max number of threads
        po.MaxDegreeOfParallelism = DegreeOfParallelism;
        //Exceptio logging queue
        var exceptions = new ConcurrentQueue<Exception>();
        var completeItems = new ConcurrentQueue<CopyParameterBundle>();
        var erroredItems = new ConcurrentQueue<CopyParameterBundle>();
        //Logger logger = new Logger(sLogPath);
        //logger.Write("Starting copy");
        Task.Factory.StartNew(() =>
        {
            Parallel.ForEach(CopyParameters,
                po,
                (i, loopState, localSum) =>
                {
                    localSum = retryCount;
                    do
                    {
                        try
                        {
                            //Go off and attempt to copy the file
                            DoWork(i);
                            //Incrememt total count by 1 if successfull
                            i.copyResults.TransferTime = DateTime.Now;
                            i.copyResults.TransferComplete = true;
                            completeItems.Enqueue(i);
                            //logger.Write("Copied file from: " + i.SourcePath + "\" + i.SourceFile + "  =>  " + i.DestPath + "\" + i.SourceFile);
                            break;
                        }
                        catch (Exception ex)
                        {
                            //this.richTextBox1.AppendText("[-] Exception on: " + i.SourcePath + "\" + i.SourceFile + "   => " + ex.Message.ToString() + System.Environment.NewLine);
                            //Exception was thrown when attempting to copy file
                            if (localSum == 0)
                            {
                                //Given up attempting to copy. Log exception in exception queue
                                exceptions.Enqueue(ex);
                                this.SetErrorText(exceptions.Count());
                                //Write the error to the screen
                                this.Invoke((MethodInvoker)delegate
                                {
                                    this.richTextBox1.AppendText("[-] Exception on: " + i.SourcePath + "\" + i.SourceFile + "   => " + ex.Message.ToString() + System.Environment.NewLine);
                                    i.copyResults.TransferComplete = false;
                                    i.copyResults.TransferTime = DateTime.Now;
                                    i.copyResults.exceptionMsg = ex;
                                    erroredItems.Enqueue(i);
                                    //logger.Write("ERROR COPYING FILE FROM : " + i.SourcePath + "\" + i.SourceFile + " => " + i.DestPath + "\" + i.SourceFile + "  => " + ex.Message.ToString() + "  => " + ex.Source);
                                });
                            }
                            //Sleep for specified time before trying again
                            Thread.Sleep(retryDelay);
                            localSum--;
                        }
                        //Attempt to Repeat X times
                    } while (localSum >= 0);
                    //Check cancellation token
                    po.CancellationToken.ThrowIfCancellationRequested();
                    Interlocked.Increment(ref TotalProcessed);
                    this.SetProcessedText(TotalProcessed);
                    //Update Progress Bar
                    this.Invoke((MethodInvoker)delegate
                    {
                        this.progressBar1.Value = (TotalProcessed);
                    });
                });

            //aTimer.Stop();
            this.Invoke((MethodInvoker)delegate
            {
                this.label9.Text = "Process: Writing Log";
            });
            WriteLog(sLogPath, completeItems, erroredItems);
            this.Invoke((MethodInvoker)delegate
            {
                this.label9.Text = "Process: Done!";
            });
            if (exceptions.Count == 0)
                MessageBox.Show("Done!");
            else
                MessageBox.Show("Done with errors!");
            EnableDisableButton(this.button2, true);
            EnableDisableButton(this.button4, false);
        });
    }

发生的情况很可能是防病毒软件知道病毒文件,因此当它检测到文件系统发生更改(移动文件)时,它终止了程序,因为将病毒移动到计算机中的其他位置可能会导致问题(因为这是一种病毒)。它被标记为滴管,基本上是一种用于安装病毒的程序。

编辑:我忘了提一下,为了解决这个问题,你很可能需要许可你的程序。

最新更新