├── README.md ├── LICENSE ├── dialogmultidisasm.ui ├── dialogmultidisasm.h ├── xdisasmview.pri ├── xdisasmviewoptionswidget.h ├── dialogmultidisasm.cpp ├── Widgets ├── dialogmultidisasmsignature.h ├── dialogmultidisasmsignature.ui └── dialogmultidisasmsignature.cpp ├── xdisasmview.cmake ├── xmultidisasmwidget.h ├── xdisasmviewoptionswidget.ui ├── xmultidisasmwidget.ui ├── xdisasmview.h ├── xmultidisasmwidget.cpp ├── xdisasmviewoptionswidget.cpp └── xdisasmview.cpp /README.md: -------------------------------------------------------------------------------- 1 | # XDisasmView 2 | 3 | Disasm widgets 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /dialogmultidisasm.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | DialogMultiDisasm 4 | 5 | 6 | Qt::ApplicationModal 7 | 8 | 9 | 10 | 0 11 | 0 12 | 801 13 | 388 14 | 15 | 16 | 17 | Disasm 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 | XMultiDisasmWidget 62 | QWidget 63 |
xmultidisasmwidget.h
64 | 1 65 |
66 |
67 | 68 | 69 |
70 | -------------------------------------------------------------------------------- /dialogmultidisasm.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 DIALOGMULTIDISASM_H 22 | #define DIALOGMULTIDISASM_H 23 | 24 | #include 25 | 26 | #include "xmultidisasmwidget.h" 27 | 28 | namespace Ui { 29 | class DialogMultiDisasm; 30 | } 31 | 32 | class DialogMultiDisasm : public XShortcutsDialog { 33 | Q_OBJECT 34 | 35 | public: 36 | explicit DialogMultiDisasm(QWidget *pParent = nullptr); 37 | ~DialogMultiDisasm(); 38 | 39 | virtual void adjustView(); 40 | 41 | void setData(QIODevice *pDevice, const XMultiDisasmWidget::OPTIONS &options); 42 | void setGlobal(XShortcuts *pShortcuts, XOptions *pXOptions); 43 | 44 | signals: 45 | void deviceSizeChanged(qint64 nOldSize, qint64 nNewSize); 46 | 47 | private slots: 48 | void on_pushButtonClose_clicked(); 49 | 50 | protected: 51 | virtual void registerShortcuts(bool bState); 52 | 53 | private: 54 | Ui::DialogMultiDisasm *ui; 55 | }; 56 | 57 | #endif // DIALOGMULTIDISASM_H 58 | -------------------------------------------------------------------------------- /xdisasmview.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/dialogmultidisasm.h \ 6 | $$PWD/Widgets/dialogmultidisasmsignature.h \ 7 | $$PWD/xdisasmview.h \ 8 | $$PWD/xdisasmviewoptionswidget.h \ 9 | $$PWD/xmultidisasmwidget.h 10 | 11 | SOURCES += \ 12 | $$PWD/dialogmultidisasm.cpp \ 13 | $$PWD/Widgets/dialogmultidisasmsignature.cpp \ 14 | $$PWD/xdisasmview.cpp \ 15 | $$PWD/xdisasmviewoptionswidget.cpp \ 16 | $$PWD/xmultidisasmwidget.cpp 17 | 18 | FORMS += \ 19 | $$PWD/dialogmultidisasm.ui \ 20 | $$PWD/Widgets/dialogmultidisasmsignature.ui \ 21 | $$PWD/xdisasmviewoptionswidget.ui \ 22 | $$PWD/xmultidisasmwidget.ui 23 | 24 | !contains(XCONFIG, xformats) { 25 | XCONFIG += xformats 26 | include($$PWD/../Formats/xformats.pri) 27 | } 28 | 29 | !contains(XCONFIG, xabstracttableview) { 30 | XCONFIG += xabstracttableview 31 | include($$PWD/../Controls/xabstracttableview.pri) 32 | } 33 | 34 | !contains(XCONFIG, xcapstone) { 35 | XCONFIG += xcapstone 36 | include($$PWD/../XCapstone/xcapstone.pri) 37 | } 38 | 39 | !contains(XCONFIG, dialoggotoaddress) { 40 | XCONFIG += dialoggotoaddress 41 | include($$PWD/../FormatDialogs/dialoggotoaddress.pri) 42 | } 43 | 44 | !contains(XCONFIG, dialogsearch) { 45 | XCONFIG += dialogsearch 46 | include($$PWD/../FormatDialogs/dialogsearch.pri) 47 | } 48 | 49 | !contains(XCONFIG, dialogdump) { 50 | XCONFIG += dialogdump 51 | include($$PWD/../FormatDialogs/dialogdump.pri) 52 | } 53 | 54 | !contains(XCONFIG, searchsignatureswidget) { 55 | XCONFIG += searchsignatureswidget 56 | include($$PWD/../FormatWidgets/SearchSignatures/searchsignatureswidget.pri) 57 | } 58 | 59 | !contains(XCONFIG, dialoghexsignature) { 60 | XCONFIG += dialoghexsignature 61 | include($$PWD/../FormatDialogs/dialoghexsignature.pri) 62 | } 63 | 64 | !contains(XCONFIG, xhexedit) { 65 | XCONFIG += xhexedit 66 | include($$PWD/../XHexEdit/xhexedit.pri) 67 | } 68 | 69 | !contains(XCONFIG, xsymbolswidget) { 70 | XCONFIG += xsymbolswidget 71 | include($$PWD/../XSymbolsWidget/xsymbolswidget.pri) 72 | } 73 | 74 | !contains(XCONFIG, xdecompiler) { 75 | XCONFIG += xdecompiler 76 | include($$PWD/../XDecompiler/xdecompiler.pri) 77 | } 78 | 79 | DISTFILES += \ 80 | $$PWD/LICENSE \ 81 | $$PWD/README.md \ 82 | $$PWD/xdisasmview.cmake 83 | -------------------------------------------------------------------------------- /xdisasmviewoptionswidget.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 XDISASMVIEWOPTIONSWIDGET_H 22 | #define XDISASMVIEWOPTIONSWIDGET_H 23 | 24 | #include "xshortcutswidget.h" 25 | #include "dialogviewcolors.h" 26 | #include "xoptions.h" 27 | 28 | namespace Ui { 29 | class XDisasmViewOptionsWidget; 30 | } 31 | 32 | class XDisasmViewOptionsWidget : public XShortcutsWidget { 33 | Q_OBJECT 34 | 35 | public: 36 | enum MODE { 37 | MODE_ALL = 0, 38 | MODE_X86, 39 | MODE_ARM 40 | }; 41 | 42 | explicit XDisasmViewOptionsWidget(QWidget *pParent = nullptr); 43 | ~XDisasmViewOptionsWidget(); 44 | virtual void adjustView(); 45 | 46 | void setOptions(XOptions *pOptions, MODE mode = MODE_ALL); 47 | 48 | static void setDefaultValues(XOptions *pOptions, MODE mode = MODE_ALL); 49 | static QList getRecords(MODE mode = MODE_ALL); 50 | virtual void reloadData(bool bSaveSelection); 51 | 52 | public slots: 53 | void save(); 54 | void reload(); 55 | 56 | private slots: 57 | void on_pushButtonDisasmColors_clicked(); 58 | 59 | protected: 60 | virtual void registerShortcuts(bool bState); 61 | 62 | private: 63 | Ui::XDisasmViewOptionsWidget *ui; 64 | XOptions *m_pOptions; 65 | MODE m_mode; 66 | }; 67 | 68 | #endif // XDISASMVIEWOPTIONSWIDGET_H 69 | -------------------------------------------------------------------------------- /dialogmultidisasm.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 "dialogmultidisasm.h" 22 | 23 | #include "ui_dialogmultidisasm.h" 24 | 25 | DialogMultiDisasm::DialogMultiDisasm(QWidget *pParent) : XShortcutsDialog(pParent, true), ui(new Ui::DialogMultiDisasm) 26 | { 27 | ui->setupUi(this); 28 | 29 | connect(ui->widgetDisasm, SIGNAL(dataChanged(qint64, qint64)), this, SIGNAL(dataChanged(qint64, qint64))); 30 | connect(ui->widgetDisasm, SIGNAL(deviceSizeChanged(qint64, qint64)), this, SIGNAL(deviceSizeChanged(qint64, qint64))); 31 | 32 | ui->widgetDisasm->setReadonlyVisible(true); 33 | } 34 | 35 | DialogMultiDisasm::~DialogMultiDisasm() 36 | { 37 | delete ui; 38 | } 39 | 40 | void DialogMultiDisasm::adjustView() 41 | { 42 | } 43 | 44 | void DialogMultiDisasm::setData(QIODevice *pDevice, const XMultiDisasmWidget::OPTIONS &options) 45 | { 46 | ui->widgetDisasm->setData(pDevice, options); 47 | 48 | if (options.sTitle != "") { 49 | setWindowTitle(options.sTitle); 50 | } 51 | 52 | if (options.bHideReadOnly) { 53 | ui->widgetDisasm->setReadonlyVisible(false); 54 | } 55 | } 56 | 57 | void DialogMultiDisasm::setGlobal(XShortcuts *pShortcuts, XOptions *pXOptions) 58 | { 59 | ui->widgetDisasm->setGlobal(pShortcuts, pXOptions); 60 | XShortcutsDialog::setGlobal(pShortcuts, pXOptions); 61 | } 62 | 63 | void DialogMultiDisasm::on_pushButtonClose_clicked() 64 | { 65 | this->close(); 66 | } 67 | 68 | void DialogMultiDisasm::registerShortcuts(bool bState) 69 | { 70 | Q_UNUSED(bState) 71 | } 72 | -------------------------------------------------------------------------------- /Widgets/dialogmultidisasmsignature.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 DIALOGMULTIDISASMSIGNATURE_H 22 | #define DIALOGMULTIDISASMSIGNATURE_H 23 | 24 | #include "dialogsearchvalues.h" 25 | #include "xabstracttableview.h" 26 | #include "xdisasmcore.h" 27 | #include "xlineedithex.h" 28 | #include "xshortcutsdialog.h" 29 | 30 | namespace Ui { 31 | class DialogMultiDisasmSignature; 32 | } 33 | 34 | class DialogMultiDisasmSignature : public XShortcutsDialog { 35 | Q_OBJECT 36 | 37 | public: 38 | explicit DialogMultiDisasmSignature(QWidget *pParent); 39 | ~DialogMultiDisasmSignature(); 40 | 41 | virtual void adjustView(); 42 | 43 | void setData(QIODevice *pDevice, qint64 nOffset, XBinary::_MEMORY_MAP *pMemoryMap, XDisasmCore *pDisasmCore); 44 | void reload(); 45 | 46 | private slots: 47 | void on_pushButtonOK_clicked(); 48 | void reloadSignature(); 49 | void on_checkBoxSpaces_toggled(bool bChecked); 50 | void on_checkBoxUpper_toggled(bool bChecked); 51 | void on_lineEditWildcard_textChanged(const QString &sText); 52 | void on_pushButtonCopy_clicked(); 53 | void on_spinBoxCount_valueChanged(int nValue); 54 | void on_comboBoxMethod_currentIndexChanged(int nIndex); 55 | void on_pushButtonScan_clicked(); 56 | 57 | protected: 58 | virtual void registerShortcuts(bool bState); 59 | 60 | private: 61 | Ui::DialogMultiDisasmSignature *ui; 62 | QIODevice *m_pDevice; 63 | qint64 m_nOffset; 64 | XBinary::_MEMORY_MAP *m_pMemoryMap; 65 | XDisasmCore *m_pDisasmCore; 66 | QList m_listRecords; 67 | qint32 m_nSymbolWidth; 68 | }; 69 | 70 | #endif // DIALOGMULTIDISASMSIGNATURE_H 71 | -------------------------------------------------------------------------------- /xdisasmview.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | if (NOT DEFINED XFORMATS_SOURCES) 4 | include(${CMAKE_CURRENT_LIST_DIR}/../Formats/xformats.cmake) 5 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${XFORMATS_SOURCES}) 6 | endif() 7 | if (NOT DEFINED XABSTRACTTABLEVIEW_SOURCES) 8 | include(${CMAKE_CURRENT_LIST_DIR}/../Controls/xabstracttableview.cmake) 9 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${XABSTRACTTABLEVIEW_SOURCES}) 10 | endif() 11 | if (NOT DEFINED XCAPSTONE_SOURCES) 12 | include(${CMAKE_CURRENT_LIST_DIR}/../XCapstone/xcapstone.cmake) 13 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${XCAPSTONE_SOURCES}) 14 | endif() 15 | if (NOT DEFINED DIALOGGOTOADDRESS_SOURCES) 16 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatDialogs/dialoggotoaddress.cmake) 17 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${DIALOGGOTOADDRESS_SOURCES}) 18 | endif() 19 | if (NOT DEFINED DIALOGSEARCH_SOURCES) 20 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatDialogs/dialogsearch.cmake) 21 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${DIALOGSEARCH_SOURCES}) 22 | endif() 23 | if (NOT DEFINED DIALOGDUMP_SOURCES) 24 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatDialogs/dialogdump.cmake) 25 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${DIALOGDUMP_SOURCES}) 26 | endif() 27 | if (NOT DEFINED DIALOGHEXSIGNATURE_SOURCES) 28 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatDialogs/dialoghexsignature.cmake) 29 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${DIALOGHEXSIGNATURE_SOURCES}) 30 | endif() 31 | if (NOT DEFINED SEARCHSIGNATURESWIDGET_SOURCES) 32 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatWidgets/SearchSignatures/searchsignatureswidget.cmake) 33 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${SEARCHSIGNATURESWIDGET_SOURCES}) 34 | endif() 35 | if (NOT DEFINED XHEXEDIT_SOURCES) 36 | include(${CMAKE_CURRENT_LIST_DIR}/../XHexEdit/xhexedit.cmake) 37 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${XHEXEDIT_SOURCES}) 38 | endif() 39 | if (NOT DEFINED XSYMBOLSWIDGET_SOURCES) 40 | include(${CMAKE_CURRENT_LIST_DIR}/../XSymbolsWidget/xsymbolswidget.cmake) 41 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${XSYMBOLSWIDGET_SOURCES}) 42 | endif() 43 | if (NOT DEFINED XDECOMPILER_SOURCES) 44 | include(${CMAKE_CURRENT_LIST_DIR}/../XDecompiler/xdecompiler.cmake) 45 | set(XDISASMVIEW_SOURCES ${XDISASMVIEW_SOURCES} ${XDECOMPILER_SOURCES}) 46 | endif() 47 | 48 | set(XDISASMVIEW_SOURCES 49 | ${XDISASMVIEW_SOURCES} 50 | ${CMAKE_CURRENT_LIST_DIR}/dialogmultidisasm.cpp 51 | ${CMAKE_CURRENT_LIST_DIR}/dialogmultidisasm.h 52 | ${CMAKE_CURRENT_LIST_DIR}/dialogmultidisasm.ui 53 | ${CMAKE_CURRENT_LIST_DIR}/Widgets/dialogmultidisasmsignature.cpp 54 | ${CMAKE_CURRENT_LIST_DIR}/Widgets/dialogmultidisasmsignature.h 55 | ${CMAKE_CURRENT_LIST_DIR}/Widgets/dialogmultidisasmsignature.ui 56 | ${CMAKE_CURRENT_LIST_DIR}/xdisasmview.cpp 57 | ${CMAKE_CURRENT_LIST_DIR}/xdisasmview.h 58 | ${CMAKE_CURRENT_LIST_DIR}/xmultidisasmwidget.cpp 59 | ${CMAKE_CURRENT_LIST_DIR}/xmultidisasmwidget.h 60 | ${CMAKE_CURRENT_LIST_DIR}/xmultidisasmwidget.ui 61 | ${CMAKE_CURRENT_LIST_DIR}/xdisasmviewoptionswidget.cpp 62 | ${CMAKE_CURRENT_LIST_DIR}/xdisasmviewoptionswidget.h 63 | ${CMAKE_CURRENT_LIST_DIR}/xdisasmviewoptionswidget.ui 64 | ) 65 | -------------------------------------------------------------------------------- /xmultidisasmwidget.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 XMULTIDISASMWIDGET_H 22 | #define XMULTIDISASMWIDGET_H 23 | 24 | #include 25 | 26 | #include "xdisasmview.h" 27 | #include "xformats.h" 28 | 29 | namespace Ui { 30 | class XMultiDisasmWidget; 31 | } 32 | 33 | class XMultiDisasmWidget : public XShortcutsWidget { 34 | Q_OBJECT 35 | 36 | public: 37 | struct OPTIONS { 38 | XBinary::FT fileType; 39 | XADDR nStartAddress; // For FT_REGION 40 | XADDR nInitAddress; 41 | QString sTitle; 42 | bool bModeFixed; // TODO Check 43 | QString sArch; 44 | bool bMenu_Hex; 45 | bool bHideReadOnly; 46 | }; 47 | 48 | explicit XMultiDisasmWidget(QWidget *pParent = nullptr); 49 | ~XMultiDisasmWidget(); 50 | 51 | void setData(QIODevice *pDevice, const OPTIONS &options); 52 | void setDevice(QIODevice *pDevice); 53 | void setXInfoDB(XInfoDB *pXInfoDB); 54 | void setGlobal(XShortcuts *pShortcuts, XOptions *pXOptions); 55 | virtual void setReadonly(bool bState); 56 | void setReadonlyVisible(bool bState); 57 | void setEdited(qint64 nDeviceOffset, qint64 nDeviceSize); 58 | virtual void setLocation(quint64 nLocation, qint32 nLocationType, qint64 nSize); 59 | virtual void adjustView(); 60 | void setWidgetFocus(); 61 | virtual void reloadData(bool bSaveSelection); 62 | 63 | private: 64 | void reloadFileType(); 65 | void reloadMethod(); 66 | void adjustMode(); 67 | 68 | private slots: 69 | void on_comboBoxMode_currentIndexChanged(int nIndex); 70 | void on_checkBoxReadonly_toggled(bool bChecked); 71 | void on_comboBoxType_currentIndexChanged(int nIndex); 72 | void adjustVisitedState(); 73 | void on_toolButtonVisitedPrev_clicked(); 74 | void on_toolButtonVisitedNext_clicked(); 75 | void on_comboBoxMethod_currentIndexChanged(int nIndex); 76 | void on_comboBoxView_currentIndexChanged(int nIndex); 77 | 78 | protected: 79 | virtual void registerShortcuts(bool bState); 80 | 81 | signals: 82 | void deviceSizeChanged(qint64 nOldSize, qint64 nNewSize); 83 | void showOffsetHex(qint64 nOffset); 84 | 85 | private: 86 | Ui::XMultiDisasmWidget *ui; 87 | QIODevice *m_pDevice; 88 | XInfoDB *m_pXInfoDB; 89 | OPTIONS m_options; 90 | }; 91 | 92 | #endif // XMULTIDISASMWIDGET_H 93 | -------------------------------------------------------------------------------- /xdisasmviewoptionswidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | XDisasmViewOptionsWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 31 | 32 | QFrame::NoFrame 33 | 34 | 35 | QFrame::Plain 36 | 37 | 38 | true 39 | 40 | 41 | 42 | 43 | 0 44 | 0 45 | 400 46 | 300 47 | 48 | 49 | 50 | 51 | 0 52 | 53 | 54 | 0 55 | 56 | 57 | 0 58 | 59 | 60 | 61 | 62 | Syntax 63 | 64 | 65 | 66 | 2 67 | 68 | 69 | 2 70 | 71 | 72 | 2 73 | 74 | 75 | 2 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | Uppercase 87 | 88 | 89 | 90 | 91 | 92 | 93 | Show colons in addresses 94 | 95 | 96 | 97 | 98 | 99 | 100 | Highlight 101 | 102 | 103 | true 104 | 105 | 106 | false 107 | 108 | 109 | 110 | 2 111 | 112 | 113 | 2 114 | 115 | 116 | 2 117 | 118 | 119 | 2 120 | 121 | 122 | 123 | 124 | Colors 125 | 126 | 127 | 128 | 129 | 130 | 131 | Qt::Horizontal 132 | 133 | 134 | 135 | 294 136 | 20 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | Qt::Vertical 148 | 149 | 150 | 151 | 20 152 | 231 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /xmultidisasmwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | XMultiDisasmWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 859 10 | 447 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 | 36 | 37 | 38 | 1 39 | 40 | 41 | 1 42 | 43 | 44 | 1 45 | 46 | 47 | 1 48 | 49 | 50 | 51 | 52 | 53 | 120 54 | 0 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 200 64 | 0 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 24 74 | 16777215 75 | 76 | 77 | 78 | < 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 24 87 | 16777215 88 | 89 | 90 | 91 | > 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 120 100 | 0 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | Qt::Orientation::Horizontal 109 | 110 | 111 | 112 | 40 113 | 20 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | Readonly 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 0 135 | 136 | 137 | 0 138 | 139 | 140 | 0 141 | 142 | 143 | 0 144 | 145 | 146 | 147 | 148 | 149 | 120 150 | 0 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | Qt::Orientation::Horizontal 159 | 160 | 161 | 162 | 40 163 | 20 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 0 176 | 0 177 | 178 | 179 | 180 | true 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | XDisasmView 189 | QWidget 190 |
xdisasmview.h
191 | 1 192 |
193 |
194 | 195 | 196 |
197 | -------------------------------------------------------------------------------- /Widgets/dialogmultidisasmsignature.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | DialogMultiDisasmSignature 4 | 5 | 6 | Qt::ApplicationModal 7 | 8 | 9 | 10 | 0 11 | 0 12 | 935 13 | 413 14 | 15 | 16 | 17 | Signature 18 | 19 | 20 | true 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 1 29 | 30 | 31 | 20 32 | 33 | 34 | 8 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 200 43 | 0 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | Qt::Horizontal 52 | 53 | 54 | 55 | 40 56 | 20 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | QAbstractItemView::NoEditTriggers 67 | 68 | 69 | QAbstractItemView::SingleSelection 70 | 71 | 72 | QAbstractItemView::SelectRows 73 | 74 | 75 | false 76 | 77 | 78 | false 79 | 80 | 81 | 20 82 | 83 | 84 | 20 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 16777215 93 | 100 94 | 95 | 96 | 97 | true 98 | 99 | 100 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 101 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 102 | p, li { white-space: pre-wrap; } 103 | </style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> 104 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8.25pt;"><br /></p></body></html> 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | Spaces 114 | 115 | 116 | 117 | 118 | 119 | 120 | Upper 121 | 122 | 123 | true 124 | 125 | 126 | 127 | 128 | 129 | 130 | Wildcard 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 20 139 | 16777215 140 | 141 | 142 | 143 | . 144 | 145 | 146 | 1 147 | 148 | 149 | Qt::AlignCenter 150 | 151 | 152 | 153 | 154 | 155 | 156 | Scan 157 | 158 | 159 | 160 | 161 | 162 | 163 | Qt::Horizontal 164 | 165 | 166 | 167 | 40 168 | 20 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | Copy 177 | 178 | 179 | 180 | 181 | 182 | 183 | OK 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /xdisasmview.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 XDISASMVIEW_H 22 | #define XDISASMVIEW_H 23 | 24 | #include 25 | 26 | #include "dialoghexedit.h" 27 | #include "Widgets/dialogmultidisasmsignature.h" 28 | #include "xdevicetableeditview.h" 29 | #include "dialogxsymbols.h" 30 | #include "xdialogprocess.h" 31 | 32 | // TODO AbstractQuery 33 | // Load symbols Save db 34 | // TODO Click on Comment Header All -> User Comments -> System Comments 35 | // TODO Click on Opcode label -> Addresses 36 | // TODO Capstone info 37 | class XDisasmView : public XDeviceTableEditView { 38 | Q_OBJECT 39 | 40 | struct TRANSRECORD { 41 | qint64 nViewPos; 42 | XADDR nAddress; 43 | qint64 nOffset; 44 | qint64 nSize; 45 | }; 46 | 47 | public: 48 | enum VIEWMETHOD { 49 | VIEWMETHOD_NONE = 0, 50 | VIEWMETHOD_ANALYZED 51 | }; 52 | 53 | enum VIEWDISASM { 54 | VIEWDISASM_COMPACT = 0, 55 | VIEWDISASM_FULL 56 | }; 57 | 58 | explicit XDisasmView(QWidget *pParent = nullptr); 59 | ~XDisasmView(); 60 | 61 | virtual void adjustView(); 62 | void setData(QIODevice *pDevice, const XBinaryView::OPTIONS &options, bool bReload = true); 63 | void setViewMethod(VIEWMETHOD viewMethod); 64 | void setViewDisasm(VIEWDISASM viewDisasm); 65 | XBinary::DM getDisasmMode(); // TODO Check -> remove 66 | XADDR getSelectionInitAddress(); 67 | DEVICESTATE getDeviceState(bool bGlobalOffset = false); 68 | void setDeviceState(const DEVICESTATE &deviceState, bool bGlobalOffset = false); 69 | // virtual qint64 deviceOffsetToViewPos(qint64 nOffset, bool bGlobalOffset = false); 70 | // virtual qint64 deviceSizeToViewSize(qint64 nOffset, qint64 nSize, bool bGlobalOffset = false); 71 | // virtual qint64 viewPosToDeviceOffset(qint64 nViewPos, bool bGlobalOffset = false); 72 | void showReferences(XADDR nAddress); 73 | 74 | void analyzeAll(); 75 | 76 | virtual QList getMenuItems(); 77 | 78 | private: 79 | enum COLUMN { 80 | COLUMN_ARROWS = 0, 81 | COLUMN_BREAKPOINT, 82 | COLUMN_LOCATION, 83 | COLUMN_LABEL, 84 | COLUMN_BYTES, 85 | COLUMN_OPCODE, 86 | COLUMN_COMMENT 87 | }; 88 | 89 | enum ARROW { 90 | ARROW_NONE = 0, 91 | ARROW_UP, 92 | ARROW_DOWN 93 | }; 94 | 95 | struct RECORD { 96 | QString sLocation; 97 | QString sBytes; 98 | QString sLabel; 99 | QString sComment; 100 | qint64 nViewPos; // Line 101 | qint64 nDeviceOffset; 102 | XDisasmAbstract::DISASM_RESULT disasmResult; 103 | #ifdef USE_XPROCESS 104 | XInfoDB::BPT breakpointType; 105 | bool bIsCurrentIP; 106 | #endif 107 | bool bIsAnalysed; 108 | ARROW array; 109 | qint32 nArrayLevel; 110 | qint32 nMaxLevel; 111 | qint32 nArraySize; 112 | bool bIsEnd; 113 | bool bHasRefFrom; 114 | bool bIsBytesHighlighted; 115 | QColor colBytesBackground; 116 | QColor colBytesBackgroundSelected; 117 | quint32 nInfo; 118 | bool bIsAprox; // TODO mb red color!!! 119 | // TODO jmp/jcc 120 | }; 121 | 122 | struct MENU_STATE { 123 | // bool bOffset; 124 | bool bPhysicalSize; 125 | bool bSize; 126 | bool bHex; 127 | }; 128 | 129 | QString convertOpcodeString(const XDisasmAbstract::DISASM_RESULT &disasmResult); 130 | qint64 getDisasmViewPos(qint64 nViewPos, qint64 nOldViewPos); // TODO rename 131 | MENU_STATE getMenuState(); 132 | 133 | struct TEXT_OPTION { 134 | bool bIsSelected; 135 | bool bIsCurrentIP; 136 | // bool bIsCursor; 137 | bool bIsBreakpoint; 138 | bool bIsAnalysed; 139 | QColor colSelected; 140 | QColor colBreakpoint; 141 | QColor colAnalyzed; 142 | }; 143 | 144 | void drawText(QPainter *pPainter, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight, const QString &sText, TEXT_OPTION *pTextOption); 145 | void drawDisasmText(QPainter *pPainter, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight, const XDisasmAbstract::DISASM_RESULT &disasmResult, 146 | TEXT_OPTION *pTextOption); 147 | void drawArrowHead(QPainter *pPainter, QPointF pointStart, QPointF pointEnd, bool bIsSelected, bool bIsCond); 148 | void drawArrowLine(QPainter *pPainter, QPointF pointStart, QPointF pointEnd, bool bIsSelected, bool bIsCond); 149 | 150 | private: 151 | RECORD _getRecordByViewPos(QList *pListRecord, qint64 nViewPos); 152 | RECORD _getRecordByVirtualAddress(QList *pListRecord, XADDR nVirtualAddress); 153 | 154 | QList _getTransRecords(qint64 nViewPos, qint64 nSize); 155 | void getRecords(); 156 | void updateArrows(); 157 | void updateLocations(); 158 | 159 | protected: 160 | virtual OS cursorPositionToOS(const CURSOR_POSITION &cursorPosition); 161 | virtual void updateData(); 162 | virtual void paintColumn(QPainter *pPainter, qint32 nColumn, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight); 163 | virtual void paintCell(QPainter *pPainter, qint32 nRow, qint32 nColumn, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight); 164 | virtual void wheelEvent(QWheelEvent *pEvent); 165 | virtual void keyPressEvent(QKeyEvent *pEvent); 166 | virtual XVPOS getCurrentViewPosFromScroll(); 167 | virtual void setCurrentViewPosToScroll(XVPOS nViewPos); 168 | virtual void adjustColumns(); 169 | virtual void _headerClicked(qint32 nColumn); 170 | virtual void _cellDoubleClicked(qint32 nRow, qint32 nColumn); 171 | virtual qint64 getFixViewPos(qint64 nViewPos); // TODO rewrite 172 | virtual void adjustScrollCount(); 173 | virtual qint64 getViewSizeByViewPos(qint64 nViewPos); // TODO rewrite 174 | 175 | protected slots: 176 | void _goToEntryPointSlot(); 177 | void _goToXrefSlot(); 178 | void _signatureSlot(); 179 | void _hexSlot(); 180 | void _referencesSlot(); 181 | void _analyzeAll(); 182 | void _analyzeAnalyze(); 183 | void _analyzeSymbols(); 184 | void _analyzeFunctions(); 185 | void _transfer(XInfoDBTransfer::COMMAND command); 186 | 187 | private: 188 | qint32 m_nBytesProLine; 189 | QList m_listRecords; 190 | qint32 m_nAddressWidth; 191 | qint32 m_nOpcodeSize; 192 | XADDR m_nThisBaseVirtualAddress; 193 | qint64 m_nThisBaseDeviceOffset; 194 | bool m_bIsLocationColon; 195 | bool m_bIsHighlight; 196 | // OPCODEMODE g_opcodeMode; 197 | // BYTESMODE g_bytesMode; 198 | QTextOption _qTextOptions; 199 | XDisasmAbstract::DISASM_OPTIONS m_disasmOptions; 200 | 201 | QList m_listHighlightsRegion; 202 | VIEWMETHOD m_viewMethod; 203 | VIEWDISASM m_viewDisasm; 204 | }; 205 | 206 | #endif // XDISASMVIEW_H 207 | -------------------------------------------------------------------------------- /xmultidisasmwidget.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 "xmultidisasmwidget.h" 22 | 23 | #include "ui_xmultidisasmwidget.h" 24 | 25 | XMultiDisasmWidget::XMultiDisasmWidget(QWidget *pParent) : XShortcutsWidget(pParent), ui(new Ui::XMultiDisasmWidget) 26 | { 27 | ui->setupUi(this); 28 | 29 | XOptions::adjustToolButton(ui->toolButtonVisitedNext, XOptions::ICONTYPE_FORWARD, Qt::ToolButtonIconOnly); 30 | XOptions::adjustToolButton(ui->toolButtonVisitedPrev, XOptions::ICONTYPE_BACKWARD, Qt::ToolButtonIconOnly); 31 | 32 | ui->comboBoxType->setToolTip(tr("Type")); 33 | ui->comboBoxMode->setToolTip(tr("Mode")); 34 | ui->toolButtonVisitedNext->setToolTip(tr("Next visited")); 35 | ui->toolButtonVisitedPrev->setToolTip(tr("Previous visited")); 36 | ui->checkBoxReadonly->setToolTip(tr("Readonly")); 37 | ui->comboBoxMethod->setToolTip(tr("Method")); 38 | ui->comboBoxView->setToolTip(tr("View")); 39 | 40 | m_pDevice = nullptr; 41 | m_pXInfoDB = nullptr; 42 | m_options = {}; 43 | 44 | // TODO BPF 45 | // TODO Check more !!! 46 | 47 | connect(ui->scrollAreaDisasm, SIGNAL(followLocation(quint64, qint32, qint64, qint32)), this, SIGNAL(followLocation(quint64, qint32, qint64, qint32))); 48 | connect(ui->scrollAreaDisasm, SIGNAL(errorMessage(QString)), this, SLOT(errorMessageSlot(QString))); 49 | // connect(ui->scrollAreaDisasm,SIGNAL(cursorViewPosChanged(qint64)),this,SLOT(cursorChanged(qint64))); 50 | // connect(ui->scrollAreaDisasm,SIGNAL(selectionChanged()),this,SLOT(selectionChanged())); 51 | connect(ui->scrollAreaDisasm, SIGNAL(currentLocationChanged(quint64, qint32, qint64)), this, SIGNAL(currentLocationChanged(quint64, qint32, qint64))); 52 | connect(ui->scrollAreaDisasm, SIGNAL(dataChanged(qint64, qint64)), this, SIGNAL(dataChanged(qint64, qint64))); 53 | connect(ui->scrollAreaDisasm, SIGNAL(deviceSizeChanged(qint64, qint64)), this, SIGNAL(deviceSizeChanged(qint64, qint64))); 54 | connect(ui->scrollAreaDisasm, SIGNAL(visitedStateChanged()), this, SLOT(adjustVisitedState())); 55 | 56 | setReadonlyVisible(false); 57 | ui->checkBoxReadonly->setChecked(true); 58 | 59 | adjustVisitedState(); 60 | 61 | ui->comboBoxView->addItem(tr("Compact"), XDisasmView::VIEWDISASM_COMPACT); 62 | ui->comboBoxView->addItem(tr("Full"), XDisasmView::VIEWDISASM_FULL); 63 | 64 | // ui->frameAnalize->hide(); 65 | } 66 | 67 | XMultiDisasmWidget::~XMultiDisasmWidget() 68 | { 69 | delete ui; 70 | } 71 | 72 | void XMultiDisasmWidget::setData(QIODevice *pDevice, const OPTIONS &options) 73 | { 74 | m_pDevice = pDevice; 75 | m_options = options; 76 | 77 | if (pDevice) { 78 | XFormats::setFileTypeComboBox(options.fileType, pDevice, ui->comboBoxType, XBinary::TL_OPTION_EXECUTABLE); 79 | } else { 80 | XBinaryView::OPTIONS _options = {}; 81 | ui->scrollAreaDisasm->setData(nullptr, _options); 82 | } 83 | 84 | adjustVisitedState(); 85 | 86 | reloadFileType(); 87 | } 88 | 89 | void XMultiDisasmWidget::setDevice(QIODevice *pDevice) 90 | { 91 | XBinaryView::OPTIONS _options = {}; 92 | ui->scrollAreaDisasm->setData(pDevice, _options); 93 | } 94 | 95 | void XMultiDisasmWidget::setXInfoDB(XInfoDB *pXInfoDB) 96 | { 97 | ui->scrollAreaDisasm->setXInfoDB(pXInfoDB); 98 | } 99 | 100 | void XMultiDisasmWidget::setLocation(quint64 nLocation, qint32 nLocationType, qint64 nSize) 101 | { 102 | ui->scrollAreaDisasm->setLocation(nLocation, nLocationType, nSize); 103 | } 104 | 105 | void XMultiDisasmWidget::adjustView() 106 | { 107 | ui->scrollAreaDisasm->adjustView(); 108 | } 109 | 110 | void XMultiDisasmWidget::setWidgetFocus() 111 | { 112 | ui->scrollAreaDisasm->setFocus(); 113 | } 114 | 115 | void XMultiDisasmWidget::reloadData(bool bSaveSelection) 116 | { 117 | Q_UNUSED(bSaveSelection) 118 | ui->scrollAreaDisasm->reload(true); 119 | } 120 | 121 | void XMultiDisasmWidget::setGlobal(XShortcuts *pShortcuts, XOptions *pXOptions) 122 | { 123 | ui->scrollAreaDisasm->setGlobal(pShortcuts, pXOptions); 124 | XShortcutsWidget::setGlobal(pShortcuts, pXOptions); 125 | } 126 | 127 | void XMultiDisasmWidget::setReadonly(bool bState) 128 | { 129 | ui->scrollAreaDisasm->setReadonly(bState); 130 | } 131 | 132 | void XMultiDisasmWidget::setReadonlyVisible(bool bState) 133 | { 134 | if (bState) { 135 | ui->checkBoxReadonly->show(); 136 | } else { 137 | ui->checkBoxReadonly->hide(); 138 | } 139 | } 140 | 141 | void XMultiDisasmWidget::setEdited(qint64 nDeviceOffset, qint64 nDeviceSize) 142 | { 143 | ui->scrollAreaDisasm->setEdited(nDeviceOffset, nDeviceSize); 144 | 145 | // emit changed(); 146 | } 147 | 148 | void XMultiDisasmWidget::reloadFileType() 149 | { 150 | if (m_pDevice) { 151 | m_options.fileType = (XBinary::FT)(ui->comboBoxType->currentData().toInt()); 152 | 153 | XBinaryView::OPTIONS options = {}; 154 | options.nInitAddress = m_options.nInitAddress; 155 | options.nEntryPointAddress = XFormats::getEntryPointAddress(m_options.fileType, m_pDevice); 156 | options.bMenu_Hex = m_options.bMenu_Hex; 157 | options.bHideReadOnly = m_options.bHideReadOnly; 158 | 159 | XBinary::FILEFORMATINFO fileFormatInfo = {}; 160 | 161 | if (m_options.fileType == XBinary::FT_REGION) { 162 | fileFormatInfo = XFormats::getFileFormatInfo(m_options.fileType, m_pDevice, true, m_options.nStartAddress); 163 | } else { 164 | fileFormatInfo = XFormats::getFileFormatInfo(m_options.fileType, m_pDevice); 165 | } 166 | 167 | // if (m_options.sArch != "") { 168 | // options.memoryMapRegion.sArch = m_options.sArch; 169 | // } 170 | 171 | ui->comboBoxMode->setEnabled(!m_options.bModeFixed); 172 | 173 | // ui->scrollAreaDisasm->setData(m_pDevice, options); 174 | 175 | XBinary::DM disasmMode = XBinary::getDisasmMode(&fileFormatInfo); 176 | 177 | XFormats::setDisasmModeComboBox(disasmMode, ui->comboBoxMode); 178 | 179 | options.fileType = (XBinary::FT)(ui->comboBoxType->currentData().toInt()); 180 | options.disasmMode = (XBinary::DM)(ui->comboBoxMode->currentData().toInt()); 181 | 182 | // // TODO Check 183 | // if (ui->scrollAreaDisasm->getXInfoDB()) { 184 | // ui->scrollAreaDisasm->getXInfoDB()->setData(m_pDevice, options.memoryMapRegion.fileType, options.disasmMode); 185 | // // getSymbols(); 186 | // } 187 | 188 | ui->scrollAreaDisasm->setData(m_pDevice, options); 189 | ui->scrollAreaDisasm->reload(true); 190 | reloadMethod(); 191 | } 192 | } 193 | 194 | void XMultiDisasmWidget::reloadMethod() 195 | { 196 | const bool bBlocked1 = ui->comboBoxMethod->blockSignals(true); 197 | ui->comboBoxMethod->clear(); 198 | ui->comboBoxMethod->addItem("", XDisasmView::VIEWMETHOD_NONE); 199 | ui->comboBoxMethod->addItem(tr("Analyzed"), XDisasmView::VIEWMETHOD_ANALYZED); 200 | 201 | ui->comboBoxMethod->blockSignals(bBlocked1); 202 | } 203 | 204 | void XMultiDisasmWidget::adjustMode() 205 | { 206 | XBinaryView::OPTIONS options = *(ui->scrollAreaDisasm->getBinaryView()->getOptions()); 207 | options.disasmMode = (XBinary::DM)(ui->comboBoxMode->currentData().toInt()); 208 | 209 | ui->scrollAreaDisasm->setData(m_pDevice, options); 210 | ui->scrollAreaDisasm->reload(true); 211 | 212 | // if (ui->scrollAreaDisasm->getXInfoDB()) { 213 | // ui->scrollAreaDisasm->getXInfoDB()->setData(m_pDevice, options.memoryMapRegion.fileType, options.disasmMode); 214 | // } 215 | } 216 | 217 | void XMultiDisasmWidget::on_comboBoxMode_currentIndexChanged(int nIndex) 218 | { 219 | Q_UNUSED(nIndex) 220 | 221 | adjustMode(); 222 | } 223 | 224 | void XMultiDisasmWidget::registerShortcuts(bool bState) 225 | { 226 | Q_UNUSED(bState) 227 | } 228 | 229 | void XMultiDisasmWidget::on_checkBoxReadonly_toggled(bool bChecked) 230 | { 231 | ui->scrollAreaDisasm->setReadonly(bChecked); 232 | } 233 | 234 | void XMultiDisasmWidget::on_comboBoxType_currentIndexChanged(int nIndex) 235 | { 236 | Q_UNUSED(nIndex) 237 | 238 | reloadFileType(); 239 | } 240 | 241 | void XMultiDisasmWidget::adjustVisitedState() 242 | { 243 | ui->toolButtonVisitedPrev->setEnabled(ui->scrollAreaDisasm->isPrevVisitedAvailable()); 244 | ui->toolButtonVisitedNext->setEnabled(ui->scrollAreaDisasm->isNextVisitedAvailable()); 245 | } 246 | 247 | void XMultiDisasmWidget::on_toolButtonVisitedPrev_clicked() 248 | { 249 | ui->scrollAreaDisasm->goToPrevVisited(); 250 | } 251 | 252 | void XMultiDisasmWidget::on_toolButtonVisitedNext_clicked() 253 | { 254 | ui->scrollAreaDisasm->goToNextVisited(); 255 | } 256 | 257 | void XMultiDisasmWidget::on_comboBoxMethod_currentIndexChanged(int nIndex) 258 | { 259 | Q_UNUSED(nIndex) 260 | 261 | ui->scrollAreaDisasm->setViewMethod((XDisasmView::VIEWMETHOD)(ui->comboBoxMethod->currentData().toInt())); 262 | } 263 | 264 | void XMultiDisasmWidget::on_comboBoxView_currentIndexChanged(int nIndex) 265 | { 266 | Q_UNUSED(nIndex) 267 | 268 | ui->scrollAreaDisasm->setViewDisasm((XDisasmView::VIEWDISASM)(ui->comboBoxView->currentData().toInt())); 269 | } 270 | -------------------------------------------------------------------------------- /Widgets/dialogmultidisasmsignature.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 "dialogmultidisasmsignature.h" 22 | 23 | #include "ui_dialogmultidisasmsignature.h" 24 | 25 | DialogMultiDisasmSignature::DialogMultiDisasmSignature(QWidget *pParent) : XShortcutsDialog(pParent, false), ui(new Ui::DialogMultiDisasmSignature) 26 | { 27 | ui->setupUi(this); 28 | 29 | this->m_pDevice = nullptr; 30 | this->m_nOffset = 0; 31 | this->m_pMemoryMap = nullptr; 32 | 33 | // ui->tableWidgetSignature->setFont(XAbstractTableView::getMonoFont(10)); 34 | ui->textEditSignature->setFont(XOptions::getMonoFont()); 35 | 36 | const bool bBlocked1 = ui->spinBoxCount->blockSignals(true); 37 | const bool bBlocked2 = ui->comboBoxMethod->blockSignals(true); 38 | 39 | ui->comboBoxMethod->addItem("", 0); 40 | ui->comboBoxMethod->addItem(tr("Relative virtual address"), 1); 41 | 42 | m_nSymbolWidth = XLineEditHEX::getSymbolWidth(ui->tableWidgetSignature); 43 | 44 | ui->spinBoxCount->blockSignals(bBlocked1); 45 | ui->comboBoxMethod->blockSignals(bBlocked2); 46 | } 47 | 48 | DialogMultiDisasmSignature::~DialogMultiDisasmSignature() 49 | { 50 | delete ui; 51 | } 52 | 53 | void DialogMultiDisasmSignature::adjustView() 54 | { 55 | getGlobalOptions()->adjustTableWidget(ui->tableWidgetSignature, XOptions::ID_VIEW_FONT_TABLEVIEWS); 56 | } 57 | 58 | void DialogMultiDisasmSignature::setData(QIODevice *pDevice, qint64 nOffset, XBinary::_MEMORY_MAP *pMemoryMap, XDisasmCore *pDisasmCore) 59 | { 60 | this->m_pDevice = pDevice; 61 | this->m_nOffset = nOffset; 62 | this->m_pMemoryMap = pMemoryMap; 63 | this->m_pDisasmCore = pDisasmCore; 64 | 65 | reload(); 66 | } 67 | 68 | void DialogMultiDisasmSignature::reload() 69 | { 70 | qint32 nCount = ui->spinBoxCount->value(); 71 | qint32 nMethod = ui->comboBoxMethod->currentData().toInt(); 72 | 73 | XDisasmCore::ST st = XDisasmCore::ST_FULL; 74 | 75 | if (nMethod == 1) { 76 | st = XDisasmCore::ST_REL; 77 | } 78 | 79 | m_listRecords = m_pDisasmCore->getSignatureRecords(m_pDevice, m_pMemoryMap, m_nOffset, nCount, st); 80 | 81 | qint32 nNumberOfRecords = m_listRecords.count(); 82 | 83 | ui->tableWidgetSignature->clear(); 84 | 85 | ui->tableWidgetSignature->setColumnCount(5); 86 | ui->tableWidgetSignature->setRowCount(nNumberOfRecords); 87 | 88 | QStringList listHeaders; 89 | listHeaders.append(tr("Address")); 90 | listHeaders.append(tr("Bytes")); 91 | listHeaders.append(tr("Opcode")); 92 | listHeaders.append(""); 93 | listHeaders.append(""); 94 | 95 | ui->tableWidgetSignature->setHorizontalHeaderLabels(listHeaders); 96 | 97 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 98 | ui->tableWidgetSignature->setItem(i, 0, new QTableWidgetItem(XBinary::valueToHex(m_listRecords.at(i).nAddress))); 99 | ui->tableWidgetSignature->setItem(i, 1, new QTableWidgetItem(m_listRecords.at(i).baOpcode.toHex().data())); 100 | 101 | if (!m_listRecords.at(i).bIsConst) { 102 | QPushButton *pUseSignatureButton = new QPushButton(this); 103 | pUseSignatureButton->setText(m_listRecords.at(i).sOpcode); 104 | pUseSignatureButton->setCheckable(true); 105 | connect(pUseSignatureButton, SIGNAL(clicked()), this, SLOT(reloadSignature())); 106 | 107 | ui->tableWidgetSignature->setCellWidget(i, 2, pUseSignatureButton); 108 | 109 | if (m_listRecords.at(i).nDispSize) { 110 | QPushButton *pDispButton = new QPushButton(this); 111 | pDispButton->setText(QString("d")); 112 | pDispButton->setCheckable(true); 113 | pDispButton->setMaximumWidth(m_nSymbolWidth * 6); 114 | connect(pDispButton, SIGNAL(clicked()), this, SLOT(reloadSignature())); 115 | 116 | ui->tableWidgetSignature->setCellWidget(i, 3, pDispButton); 117 | } 118 | 119 | if (m_listRecords.at(i).nImmSize) { 120 | QPushButton *pImmButton = new QPushButton(this); 121 | pImmButton->setText(QString("i")); 122 | pImmButton->setCheckable(true); 123 | pImmButton->setMaximumWidth(m_nSymbolWidth * 6); 124 | connect(pImmButton, SIGNAL(clicked()), this, SLOT(reloadSignature())); 125 | 126 | ui->tableWidgetSignature->setCellWidget(i, 4, pImmButton); 127 | } 128 | } else { 129 | ui->tableWidgetSignature->setItem(i, 2, new QTableWidgetItem(m_listRecords.at(i).sOpcode)); 130 | } 131 | } 132 | 133 | ui->tableWidgetSignature->setColumnWidth(0, m_nSymbolWidth * 12); 134 | ui->tableWidgetSignature->setColumnWidth(1, m_nSymbolWidth * 20); 135 | ui->tableWidgetSignature->setColumnWidth(2, m_nSymbolWidth * 20); 136 | ui->tableWidgetSignature->setColumnWidth(3, m_nSymbolWidth * 6); 137 | ui->tableWidgetSignature->setColumnWidth(4, m_nSymbolWidth * 6); 138 | 139 | ui->tableWidgetSignature->horizontalHeader()->setVisible(true); 140 | 141 | // ui->tableWidgetSignature->horizontalHeader()->setSectionResizeMode(0,QHeaderView::Interactive); 142 | // ui->tableWidgetSignature->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch); 143 | // ui->tableWidgetSignature->horizontalHeader()->setSectionResizeMode(2,QHeaderView::Interactive); 144 | // ui->tableWidgetSignature->horizontalHeader()->setSectionResizeMode(3,QHeaderView::Interactive); 145 | // ui->tableWidgetSignature->horizontalHeader()->setSectionResizeMode(4,QHeaderView::Interactive); 146 | 147 | reloadSignature(); 148 | } 149 | 150 | void DialogMultiDisasmSignature::reloadSignature() 151 | { 152 | QString sText; 153 | 154 | QChar cWild = QChar('.'); 155 | QString _sWild = ui->lineEditWildcard->text(); 156 | 157 | if (_sWild.size()) { 158 | cWild = _sWild.at(0); 159 | } 160 | 161 | qint32 nNumberOfRecords = m_listRecords.count(); 162 | 163 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 164 | bool bUse = true; 165 | bool bDisp = true; 166 | bool bImm = true; 167 | 168 | QPushButton *pUseSignatureButton = dynamic_cast(ui->tableWidgetSignature->cellWidget(i, 2)); 169 | QPushButton *pDispButton = dynamic_cast(ui->tableWidgetSignature->cellWidget(i, 3)); 170 | QPushButton *pImmButton = dynamic_cast(ui->tableWidgetSignature->cellWidget(i, 4)); 171 | 172 | if (pUseSignatureButton) { 173 | bUse = !(pUseSignatureButton->isChecked()); 174 | } 175 | 176 | if (pDispButton) { 177 | pDispButton->setEnabled(bUse); 178 | bDisp = !(pDispButton->isChecked()); 179 | } 180 | 181 | if (pImmButton) { 182 | pImmButton->setEnabled(bUse); 183 | bImm = !(pImmButton->isChecked()); 184 | } 185 | 186 | qint32 nSize = m_listRecords.at(i).baOpcode.size(); 187 | 188 | QString sRecord; 189 | 190 | if (bUse) { 191 | sRecord = m_listRecords.at(i).baOpcode.toHex().data(); 192 | 193 | if (!bDisp) { 194 | sRecord = XDisasmCore::replaceWildChar(sRecord, m_listRecords.at(i).nDispOffset, m_listRecords.at(i).nDispSize, cWild); 195 | } 196 | 197 | if (!bImm) { 198 | sRecord = XDisasmCore::replaceWildChar(sRecord, m_listRecords.at(i).nImmOffset, m_listRecords.at(i).nImmSize, cWild); 199 | } 200 | 201 | if (m_listRecords.at(i).bIsConst) { 202 | sRecord = XDisasmCore::replaceWildChar(sRecord, m_listRecords.at(i).nImmOffset, m_listRecords.at(i).nImmSize, QChar('$')); 203 | } 204 | } else { 205 | for (qint32 j = 0; j < nSize; j++) { 206 | sRecord += cWild; 207 | sRecord += cWild; 208 | } 209 | } 210 | 211 | sText += sRecord; 212 | } 213 | 214 | if (ui->checkBoxUpper->isChecked()) { 215 | sText = sText.toUpper(); 216 | } else { 217 | sText = sText.toLower(); 218 | } 219 | 220 | if (ui->checkBoxSpaces->isChecked()) { 221 | QString _sText; 222 | 223 | qint32 nSize = sText.size(); 224 | 225 | for (qint32 i = 0; i < nSize; i++) { 226 | _sText += sText.at(i); 227 | 228 | if ((i % 2) && (i != (nSize - 1))) { 229 | _sText += QChar(' '); 230 | } 231 | } 232 | 233 | sText = _sText; 234 | } 235 | 236 | ui->textEditSignature->setText(sText); 237 | } 238 | 239 | void DialogMultiDisasmSignature::on_pushButtonOK_clicked() 240 | { 241 | this->close(); 242 | } 243 | 244 | void DialogMultiDisasmSignature::on_checkBoxSpaces_toggled(bool bChecked) 245 | { 246 | Q_UNUSED(bChecked) 247 | 248 | reloadSignature(); 249 | } 250 | 251 | void DialogMultiDisasmSignature::on_checkBoxUpper_toggled(bool bChecked) 252 | { 253 | Q_UNUSED(bChecked) 254 | 255 | reloadSignature(); 256 | } 257 | 258 | void DialogMultiDisasmSignature::on_lineEditWildcard_textChanged(const QString &sText) 259 | { 260 | Q_UNUSED(sText) 261 | 262 | reloadSignature(); 263 | } 264 | 265 | void DialogMultiDisasmSignature::on_pushButtonCopy_clicked() 266 | { 267 | QClipboard *pClipboard = QApplication::clipboard(); 268 | pClipboard->setText(ui->textEditSignature->toPlainText()); 269 | } 270 | 271 | void DialogMultiDisasmSignature::on_spinBoxCount_valueChanged(int nValue) 272 | { 273 | Q_UNUSED(nValue) 274 | 275 | reload(); 276 | } 277 | 278 | void DialogMultiDisasmSignature::on_comboBoxMethod_currentIndexChanged(int nIndex) 279 | { 280 | Q_UNUSED(nIndex) 281 | 282 | reload(); 283 | } 284 | 285 | void DialogMultiDisasmSignature::on_pushButtonScan_clicked() 286 | { 287 | SearchValuesWidget::OPTIONS options = {}; 288 | options.fileType = m_pMemoryMap->fileType; 289 | options.valueType = XBinary::VT_SIGNATURE; 290 | options.endian = m_pMemoryMap->endian; 291 | options.varValue = ui->textEditSignature->toPlainText(); 292 | options.bScan = true; 293 | 294 | DialogSearchValues dialogSearchValues(this); 295 | dialogSearchValues.setGlobal(getShortcuts(), getGlobalOptions()); 296 | dialogSearchValues.setData(m_pDevice, options); 297 | 298 | dialogSearchValues.exec(); 299 | } 300 | 301 | void DialogMultiDisasmSignature::registerShortcuts(bool bState) 302 | { 303 | Q_UNUSED(bState) 304 | } 305 | -------------------------------------------------------------------------------- /xdisasmviewoptionswidget.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 "xdisasmviewoptionswidget.h" 22 | 23 | #include "ui_xdisasmviewoptionswidget.h" 24 | 25 | XDisasmViewOptionsWidget::XDisasmViewOptionsWidget(QWidget *pParent) : XShortcutsWidget(pParent), ui(new Ui::XDisasmViewOptionsWidget) 26 | { 27 | ui->setupUi(this); 28 | 29 | m_pOptions = nullptr; 30 | m_mode = MODE_ALL; 31 | 32 | setProperty("GROUPID", XOptions::GROUPID_DISASM); 33 | } 34 | 35 | XDisasmViewOptionsWidget::~XDisasmViewOptionsWidget() 36 | { 37 | delete ui; 38 | } 39 | 40 | void XDisasmViewOptionsWidget::adjustView() 41 | { 42 | // TODO 43 | } 44 | 45 | void XDisasmViewOptionsWidget::setOptions(XOptions *pOptions, MODE mode) 46 | { 47 | m_pOptions = pOptions; 48 | m_mode = mode; 49 | 50 | reload(); 51 | } 52 | 53 | void XDisasmViewOptionsWidget::save() 54 | { 55 | m_pOptions->getComboBox(ui->comboBoxDisasmSyntax, XOptions::ID_DISASM_SYNTAX); 56 | m_pOptions->getCheckBox(ui->checkBoxDisasmLocationColon, XOptions::ID_DISASM_LOCATIONCOLON); 57 | m_pOptions->getCheckBox(ui->checkBoxDisasmUppercase, XOptions::ID_DISASM_UPPERCASE); 58 | m_pOptions->getCheckBox(ui->groupBoxDisasmHighlight, XOptions::ID_DISASM_HIGHLIGHT); 59 | } 60 | 61 | void XDisasmViewOptionsWidget::setDefaultValues(XOptions *pOptions, MODE mode) 62 | { 63 | pOptions->addID(XOptions::ID_DISASM_FONT, XOptions::getMonoFont().toString()); 64 | 65 | if ((mode == MODE_ALL) || (mode == MODE_X86)) { 66 | pOptions->addID(XOptions::ID_DISASM_SYNTAX, ""); 67 | } 68 | 69 | pOptions->addID(XOptions::ID_DISASM_LOCATIONCOLON, true); 70 | pOptions->addID(XOptions::ID_DISASM_HIGHLIGHT, true); 71 | pOptions->addID(XOptions::ID_DISASM_UPPERCASE, false); 72 | 73 | // Colors 74 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARROWS, QString("%1|%2").arg("", "")); 75 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARROWS_SELECTED, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 76 | pOptions->addID(XOptions::ID_DISASM_COLOR_REGS, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 77 | pOptions->addID(XOptions::ID_DISASM_COLOR_NUMBERS, QString("%1|%2").arg(QColor(Qt::blue).name(), "")); // TODO color 78 | pOptions->addID(XOptions::ID_DISASM_COLOR_OPCODE, QString("%1|%2").arg(QColor(Qt::blue).name(), "")); 79 | pOptions->addID(XOptions::ID_DISASM_COLOR_REFS, QString("%1|%2").arg(QColor(Qt::darkGreen).name(), "")); 80 | // X86 81 | if ((mode == MODE_ALL) || (mode == MODE_X86)) { 82 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_REGS_GENERAL, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 83 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_REGS_STACK, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 84 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_REGS_SEGMENT, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 85 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_REGS_DEBUG, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 86 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_REGS_IP, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 87 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_REGS_FLAGS, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 88 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_REGS_FPU, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 89 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_REGS_XMM, QString("%1|%2").arg(QColor(Qt::red).name(), "")); // TODO color 90 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_CALL, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 91 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_RET, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 92 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_NOP, QString("%1|%2").arg(QColor(Qt::gray).name(), "")); 93 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_PUSH, QString("%1|%2").arg(QColor(Qt::blue).name(), "")); 94 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_POP, QString("%1|%2").arg(QColor(Qt::blue).name(), "")); 95 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_COND_JMP, QString("%1|%2").arg(QColor(Qt::green).name(), "")); 96 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_JMP, QString("%1|%2").arg(QColor(Qt::darkBlue).name(), "")); 97 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_INT3, QString("%1|%2").arg(QColor(Qt::darkGray).name(), "")); 98 | pOptions->addID(XOptions::ID_DISASM_COLOR_X86_OPCODE_SYSCALL, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 99 | } 100 | 101 | if ((mode == MODE_ALL) || (mode == MODE_ARM)) { 102 | // ARM 103 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARM_REGS_GENERAL, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 104 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARM_REGS_STACK, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 105 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARM_OPCODE_BRANCH, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 106 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARM_OPCODE_BRANCHLINK, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 107 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARM_OPCODE_RET, QString("%1|%2").arg(QColor(Qt::red).name(), "")); 108 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARM_OPCODE_PUSH, QString("%1|%2").arg(QColor(Qt::blue).name(), "")); 109 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARM_OPCODE_POP, QString("%1|%2").arg(QColor(Qt::blue).name(), "")); 110 | pOptions->addID(XOptions::ID_DISASM_COLOR_ARM_OPCODE_NOP, QString("%1|%2").arg(QColor(Qt::gray).name(), "")); 111 | // TODO more 112 | } 113 | } 114 | 115 | QList XDisasmViewOptionsWidget::getRecords(MODE mode) 116 | { 117 | QList listResult; 118 | 119 | { 120 | QString sGroup = tr("Arrows"); 121 | 122 | { 123 | DialogViewColors::RECORD record = {sGroup, tr("All"), XOptions::ID_DISASM_COLOR_ARROWS}; 124 | listResult.append(record); 125 | } 126 | { 127 | DialogViewColors::RECORD record = {sGroup, tr("Selected"), XOptions::ID_DISASM_COLOR_ARROWS_SELECTED}; 128 | listResult.append(record); 129 | } 130 | } 131 | { 132 | DialogViewColors::RECORD record = {"", tr("Registers"), XOptions::ID_DISASM_COLOR_REGS}; 133 | listResult.append(record); 134 | } 135 | { 136 | DialogViewColors::RECORD record = {"", tr("Numbers"), XOptions::ID_DISASM_COLOR_NUMBERS}; 137 | listResult.append(record); 138 | } 139 | { 140 | DialogViewColors::RECORD record = {"", tr("Opcodes"), XOptions::ID_DISASM_COLOR_OPCODE}; 141 | listResult.append(record); 142 | } 143 | { 144 | DialogViewColors::RECORD record = {"", tr("References"), XOptions::ID_DISASM_COLOR_REFS}; 145 | listResult.append(record); 146 | } 147 | 148 | // TODO another assemblers 149 | if ((mode == MODE_ALL) || (mode == MODE_X86)) { 150 | QString sGroup = "x86/amd64"; 151 | { 152 | DialogViewColors::RECORD record = {sGroup, tr("General registers"), XOptions::ID_DISASM_COLOR_X86_REGS_GENERAL}; 153 | listResult.append(record); 154 | } 155 | { 156 | DialogViewColors::RECORD record = {sGroup, tr("Stack registers"), XOptions::ID_DISASM_COLOR_X86_REGS_STACK}; 157 | listResult.append(record); 158 | } 159 | { 160 | DialogViewColors::RECORD record = {sGroup, tr("Segment registers"), XOptions::ID_DISASM_COLOR_X86_REGS_SEGMENT}; 161 | listResult.append(record); 162 | } 163 | { 164 | DialogViewColors::RECORD record = {sGroup, tr("Debug registers"), XOptions::ID_DISASM_COLOR_X86_REGS_DEBUG}; 165 | listResult.append(record); 166 | } 167 | { 168 | DialogViewColors::RECORD record = {sGroup, tr("Instruction pointer register"), XOptions::ID_DISASM_COLOR_X86_REGS_IP}; 169 | listResult.append(record); 170 | } 171 | { 172 | DialogViewColors::RECORD record = {sGroup, tr("Flags register"), XOptions::ID_DISASM_COLOR_X86_REGS_FLAGS}; 173 | listResult.append(record); 174 | } 175 | { 176 | DialogViewColors::RECORD record = {sGroup, QString("FPU %1").arg(tr("Registers")), XOptions::ID_DISASM_COLOR_X86_REGS_FPU}; 177 | listResult.append(record); 178 | } 179 | { 180 | DialogViewColors::RECORD record = {sGroup, QString("XMM %1").arg(tr("Registers")), XOptions::ID_DISASM_COLOR_X86_REGS_XMM}; 181 | listResult.append(record); 182 | } 183 | { 184 | DialogViewColors::RECORD record = {sGroup, QString("YMM %1").arg(tr("Registers")), XOptions::ID_DISASM_COLOR_X86_REGS_YMM}; 185 | listResult.append(record); 186 | } 187 | { 188 | DialogViewColors::RECORD record = {sGroup, QString("ZMM %1").arg(tr("Registers")), XOptions::ID_DISASM_COLOR_X86_REGS_ZMM}; 189 | listResult.append(record); 190 | } 191 | { 192 | DialogViewColors::RECORD record = {sGroup, "CALL", XOptions::ID_DISASM_COLOR_X86_OPCODE_CALL}; 193 | listResult.append(record); 194 | } 195 | { 196 | DialogViewColors::RECORD record = {sGroup, "RET", XOptions::ID_DISASM_COLOR_X86_OPCODE_RET}; 197 | listResult.append(record); 198 | } 199 | { 200 | DialogViewColors::RECORD record = {sGroup, "COND JMP", XOptions::ID_DISASM_COLOR_X86_OPCODE_COND_JMP}; 201 | listResult.append(record); 202 | } 203 | { 204 | DialogViewColors::RECORD record = {sGroup, "PUSH", XOptions::ID_DISASM_COLOR_X86_OPCODE_PUSH}; 205 | listResult.append(record); 206 | } 207 | { 208 | DialogViewColors::RECORD record = {sGroup, "POP", XOptions::ID_DISASM_COLOR_X86_OPCODE_POP}; 209 | listResult.append(record); 210 | } 211 | { 212 | DialogViewColors::RECORD record = {sGroup, "NOP", XOptions::ID_DISASM_COLOR_X86_OPCODE_NOP}; 213 | listResult.append(record); 214 | } 215 | { 216 | DialogViewColors::RECORD record = {sGroup, "JMP", XOptions::ID_DISASM_COLOR_X86_OPCODE_JMP}; 217 | listResult.append(record); 218 | } 219 | { 220 | DialogViewColors::RECORD record = {sGroup, "INT3", XOptions::ID_DISASM_COLOR_X86_OPCODE_INT3}; 221 | listResult.append(record); 222 | } 223 | { 224 | DialogViewColors::RECORD record = {sGroup, "SYSCALL", XOptions::ID_DISASM_COLOR_X86_OPCODE_SYSCALL}; 225 | listResult.append(record); 226 | } 227 | } 228 | 229 | if ((mode == MODE_ALL) || (mode == MODE_ARM)) { 230 | QString sGroup = "arm/arm64"; 231 | { 232 | DialogViewColors::RECORD record = {sGroup, tr("General registers"), XOptions::ID_DISASM_COLOR_ARM_REGS_GENERAL}; 233 | listResult.append(record); 234 | } 235 | { 236 | DialogViewColors::RECORD record = {sGroup, tr("Stack registers"), XOptions::ID_DISASM_COLOR_ARM_REGS_STACK}; 237 | listResult.append(record); 238 | } 239 | { 240 | DialogViewColors::RECORD record = {sGroup, "Branch (B)", XOptions::ID_DISASM_COLOR_ARM_OPCODE_BRANCH}; 241 | listResult.append(record); 242 | } 243 | { 244 | DialogViewColors::RECORD record = {sGroup, "Branch with Link (BL)", XOptions::ID_DISASM_COLOR_ARM_OPCODE_BRANCHLINK}; 245 | listResult.append(record); 246 | } 247 | { 248 | DialogViewColors::RECORD record = {sGroup, "RET", XOptions::ID_DISASM_COLOR_ARM_OPCODE_RET}; 249 | listResult.append(record); 250 | } 251 | { 252 | DialogViewColors::RECORD record = {sGroup, "PUSH", XOptions::ID_DISASM_COLOR_ARM_OPCODE_PUSH}; 253 | listResult.append(record); 254 | } 255 | { 256 | DialogViewColors::RECORD record = {sGroup, "POP", XOptions::ID_DISASM_COLOR_ARM_OPCODE_POP}; 257 | listResult.append(record); 258 | } 259 | { 260 | DialogViewColors::RECORD record = {sGroup, "NOP", XOptions::ID_DISASM_COLOR_ARM_OPCODE_NOP}; 261 | listResult.append(record); 262 | } 263 | } 264 | return listResult; 265 | } 266 | 267 | void XDisasmViewOptionsWidget::reloadData(bool bSaveSelection) 268 | { 269 | Q_UNUSED(bSaveSelection) 270 | reload(); 271 | } 272 | 273 | void XDisasmViewOptionsWidget::reload() 274 | { 275 | m_pOptions->setCheckBox(ui->checkBoxDisasmLocationColon, XOptions::ID_DISASM_LOCATIONCOLON); 276 | m_pOptions->setCheckBox(ui->groupBoxDisasmHighlight, XOptions::ID_DISASM_HIGHLIGHT); 277 | m_pOptions->setCheckBox(ui->checkBoxDisasmUppercase, XOptions::ID_DISASM_UPPERCASE); 278 | 279 | if ((m_mode == MODE_ALL) || (m_mode == MODE_X86)) { 280 | m_pOptions->setComboBox(ui->comboBoxDisasmSyntax, XOptions::ID_DISASM_SYNTAX); 281 | } else { 282 | ui->groupBoxDisasmSyntax->hide(); 283 | } 284 | } 285 | 286 | void XDisasmViewOptionsWidget::on_pushButtonDisasmColors_clicked() 287 | { 288 | DialogViewColors dialogColors(this); 289 | dialogColors.setGlobal(getShortcuts(), getGlobalOptions()); 290 | 291 | QList listRecords = getRecords(m_mode); 292 | 293 | dialogColors.setOptions(m_pOptions, listRecords, tr("Colors")); 294 | 295 | dialogColors.exec(); 296 | } 297 | 298 | void XDisasmViewOptionsWidget::registerShortcuts(bool bState) 299 | { 300 | Q_UNUSED(bState) 301 | } 302 | -------------------------------------------------------------------------------- /xdisasmview.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 "xdisasmview.h" 22 | 23 | XDisasmView::XDisasmView(QWidget *pParent) : XDeviceTableEditView(pParent) 24 | { 25 | addShortcut(X_ID_DISASM_GOTO_OFFSET, this, SLOT(_goToOffsetSlot())); 26 | addShortcut(X_ID_DISASM_GOTO_ADDRESS, this, SLOT(_goToAddressSlot())); 27 | addShortcut(X_ID_DISASM_DUMPTOFILE, this, SLOT(_dumpToFileSlot())); 28 | addShortcut(X_ID_DISASM_SELECT_ALL, this, SLOT(_selectAllSlot())); 29 | addShortcut(X_ID_DISASM_COPY_DATA, this, SLOT(_copyDataSlot())); 30 | addShortcut(X_ID_DISASM_COPY_OFFSET, this, SLOT(_copyOffsetSlot())); 31 | addShortcut(X_ID_DISASM_COPY_ADDRESS, this, SLOT(_copyAddressSlot())); 32 | addShortcut(X_ID_DISASM_FIND_STRING, this, SLOT(_findStringSlot())); 33 | addShortcut(X_ID_DISASM_FIND_SIGNATURE, this, SLOT(_findSignatureSlot())); 34 | addShortcut(X_ID_DISASM_FIND_VALUE, this, SLOT(_findValueSlot())); 35 | addShortcut(X_ID_DISASM_FIND_NEXT, this, SLOT(_findNextSlot())); 36 | addShortcut(X_ID_DISASM_SIGNATURE, this, SLOT(_hexSignatureSlot())); 37 | // addShortcut(X_ID_DISASM_FOLLOWIN_HEX, this, SLOT(_mainHexSlot())); 38 | addShortcut(X_ID_DISASM_EDIT_HEX, this, SLOT(_editHex())); 39 | 40 | // TODO click on Address -> Offset 41 | m_nBytesProLine = 1; 42 | 43 | m_disasmOptions = XDisasmAbstract::DISASM_OPTIONS(); 44 | m_viewMethod = VIEWMETHOD_NONE; 45 | m_viewDisasm = VIEWDISASM_COMPACT; 46 | 47 | m_nAddressWidth = 8; 48 | m_nOpcodeSize = 16; // TODO Check 49 | m_nThisBaseVirtualAddress = 0; 50 | m_nThisBaseDeviceOffset = 0; 51 | m_bIsLocationColon = false; 52 | m_bIsHighlight = false; 53 | // g_opcodeMode = OPCODEMODE_SYMBOLADDRESS; 54 | // g_bytesMode = BYTESMODE_RAW; 55 | 56 | addColumn(""); // Arrows 57 | addColumn(""); // Breakpoints 58 | // addColumn(tr("Address"),0,true); 59 | addColumn(tr("Address"), 0, true); 60 | addColumn(""); // Info 61 | addColumn(tr("Bytes"), 0, true); 62 | addColumn(tr("Opcode"), 0, true); // TODO fix it in _adjustWindow 63 | addColumn(tr("Comment")); 64 | 65 | // setLastColumnStretch(true); 66 | 67 | setTextFont(XOptions::getMonoFont()); 68 | setLocationMode(XBinaryView::LOCMODE_ADDRESS); 69 | 70 | _qTextOptions.setWrapMode(QTextOption::NoWrap); 71 | 72 | setVerticalLinesVisible(false); 73 | } 74 | 75 | XDisasmView::~XDisasmView() 76 | { 77 | } 78 | 79 | void XDisasmView::adjustView() 80 | { 81 | setTextFontFromOptions(XOptions::ID_DISASM_FONT); 82 | 83 | m_bIsHighlight = getGlobalOptions()->getValue(XOptions::ID_DISASM_HIGHLIGHT).toBool(); 84 | m_disasmOptions.bIsUppercase = getGlobalOptions()->getValue(XOptions::ID_DISASM_UPPERCASE).toBool(); 85 | // XBinary::SYNTAX syntax = XBinary::stringToSyntaxId(getGlobalOptions()->getValue(XOptions::ID_DISASM_SYNTAX).toString()); 86 | // XBinary::DM disasmMode = g_options.disasmMode; 87 | m_bIsLocationColon = getGlobalOptions()->getValue(XOptions::ID_DISASM_LOCATIONCOLON).toBool(); 88 | 89 | // g_dmFamily = XBinary::getDisasmFamily(g_options.disasmMode); 90 | 91 | // TODO BP color 92 | 93 | // if (getXInfoDB()) { 94 | // g_pDisasmCore = &(getXInfoDB()->getState(g_options.memoryMapRegion.fileType)->disasmCore); 95 | // } 96 | 97 | // g_pDisasmCore->setMode(disasmMode); 98 | getBinaryView()->getDisasmCore()->setOptions(getGlobalOptions()); 99 | 100 | reload(true); 101 | viewport()->update(); 102 | } 103 | 104 | void XDisasmView::setData(QIODevice *pDevice, const XBinaryView::OPTIONS &options, bool bReload) 105 | { 106 | XDeviceTableView::setData(pDevice, options); 107 | 108 | m_listRecords.clear(); 109 | 110 | // setDevice(pDevice, 0, -1); // TODO 111 | // setMode(options.fileType, options.disasmMode, true); 112 | // // setMemoryMap(g_options.memoryMapRegion); 113 | 114 | // if (m_options.disasmMode == XBinary::DM_UNKNOWN) { 115 | // m_options.disasmMode = XBinary::getDisasmMode(getMemoryMap()); 116 | // } 117 | 118 | adjustView(); 119 | 120 | adjustColumns(); 121 | adjustScrollCount(); 122 | 123 | if (options.nInitAddress != (XADDR)-1) { 124 | // qint64 nOffset = XBinary::addressToOffset(getMemoryMap(), options.nInitAddress); 125 | 126 | // if (nOffset == -1) { 127 | // nOffset = 0; 128 | // } 129 | 130 | // _goToViewPos(nOffset, false, false, options.bAprox); 131 | goToAddress(options.nInitAddress, false, options.bAprox, false); 132 | // addVisited(options.nInitAddress); 133 | } else { 134 | // addVisited(0); 135 | } 136 | 137 | if (bReload) { 138 | reload(true); 139 | } 140 | } 141 | 142 | void XDisasmView::setViewMethod(VIEWMETHOD viewMethod) 143 | { 144 | m_viewMethod = viewMethod; 145 | 146 | if (viewMethod == VIEWMETHOD_ANALYZED) { 147 | if (getXInfoDB()) { 148 | // if (!getXInfoDB()->isAnalyzed(g_options.memoryMapRegion.fileType)) { 149 | // analyzeAll(); 150 | // } 151 | } 152 | } 153 | 154 | adjustAfterAnalysis(); 155 | } 156 | 157 | void XDisasmView::setViewDisasm(VIEWDISASM viewDisasm) 158 | { 159 | m_viewDisasm = viewDisasm; 160 | 161 | adjustColumns(); 162 | adjust(); 163 | viewport()->update(); 164 | } 165 | 166 | XBinary::DM XDisasmView::getDisasmMode() 167 | { 168 | return getBinaryView()->getDisasmCore()->getDisasmMode(); 169 | } 170 | 171 | XADDR XDisasmView::getSelectionInitAddress() 172 | { 173 | XADDR nResult = -1; 174 | 175 | qint64 nOffset = getSelectionInitOffset(); 176 | 177 | if (nOffset != -1) { 178 | nResult = XBinary::offsetToAddress(getBinaryView()->getMemoryMap(), nOffset); 179 | } 180 | 181 | return nResult; 182 | } 183 | 184 | XDeviceTableView::DEVICESTATE XDisasmView::getDeviceState(bool bGlobalOffset) 185 | { 186 | // DEVICESTATE result = {}; 187 | 188 | // if (isAnalyzed()) { 189 | // // TODO 190 | // STATE state = getState(); 191 | 192 | // if (state.nSelectionViewSize == 0) { 193 | // state.nSelectionViewSize = 1; 194 | // } 195 | 196 | // qint64 nShowOffset = getViewPosStart(); // TODO convert 197 | 198 | // // XInfoDB::SHOWRECORD showRecordCursor = getXInfoDB()->getShowRecordByLine(state.nCursorViewPos); 199 | // XInfoDB::SHOWRECORD showRecordStartSelection = getXInfoDB()->getShowRecordByLine(state.nSelectionViewPos); 200 | // XInfoDB::SHOWRECORD showRecordEndSelection = getXInfoDB()->getShowRecordByLine(state.nSelectionViewPos + state.nSelectionViewSize - 1); 201 | // XInfoDB::SHOWRECORD showRecordShowStart = getXInfoDB()->getShowRecordByLine(nShowOffset); 202 | 203 | // // if (showRecordCursor.nOffset != -1 ) { 204 | // // result.nCursorOffset = showRecordCursor.nOffset; 205 | // // } 206 | 207 | // XADDR nStartSelectionAddress = showRecordStartSelection.nAddress; 208 | // qint64 nSelectionSize = showRecordEndSelection.nAddress + showRecordEndSelection.nSize - nStartSelectionAddress; 209 | 210 | // if (!getXInfoDB()->isAnalyzedRegionVirtual(nStartSelectionAddress, nSelectionSize)) { 211 | // result.nSelectionLocation = showRecordStartSelection.nOffset; 212 | // result.nSelectionSize = nSelectionSize; 213 | // } 214 | 215 | // if (showRecordShowStart.nOffset == -1) { 216 | // result.nShowLocation = getXInfoDB()->getShowRecordPrevOffsetByAddress(showRecordShowStart.nAddress); 217 | // } else { 218 | // result.nShowLocation = showRecordShowStart.nOffset; 219 | // } 220 | 221 | // if (bGlobalOffset) { 222 | // XIODevice *pSubDevice = dynamic_cast(getDevice()); 223 | 224 | // if (pSubDevice) { 225 | // quint64 nInitOffset = pSubDevice->getInitLocation(); 226 | // result.nSelectionLocation += nInitOffset; 227 | // // result.nCursorOffset += nInitOffset; 228 | // result.nShowLocation += nInitOffset; 229 | // } 230 | // } 231 | // } else { 232 | // DEVICESTATE result = {}; 233 | // STATE state = getState(); 234 | 235 | // result.nSelectionLocation = viewPosToDeviceOffset(state.nSelectionViewPos, bGlobalOffset); 236 | // result.nSelectionSize = state.nSelectionViewSize; // TODO Check 237 | // result.nShowLocation = viewPosToDeviceOffset(state.nSelectionViewPos, bGlobalOffset); 238 | 239 | // return result; 240 | // } 241 | 242 | // return result; 243 | DEVICESTATE result = {}; 244 | STATE state = getState(); 245 | 246 | result.nSelectionDeviceOffset = getBinaryView()->viewPosToDeviceOffset(state.nSelectionViewPos); 247 | result.nStartDeviceOffset = getBinaryView()->viewPosToDeviceOffset(getViewPosStart()); 248 | 249 | if (result.nSelectionDeviceOffset != (quint64)-1) { 250 | result.nSelectionSize = state.nSelectionViewSize; 251 | // TODO if virtual region return 0 252 | } 253 | 254 | return result; 255 | } 256 | 257 | void XDisasmView::setDeviceState(const DEVICESTATE &deviceState, bool bGlobalOffset) 258 | { 259 | _goToViewPos(getBinaryView()->deviceOffsetToViewPos(deviceState.nStartDeviceOffset)); 260 | _initSetSelection(getBinaryView()->deviceOffsetToViewPos(deviceState.nSelectionDeviceOffset), deviceState.nSelectionSize); 261 | 262 | adjust(); 263 | viewport()->update(); 264 | } 265 | 266 | // qint64 XDisasmView::deviceOffsetToViewPos(qint64 nOffset, bool bGlobalOffset) 267 | // { 268 | // qint64 nResult = 0; 269 | 270 | // // if (isAnalyzed()) { 271 | // // qint64 _nOffset = XDeviceTableView::deviceOffsetToViewPos(nOffset, bGlobalOffset); 272 | 273 | // // nResult = getXInfoDB()->getShowRecordLineByOffset(_nOffset); 274 | // // } else { 275 | // // nResult = XDeviceTableView::deviceOffsetToViewPos(nOffset, bGlobalOffset); 276 | // // } 277 | // qint64 _nOffset = XDeviceTableView::deviceOffsetToViewPos(nOffset, bGlobalOffset); 278 | 279 | // VIEWSTRUCT viewStruct = _getViewStructByOffset(_nOffset); 280 | 281 | // if (viewStruct.nSize) { 282 | // nResult = viewStruct.nViewPos + (nOffset - viewStruct.nOffset); 283 | // } 284 | 285 | // return nResult; 286 | // } 287 | 288 | // qint64 XDisasmView::deviceSizeToViewSize(qint64 nOffset, qint64 nSize, bool bGlobalOffset) 289 | // { 290 | // Q_UNUSED(bGlobalOffset) 291 | 292 | // qint64 nResult = 0; 293 | 294 | // // if (isAnalyzed()) { 295 | // // qint64 _nOffsetStart = XDeviceTableView::deviceOffsetToViewPos(nOffset, bGlobalOffset); 296 | // // qint64 _nOffsetEnd = XDeviceTableView::deviceOffsetToViewPos(nOffset + nSize, bGlobalOffset); 297 | 298 | // // nResult = getXInfoDB()->getShowRecordLineByOffset(_nOffsetEnd) - getXInfoDB()->getShowRecordLineByOffset(_nOffsetStart); 299 | 300 | // // nResult = nResult + 1; 301 | // // } else { 302 | // // nResult = XDeviceTableView::deviceOffsetToViewPos(nOffset, nSize); 303 | // // } 304 | 305 | // nResult = XDeviceTableView::deviceSizeToViewSize(nOffset, nSize); 306 | 307 | // return nResult; 308 | // } 309 | 310 | // qint64 XDisasmView::viewPosToDeviceOffset(qint64 nViewPos, bool bGlobalOffset) 311 | // { 312 | // qint64 nResult = -1; 313 | 314 | // VIEWSTRUCT viewStruct = _getViewStructByViewPos(nViewPos); 315 | 316 | // if (viewStruct.nSize && (viewStruct.nOffset != -1)) { 317 | // nResult = viewStruct.nOffset + (nViewPos - viewStruct.nViewPos); 318 | // nResult = XDeviceTableView::viewPosToDeviceOffset(nResult, bGlobalOffset); 319 | // } 320 | 321 | // return nResult; 322 | // } 323 | 324 | void XDisasmView::adjustScrollCount() 325 | { 326 | setTotalScrollCount(getBinaryView()->getViewSize()); 327 | } 328 | 329 | qint64 XDisasmView::getViewSizeByViewPos(qint64 nViewPos) 330 | { 331 | return 1; 332 | } 333 | 334 | QString XDisasmView::convertOpcodeString(const XDisasmAbstract::DISASM_RESULT &disasmResult) 335 | { 336 | // TODO remove, move to XInfoDB 337 | QString sResult; 338 | 339 | if (getXInfoDB()) { 340 | XInfoDB::RI_TYPE riType = XInfoDB::RI_TYPE_SYMBOLADDRESS; 341 | sResult = getXInfoDB()->convertOpcodeString(disasmResult, riType, m_disasmOptions); 342 | } 343 | 344 | if (sResult == "") { 345 | sResult = disasmResult.sOperands; 346 | } 347 | 348 | return sResult; 349 | } 350 | 351 | qint64 XDisasmView::getDisasmViewPos(qint64 nViewPos, qint64 nOldViewPos) 352 | { 353 | qint64 nResult = nViewPos; 354 | 355 | if (nViewPos != nOldViewPos) { 356 | if (nOldViewPos == -1) { 357 | nOldViewPos = nViewPos; 358 | } 359 | 360 | XBinaryView::VIEWSTRUCT viewStruct = getBinaryView()->_getViewStructByViewPos(nViewPos); 361 | 362 | if (m_viewMethod == VIEWMETHOD_NONE) { 363 | qint64 nOffset = -1; 364 | 365 | if (viewStruct.nOffset != -1) { 366 | nOffset = viewStruct.nOffset + (nViewPos - viewStruct.nViewPos); 367 | } 368 | 369 | if (nOffset != -1) { 370 | qint64 nStartOffset = 0; 371 | qint64 nEndOffset = 0; 372 | 373 | nStartOffset = nOffset - 5 * m_nOpcodeSize; 374 | nEndOffset = nOffset + 5 * m_nOpcodeSize; 375 | 376 | if (getBinaryView()->getDisasmCore()->getDisasmFamily() == XBinary::DMFAMILY_ARM) // TODO Check 377 | { 378 | nStartOffset = S_ALIGN_DOWN(nStartOffset, 4); 379 | } else if (getBinaryView()->getDisasmCore()->getDisasmFamily() == XBinary::DMFAMILY_ARM64) { 380 | nStartOffset = S_ALIGN_DOWN(nStartOffset, 4); 381 | } else if (getBinaryView()->getDisasmCore()->getDisasmFamily() == XBinary::DMFAMILY_M68K) { 382 | nStartOffset = S_ALIGN_DOWN(nStartOffset, 2); 383 | } else if (getBinaryView()->getDisasmCore()->getDisasmFamily() == XBinary::DMFAMILY_X86) { 384 | // QByteArray _baData = read_array(nStartOffset, 2); // TODO optimize 385 | 386 | // if (*((quint16 *)_baData.data()) == 0) // 0000 387 | // { 388 | // nStartOffset = S_ALIGN_DOWN(nStartOffset, 4); 389 | // } 390 | nStartOffset = S_ALIGN_DOWN(nStartOffset, 4); 391 | } 392 | 393 | nStartOffset = qMax(nStartOffset, viewStruct.nOffset); 394 | nEndOffset = qMin(nEndOffset, viewStruct.nOffset + viewStruct.nSize); 395 | 396 | qint32 nSize = nEndOffset - nStartOffset; 397 | 398 | QByteArray baData = read_array(nStartOffset, nSize); 399 | 400 | nSize = baData.size(); 401 | 402 | qint64 _nCurrentOffset = 0; 403 | qint64 _nResult = 0; 404 | 405 | while (nSize > 0) { 406 | qint64 _nOffset = nStartOffset + _nCurrentOffset; 407 | 408 | XDisasmAbstract::DISASM_RESULT disasmResult = 409 | getBinaryView()->getDisasmCore()->disAsm(baData.data() + _nCurrentOffset, nSize, _nCurrentOffset, m_disasmOptions); 410 | 411 | if ((nOffset >= _nOffset) && (nOffset < _nOffset + disasmResult.nSize)) { 412 | if (_nOffset == nOffset) { 413 | _nResult = _nOffset; 414 | } else { 415 | if (nViewPos > nOldViewPos) { 416 | _nResult = _nOffset + disasmResult.nSize; 417 | } else { 418 | _nResult = _nOffset; 419 | } 420 | } 421 | nResult = viewStruct.nViewPos + (_nResult - viewStruct.nOffset); 422 | 423 | break; 424 | } 425 | 426 | _nCurrentOffset += disasmResult.nSize; 427 | nSize -= disasmResult.nSize; 428 | } 429 | } 430 | } else if (m_viewMethod == VIEWMETHOD_ANALYZED) { 431 | XADDR nAddress = -1; 432 | 433 | if (viewStruct.nAddress != -1) { 434 | nAddress = viewStruct.nAddress + (nViewPos - viewStruct.nViewPos); 435 | } 436 | 437 | if (nAddress != -1) { 438 | if (getXInfoDB()) { 439 | // XInfoDB::STATE *pState = getXInfoDB()->getState(g_options.memoryMapRegion.fileType); 440 | 441 | // if (pState) { 442 | // qint32 nIndex = getXInfoDB()->_searchXRecordByAddress(pState, nAddress, true); 443 | 444 | // if (nIndex != -1) { 445 | // XInfoDB::XRECORD record = pState->listRecords.at(nIndex); 446 | 447 | // if (nViewPos > nOldViewPos) { 448 | // nResult = viewStruct.nViewPos + record.nRelOffset + record.nSize; 449 | // } else { 450 | // nResult = viewStruct.nViewPos + record.nRelOffset; 451 | // } 452 | // } 453 | // } 454 | } 455 | } 456 | } 457 | } 458 | 459 | return nResult; 460 | } 461 | 462 | XDisasmView::MENU_STATE XDisasmView::getMenuState() 463 | { 464 | MENU_STATE result = {}; 465 | 466 | DEVICESTATE deviceState = getDeviceState(); 467 | STATE state = getState(); 468 | 469 | // if(state.nCursorOffset!=XBinary::offsetToAddress(&(g_options.memoryMap),state.nCursorOffset)) 470 | // { 471 | // result.bOffset=true; 472 | // } 473 | 474 | if (deviceState.nSelectionSize) { 475 | result.bPhysicalSize = true; 476 | } 477 | if (state.nSelectionViewSize) { 478 | result.bSize = true; 479 | } 480 | 481 | if (getBinaryView()->getOptions()->bMenu_Hex) { 482 | result.bHex = true; 483 | } 484 | 485 | return result; 486 | } 487 | 488 | void XDisasmView::drawText(QPainter *pPainter, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight, const QString &sText, TEXT_OPTION *pTextOption) 489 | { 490 | QRectF rectText; 491 | 492 | rectText.setLeft(nLeft + getCharWidth()); 493 | rectText.setTop(nTop + getLineDelta()); 494 | rectText.setWidth(nWidth); 495 | rectText.setHeight(nHeight - getLineDelta()); 496 | 497 | bool bSave = false; 498 | 499 | // if (pTextOption->bIsCursor) { 500 | // bSave = true; 501 | // } 502 | 503 | if (bSave) { 504 | pPainter->save(); 505 | } 506 | 507 | if (pTextOption->bIsSelected) { 508 | pPainter->fillRect(nLeft, nTop, nWidth, nHeight, pTextOption->colSelected); 509 | } 510 | 511 | // if (pTextOption->bIsBreakpoint) { 512 | // pPainter->fillRect(nLeft, nTop, nWidth, nHeight, pTextOption->colBreakpoint); 513 | // } else if (pTextOption->bIsAnalysed) { 514 | // pPainter->fillRect(nLeft, nTop, nWidth, nHeight, pTextOption->colAnalyzed); 515 | // } else if (pTextOption->bIsCursor) { 516 | // pPainter->fillRect(nLeft, nTop, nWidth, nHeight, viewport()->palette().color(QPalette::WindowText)); 517 | // pPainter->setPen(viewport()->palette().color(QPalette::Base)); 518 | // } 519 | 520 | pPainter->drawText(rectText, sText, _qTextOptions); 521 | 522 | if (bSave) { 523 | pPainter->restore(); 524 | } 525 | } 526 | 527 | void XDisasmView::drawDisasmText(QPainter *pPainter, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight, const XDisasmAbstract::DISASM_RESULT &disasmResult, 528 | TEXT_OPTION *pTextOption) 529 | { 530 | if (m_bIsHighlight) { 531 | if (pTextOption->bIsSelected) { 532 | pPainter->fillRect(nLeft, nTop, nWidth, nHeight, pTextOption->colSelected); 533 | } 534 | 535 | QRectF rectText; 536 | rectText.setLeft(nLeft + getCharWidth()); 537 | rectText.setTop(nTop + getLineDelta()); 538 | rectText.setWidth(nWidth); 539 | rectText.setHeight(nHeight - getLineDelta()); 540 | 541 | getBinaryView()->getDisasmCore()->drawDisasmText(pPainter, rectText, disasmResult); 542 | // TODO 543 | } else { 544 | QString sText = XDisasmAbstract::getOpcodeFullString(disasmResult); 545 | drawText(pPainter, nLeft, nTop, nWidth, nHeight, sText, pTextOption); 546 | } 547 | } 548 | 549 | void XDisasmView::drawArrowHead(QPainter *pPainter, QPointF pointStart, QPointF pointEnd, bool bIsSelected, bool bIsCond) 550 | { 551 | pPainter->save(); 552 | 553 | QPen pen; 554 | 555 | if (bIsSelected) { 556 | pen.setColor(XOptions::stringToColor(getBinaryView()->getDisasmCore()->getColorRecord(XDisasmCore::OG_ARROWS_SELECTED).sColorMain)); 557 | } else { 558 | pen.setColor(XOptions::stringToColor(getBinaryView()->getDisasmCore()->getColorRecord(XDisasmCore::OG_ARROWS).sColorMain)); 559 | } 560 | 561 | pPainter->setPen(pen); 562 | 563 | QPolygonF arrowHead; 564 | qreal arrowSize = 8; 565 | 566 | QLineF line(pointEnd, pointStart); 567 | 568 | double angle = std::atan2(-line.dy(), line.dx()); 569 | 570 | QPointF arrowP1 = line.p1() + QPointF(sin(angle + M_PI / 3) * arrowSize, cos(angle + M_PI / 3) * arrowSize); 571 | QPointF arrowP2 = line.p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, cos(angle + M_PI - M_PI / 3) * arrowSize); 572 | 573 | arrowHead << line.p1() << arrowP1 << arrowP2; 574 | 575 | pPainter->drawPolygon(arrowHead); 576 | 577 | pPainter->restore(); 578 | 579 | drawArrowLine(pPainter, pointStart, pointEnd, bIsSelected, bIsCond); 580 | } 581 | 582 | void XDisasmView::drawArrowLine(QPainter *pPainter, QPointF pointStart, QPointF pointEnd, bool bIsSelected, bool bIsCond) 583 | { 584 | pPainter->save(); 585 | 586 | QPen pen; 587 | 588 | if (bIsSelected) { 589 | pen.setColor(XOptions::stringToColor(getBinaryView()->getDisasmCore()->getColorRecord(XDisasmCore::OG_ARROWS_SELECTED).sColorMain)); 590 | } else { 591 | pen.setColor(XOptions::stringToColor(getBinaryView()->getDisasmCore()->getColorRecord(XDisasmCore::OG_ARROWS).sColorMain)); 592 | } 593 | 594 | if (bIsCond) { 595 | pen.setStyle(Qt::DotLine); 596 | } 597 | 598 | pPainter->setPen(pen); 599 | pPainter->drawLine(pointStart, pointEnd); 600 | 601 | pPainter->restore(); 602 | } 603 | 604 | void XDisasmView::analyzeAll() 605 | { 606 | _analyzeAll(); 607 | } 608 | 609 | QList XDisasmView::getMenuItems() 610 | { 611 | QList listResult; 612 | 613 | MENU_STATE mstate = getMenuState(); 614 | STATE state = getState(); 615 | XDisasmView::RECORD record = _getRecordByViewPos(&m_listRecords, state.nSelectionViewPos); 616 | 617 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_GOTO_ADDRESS, this, SLOT(_goToAddressSlot()), XShortcuts::GROUPID_GOTO); 618 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_GOTO_OFFSET, this, SLOT(_goToOffsetSlot()), XShortcuts::GROUPID_GOTO); 619 | 620 | { 621 | XShortcuts::MENUITEM menuItem = {}; 622 | 623 | menuItem.nShortcutId = X_ID_DISASM_GOTO_ENTRYPOINT; 624 | menuItem.pRecv = this; 625 | menuItem.pMethod = SLOT(_goToEntryPointSlot()); 626 | menuItem.nSubgroups = XShortcuts::GROUPID_GOTO; 627 | menuItem.sText = QString("0x%1").arg(getBinaryView()->getOptions()->nEntryPointAddress, 0, 16); 628 | 629 | listResult.append(menuItem); 630 | } 631 | 632 | if (record.disasmResult.relType || record.disasmResult.memType) { 633 | getShortcuts()->_addMenuSeparator(&listResult, XShortcuts::GROUPID_GOTO); 634 | 635 | if (record.disasmResult.relType) { 636 | XShortcuts::MENUITEM menuItem = {}; 637 | 638 | menuItem.pRecv = this; 639 | menuItem.pMethod = SLOT(_goToXrefSlot()); 640 | menuItem.nSubgroups = XShortcuts::GROUPID_GOTO; 641 | menuItem.sText = QString("0x%1").arg(record.disasmResult.nXrefToRelative, 0, 16); 642 | menuItem.iconType = XOptions::ICONTYPE_GOTO; 643 | menuItem.sPropertyName = "ADDRESS"; 644 | menuItem.varProperty = record.disasmResult.nXrefToRelative; 645 | 646 | listResult.append(menuItem); 647 | } 648 | 649 | if (record.disasmResult.memType) { 650 | XShortcuts::MENUITEM menuItem = {}; 651 | 652 | menuItem.pRecv = this; 653 | menuItem.pMethod = SLOT(_goToXrefSlot()); 654 | menuItem.nSubgroups = XShortcuts::GROUPID_GOTO; 655 | menuItem.sText = QString("0x%1").arg(record.disasmResult.nXrefToMemory, 0, 16); 656 | menuItem.iconType = XOptions::ICONTYPE_GOTO; 657 | menuItem.sPropertyName = "ADDRESS"; 658 | menuItem.varProperty = record.disasmResult.nXrefToMemory; 659 | 660 | listResult.append(menuItem); 661 | } 662 | } 663 | 664 | if (record.bHasRefFrom) { 665 | XShortcuts::MENUITEM menuItem = {}; 666 | 667 | menuItem.pRecv = this; 668 | menuItem.pMethod = SLOT(_referencesSlot()); 669 | menuItem.nSubgroups = XShortcuts::GROUPID_GOTO; 670 | menuItem.nShortcutId = X_ID_DISASM_GOTO_REFERENCES; 671 | menuItem.sPropertyName = "ADDRESS"; 672 | menuItem.varProperty = record.disasmResult.nAddress; 673 | 674 | listResult.append(menuItem); 675 | } 676 | 677 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_COPY_ADDRESS, this, SLOT(_copyAddressSlot()), XShortcuts::GROUPID_COPY); 678 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_COPY_OFFSET, this, SLOT(_copyOffsetSlot()), XShortcuts::GROUPID_COPY); 679 | 680 | if (mstate.bPhysicalSize) { 681 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_COPY_DATA, this, SLOT(_copyDataSlot()), XShortcuts::GROUPID_COPY); 682 | } 683 | 684 | if ((record.sLocation != "") || (record.sBytes != "") || (record.disasmResult.sMnemonic != "") || (record.sComment != "")) { 685 | getShortcuts()->_addMenuSeparator(&listResult, XShortcuts::GROUPID_COPY); 686 | 687 | if (record.sLocation != "") { 688 | XShortcuts::MENUITEM menuItem = {}; 689 | 690 | menuItem.pRecv = getShortcuts(); 691 | menuItem.pMethod = SLOT(copyRecord()); 692 | menuItem.nSubgroups = XShortcuts::GROUPID_COPY; 693 | menuItem.sText = record.sLocation; 694 | menuItem.sPropertyName = "VALUE"; 695 | menuItem.varProperty = record.sLocation; 696 | 697 | listResult.append(menuItem); 698 | } 699 | 700 | if (record.sBytes != "") { 701 | XShortcuts::MENUITEM menuItem = {}; 702 | 703 | menuItem.pRecv = getShortcuts(); 704 | menuItem.pMethod = SLOT(copyRecord()); 705 | menuItem.nSubgroups = XShortcuts::GROUPID_COPY; 706 | menuItem.sText = record.sBytes; 707 | menuItem.sPropertyName = "VALUE"; 708 | menuItem.varProperty = record.sBytes; 709 | 710 | listResult.append(menuItem); 711 | } 712 | 713 | if (record.disasmResult.sMnemonic != "") { 714 | QString sString = record.disasmResult.sMnemonic; 715 | 716 | if (record.disasmResult.sOperands != "") { 717 | sString.append(QString(" %1").arg(convertOpcodeString(record.disasmResult))); 718 | } 719 | 720 | XShortcuts::MENUITEM menuItem = {}; 721 | 722 | menuItem.pRecv = getShortcuts(); 723 | menuItem.pMethod = SLOT(copyRecord()); 724 | menuItem.nSubgroups = XShortcuts::GROUPID_COPY; 725 | menuItem.sText = sString; 726 | menuItem.sPropertyName = "VALUE"; 727 | menuItem.varProperty = sString; 728 | 729 | listResult.append(menuItem); 730 | } 731 | 732 | if (record.sComment != "") { 733 | XShortcuts::MENUITEM menuItem = {}; 734 | 735 | menuItem.pRecv = getShortcuts(); 736 | menuItem.pMethod = SLOT(copyRecord()); 737 | menuItem.nSubgroups = XShortcuts::GROUPID_COPY; 738 | menuItem.sText = record.sComment; 739 | menuItem.sPropertyName = "VALUE"; 740 | menuItem.varProperty = record.sComment; 741 | 742 | listResult.append(menuItem); 743 | } 744 | } 745 | 746 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_FIND_STRING, this, SLOT(_findStringSlot()), XShortcuts::GROUPID_FIND); 747 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_FIND_SIGNATURE, this, SLOT(_findSignatureSlot()), XShortcuts::GROUPID_FIND); 748 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_FIND_VALUE, this, SLOT(_findValueSlot()), XShortcuts::GROUPID_FIND); 749 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_FIND_NEXT, this, SLOT(_findNextSlot()), XShortcuts::GROUPID_FIND); 750 | 751 | if (mstate.bPhysicalSize) { 752 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_DUMPTOFILE, this, SLOT(_dumpToFileSlot()), XShortcuts::GROUPID_NONE); 753 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_SIGNATURE, this, SLOT(_signatureSlot()), XShortcuts::GROUPID_NONE); 754 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_HEX_SIGNATURE, this, SLOT(_hexSignatureSlot()), XShortcuts::GROUPID_HEX); 755 | } 756 | 757 | if (mstate.bHex) { 758 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_FOLLOWIN_HEX, this, SLOT(_hexSlot()), XShortcuts::GROUPID_FOLLOWIN); 759 | } 760 | 761 | if (!isReadonly()) { 762 | if (mstate.bPhysicalSize) { 763 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_EDIT_HEX, this, SLOT(_editHex()), XShortcuts::GROUPID_EDIT); 764 | } 765 | getShortcuts()->_addMenuItem(&listResult, X_ID_DISASM_EDIT_PATCH, this, SLOT(_editPatch()), XShortcuts::GROUPID_EDIT); 766 | } 767 | 768 | return listResult; 769 | } 770 | 771 | XDisasmView::RECORD XDisasmView::_getRecordByViewPos(QList *pListRecord, qint64 nViewPos) 772 | { 773 | RECORD result = {}; 774 | 775 | qint32 nNumberOfRecords = pListRecord->count(); 776 | 777 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 778 | if (pListRecord->at(i).nViewPos == nViewPos) { 779 | result = pListRecord->at(i); 780 | 781 | break; 782 | } 783 | } 784 | 785 | return result; 786 | } 787 | 788 | XDisasmView::RECORD XDisasmView::_getRecordByVirtualAddress(QList *pListRecord, XADDR nVirtualAddress) 789 | { 790 | RECORD result = {}; 791 | 792 | qint32 nNumberOfRecords = pListRecord->count(); 793 | 794 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 795 | if (pListRecord->at(i).disasmResult.nAddress == nVirtualAddress) { 796 | result = pListRecord->at(i); 797 | 798 | break; 799 | } 800 | } 801 | 802 | return result; 803 | } 804 | 805 | // XDisasmView::VIEWSTRUCT XDisasmView::_getViewStructByScroll(qint64 nValue) 806 | // { 807 | // VIEWSTRUCT result = {}; 808 | 809 | // qint32 nNumberOfRecords = g_listViewStruct.count(); 810 | 811 | // for (qint32 i = 0; i < nNumberOfRecords; i++) { 812 | // if ((g_listViewStruct.at(i).nScrollStart <= nValue) && (nValue < (g_listViewStruct.at(i).nScrollStart + g_listViewStruct.at(i).nScrollCount))) { 813 | // result = g_listViewStruct.at(i); 814 | // break; 815 | // } 816 | // } 817 | 818 | // return result; 819 | // } 820 | 821 | QList XDisasmView::_getTransRecords(qint64 nViewPos, qint64 nSize) 822 | { 823 | QList listResult; 824 | 825 | // qint32 nNumberOfRecords = g_listViewStruct.count(); 826 | 827 | // for (qint32 i = 0; i < nNumberOfRecords; i++) { 828 | // // TODO Check 829 | // if ((((nViewPos + nSize) > g_listViewStruct.at(i).nViewPos) && 830 | // ((g_listViewStruct.at(i).nViewPos >= nViewPos) || ((nViewPos + nSize) < (g_listViewStruct.at(i).nViewPos + g_listViewStruct.at(i).nSize)))) || 831 | // (((g_listViewStruct.at(i).nViewPos + g_listViewStruct.at(i).nSize) > nViewPos) && 832 | // ((nViewPos >= g_listViewStruct.at(i).nViewPos) || ((g_listViewStruct.at(i).nViewPos + g_listViewStruct.at(i).nSize) < (nViewPos + nSize))))) { 833 | // qint64 nNewViewPos = qMax(g_listViewStruct.at(i).nViewPos, nViewPos); 834 | // qint64 nNewViewSize = qMin(g_listViewStruct.at(i).nViewPos + g_listViewStruct.at(i).nSize, nViewPos + nSize) - nNewViewPos; 835 | // qint64 nDelta = nNewViewPos - g_listViewStruct.at(i).nViewPos; 836 | 837 | // XDisasmView::TRANSRECORD record = {}; 838 | // record.nViewPos = nNewViewPos; 839 | // record.nSize = nNewViewSize; 840 | // record.nAddress = g_listViewStruct.at(i).nAddress + nDelta; 841 | // record.nOffset = g_listViewStruct.at(i).nOffset + nDelta; 842 | 843 | // listResult.append(record); 844 | // } 845 | // } 846 | 847 | return listResult; 848 | } 849 | 850 | void XDisasmView::getRecords() 851 | { 852 | m_listRecords.clear(); 853 | 854 | XInfoDB::STATE *pState = 0; 855 | 856 | // if (getXInfoDB() && (m_viewMethod == VIEWMETHOD_ANALYZED)) { 857 | // pState = getXInfoDB()->getState(g_options.memoryMapRegion.fileType); 858 | // } 859 | 860 | XVPOS nViewPosStart = getViewPosStart(); 861 | qint32 nNumberLinesProPage = getLinesProPage(); 862 | XVPOS nCurrentViewPos = nViewPosStart; 863 | 864 | for (qint32 i = 0; i < nNumberLinesProPage; i++) { 865 | if (nCurrentViewPos < getBinaryView()->getViewSize()) { 866 | qint64 nDataSize = 0; 867 | 868 | RECORD record = {}; 869 | record.nViewPos = nCurrentViewPos; 870 | 871 | qint32 nBufferSize = 0; 872 | QByteArray baBuffer; // mb TODO fix buffer 873 | XBinaryView::VIEWSTRUCT viewStruct = getBinaryView()->_getViewStructByViewPos(nCurrentViewPos); 874 | 875 | if (viewStruct.nSize) { 876 | if (viewStruct.nOffset != -1) { 877 | record.nDeviceOffset = viewStruct.nOffset + (nCurrentViewPos - viewStruct.nViewPos); 878 | } else { 879 | record.nDeviceOffset = -1; 880 | } 881 | 882 | XADDR nVirtualAddress = 0; 883 | 884 | if (viewStruct.nAddress != (XADDR)-1) { 885 | nVirtualAddress = viewStruct.nAddress + (nCurrentViewPos - viewStruct.nViewPos); 886 | } else { 887 | nVirtualAddress = -1; 888 | } 889 | 890 | if (record.nDeviceOffset != -1) { 891 | if (m_viewMethod == VIEWMETHOD_NONE) { 892 | nBufferSize = qMin(m_nOpcodeSize, qint32((getDevice()->size()) - record.nDeviceOffset)); 893 | 894 | baBuffer = read_array(record.nDeviceOffset, nBufferSize); 895 | nBufferSize = baBuffer.size(); 896 | 897 | if (nBufferSize == 0) { 898 | break; 899 | } 900 | 901 | record.disasmResult = getBinaryView()->getDisasmCore()->disAsm(baBuffer.data(), baBuffer.size(), nVirtualAddress, m_disasmOptions); 902 | 903 | nBufferSize = record.disasmResult.nSize; 904 | baBuffer.resize(nBufferSize); 905 | record.sBytes = baBuffer.toHex().data(); 906 | 907 | nDataSize = nBufferSize; 908 | } else if (m_viewMethod == VIEWMETHOD_ANALYZED) { 909 | if (pState) { 910 | qint32 nIndex = getXInfoDB()->_searchXRecordByAddress(pState, nVirtualAddress, false); 911 | 912 | if (nIndex != -1) { 913 | XInfoDB::XRECORD showRecord = pState->listRecords.at(nIndex); 914 | nVirtualAddress = XInfoDB::getAddress(pState, showRecord.nRegionIndex, showRecord.nRelOffset); 915 | record.nDeviceOffset = XInfoDB::getOffset(pState, showRecord.nRegionIndex, showRecord.nRelOffset); 916 | 917 | if ((record.nDeviceOffset != -1) && (nVirtualAddress != -1)) { 918 | if (showRecord.nFlags & XInfoDB::XRECORD_FLAG_CODE) { 919 | QByteArray baBuffer = read_array(record.nDeviceOffset, showRecord.nSize); 920 | record.disasmResult = 921 | getBinaryView()->getDisasmCore()->disAsm(baBuffer.data(), baBuffer.size(), nVirtualAddress, m_disasmOptions); 922 | record.sBytes = baBuffer.toHex().data(); 923 | 924 | nDataSize = showRecord.nSize; 925 | } 926 | } 927 | 928 | record.sLabel = QString::number(showRecord.nBranch); 929 | } else { 930 | QByteArray baBuffer = read_array(record.nDeviceOffset, 1); 931 | nDataSize = 1; 932 | record.sBytes = baBuffer.toHex().data(); 933 | record.disasmResult.bIsValid = true; 934 | record.disasmResult.nAddress = nVirtualAddress; 935 | record.disasmResult.nSize = 1; 936 | record.disasmResult.sMnemonic = "db"; 937 | record.disasmResult.sOperands = record.sBytes; 938 | 939 | if (m_disasmOptions.bIsUppercase) { 940 | record.disasmResult.sMnemonic = record.disasmResult.sMnemonic.toUpper(); 941 | record.disasmResult.sOperands = record.disasmResult.sOperands.toUpper(); 942 | } 943 | } 944 | } 945 | } 946 | } else { 947 | nDataSize = 1; 948 | record.sBytes = "?"; 949 | record.disasmResult.bIsValid = true; 950 | record.disasmResult.nAddress = nVirtualAddress; 951 | record.disasmResult.nSize = 1; 952 | record.disasmResult.sMnemonic = "db"; 953 | record.disasmResult.sOperands = "1 dup(?)"; 954 | 955 | if (m_disasmOptions.bIsUppercase) { 956 | record.disasmResult.sMnemonic = record.disasmResult.sMnemonic.toUpper(); 957 | record.disasmResult.sOperands = record.disasmResult.sOperands.toUpper(); 958 | } 959 | } 960 | } else { 961 | nDataSize = 0; 962 | } 963 | 964 | if (nDataSize == 0) { 965 | break; 966 | } 967 | 968 | // if (getXInfoDB()) { 969 | // #ifdef USE_XPROCESS 970 | // record.bIsCurrentIP = (record.nVirtualAddress == nCurrentIP); 971 | // // TODO different colors 972 | // record.breakpointType = getXInfoDB()->findBreakPointByRegion(record.nVirtualAddress, record.disasmResult.nSize).bpType; 973 | // #endif 974 | // } 975 | 976 | // if (record.nVirtualAddress != (XADDR)-1) { 977 | // if (getXInfoDB()) { 978 | // record.sLabel = getXInfoDB()->getSymbolStringByAddress(record.nVirtualAddress); 979 | // } 980 | // } 981 | 982 | // QList listHighLightRegions; 983 | 984 | // if (record.nDeviceOffset != -1) { 985 | // listHighLightRegions = getHighlightRegion(&m_listHighlightsRegion, record.nDeviceOffset, XBinary::LT_OFFSET); 986 | // } 987 | 988 | // if (listHighLightRegions.count()) { 989 | // record.bIsBytesHighlighted = true; 990 | // record.colBytesBackground = listHighLightRegions.at(0).colBackground; 991 | // record.colBytesBackgroundSelected = listHighLightRegions.at(0).colBackgroundSelected; 992 | // } else { 993 | // record.colBytesBackgroundSelected = getColor(TCLOLOR_SELECTED); 994 | // } 995 | 996 | m_listRecords.append(record); 997 | 998 | nCurrentViewPos += nDataSize; 999 | } else { 1000 | break; 1001 | } 1002 | } 1003 | 1004 | setCurrentBlock(nViewPosStart, (nCurrentViewPos - nViewPosStart)); 1005 | } 1006 | 1007 | void XDisasmView::updateArrows() 1008 | { 1009 | qint32 nNumberOfRecords = m_listRecords.count(); 1010 | 1011 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 1012 | if (m_listRecords.at(i).disasmResult.relType) { 1013 | XADDR nXrefTo = m_listRecords.at(i).disasmResult.nXrefToRelative; 1014 | XADDR nCurrentAddress = m_listRecords.at(i).disasmResult.nAddress; 1015 | 1016 | qint32 nStart = 0; 1017 | qint32 nEnd = nNumberOfRecords - 1; 1018 | qint32 nMaxLevel = 0; 1019 | 1020 | if (nCurrentAddress > nXrefTo) { 1021 | nEnd = i; 1022 | 1023 | m_listRecords[i].nArraySize = nEnd; 1024 | 1025 | for (qint32 j = i; j >= nStart; j--) { 1026 | nMaxLevel = qMax(m_listRecords.at(j).nMaxLevel, nMaxLevel); 1027 | 1028 | if ((nXrefTo >= m_listRecords.at(j).disasmResult.nAddress) && 1029 | (nXrefTo < (m_listRecords.at(j).disasmResult.nAddress + m_listRecords.at(j).disasmResult.nSize))) { 1030 | nStart = j; 1031 | m_listRecords[i].nArraySize = nEnd - nStart; 1032 | m_listRecords[i].bIsEnd = true; 1033 | 1034 | break; 1035 | } 1036 | } 1037 | 1038 | m_listRecords[i].array = ARROW_UP; 1039 | } else if (nCurrentAddress < nXrefTo) { 1040 | nStart = i; 1041 | 1042 | m_listRecords[i].nArraySize = nNumberOfRecords - nStart; 1043 | 1044 | for (qint32 j = i; j <= nEnd; j++) { 1045 | nMaxLevel = qMax(m_listRecords.at(j).nMaxLevel, nMaxLevel); 1046 | 1047 | if ((nXrefTo >= m_listRecords.at(j).disasmResult.nAddress) && 1048 | (nXrefTo < (m_listRecords.at(j).disasmResult.nAddress + m_listRecords.at(j).disasmResult.nSize))) { 1049 | nEnd = j; 1050 | m_listRecords[i].nArraySize = nEnd - nStart; 1051 | m_listRecords[i].bIsEnd = true; 1052 | 1053 | break; 1054 | } 1055 | } 1056 | 1057 | m_listRecords[i].array = ARROW_DOWN; 1058 | } 1059 | 1060 | m_listRecords[i].nArrayLevel = nMaxLevel + 1; 1061 | 1062 | for (qint32 j = nStart; j <= nEnd; j++) { 1063 | m_listRecords[j].nMaxLevel = nMaxLevel + 1; 1064 | } 1065 | } 1066 | } 1067 | } 1068 | 1069 | void XDisasmView::updateLocations() 1070 | { 1071 | XBinary::MODE mode = XBinary::getWidthModeFromByteSize(m_nAddressWidth); 1072 | 1073 | qint32 nNumberOfRecords = m_listRecords.count(); 1074 | 1075 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 1076 | if (getlocationMode() == XBinaryView::LOCMODE_THIS) { 1077 | qint64 nDelta = 0; 1078 | XADDR _nCurrent = 0; 1079 | 1080 | if (m_nThisBaseVirtualAddress != (XADDR)-1) { 1081 | _nCurrent = m_listRecords.at(i).disasmResult.nAddress; 1082 | nDelta = (qint64)_nCurrent - (qint64)m_nThisBaseVirtualAddress; 1083 | } else if (m_nThisBaseDeviceOffset != -1) { 1084 | _nCurrent = m_listRecords.at(i).nDeviceOffset; 1085 | nDelta = (qint64)_nCurrent - (qint64)m_nThisBaseDeviceOffset; 1086 | } 1087 | 1088 | m_listRecords[i].sLocation = XBinary::thisToString(nDelta); 1089 | } else if (getlocationMode() == XBinaryView::LOCMODE_ADDRESS) { 1090 | QString sPrefix; 1091 | XADDR _nCurrent = m_listRecords.at(i).disasmResult.nAddress; 1092 | 1093 | if (_nCurrent == (XADDR)-1) { 1094 | sPrefix = QString("%1: ").arg(tr("Offset")); 1095 | _nCurrent = m_listRecords.at(i).nDeviceOffset; 1096 | } 1097 | 1098 | if (m_bIsLocationColon) { 1099 | m_listRecords[i].sLocation = sPrefix + XBinary::valueToHexColon(mode, _nCurrent); 1100 | } else { 1101 | m_listRecords[i].sLocation = sPrefix + XBinary::valueToHex(mode, _nCurrent); 1102 | } 1103 | } else if (getlocationMode() == XBinaryView::LOCMODE_OFFSET) { 1104 | QString sPrefix; 1105 | XADDR _nCurrent = m_listRecords.at(i).nDeviceOffset; 1106 | 1107 | if (_nCurrent == (XADDR)-1) { 1108 | sPrefix = QString("%1: ").arg(tr("Address")); 1109 | _nCurrent = m_listRecords.at(i).disasmResult.nAddress; 1110 | } 1111 | 1112 | if (m_bIsLocationColon) { 1113 | m_listRecords[i].sLocation = sPrefix + XBinary::valueToHexColon(mode, _nCurrent); 1114 | } else { 1115 | m_listRecords[i].sLocation = sPrefix + XBinary::valueToHex(mode, _nCurrent); 1116 | } 1117 | } else if (getlocationMode() == XBinaryView::LOCMODE_RELADDRESS) { 1118 | QString sPrefix; 1119 | QString sSymbol; 1120 | XADDR _nCurrent = 0; 1121 | 1122 | if (m_listRecords.at(i).nDeviceOffset != -1) { 1123 | sPrefix = XBinary::getMemoryRecordInfoByOffset(getBinaryView()->getMemoryMap(), m_listRecords.at(i).nDeviceOffset); 1124 | _nCurrent = m_listRecords.at(i).nDeviceOffset; 1125 | } else if (m_listRecords.at(i).disasmResult.nAddress != (XADDR)-1) { 1126 | sPrefix = XBinary::getMemoryRecordInfoByAddress(getBinaryView()->getMemoryMap(), m_listRecords.at(i).disasmResult.nAddress); 1127 | _nCurrent = m_listRecords.at(i).disasmResult.nAddress; 1128 | } 1129 | 1130 | // if (m_listRecords.at(i).nVirtualAddress != (XADDR)-1) { 1131 | // if (getXInfoDB()) { 1132 | // sSymbol = getXInfoDB()->getSymbolStringByAddress(m_listRecords.at(i).nVirtualAddress); 1133 | // } 1134 | // } 1135 | 1136 | if (m_bIsLocationColon) { 1137 | m_listRecords[i].sLocation = XBinary::valueToHexColon(mode, _nCurrent); 1138 | } else { 1139 | m_listRecords[i].sLocation = XBinary::valueToHex(mode, _nCurrent); 1140 | } 1141 | 1142 | if (sPrefix != "") { 1143 | m_listRecords[i].sLocation = QString("%1:%2").arg(sPrefix, m_listRecords.at(i).sLocation); 1144 | } 1145 | 1146 | if (sSymbol != "") { 1147 | m_listRecords[i].sLocation = QString("%1.%2").arg(m_listRecords.at(i).sLocation, sSymbol); 1148 | } 1149 | } 1150 | } 1151 | } 1152 | 1153 | XAbstractTableView::OS XDisasmView::cursorPositionToOS(const XAbstractTableView::CURSOR_POSITION &cursorPosition) 1154 | { 1155 | OS osResult = {}; 1156 | osResult.nViewPos = -1; 1157 | 1158 | if ((cursorPosition.bIsValid) && (cursorPosition.ptype == PT_CELL)) { 1159 | if (cursorPosition.nRow < m_listRecords.count()) { 1160 | qint64 nBlockOffset = m_listRecords.at(cursorPosition.nRow).nViewPos; 1161 | qint64 nBlockSize = 0; 1162 | 1163 | // if (m_viewMethod == VIEWMETHOD_NONE) { 1164 | // nBlockSize = m_listRecords.at(cursorPosition.nRow).disasmResult.nSize; 1165 | // } else if (m_viewMethod == VIEWMETHOD_ANALYZED) { 1166 | // nBlockSize = 1; 1167 | // } 1168 | nBlockSize = m_listRecords.at(cursorPosition.nRow).disasmResult.nSize; 1169 | // nBlockSize = 1; 1170 | 1171 | osResult.nViewPos = nBlockOffset; 1172 | osResult.nSize = nBlockSize; 1173 | } else { 1174 | if (!isViewPosValid(osResult.nViewPos)) { 1175 | osResult.nViewPos = getBinaryView()->getViewSize(); // TODO Check 1176 | osResult.nSize = 0; 1177 | } 1178 | } 1179 | } 1180 | 1181 | return osResult; 1182 | } 1183 | 1184 | void XDisasmView::updateData() 1185 | { 1186 | // g_listArrows.clear(); 1187 | 1188 | if (getDevice()) { 1189 | // QList listShowRecords; 1190 | 1191 | // if (isAnalyzed()) { 1192 | // listShowRecords = getXInfoDB()->getShowRecords(nViewPosStart, nNumberLinesProPage); 1193 | // nNumberLinesProPage = qMin(nNumberLinesProPage, listShowRecords.count()); 1194 | // } 1195 | #ifdef USE_XPROCESS 1196 | XADDR nCurrentIP = 0; 1197 | #endif 1198 | if (getXInfoDB()) { 1199 | #ifdef USE_XPROCESS 1200 | nCurrentIP = getXInfoDB()->getCurrentInstructionPointerCache(); 1201 | qDebug("Current IP %s", XBinary::valueToHex(nCurrentIP).toLatin1().data()); 1202 | #endif 1203 | } 1204 | 1205 | // m_listHighlightsRegion.clear(); // TODO 1206 | // if (getXInfoDB()) { 1207 | // QList listTransRecords = _getTransRecords(nViewPosStart, nNumberLinesProPage * 16); // TODO 16 const 1208 | 1209 | // qint32 nNumberOfTransRecords = listTransRecords.count(); 1210 | 1211 | // for (qint32 i = 0; i < nNumberOfTransRecords; i++) { 1212 | // QList listBookMarks; 1213 | 1214 | // if (listTransRecords.at(i).nOffset != -1) { 1215 | // listBookMarks = getXInfoDB()->getBookmarkRecords(listTransRecords.at(i).nOffset, XBinary::LT_OFFSET, listTransRecords.at(i).nSize); 1216 | // } 1217 | 1218 | // m_listHighlightsRegion.append(_convertBookmarksToHighlightRegion(&listBookMarks)); 1219 | // } 1220 | // } 1221 | 1222 | getRecords(); 1223 | updateLocations(); 1224 | updateArrows(); 1225 | } 1226 | } 1227 | 1228 | void XDisasmView::paintColumn(QPainter *pPainter, qint32 nColumn, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight) 1229 | { 1230 | Q_UNUSED(nHeight) 1231 | 1232 | qint32 nArrowDelta = 0; 1233 | 1234 | if (nColumn == COLUMN_ARROWS) { 1235 | qint32 nNumberOfRecords = m_listRecords.count(); 1236 | 1237 | if (nNumberOfRecords) { 1238 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 1239 | if ((m_listRecords.at(i).disasmResult.relType == XDisasmAbstract::RELTYPE_JMP) || 1240 | (m_listRecords.at(i).disasmResult.relType == XDisasmAbstract::RELTYPE_JMP_COND) || 1241 | (m_listRecords.at(i).disasmResult.relType == XDisasmAbstract::RELTYPE_JMP_UNCOND)) { 1242 | bool bIsSelected = isViewPosSelected(m_listRecords.at(i).nViewPos); 1243 | bool bIsCond = (m_listRecords.at(i).disasmResult.relType == XDisasmAbstract::RELTYPE_JMP_COND); 1244 | 1245 | QPointF point1; 1246 | point1.setX(nLeft + nWidth - nArrowDelta); 1247 | point1.setY(nTop + ((i + 0.5) * getLineHeight())); 1248 | 1249 | QPointF point2; 1250 | point2.setX((nLeft + nWidth - nArrowDelta) - getCharWidth() * (m_listRecords.at(i).nArrayLevel)); 1251 | point2.setY(point1.y()); 1252 | 1253 | QPointF point3; 1254 | 1255 | point3.setX(point2.x()); 1256 | 1257 | qint32 nDelta = getLineHeight() * m_listRecords.at(i).nArraySize; 1258 | 1259 | if (!(m_listRecords.at(i).bIsEnd)) { 1260 | nDelta += 0.5 * getLineHeight(); 1261 | } 1262 | 1263 | if (m_listRecords.at(i).array == ARROW_UP) { 1264 | point3.setY(point1.y() - nDelta); 1265 | } else if (m_listRecords.at(i).array == ARROW_DOWN) { 1266 | point3.setY(point1.y() + nDelta); 1267 | } 1268 | 1269 | drawArrowLine(pPainter, point1, point2, bIsSelected, bIsCond); 1270 | 1271 | if (m_listRecords.at(i).bIsEnd) { 1272 | drawArrowLine(pPainter, point2, point3, bIsSelected, bIsCond); 1273 | 1274 | QPointF point4; 1275 | point4.setX(point1.x()); 1276 | point4.setY(point3.y()); 1277 | 1278 | drawArrowHead(pPainter, point3, point4, bIsSelected, bIsCond); 1279 | } else { 1280 | drawArrowHead(pPainter, point2, point3, bIsSelected, bIsCond); 1281 | } 1282 | } 1283 | } 1284 | } 1285 | } else if (nColumn == COLUMN_LABEL) { 1286 | // TODO 1287 | } 1288 | } 1289 | 1290 | void XDisasmView::paintCell(QPainter *pPainter, qint32 nRow, qint32 nColumn, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight) 1291 | { 1292 | qint32 nNumberOfRows = m_listRecords.count(); 1293 | 1294 | // qint64 nCursorOffset = getState().nCursorViewPos; 1295 | 1296 | if (nRow < nNumberOfRows) { 1297 | qint64 nOffset = m_listRecords.at(nRow).nViewPos; 1298 | 1299 | bool bIsDebugger = false; 1300 | // bool bIsCurrentIP = false; 1301 | // bool bIsBreakpoint = false; 1302 | 1303 | if (getXInfoDB()) { 1304 | if (nColumn == COLUMN_BREAKPOINT) { 1305 | #ifdef USE_XPROCESS 1306 | bIsDebugger = getXInfoDB()->isDebugger(); 1307 | // XADDR nAddress = m_listRecords.at(nRow).disasmResult.nAddress; 1308 | // XADDR nCurrentIP = getXInfoDB()->getCurrentInstructionPointerCache(); 1309 | 1310 | // bIsCurrentIP = ((nCurrentIP != -1) && (nAddress == nCurrentIP)); 1311 | // bIsBreakpoint = getXInfoDB()->isBreakPointPresent(nAddress); 1312 | #endif 1313 | } 1314 | } 1315 | 1316 | TEXT_OPTION textOption = {}; 1317 | 1318 | // if (nColumn == COLUMN_BYTES) { 1319 | 1320 | // } 1321 | 1322 | if (isViewPosSelected(nOffset)) { 1323 | textOption.bIsSelected = true; 1324 | 1325 | if (m_listRecords.at(nRow).bIsBytesHighlighted && (nColumn == COLUMN_BYTES)) { 1326 | textOption.colSelected = m_listRecords.at(nRow).colBytesBackgroundSelected; 1327 | } else { 1328 | textOption.colSelected = getColor(TCLOLOR_SELECTED); 1329 | } 1330 | } 1331 | #ifdef USE_XPROCESS 1332 | if ((m_listRecords.at(nRow).bIsCurrentIP) && (nColumn == COLUMN_LOCATION)) { 1333 | textOption.bIsCurrentIP = true; 1334 | } 1335 | 1336 | if ((m_listRecords.at(nRow).breakpointType != XInfoDB::BPT_UNKNOWN) && (nColumn == COLUMN_LOCATION)) { 1337 | textOption.bIsBreakpoint = true; 1338 | textOption.colBreakpoint = getColor(TCLOLOR_BREAKPOINT); 1339 | } 1340 | #endif 1341 | if ((m_listRecords.at(nRow).bIsAnalysed) && (nColumn == COLUMN_OPCODE)) { 1342 | textOption.bIsAnalysed = true; 1343 | textOption.colAnalyzed = getColor(TCLOLOR_ANALYSED); 1344 | } 1345 | 1346 | // textOption.bIsCursor = (nOffset == nCursorOffset) && (nColumn == COLUMN_BYTES); 1347 | 1348 | if (nColumn == COLUMN_BREAKPOINT) { 1349 | if (bIsDebugger) { 1350 | #ifdef USE_XPROCESS 1351 | qint32 _nLeft = nLeft + nWidth - getCharWidth() - getSideDelta(); 1352 | qint32 _nWidth = getCharWidth(); 1353 | qint32 _nHeight = _nWidth; 1354 | qint32 _nTop = nTop + 2; 1355 | 1356 | pPainter->save(); 1357 | 1358 | if (m_listRecords.at(nRow).breakpointType != XInfoDB::BPT_UNKNOWN) { 1359 | // TODO 1360 | pPainter->setBrush(Qt::red); 1361 | pPainter->setPen(Qt::red); 1362 | } else if (m_listRecords.at(nRow).bIsCurrentIP) { 1363 | pPainter->setBrush(Qt::green); // TODO consts 1364 | pPainter->setPen(Qt::green); 1365 | } else { 1366 | pPainter->setBrush(Qt::gray); // TODO consts 1367 | pPainter->setPen(Qt::gray); 1368 | } 1369 | 1370 | pPainter->drawEllipse(QRect(_nLeft, _nTop, _nWidth, _nHeight)); 1371 | pPainter->restore(); 1372 | #endif 1373 | } 1374 | // TODO 1375 | } else if (nColumn == COLUMN_LOCATION) { 1376 | drawText(pPainter, nLeft, nTop, nWidth, nHeight, m_listRecords.at(nRow).sLocation, &textOption); 1377 | } else if (nColumn == COLUMN_LABEL) { 1378 | // QString sInfoText; 1379 | // if (m_listRecords.at(nRow).nInfo) { 1380 | // sInfoText = QString::number(m_listRecords.at(nRow).nInfo); 1381 | // } 1382 | drawText(pPainter, nLeft, nTop, nWidth, nHeight, m_listRecords.at(nRow).sLabel, &textOption); 1383 | } else if (nColumn == COLUMN_BYTES) { 1384 | if (m_listRecords.at(nRow).bIsBytesHighlighted) { 1385 | pPainter->fillRect(nLeft, nTop, nWidth, nHeight, m_listRecords.at(nRow).colBytesBackground); 1386 | } 1387 | 1388 | drawText(pPainter, nLeft, nTop, nWidth, nHeight, m_listRecords.at(nRow).sBytes, &textOption); 1389 | } else if (nColumn == COLUMN_OPCODE) { 1390 | // QString sOpcode = QString("%1|%2").arg(m_listRecords.at(nRow).disasmResult.sMnemonic, convertOpcodeString(m_listRecords.at(nRow).disasmResult)); 1391 | drawDisasmText(pPainter, nLeft, nTop, nWidth, nHeight, m_listRecords.at(nRow).disasmResult, &textOption); 1392 | } else if (nColumn == COLUMN_COMMENT) { 1393 | drawText(pPainter, nLeft, nTop, nWidth, nHeight, m_listRecords.at(nRow).sComment, &textOption); 1394 | } 1395 | } 1396 | } 1397 | 1398 | // void XDisasmView::contextMenu(const QPoint &pos) 1399 | // { 1400 | // if (isContextMenuEnable()) { 1401 | // MENU_STATE mstate = getMenuState(); 1402 | // STATE state = getState(); 1403 | // XDisasmView::RECORD record = _getRecordByViewPos(&m_listRecords, state.nSelectionViewPos); 1404 | 1405 | // QMenu contextMenu(this); // TODO 1406 | 1407 | // QList listMenuItems; 1408 | 1409 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_GOTO_ADDRESS, this, SLOT(_goToAddressSlot()), XShortcuts::GROUPID_GOTO); 1410 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_GOTO_OFFSET, this, SLOT(_goToOffsetSlot()), XShortcuts::GROUPID_GOTO); 1411 | 1412 | // { 1413 | // XShortcuts::MENUITEM menuItem = {}; 1414 | 1415 | // menuItem.nShortcutId = X_ID_DISASM_GOTO_ENTRYPOINT; 1416 | // menuItem.pRecv = this; 1417 | // menuItem.pMethod = SLOT(_goToEntryPointSlot()); 1418 | // menuItem.nSubgroups = XShortcuts::GROUPID_GOTO; 1419 | // menuItem.sText = QString("0x%1").arg(g_options.nEntryPointAddress, 0, 16); 1420 | 1421 | // listMenuItems.append(menuItem); 1422 | // } 1423 | 1424 | // if (record.disasmResult.relType || record.disasmResult.memType) { 1425 | // getShortcuts()->_addMenuSeparator(&listMenuItems, XShortcuts::GROUPID_GOTO); 1426 | 1427 | // if (record.disasmResult.relType) { 1428 | // XShortcuts::MENUITEM menuItem = {}; 1429 | 1430 | // menuItem.pRecv = this; 1431 | // menuItem.pMethod = SLOT(_goToXrefSlot()); 1432 | // menuItem.nSubgroups = XShortcuts::GROUPID_GOTO; 1433 | // menuItem.sText = QString("0x%1").arg(record.disasmResult.nXrefToRelative, 0, 16); 1434 | // menuItem.iconType = XOptions::ICONTYPE_GOTO; 1435 | // menuItem.sPropertyName = "ADDRESS"; 1436 | // menuItem.varProperty = record.disasmResult.nXrefToRelative; 1437 | 1438 | // listMenuItems.append(menuItem); 1439 | // } 1440 | 1441 | // if (record.disasmResult.memType) { 1442 | // XShortcuts::MENUITEM menuItem = {}; 1443 | 1444 | // menuItem.pRecv = this; 1445 | // menuItem.pMethod = SLOT(_goToXrefSlot()); 1446 | // menuItem.nSubgroups = XShortcuts::GROUPID_GOTO; 1447 | // menuItem.sText = QString("0x%1").arg(record.disasmResult.nXrefToMemory, 0, 16); 1448 | // menuItem.iconType = XOptions::ICONTYPE_GOTO; 1449 | // menuItem.sPropertyName = "ADDRESS"; 1450 | // menuItem.varProperty = record.disasmResult.nXrefToMemory; 1451 | 1452 | // listMenuItems.append(menuItem); 1453 | // } 1454 | // } 1455 | 1456 | // if (record.bHasRefFrom) { 1457 | // XShortcuts::MENUITEM menuItem = {}; 1458 | 1459 | // menuItem.pRecv = this; 1460 | // menuItem.pMethod = SLOT(_referencesSlot()); 1461 | // menuItem.nSubgroups = XShortcuts::GROUPID_GOTO; 1462 | // menuItem.nShortcutId = X_ID_DISASM_GOTO_REFERENCES; 1463 | // menuItem.sPropertyName = "ADDRESS"; 1464 | // menuItem.varProperty = record.disasmResult.nAddress; 1465 | 1466 | // listMenuItems.append(menuItem); 1467 | // } 1468 | 1469 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_COPY_ADDRESS, this, SLOT(_copyAddressSlot()), XShortcuts::GROUPID_COPY); 1470 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_COPY_OFFSET, this, SLOT(_copyOffsetSlot()), XShortcuts::GROUPID_COPY); 1471 | 1472 | // if (mstate.bPhysicalSize) { 1473 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_COPY_DATA, this, SLOT(_copyDataSlot()), XShortcuts::GROUPID_COPY); 1474 | // } 1475 | 1476 | // if ((record.sLocation != "") || (record.sBytes != "") || (record.disasmResult.sMnemonic != "") || (record.sComment != "")) { 1477 | // getShortcuts()->_addMenuSeparator(&listMenuItems, XShortcuts::GROUPID_COPY); 1478 | 1479 | // if (record.sLocation != "") { 1480 | // XShortcuts::MENUITEM menuItem = {}; 1481 | 1482 | // menuItem.pRecv = getShortcuts(); 1483 | // menuItem.pMethod = SLOT(copyRecord()); 1484 | // menuItem.nSubgroups = XShortcuts::GROUPID_COPY; 1485 | // menuItem.sText = record.sLocation; 1486 | // menuItem.sPropertyName = "VALUE"; 1487 | // menuItem.varProperty = record.sLocation; 1488 | 1489 | // listMenuItems.append(menuItem); 1490 | // } 1491 | 1492 | // if (record.sBytes != "") { 1493 | // XShortcuts::MENUITEM menuItem = {}; 1494 | 1495 | // menuItem.pRecv = getShortcuts(); 1496 | // menuItem.pMethod = SLOT(copyRecord()); 1497 | // menuItem.nSubgroups = XShortcuts::GROUPID_COPY; 1498 | // menuItem.sText = record.sBytes; 1499 | // menuItem.sPropertyName = "VALUE"; 1500 | // menuItem.varProperty = record.sBytes; 1501 | 1502 | // listMenuItems.append(menuItem); 1503 | // } 1504 | 1505 | // if (record.disasmResult.sMnemonic != "") { 1506 | // QString sString = record.disasmResult.sMnemonic; 1507 | 1508 | // if (record.disasmResult.sOperands != "") { 1509 | // sString.append(QString(" %1").arg(convertOpcodeString(record.disasmResult))); 1510 | // } 1511 | 1512 | // XShortcuts::MENUITEM menuItem = {}; 1513 | 1514 | // menuItem.pRecv = getShortcuts(); 1515 | // menuItem.pMethod = SLOT(copyRecord()); 1516 | // menuItem.nSubgroups = XShortcuts::GROUPID_COPY; 1517 | // menuItem.sText = sString; 1518 | // menuItem.sPropertyName = "VALUE"; 1519 | // menuItem.varProperty = sString; 1520 | 1521 | // listMenuItems.append(menuItem); 1522 | // } 1523 | 1524 | // if (record.sComment != "") { 1525 | // XShortcuts::MENUITEM menuItem = {}; 1526 | 1527 | // menuItem.pRecv = getShortcuts(); 1528 | // menuItem.pMethod = SLOT(copyRecord()); 1529 | // menuItem.nSubgroups = XShortcuts::GROUPID_COPY; 1530 | // menuItem.sText = record.sComment; 1531 | // menuItem.sPropertyName = "VALUE"; 1532 | // menuItem.varProperty = record.sComment; 1533 | 1534 | // listMenuItems.append(menuItem); 1535 | // } 1536 | // } 1537 | 1538 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_FIND_STRING, this, SLOT(_findStringSlot()), XShortcuts::GROUPID_FIND); 1539 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_FIND_SIGNATURE, this, SLOT(_findSignatureSlot()), XShortcuts::GROUPID_FIND); 1540 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_FIND_VALUE, this, SLOT(_findValueSlot()), XShortcuts::GROUPID_FIND); 1541 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_FIND_NEXT, this, SLOT(_findNextSlot()), XShortcuts::GROUPID_FIND); 1542 | 1543 | // if (mstate.bPhysicalSize) { 1544 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_DUMPTOFILE, this, SLOT(_dumpToFileSlot()), XShortcuts::GROUPID_NONE); 1545 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_SIGNATURE, this, SLOT(_signatureSlot()), XShortcuts::GROUPID_NONE); 1546 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_HEX_SIGNATURE, this, SLOT(_hexSignatureSlot()), XShortcuts::GROUPID_HEX); 1547 | // } 1548 | 1549 | // if (mstate.bHex) { 1550 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_FOLLOWIN_HEX, this, SLOT(_hexSlot()), XShortcuts::GROUPID_FOLLOWIN); 1551 | // } 1552 | 1553 | // if (!isReadonly()) { 1554 | // if (mstate.bPhysicalSize) { 1555 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_EDIT_HEX, this, SLOT(_editHex()), XShortcuts::GROUPID_EDIT); 1556 | // } 1557 | // getShortcuts()->_addMenuItem(&listMenuItems, X_ID_DISASM_EDIT_PATCH, this, SLOT(_editPatch()), XShortcuts::GROUPID_EDIT); 1558 | // } 1559 | 1560 | // getShortcuts()->adjustContextMenu(&contextMenu, &listMenuItems); 1561 | 1562 | // contextMenu.exec(pos); 1563 | 1564 | // XOptions::deleteQObjectList(&listObjects); 1565 | 1566 | // return; 1567 | 1568 | // QMenu menuAnalyze(tr("Analyze"), this); 1569 | // QMenu menuBookmarks(tr("Bookmarks"), this); 1570 | // QAction actionAnalyzeAll(tr("All"), this); 1571 | // QAction actionAnalyzeAnalyze(tr("Analyze"), this); 1572 | // QAction actionAnalyzeDisasm(tr("Disasm"), this); 1573 | // QAction actionAnalyzeRemove(tr("Remove"), this); 1574 | // QAction actionAnalyzeSymbols(tr("Symbols"), this); 1575 | // QAction actionAnalyzeFunctions(tr("Functions"), this); 1576 | // QAction actionAnalyzeClear(tr("Clear"), this); 1577 | // QAction actionBookmarkNew(tr("New"), this); 1578 | // QAction actionBookmarkList(tr("List"), this); 1579 | 1580 | // QMenu menuEdit(this); 1581 | // QAction actionEditHex(this); 1582 | 1583 | // if (!(g_options.bHideReadOnly)) { 1584 | // if (mstate.bPhysicalSize) { 1585 | // menuEdit.setEnabled(!isReadonly()); 1586 | // getShortcuts()->adjustMenu(&contextMenu, &menuEdit, XShortcuts::GROUPID_EDIT); 1587 | // getShortcuts()->adjustAction(&menuEdit, &actionEditHex, X_ID_DISASM_EDIT_HEX, this, SLOT(_editHex())); 1588 | // } 1589 | // } 1590 | 1591 | // QMenu menuSelect(this); 1592 | // QAction actionSelectAll(this); 1593 | 1594 | // { 1595 | // getShortcuts()->adjustMenu(&contextMenu, &menuSelect, XShortcuts::GROUPID_SELECT); 1596 | // getShortcuts()->adjustAction(&menuSelect, &actionSelectAll, X_ID_DISASM_SELECT_ALL, this, SLOT(_selectAllSlot())); 1597 | // } 1598 | 1599 | // if ((mstate.bSize) && (getXInfoDB())) { 1600 | // { 1601 | // actionAnalyzeAll.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_ANALYZE_ALL)); 1602 | // connect(&actionAnalyzeAll, SIGNAL(triggered()), this, SLOT(_analyzeAll())); 1603 | // menuAnalyze.addAction(&actionAnalyzeAll); 1604 | // } 1605 | // { 1606 | // menuAnalyze.addSeparator(); 1607 | // } 1608 | // { 1609 | // actionAnalyzeAnalyze.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_ANALYZE_ANALYZE)); 1610 | // connect(&actionAnalyzeAnalyze, SIGNAL(triggered()), this, SLOT(_analyzeAnalyze())); 1611 | // menuAnalyze.addAction(&actionAnalyzeAnalyze); 1612 | // } 1613 | // { 1614 | // actionAnalyzeDisasm.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_ANALYZE_DISASM)); 1615 | // connect(&actionAnalyzeDisasm, SIGNAL(triggered()), this, SLOT(_analyzeDisasm())); 1616 | // menuAnalyze.addAction(&actionAnalyzeDisasm); 1617 | // } 1618 | // { 1619 | // actionAnalyzeRemove.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_ANALYZE_REMOVE)); 1620 | // connect(&actionAnalyzeRemove, SIGNAL(triggered()), this, SLOT(_analyzeRemove())); 1621 | // menuAnalyze.addAction(&actionAnalyzeRemove); 1622 | // } 1623 | // { 1624 | // menuAnalyze.addSeparator(); 1625 | // } 1626 | // { 1627 | // actionAnalyzeSymbols.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_ANALYZE_SYMBOLS)); 1628 | // connect(&actionAnalyzeSymbols, SIGNAL(triggered()), this, SLOT(_analyzeSymbols())); 1629 | // menuAnalyze.addAction(&actionAnalyzeSymbols); 1630 | // } 1631 | // { 1632 | // actionAnalyzeFunctions.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_ANALYZE_FUNCTIONS)); 1633 | // connect(&actionAnalyzeFunctions, SIGNAL(triggered()), this, SLOT(_analyzeFunctions())); 1634 | // menuAnalyze.addAction(&actionAnalyzeFunctions); 1635 | // } 1636 | // { 1637 | // menuAnalyze.addSeparator(); 1638 | // } 1639 | // { 1640 | // actionAnalyzeClear.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_ANALYZE_CLEAR)); 1641 | // connect(&actionAnalyzeClear, SIGNAL(triggered()), this, SLOT(_analyzeClear())); 1642 | // menuAnalyze.addAction(&actionAnalyzeClear); 1643 | // } 1644 | 1645 | // contextMenu.addMenu(&menuAnalyze); 1646 | 1647 | // { 1648 | // actionBookmarkNew.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_BOOKMARKS_NEW)); 1649 | // connect(&actionBookmarkNew, SIGNAL(triggered()), this, SLOT(_bookmarkNew())); 1650 | // } 1651 | // { 1652 | // actionBookmarkList.setShortcut(getShortcuts()->getShortcut(X_ID_DISASM_BOOKMARKS_LIST)); 1653 | // if (getViewWidgetState(VIEWWIDGET_BOOKMARKS)) { 1654 | // actionBookmarkList.setCheckable(true); 1655 | // actionBookmarkList.setChecked(true); 1656 | // } 1657 | // connect(&actionBookmarkList, SIGNAL(triggered()), this, SLOT(_bookmarkList())); 1658 | // } 1659 | 1660 | // menuBookmarks.addAction(&actionBookmarkNew); 1661 | // menuBookmarks.addAction(&actionBookmarkList); 1662 | // contextMenu.addMenu(&menuBookmarks); 1663 | // } 1664 | 1665 | // // TODO reset select 1666 | 1667 | // contextMenu.exec(pos); 1668 | // } 1669 | // } 1670 | 1671 | void XDisasmView::wheelEvent(QWheelEvent *pEvent) 1672 | { 1673 | XAbstractTableView::wheelEvent(pEvent); 1674 | } 1675 | 1676 | void XDisasmView::keyPressEvent(QKeyEvent *pEvent) 1677 | { 1678 | XAbstractTableView::keyPressEvent(pEvent); 1679 | } 1680 | 1681 | XVPOS XDisasmView::getCurrentViewPosFromScroll() 1682 | { 1683 | XVPOS nResult = 0; 1684 | 1685 | qint32 nValue = verticalScrollBar()->value(); 1686 | 1687 | qint64 nMaxValue = getMaxScrollValue(); 1688 | 1689 | if (getTotalScrollCount() > (quint64)nMaxValue) { // TODO a flag for large files 1690 | if (nValue == getMaxScrollValue()) { 1691 | nResult = getBinaryView()->getViewSize() - m_nBytesProLine; 1692 | } else { 1693 | nResult = ((double)nValue / (double)getMaxScrollValue()) * getBinaryView()->getViewSize(); 1694 | } 1695 | } else { 1696 | nResult = (XVPOS)nValue * m_nBytesProLine; 1697 | } 1698 | 1699 | XVPOS _nViewPosStart = getViewPosStart(); 1700 | XVPOS _nResult = getDisasmViewPos(nResult, _nViewPosStart); // TODO Convert 1701 | 1702 | if (_nResult != nResult) { 1703 | nResult = _nResult; 1704 | 1705 | setCurrentViewPosToScroll(nResult); 1706 | } 1707 | 1708 | return nResult; 1709 | } 1710 | 1711 | void XDisasmView::setCurrentViewPosToScroll(XVPOS nViewPos) 1712 | { 1713 | setViewPosStart(nViewPos); // TODO Check 1714 | 1715 | qint32 nValue = 0; 1716 | 1717 | if (getBinaryView()->getViewSize() > (getMaxScrollValue() * m_nBytesProLine)) { 1718 | if (nViewPos == getBinaryView()->getViewSize() - m_nBytesProLine) { 1719 | nValue = getMaxScrollValue(); 1720 | } else { 1721 | nValue = ((double)(nViewPos) / ((double)getBinaryView()->getViewSize())) * (double)getMaxScrollValue(); 1722 | } 1723 | } else { 1724 | nValue = (nViewPos) / m_nBytesProLine; 1725 | } 1726 | 1727 | verticalScrollBar()->setValue(nValue); 1728 | 1729 | // adjust(true); // TODO mb Remove 1730 | } 1731 | 1732 | void XDisasmView::adjustColumns() 1733 | { 1734 | // setColumnEnabled(COLUMN_OFFSET,!(g_options.bHideOffset)); 1735 | 1736 | const QFontMetricsF fm(getTextFont()); 1737 | 1738 | if (XBinary::getWidthModeFromSize(getBinaryView()->getOptions()->nInitAddress + getBinaryView()->getViewSize()) == XBinary::MODE_64) { 1739 | m_nAddressWidth = 16; 1740 | setColumnWidth(COLUMN_LOCATION, 2 * getCharWidth() + fm.boundingRect("00000000:00000000").width()); 1741 | } else { 1742 | m_nAddressWidth = 8; 1743 | setColumnWidth(COLUMN_LOCATION, 2 * getCharWidth() + fm.boundingRect("0000:0000").width()); 1744 | } 1745 | 1746 | if (m_viewDisasm == VIEWDISASM_FULL) { 1747 | QString sBytes; 1748 | 1749 | for (qint32 i = 0; i < m_nOpcodeSize; i++) { 1750 | sBytes += "00"; 1751 | } 1752 | 1753 | setColumnWidth(COLUMN_BYTES, 2 * getCharWidth() + fm.boundingRect(sBytes).width()); 1754 | setColumnWidth(COLUMN_ARROWS, 5 * getCharWidth()); 1755 | setColumnWidth(COLUMN_OPCODE, 40 * getCharWidth()); 1756 | setColumnWidth(COLUMN_COMMENT, 60 * getCharWidth()); 1757 | setColumnWidth(COLUMN_LABEL, 10 * getCharWidth()); 1758 | 1759 | setColumnEnabled(COLUMN_LABEL, true); 1760 | setColumnEnabled(COLUMN_COMMENT, true); 1761 | } else if (m_viewDisasm == VIEWDISASM_COMPACT) { 1762 | setColumnWidth(COLUMN_BYTES, 10 * getCharWidth()); 1763 | setColumnWidth(COLUMN_ARROWS, 2 * getCharWidth()); 1764 | setColumnWidth(COLUMN_OPCODE, 40 * getCharWidth()); 1765 | 1766 | setColumnEnabled(COLUMN_LABEL, false); 1767 | setColumnEnabled(COLUMN_COMMENT, false); 1768 | } 1769 | 1770 | #ifndef USE_XPROCESS 1771 | setColumnEnabled(COLUMN_BREAKPOINT, false); 1772 | #else 1773 | setColumnWidth(COLUMN_BREAKPOINT, 2 * getCharWidth()); 1774 | setColumnEnabled(COLUMN_BREAKPOINT, true); 1775 | #endif 1776 | } 1777 | 1778 | void XDisasmView::_headerClicked(qint32 nColumn) 1779 | { 1780 | if (nColumn == COLUMN_LOCATION) { 1781 | if (getlocationMode() == XBinaryView::LOCMODE_ADDRESS) { 1782 | setColumnTitle(COLUMN_LOCATION, tr("Offset")); 1783 | setLocationMode(XBinaryView::LOCMODE_OFFSET); 1784 | } else if (getlocationMode() == XBinaryView::LOCMODE_OFFSET) { 1785 | setColumnTitle(COLUMN_LOCATION, tr("Relative address")); 1786 | setLocationMode(XBinaryView::LOCMODE_RELADDRESS); 1787 | } else if (getlocationMode() == XBinaryView::LOCMODE_RELADDRESS) { 1788 | setColumnTitle(COLUMN_LOCATION, tr("Address")); 1789 | setLocationMode(XBinaryView::LOCMODE_ADDRESS); 1790 | } else if (getlocationMode() == XBinaryView::LOCMODE_THIS) { 1791 | setColumnTitle(COLUMN_LOCATION, tr("Address")); 1792 | setLocationMode(XBinaryView::LOCMODE_ADDRESS); 1793 | } 1794 | 1795 | adjust(true); 1796 | } else if (nColumn == COLUMN_OPCODE) { 1797 | // QMenu contextMenu(this); // TODO 1798 | // QMenu menuWidth(tr("Width"), this); 1799 | 1800 | // QAction action8(QString("8"), this); 1801 | // action8.setProperty("width", 8); 1802 | // connect(&action8, SIGNAL(triggered()), this, SLOT(changeWidth())); 1803 | // menuWidth.addAction(&action8); 1804 | // QAction action16(QString("16"), this); 1805 | // action16.setProperty("width", 16); 1806 | // connect(&action16, SIGNAL(triggered()), this, SLOT(changeWidth())); 1807 | // menuWidth.addAction(&action16); 1808 | // QAction action32(QString("32"), this); 1809 | // action32.setProperty("width", 32); 1810 | // connect(&action32, SIGNAL(triggered()), this, SLOT(changeWidth())); 1811 | // menuWidth.addAction(&action32); 1812 | 1813 | // contextMenu.addMenu(&menuWidth); 1814 | 1815 | // contextMenu.exec(QCursor::pos()); 1816 | 1817 | // if (g_opcodeMode == OPCODEMODE_SYMBOLADDRESS) { 1818 | // setColumnTitle(COLUMN_OPCODE, tr("Opcode")); 1819 | // g_opcodeMode = OPCODEMODE_ORIGINAL; 1820 | // } else if (g_opcodeMode == OPCODEMODE_ORIGINAL) { 1821 | // setColumnTitle(COLUMN_OPCODE, QString("%1(%2)").arg(tr("Opcode"), tr("Symbol"))); 1822 | // g_opcodeMode = OPCODEMODE_SYMBOL; 1823 | // } else if (g_opcodeMode == OPCODEMODE_SYMBOL) { 1824 | // setColumnTitle(COLUMN_OPCODE, QString("%1(%2)").arg(tr("Opcode"), tr("Address"))); 1825 | // g_opcodeMode = OPCODEMODE_ADDRESS; 1826 | // } else if (g_opcodeMode == OPCODEMODE_ADDRESS) { 1827 | // setColumnTitle(COLUMN_OPCODE, QString("%1(%2->%3)").arg(tr("Opcode"), tr("Symbol"), tr("Address"))); 1828 | // g_opcodeMode = OPCODEMODE_SYMBOLADDRESS; 1829 | // } 1830 | // adjust(true); 1831 | // } else if (nColumn == COLUMN_BYTES) { 1832 | // if (g_bytesMode == BYTESMODE_RAW) { 1833 | // setColumnTitle(COLUMN_BYTES, tr("Label")); 1834 | // g_bytesMode = BYTESMODE_LABEL; 1835 | // } else if (g_bytesMode == BYTESMODE_LABEL) { 1836 | // setColumnTitle(COLUMN_BYTES, tr("Bytes")); 1837 | // g_bytesMode = BYTESMODE_RAW; 1838 | // } 1839 | 1840 | // adjust(true); 1841 | } 1842 | 1843 | XAbstractTableView::_headerClicked(nColumn); 1844 | } 1845 | 1846 | void XDisasmView::_cellDoubleClicked(qint32 nRow, qint32 nColumn) 1847 | { 1848 | if (nColumn == COLUMN_LOCATION) { 1849 | setColumnTitle(COLUMN_LOCATION, ""); 1850 | setLocationMode(XBinaryView::LOCMODE_THIS); 1851 | 1852 | if (nRow < m_listRecords.count()) { 1853 | m_nThisBaseVirtualAddress = m_listRecords.at(nRow).nViewPos; 1854 | m_nThisBaseDeviceOffset = m_listRecords.at(nRow).nDeviceOffset; 1855 | } 1856 | 1857 | adjust(true); 1858 | } else if (nColumn == COLUMN_OPCODE) { 1859 | if (nRow < m_listRecords.count()) { 1860 | XADDR nAddress = -1; 1861 | 1862 | if (m_listRecords.at(nRow).disasmResult.relType) { 1863 | nAddress = m_listRecords.at(nRow).disasmResult.nXrefToRelative; 1864 | } else if (m_listRecords.at(nRow).disasmResult.memType) { 1865 | nAddress = m_listRecords.at(nRow).disasmResult.nXrefToMemory; 1866 | } 1867 | 1868 | if (nAddress != (XADDR)-1) { 1869 | goToAddress(nAddress, true, true, true); 1870 | } 1871 | } 1872 | } 1873 | } 1874 | 1875 | qint64 XDisasmView::getFixViewPos(qint64 nViewPos) 1876 | { 1877 | qint64 nResult = 0; 1878 | 1879 | nResult = getDisasmViewPos(nViewPos, -1); 1880 | 1881 | return nResult; 1882 | } 1883 | 1884 | void XDisasmView::_goToEntryPointSlot() 1885 | { 1886 | goToAddress(getBinaryView()->getOptions()->nEntryPointAddress, false, false, true); 1887 | setFocus(); 1888 | viewport()->update(); 1889 | } 1890 | 1891 | void XDisasmView::_goToXrefSlot() 1892 | { 1893 | QAction *pAction = qobject_cast(sender()); 1894 | 1895 | if (pAction) { 1896 | XADDR nAddress = pAction->property("ADDRESS").toULongLong(); 1897 | 1898 | goToAddress(nAddress, false, false, true); 1899 | setFocus(); 1900 | viewport()->update(); 1901 | } 1902 | } 1903 | 1904 | void XDisasmView::_signatureSlot() 1905 | { 1906 | DEVICESTATE state = getDeviceState(); 1907 | 1908 | if (state.nSelectionSize) { 1909 | DialogMultiDisasmSignature dmds(this); 1910 | dmds.setGlobal(getShortcuts(), getGlobalOptions()); 1911 | dmds.setData(getDevice(), state.nSelectionDeviceOffset, getBinaryView()->getMemoryMap(), getBinaryView()->getDisasmCore()); 1912 | 1913 | dmds.exec(); 1914 | } 1915 | } 1916 | 1917 | void XDisasmView::_hexSlot() 1918 | { 1919 | if (getBinaryView()->getOptions()->bMenu_Hex) { 1920 | DEVICESTATE state = getDeviceState(); 1921 | 1922 | if (state.nSelectionDeviceOffset != (quint64)-1) { 1923 | emit followLocation(state.nSelectionDeviceOffset, XBinary::LT_OFFSET, state.nSelectionSize, XOptions::WIDGETTYPE_HEX); 1924 | } 1925 | } 1926 | } 1927 | 1928 | void XDisasmView::_referencesSlot() 1929 | { 1930 | QAction *pAction = qobject_cast(sender()); 1931 | 1932 | if (pAction) { 1933 | XADDR nAddress = pAction->property("ADDRESS").toULongLong(); 1934 | 1935 | showReferences(nAddress); 1936 | } 1937 | } 1938 | 1939 | void XDisasmView::_analyzeAll() 1940 | { 1941 | // if (getXInfoDB()) { 1942 | // getXInfoDB()->addAddressForAnalyze(); 1943 | // } 1944 | 1945 | _transfer(XInfoDBTransfer::COMMAND_ANALYZEALL); 1946 | } 1947 | 1948 | void XDisasmView::_analyzeAnalyze() 1949 | { 1950 | _transfer(XInfoDBTransfer::COMMAND_ANALYZE); 1951 | } 1952 | 1953 | void XDisasmView::_analyzeSymbols() 1954 | { 1955 | if (getXInfoDB()) { 1956 | #ifdef QT_DEBUG 1957 | qDebug("void XDisasmView::_analyzeSymbols()"); 1958 | #endif 1959 | DialogXSymbols dialogSymbols(this); 1960 | dialogSymbols.setGlobal(getShortcuts(), getGlobalOptions()); 1961 | // dialogSymbols.setData(getXInfoDB(), getXInfoProfile(), XSymbolsWidget::MODE_ALL, true); 1962 | 1963 | connect(&dialogSymbols, SIGNAL(currentSymbolChanged(XADDR, qint64)), this, SLOT(goToAddressSlot(XADDR, qint64))); 1964 | 1965 | XOptions::_adjustStayOnTop(&dialogSymbols, true); 1966 | 1967 | dialogSymbols.exec(); 1968 | } 1969 | } 1970 | 1971 | void XDisasmView::_analyzeFunctions() 1972 | { 1973 | if (getXInfoDB()) { 1974 | #ifdef QT_DEBUG 1975 | qDebug("void XDisasmView::_analyzeFunctions()"); 1976 | #endif 1977 | DialogXSymbols dialogSymbols(this); 1978 | dialogSymbols.setGlobal(getShortcuts(), getGlobalOptions()); 1979 | // dialogSymbols.setData(getXInfoDB(), getXInfoProfile(), XSymbolsWidget::MODE_FUNCTIONS, true); 1980 | 1981 | connect(&dialogSymbols, SIGNAL(currentSymbolChanged(XADDR, qint64)), this, SLOT(goToAddressSlot(XADDR, qint64))); 1982 | 1983 | XOptions::_adjustStayOnTop(&dialogSymbols, true); 1984 | 1985 | dialogSymbols.exec(); 1986 | } 1987 | } 1988 | 1989 | void XDisasmView::_transfer(XInfoDBTransfer::COMMAND command) 1990 | { 1991 | if (getXInfoDB()) { 1992 | STATE state = getState(); 1993 | 1994 | // XADDR nAddress = getAddressByViewPos(state.nSelectionViewPos); // TODO Offsets ??? 1995 | XADDR nAddress = 0; 1996 | 1997 | if (nAddress != (XADDR)-1) { 1998 | XVPOS nViewStart = getViewPosStart(); 1999 | 2000 | XInfoDBTransfer::OPTIONS options = {}; 2001 | options.pDevice = getDevice(); 2002 | 2003 | XInfoDBTransfer infoTransfer; 2004 | XDialogProcess dialogTransfer(this, &infoTransfer); 2005 | dialogTransfer.setGlobal(getShortcuts(), getGlobalOptions()); 2006 | infoTransfer.setData(getXInfoDB(), command, options, dialogTransfer.getPdStruct()); 2007 | dialogTransfer.start(); 2008 | dialogTransfer.showDialogDelay(); 2009 | 2010 | adjustAfterAnalysis(); 2011 | 2012 | setState(state); 2013 | setViewPosStart(nViewStart); 2014 | } 2015 | } 2016 | } 2017 | 2018 | void XDisasmView::showReferences(XADDR nAddress) 2019 | { 2020 | if (getXInfoDB()) { 2021 | #ifdef QT_DEBUG 2022 | qDebug("void XDisasmView::showReferences()"); 2023 | #endif 2024 | DialogXSymbols dialogSymbols(this); 2025 | dialogSymbols.setGlobal(getShortcuts(), getGlobalOptions()); 2026 | // dialogSymbols.setData(getXInfoDB(), getXInfoProfile(), XSymbolsWidget::MODE_REFERENCES, true); 2027 | 2028 | connect(&dialogSymbols, SIGNAL(currentSymbolChanged(XADDR, qint64)), this, SLOT(goToAddressSlot(XADDR, qint64))); 2029 | 2030 | XOptions::_adjustStayOnTop(&dialogSymbols, true); 2031 | 2032 | dialogSymbols.exec(); 2033 | } 2034 | } 2035 | --------------------------------------------------------------------------------