/* Copyright (c) 2017-2026 hors<horsicq@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#include "peprocessdata.h"

PEProcessData::PEProcessData(qint32 nType, QStandardItemModel **ppModel, XPE *pPE, qint32 nNumber, qint64 nOffset, qint64 nSize, QVariant varInfo) : ProcessData()
{
    this->m_nType = nType;
    this->m_ppModel = ppModel;
    this->m_pPE = pPE;
    this->m_nNumber = nNumber;
    this->m_nOffset = nOffset;
    this->m_nSize = nSize;
    this->m_varInfo = varInfo;
}

void PEProcessData::_process()
{
    bool bIs64 = m_pPE->is64();

    if (m_nType == SPE::TYPE_SECTIONS) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_SECTION_HEADER::records, N_IMAGE_SECTION_HEADER::__data_size));

        XBinary::_MEMORY_MAP memoryMap = m_pPE->getMemoryMap(XBinary::MAPMODE_UNKNOWN, getPdStruct());

        XBinary::OFFSETSIZE osStringTable = m_pPE->getStringTable();

        QList<XPE_DEF::IMAGE_SECTION_HEADER> listSections = m_pPE->getSectionHeaders(getPdStruct());  // TODO pdsStruct

        qint32 nNumberOfRecords = listSections.count();

        *m_ppModel = new QStandardItemModel(nNumberOfRecords, listLabels.count());

        setMaximum(nNumberOfRecords);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfRecords) && (isRun()); i++) {
            QStandardItem *pItemNumber = new QStandardItem;
            pItemNumber->setData(i, Qt::DisplayRole);

            pItemNumber->setData(memoryMap.nModuleAddress + listSections.at(i).VirtualAddress, Qt::UserRole + FW_DEF::SECTION_DATA_ADDRESS);

            if (m_pPE->isImage()) {
                pItemNumber->setData(listSections.at(i).Misc.VirtualSize, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
                pItemNumber->setData(listSections.at(i).VirtualAddress, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
            } else {
                pItemNumber->setData(listSections.at(i).SizeOfRawData, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
                pItemNumber->setData(listSections.at(i).PointerToRawData, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
            }

            (*m_ppModel)->setItem(i, 0, pItemNumber);

            QStandardItem *pItemName = new QStandardItem();
            QString sName = QString((char *)listSections.at(i).Name);
            sName.resize(qMin(sName.length(), XPE_DEF::S_IMAGE_SIZEOF_SHORT_NAME));

            if (m_varInfo.toBool()) {
                sName = m_pPE->convertSectionName(sName, &osStringTable);
            }

            pItemName->setText(sName);

            pItemNumber->setData(QString("%1_%2_%3.bin").arg(tr("Section"), QString::number(i), XBinary::convertFileNameSymbols(sName)),
                                 Qt::UserRole + FW_DEF::SECTION_DATA_NAME);

            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::Name + 1, pItemName);

            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::VirtualSize + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).Misc.VirtualSize)));
            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::VirtualAddress + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).VirtualAddress)));
            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::SizeOfRawData + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).SizeOfRawData)));
            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::PointerToRawData + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).PointerToRawData)));
            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::PointerToRelocations + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).PointerToRelocations)));
            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::PointerToLinenumbers + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).PointerToLinenumbers)));
            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::NumberOfRelocations + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).NumberOfRelocations)));
            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::NumberOfLinenumbers + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).NumberOfLinenumbers)));
            (*m_ppModel)->setItem(i, N_IMAGE_SECTION_HEADER::Characteristics + 1, new QStandardItem(XBinary::valueToHex(listSections.at(i).Characteristics)));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_SECTIONS_INFO) {
        *m_ppModel = new QStandardItemModel;

        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(tr("Name"));
        listLabels.append(tr("Relative address"));
        listLabels.append(tr("Virtual size"));
        listLabels.append(tr("File offset"));
        listLabels.append(tr("Size"));
        listLabels.append(tr("Flags"));
        listLabels.append(tr("Info"));

        setTreeHeader(*m_ppModel, &listLabels);

        QList<XPE_DEF::IMAGE_SECTION_HEADER> listSectionHeaders = m_pPE->getSectionHeaders(getPdStruct());
        QList<XPE::SECTION_RECORD> listSectionRecords = m_pPE->getSectionRecords(&listSectionHeaders, getPdStruct());
        XBinary::_MEMORY_MAP memoryMap = m_pPE->getMemoryMap(XBinary::MAPMODE_UNKNOWN, getPdStruct());

        QList<QString> listStrDb = XInfoDB::loadStrDB(getOptions()->getInfoPath(), XInfoDB::STRDB_PESECTIONS);

        qint32 nNumberOfSections = listSectionRecords.count();

        setMaximum(nNumberOfSections + 2);

        QStandardItem *pItemNumberHeader = nullptr;
        QStandardItem *pItemOverlay = nullptr;

        QList<QStandardItem *> listItemNameSections;

        {
            pItemNumberHeader = new QStandardItem("");

            QList<QStandardItem *> listItems;

            listItems.append(pItemNumberHeader);
            listItems.append(new QStandardItem(""));
            listItems.append(new QStandardItem(XBinary::valueToHex((quint32)0)));
            listItems.append(new QStandardItem(XBinary::valueToHex(S_ALIGN_UP32(m_pPE->getOptionalHeader_SizeOfHeaders(), m_pPE->getOptionalHeader_SectionAlignment()))));
            listItems.append(new QStandardItem(XBinary::valueToHex((quint32)0)));
            listItems.append(new QStandardItem(XBinary::valueToHex(m_pPE->getOptionalHeader_SizeOfHeaders())));
            listItems.append(new QStandardItem(""));
            listItems.append(new QStandardItem(tr("Header")));  // Info

            (*m_ppModel)->appendRow(listItems);

            incValue();
        }

        for (qint32 i = 0; i < nNumberOfSections; i++) {
            XInfoDB::STRRECORD strRecord = XInfoDB::handleStringDB(&listStrDb, XInfoDB::STRDB_PESECTIONS, listSectionRecords.at(i).sName, true);
            XOptions::COLOR_RECORD globalColorRecord = XScanEngine::typeToColorRecord(strRecord.sType, nullptr);

            QColor colText;

            if (globalColorRecord.sColorMain == "") {
                colText = QApplication::palette().text().color();
            } else {
                colText = QColor(globalColorRecord.sColorMain);
            }

            QColor colBackground;

            if (globalColorRecord.sColorBackground == "") {
                colBackground = QApplication::palette().window().color();
            } else {
                colBackground = QColor(globalColorRecord.sColorBackground);
            }

            strRecord.sType = XScanEngine::translateType(strRecord.sType);

            QStandardItem *pItemNumber = new QStandardItem(QString::number(i));

            QStandardItem *pItemName = new QStandardItem(listSectionRecords.at(i).sName);
            pItemName->setData(colText, Qt::ForegroundRole);
            pItemName->setData(colBackground, Qt::BackgroundRole);

            QList<QStandardItem *> listItems;
            listItems.append(pItemNumber);
            listItems.append(pItemName);
            listItems.append(new QStandardItem(XBinary::valueToHex(listSectionHeaders.at(i).VirtualAddress)));
            listItems.append(new QStandardItem(XBinary::valueToHex(listSectionHeaders.at(i).Misc.VirtualSize)));
            listItems.append(new QStandardItem(XBinary::valueToHex(listSectionHeaders.at(i).PointerToRawData)));
            listItems.append(new QStandardItem(XBinary::valueToHex(listSectionHeaders.at(i).SizeOfRawData)));
            listItems.append(new QStandardItem(XPE::sectionCharacteristicToString(listSectionHeaders.at(i).Characteristics)));
            listItems.append(new QStandardItem(strRecord.sDescription));  // Info

            (*m_ppModel)->appendRow(listItems);

            listItemNameSections.append(pItemNumber);

            incValue();
        }

        if (m_pPE->isOverlayPresent(&memoryMap, getPdStruct())) {
            pItemOverlay = new QStandardItem("");

            QList<QStandardItem *> listItems;
            listItems.append(pItemOverlay);
            listItems.append(new QStandardItem(""));
            listItems.append(new QStandardItem(""));
            listItems.append(new QStandardItem(""));
            listItems.append(new QStandardItem(XBinary::valueToHex((quint32)(m_pPE->getOverlayOffset(&memoryMap, getPdStruct())))));
            listItems.append(new QStandardItem(XBinary::valueToHex((quint32)(m_pPE->getOverlaySize(&memoryMap, getPdStruct())))));
            listItems.append(new QStandardItem(""));
            listItems.append(new QStandardItem(tr("Overlay")));  // Info

            (*m_ppModel)->appendRow(listItems);

            incValue();
        }

        QMap<qint64, QString> mapRegionAddresses;
        QMap<qint64, QString> mapRegionSizes;

        {
            QString sRecord = tr("Entry point");

            mapRegionAddresses.insert(m_pPE->getOptionalHeader_AddressOfEntryPoint(), sRecord);
            mapRegionSizes.insert(0, sRecord);
        }

        if (m_pPE->isExportPresent()) {
            QString sRecord = tr("Export");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_EXPORT);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isImportPresent()) {
            QString sRecord = tr("Import");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_IMPORT);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isResourcesPresent()) {
            QString sRecord = tr("Resources");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_RESOURCE);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isExceptionPresent()) {
            QString sRecord = tr("Exceptions");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_EXCEPTION);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isRelocsPresent()) {
            QString sRecord = tr("Relocs");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_BASERELOC);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isDebugPresent()) {
            QString sRecord = tr("Debug");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_DEBUG);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isTLSPresent()) {
            QString sRecord = QString("TLS");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_TLS);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isLoadConfigPresent()) {
            QString sRecord = tr("Load config");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isBoundImportPresent()) {
            QString sRecord = tr("Bound import");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isIATPresent()) {
            QString sRecord = QString("IAT");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_IAT);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isDelayImportPresent()) {
            QString sRecord = tr("Delay import");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        if (m_pPE->isNETPresent()) {
            QString sRecord = QString(".NET");

            XPE_DEF::IMAGE_DATA_DIRECTORY dd = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR);

            mapRegionAddresses.insert(dd.VirtualAddress, sRecord);
            mapRegionSizes.insert(dd.Size, sRecord);
        }

        QMapIterator<qint64, QString> iter(mapRegionAddresses);

        while (iter.hasNext()) {
            iter.next();

            qint64 nRelAddress = iter.key();
            qint64 nOffset = m_pPE->relAddressToOffset(&memoryMap, nRelAddress);
            QString sOffset;

            if (nOffset != -1) {
                sOffset = XBinary::valueToHex((quint32)(nOffset));
            }

            QString sName = iter.value();

            qint32 nSection = XBinary::relAddressToFileTypeNumber(&memoryMap, nRelAddress);
            bool bIsHeader = false;
            nSection--;

            if (nSection == -1) {
                bIsHeader = XBinary::isRelAddressInHeader(&memoryMap, nRelAddress);
            }

            if ((nSection != -1) || (bIsHeader)) {
                QList<QStandardItem *> listItems;
                listItems.append(new QStandardItem(""));
                listItems.append(new QStandardItem(sName));
                listItems.append(new QStandardItem(XBinary::valueToHex((quint32)(nRelAddress))));
                listItems.append(new QStandardItem(XBinary::valueToHex((quint32)(mapRegionSizes.key(sName)))));
                listItems.append(new QStandardItem(sOffset));
                listItems.append(new QStandardItem(XBinary::valueToHex((quint32)(mapRegionSizes.key(sName)))));
                listItems.append(new QStandardItem(""));
                listItems.append(new QStandardItem(""));  // Info

                if (nSection != -1) {
                    if (nSection < nNumberOfSections) {
                        listItemNameSections.at(nSection)->appendRow(listItems);
                    }
                } else if (bIsHeader) {
                    pItemNumberHeader->appendRow(listItems);
                }
            }
        }
    } else if (m_nType == SPE::TYPE_IMPORT_INFO) {
        *m_ppModel = new QStandardItemModel;

        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(tr("Name"));
        listLabels.append(tr("Tags"));
        listLabels.append(tr("Description"));

        setTreeHeader(*m_ppModel, &listLabels);
        XBinary::_MEMORY_MAP memoryMap = m_pPE->getMemoryMap(XBinary::MAPMODE_UNKNOWN, getPdStruct());

        QList<XPE::IMPORT_HEADER> listImports = m_pPE->getImports(&memoryMap, getPdStruct());

        qint32 nNumberOfImports = listImports.count();
        setMaximum(nNumberOfImports);

        for (qint32 i = 0; i < nNumberOfImports; i++) {
            QList<QStandardItem *> listItems;

            XInfoDB::STRRECORD strRecord;

            QStandardItem *pItemNumber = new QStandardItem(QString::number(i));

            listItems.append(pItemNumber);
            listItems.append(new QStandardItem(listImports.at(i).sName));
            listItems.append(new QStandardItem(strRecord.sTags));
            listItems.append(new QStandardItem(strRecord.sDescription));

            (*m_ppModel)->appendRow(listItems);

            incValue();
        }
    } else if (m_nType == SPE::TYPE_RELOCS) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_RELOCS::records, N_IMAGE_RELOCS::__data_size));
        listLabels.append("");
        listLabels.append("");

        QList<XPE::RELOCS_HEADER> listRelocsHeaders = m_pPE->getRelocsHeaders(getPdStruct());

        qint32 nNumberOfRecords = listRelocsHeaders.count();

        *m_ppModel = new QStandardItemModel(nNumberOfRecords, listLabels.count());

        setMaximum(nNumberOfRecords);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfRecords) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);
            pItem->setData(listRelocsHeaders.at(i).nOffset, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
            pItem->setData(listRelocsHeaders.at(i).nOffset, Qt::UserRole + FW_DEF::SECTION_DATA_HEADEROFFSET);
            (*m_ppModel)->setItem(i, 0, pItem);
            (*m_ppModel)->setItem(i, N_IMAGE_RELOCS::VirtualAddress + 1, new QStandardItem(XBinary::valueToHex(listRelocsHeaders.at(i).baseRelocation.VirtualAddress)));
            (*m_ppModel)->setItem(i, N_IMAGE_RELOCS::SizeOfBlock + 1, new QStandardItem(XBinary::valueToHex(listRelocsHeaders.at(i).baseRelocation.SizeOfBlock)));
            (*m_ppModel)->setItem(i, N_IMAGE_RELOCS::SizeOfBlock + 2, new QStandardItem(QString::number(listRelocsHeaders.at(i).nCount)));
            (*m_ppModel)
                ->setItem(i, N_IMAGE_RELOCS::SizeOfBlock + 3,
                          new QStandardItem(m_pPE->getMemoryRecordInfoByRelAddress(listRelocsHeaders.at(i).baseRelocation.VirtualAddress)));  // Comment

            incValue();
        }
    } else if (m_nType == SPE::TYPE_RELOCS_POSITION) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_RELOCS_POSITION::records, N_IMAGE_RELOCS_POSITION::__data_size));
        listLabels.append(tr("Type"));
        listLabels.append(tr("Address"));

        QList<XPE::RELOCS_POSITION> listRelocsPositions = m_pPE->getRelocsPositions(m_nOffset);  // TODO pdsStruct

        qint32 nNumberOfRelocs = listRelocsPositions.count();

        *m_ppModel = new QStandardItemModel(nNumberOfRelocs, listLabels.count());

        setMaximum(nNumberOfRelocs);

        setTableHeader(*m_ppModel, &listLabels);

        QMap<quint64, QString> mapTypes = m_pPE->getImageRelBasedS();

        for (qint32 i = 0; (i < nNumberOfRelocs) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);
            (*m_ppModel)->setItem(i, 0, pItem);
            (*m_ppModel)->setItem(i, N_IMAGE_RELOCS_POSITION::TypeOffset + 1, new QStandardItem(XBinary::valueToHex(listRelocsPositions.at(i).nTypeOffset)));
            (*m_ppModel)->setItem(i, N_IMAGE_RELOCS_POSITION::TypeOffset + 2, new QStandardItem(mapTypes.value(listRelocsPositions.at(i).nType)));
            (*m_ppModel)->setItem(i, N_IMAGE_RELOCS_POSITION::TypeOffset + 3, new QStandardItem(XBinary::valueToHex((quint32)listRelocsPositions.at(i).nAddress)));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_IMPORT) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_IMPORT::records, N_IMAGE_IMPORT::__data_size));
        listLabels.append(tr("Hash"));
        listLabels.append(tr("Name"));

        XBinary::_MEMORY_MAP memoryMap = m_pPE->getMemoryMap(XBinary::MAPMODE_UNKNOWN, getPdStruct());

        QList<XPE::IMPORT_HEADER> listImport = m_pPE->getImports(&memoryMap);  // TODO pdsStruct

        QList<quint32> listImportPositionHashes = m_pPE->getImportPositionHashes(&listImport);  // TODO pdsStruct

        QList<XPE::IMAGE_IMPORT_DESCRIPTOR_EX> listID = m_pPE->getImportDescriptorsEx(&memoryMap);  // TODO pdsStruct

        qint32 nNumberOfIDs = listID.count();

        *m_ppModel = new QStandardItemModel(nNumberOfIDs, listLabels.count());

        setMaximum(nNumberOfIDs);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfIDs) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);
            (*m_ppModel)->setItem(i, 0, pItem);
            (*m_ppModel)->setItem(i, N_IMAGE_IMPORT::OriginalFirstThunk + 1, new QStandardItem(XBinary::valueToHex(listID.at(i).OriginalFirstThunk)));
            (*m_ppModel)->setItem(i, N_IMAGE_IMPORT::TimeDateStamp + 1, new QStandardItem(XBinary::valueToHex(listID.at(i).TimeDateStamp)));
            (*m_ppModel)->setItem(i, N_IMAGE_IMPORT::ForwarderChain + 1, new QStandardItem(XBinary::valueToHex(listID.at(i).ForwarderChain)));
            (*m_ppModel)->setItem(i, N_IMAGE_IMPORT::Name + 1, new QStandardItem(XBinary::valueToHex(listID.at(i).Name)));
            (*m_ppModel)->setItem(i, N_IMAGE_IMPORT::FirstThunk + 1, new QStandardItem(XBinary::valueToHex(listID.at(i).FirstThunk)));
            (*m_ppModel)->setItem(i, N_IMAGE_IMPORT::FirstThunk + 2, new QStandardItem(XBinary::valueToHex(listImportPositionHashes.at(i))));
            (*m_ppModel)->setItem(i, N_IMAGE_IMPORT::FirstThunk + 3, new QStandardItem(listID.at(i).sLibrary));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_IMPORT_FUNCTION) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_IMPORT_FUNCTION::records32, N_IMAGE_IMPORT_FUNCTION::__data_size));
        listLabels.append(tr("Name"));

        QList<XPE::IMPORT_POSITION> listImportPositions = m_pPE->getImportPositions(m_nNumber);  // TODO pdsStruct

        qint32 nNumberOfIPs = listImportPositions.count();

        *m_ppModel = new QStandardItemModel(nNumberOfIPs, listLabels.count());

        setMaximum(nNumberOfIPs);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfIPs) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);

            (*m_ppModel)->setItem(i, 0, pItem);

            if (listImportPositions.at(i).nOrdinal) {
                QString sOrdinal;

                if (bIs64) {
                    sOrdinal = XBinary::valueToHex((quint64)listImportPositions.at(i).nOrdinal);
                } else {
                    sOrdinal = XBinary::valueToHex((quint32)listImportPositions.at(i).nOrdinal);
                }

                (*m_ppModel)->setItem(i, N_IMAGE_IMPORT_FUNCTION::Ordinal + 1, new QStandardItem(sOrdinal));
            } else {
                QString sThunk;

                if (bIs64) {
                    sThunk = XBinary::valueToHex((quint64)listImportPositions.at(i).nThunkValue);
                } else {
                    sThunk = XBinary::valueToHex((quint32)listImportPositions.at(i).nThunkValue);
                }

                (*m_ppModel)->setItem(i, N_IMAGE_IMPORT_FUNCTION::Thunk + 1, new QStandardItem(sThunk));
                (*m_ppModel)->setItem(i, N_IMAGE_IMPORT_FUNCTION::Hint + 1, new QStandardItem(XBinary::valueToHex(listImportPositions.at(i).nHint)));
                (*m_ppModel)->setItem(i, N_IMAGE_IMPORT_FUNCTION::Hint + 2, new QStandardItem(listImportPositions.at(i).sName));
            }

            incValue();
        }
    } else if (m_nType == SPE::TYPE_EXCEPTION) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_EXCEPTIONS::records, N_IMAGE_EXCEPTIONS::__data_size));
        listLabels.append("");

        QList<XPE_DEF::S_IMAGE_RUNTIME_FUNCTION_ENTRY> listRFE = m_pPE->getExceptionsList();  // TODO pdsStruct

        qint32 nNumberOfRFEs = listRFE.count();

        *m_ppModel = new QStandardItemModel(nNumberOfRFEs, listLabels.count());

        setMaximum(nNumberOfRFEs);

        setTableHeader(*m_ppModel, &listLabels);

        XBinary::_MEMORY_MAP memoryMap = m_pPE->getMemoryMap(XBinary::MAPMODE_UNKNOWN, getPdStruct());

        for (qint32 i = 0; (i < nNumberOfRFEs) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);

            pItem->setData(listRFE.at(i).BeginAddress, Qt::UserRole + FW_DEF::SECTION_DATA_ADDRESS);
            pItem->setData(listRFE.at(i).EndAddress - listRFE.at(i).BeginAddress, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
            pItem->setData(m_pPE->addressToOffset(&memoryMap, memoryMap.nModuleAddress + listRFE.at(i).BeginAddress), Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);

            (*m_ppModel)->setItem(i, 0, pItem);
            (*m_ppModel)->setItem(i, N_IMAGE_EXCEPTIONS::BeginAddress + 1, new QStandardItem(XBinary::valueToHex(listRFE.at(i).BeginAddress)));
            (*m_ppModel)->setItem(i, N_IMAGE_EXCEPTIONS::EndAddress + 1, new QStandardItem(XBinary::valueToHex(listRFE.at(i).EndAddress)));
            (*m_ppModel)->setItem(i, N_IMAGE_EXCEPTIONS::UnwindInfoAddress + 1, new QStandardItem(XBinary::valueToHex(listRFE.at(i).UnwindInfoAddress)));
            (*m_ppModel)
                ->setItem(i, N_IMAGE_EXCEPTIONS::UnwindInfoAddress + 2,
                          new QStandardItem(m_pPE->getMemoryRecordInfoByRelAddress(listRFE.at(i).BeginAddress)));  // Comment

            incValue();
        }
    } else if (m_nType == SPE::TYPE_DELAYIMPORT) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_DELAYIMPORT::records, N_IMAGE_DELAYIMPORT::__data_size));
        listLabels.append("");

        QList<XPE_DEF::S_IMAGE_DELAYLOAD_DESCRIPTOR> listDelayImport = m_pPE->getDelayImportsList();  // TODO pdsStruct

        qint32 nNumberOfDelayImports = listDelayImport.count();

        *m_ppModel = new QStandardItemModel(nNumberOfDelayImports, listLabels.count());

        setMaximum(nNumberOfDelayImports);

        setTableHeader(*m_ppModel, &listLabels);

        XBinary::_MEMORY_MAP memoryMap = m_pPE->getMemoryMap(XBinary::MAPMODE_UNKNOWN, getPdStruct());

        for (qint32 i = 0; (i < nNumberOfDelayImports) && (isRun()); i++) {
            QString sLibraryName = m_pPE->read_ansiString(m_pPE->relAddressToOffset(&memoryMap, listDelayImport.at(i).DllNameRVA));

            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);

            (*m_ppModel)->setItem(i, 0, pItem);
            (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT::AllAttributes + 1, new QStandardItem(XBinary::valueToHex(listDelayImport.at(i).AllAttributes)));
            (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT::DllNameRVA + 1, new QStandardItem(XBinary::valueToHex(listDelayImport.at(i).DllNameRVA)));
            (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT::ModuleHandleRVA + 1, new QStandardItem(XBinary::valueToHex(listDelayImport.at(i).ModuleHandleRVA)));
            (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT::ImportAddressTableRVA + 1, new QStandardItem(XBinary::valueToHex(listDelayImport.at(i).ImportAddressTableRVA)));
            (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT::ImportNameTableRVA + 1, new QStandardItem(XBinary::valueToHex(listDelayImport.at(i).ImportNameTableRVA)));
            (*m_ppModel)
                ->setItem(i, N_IMAGE_DELAYIMPORT::BoundImportAddressTableRVA + 1,
                          new QStandardItem(XBinary::valueToHex(listDelayImport.at(i).BoundImportAddressTableRVA)));
            (*m_ppModel)
                ->setItem(i, N_IMAGE_DELAYIMPORT::UnloadInformationTableRVA + 1, new QStandardItem(XBinary::valueToHex(listDelayImport.at(i).UnloadInformationTableRVA)));
            (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT::TimeDateStamp + 1, new QStandardItem(XBinary::valueToHex(listDelayImport.at(i).TimeDateStamp)));
            (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT::TimeDateStamp + 2, new QStandardItem(sLibraryName));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_EXPORT_FUNCTION) {
        QList<QString> listLabels;
        // No need number
        listLabels.append(getStructList(N_IMAGE_EXPORT_FUNCTION::records, N_IMAGE_EXPORT_FUNCTION::__data_size));
        listLabels.append("");

        bool bFilter = m_varInfo.toBool();

        XPE::EXPORT_HEADER eh = m_pPE->getExport(bFilter);  // TODO pdsStruct

        qint32 nNumberOfPositions = eh.listPositions.count();

        *m_ppModel = new QStandardItemModel(nNumberOfPositions, listLabels.count());

        setMaximum(nNumberOfPositions);

        setTableHeader(*m_ppModel, &listLabels);

        XBinary::_MEMORY_MAP memoryMap = m_pPE->getMemoryMap(XBinary::MAPMODE_UNKNOWN, getPdStruct());

        for (qint32 i = 0; (i < nNumberOfPositions) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setText(XBinary::valueToHex(eh.listPositions.at(i).nOrdinal));

            pItem->setData(memoryMap.nModuleAddress + eh.listPositions.at(i).nRVA, Qt::UserRole + FW_DEF::SECTION_DATA_ADDRESS);
            pItem->setData(1, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
            pItem->setData(m_pPE->addressToOffset(&memoryMap, memoryMap.nModuleAddress + eh.listPositions.at(i).nRVA), Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);

            (*m_ppModel)->setItem(i, N_IMAGE_EXPORT_FUNCTION::Ordinal, pItem);
            (*m_ppModel)->setItem(i, N_IMAGE_EXPORT_FUNCTION::RVA, new QStandardItem(XBinary::valueToHex(eh.listPositions.at(i).nRVA)));
            (*m_ppModel)->setItem(i, N_IMAGE_EXPORT_FUNCTION::Name, new QStandardItem(XBinary::valueToHex(eh.listPositions.at(i).nNameRVA)));
            (*m_ppModel)->setItem(i, N_IMAGE_EXPORT_FUNCTION::Name + 1, new QStandardItem(eh.listPositions.at(i).sFunctionName));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_BOUNDIMPORT) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_BOUNDIMPORT::records, N_IMAGE_BOUNDIMPORT::__data_size));
        listLabels.append("");
        listLabels.append("");

        QList<XPE::BOUND_IMPORT_POSITION> listBoundImportPositions = m_pPE->getBoundImportPositions();  // TODO pdsStruct

        qint32 nNumberOfPositions = listBoundImportPositions.count();

        *m_ppModel = new QStandardItemModel(nNumberOfPositions, listLabels.count());

        setMaximum(nNumberOfPositions);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfPositions) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);

            (*m_ppModel)->setItem(i, 0, pItem);
            (*m_ppModel)
                ->setItem(i, N_IMAGE_BOUNDIMPORT::TimeDateStamp + 1, new QStandardItem(XBinary::valueToHex(listBoundImportPositions.at(i).descriptor.TimeDateStamp)));
            (*m_ppModel)
                ->setItem(i, N_IMAGE_BOUNDIMPORT::OffsetModuleName + 1,
                          new QStandardItem(XBinary::valueToHex(listBoundImportPositions.at(i).descriptor.OffsetModuleName)));
            (*m_ppModel)
                ->setItem(i, N_IMAGE_BOUNDIMPORT::NumberOfModuleForwarderRefs + 1,
                          new QStandardItem(XBinary::valueToHex(listBoundImportPositions.at(i).descriptor.NumberOfModuleForwarderRefs)));
            (*m_ppModel)
                ->setItem(i, N_IMAGE_BOUNDIMPORT::NumberOfModuleForwarderRefs + 2,
                          new QStandardItem(XBinary::valueToTimeString(listBoundImportPositions.at(i).descriptor.TimeDateStamp, XBinary::DT_TYPE_POSIX)));
            (*m_ppModel)->setItem(i, N_IMAGE_BOUNDIMPORT::NumberOfModuleForwarderRefs + 3, new QStandardItem(listBoundImportPositions.at(i).sName));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_DEBUG) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_DEBUG::records, N_IMAGE_DEBUG::__data_size));

        QList<XPE_DEF::S_IMAGE_DEBUG_DIRECTORY> listDebug = m_pPE->getDebugList();  // TODO pdsStruct

        qint32 nNumberOfDebugs = listDebug.count();

        *m_ppModel = new QStandardItemModel(nNumberOfDebugs, listLabels.count());

        setMaximum(nNumberOfDebugs);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfDebugs) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);
            pItem->setData(listDebug.at(i).AddressOfRawData, Qt::UserRole + FW_DEF::SECTION_DATA_ADDRESS);
            pItem->setData(listDebug.at(i).SizeOfData, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
            pItem->setData(listDebug.at(i).PointerToRawData, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
            (*m_ppModel)->setItem(i, 0, pItem);
            (*m_ppModel)->setItem(i, N_IMAGE_DEBUG::Characteristics + 1, new QStandardItem(XBinary::valueToHex(listDebug.at(i).Characteristics)));
            (*m_ppModel)->setItem(i, N_IMAGE_DEBUG::TimeDateStamp + 1, new QStandardItem(XBinary::valueToHex(listDebug.at(i).TimeDateStamp)));
            (*m_ppModel)->setItem(i, N_IMAGE_DEBUG::MajorVersion + 1, new QStandardItem(XBinary::valueToHex(listDebug.at(i).MajorVersion)));
            (*m_ppModel)->setItem(i, N_IMAGE_DEBUG::MinorVersion + 1, new QStandardItem(XBinary::valueToHex(listDebug.at(i).MinorVersion)));
            (*m_ppModel)->setItem(i, N_IMAGE_DEBUG::Type + 1, new QStandardItem(XBinary::valueToHex(listDebug.at(i).Type)));
            (*m_ppModel)->setItem(i, N_IMAGE_DEBUG::SizeOfData + 1, new QStandardItem(XBinary::valueToHex(listDebug.at(i).SizeOfData)));
            (*m_ppModel)->setItem(i, N_IMAGE_DEBUG::AddressOfRawData + 1, new QStandardItem(XBinary::valueToHex(listDebug.at(i).AddressOfRawData)));
            (*m_ppModel)->setItem(i, N_IMAGE_DEBUG::PointerToRawData + 1, new QStandardItem(XBinary::valueToHex(listDebug.at(i).PointerToRawData)));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_TLSCALLBACKS) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(tr("Address"));
        listLabels.append("");

        QList<XADDR> listCallbacks = m_pPE->getTLS_CallbacksList();  // TODO pdsStruct

        qint32 nNumberOfRecords = listCallbacks.count();

        *m_ppModel = new QStandardItemModel(nNumberOfRecords, listLabels.count());

        setMaximum(nNumberOfRecords);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfRecords) && (isRun()); i++) {
            XADDR nAddress = listCallbacks.at(i);

            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);
            pItem->setData(nAddress, Qt::UserRole + FW_DEF::SECTION_DATA_ADDRESS);
            //                        pItem->setData(listCallbacks.at(i).SizeOfData,Qt::UserRole+FW_DEF::SECTION_DATA_SIZE);
            //                        pItem->setData(listCallbacks.at(i).PointerToRawData,Qt::UserRole+FW_DEF::SECTION_DATA_OFFSET);
            (*m_ppModel)->setItem(i, 0, pItem);
            if (bIs64) {
                (*m_ppModel)->setItem(i, 1, new QStandardItem(XBinary::valueToHex((quint64)nAddress)));
            } else {
                (*m_ppModel)->setItem(i, 1, new QStandardItem(XBinary::valueToHex((quint32)nAddress)));
            }

            (*m_ppModel)->setItem(i, 2, new QStandardItem(m_pPE->getMemoryRecordInfoByAddress(nAddress)));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_DELAYIMPORT_FUNCTION) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(getStructList(N_IMAGE_DELAYIMPORT_FUNCTION::records32, N_IMAGE_DELAYIMPORT_FUNCTION::__data_size));
        listLabels.append(tr("Name"));

        QList<XPE::DELAYIMPORT_POSITION> listDIP = m_pPE->getDelayImportPositions(m_nNumber);  // TODO pdsStruct

        qint32 nNumberOfDIPs = listDIP.count();

        *m_ppModel = new QStandardItemModel(nNumberOfDIPs, listLabels.count());

        setMaximum(nNumberOfDIPs);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfDIPs) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);

            (*m_ppModel)->setItem(i, 0, pItem);

            if (bIs64) {
                (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT_FUNCTION::AddressThunk + 1, new QStandardItem(XBinary::valueToHex((quint64)listDIP.at(i).nAddressThunkRVA)));
                (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT_FUNCTION::BoundThunk + 1, new QStandardItem(XBinary::valueToHex((quint64)listDIP.at(i).nBoundThunkRVA)));
            } else {
                (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT_FUNCTION::AddressThunk + 1, new QStandardItem(XBinary::valueToHex((quint32)listDIP.at(i).nAddressThunkRVA)));
                (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT_FUNCTION::BoundThunk + 1, new QStandardItem(XBinary::valueToHex((quint32)listDIP.at(i).nBoundThunkRVA)));
            }

            if (listDIP.at(i).nOrdinal) {
                QString sOrdinal;

                if (bIs64) {
                    sOrdinal = XBinary::valueToHex((quint64)listDIP.at(i).nOrdinal);
                } else {
                    sOrdinal = XBinary::valueToHex((quint32)listDIP.at(i).nOrdinal);
                }

                (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT_FUNCTION::Ordinal + 1, new QStandardItem(sOrdinal));
            } else {
                QString sThunk;

                if (bIs64) {
                    sThunk = XBinary::valueToHex((quint64)listDIP.at(i).nNameThunkValue);
                } else {
                    sThunk = XBinary::valueToHex((quint32)listDIP.at(i).nNameThunkValue);
                }

                (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT_FUNCTION::NameThunk + 1, new QStandardItem(sThunk));
                (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT_FUNCTION::Hint + 1, new QStandardItem(XBinary::valueToHex(listDIP.at(i).nHint)));
                (*m_ppModel)->setItem(i, N_IMAGE_DELAYIMPORT_FUNCTION::Hint + 2, new QStandardItem(listDIP.at(i).sName));
            }

            incValue();
        }
    } else if (m_nType == SPE::TYPE_RESOURCES) {
        if (m_varInfo.toBool()) {
            XPE::RESOURCE_HEADER rh = m_pPE->getResourceHeader();  // TODO pdsStruct

            *m_ppModel = new QStandardItemModel;

            qint32 nNumberOfPositions = rh.listPositions.count();

            if (nNumberOfPositions) {
                QStandardItem *pRoot = new QStandardItem();
                pRoot->setText(tr("Resources"));

                (*m_ppModel)->appendRow(pRoot);

                for (qint32 i = 0; i < nNumberOfPositions; i++) {
                    XPE::RESOURCE_POSITION pos = rh.listPositions.at(i);
                    QStandardItem *pPos = new QStandardItem;
                    QString sPosText = XPE::resourceIdNameToString(pos.rin, 0);

                    pPos->setText(sPosText);

                    pRoot->appendRow(pPos);

                    qint32 nNumberOfPositions = pos.listPositions.count();

                    for (qint32 j = 0; (j < nNumberOfPositions) && (isRun()); j++) {
                        XPE::RESOURCE_POSITION subpos = rh.listPositions.at(i).listPositions.at(j);
                        QStandardItem *pSubPos = new QStandardItem;
                        QString sSubPosText = XPE::resourceIdNameToString(pos.rin, 1);

                        pSubPos->setText(sSubPosText);

                        pPos->appendRow(pSubPos);

                        qint32 nNumberOfSubPositions = subpos.listPositions.count();

                        for (qint32 k = 0; (k < nNumberOfSubPositions) && (isRun()); k++) {
                            XPE::RESOURCE_POSITION record1 = rh.listPositions.at(i);
                            XPE::RESOURCE_POSITION record2 = rh.listPositions.at(i).listPositions.at(j);
                            XPE::RESOURCE_POSITION record3 = rh.listPositions.at(i).listPositions.at(j).listPositions.at(k);
                            QStandardItem *pRecord = new QStandardItem;

                            QString sRecordText1 = XPE::resourceIdNameToString(record1.rin, -1);
                            QString sRecordText2 = XPE::resourceIdNameToString(record2.rin, -1);
                            QString sRecordText3 = XPE::resourceIdNameToString(record3.rin, -1);

                            pRecord->setText(sRecordText3);

                            pRecord->setData(sRecordText1, Qt::UserRole + FW_DEF::SECTION_DATA_VALUE1);
                            pRecord->setData(sRecordText2, Qt::UserRole + FW_DEF::SECTION_DATA_VALUE2);
                            pRecord->setData(sRecordText3, Qt::UserRole + FW_DEF::SECTION_DATA_VALUE3);
                            pRecord->setData(record3.dataEntry.Size, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
                            pRecord->setData(record3.dataEntry.OffsetToData, Qt::UserRole + FW_DEF::SECTION_DATA_ADDRESS);

                            if (m_pPE->isImage()) {
                                pRecord->setData(record3.dataEntry.OffsetToData, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
                            } else {
                                pRecord->setData(record3.nDataOffset, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
                            }

                            pSubPos->appendRow(pRecord);
                        }
                    }

                    incValue();
                }
            }
        } else {
            QList<QString> listLabels;
            listLabels.append("#");
            listLabels.append("");
            listLabels.append("");
            listLabels.append("");
            listLabels.append(tr("Address"));
            listLabels.append(tr("Offset"));
            listLabels.append(tr("Size"));
            listLabels.append("");

            QList<XPE::RESOURCE_RECORD> listResources = m_pPE->getResources(10000, getPdStruct());

            qint32 nNumberOfRecords = listResources.count();

            *m_ppModel = new QStandardItemModel(nNumberOfRecords, listLabels.count());

            setMaximum(nNumberOfRecords);

            setTableHeader(*m_ppModel, &listLabels);

            for (qint32 i = 0; (i < nNumberOfRecords) && (isRun()); i++) {
                QStandardItem *pItemNumber = new QStandardItem;
                pItemNumber->setData(i, Qt::DisplayRole);

                pItemNumber->setData(listResources.at(i).nAddress, Qt::UserRole + FW_DEF::SECTION_DATA_ADDRESS);
                pItemNumber->setData(listResources.at(i).nOffset, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
                pItemNumber->setData(listResources.at(i).nSize, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);

                QString sResID1 = XPE::resourceIdNameToString(listResources.at(i).irin[0], 0);
                QString sResID2 = XPE::resourceIdNameToString(listResources.at(i).irin[1], 1);
                QString sResID3 = XPE::resourceIdNameToString(listResources.at(i).irin[2], 2);

                //                pItemNumber->setData(QString("%1_%2_%3.bin").arg(sResID1, sResID2, sResID3), Qt::UserRole + FW_DEF::SECTION_DATA_NAME);

                QString sResName = XBinary::convertFileNameSymbols(m_pPE->resourceRecordToString(listResources.at(i)));

                pItemNumber->setData(sResName, Qt::UserRole + FW_DEF::SECTION_DATA_NAME);

                (*m_ppModel)->setItem(i, 0, pItemNumber);

                //                (*m_ppModel)->setItem(i,1,pItemName);
                (*m_ppModel)->setItem(i, 1, new QStandardItem(sResID1));
                (*m_ppModel)->setItem(i, 2, new QStandardItem(sResID2));
                (*m_ppModel)->setItem(i, 3, new QStandardItem(sResID3));

                (*m_ppModel)->setItem(i, 4, new QStandardItem(XBinary::valueToHexEx(listResources.at(i).nAddress)));
                (*m_ppModel)->setItem(i, 5, new QStandardItem(XBinary::valueToHexEx(listResources.at(i).nOffset)));
                (*m_ppModel)->setItem(i, 6, new QStandardItem(XBinary::valueToHexEx(listResources.at(i).nSize)));

                XScanEngine::SCAN_OPTIONS scanOptions = {};
                scanOptions.bUseCustomDatabase = true;
                scanOptions.bUseExtraDatabase = true;
                scanOptions.bShowType = true;
                scanOptions.bShowVersion = true;
                scanOptions.bShowInfo = true;
                scanOptions.varInfo = listResources.at(i).irin[0].nID;
                scanOptions.initFilePart = XBinary::FILEPART_RESOURCE;

                XScanEngine::SCAN_RESULT scanResult =
                    SpecAbstract().scanSubdevice(m_pPE->getDevice(), listResources.at(i).nOffset, listResources.at(i).nSize, &scanOptions, getPdStruct());

                (*m_ppModel)->setItem(i, 7, new QStandardItem(XScanEngine::createShortResultString(&scanOptions, scanResult)));

                incValue();
            }
        }
    } else if (m_nType == SPE::TYPE_RESOURCES_STRINGTABLE) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(QString("Id"));
        listLabels.append(tr("Language"));
        listLabels.append(tr("String"));

        QList<XPE::RESOURCE_STRINGTABLE_RECORD> listSTR = m_pPE->getResourceStringTableRecords();  // TODO pdsStruct

        qint32 nNumberOfRecords = listSTR.count();

        *m_ppModel = new QStandardItemModel(nNumberOfRecords, listLabels.count());

        setMaximum(nNumberOfRecords);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfRecords) && (isRun()); i++) {
            QStandardItem *pItem = new QStandardItem;
            pItem->setData(i, Qt::DisplayRole);

            pItem->setData(listSTR.at(i).nAddress, Qt::UserRole + FW_DEF::SECTION_DATA_ADDRESS);
            pItem->setData(listSTR.at(i).nOffset, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
            pItem->setData(listSTR.at(i).nSize, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);

            (*m_ppModel)->setItem(i, 0, pItem);
            (*m_ppModel)->setItem(i, 1, new QStandardItem(QString::number(listSTR.at(i).nID)));
            (*m_ppModel)->setItem(i, 2, new QStandardItem(QString::number(listSTR.at(i).nLanguage)));
            (*m_ppModel)->setItem(i, 3, new QStandardItem(listSTR.at(i).sString));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_CERTIFICATE) {
        //        m_pPE->getCertInfo();

        *m_ppModel = new QStandardItemModel;

        XPE_DEF::IMAGE_DATA_DIRECTORY ddSecurity = m_pPE->getOptionalHeader_DataDirectory(XPE_DEF::S_IMAGE_DIRECTORY_ENTRY_SECURITY);

        QList<XPE::CERT> listCert = m_pPE->getCertList(ddSecurity.VirtualAddress, ddSecurity.Size);

        if (listCert.count()) {
            qint32 nNumberOfCerts = listCert.count();

            for (qint32 i = 0; (i < nNumberOfCerts) && (isRun()); i++) {
                QStandardItem *pRoot = new QStandardItem;

                pRoot->setText(tr("Certificate"));

                pRoot->setData(listCert.at(i).record.dwLength, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
                pRoot->setData(listCert.at(i).nOffset, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);

                qint32 nNumberOfRecords = listCert.at(i).certRecord.listRecords.count();

                for (qint32 j = 0; (j < nNumberOfRecords) && (isRun()); j++) {
                    QStandardItem *pRecord = new QStandardItem;

                    handleCertRecord(pRecord, listCert.at(i).certRecord.listRecords.at(j));

                    pRoot->appendRow(pRecord);
                }

                (*m_ppModel)->appendRow(pRoot);
            }
        }
    } else if (m_nType == SPE::TYPE_CERTIFICATE_CHECK) {
        *m_ppModel = new QStandardItemModel;

        QTemporaryDir tempDir;
        if (tempDir.isValid()) {
            QString sFileName = tempDir.path() + QDir::separator() + "CERT.DAT";

            if (m_pPE->dumpToFile(sFileName, (qint64)0, m_pPE->getSize())) {
                XPE::XCERT_INFO xsertInfo = XPE::getCertInfo(sFileName);

                (*m_ppModel)->appendRow(new QStandardItem(QString("%1: %2").arg(tr("Status"), xsertInfo.sStatus)));

                if (xsertInfo.sProgramName != "") (*m_ppModel)->appendRow(new QStandardItem(QString("%1: %2").arg(tr("Program name"), xsertInfo.sProgramName)));
                if (xsertInfo.sPublisher != "") (*m_ppModel)->appendRow(new QStandardItem(QString("%1: %2").arg(tr("Publisher"), xsertInfo.sPublisher)));
                if (xsertInfo.sMoreInfo != "") (*m_ppModel)->appendRow(new QStandardItem(QString("%1: %2").arg(tr("More info"), xsertInfo.sMoreInfo)));
                if (xsertInfo.sSerialNumber != "") (*m_ppModel)->appendRow(new QStandardItem(QString("%1: %2").arg(tr("Serial number"), xsertInfo.sSerialNumber)));
                if (xsertInfo.sIssuer != "") (*m_ppModel)->appendRow(new QStandardItem(QString("%1: %2").arg(tr("Issuer"), xsertInfo.sIssuer)));
                if (xsertInfo.sSubject != "") (*m_ppModel)->appendRow(new QStandardItem(QString("%1: %2").arg(tr("Subject"), xsertInfo.sSubject)));
                if (xsertInfo.sAlgorithm != "") (*m_ppModel)->appendRow(new QStandardItem(QString("%1: %2").arg(tr("Algorithm"), xsertInfo.sAlgorithm)));
                if (xsertInfo.sTSSerialNumber != "") (*m_ppModel)->appendRow(new QStandardItem(QString("TS %1: %2").arg(tr("Serial number"), xsertInfo.sTSSerialNumber)));
                if (xsertInfo.sTSIssuer != "") (*m_ppModel)->appendRow(new QStandardItem(QString("TS %1: %2").arg(tr("Issuer"), xsertInfo.sTSIssuer)));
                if (xsertInfo.sTSSubject != "") (*m_ppModel)->appendRow(new QStandardItem(QString("TS %1: %2").arg(tr("Subject"), xsertInfo.sTSSubject)));
            }
        }
    } else if (m_nType == SPE::TYPE_RICH) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(QString("Id"));
        listLabels.append(tr("Version"));
        listLabels.append(tr("Count"));
        listLabels.append("");

        QList<XMSDOS::MS_RICH_RECORD> listRichSignatures = m_pPE->getRichSignatureRecords(getPdStruct());

        qint32 nNumberOfRecords = listRichSignatures.count();

        *m_ppModel = new QStandardItemModel(nNumberOfRecords, listLabels.count());

        setMaximum(nNumberOfRecords);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfRecords) && (isRun()); i++) {
            QStandardItem *pItemNumber = new QStandardItem;
            pItemNumber->setData(i, Qt::DisplayRole);

            (*m_ppModel)->setItem(i, 0, pItemNumber);

            //                (*m_ppModel)->setItem(i,1,pItemName);
            (*m_ppModel)->setItem(i, 1, new QStandardItem(XBinary::valueToHex(listRichSignatures.at(i).nId)));
            (*m_ppModel)->setItem(i, 2, new QStandardItem(QString::number(listRichSignatures.at(i).nVersion)));
            (*m_ppModel)->setItem(i, 3, new QStandardItem(QString::number(listRichSignatures.at(i).nCount)));
            (*m_ppModel)
                ->setItem(i, 4,
                          new QStandardItem(NFD_MSDOS::getMsRichString(listRichSignatures.at(i).nId, listRichSignatures.at(i).nVersion, listRichSignatures.at(i).nCount,
                                                                       getPdStruct())));

            incValue();
        }
    } else if (m_nType == SPE::TYPE_NET_METADATA_TABLE) {
        QList<QString> listLabels;
        listLabels.append("#");
        listLabels.append(QString("Id"));
        listLabels.append(tr("Count"));
        listLabels.append(tr("Sorted"));

        XPE::CLI_INFO cliInfo = m_pPE->getCliInfo(true);  // TODO pdStruct
        QList<XPE::CLI_METADATA_RECORD> listMetaDataTables = m_pPE->getCliMetadataRecords(&cliInfo, getPdStruct());

        qint32 nNumberOfRecords = listMetaDataTables.count();

        *m_ppModel = new QStandardItemModel(nNumberOfRecords, listLabels.count());

        setMaximum(nNumberOfRecords);

        setTableHeader(*m_ppModel, &listLabels);

        for (qint32 i = 0; (i < nNumberOfRecords) && (isRun()); i++) {
            QStandardItem *pItemNumber = new QStandardItem;
            pItemNumber->setData(listMetaDataTables.at(i).nNumber, Qt::DisplayRole);

            pItemNumber->setData(listMetaDataTables.at(i).nTableSize, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
            // pItemNumber->setData(listMetaDataTables.at(i).nTableOffset - cliInfo.metaData.osMetadata.nOffset, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);
            pItemNumber->setData(listMetaDataTables.at(i).nTableOffset, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);

            (*m_ppModel)->setItem(i, 0, pItemNumber);
            (*m_ppModel)->setItem(i, 1, new QStandardItem(listMetaDataTables.at(i).sId));
            (*m_ppModel)->setItem(i, 2, new QStandardItem(QString::number(listMetaDataTables.at(i).nCount)));
            (*m_ppModel)->setItem(i, 3, new QStandardItem(XBinary::boolToString(listMetaDataTables.at(i).bIsSorted)));

            incValue();
        }
    }

    adjustModel(*m_ppModel);
}

void PEProcessData::ajustTableView(qint32 nType, QTableView *pTableView)
{
    XBinary::MODE mode = m_pPE->getMode();

    if (nType == SPE::TYPE_SECTIONS) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGSHORT2, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 5, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 6, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 7, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 8, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 9, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 10, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
    } else if (nType == SPE::TYPE_RELOCS) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGMID, mode));
    } else if (nType == SPE::TYPE_RELOCS_POSITION) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
    } else if (nType == SPE::TYPE_IMPORT) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 5, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 6, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 7, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGMID, mode));
    } else if (nType == SPE::TYPE_IMPORT_FUNCTION) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGLONG, mode));
    } else if (nType == SPE::TYPE_EXCEPTION) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGMID, mode));
    } else if (nType == SPE::TYPE_DELAYIMPORT) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 5, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 6, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 7, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 8, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 9, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGMID, mode));
    } else if (nType == SPE::TYPE_EXPORT_FUNCTION) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGLONG, mode));
    } else if (nType == SPE::TYPE_BOUNDIMPORT) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 5, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGLONG, mode));
    } else if (nType == SPE::TYPE_DEBUG) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 5, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 6, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 7, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 8, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
    } else if (nType == SPE::TYPE_DELAYIMPORT_FUNCTION) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 5, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 6, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGMID, mode));
    } else if (nType == SPE::TYPE_TLSCALLBACKS) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
    } else if (nType == SPE::TYPE_RESOURCES) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGSHORT, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGSHORT, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 4, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINTMODE, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 5, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 6, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
    } else if (nType == SPE::TYPE_RICH) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
    } else if (nType == SPE::TYPE_NET_METADATA_TABLE) {
        XOptions::setTableViewHeaderWidth(pTableView, 0, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT16, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 1, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGSHORT2, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 2, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_UINT32, mode));
        XOptions::setTableViewHeaderWidth(pTableView, 3, FormatWidget::getColumnWidth(pTableView, FormatWidget::CW_STRINGSHORT, mode));
    } else {
        ProcessData::adjustTableView(nType, pTableView);
    }
}

void PEProcessData::ajustTreeView(qint32 nType, QTreeView *pTreeView)
{
    XBinary::MODE mode = m_pPE->getMode();

    if (nType == SPE::TYPE_SECTIONS_INFO) {
        XOptions::setTreeViewHeaderWidth(pTreeView, 0, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_UINT16, mode));
        XOptions::setTreeViewHeaderWidth(pTreeView, 1, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_UINT32, mode));
        XOptions::setTreeViewHeaderWidth(pTreeView, 2, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_UINT32, mode));
        XOptions::setTreeViewHeaderWidth(pTreeView, 3, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_UINT32, mode));
        XOptions::setTreeViewHeaderWidth(pTreeView, 4, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_UINT32, mode));
        XOptions::setTreeViewHeaderWidth(pTreeView, 5, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_UINT32, mode));
        XOptions::setTreeViewHeaderWidth(pTreeView, 6, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_UINT32, mode));
    } else if (nType == SPE::TYPE_IMPORT_INFO) {
        XOptions::setTreeViewHeaderWidth(pTreeView, 0, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_UINT16, mode));
        XOptions::setTreeViewHeaderWidth(pTreeView, 1, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_STRINGMID, mode));
        XOptions::setTreeViewHeaderWidth(pTreeView, 2, FormatWidget::getColumnWidth(pTreeView, FormatWidget::CW_STRINGSHORT2, mode));
    }
}

void PEProcessData::handleCertRecord(QStandardItem *pParent, XPE::CERT_RECORD certRecord)
{
    QString sText = QString("%1 (%2)").arg(XBinary::valueToHex(XBinary::MODE_UNKNOWN, certRecord.certTag.nTag), XPE::certTagToString(certRecord.certTag.nTag));

    QString sValue = certRecord.varValue.toString();

    if (sValue.size()) {
        sText += QString(": %1").arg(sValue);

        if (certRecord.certTag.nTag == XPE_DEF::S_ASN1_OBJECT_ID) {
            QString sObject = XPE::objectIdToString(sValue);

            if (sObject != "") {
                sText += QString(": %1").arg(sObject);
            }
        }
    }

    pParent->setText(sText);

    pParent->setData(certRecord.certTag.nHeaderSize + certRecord.certTag.nSize, Qt::UserRole + FW_DEF::SECTION_DATA_SIZE);
    pParent->setData(certRecord.certTag.nOffset, Qt::UserRole + FW_DEF::SECTION_DATA_OFFSET);

    qint32 nNumberOfRecords = certRecord.listRecords.count();

    for (qint32 i = 0; (i < nNumberOfRecords) && (isRun()); i++) {
        QStandardItem *pRecord = new QStandardItem;

        handleCertRecord(pRecord, certRecord.listRecords.at(i));

        pParent->appendRow(pRecord);
    }
}

void PEProcessData::adjustModel(QStandardItemModel *pModel)
{
    if (m_nType == SPE::TYPE_SECTIONS) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 5, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 6, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 7, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 8, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 9, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 10, Qt::AlignRight | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_SECTIONS_INFO) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 5, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 6, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_RELOCS) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_RELOCS_POSITION) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_IMPORT) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 5, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 6, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 7, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_IMPORT_FUNCTION) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_EXCEPTION) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_DELAYIMPORT) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 5, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 6, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 7, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 8, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 9, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_EXPORT_FUNCTION) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_BOUNDIMPORT) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 5, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_DEBUG) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 5, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 6, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 7, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 8, Qt::AlignRight | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_DELAYIMPORT_FUNCTION) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 4, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 5, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 6, Qt::AlignLeft | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_TLSCALLBACKS) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_RESOURCES) {
        if (!m_varInfo.toBool()) {
            XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
            XOptions::setModelTextAlignment(pModel, 1, Qt::AlignLeft | Qt::AlignVCenter);
            XOptions::setModelTextAlignment(pModel, 2, Qt::AlignLeft | Qt::AlignVCenter);
            XOptions::setModelTextAlignment(pModel, 3, Qt::AlignLeft | Qt::AlignVCenter);
            XOptions::setModelTextAlignment(pModel, 4, Qt::AlignRight | Qt::AlignVCenter);
            XOptions::setModelTextAlignment(pModel, 5, Qt::AlignRight | Qt::AlignVCenter);
            XOptions::setModelTextAlignment(pModel, 6, Qt::AlignRight | Qt::AlignVCenter);
        }
    } else if (m_nType == SPE::TYPE_RICH) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignRight | Qt::AlignVCenter);
    } else if (m_nType == SPE::TYPE_NET_METADATA_TABLE) {
        XOptions::setModelTextAlignment(pModel, 0, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 1, Qt::AlignLeft | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter);
        XOptions::setModelTextAlignment(pModel, 3, Qt::AlignLeft | Qt::AlignVCenter);
    }
}
