<commit_before>#include "ExeFactory.h"

#include "pe/DOSExe.h"
#include "pe/PEFile.h"

std::map<ExeFactory::exe_type, ExeBuilder*> ExeFactory::builders;

void ExeFactory::init()
{
    if (builders.size() > 0) {
        return; // already initialized
    }
    builders[MZ] = new DOSExeBuilder();
    builders[PE] = new PEFileBuilder();
}

void ExeFactory::destroy()
{
    std::map<exe_type, ExeBuilder*>::iterator itr;
    for (itr = builders.begin(); itr != builders.end(); itr++) {
        ExeBuilder* builder = itr->second;
        delete builder;
    }
    builders.clear();
}

ExeFactory::exe_type ExeFactory::findMatching(AbstractByteBuffer *buf)
{
    if (!buf) return NONE;

    std::map<exe_type, ExeBuilder*>::iterator itr;
    for (itr = builders.begin(); itr != builders.end(); itr++) {

        ExeBuilder* builder = itr->second;
        if (builder == NULL) continue;

        if (builder->signatureMatches(buf)) {
            return itr->first;
        }
    }
    return NONE;
}

Executable* ExeFactory::build(AbstractByteBuffer *buf, exe_type type)
{
    if (builders.find(type) == builders.end()) return NULL;

    ExeBuilder* builder = builders[type];
    if (builder == NULL) return NULL;

    return builder->build(buf);
}

QString ExeFactory::getTypeName(exe_type type)
{
    if (builders.find(type) == builders.end()) return "Not supported";

    ExeBuilder* builder = builders[type];
    if (builder == NULL) return "Not supported";

    return builder->typeName();
}<commit_msg>[FEATURE] In ExeFactory: autoinit builders<commit_after>#include "ExeFactory.h"

#include "pe/DOSExe.h"
#include "pe/PEFile.h"

std::map<ExeFactory::exe_type, ExeBuilder*> ExeFactory::builders;

void ExeFactory::init()
{
    if (builders.size() > 0) {
        return; // already initialized
    }
    builders[MZ] = new DOSExeBuilder();
    builders[PE] = new PEFileBuilder();
}

void ExeFactory::destroy()
{
    std::map<exe_type, ExeBuilder*>::iterator itr;
    for (itr = builders.begin(); itr != builders.end(); itr++) {
        ExeBuilder* builder = itr->second;
        delete builder;
    }
    builders.clear();
}

ExeFactory::exe_type ExeFactory::findMatching(AbstractByteBuffer *buf)
{
    if (!buf) return NONE;
    
    ExeFactory::init(); //ensue that the builders are initialized

    std::map<exe_type, ExeBuilder*>::iterator itr;
    for (itr = builders.begin(); itr != builders.end(); itr++) {

        ExeBuilder* builder = itr->second;
        if (builder == NULL) continue;

        if (builder->signatureMatches(buf)) {
            return itr->first;
        }
    }
    return NONE;
}

Executable* ExeFactory::build(AbstractByteBuffer *buf, exe_type type)
{
    ExeFactory::init(); //ensue that the builders are initialized

    if (builders.find(type) == builders.end()) {
        return NULL;
    }
    ExeBuilder* builder = builders[type];
    if (!builder) return NULL;

    return builder->build(buf);
}

QString ExeFactory::getTypeName(exe_type type)
{
    ExeFactory::init(); //ensue that the builders are initialized

    if (builders.find(type) == builders.end()) return "Not supported";

    ExeBuilder* builder = builders[type];
    if (builder == NULL) return "Not supported";

    return builder->typeName();
}
{'fraction_non_alphanumeric': 0.1499384236453202, 'fraction_numerical': 0.0006157635467980296, 'mean_word_length': 3.475206611570248, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6848452', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1063, 'n_words': 242}