PDA

View Full Version : Fake virus alert (avast)



Coder5546
23rd November 2014, 13:41
Hi, recently my updater is treated as a virus by some antivirus programs (Avast, avira etc), I don't have any idea how resolve this problem.

My code:



#include <dirent.h>
#ifdef __linux__
#include <sys/stat.h>
#include <sys/wait.h>
#elif __unix__
#include <sys/stat.h>
#include <sys/wait.h>
#else
#include <direct.h>
#endif
#include <iostream>
#include <ctime>
#include <vector>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <unistd.h>
#include <cstdio>
std::vector <std::string> split(std::string string, char delimiter)
{
std::stringstream ss(string);
std::string item;
std::vector<std::string > elems;
while(std::getline(ss,item,delimiter)) {
elems.push_back(item);
}
return elems;
}


void pause(int duration)
{

int temp = time(NULL) + duration;
while(temp > time(NULL)) {

}
}

void createDirectory(std::string directory)
{
#ifdef __linux__
mkdir(directory.c_str(),0777);
#elif __unix__
mkdir(directory.c_str(),0777);
#else
_mkdir(directory.c_str());
#endif
}

std::vector <std::string > readDirectory(std::string directory)
{
std::vector<std::string > files;
DIR *dir;
DIR *subdir;
struct dirent *ent;
if((dir = opendir(directory.c_str())) != NULL) {
while((ent = readdir(dir)) != NULL) {
if(std::string(ent->d_name) == "." || std::string(ent->d_name) == ".." || std::string(ent->d_name) == "Updater.exe" || std::string(ent->d_name) == "Updater") {
continue;
}
#ifdef __linux__
if(ent->d_type == DT_DIR) {
#elif __unix__
if(ent->d_type == DT_DIR) {
#else
std::string dir(directory + "/" + ent->d_name);
if((subdir = opendir(dir.c_str())) != NULL) {
closedir(subdir);
#endif
std::vector<std::string > subdir_files = readDirectory(directory + "/" + ent->d_name);
for(std::string file : subdir_files) {
files.push_back(file);
}
} else {
files.push_back(directory + "/" + ent->d_name);
}
}
}
closedir(dir);
return files;
}

void moveFile(const std::string &from, const std::string &to)
{
/*std::ifstream is(from, std::ios::binary);
std::ofstream os(to, std::ios::binary);

std::copy(std::istream_iterator<char>(is), std::istream_iterator<char>(),
std::ostream_iterator<char>(os));
*/
if(to == "Updater.exe" || to == "Updater") {
return;
}
std::cout << "moving from: " << from << " to: " << to << "\n";
std::remove(to.c_str());

std::rename(from.data(), to.data());

}


int main()
{
pause(2);
std::vector <std::string > files = readDirectory("Updates");
std::cout << "files " << files.size() << "\n";
for(std::string file : files) {
std::cout << file << "\n";
if(file == "Updates/Updater.exe" || file == "Updates") {
continue;
}
std::cout << file << "\n";
std::string name = "";
std::vector<std::string > pieces = split(file, '/');
pieces.erase(pieces.begin(), pieces.begin()+1);
name = pieces.at(pieces.size()-1);
std::string directory = "";
if(pieces.size() > 0) {
pieces.pop_back();
for(std::string value : pieces) {
directory.append(value).append("/");
}
if(directory.length() > 0) {
directory.erase(directory.end()-1);
}
}
std::string filePath = (directory.length() > 0) ? directory + "/" + name : name;
std::cout << directory << "\n";
createDirectory(directory);
moveFile(file, filePath);
}
std::cout << "exec" << "\n";
#ifdef _WIN32
std::system("MyApp.exe update");
pause(2);
// execl("MyApp.exe", "update");
#else
std::system("./MyApp update");
pause(2);
#endif
return 0;
}


Thank You for any answers
Regards

wysota
25th November 2014, 07:51
You might want to contact the authors of anti virus programs and ask them. Apparently the app triggers some signature.

kaufenpreis
15th December 2014, 20:50
Coder5546, did you find line(s) of your code that caused fake virus alert?