DEV Community

Cătălin Grigoriev
Cătălin Grigoriev

Posted on

Antivirus in C++

Hi,

I'm working on an antivirus project in C++. You can find my progress so far on GitHub:
https://github.com/catalingrigoriev285/nodedefence

I've created a class to retrieve signatures from files.

char* FileSignature::getFileSignature(const char* filePath) {
    std::ifstream file(filePath, std::ios::binary);

    if (!file) {
        //std::cerr << "Error: Unable to open file " << filePath << std::endl;
        throw Exception("FileSignature", "Unable to open file", "FileError");
        return nullptr;
    }

    std::vector<unsigned char> signature(SIGNATURE_MAX_SIZE);
    file.read(reinterpret_cast<char*>(signature.data()), signature.size());

    if (file) {     
        char* result = new char[SIGNATURE_MAX_SIZE * 3];
        result[SIGNATURE_MAX_SIZE * 3 - 1] = '\0';

        for (int i = 0; i < SIGNATURE_MAX_SIZE; i++) {
            sprintf(result + i * 3, "%02X ", signature[i]);
        }

        file.close();
        return result;
    }
    else {
        throw Exception("FileSignature", "Unable to read file", "FileError");
        return nullptr;
    }
}
Enter fullscreen mode Exit fullscreen mode

Next, I'm planning to:

Create a database class to store all signatures.
Develop a core antivirus class with methods to search and analyze files.

I would appreciate any suggestions on how to proceed, as well as recommendations on resources for developing an antivirus.

Top comments (0)