From feeb1f58799a443247b60d3acc1b653aff53f542 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Fri, 17 Mar 2023 12:27:14 +0800 Subject: [PATCH] Do not run the loaded module detection for a second time if the module is already loaded --- core/debuggercontroller.cpp | 10 +++++++++- core/debuggercontroller.h | 2 ++ core/debuggerstate.cpp | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/debuggercontroller.cpp b/core/debuggercontroller.cpp index 6577ff1d..c50eb261 100644 --- a/core/debuggercontroller.cpp +++ b/core/debuggercontroller.cpp @@ -118,6 +118,7 @@ bool DebuggerController::Launch() if (!CreateDebugAdapter()) return false; + m_inputFileLoaded = false; m_state->MarkDirty(); bool result = Execute(); if (result) @@ -144,6 +145,7 @@ bool DebuggerController::Attach(int32_t pid) if (!CreateDebugAdapter()) return false; + m_inputFileLoaded = false; m_state->MarkDirty(); bool result = m_adapter->Attach(pid); if (result) @@ -640,7 +642,10 @@ void DebuggerController::DetectLoadedModule() { // Rebase the binary and create DebugView uint64_t remoteBase; - if (!m_state->GetRemoteBase(remoteBase)) + // Right now we only support applying the analysis info from one module into the debugger view, So we use a bool + // here. In the future, we would like to support loading multiple modules, and we will need a more + // robust mechanism. + if (m_inputFileLoaded || (!m_state->GetRemoteBase(remoteBase))) return; FileMetadataRef fileMetadata = m_data->GetFile(); @@ -663,6 +668,8 @@ void DebuggerController::DetectLoadedModule() }); if (!ok) LogWarn("create snapshoted view failed"); + + m_inputFileLoaded = true; } @@ -733,6 +740,7 @@ void DebuggerController::Connect() if (!CreateDebugAdapter()) return; + m_inputFileLoaded = false; m_state->MarkDirty(); m_state->SetConnectionStatus(DebugAdapterConnectingStatus); diff --git a/core/debuggercontroller.h b/core/debuggercontroller.h index 053eb9f1..5785db33 100644 --- a/core/debuggercontroller.h +++ b/core/debuggercontroller.h @@ -90,6 +90,8 @@ namespace BinaryNinjaDebugger { bool m_lastAdapterStopEventConsumed = true; + bool m_inputFileLoaded = false; + void EventHandler(const DebuggerEvent& event); void UpdateStackVariables(); void AddRegisterValuesToExpressionParser(); diff --git a/core/debuggerstate.cpp b/core/debuggerstate.cpp index b531f747..ec813d59 100644 --- a/core/debuggerstate.cpp +++ b/core/debuggerstate.cpp @@ -320,6 +320,9 @@ bool DebuggerModules::GetModuleBase(const std::string& name, uint64_t& address) if (IsDirty()) Update(); + if (name.empty()) + return false; + for (const DebugModule& module : m_modules) { if (module.IsSameBaseModule(name))