diff options
| author | kat <kat@vector35.com> | 2024-10-28 12:58:23 -0400 |
|---|---|---|
| committer | kat <kat@vector35.com> | 2024-10-28 12:58:51 -0400 |
| commit | fc5ffbbcfbc16402583a9e05d7db3036ad587066 (patch) | |
| tree | 1448f57740483206a1fa688e605724188129ea05 /view/sharedcache | |
| parent | 07bce5f257d30061475452ec9c2e06a132747b54 (diff) | |
[SharedCache] Warnings Cleanup
Diffstat (limited to 'view/sharedcache')
| -rw-r--r-- | view/sharedcache/core/DSCView.cpp | 6 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCache.cpp | 42 | ||||
| -rw-r--r-- | view/sharedcache/ui/dsctriage.cpp | 8 | ||||
| -rw-r--r-- | view/sharedcache/ui/dsctriage.h | 1 | ||||
| -rw-r--r-- | view/sharedcache/ui/dscwidget.cpp | 437 | ||||
| -rw-r--r-- | view/sharedcache/ui/dscwidget.h | 190 |
6 files changed, 26 insertions, 658 deletions
diff --git a/view/sharedcache/core/DSCView.cpp b/view/sharedcache/core/DSCView.cpp index e690f765..7a1b3677 100644 --- a/view/sharedcache/core/DSCView.cpp +++ b/view/sharedcache/core/DSCView.cpp @@ -207,8 +207,7 @@ bool DSCView::Init() if (!settings) { Ref<Settings> programSettings = Settings::Instance(); - programSettings->Set("workflows.enable", true, this); - programSettings->Set("workflows.functionWorkflow", "core.function.dsc", this); + programSettings->Set("analysis.workflows.functionWorkflow", "core.function.dsc", this); } // Add Mach-O file header type info @@ -751,6 +750,7 @@ bool DSCView::Init() } AddAutoSegment(primaryBase, 0x200, 0, 0x200, SegmentReadable); + AddAutoSection("__dsc_header", primaryBase, 0x200, ReadOnlyCodeSectionSemantics); DefineType("dyld_cache_header", headerType.name, headerType.type); DefineAutoSymbolAndVariableOrFunction(GetDefaultPlatform(), new Symbol(DataSymbol, "primary_cache_header", primaryBase), headerType.type); @@ -789,7 +789,7 @@ Ref<Settings> DSCViewType::GetLoadSettingsForData(BinaryView* data) } Ref<Settings> programSettings = Settings::Instance(); - programSettings->Set("workflows.functionWorkflow", "core.function.dsc", viewRef); + programSettings->Set("analysis.workflows.functionWorkflow", "core.function.dsc", viewRef); settings->RegisterSetting("loader.dsc.processCFStrings", R"({ diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index d468ff9a..a597cfb5 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -1341,33 +1341,29 @@ SharedCache::SharedCache(BinaryNinja::Ref<BinaryNinja::BinaryView> dscView) : m_ { if (m_viewState == DSCViewStateUnloaded) { - // maybe we are getting called from UI thread. probably. do this on a separate thread just in case. - // TODO `wait` argument - WorkerEnqueue([this]() { - std::unique_lock<std::mutex> lock(viewSpecificMutexes[m_dscView->GetFile()->GetSessionId()].viewOperationsThatInfluenceMetadataMutex); - try { - PerformInitialLoad(); - } - catch (...) - { - m_logger->LogError("Failed to perform initial load of Shared Cache"); - } + std::unique_lock<std::mutex> lock(viewSpecificMutexes[m_dscView->GetFile()->GetSessionId()].viewOperationsThatInfluenceMetadataMutex); + try { + PerformInitialLoad(); + } + catch (...) + { + m_logger->LogError("Failed to perform initial load of Shared Cache"); + } - for (const auto& [_, header] : m_headers) + for (const auto& [_, header] : m_headers) + { + if (header.installName.find("libsystem_c.dylib") != std::string::npos) { - if (header.installName.find("libsystem_c.dylib") != std::string::npos) - { - lock.unlock(); - m_logger->LogInfo("Loading core libsystem_c.dylib library"); - LoadImageWithInstallName(header.installName); - lock.lock(); - break ; - } + lock.unlock(); + m_logger->LogInfo("Loading core libsystem_c.dylib library"); + LoadImageWithInstallName(header.installName); + lock.lock(); + break ; } + } - m_viewState = DSCViewStateLoaded; - SaveToDSCView(); - }); + m_viewState = DSCViewStateLoaded; + SaveToDSCView(); } } else diff --git a/view/sharedcache/ui/dsctriage.cpp b/view/sharedcache/ui/dsctriage.cpp index 6f931ee6..7680317c 100644 --- a/view/sharedcache/ui/dsctriage.cpp +++ b/view/sharedcache/ui/dsctriage.cpp @@ -478,7 +478,7 @@ void SymbolTableModel::setFilter(std::string text) SymbolTableView::SymbolTableView(QWidget* parent, Ref<SharedCacheAPI::SharedCache> cache) - : m_model(new SymbolTableModel(this)){ + : m_model(new SymbolTableModel(this)) { // Set up the filter model setModel(m_model); @@ -631,7 +631,7 @@ DSCTriageView::DSCTriageView(QWidget* parent, BinaryViewRef data) : QWidget(pare containerWidget->addWidget(cacheInfo); - QWidget* defaultWidget; + QWidget* defaultWidget = nullptr; // check for alpha popup qsetting QSettings settings; @@ -687,7 +687,7 @@ Contributions are always welcome! </p> auto loadImageModel = new QStandardItemModel(0, 2, loadImageTable); { connect( - cacheBlocksView, &DSCCacheBlocksView::loadDone, [this, loadImageModel, cacheInfo]() + cacheBlocksView, &DSCCacheBlocksView::loadDone, [this, loadImageModel]() { for (const auto& img : m_cache->GetImages()) { @@ -706,7 +706,7 @@ Contributions are always welcome! </p> auto loadImageButton = new CustomStyleFlatPushButton(); { connect(loadImageButton, &QPushButton::clicked, - [this, loadImageTable, cacheInfo, mappingModel, sectionModel](bool) { + [this, loadImageTable](bool) { auto selected = loadImageTable->selectionModel()->selectedRows(); if (selected.size() == 0) { diff --git a/view/sharedcache/ui/dsctriage.h b/view/sharedcache/ui/dsctriage.h index a0460e63..39f06ce7 100644 --- a/view/sharedcache/ui/dsctriage.h +++ b/view/sharedcache/ui/dsctriage.h @@ -268,7 +268,6 @@ class DSCTriageView : public QWidget, public View DockableTabCollection* m_triageCollection; SplitTabWidget* m_bottomRegionTabs; - QTimer* m_tabLayoutTimer; DockableTabCollection* m_bottomRegionCollection; std::vector<SharedCacheAPI::SharedCacheMachOHeader> m_headers; diff --git a/view/sharedcache/ui/dscwidget.cpp b/view/sharedcache/ui/dscwidget.cpp deleted file mode 100644 index adece165..00000000 --- a/view/sharedcache/ui/dscwidget.cpp +++ /dev/null @@ -1,437 +0,0 @@ -// -// by kat // 9/15/22. -// - -// CURRENTLY UNUSED CODE - -#include "dscwidget.h" - -#include "ui/viewframe.h" -#include "ui/progresstask.h" - -#include <QtCore/QMimeData> -#include <QtWidgets/QHeaderView> -#include <QtWidgets/QVBoxLayout> -#include <filesystem> -#include <QtWidgets> - -namespace fs = std::filesystem; - - -/// Format an address as hexadecimal. Does not include leading '0x' prefix. -QString formatAddress(uint64_t address) -{ - return QString::number(address, 16).rightJustified(8, '0'); -}; - -//===-- DSCContentsModelItem ------------------------------------------------===// - -DSCContentsModelItem::DSCContentsModelItem(DSCContentsModelItem* parent) : DSCContentsModelItem(nullptr, {}, {}, parent) -{} - -DSCContentsModelItem::DSCContentsModelItem( - BinaryViewRef view, std::string name, std::string installName, DSCContentsModelItem* parent) : - m_bv(view), - m_name(name), m_installName(installName), m_parent(parent) -{ - if (!installName.empty()) - m_type = ImageModelItem; - else - m_type = FolderModelItem; -} - -QString DSCContentsModelItem::displayName() const -{ - return QString::fromStdString(m_name); -} - -size_t DSCContentsModelItem::childCount() const -{ - return m_children.size(); -} - -DSCContentsModelItem* DSCContentsModelItem::child(size_t index) -{ - if (index < 0 || index >= m_children.size()) - return nullptr; - - return m_children[index]; -} - -void DSCContentsModelItem::addChild(DSCContentsModelItem* item) -{ - item->m_parent = this; - m_children.push_back(item); -} - -DSCContentsModelItem* DSCContentsModelItem::parent() const -{ - return m_parent; -} - -size_t DSCContentsModelItem::row() const -{ - if (!m_parent) - return 0; - auto it = std::find(m_parent->m_children.begin(), m_parent->m_children.end(), this); - return it - m_parent->m_children.begin(); -} - -QVariant DSCContentsModelItem::data(int column) const -{ - switch (column) - { - case DSCContentsModel::NameColumn: - return displayName(); - - default: - return QVariant(); - } -} - -QImage DSCContentsModelItem::icon() const -{ - auto kind = data(DSCContentsModel::KindColumn).toString(); - auto icon = QImage(":/icons/images/ComponentTree_" + kind + ".png"); - - return icon.scaled(16, 16, Qt::KeepAspectRatio); -} - -//===-- DSCContentsModel ----------------------------------------------------===// - -DSCContentsModel::DSCContentsModel(BinaryViewRef bv, QObject* parent) : QAbstractItemModel(parent), m_bv(bv) -{ - m_cache = new SharedCacheAPI::SharedCache(bv); - refresh(); -} - -struct ItemNode -{ - ItemNode* parent = nullptr; - std::string fullPath; - std::string path; - DSCContentsModelItem* assignedModelItem = nullptr; - std::unordered_map<std::string, ItemNode*> edges {}; -}; - -std::vector<std::string> split(std::string str, std::string token) -{ - std::vector<std::string> result; - while (str.size()) - { - int index = str.find(token); - if (index != std::string::npos) - { - result.push_back(str.substr(0, index)); - str = str.substr(index + token.size()); - if (str.size() == 0) - result.push_back(str); - } - else - { - result.push_back(str); - str = ""; - } - } - return result; -} - -void DSCContentsModel::refresh() -{ - std::scoped_lock<std::mutex> lock(m_updateMutex); - - // Using `{begin,end}ResetModel` here is not ideal and is a temporary - // hack at best. Actual model indices should be updated. That requires - // more work and will be implemented after more important things have - // been taken care of. - beginResetModel(); - - auto inames = m_cache->GetAvailableImages(); - - m_root = new DSCContentsModelItem(); - - std::unordered_map<std::string, DSCContentsModelItem*> folders {}; - folders["/"] = m_root; - for (const auto& iname : inames) - { - auto pathItems = split(iname, "/"); - pathItems.pop_back(); // skip filenames - std::string fullPath = "/"; - - for (const auto& item : pathItems) - { - if (item.empty()) - continue; - auto parentPath = fullPath; - fullPath += item + "/"; - if (folders.count(fullPath) == 0) - { - auto pnode = folders.at(parentPath); - auto* nnode = new DSCContentsModelItem(m_bv, item, "", pnode); - pnode->addChild(nnode); - folders[fullPath] = nnode; - } - } - } - - // Ok, all our folders are in place. Put files in them. - - for (const auto& iname : inames) - { - auto file = fs::path(iname).filename().string(); - auto folderName = fs::path(iname).parent_path().string() + "/"; - if (auto folder = folders.find(folderName); folder != folders.end()) - { - auto* nnode = new DSCContentsModelItem(m_bv, file, iname, folder->second); - folder->second->addChild(nnode); - } - else - BNLogError("DSCView Sidebar Logic Error: Couldn't find folder for %s %s %s", iname.c_str(), file.c_str(), - folderName.c_str()); - } - - endResetModel(); -} - -QModelIndex DSCContentsModel::index(int row, int column, const QModelIndex& parentIndex) const -{ - if (!hasIndex(row, column, parentIndex)) - return QModelIndex(); - - // Use the parent index's item if it is valid, otherwise use the root. - DSCContentsModelItem* parent = nullptr; - if (parentIndex.isValid()) - parent = static_cast<DSCContentsModelItem*>(parentIndex.internalPointer()); - else - parent = m_root; - - // If the child is found, create an index for it; use an invalid index otherwise. - auto item = parent->child(row); - if (item) - return createIndex(row, column, item); - - return QModelIndex(); -} - -QModelIndex DSCContentsModel::parent(const QModelIndex& index) const -{ - if (!index.isValid()) - return QModelIndex(); - - auto child = static_cast<DSCContentsModelItem*>(index.internalPointer()); - auto parent = child->parent(); - if (parent == m_root || parent == nullptr) - return QModelIndex(); - - return createIndex(parent->row(), 0, parent); -} - -QVariant DSCContentsModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - { - switch (section) - { - case DSCContentsModel::NameColumn: - return "Name"; - default: - return ""; - } - } - - return QAbstractItemModel::headerData(section, orientation, role); -} - -constexpr int ComponentGuidDataRole = 64; - -QVariant DSCContentsModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - auto item = static_cast<DSCContentsModelItem*>(index.internalPointer()); - if (!item) - return {}; - - switch (role) - { - case Qt::DisplayRole: - return item->data(index.column()); - default: - return {}; - } -} - -bool DSCContentsModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - return false; -} - -Qt::ItemFlags DSCContentsModel::flags(const QModelIndex& index) const -{ - if (!index.isValid()) - return Qt::ItemIsDropEnabled; // Root node - - Qt::ItemFlags flags = QAbstractItemModel::flags(index); - - return flags; -} - - -int DSCContentsModel::rowCount(const QModelIndex& parent) const -{ - DSCContentsModelItem* item; - if (!parent.isValid()) - item = m_root; - else - item = static_cast<DSCContentsModelItem*>(parent.internalPointer()); - - return item->childCount(); -} - -int DSCContentsModel::columnCount(const QModelIndex& parent) const -{ - return 1; -} - -Qt::DropActions DSCContentsModel::supportedDropActions() const -{ - return Qt::IgnoreAction; -} - - -//===-- ComponentFilterModel ----------------------------------------------===// - -DSCFilterModel::DSCFilterModel(BinaryViewRef data, QObject* parent) : - QSortFilterProxyModel(parent), m_model(new DSCContentsModel(data)) -{ - setSourceModel(m_model); -} - -bool DSCFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const -{ - auto index = sourceModel()->index(sourceRow, 0, sourceParent); - if (!index.isValid()) - return false; - - return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); -} - -DSCSidebarView::DSCSidebarView(ViewFrame* frame, BinaryViewRef data, QWidget* parent) : - QTreeView(parent), m_data(data), m_frame(frame), m_parent(parent) -{ - connect(this, &DSCSidebarView::doubleClicked, this, &DSCSidebarView::navigateToIndex); - - setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, &DSCSidebarView::customContextMenuRequested, [this](const QPoint& p) { - auto menu = createContextMenu(); - menu->popup(viewport()->mapToGlobal(p)); - }); -} - - -void DSCSidebarView::navigateToIndex(const QModelIndex& index) -{ - auto filterParent = static_cast<DSCSidebarWidget*>(m_parent); - if (!filterParent) - return; - auto modelItem = static_cast<DSCContentsModelItem*>(filterParent->m_model->mapToSource(index).internalPointer()); - - if (modelItem->m_installName.empty()) - return; - - QMessageBox::StandardButton reply; - reply = QMessageBox::question(this, "Load Image", "Load " + QString::fromStdString(modelItem->m_name) + "?", - QMessageBox::Yes | QMessageBox::No); - - if (reply == QMessageBox::Yes) - { - Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(m_data); - cache->LoadImageWithInstallName(modelItem->m_installName); - m_data->UpdateAnalysis(); - } -} - -QMenu* DSCSidebarView::createContextMenu() -{ - auto menu = new QMenu(); - - return menu; -} - -//===-- ComponentTree -----------------------------------------------------===// - -DSCSidebarWidget::DSCSidebarWidget(ViewFrame* frame, BinaryViewRef data) : - SidebarWidget("dyld_shared_cache"), m_data(data), m_frame(frame), m_header(new QWidget) -{ - auto view = data; - m_tree = new DSCSidebarView(frame, view, this); - m_model = new DSCFilterModel(view); - m_tree->setDragDropMode(QAbstractItemView::DragDrop); - m_tree->setSelectionMode(QAbstractItemView::ExtendedSelection); - m_tree->setDragEnabled(true); - m_tree->setAcceptDrops(true); - m_tree->setDropIndicatorShown(true); - m_tree->header()->setSectionsMovable(false); - - m_tree->setModel(m_model); - m_model->setRecursiveFilteringEnabled(true); - - m_filterEdit = new FilterEdit(this); - m_filterView = new FilteredView(this, m_tree, this, m_filterEdit); - m_filterView->setFilterPlaceholderText("Search Shared Cache Files"); - - auto headerLayout = new QHBoxLayout(m_header); - headerLayout->setContentsMargins(0, 0, 0, 0); - headerLayout->addWidget(m_filterEdit); - - auto layout = new QVBoxLayout(this); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(m_filterView); -} - -//===-- ComponentTree - FilterTarget --------------------------------------===// - -void DSCSidebarWidget::setFilter(const std::string& filter) -{ - m_model->setFilterFixedString(QString::fromStdString(filter)); -} - -void DSCSidebarWidget::scrollToFirstItem() {} - -void DSCSidebarWidget::scrollToCurrentItem() {} - -void DSCSidebarWidget::selectFirstItem() {} - -void DSCSidebarWidget::activateFirstItem() {} - -//===-- DSCSidebarWidget - SidebarWidget -------------------------------------===// - -QWidget* DSCSidebarWidget::headerWidget() -{ - return m_header; -} - -void DSCSidebarWidget::focus() {} - -QImage temporaryIcon() -{ - QImage icon(56, 56, QImage::Format_RGB32); - icon.fill(0); - - QPainter p; - p.begin(&icon); - p.setFont({"Inter", 16}); - p.setPen({255, 255, 255, 255}); - p.drawText(QRectF {0, 0, 56, 56}, Qt::AlignCenter, "DSC"); - p.end(); - - return icon; -} - -DSCSidebarWidgetType::DSCSidebarWidgetType() : SidebarWidgetType(temporaryIcon(), "Shared Cache") {} - -SidebarWidget* DSCSidebarWidgetType::createWidget(ViewFrame* frame, BinaryViewRef data) -{ - return new DSCSidebarWidget(frame, data); -} diff --git a/view/sharedcache/ui/dscwidget.h b/view/sharedcache/ui/dscwidget.h deleted file mode 100644 index c4be969c..00000000 --- a/view/sharedcache/ui/dscwidget.h +++ /dev/null @@ -1,190 +0,0 @@ -// -// by kat // 9/15/22. -// - -#ifndef SHAREDCACHE_DSCSIDEBARWIDGET_H -#define SHAREDCACHE_DSCSIDEBARWIDGET_H - -#include <QtCore/QAbstractItemModel> -#include <QtCore/QSortFilterProxyModel> -#include <QtWidgets/QTreeView> - -#include "ui/filter.h" -#include "ui/sidebar.h" -#include "ui/uitypes.h" -#include <binaryninjaapi.h> -#include <sharedcacheapi.h> - -#include <mutex> - - -class DSCContentsModel; - -class DSCFilterModel; - -class DSCSidebarView; - -enum ModelItemType { - FolderModelItem, - ImageModelItem -}; - -class DSCContentsModelItem { - friend class ComponentModel; - - friend class ComponentFilterModel; - - friend class DSCSidebarView; - - ModelItemType m_type; - - DSCContentsModelItem *m_parent; - std::vector<DSCContentsModelItem *> m_children; - - BinaryViewRef m_bv; - - std::string m_name; - std::string m_installName; // only set on images, not dirs - - bool m_hasDataVar = false; - BinaryNinja::DataVariable m_dataVar; - -public: - explicit DSCContentsModelItem(DSCContentsModelItem *parent = nullptr); - - explicit DSCContentsModelItem(BinaryViewRef, std::string, std::string, DSCContentsModelItem *parent = nullptr); - - /// Get the "name" that should be displayed for an item. - QString displayName() const; - - size_t childCount() const; - - DSCContentsModelItem *child(size_t); - - void addChild(DSCContentsModelItem *); - - DSCContentsModelItem *parent() const; - - size_t row() const; - - QVariant data(int column) const; - - QImage icon() const; -}; - -class DSCContentsModel : public QAbstractItemModel { -Q_OBJECT - - BinaryViewRef m_bv; - Ref<SharedCacheAPI::SharedCache> m_cache; - DSCContentsModelItem *m_root; - - std::unordered_map<std::string, DSCContentsModelItem *> m_dscItems; - - std::mutex m_updateMutex; - - void refresh(); - -public: - enum Column : int { - NameColumn = 0, - AddressColumn, - KindColumn, - }; - - DSCContentsModel(BinaryViewRef, QObject *parent = nullptr); - - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; - - QModelIndex parent(const QModelIndex &) const override; - - QVariant headerData(int, Qt::Orientation, int role = Qt::DisplayRole) const override; - - QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const override; - - bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; - - Qt::ItemFlags flags(const QModelIndex &) const override; - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - - Qt::DropActions supportedDropActions() const override; - -}; - -/// Filtering model to wrap a `ComponentModel`. -class DSCFilterModel : public QSortFilterProxyModel { -Q_OBJECT - - DSCContentsModel *m_model; - -public: - DSCFilterModel(BinaryViewRef, QObject *parent = nullptr); - - [[nodiscard]] bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; -}; - -class DSCSidebarView : public QTreeView { - BinaryViewRef m_data; - ViewFrame *m_frame; - QWidget *m_parent; - - void navigateToIndex(const QModelIndex &); - - QMenu *createContextMenu(); - -public: - DSCSidebarView(ViewFrame *, BinaryViewRef, QWidget *parent = nullptr); -}; - -class DSCSidebarWidget : public SidebarWidget, public FilterTarget { -Q_OBJECT - - friend DSCSidebarView; - - BinaryViewRef m_data; - ViewFrame *m_frame; - QWidget *m_header; - - DSCSidebarView *m_tree; - - QSortFilterProxyModel *m_model; - - FilterEdit *m_filterEdit; - FilteredView *m_filterView; - -public: - DSCSidebarWidget(ViewFrame *, BinaryViewRef); - - QWidget *headerWidget() override; - - void focus() override; - - void setFilter(const std::string &) override; - - void scrollToFirstItem() override; - - void scrollToCurrentItem() override; - - void selectFirstItem() override; - - void activateFirstItem() override; -}; - -class DSCSidebarWidgetType : public SidebarWidgetType { -public: - DSCSidebarWidgetType(); - - bool ValidForView(BinaryNinja::BinaryView* view) - { - if (!view) - return false; - return (view->GetTypeName() == VIEW_NAME); - } - - SidebarWidget *createWidget(ViewFrame *, BinaryViewRef) override; -}; - -#endif //SHAREDCACHE_DSCSIDEBARWIDGET_H |
