├── README.md ├── xhashwidget.cmake ├── xhashwidget.pri ├── LICENSE ├── dialoghash.ui ├── dialoghash.h ├── dialoghash.cpp ├── hashprocess.h ├── xhashwidget.h ├── hashprocess.cpp ├── xhashwidget.ui └── xhashwidget.cpp /README.md: -------------------------------------------------------------------------------- 1 | # XHashWidget 2 | 3 | Widget for Hash calculation 4 | -------------------------------------------------------------------------------- /xhashwidget.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | # TODO Check includes 4 | # xformats 5 | # xlineedithex 6 | 7 | if (NOT DEFINED XDIALOGPROCESS_SOURCES) 8 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatDialogs/xdialogprocess.cmake) 9 | set(XHASHWIDGET_SOURCES ${XHASHWIDGET_SOURCES} ${XDIALOGPROCESS_SOURCES}) 10 | endif() 11 | 12 | set(XHASHWIDGET_SOURCES 13 | ${XHASHWIDGET_SOURCES} 14 | ${CMAKE_CURRENT_LIST_DIR}/dialoghash.cpp 15 | ${CMAKE_CURRENT_LIST_DIR}/dialoghash.h 16 | ${CMAKE_CURRENT_LIST_DIR}/dialoghash.ui 17 | ${CMAKE_CURRENT_LIST_DIR}/hashprocess.cpp 18 | ${CMAKE_CURRENT_LIST_DIR}/hashprocess.h 19 | ${CMAKE_CURRENT_LIST_DIR}/xhashwidget.cpp 20 | ${CMAKE_CURRENT_LIST_DIR}/xhashwidget.h 21 | ${CMAKE_CURRENT_LIST_DIR}/xhashwidget.ui 22 | ) 23 | -------------------------------------------------------------------------------- /xhashwidget.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/hashprocess.h \ 6 | $$PWD/xhashwidget.h \ 7 | $$PWD/dialoghash.h 8 | 9 | SOURCES += \ 10 | $$PWD/hashprocess.cpp \ 11 | $$PWD/xhashwidget.cpp \ 12 | $$PWD/dialoghash.cpp 13 | 14 | FORMS += \ 15 | $$PWD/xhashwidget.ui \ 16 | $$PWD/dialoghash.ui 17 | 18 | !contains(XCONFIG, xformats) { 19 | XCONFIG += xformats 20 | include($$PWD/../Formats/xformats.pri) 21 | } 22 | 23 | !contains(XCONFIG, xlineedithex) { 24 | XCONFIG += xlineedithex 25 | include($$PWD/../Controls/xlineedithex.pri) 26 | } 27 | 28 | !contains(XCONFIG, xtableview) { 29 | XCONFIG += xtableview 30 | include($$PWD/../Controls/xtableview.pri) 31 | } 32 | 33 | !contains(XCONFIG, xdialogprocess) { 34 | XCONFIG += xdialogprocess 35 | include($$PWD/../FormatDialogs/xdialogprocess.pri) 36 | } 37 | 38 | DISTFILES += \ 39 | $$PWD/LICENSE \ 40 | $$PWD/README.md \ 41 | $$PWD/xhashwidget.cmake 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2025 hors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /dialoghash.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | DialogHash 4 | 5 | 6 | Qt::ApplicationModal 7 | 8 | 9 | 10 | 0 11 | 0 12 | 763 13 | 599 14 | 15 | 16 | 17 | Hash 18 | 19 | 20 | true 21 | 22 | 23 | 24 | 25 | 26 | 27 | 0 28 | 0 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Qt::Horizontal 39 | 40 | 41 | 42 | 40 43 | 20 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | Close 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | XHashWidget 62 | QWidget 63 |
xhashwidget.h
64 | 1 65 |
66 |
67 | 68 | 69 |
70 | -------------------------------------------------------------------------------- /dialoghash.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef DIALOGHASH_H 22 | #define DIALOGHASH_H 23 | 24 | #include "xshortcutsdialog.h" 25 | #include "xhashwidget.h" 26 | #include "xshortcuts.h" 27 | 28 | namespace Ui { 29 | class DialogHash; 30 | } 31 | 32 | class DialogHash : public XShortcutsDialog { 33 | Q_OBJECT 34 | 35 | public: 36 | explicit DialogHash(QWidget *pParent); 37 | ~DialogHash(); 38 | 39 | virtual void adjustView(); 40 | 41 | void setData(QIODevice *pDevice, XBinary::FT fileType, qint64 nOffset = 0, qint64 nSize = -1); 42 | void setGlobal(XShortcuts *pShortcuts, XOptions *pXOptions); 43 | 44 | private slots: 45 | void on_pushButtonClose_clicked(); 46 | 47 | protected: 48 | virtual void registerShortcuts(bool bState); 49 | 50 | private: 51 | Ui::DialogHash *ui; 52 | }; 53 | 54 | #endif // DIALOGHASH_H 55 | -------------------------------------------------------------------------------- /dialoghash.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "dialoghash.h" 22 | 23 | #include "ui_dialoghash.h" 24 | 25 | DialogHash::DialogHash(QWidget *pParent) : XShortcutsDialog(pParent, true), ui(new Ui::DialogHash) 26 | { 27 | ui->setupUi(this); 28 | } 29 | 30 | DialogHash::~DialogHash() 31 | { 32 | delete ui; 33 | } 34 | 35 | void DialogHash::adjustView() 36 | { 37 | } 38 | 39 | void DialogHash::setData(QIODevice *pDevice, XBinary::FT fileType, qint64 nOffset, qint64 nSize) 40 | { 41 | ui->widgetHash->setData(pDevice, fileType, nOffset, nSize, true); 42 | } 43 | 44 | void DialogHash::setGlobal(XShortcuts *pShortcuts, XOptions *pXOptions) 45 | { 46 | ui->widgetHash->setGlobal(pShortcuts, pXOptions); 47 | } 48 | 49 | void DialogHash::on_pushButtonClose_clicked() 50 | { 51 | this->close(); 52 | } 53 | 54 | void DialogHash::registerShortcuts(bool bState) 55 | { 56 | Q_UNUSED(bState) 57 | } 58 | -------------------------------------------------------------------------------- /hashprocess.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef HASHPROCESS_H 22 | #define HASHPROCESS_H 23 | 24 | #include "xformats.h" 25 | #include "xlineedithex.h" 26 | #include "xthreadobject.h" 27 | 28 | class HashProcess : public XThreadObject { 29 | Q_OBJECT 30 | 31 | public: 32 | struct MEMORY_RECORD { 33 | QString sName; 34 | qint64 nOffset; 35 | qint64 nSize; 36 | QString sHash; 37 | }; 38 | 39 | struct DATA { 40 | qint64 nOffset; 41 | qint64 nSize; 42 | QString sHash; 43 | XBinary::HASH hash; 44 | XBinary::FT fileType; 45 | XBinary::MAPMODE mapMode; 46 | XLineEditValidator::MODE mode; 47 | QList listMemoryRecords; 48 | }; 49 | 50 | explicit HashProcess(QObject *pParent = nullptr); 51 | 52 | void setData(QIODevice *pDevice, DATA *pData, XBinary::PDSTRUCT *pPdStruct); 53 | void process(); 54 | 55 | private: 56 | QIODevice *m_pDevice; 57 | DATA *m_pData; 58 | XBinary::PDSTRUCT *m_pPdStruct; 59 | }; 60 | 61 | #endif // HASHPROCESS_H 62 | -------------------------------------------------------------------------------- /xhashwidget.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XHASHWIDGET_H 22 | #define XHASHWIDGET_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "hashprocess.h" 30 | #include "xdialogprocess.h" 31 | #include "xformats.h" 32 | #include "xshortcutswidget.h" 33 | 34 | namespace Ui { 35 | class XHashWidget; 36 | } 37 | 38 | class XHashWidget : public XShortcutsWidget { 39 | Q_OBJECT 40 | 41 | public: 42 | explicit XHashWidget(QWidget *pParent = nullptr); 43 | ~XHashWidget(); 44 | 45 | void setData(QIODevice *pDevice, XBinary::FT fileType, qint64 nOffset, qint64 nSize, bool bAuto = false); 46 | void reload(); 47 | virtual void adjustView(); 48 | virtual void reloadData(bool bSaveSelection); 49 | 50 | private slots: 51 | void on_toolButtonReload_clicked(); 52 | void on_comboBoxType_currentIndexChanged(int nIndex); 53 | void on_comboBoxMethod_currentIndexChanged(int nIndex); 54 | void on_toolButtonSave_clicked(); 55 | void on_tableViewRegions_customContextMenuRequested(const QPoint &pos); 56 | void on_comboBoxMapMode_currentIndexChanged(int nIndex); 57 | 58 | protected: 59 | virtual void registerShortcuts(bool bState); 60 | 61 | private: 62 | Ui::XHashWidget *ui; 63 | QIODevice *m_pDevice; 64 | qint64 m_nOffset; 65 | qint64 m_nSize; 66 | HashProcess::DATA m_hashData; 67 | }; 68 | 69 | #endif // XHASHWIDGET_H 70 | -------------------------------------------------------------------------------- /hashprocess.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "hashprocess.h" 22 | 23 | HashProcess::HashProcess(QObject *pParent) : XThreadObject(pParent) 24 | { 25 | m_pDevice = nullptr; 26 | m_pData = nullptr; 27 | m_pPdStruct = nullptr; 28 | } 29 | 30 | void HashProcess::setData(QIODevice *pDevice, DATA *pData, XBinary::PDSTRUCT *pPdStruct) 31 | { 32 | this->m_pDevice = pDevice; 33 | this->m_pData = pData; 34 | this->m_pPdStruct = pPdStruct; 35 | } 36 | 37 | void HashProcess::process() 38 | { 39 | // TODO the second ProgressBar 40 | 41 | qint32 _nFreeIndex = XBinary::getFreeIndex(m_pPdStruct); 42 | XBinary::setPdStructInit(m_pPdStruct, _nFreeIndex, 0); // TODO Total / Check 43 | 44 | XBinary g_binary(this->m_pDevice); 45 | 46 | connect(&g_binary, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString))); 47 | 48 | m_pData->sHash = g_binary.getHash(m_pData->hash, m_pData->nOffset, m_pData->nSize, this->m_pPdStruct); 49 | 50 | m_pData->listMemoryRecords.clear(); 51 | 52 | XBinary::_MEMORY_MAP memoryMap = XFormats::getMemoryMap(m_pData->fileType, m_pData->mapMode, this->m_pDevice); 53 | 54 | m_pData->mode = XLineEditValidator::MODE_HEX_32; 55 | 56 | XBinary::MODE _mode = XBinary::getWidthModeFromMemoryMap(&memoryMap); 57 | 58 | // mb TODO a function !!! TODO move to Widget Check 59 | if (_mode == XBinary::MODE_8) m_pData->mode = XLineEditValidator::MODE_HEX_8; 60 | else if (_mode == XBinary::MODE_16) m_pData->mode = XLineEditValidator::MODE_HEX_16; 61 | else if (_mode == XBinary::MODE_32) m_pData->mode = XLineEditValidator::MODE_HEX_32; 62 | else if (_mode == XBinary::MODE_64) m_pData->mode = XLineEditValidator::MODE_HEX_64; 63 | 64 | qint32 nNumberOfRecords = memoryMap.listRecords.count(); 65 | 66 | for (qint32 i = 0, j = 0; (i < nNumberOfRecords) && XBinary::isPdStructNotCanceled(m_pPdStruct); i++) { 67 | bool bIsVirtual = memoryMap.listRecords.at(i).bIsVirtual; 68 | 69 | if (!bIsVirtual) { 70 | MEMORY_RECORD memoryRecord = {}; 71 | 72 | if ((memoryMap.listRecords.at(i).nOffset == 0) && (memoryMap.listRecords.at(i).nSize == m_pData->nSize)) { 73 | memoryRecord.sHash = m_pData->sHash; 74 | } else { 75 | memoryRecord.sHash = 76 | g_binary.getHash(m_pData->hash, m_pData->nOffset + memoryMap.listRecords.at(i).nOffset, memoryMap.listRecords.at(i).nSize, this->m_pPdStruct); 77 | } 78 | 79 | memoryRecord.sName = memoryMap.listRecords.at(i).sName; 80 | memoryRecord.nOffset = memoryMap.listRecords.at(i).nOffset; 81 | memoryRecord.nSize = memoryMap.listRecords.at(i).nSize; 82 | 83 | m_pData->listMemoryRecords.append(memoryRecord); 84 | 85 | j++; 86 | } 87 | } 88 | 89 | if (XBinary::checkFileType(XBinary::FT_PE, m_pData->fileType)) { 90 | XPE pe(this->m_pDevice); 91 | 92 | if (pe.isValid(m_pPdStruct)) { 93 | QList listImportRecords = pe.getImportRecords(&memoryMap); 94 | 95 | { 96 | MEMORY_RECORD memoryRecord = {}; 97 | 98 | memoryRecord.sName = QString("%1 32(CRC)").arg(tr("Import")); 99 | memoryRecord.nOffset = -1; 100 | memoryRecord.nSize = -1; 101 | memoryRecord.sHash = XBinary::valueToHex(pe.getImportHash32(&listImportRecords, m_pPdStruct)); 102 | 103 | m_pData->listMemoryRecords.append(memoryRecord); 104 | } 105 | 106 | { 107 | MEMORY_RECORD memoryRecord = {}; 108 | 109 | memoryRecord.sName = QString("%1 64(CRC)").arg(tr("Import")); 110 | memoryRecord.nOffset = -1; 111 | memoryRecord.nSize = -1; 112 | memoryRecord.sHash = XBinary::valueToHex(pe.getImportHash64(&listImportRecords, m_pPdStruct)); 113 | 114 | m_pData->listMemoryRecords.append(memoryRecord); 115 | } 116 | 117 | QList listImports = pe.getImports(&memoryMap); 118 | QList listHashes = pe.getImportPositionHashes(&listImports); 119 | 120 | qint32 nNumberOfImports = listImports.count(); 121 | 122 | for (qint32 i = 0; (i < nNumberOfImports) && XBinary::isPdStructNotCanceled(m_pPdStruct); i++) { 123 | MEMORY_RECORD memoryRecord = {}; 124 | 125 | memoryRecord.sName = QString("%1(%2)(CRC)['%3']").arg(tr("Import"), QString::number(i), listImports.at(i).sName); 126 | memoryRecord.nOffset = -1; 127 | memoryRecord.nSize = -1; 128 | memoryRecord.sHash = XBinary::valueToHex(listHashes.at(i)); 129 | 130 | m_pData->listMemoryRecords.append(memoryRecord); 131 | } 132 | } 133 | } 134 | 135 | XBinary::setPdStructFinished(m_pPdStruct, _nFreeIndex); 136 | } 137 | -------------------------------------------------------------------------------- /xhashwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | XHashWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 802 10 | 448 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 120 36 | 0 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 120 46 | 0 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 120 56 | 0 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 150 66 | 16777215 67 | 68 | 69 | 70 | Qt::AlignCenter 71 | 72 | 73 | true 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 120 82 | 0 83 | 84 | 85 | 86 | 87 | 150 88 | 16777215 89 | 90 | 91 | 92 | Qt::AlignCenter 93 | 94 | 95 | true 96 | 97 | 98 | 99 | 100 | 101 | 102 | Qt::Horizontal 103 | 104 | 105 | 106 | 40 107 | 20 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 0 117 | 0 118 | 119 | 120 | 121 | Save 122 | 123 | 124 | Qt::ToolButtonTextBesideIcon 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 0 133 | 0 134 | 135 | 136 | 137 | Reload 138 | 139 | 140 | Qt::ToolButtonTextBesideIcon 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter 150 | 151 | 152 | true 153 | 154 | 155 | 156 | 157 | 158 | 159 | Qt::CustomContextMenu 160 | 161 | 162 | QAbstractItemView::NoEditTriggers 163 | 164 | 165 | QAbstractItemView::SingleSelection 166 | 167 | 168 | QAbstractItemView::SelectRows 169 | 170 | 171 | true 172 | 173 | 174 | false 175 | 176 | 177 | false 178 | 179 | 180 | 20 181 | 182 | 183 | 20 184 | 185 | 186 | false 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | XLineEditHEX 195 | QLineEdit 196 |
xlineedithex.h
197 |
198 | 199 | XTableView 200 | QTableView 201 |
xtableview.h
202 |
203 |
204 | 205 | 206 |
207 | -------------------------------------------------------------------------------- /xhashwidget.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xhashwidget.h" 22 | 23 | #include "ui_xhashwidget.h" 24 | 25 | XHashWidget::XHashWidget(QWidget *pParent) : XShortcutsWidget(pParent), ui(new Ui::XHashWidget) 26 | { 27 | ui->setupUi(this); 28 | 29 | XOptions::adjustToolButton(ui->toolButtonReload, XOptions::ICONTYPE_RELOAD); 30 | XOptions::adjustToolButton(ui->toolButtonSave, XOptions::ICONTYPE_SAVE); 31 | 32 | ui->comboBoxType->setToolTip(tr("Type")); 33 | ui->comboBoxMethod->setToolTip(tr("Method")); 34 | ui->comboBoxMapMode->setToolTip(tr("Mode")); 35 | ui->lineEditOffset->setToolTip(tr("Offset")); 36 | ui->lineEditSize->setToolTip(tr("Size")); 37 | ui->lineEditHash->setToolTip(tr("Hash")); 38 | ui->tableViewRegions->setToolTip(tr("Regions")); 39 | ui->toolButtonReload->setToolTip(tr("Reload")); 40 | ui->toolButtonSave->setToolTip(tr("Save")); 41 | 42 | m_pDevice = nullptr; 43 | m_nOffset = 0; 44 | m_nSize = 0; 45 | m_hashData = {}; 46 | 47 | ui->lineEditHash->setValidatorMode(XLineEditValidator::MODE_TEXT); 48 | 49 | const bool bBlocked1 = ui->comboBoxMethod->blockSignals(true); 50 | 51 | QList listHashMethods = XBinary::getHashMethodsAsList(); 52 | 53 | qint32 nNumberOfMethods = listHashMethods.count(); 54 | 55 | for (qint32 i = 0; i < nNumberOfMethods; i++) { 56 | XBinary::HASH hash = listHashMethods.at(i); 57 | ui->comboBoxMethod->addItem(XBinary::hashIdToString(hash), hash); 58 | } 59 | 60 | if (nNumberOfMethods > 1) // TODO Check 61 | { 62 | ui->comboBoxMethod->setCurrentIndex(1); // MD5 default TODO consts !!! 63 | } 64 | 65 | ui->comboBoxMethod->blockSignals(bBlocked1); 66 | } 67 | 68 | XHashWidget::~XHashWidget() 69 | { 70 | delete ui; 71 | } 72 | 73 | void XHashWidget::setData(QIODevice *pDevice, XBinary::FT fileType, qint64 nOffset, qint64 nSize, bool bAuto) 74 | { 75 | this->m_pDevice = pDevice; 76 | this->m_nOffset = nOffset; 77 | this->m_nSize = nSize; 78 | 79 | if (this->m_nSize == -1) { 80 | this->m_nSize = (pDevice->size()) - (this->m_nOffset); 81 | } 82 | 83 | ui->lineEditOffset->setValue32_64(this->m_nOffset); 84 | ui->lineEditSize->setValue32_64(this->m_nSize); 85 | 86 | SubDevice subDevice(pDevice, this->m_nOffset, this->m_nSize); 87 | 88 | if (subDevice.open(QIODevice::ReadOnly)) { 89 | XFormats::setFileTypeComboBox(fileType, &subDevice, ui->comboBoxType); 90 | XFormats::getMapModesList(fileType, ui->comboBoxMapMode); 91 | 92 | subDevice.close(); 93 | } 94 | 95 | if (bAuto) { 96 | reload(); 97 | } 98 | } 99 | 100 | void XHashWidget::reload() 101 | { 102 | // TODO QTableView 103 | m_hashData.hash = (XBinary::HASH)ui->comboBoxMethod->currentData().toInt(); 104 | m_hashData.fileType = (XBinary::FT)(ui->comboBoxType->currentData().toInt()); 105 | m_hashData.mapMode = (XBinary::MAPMODE)(ui->comboBoxMapMode->currentData().toInt()); 106 | m_hashData.nOffset = m_nOffset; 107 | m_hashData.nSize = m_nSize; 108 | 109 | HashProcess hashProcess; 110 | XDialogProcess dhp(XOptions::getMainWidget(this), &hashProcess); 111 | dhp.setGlobal(getShortcuts(), getGlobalOptions()); 112 | hashProcess.setData(m_pDevice, &m_hashData, dhp.getPdStruct()); 113 | dhp.start(); 114 | dhp.showDialogDelay(); 115 | 116 | if (dhp.isSuccess()) { 117 | ui->lineEditHash->setValue_String(m_hashData.sHash); 118 | 119 | qint32 nNumberOfMemoryRecords = m_hashData.listMemoryRecords.count(); 120 | 121 | QStandardItemModel *pModel = new QStandardItemModel(nNumberOfMemoryRecords, 4); 122 | 123 | pModel->setHeaderData(0, Qt::Horizontal, tr("Name")); 124 | pModel->setHeaderData(1, Qt::Horizontal, tr("Offset")); 125 | pModel->setHeaderData(2, Qt::Horizontal, tr("Size")); 126 | pModel->setHeaderData(3, Qt::Horizontal, tr("Hash")); 127 | 128 | for (qint32 i = 0; i < nNumberOfMemoryRecords; i++) { 129 | QStandardItem *pItemName = new QStandardItem; 130 | 131 | pItemName->setText(m_hashData.listMemoryRecords.at(i).sName); 132 | 133 | pModel->setItem(i, 0, pItemName); 134 | 135 | if (m_hashData.listMemoryRecords.at(i).nOffset != -1) { 136 | QStandardItem *pItemOffset = new QStandardItem; 137 | 138 | pItemOffset->setText(XLineEditHEX::getFormatString(m_hashData.mode, m_hashData.listMemoryRecords.at(i).nOffset)); 139 | // pItemOffset->setData(m_hashData.listMemoryRecords.at(i).nOffset, Qt::DisplayRole); 140 | pModel->setItem(i, 1, pItemOffset); 141 | } 142 | 143 | if (m_hashData.listMemoryRecords.at(i).nSize != -1) { 144 | QStandardItem *pItemSize = new QStandardItem; 145 | 146 | pItemSize->setText(XLineEditHEX::getFormatString(m_hashData.mode, m_hashData.listMemoryRecords.at(i).nSize)); 147 | // pItemSize->setData(m_hashData.listMemoryRecords.at(i).nSize, Qt::DisplayRole); 148 | pModel->setItem(i, 2, pItemSize); 149 | } 150 | 151 | QStandardItem *pItemHash = new QStandardItem; 152 | 153 | QString sHash = m_hashData.listMemoryRecords.at(i).sHash; 154 | 155 | pItemHash->setText(sHash); 156 | pModel->setItem(i, 3, pItemHash); 157 | } 158 | 159 | XOptions::setModelTextAlignment(pModel, 0, Qt::AlignLeft | Qt::AlignVCenter); 160 | XOptions::setModelTextAlignment(pModel, 1, Qt::AlignRight | Qt::AlignVCenter); 161 | XOptions::setModelTextAlignment(pModel, 2, Qt::AlignRight | Qt::AlignVCenter); 162 | XOptions::setModelTextAlignment(pModel, 3, Qt::AlignLeft | Qt::AlignVCenter); 163 | 164 | ui->tableViewRegions->setCustomModel(pModel, true); 165 | 166 | ui->tableViewRegions->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Interactive); 167 | ui->tableViewRegions->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Interactive); 168 | ui->tableViewRegions->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Interactive); 169 | ui->tableViewRegions->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch); 170 | 171 | qint32 nColumnSize = XLineEditHEX::getWidthFromMode(this, m_hashData.mode); 172 | 173 | ui->tableViewRegions->setColumnWidth(0, 150); // TODO consts 174 | ui->tableViewRegions->setColumnWidth(1, nColumnSize); 175 | ui->tableViewRegions->setColumnWidth(2, nColumnSize); 176 | } 177 | } 178 | 179 | void XHashWidget::adjustView() 180 | { 181 | } 182 | 183 | void XHashWidget::reloadData(bool bSaveSelection) 184 | { 185 | Q_UNUSED(bSaveSelection) 186 | reload(); 187 | } 188 | 189 | void XHashWidget::on_toolButtonReload_clicked() 190 | { 191 | reload(); 192 | } 193 | 194 | void XHashWidget::on_comboBoxType_currentIndexChanged(int nIndex) 195 | { 196 | Q_UNUSED(nIndex) 197 | 198 | XBinary::FT fileType = (XBinary::FT)(ui->comboBoxType->currentData().toInt()); 199 | XFormats::getMapModesList(fileType, ui->comboBoxMapMode); 200 | 201 | reload(); 202 | } 203 | 204 | void XHashWidget::on_comboBoxMethod_currentIndexChanged(int nIndex) 205 | { 206 | Q_UNUSED(nIndex) 207 | 208 | reload(); 209 | } 210 | 211 | void XHashWidget::registerShortcuts(bool bState) 212 | { 213 | Q_UNUSED(bState) 214 | // TODO !!! 215 | } 216 | 217 | void XHashWidget::on_toolButtonSave_clicked() 218 | { 219 | XShortcutsWidget::saveTableModel(ui->tableViewRegions->getProxyModel(), XBinary::getResultFileName(m_pDevice, QString("%1.txt").arg(tr("Hash")))); 220 | } 221 | 222 | void XHashWidget::on_tableViewRegions_customContextMenuRequested(const QPoint &pos) 223 | { 224 | qint32 nRow = ui->tableViewRegions->currentIndex().row(); 225 | 226 | if (nRow != -1) { 227 | QMenu contextMenu(this); 228 | 229 | QList listMenuItems; 230 | 231 | getShortcuts()->_addMenuItem_CopyRow(&listMenuItems, ui->tableViewRegions); 232 | 233 | getShortcuts()->adjustContextMenu(&contextMenu, &listMenuItems); 234 | 235 | contextMenu.exec(ui->tableViewRegions->viewport()->mapToGlobal(pos)); 236 | } 237 | } 238 | 239 | void XHashWidget::on_comboBoxMapMode_currentIndexChanged(int nIndex) 240 | { 241 | Q_UNUSED(nIndex) 242 | 243 | reload(); 244 | } 245 | --------------------------------------------------------------------------------