diff options
| author | kat <kat@vector35.com> | 2024-10-28 11:58:15 -0400 |
|---|---|---|
| committer | kat <kat@vector35.com> | 2024-10-28 12:58:51 -0400 |
| commit | 07bce5f257d30061475452ec9c2e06a132747b54 (patch) | |
| tree | 434dbd4660b981edd81c3f1651e868aacb240b26 /view/sharedcache | |
| parent | 891b8c0d4366266c0b9af08037dbd71c54cf86b3 (diff) | |
[SharedCache] Fix UI causing BV leaks
Diffstat (limited to 'view/sharedcache')
| -rw-r--r-- | view/sharedcache/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | view/sharedcache/api/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | view/sharedcache/api/sharedcacheapi.h | 137 | ||||
| -rw-r--r-- | view/sharedcache/core/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | view/sharedcache/core/DSCView.cpp | 9 | ||||
| -rw-r--r-- | view/sharedcache/ui/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | view/sharedcache/ui/SharedCacheUINotifications.cpp | 16 | ||||
| -rw-r--r-- | view/sharedcache/ui/dscpicker.cpp | 4 | ||||
| -rw-r--r-- | view/sharedcache/ui/dsctriage.cpp | 7 | ||||
| -rw-r--r-- | view/sharedcache/ui/dsctriage.h | 9 | ||||
| -rw-r--r-- | view/sharedcache/ui/dscwidget.cpp | 2 | ||||
| -rw-r--r-- | view/sharedcache/ui/dscwidget.h | 2 | ||||
| -rw-r--r-- | view/sharedcache/workflow/CMakeLists.txt | 8 |
13 files changed, 51 insertions, 169 deletions
diff --git a/view/sharedcache/CMakeLists.txt b/view/sharedcache/CMakeLists.txt index 83ff4a57..2d073204 100644 --- a/view/sharedcache/CMakeLists.txt +++ b/view/sharedcache/CMakeLists.txt @@ -84,5 +84,5 @@ message(" ░▒████▓ ▒██████▒▒▒ ▓███▀ ░ Qt Version: ${QT_VERSION} ▒▒▓ ▒ ▒ ▒▓▒ ▒ ░░ ░▒ ▒ ░ Crash on Failure: ${HARD_FAIL_MODE} ░ ▒ ▒ ░ ░▒ ░ ░ ░ ▒ Slideinfo Debug Tags: ${SLIDEINFO_DEBUG_TAGS} - ░ ░ ░ ░ ░ ░ ░ + ░ ░ ░ ░ ░ ░ ░ REFCOUNT_DEBUG: ${BN_REF_COUNT_DEBUG} ")
\ No newline at end of file diff --git a/view/sharedcache/api/CMakeLists.txt b/view/sharedcache/api/CMakeLists.txt index b09ae321..1766352d 100644 --- a/view/sharedcache/api/CMakeLists.txt +++ b/view/sharedcache/api/CMakeLists.txt @@ -5,7 +5,11 @@ file(GLOB BN_MACHO_API_SOURCES *.cpp *.h) add_library(sharedcacheapi OBJECT ${BN_MACHO_API_SOURCES}) if (VIEW_NAME) - target_compile_definitions(sharedcacheapi PRIVATE VIEW_NAME="${VIEW_NAME}") + if (BN_REF_COUNT_DEBUG) + target_compile_definitions(sharedcacheapi PRIVATE VIEW_NAME="${VIEW_NAME}" BN_REF_COUNT_DEBUG) + else() + target_compile_definitions(sharedcacheapi PRIVATE VIEW_NAME="${VIEW_NAME}") + endif() else() error("VIEW_NAME must be defined") endif() diff --git a/view/sharedcache/api/sharedcacheapi.h b/view/sharedcache/api/sharedcacheapi.h index efd38532..19f021e7 100644 --- a/view/sharedcache/api/sharedcacheapi.h +++ b/view/sharedcache/api/sharedcacheapi.h @@ -91,143 +91,6 @@ namespace SharedCacheAPI { } }; - - template<class T> - class SCRef { - T *m_obj; -#ifdef BN_REF_COUNT_DEBUG - void* m_assignmentTrace = nullptr; -#endif - - public: - SCRef<T>() : m_obj(NULL) {} - - SCRef<T>(T *obj) : m_obj(obj) { - if (m_obj) { - m_obj->AddRef(); -#ifdef BN_REF_COUNT_DEBUG - m_assignmentTrace = BNRegisterObjectRefDebugTrace(typeid(T).name()); -#endif - } - } - - SCRef<T>(const SCRef<T> &obj) : m_obj(obj.m_obj) { - if (m_obj) { - m_obj->AddRef(); -#ifdef BN_REF_COUNT_DEBUG - m_assignmentTrace = BNRegisterObjectRefDebugTrace(typeid(T).name()); -#endif - } - } - - SCRef<T>(SCRef<T> &&other) : m_obj(other.m_obj) { - other.m_obj = 0; -#ifdef BN_REF_COUNT_DEBUG - m_assignmentTrace = other.m_assignmentTrace; -#endif - } - - ~SCRef<T>() { - if (m_obj) { - m_obj->Release(); -#ifdef BN_REF_COUNT_DEBUG - BNUnregisterObjectRefDebugTrace(typeid(T).name(), m_assignmentTrace); -#endif - } - } - - SCRef<T> &operator=(const Ref<T> &obj) { -#ifdef BN_REF_COUNT_DEBUG - if (m_obj) - BNUnregisterObjectRefDebugTrace(typeid(T).name(), m_assignmentTrace); - if (obj.m_obj) - m_assignmentTrace = BNRegisterObjectRefDebugTrace(typeid(T).name()); -#endif - T *oldObj = m_obj; - m_obj = obj.m_obj; - if (m_obj) - m_obj->AddRef(); - if (oldObj) - oldObj->Release(); - return *this; - } - - SCRef<T> &operator=(SCRef<T> &&other) { - if (m_obj) { -#ifdef BN_REF_COUNT_DEBUG - BNUnregisterObjectRefDebugTrace(typeid(T).name(), m_assignmentTrace); -#endif - m_obj->Release(); - } - m_obj = other.m_obj; - other.m_obj = 0; -#ifdef BN_REF_COUNT_DEBUG - m_assignmentTrace = other.m_assignmentTrace; -#endif - return *this; - } - - SCRef<T> &operator=(T *obj) { -#ifdef BN_REF_COUNT_DEBUG - if (m_obj) - BNUnregisterObjectRefDebugTrace(typeid(T).name(), m_assignmentTrace); - if (obj) - m_assignmentTrace = BNRegisterObjectRefDebugTrace(typeid(T).name()); -#endif - T *oldObj = m_obj; - m_obj = obj; - if (m_obj) - m_obj->AddRef(); - if (oldObj) - oldObj->Release(); - return *this; - } - - operator T *() const { - return m_obj; - } - - T *operator->() const { - return m_obj; - } - - T &operator*() const { - return *m_obj; - } - - bool operator!() const { - return m_obj == NULL; - } - - bool operator==(const T *obj) const { - return T::GetObject(m_obj) == T::GetObject(obj); - } - - bool operator==(const SCRef<T> &obj) const { - return T::GetObject(m_obj) == T::GetObject(obj.m_obj); - } - - bool operator!=(const T *obj) const { - return T::GetObject(m_obj) != T::GetObject(obj); - } - - bool operator!=(const SCRef<T> &obj) const { - return T::GetObject(m_obj) != T::GetObject(obj.m_obj); - } - - bool operator<(const T *obj) const { - return T::GetObject(m_obj) < T::GetObject(obj); - } - - bool operator<(const SCRef<T> &obj) const { - return T::GetObject(m_obj) < T::GetObject(obj.m_obj); - } - - T *GetPtr() const { - return m_obj; - } - }; - struct DSCMemoryRegion { uint64_t vmAddress; uint64_t size; diff --git a/view/sharedcache/core/CMakeLists.txt b/view/sharedcache/core/CMakeLists.txt index 89e89811..9cf3fa9d 100644 --- a/view/sharedcache/core/CMakeLists.txt +++ b/view/sharedcache/core/CMakeLists.txt @@ -48,9 +48,17 @@ get_recursive_include_dirs(binaryninjaapi INCLUDES) if (VIEW_NAME) if (SLIDEINFO_DEBUG_TAGS) - target_compile_definitions(sharedcachecore PRIVATE VIEW_NAME="${VIEW_NAME}" SHAREDCACHE_LIBRARY SLIDEINFO_DEBUG_TAGS) + if (BN_REF_COUNT_DEBUG) + target_compile_definitions(sharedcachecore PRIVATE VIEW_NAME="${VIEW_NAME}" SHAREDCACHE_LIBRARY SLIDEINFO_DEBUG_TAGS BN_REF_COUNT_DEBUG) + else() + target_compile_definitions(sharedcachecore PRIVATE VIEW_NAME="${VIEW_NAME}" SHAREDCACHE_LIBRARY SLIDEINFO_DEBUG_TAGS) + endif() else() - target_compile_definitions(sharedcachecore PRIVATE VIEW_NAME="${VIEW_NAME}" SHAREDCACHE_LIBRARY) + if (BN_REF_COUNT_DEBUG) + target_compile_definitions(sharedcachecore PRIVATE VIEW_NAME="${VIEW_NAME}" SHAREDCACHE_LIBRARY BN_REF_COUNT_DEBUG) + else() + target_compile_definitions(sharedcachecore PRIVATE VIEW_NAME="${VIEW_NAME}" SHAREDCACHE_LIBRARY) + endif() endif() message(STATUS "VIEW_NAME: ${VIEW_NAME}") else() diff --git a/view/sharedcache/core/DSCView.cpp b/view/sharedcache/core/DSCView.cpp index b065f1e6..e690f765 100644 --- a/view/sharedcache/core/DSCView.cpp +++ b/view/sharedcache/core/DSCView.cpp @@ -32,9 +32,9 @@ DSCRawView::DSCRawView(const std::string& typeName, BinaryView* data, bool parse // This is going to load _only_ the dyld header of the loaded file. // This written region will be immediately overwritten on image loading by SharedCache.cpp GetFile()->SetFilename(data->GetFile()->GetOriginalFilename()); - auto reader = new BinaryReader(GetParentView()); - reader->Seek(16); - auto size = reader->Read32() + 0x8; + uint32_t size; + GetParentView()->Read(&size, 16, 4); + size += 8; AddAutoSegment(0, size, 0, size, SegmentReadable); GetParentView()->WriteBuffer(0, GetParentView()->ReadBuffer(0, size)); } @@ -762,7 +762,8 @@ DSCViewType::DSCViewType() : BinaryViewType(VIEW_NAME, VIEW_NAME) {} BinaryNinja::Ref<BinaryNinja::BinaryView> DSCViewType::Create(BinaryNinja::BinaryView* data) { - return new DSCView(VIEW_NAME, new DSCRawView("DSCRawView", data, false), false); + Ref<BinaryView> rawViewRef = new DSCRawView("DSCRawView", data, false); + return new DSCView(VIEW_NAME, rawViewRef, false); } diff --git a/view/sharedcache/ui/CMakeLists.txt b/view/sharedcache/ui/CMakeLists.txt index 04e2f3cb..1695b8dd 100644 --- a/view/sharedcache/ui/CMakeLists.txt +++ b/view/sharedcache/ui/CMakeLists.txt @@ -13,7 +13,11 @@ list(FILTER SOURCES EXCLUDE REGEX qrc_.*) add_library(sharedcacheui SHARED ${SOURCES}) if (VIEW_NAME) - target_compile_definitions(sharedcacheui PRIVATE VIEW_NAME="${VIEW_NAME}") + if (BN_REF_COUNT_DEBUG) + target_compile_definitions(sharedcacheui PRIVATE VIEW_NAME="${VIEW_NAME}" BN_REF_COUNT_DEBUG) + else() + target_compile_definitions(sharedcacheui PRIVATE VIEW_NAME="${VIEW_NAME}") + endif() else() error("VIEW_NAME must be defined") endif() diff --git a/view/sharedcache/ui/SharedCacheUINotifications.cpp b/view/sharedcache/ui/SharedCacheUINotifications.cpp index 6c64c9ef..6979bac3 100644 --- a/view/sharedcache/ui/SharedCacheUINotifications.cpp +++ b/view/sharedcache/ui/SharedCacheUINotifications.cpp @@ -48,11 +48,11 @@ void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const Q if (!ah->isBoundAction("Load Image by Name")) { ah->bindAction("Load Image by Name", UIAction([view = view](const UIActionContext& ctx) { - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(view); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(view); DisplayDSCPicker(ctx.context, view); })); ah->bindAction("Load Section by Address", UIAction([view = view](const UIActionContext& ctx) { - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); uint64_t addr = 0; bool gotAddr = GetAddressInput(addr, "Address", "Address"); if (gotAddr) @@ -67,7 +67,7 @@ void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const Q UIAction( [](const UIActionContext& ctx) { Ref<BinaryView> view = ctx.binaryView; - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); uint64_t addr = ctx.token.token.value; if (addr) { @@ -78,7 +78,7 @@ void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const Q } }, [](const UIActionContext& ctx) { - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); uint64_t addr = ctx.token.token.value; if (isAddrMapped(ctx.binaryView, addr)) return false; @@ -88,7 +88,7 @@ void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const Q UIAction( [](const UIActionContext& ctx) { Ref<BinaryView> view = ctx.binaryView; - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(view); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(view); uint64_t addr = ctx.token.token.value; if (addr) { @@ -99,21 +99,21 @@ void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const Q } }, [](const UIActionContext& ctx) { - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); uint64_t addr = ctx.token.token.value; if (isAddrMapped(ctx.binaryView, addr)) return false; return addr && cache->GetImageNameForAddress(addr) != ""; // bool })); ah->setActionDisplayName("Load ADDRHERE", [](const UIActionContext& ctx) { - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); uint64_t addr = ctx.token.token.value; if (addr) return QString("Load ") + cache->GetNameForAddress(addr).c_str(); return QString("Error"); }); ah->setActionDisplayName("Load IMGHERE", [](const UIActionContext& ctx) { - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(ctx.binaryView); uint64_t addr = ctx.token.token.value; if (addr) return QString("Load ") + cache->GetImageNameForAddress(addr).c_str(); diff --git a/view/sharedcache/ui/dscpicker.cpp b/view/sharedcache/ui/dscpicker.cpp index 33877675..a82da4fc 100644 --- a/view/sharedcache/ui/dscpicker.cpp +++ b/view/sharedcache/ui/dscpicker.cpp @@ -15,7 +15,7 @@ void DisplayDSCPicker(UIContext* ctx, Ref<BinaryView> dscView) BackgroundThread::create(ctx ? ctx->mainWindow() : nullptr)->thenBackground( [dscView=dscView](QVariant var) { QStringList entries; - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(dscView); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(dscView); for (const auto& img : cache->GetAvailableImages()) entries.push_back(QString::fromStdString(img)); @@ -36,7 +36,7 @@ void DisplayDSCPicker(UIContext* ctx, Ref<BinaryView> dscView) })->thenBackground([dscView=dscView](QVariant var){ if (var.toString().isEmpty()) return; - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(dscView); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(dscView); cache->LoadImageWithInstallName(var.toString().toStdString()); })->start(); } diff --git a/view/sharedcache/ui/dsctriage.cpp b/view/sharedcache/ui/dsctriage.cpp index 0dca96bf..6f931ee6 100644 --- a/view/sharedcache/ui/dsctriage.cpp +++ b/view/sharedcache/ui/dsctriage.cpp @@ -20,7 +20,7 @@ #define QSETTINGS_KEY_ALPHA_POPUP_SEEN "DSCTriage-AlphaPopupSeen" -DSCCacheBlocksView::DSCCacheBlocksView(QWidget* parent, BinaryViewRef data, SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache) +DSCCacheBlocksView::DSCCacheBlocksView(QWidget* parent, BinaryViewRef data, Ref<SharedCacheAPI::SharedCache> cache) : QWidget(parent), m_data(data), m_cache(cache) { setMouseTracking(true); @@ -477,7 +477,7 @@ void SymbolTableModel::setFilter(std::string text) } -SymbolTableView::SymbolTableView(QWidget* parent, SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache) +SymbolTableView::SymbolTableView(QWidget* parent, Ref<SharedCacheAPI::SharedCache> cache) : m_model(new SymbolTableModel(this)){ // Set up the filter model @@ -865,9 +865,6 @@ Contributions are always welcome! </p> } -DSCTriageView::~DSCTriageView() {} - - QFont DSCTriageView::getFont() { return getMonospaceFont(this); diff --git a/view/sharedcache/ui/dsctriage.h b/view/sharedcache/ui/dsctriage.h index 96099a53..a0460e63 100644 --- a/view/sharedcache/ui/dsctriage.h +++ b/view/sharedcache/ui/dsctriage.h @@ -24,7 +24,7 @@ class DSCCacheBlocksView : public QWidget Q_OBJECT BinaryViewRef m_data; - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> m_cache; + Ref<SharedCacheAPI::SharedCache> m_cache; uint64_t m_backingCacheCount = 0; std::vector<SharedCacheAPI::BackingCache> m_backingCaches; @@ -45,7 +45,7 @@ class DSCCacheBlocksView : public QWidget void blockSelected(int index); public: - DSCCacheBlocksView(QWidget* parent, BinaryViewRef data, SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache); + DSCCacheBlocksView(QWidget* parent, BinaryViewRef data, Ref<SharedCacheAPI::SharedCache> cache); virtual ~DSCCacheBlocksView() override; protected: @@ -218,7 +218,7 @@ class SymbolTableView : public QTableView, public FilterTarget SymbolTableModel* m_model; public: - SymbolTableView(QWidget* parent, SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> cache); + SymbolTableView(QWidget* parent, Ref<SharedCacheAPI::SharedCache> cache); virtual ~SymbolTableView() override; void scrollToFirstItem() override { @@ -262,7 +262,7 @@ class DSCTriageView : public QWidget, public View { BinaryViewRef m_data; QVBoxLayout* m_layout; - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> m_cache; + Ref<SharedCacheAPI::SharedCache> m_cache; SplitTabWidget* m_triageTabs; DockableTabCollection* m_triageCollection; @@ -275,7 +275,6 @@ class DSCTriageView : public QWidget, public View public: DSCTriageView(QWidget* parent, BinaryViewRef data); - virtual ~DSCTriageView() override; BinaryViewRef getData() override; void setSelectionOffsets(BNAddressRange range) override {}; QFont getFont() override; diff --git a/view/sharedcache/ui/dscwidget.cpp b/view/sharedcache/ui/dscwidget.cpp index 2483a26e..adece165 100644 --- a/view/sharedcache/ui/dscwidget.cpp +++ b/view/sharedcache/ui/dscwidget.cpp @@ -346,7 +346,7 @@ void DSCSidebarView::navigateToIndex(const QModelIndex& index) if (reply == QMessageBox::Yes) { - SharedCacheAPI::SharedCache* cache = new SharedCacheAPI::SharedCache(m_data); + Ref<SharedCacheAPI::SharedCache> cache = new SharedCacheAPI::SharedCache(m_data); cache->LoadImageWithInstallName(modelItem->m_installName); m_data->UpdateAnalysis(); } diff --git a/view/sharedcache/ui/dscwidget.h b/view/sharedcache/ui/dscwidget.h index 0d5b9e0b..c4be969c 100644 --- a/view/sharedcache/ui/dscwidget.h +++ b/view/sharedcache/ui/dscwidget.h @@ -76,7 +76,7 @@ class DSCContentsModel : public QAbstractItemModel { Q_OBJECT BinaryViewRef m_bv; - SharedCacheAPI::SCRef<SharedCacheAPI::SharedCache> m_cache; + Ref<SharedCacheAPI::SharedCache> m_cache; DSCContentsModelItem *m_root; std::unordered_map<std::string, DSCContentsModelItem *> m_dscItems; diff --git a/view/sharedcache/workflow/CMakeLists.txt b/view/sharedcache/workflow/CMakeLists.txt index 81e4498c..7648492a 100644 --- a/view/sharedcache/workflow/CMakeLists.txt +++ b/view/sharedcache/workflow/CMakeLists.txt @@ -5,7 +5,11 @@ file(GLOB SOURCES *.cpp *.h) add_library(sharedcacheworkflow OBJECT ${SOURCES}) if (VIEW_NAME) - target_compile_definitions(sharedcacheworkflow PRIVATE VIEW_NAME="${VIEW_NAME}") + if (BN_REF_COUNT_DEBUG) + target_compile_definitions(sharedcacheworkflow PRIVATE VIEW_NAME="${VIEW_NAME}" BN_REF_COUNT_DEBUG) + else() + target_compile_definitions(sharedcacheworkflow PRIVATE VIEW_NAME="${VIEW_NAME}") + endif() else() error("VIEW_NAME must be defined") endif() @@ -38,6 +42,8 @@ function(get_recursive_include_dirs target result) set(${result} ${include_dirs} PARENT_SCOPE) endfunction() +message(STATUS "RCD: ${BN_REF_COUNT_DEBUG}") + get_recursive_include_dirs(binaryninjaapi INCLUDES) target_include_directories(sharedcacheworkflow |
