When compiling code antivirus says it's virus and delete it

做~自己de王妃 提交于 2021-02-19 07:30:53

问题


Hi i try to make code in c++. This code only makes text file easy encrypted and save into a new file. And when i compile this code antivirus says, it is virus/spyware Gen:Variant.Kazy.20825. I dont know why it is virus. Here is my code:

#include <iostream>
#include <fstream>
#include <string>


using namespace std;

void controlParameters(int argc){  //check if input parameters are ok
    if(argc == 1){
        cout << "Pokud chcete text zasifrovat, spustte program s parametrem: -enc \"Nazev_souboru.txt\"\n";
        cout << "Pokud ho chcete desifrovat, spustte program s parametrem: -dec \"Nazev_souboru.txt\"\n";
    }else if(argc > 3){
        cout << "Moc parametru. Spustte si program bez parametru.\n";
    }else if(argc < 3){
        cout << "Chybi jeden parametr. Spustte si program bez parametru.\n";
    }else{
        cout << "Vsechno vypada zatim dobre\n";
    }
}

void encryption(string &file);  //encrypt text file
void decryption(string &file);  //decrypt text file
bool controlFile(string &file); //check if file can be opened

int main(int argc, char **argv){
    controlParameters(argc);
    string file;
    file = argv[2];
    if(controlFile(file)){

    }else{
        cout << "Soubor nesel nacist." << endl;
        return -1;
    }
    cout << "Ukonceno.\nZmacknete ENTER pro pokracovani..."<<endl;
    cin.get();
    return 0;
}

bool controlFile(string &file){
    ifstream ifs;
    ifs.open(file);
    if(ifs.is_open()){
        ifs.close();
        return true;
    }else{
        ifs.close();        
        return false;
    }
}

void encryption(string &file){
    ifstream ifs;
    ofstream ofs;
    string line;    
    ifs.open(file);
    ofs.open("encrypt.txt");
    if(ifs.is_open()){
        while(!ifs.eof()){
            getline(ifs,line);
            int a = line.length();
            int i = 0;
            while(i < a){               
                ofs << ((char)(line[i]^100));               
            }
            line.clear();
            ofs << "\n";
        }
    }else{
        cout << "Nelze nacist soubor" << endl;
    }
}

void decryption(string &file){
    ifstream ifs;
    ofstream ofs;
    string line;
    ifs.open(file);
    ofs.open("decrypt.txt");
    if(ifs.is_open()){
        while(!ifs.eof()){
            getline(ifs,line);
            int a =line.length();
            int i = 0;
            while(i < a){               
                ofs << ((char)(line[i]^100));               
            }
            line.clear();
            ofs << "\n";
        }
    }else{
        cout << "Nelze nacist soubor" << endl;
    }
}

回答1:


Antivirus software uses "heuristics" to determine what is a virus and what isn't. So it looks for patterns in the file that does things that it finds suspicious. I can't see anything directly wrong in your code, so I suspect it's a "false-positive". I personally don't like antivirus software, it causes more problems than it solves...

By the way, you could add the "output filename" to your encrypt/decrypt function, and make them one function! ;)




回答2:


It's good practice to exclude your source-control directories from virus scanners; they can cause performance and locking problems even if there are no false positives while performing source-control actions or compiling (I've seen it happen several times).

So if only to make your programming experience more reliable, disable the virus scanner on those directories.

You may still want to scan the final, released version of your executable to help avoid false positives: after all, even if it's not your fault the virus scanner chokes, it's not a good impression to leave behind on a user.



来源:https://stackoverflow.com/questions/14460776/when-compiling-code-antivirus-says-its-virus-and-delete-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!