<commit_before>#include "sht_entry_container.hpp"
#include "util/util.hpp"

using namespace elf;

ShtEntryContainer::ShtEntryContainer(ELFFile *file, const std::pair<int, int> &interval, unsigned int index) :
    Container(file, true, interval), index(index)
{
    ELFIO::elfio *elfData = file->getELFIO();
    ELFIO::section *entry = elfData->sections[index];

    if (entry)
    {
        setName(entry->get_name() + " header");
    }
}

std::vector<Container *> &ShtEntryContainer::getInnerContainers()
{
    if (innerContainers.empty())
    {
        Container *container;
        ELFFile *efile = dynamic_cast<ELFFile *>(getFile());
        ELFIO::elfio *elfData = efile->getELFIO();
        ELFIO::section *entry = elfData->sections[index];

        int offset = elfData->get_sections_offset() + index * elfData->get_section_entry_size();

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_name: " + std::to_string(entry->get_name_string_offset()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        int sh_type = entry->get_type();
        std::string sh_type_string = "";

        switch(sh_type)
        {
            case SHT_NULL:
                sh_type_string = "SHT_NULL";
                break;
            case SHT_PROGBITS:
                sh_type_string = "SHT_PROGBITS";
                break;
            case SHT_SYMTAB :
                sh_type_string = "SHT_SYMTAB";
                break;
            case SHT_STRTAB:
                sh_type_string = "SHT_STRTAB";
                break;
            case SHT_RELA:
                sh_type_string = "SHT_RELA";
                break;
            case SHT_NOTE :
                sh_type_string = "SHT_NOTE";
                break;
            case SHT_REL:
                sh_type_string = "SHT_REL";
                break;
            case SHT_SHLIB:
                sh_type_string = "SHT_SHLIB";
                break;
            case SHT_DYNSYM:
                sh_type_string = "SHT_DYNSYM";
                break;
            case SHT_INIT_ARRAY:
                sh_type_string = "SHT_INIT_ARRAY";
                break;
            case SHT_FINI_ARRAY:
                sh_type_string = "SHT_FINI_ARRAY";
                break;
            case SHT_PREINIT_ARRAY:
                sh_type_string = "SHT_PREINIT_ARRAY";
                break;
            case SHT_GROUP:
                sh_type_string = "SHT_GROUP";
                break;
            case SHT_SYMTAB_SHNDX:
                sh_type_string = "SHT_SYMTAB_SHNDX";
                break;
            case SHT_LOOS:
                sh_type_string = "SHT_LOOS";
                break;
            case SHT_HIOS:
                sh_type_string = "SHT_HIOS";
                break;
            case SHT_LOPROC:
                sh_type_string = "SHT_LOPROC";
                break;
            case SHT_HIPROC:
                sh_type_string = "SHT_HIPROC";
                break;
            case SHT_LOUSER:
                sh_type_string = "SHT_LOUSER";
                break;
            case SHT_HIUSER:
                sh_type_string = "SHT_HIUSER";
                break;
            default:
                sh_type_string = std::to_string(sh_type);
                break;
        }

        container->setName("sh_type: " + sh_type_string);
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        std::string sh_flags_string = "";
        ELFIO::Elf_Xword flags = entry->get_flags();

        if (flags & SHF_WRITE)
            sh_flags_string += "SHF_WRITE ";
        if (flags & SHF_ALLOC)
            sh_flags_string += "SHF_ALLOC ";
        if (flags & SHF_EXECINSTR)
            sh_flags_string += "SHF_EXECINSTR ";
        if (flags & SHF_MERGE)
            sh_flags_string += "SHF_MERGE ";
        if (flags & SHF_STRINGS)
            sh_flags_string += "SHF_STRINGS ";
        if (flags & SHF_INFO_LINK)
            sh_flags_string += "SHF_INFO_LINK ";
        if (flags & SHF_LINK_ORDER)
            sh_flags_string += "SHF_LINK_ORDER ";
        if (flags & SHF_OS_NONCONFORMING)
            sh_flags_string += "SHF_OS_NONCONFORMING ";
        if (flags & SHF_GROUP)
            sh_flags_string += "SHF_GROUP ";
        if (flags & SHF_TLS)
            sh_flags_string += "SHF_TLS ";
        if (flags & SHF_GROUP)
            sh_flags_string += "SHF_MASKOS ";
        if (flags & SHF_TLS)
            sh_flags_string += "SHF_MASKPROC ";

        container->setName("sh_flags: " + sh_flags_string);
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Addr)));
        int sh_addr = entry->get_address();
        container->setName("sh_addr: " + printHex(sh_addr));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Addr);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Off)));
        container->setName("sh_offset: " + std::to_string(entry->get_offset()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Off);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_size: " + std::to_string(entry->get_size()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_link: " + std::to_string(entry->get_link()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_info: " + std::to_string(entry->get_info()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_addralign: " + std::to_string(entry->get_addr_align()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_entsize: " + std::to_string(entry->get_entry_size()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);
    }<commit_msg>Use printHex function for SHT entry container<commit_after>#include "sht_entry_container.hpp"
#include "util.hpp"

using namespace elf;

ShtEntryContainer::ShtEntryContainer(ELFFile *file, const std::pair<int, int> &interval, unsigned int index) :
    Container(file, true, interval), index(index)
{
    ELFIO::elfio *elfData = file->getELFIO();
    ELFIO::section *entry = elfData->sections[index];

    if (entry)
    {
        setName(entry->get_name() + " header");
    }
}

std::vector<Container *> &ShtEntryContainer::getInnerContainers()
{
    if (innerContainers.empty())
    {
        Container *container;
        ELFFile *efile = dynamic_cast<ELFFile *>(getFile());
        ELFIO::elfio *elfData = efile->getELFIO();
        ELFIO::section *entry = elfData->sections[index];

        int offset = elfData->get_sections_offset() + index * elfData->get_section_entry_size();

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_name: " + std::to_string(entry->get_name_string_offset()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        int sh_type = entry->get_type();
        std::string sh_type_string = "";

        switch(sh_type)
        {
            case SHT_NULL:
                sh_type_string = "SHT_NULL";
                break;
            case SHT_PROGBITS:
                sh_type_string = "SHT_PROGBITS";
                break;
            case SHT_SYMTAB :
                sh_type_string = "SHT_SYMTAB";
                break;
            case SHT_STRTAB:
                sh_type_string = "SHT_STRTAB";
                break;
            case SHT_RELA:
                sh_type_string = "SHT_RELA";
                break;
            case SHT_NOTE :
                sh_type_string = "SHT_NOTE";
                break;
            case SHT_REL:
                sh_type_string = "SHT_REL";
                break;
            case SHT_SHLIB:
                sh_type_string = "SHT_SHLIB";
                break;
            case SHT_DYNSYM:
                sh_type_string = "SHT_DYNSYM";
                break;
            case SHT_INIT_ARRAY:
                sh_type_string = "SHT_INIT_ARRAY";
                break;
            case SHT_FINI_ARRAY:
                sh_type_string = "SHT_FINI_ARRAY";
                break;
            case SHT_PREINIT_ARRAY:
                sh_type_string = "SHT_PREINIT_ARRAY";
                break;
            case SHT_GROUP:
                sh_type_string = "SHT_GROUP";
                break;
            case SHT_SYMTAB_SHNDX:
                sh_type_string = "SHT_SYMTAB_SHNDX";
                break;
            case SHT_LOOS:
                sh_type_string = "SHT_LOOS";
                break;
            case SHT_HIOS:
                sh_type_string = "SHT_HIOS";
                break;
            case SHT_LOPROC:
                sh_type_string = "SHT_LOPROC";
                break;
            case SHT_HIPROC:
                sh_type_string = "SHT_HIPROC";
                break;
            case SHT_LOUSER:
                sh_type_string = "SHT_LOUSER";
                break;
            case SHT_HIUSER:
                sh_type_string = "SHT_HIUSER";
                break;
            default:
                sh_type_string = std::to_string(sh_type);
                break;
        }

        container->setName("sh_type: " + sh_type_string);
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        std::string sh_flags_string = "";
        ELFIO::Elf_Xword flags = entry->get_flags();

        if (flags & SHF_WRITE)
            sh_flags_string += "SHF_WRITE ";
        if (flags & SHF_ALLOC)
            sh_flags_string += "SHF_ALLOC ";
        if (flags & SHF_EXECINSTR)
            sh_flags_string += "SHF_EXECINSTR ";
        if (flags & SHF_MERGE)
            sh_flags_string += "SHF_MERGE ";
        if (flags & SHF_STRINGS)
            sh_flags_string += "SHF_STRINGS ";
        if (flags & SHF_INFO_LINK)
            sh_flags_string += "SHF_INFO_LINK ";
        if (flags & SHF_LINK_ORDER)
            sh_flags_string += "SHF_LINK_ORDER ";
        if (flags & SHF_OS_NONCONFORMING)
            sh_flags_string += "SHF_OS_NONCONFORMING ";
        if (flags & SHF_GROUP)
            sh_flags_string += "SHF_GROUP ";
        if (flags & SHF_TLS)
            sh_flags_string += "SHF_TLS ";
        if (flags & SHF_GROUP)
            sh_flags_string += "SHF_MASKOS ";
        if (flags & SHF_TLS)
            sh_flags_string += "SHF_MASKPROC ";

        container->setName("sh_flags: " + sh_flags_string);
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Addr)));
        container->setName("sh_addr: " + printHex(entry->get_address()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Addr);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Off)));
        container->setName("sh_offset: " + printHex(entry->get_offset()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Off);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_size: " + std::to_string(entry->get_size()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_link: " + std::to_string(entry->get_link()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_info: " + std::to_string(entry->get_info()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_addralign: " + std::to_string(entry->get_addr_align()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);

        container = new Container(getFile(), false, std::make_pair(offset, offset + sizeof(ELFIO::Elf32_Word)));
        container->setName("sh_entsize: " + std::to_string(entry->get_entry_size()));
        addInnerContainer(container);
        offset += sizeof(ELFIO::Elf32_Word);
    }
{'fraction_non_alphanumeric': 0.11769386574074074, 'fraction_numerical': 0.005787037037037037, 'mean_word_length': 2.194316081330869, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 63, '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': '7191511', 'n_tokens_mistral': 4415, 'n_tokens_neox': 4257, 'n_words': 701}