How to use escape characters in a C # string?

4

I am not able to scan a file containing the EICAR (Standard File for Anti-Virus Scanning) characters, because it contains escape characters such as "\", "()", "[]". I need help identifying these characters in my program as being normal inside a string, like other common ones like "a", "b", "1", "2", and so on. Here is the code below:

string[] Lista = new string[] { "X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"};

string dir = @"C:\Program Files (x86)";

private void btnScan_Click(object sender, EventArgs e)
{
   List<string> busca= Directory.GetFiles(dir, "*.dll*", SearchOption.AllDirectories).ToList();                  
   foreach (string item in busca)
   {                                              
     StreamReader stream = new StreamReader(item);
     string ler = stream.ReadToEnd();
            foreach (string st in Lista)
            {
              if (Regex.IsMatch(ler, st))
              {
                btnDelete.Visible = true;
                btnQuarentena.Visible = true;
              }                             
            }
   }
}

I have tried to put EICAR string in this way, but it did not work:

string[] Lista = new string[] { @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"};

Visual Studio always returns me the same escape sequence error, affected by the "\", "[]" and "()" characters.

    
asked by anonymous 17.10.2014 / 02:49

1 answer

4

There is a problem there. You are trying to read a file that is essentially a binary as if it were a text. This will not work. You need to use the BinaryReader class. Alternatively you can use File.ReadAllBytes() . .

byte[] array = File.ReadAllBytes(@"C:\programa.exe");

You will throw the content into a buffer which is nothing more than a array of byte s ( byte[] ) with the

17.10.2014 / 03:37